Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
SVF::DDAPass Class Reference

#include <DDAPass.h>

Public Types

typedef SCCDetection< SVFG * > SVFGSCC
 
typedef OrderedSet< const SVFGEdge * > SVFGEdgeSet
 
typedef std::vector< PointerAnalysis * > PTAVector
 

Public Member Functions

 DDAPass ()
 
 ~DDAPass ()
 
virtual AliasResult alias (const SVFValue *V1, const SVFValue *V2)
 Interface expose to users of our pointer analysis, given Value infos.
 
virtual AliasResult alias (NodeID V1, NodeID V2)
 Interface expose to users of our pointer analysis, given PAGNodes.
 
virtual void runOnModule (SVFIR *module)
 We start from here.
 
virtual void selectClient (SVFModule *module)
 Select a client.
 
virtual std::string getPassName () const
 Pass name.
 

Static Public Attributes

static char ID = 0
 Pass ID.
 

Private Member Functions

void printQueryPTS ()
 Print queries' pts.
 
void runPointerAnalysis (SVFIR *module, u32_t kind)
 Create pointer analysis according to specified kind and analyze the module.
 
void initCxtInsensitiveEdges (PointerAnalysis *pta, const SVFG *svfg, const SVFGSCC *svfgSCC, SVFGEdgeSet &insensitveEdges)
 Context insensitive Edge for DDA.
 
bool edgeInSVFGSCC (const SVFGSCC *svfgSCC, const SVFGEdge *edge)
 Return TRUE if this edge is inside a SVFG SCC, i.e., src node and dst node are in the same SCC on the SVFG.
 
bool edgeInCallGraphSCC (PointerAnalysis *pta, const SVFGEdge *edge)
 Return TRUE if this edge is inside a SVFG SCC, i.e., src node and dst node are in the same SCC on the SVFG.
 
void collectCxtInsenEdgeForRecur (PointerAnalysis *pta, const SVFG *svfg, SVFGEdgeSet &insensitveEdges)
 
void collectCxtInsenEdgeForVFCycle (PointerAnalysis *pta, const SVFG *svfg, const SVFGSCC *svfgSCC, SVFGEdgeSet &insensitveEdges)
 

Private Attributes

std::unique_ptr< PointerAnalysis_pta
 pointer analysis to be executed.
 
DDAClient_client
 DDA client used.
 

Detailed Description

Demand-Driven Pointer Analysis. This class performs various pointer analysis on the given module.

Definition at line 46 of file DDAPass.h.

Member Typedef Documentation

◆ PTAVector

Definition at line 54 of file DDAPass.h.

◆ SVFGEdgeSet

Definition at line 53 of file DDAPass.h.

◆ SVFGSCC

Definition at line 52 of file DDAPass.h.

Constructor & Destructor Documentation

◆ DDAPass()

SVF::DDAPass::DDAPass ( )
inline

Definition at line 56 of file DDAPass.h.

56: _pta(nullptr), _client(nullptr) {}
std::unique_ptr< PointerAnalysis > _pta
pointer analysis to be executed.
Definition DDAPass.h:92
DDAClient * _client
DDA client used.
Definition DDAPass.h:93

◆ ~DDAPass()

DDAPass::~DDAPass ( )

Definition at line 47 of file DDAPass.cpp.

48{
49 // _pta->dumpStat();
50 if (_client != nullptr)
51 delete _client;
52}

Member Function Documentation

◆ alias() [1/2]

AliasResult DDAPass::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.

Definition at line 297 of file DDAPass.cpp.

298{
299 SVFIR* pag = _pta->getPAG();
300
306 if (pag->hasValueNode(V1) && pag->hasValueNode(V2))
307 {
308 PAGNode* node1 = pag->getGNode(pag->getValueNode(V1));
309 if(pag->isValidTopLevelPtr(node1))
310 _pta->computeDDAPts(node1->getId());
311
312 PAGNode* node2 = pag->getGNode(pag->getValueNode(V2));
313 if(pag->isValidTopLevelPtr(node2))
314 _pta->computeDDAPts(node2->getId());
315
316 return _pta->alias(V1,V2);
317 }
318
320}
NodeType * getGNode(NodeID id) const
Get a node.
bool hasValueNode(const SVFValue *V)
Definition IRGraph.h:141
NodeID getValueNode(const SVFValue *V)
Definition IRGraph.h:137
bool isValidTopLevelPtr(const SVFVar *node)
Definition SVFIR.cpp:685
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
@ MayAlias
Definition SVFType.h:529
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ alias() [2/2]

