Static Value-Flow Analysis
Public Types | Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
SVF::WPAPass Class Reference

#include <WPAPass.h>

Public Types

enum  AliasCheckRule { Conservative , Veto , Precise }
 

Public Member Functions

 WPAPass ()
 Constructor needs TargetLibraryInfo to be passed to the AliasAnalysis. More...
 
virtual ~WPAPass ()
 Destructor. More...
 
virtual AliasResult alias (const SVFValue *V1, const SVFValue *V2)
 Interface expose to users of our pointer analysis, given Value infos. More...
 
virtual const PointsTogetPts (const SVFValue *value)
 Retrieve points-to set information. More...
 
virtual const PointsTogetPts (NodeID var)
 
virtual void PrintAliasPairs (PointerAnalysis *pta)
 Print all alias pairs. More...
 
virtual ModRefInfo getModRefInfo (const CallICFGNode *callInst)
 Interface of mod-ref analysis to determine whether a CallSite instruction can mod or ref any memory location. More...
 
virtual ModRefInfo getModRefInfo (const CallICFGNode *callInst, const SVFValue *V)
 Interface of mod-ref analysis to determine whether a CallSite instruction can mod or ref a specific memory location, given Location infos. More...
 
virtual ModRefInfo getModRefInfo (const CallICFGNode *callInst1, const CallICFGNode *callInst2)
 Interface of mod-ref analysis between two CallSite instructions. More...
 
virtual void runOnModule (SVFIR *svfModule)
 Run pointer analysis on SVFModule. More...
 
virtual std::string getPassName () const
 PTA name. More...
 

Static Public Attributes

static char ID = 0
 Pass ID. More...
 

Private Types

typedef std::vector< PointerAnalysis * > PTAVector
 

Private Member Functions

void runPointerAnalysis (SVFIR *pag, u32_t kind)
 Create pointer analysis according to specified kind and analyze the module. More...
 

Private Attributes

PTAVector ptaVector
 all pointer analysis to be executed. More...
 
PointerAnalysis_pta
 pointer analysis to be executed. More...
 
SVFG_svfg
 svfg generated through -ander pointer analysis More...
 

Detailed Description

Whole program pointer analysis. This class performs various pointer analysis on the given module.

Definition at line 54 of file WPAPass.h.

Member Typedef Documentation

◆ PTAVector

typedef std::vector<PointerAnalysis*> SVF::WPAPass::PTAVector
private

Definition at line 56 of file WPAPass.h.

Member Enumeration Documentation

◆ AliasCheckRule

Enumerator
Conservative 

return MayAlias if any pta says alias

Veto 

return NoAlias if any pta says no alias

Precise 

return alias result by the most precise pta

Definition at line 62 of file WPAPass.h.

63  {
64  Conservative,
65  Veto,
66  Precise
67  };
@ Conservative
return MayAlias if any pta says alias
Definition: WPAPass.h:64
@ Precise
return alias result by the most precise pta
Definition: WPAPass.h:66
@ Veto
return NoAlias if any pta says no alias
Definition: WPAPass.h:65

Constructor & Destructor Documentation

◆ WPAPass()

SVF::WPAPass::WPAPass ( )
inline

Constructor needs TargetLibraryInfo to be passed to the AliasAnalysis.

Definition at line 70 of file WPAPass.h.

71  {
72 
73  }

◆ ~WPAPass()

WPAPass::~WPAPass ( )
virtual

Destructor.

Destructor

Definition at line 54 of file WPAPass.cpp.

55 {
56  PTAVector::const_iterator it = ptaVector.begin();
57  PTAVector::const_iterator eit = ptaVector.end();
58  for (; it != eit; ++it)
59  {
60  PointerAnalysis* pta = *it;
61  delete pta;
62  }
63  ptaVector.clear();
64 }
PTAVector ptaVector
all pointer analysis to be executed.
Definition: WPAPass.h:116

Member Function Documentation

◆ alias()