AliasResult DDAPass::alias ( NodeID  V1,
NodeID  V2 
)
virtual

Interface expose to users of our pointer analysis, given PAGNodes.

Definition at line 281 of file DDAPass.cpp.

282{
283 SVFIR* pag = _pta->getPAG();
284
285 if(pag->isValidTopLevelPtr(pag->getGNode(node1)))
286 _pta->computeDDAPts(node1);
287
288 if(pag->isValidTopLevelPtr(pag->getGNode(node2)))
289 _pta->computeDDAPts(node2);
290
291 return _pta->alias(node1,node2);
292}

◆ collectCxtInsenEdgeForRecur()

void DDAPass::collectCxtInsenEdgeForRecur ( PointerAnalysis pta,
const SVFG svfg,
SVFGEdgeSet insensitveEdges 
)
private

Mark insensitive edge for function recursions

Definition at line 196 of file DDAPass.cpp.

197{
198
199 for (SVFG::SVFGNodeIDToNodeMapTy::const_iterator it = svfg->begin(),eit = svfg->end(); it != eit; ++it)
200 {
201
202 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeIt = it->second->InEdgeBegin();
203 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeEit = it->second->InEdgeEnd();
204 for (; edgeIt != edgeEit; ++edgeIt)
205 {
206 const SVFGEdge* edge = *edgeIt;
207 if(edge->isCallVFGEdge() || edge->isRetVFGEdge())
208 {
209 if(edgeInCallGraphSCC(pta,edge))
210 insensitveEdges.insert(edge);
211 }
212 }
213 }
214}
bool edgeInCallGraphSCC(PointerAnalysis *pta, const SVFGEdge *edge)
Return TRUE if this edge is inside a SVFG SCC, i.e., src node and dst node are in the same SCC on the...
Definition DDAPass.cpp:178
iterator begin()
Iterators.

◆ collectCxtInsenEdgeForVFCycle()

void DDAPass::collectCxtInsenEdgeForVFCycle ( PointerAnalysis pta,
const SVFG svfg,
const SVFGSCC svfgSCC,
SVFGEdgeSet insensitveEdges 
)
private

Mark insensitive edge for value-flow cycles

Definition at line 219 of file DDAPass.cpp.

220{
221
223
224 for (SVFG::SVFGNodeIDToNodeMapTy::const_iterator it = svfg->begin(),eit = svfg->end(); it != eit; ++it)
225 {
226
227 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeIt = it->second->InEdgeBegin();
228 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeEit = it->second->InEdgeEnd();
229 for (; edgeIt != edgeEit; ++edgeIt)
230 {
231 const SVFGEdge* edge = *edgeIt;
232 if(edge->isCallVFGEdge() || edge->isRetVFGEdge())
233 {
234 if(this->edgeInSVFGSCC(svfgSCC,edge))
235 {
236
237 const SVFFunction* srcFun = edge->getSrcNode()->getICFGNode()->getFun();
238 const SVFFunction* dstFun = edge->getDstNode()->getICFGNode()->getFun();
239
240 if(srcFun && dstFun)
241 {
244 insensitvefunPairs.insert(std::make_pair(src,dst));
245 insensitvefunPairs.insert(std::make_pair(dst,src));
246 }
247 else
248 assert(edge->isRetVFGEdge() == false && "should not be an inter-procedural return edge" );
249 }
250 }
251 }
252 }
253
254 for(SVFG::SVFGNodeIDToNodeMapTy::const_iterator it = svfg->begin(),eit = svfg->end(); it != eit; ++it)
255 {
256 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeIt = it->second->InEdgeBegin();
257 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeEit = it->second->InEdgeEnd();
258 for (; edgeIt != edgeEit; ++edgeIt)
259 {
260 const SVFGEdge* edge = *edgeIt;
261
262 if(edge->isCallVFGEdge() || edge->isRetVFGEdge())
263 {
264 const SVFFunction* srcFun = edge->getSrcNode()->getICFGNode()->getFun();
265 const SVFFunction* dstFun = edge->getDstNode()->getICFGNode()->getFun();
266
267 if(srcFun && dstFun)
268 {
271 if(insensitvefunPairs.find(std::make_pair(src,dst))!=insensitvefunPairs.end())
272 insensitveEdges.insert(edge);
273 else if(insensitvefunPairs.find(std::make_pair(dst,src))!=insensitvefunPairs.end())
274 insensitveEdges.insert(edge);
275 }
276 }
277 }
278 }
279}
bool edgeInSVFGSCC(const SVFGSCC *svfgSCC, const SVFGEdge *edge)
Return TRUE if this edge is inside a SVFG SCC, i.e., src node and dst node are in the same SCC on the...
Definition DDAPass.cpp:170
PTACallGraphNode * getCallGraphNode(NodeID id) const
Get call graph node.
PTACallGraph * getCallGraph() const
Return call graph.
NodeID getId() const
Get ID.
u32_t NodeID
Definition GeneralType.h:55

◆ edgeInCallGraphSCC()

bool DDAPass::edgeInCallGraphSCC ( PointerAnalysis pta,
const SVFGEdge edge 
)
private

Return TRUE if this edge is inside a SVFG SCC, i.e., src node and dst node are in the same SCC on the SVFG.

Whether call graph edge in SVFG SCC

Definition at line 178 of file DDAPass.cpp.

179{
180 const SVFFunction* srcFun = edge->getSrcNode()->getICFGNode()->getFun();
181 const SVFFunction* dstFun = edge->getDstNode()->getICFGNode()->getFun();
182
183 if(srcFun && dstFun)
184 {
185 return pta->inSameCallGraphSCC(srcFun,dstFun);
186 }
187
188 assert(edge->isRetVFGEdge() == false && "should not be an inter-procedural return edge" );
189
190 return false;
191}
bool inSameCallGraphSCC(const SVFFunction *fun1, const SVFFunction *fun2)
Return TRUE if this edge is inside a PTACallGraph SCC, i.e., src node and dst node are in the same SC...

◆ edgeInSVFGSCC()

bool DDAPass::edgeInSVFGSCC ( const SVFGSCC svfgSCC,
const SVFGEdge edge 
)
private

Return TRUE if this edge is inside a SVFG SCC, i.e., src node and dst node are in the same SCC on the SVFG.

Whether SVFG edge in a SCC cycle

Definition at line 170 of file DDAPass.cpp.

171{
172 return (svfgSCC->repNode(edge->getSrcID()) == svfgSCC->repNode(edge->getDstID()));
173}

◆ getPassName()

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

Pass name.

Definition at line 72 of file DDAPass.h.

73 {
74 return "DDAPass";
75 }

◆ initCxtInsensitiveEdges()

void DDAPass::initCxtInsensitiveEdges ( PointerAnalysis pta,
const SVFG svfg,
const SVFGSCC svfgSCC,
SVFGEdgeSet insensitveEdges 
)
private

Context insensitive Edge for DDA.

Initialize context insensitive Edge for DDA

Definition at line 159 of file DDAPass.cpp.

160{
162 collectCxtInsenEdgeForRecur(pta,svfg,insensitveEdges);
163 else if(Options::InsenCycle())
164 collectCxtInsenEdgeForVFCycle(pta,svfg,svfgSCC,insensitveEdges);
165}
void collectCxtInsenEdgeForVFCycle(PointerAnalysis *pta, const SVFG *svfg, const SVFGSCC *svfgSCC, SVFGEdgeSet &insensitveEdges)
Definition DDAPass.cpp:219
void collectCxtInsenEdgeForRecur(PointerAnalysis *pta, const SVFG *svfg, SVFGEdgeSet &insensitveEdges)
Definition DDAPass.cpp:196
static const Option< bool > InsenCycle
Definition Options.h:89
static const Option< bool > InsenRecur
Definition Options.h:88

◆ printQueryPTS()

void DDAPass::printQueryPTS ( )
private

Print queries' pts.

Print queries' pts

Definition at line 325 of file DDAPass.cpp.

326{
327 const OrderedNodeSet& candidates = _client->getCandidateQueries();
328 for (OrderedNodeSet::const_iterator it = candidates.begin(), eit = candidates.end(); it != eit; ++it)
329 {
330 const PointsTo& pts = _pta->getPts(*it);
331 _pta->dumpPts(*it,pts);
332 }
333}
const OrderedNodeSet & getCandidateQueries() const
Get candidate queries.
Definition DDAClient.h:71
OrderedSet< NodeID > OrderedNodeSet

◆ runOnModule()

void DDAPass::runOnModule ( SVFIR module)
virtual

We start from here.

initialization for llvm alias analyzer

Definition at line 55 of file DDAPass.cpp.

56{
58 //InitializeAliasAnalysis(this, getDataLayout(&module));
59
60 selectClient(pag->getModule());
61
64 {
68 }
69}
unsigned u32_t
Definition CommandLine.h:18
virtual void selectClient(SVFModule *module)
Select a client.
Definition DDAPass.cpp:72
void runPointerAnalysis(SVFIR *module, u32_t kind)
Create pointer analysis according to specified kind and analyze the module.
Definition DDAPass.cpp:108
static OptionMultiple< PointerAnalysis::PTATY > DDASelected
register this into alias analysis group
Definition Options.h:93
PTATY
Pointer analysis type list.
@ FlowS_DDA
Flow sensitive DDA.
@ Default_PTA
default pta without any analysis

◆ runPointerAnalysis()

void DDAPass::runPointerAnalysis ( SVFIR module,
u32_t  kind 
)
private

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

Initialize pointer analysis.

initialize

compute points-to

finalize

Definition at line 108 of file DDAPass.cpp.

109{
110
113
115 switch (kind)
116 {
118 {
119 _pta = std::make_unique<ContextDDA>(pag, _client);
120 break;
121 }
123 {
124 _pta = std::make_unique<FlowDDA>(pag, _client);
125 break;
126 }
127 default:
128 outs() << "This pointer analysis has not been implemented yet.\n";
129 break;
130 }
131
132 if(Options::WPANum())
133 {
134 _client->collectWPANum(pag->getModule());
135 }
136 else
137 {
139 _pta->initialize();
141 _client->answerQueries(_pta.get());
143 _pta->finalize();
145 _pta->dumpCPts();
146
147 if (_pta->printStat())
148 _client->performStat(_pta.get());
149
152 }
153}
static void setMaxPathLen(u32_t max)
set max path limit
Definition DPItem.h:270
static void setMaxCxtLen(u32_t max)
set max context limit
Definition DPItem.h:265
virtual void answerQueries(PointerAnalysis *pta)
Definition DDAClient.cpp:46
virtual void collectWPANum(SVFModule *)
Definition DDAClient.h:103
virtual void performStat(PointerAnalysis *)
Definition DDAClient.h:101
void printQueryPTS()
Print queries' pts.
Definition DDAPass.cpp:325
static const Option< u32_t > MaxContextLen
Definition Options.h:85
static const Option< u32_t > MaxPathLen
Definition Options.h:84
static const Option< bool > WPANum
Definition Options.h:92
static const Option< bool > PrintCPts
Definition Options.h:90
static const Option< bool > PrintQueryPts
Definition Options.h:91
@ Cxt_DDA
context sensitive DDA
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:50

◆ selectClient()

void DDAPass::selectClient ( SVFModule module)
virtual

Select a client.

select a client to initialize queries

solve function pointer

allow user specify queries

Definition at line 72 of file DDAPass.cpp.

73{
74
75 if (!Options::UserInputQuery().empty())
76 {
78 if (Options::UserInputQuery() == "funptr")
79 {
81 }
82 else if (Options::UserInputQuery() == "alias")
83 {
85 }
87 else
88 {
90 if (Options::UserInputQuery() != "all")
91 {
92 u32_t buf; // Have a buffer
93 stringstream ss(Options::UserInputQuery()); // Insert the user input string into a stream
94 while (ss >> buf)
96 }
97 }
98 }
99 else
100 {
101 assert(false && "Please specify query options!");
102 }
103
105}
void setQuery(NodeID ptr)
Set pointer to be queried by DDA analysis.
Definition DDAClient.h:89
virtual void initialise(SVFModule *)
Definition DDAClient.h:55
static const Option< std::string > UserInputQuery
Definition Options.h:87

Member Data Documentation

◆ _client

DDAClient* SVF::DDAPass::_client
private

DDA client used.

Definition at line 93 of file DDAPass.h.

◆ _pta

std::unique_ptr<PointerAnalysis> SVF::DDAPass::_pta
private

pointer analysis to be executed.

Definition at line 92 of file DDAPass.h.

◆ ID

char DDAPass::ID = 0
static

Pass ID.

Definition at line 51 of file DDAPass.h.


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