AliasResult WPAPass::alias ( const SVFValue V1,
const SVFValue V2 
)
virtual

Interface expose to users of our pointer analysis, given Value infos.

Return alias results based on our points-to/alias analysis TODO: Need to handle PartialAlias and MustAlias here.

TODO: When this method is invoked during compiler optimizations, the IR used for pointer analysis may been changed, so some Values may not find corresponding SVFIR node. In this case, we only check alias between two Values if they both have SVFIR nodes. Otherwise, MayAlias will be returned.

Veto is used by default

Return NoAlias if any PTA gives NoAlias result

Return MayAlias if any PTA gives MayAlias result

Definition at line 174 of file WPAPass.cpp.

175 {
176 
178 
179  SVFIR* pag = _pta->getPAG();
180 
186  if (pag->hasValueNode(V1) && pag->hasValueNode(V2))
187  {
189  if (Options::AliasRule.nothingSet() || Options::AliasRule(Veto))
190  {
192  result = AliasResult::MayAlias;
193 
194  for (PTAVector::const_iterator it = ptaVector.begin(), eit = ptaVector.end();
195  it != eit; ++it)
196  {
197  if ((*it)->alias(V1, V2) == AliasResult::NoAlias)
198  result = AliasResult::NoAlias;
199  }
200  }
202  {
204  result = AliasResult::NoAlias;
205 
206  for (PTAVector::const_iterator it = ptaVector.begin(), eit = ptaVector.end();
207  it != eit; ++it)
208  {
209  if ((*it)->alias(V1, V2) == AliasResult::MayAlias)
210  result = AliasResult::MayAlias;
211  }
212  }
213  }
214 
215  return result;
216 }
bool hasValueNode(const SVFValue *V)
Definition: IRGraph.h:141
static OptionMultiple< WPAPass::AliasCheckRule > AliasRule
Definition: Options.h:225
SVFIR * getPAG() const
PointerAnalysis * _pta
pointer analysis to be executed.
Definition: WPAPass.h:117
AliasResult
Definition: SVFType.h:527
@ MayAlias
Definition: SVFType.h:529
@ NoAlias
Definition: SVFType.h:528

◆ getModRefInfo() [1/3]

ModRefInfo WPAPass::getModRefInfo ( const CallICFGNode callInst)
virtual

Interface of mod-ref analysis to determine whether a CallSite instruction can mod or ref any memory location.

Return mod-ref result of a Callsite

Definition at line 221 of file WPAPass.cpp.

222 {
223  assert(Options::PASelected(PointerAnalysis::AndersenWaveDiff_WPA) && Options::AnderSVFG() && "mod-ref query is only support with -ander and -svfg turned on");
224  return _svfg->getMSSA()->getMRGenerator()->getModRefInfo(callInst);
225 }
ModRefInfo getModRefInfo(const CallICFGNode *cs)
Definition: MemRegion.cpp:716
MRGenerator * getMRGenerator()
Return MRGenerator.
Definition: MemSSA.h:313
static OptionMultiple< PointerAnalysis::PTATY > PASelected
Definition: Options.h:224
static const Option< bool > AnderSVFG
Definition: Options.h:221
@ AndersenWaveDiff_WPA
Diff wave propagation andersen-style WPA.
MemSSA * getMSSA() const
Get SVFG memory SSA.
Definition: SVFG.h:138
SVFG * _svfg
svfg generated through -ander pointer analysis
Definition: WPAPass.h:118

◆ getModRefInfo() [2/3]

ModRefInfo WPAPass::getModRefInfo ( const CallICFGNode callInst,
const SVFValue V 
)
virtual

Interface of mod-ref analysis to determine whether a CallSite instruction can mod or ref a specific memory location, given Location infos.

Interface of mod-ref analysis to determine whether a CallSite instruction can mod or ref a specific memory location, given Value infos

Return mod-ref results of a Callsite to a specific memory location

Definition at line 230 of file WPAPass.cpp.

231 {
232  assert(Options::PASelected(PointerAnalysis::AndersenWaveDiff_WPA) && Options::AnderSVFG() && "mod-ref query is only support with -ander and -svfg turned on");
233  return _svfg->getMSSA()->getMRGenerator()->getModRefInfo(callInst, V);
234 }

◆ getModRefInfo() [3/3]

ModRefInfo WPAPass::getModRefInfo ( const CallICFGNode callInst1,
const CallICFGNode callInst2 
)
virtual

Interface of mod-ref analysis between two CallSite instructions.

Return mod-ref result between two CallInsts

Definition at line 239 of file WPAPass.cpp.

240 {
241  assert(Options::PASelected(PointerAnalysis::AndersenWaveDiff_WPA) && Options::AnderSVFG() && "mod-ref query is only support with -ander and -svfg turned on");
242  return _svfg->getMSSA()->getMRGenerator()->getModRefInfo(callInst1, callInst2);
243 }

◆ getPassName()

virtual std::string SVF::WPAPass::getPassName ( ) const
inlinevirtual

PTA name.

Definition at line 107 of file WPAPass.h.

108  {
109  return "WPAPass";
110  }

◆ getPts() [1/2]

const PointsTo & WPAPass::getPts ( const SVFValue value)
virtual

Retrieve points-to set information.

Definition at line 157 of file WPAPass.cpp.

158 {
159  assert(_pta && "initialize a pointer analysis first");
160  SVFIR* pag = _pta->getPAG();
161  return getPts(pag->getValueNode(value));
162 }
NodeID getValueNode(const SVFValue *V)
Definition: IRGraph.h:137
virtual const PointsTo & getPts(const SVFValue *value)
Retrieve points-to set information.
Definition: WPAPass.cpp:157

◆ getPts() [2/2]

const PointsTo & WPAPass::getPts ( NodeID  var)
virtual

Definition at line 164 of file WPAPass.cpp.

165 {
166  assert(_pta && "initialize a pointer analysis first");
167  return _pta->getPts(var);
168 }
virtual const PointsTo & getPts(NodeID ptr)=0
Get points-to targets of a pointer. It needs to be implemented in child class.

◆ PrintAliasPairs()

void WPAPass::PrintAliasPairs ( PointerAnalysis pta)
virtual

Print all alias pairs.

Definition at line 133 of file WPAPass.cpp.

134 {
135  SVFIR* pag = pta->getPAG();
136  for (SVFIR::iterator lit = pag->begin(), elit = pag->end(); lit != elit; ++lit)
137  {
138  PAGNode* node1 = lit->second;
139  PAGNode* node2 = node1;
140  for (SVFIR::iterator rit = lit, erit = pag->end(); rit != erit; ++rit)
141  {
142  node2 = rit->second;
143  if(node1==node2)
144  continue;
145  const SVFFunction* fun1 = node1->getFunction();
146  const SVFFunction* fun2 = node2->getFunction();
147  AliasResult result = pta->alias(node1->getId(), node2->getId());
148  SVFUtil::outs() << (result == AliasResult::NoAlias ? "NoAlias" : "MayAlias")
149  << " var" << node1->getId() << "[" << node1->getValueName()
150  << "@" << (fun1==nullptr?"":fun1->getName()) << "] --"
151  << " var" << node2->getId() << "[" << node2->getValueName()
152  << "@" << (fun2==nullptr?"":fun2->getName()) << "]\n";
153  }
154  }
155 }
iterator begin()
Iterators.
Definition: GenericGraph.h:627
IDToNodeMapTy::iterator iterator
Node Iterators.
Definition: GenericGraph.h:606
virtual AliasResult alias(const SVFValue *V1, const SVFValue *V2)=0
Interface exposed to users of our pointer analysis, given Value infos.
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
const std::string & getName() const
Definition: SVFValue.h:243
virtual const std::string getValueName() const =0
Get name of the LLVM value.
virtual const SVFFunction * getFunction() const
Return the function that this SVFVar resides in. Return nullptr if it is a global or constantexpr nod...
Definition: SVFVariables.h:122
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50

◆ runOnModule()

void WPAPass::runOnModule ( SVFIR pag)
virtual

Run pointer analysis on SVFModule.

We start from here

Definition at line 69 of file WPAPass.cpp.

70 {
71  for (u32_t i = 0; i<= PointerAnalysis::Default_PTA; i++)
72  {
73  PointerAnalysis::PTATY iPtaTy = static_cast<PointerAnalysis::PTATY>(i);
74  if (Options::PASelected(iPtaTy))
75  runPointerAnalysis(pag, i);
76  }
77  assert(!ptaVector.empty() && "No pointer analysis is specified.\n");
78 }
unsigned u32_t
Definition: CommandLine.h:18
PTATY
Pointer analysis type list.
@ Default_PTA
default pta without any analysis
void runPointerAnalysis(SVFIR *pag, u32_t kind)
Create pointer analysis according to specified kind and analyze the module.
Definition: WPAPass.cpp:83

◆ runPointerAnalysis()

void WPAPass::runPointerAnalysis ( SVFIR pag,
u32_t  kind 
)
private

Create pointer analysis according to specified kind and analyze the module.

Create pointer analysis according to a specified kind and then analyze the module.

Initialize pointer analysis.

support mod-ref queries only for -ander

Definition at line 83 of file WPAPass.cpp.

84 {
86  switch (kind)
87  {
89  _pta = new Andersen(pag);
90  break;
92  _pta = new AndersenSCD(pag);
93  break;
95  _pta = new AndersenSFR(pag);
96  break;
98  _pta = new AndersenWaveDiff(pag);
99  break;
101  _pta = new Steensgaard(pag);
102  break;
104  _pta = new FlowSensitive(pag);
105  break;
107  _pta = new VersionedFlowSensitive(pag);
108  break;
110  _pta = new TypeAnalysis(pag);
111  break;
112  default:
113  assert(false && "This pointer analysis has not been implemented yet.\n");
114  return;
115  }
116 
117  ptaVector.push_back(_pta);
118  _pta->analyze();
119  if (Options::AnderSVFG())
120  {
121  SVFGBuilder memSSA(true);
122  assert(SVFUtil::isa<AndersenBase>(_pta) && "supports only andersen/steensgaard for pre-computed SVFG");
123  SVFG *svfg = memSSA.buildFullSVFG((BVDataPTAImpl*)_pta);
126  _svfg = svfg;
127  }
128 
129  if (Options::PrintAliases())
131 }
static const Option< bool > PrintAliases
Definition: Options.h:223
@ VFS_WPA
Versioned sparse flow-sensitive WPA.
@ AndersenSCD_WPA
Selective cycle detection andersen-style WPA.
@ Andersen_WPA
Andersen PTA.
@ TypeCPP_WPA
Type-based analysis for C++.
@ AndersenSFR_WPA
Stride-based field representation.
@ Steensgaard_WPA
Steensgaard PTA.
@ FSSPARSE_WPA
Sparse flow sensitive WPA.
virtual void analyze()=0
Start Analysis here (main part of pointer analysis). It needs to be implemented in child class.
Definition: SVFG.h:66
virtual void PrintAliasPairs(PointerAnalysis *pta)
Print all alias pairs.
Definition: WPAPass.cpp:133

Member Data Documentation

◆ _pta

PointerAnalysis* SVF::WPAPass::_pta
private

pointer analysis to be executed.

Definition at line 117 of file WPAPass.h.

◆ _svfg

SVFG* SVF::WPAPass::_svfg
private

svfg generated through -ander pointer analysis

Definition at line 118 of file WPAPass.h.

◆ ID

char WPAPass::ID = 0
static

Pass ID.

Definition at line 60 of file WPAPass.h.

◆ ptaVector

PTAVector SVF::WPAPass::ptaVector
private

all pointer analysis to be executed.

Definition at line 116 of file WPAPass.h.


The documentation for this class was generated from the following files: