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 SVFVar *V1, const SVFVar *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 ()
 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:95
DDAClient * _client
DDA client used.
Definition DDAPass.h:96

◆ ~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]

virtual AliasResult SVF::DDAPass::alias ( const SVFVar V1,
const SVFVar V2 
)
inlinevirtual

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

Definition at line 60 of file DDAPass.h.

61 {
62 return alias(V1->getId(), V2->getId());
63 }
virtual AliasResult alias(const SVFVar *V1, const SVFVar *V2)
Interface expose to users of our pointer analysis, given Value infos.
Definition DDAPass.h:60
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ alias() [2/2]

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

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

Definition at line 280 of file DDAPass.cpp.

281{
282 SVFIR* pag = _pta->getPAG();
283
284 if(pag->isValidTopLevelPtr(pag->getSVFVar(node1)))
285 _pta->computeDDAPts(node1);
286
287 if(pag->isValidTopLevelPtr(pag->getSVFVar(node2)))
288 _pta->computeDDAPts(node2);
289
290 return _pta->alias(node1,node2);
291}
bool isValidTopLevelPtr(const SVFVar *node)
Definition SVFIR.cpp:765
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Definition SVFIR.h:133
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:118

◆ collectCxtInsenEdgeForRecur()

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

Mark insensitive edge for function recursions

Definition at line 195 of file DDAPass.cpp.

196{
197
198 for (SVFG::SVFGNodeIDToNodeMapTy::const_iterator it = svfg->begin(),eit = svfg->end(); it != eit; ++it)
199 {
200
201 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeIt = it->second->InEdgeBegin();
202 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeEit = it->second->InEdgeEnd();
203 for (; edgeIt != edgeEit; ++edgeIt)
204 {
205 const SVFGEdge* edge = *edgeIt;
206 if(edge->isCallVFGEdge() || edge->isRetVFGEdge())
207 {
208 if(edgeInCallGraphSCC(pta,edge))
209 insensitveEdges.insert(edge);
210 }
211 }
212 }
213}
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:177
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 218 of file DDAPass.cpp.

219{
220
222
223 for (SVFG::SVFGNodeIDToNodeMapTy::const_iterator it = svfg->begin(),eit = svfg->end(); it != eit; ++it)
224 {
225
226 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeIt = it->second->InEdgeBegin();
227 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeEit = it->second->InEdgeEnd();
228 for (; edgeIt != edgeEit; ++edgeIt)
229 {
230 const SVFGEdge* edge = *edgeIt;
231 if(edge->isCallVFGEdge() || edge->isRetVFGEdge())
232 {
233 if(this->edgeInSVFGSCC(svfgSCC,edge))
234 {
235
236 const FunObjVar* srcFun = edge->getSrcNode()->getICFGNode()->getFun();
237 const FunObjVar* dstFun = edge->getDstNode()->getICFGNode()->getFun();
238
239 if(srcFun && dstFun)
240 {
243 insensitvefunPairs.insert(std::make_pair(src,dst));
244 insensitvefunPairs.insert(std::make_pair(dst,src));
245 }
246 else
247 assert(edge->isRetVFGEdge() == false && "should not be an inter-procedural return edge" );
248 }
249 }
250 }
251 }
252
253 for(SVFG::SVFGNodeIDToNodeMapTy::const_iterator it = svfg->begin(),eit = svfg->end(); it != eit; ++it)
254 {
255 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeIt = it->second->InEdgeBegin();
256 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeEit = it->second->InEdgeEnd();
257 for (; edgeIt != edgeEit; ++edgeIt)
258 {
259 const SVFGEdge* edge = *edgeIt;
260
261 if(edge->isCallVFGEdge() || edge->isRetVFGEdge())
262 {
263 const FunObjVar* srcFun = edge->getSrcNode()->getICFGNode()->getFun();
264 const FunObjVar* dstFun = edge->getDstNode()->getICFGNode()->getFun();
265
266 if(srcFun && dstFun)
267 {
270 if(insensitvefunPairs.find(std::make_pair(src,dst))!=insensitvefunPairs.end())
271 insensitveEdges.insert(edge);
272 else if(insensitvefunPairs.find(std::make_pair(dst,src))!=insensitvefunPairs.end())
273 insensitveEdges.insert(edge);
274 }
275 }
276 }
277 }
278}
const ICFGNode * getICFGNode() const
Get the ICFGNode related to the creation of this object.
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
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:169
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:74
CallGraph * getCallGraph() const
Return call graph.
NodeID getId() const
Get ID.
Definition SVFValue.h:161
u32_t NodeID
Definition GeneralType.h:56

◆ 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 177 of file DDAPass.cpp.

178{
179 const FunObjVar* srcFun = edge->getSrcNode()->getICFGNode()->getFun();
180 const FunObjVar* dstFun = edge->getDstNode()->getICFGNode()->getFun();
181
182 if(srcFun && dstFun)
183 {
184 return pta->inSameCallGraphSCC(srcFun,dstFun);
185 }
186
187 assert(edge->isRetVFGEdge() == false && "should not be an inter-procedural return edge" );
188
189 return false;
190}
bool inSameCallGraphSCC(const FunObjVar *fun1, const FunObjVar *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 169 of file DDAPass.cpp.

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

◆ getPassName()

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

Pass name.

Definition at line 75 of file DDAPass.h.

76 {
77 return "DDAPass";
78 }

◆ 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 158 of file DDAPass.cpp.

159{
161 collectCxtInsenEdgeForRecur(pta,svfg,insensitveEdges);
162 else if(Options::InsenCycle())
163 collectCxtInsenEdgeForVFCycle(pta,svfg,svfgSCC,insensitveEdges);
164}
void collectCxtInsenEdgeForVFCycle(PointerAnalysis *pta, const SVFG *svfg, const SVFGSCC *svfgSCC, SVFGEdgeSet &insensitveEdges)
Definition DDAPass.cpp:218
void collectCxtInsenEdgeForRecur(PointerAnalysis *pta, const SVFG *svfg, SVFGEdgeSet &insensitveEdges)
Definition DDAPass.cpp:195
static const Option< bool > InsenCycle
Definition Options.h:86
static const Option< bool > InsenRecur
Definition Options.h:85

◆ printQueryPTS()

void DDAPass::printQueryPTS ( )
private

Print queries' pts.

Print queries' pts

Definition at line 297 of file DDAPass.cpp.

298{
299 const OrderedNodeSet& candidates = _client->getCandidateQueries();
300 for (OrderedNodeSet::const_iterator it = candidates.begin(), eit = candidates.end(); it != eit; ++it)
301 {
302 const PointsTo& pts = _pta->getPts(*it);
303 _pta->dumpPts(*it,pts);
304 }
305}
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
61
63 {
64 PTATY iPtTy = static_cast<PTATY>(i);
67 }
68}
unsigned u32_t
Definition CommandLine.h:18
virtual void selectClient()
Select a client.
Definition DDAPass.cpp:71
void runPointerAnalysis(SVFIR *module, u32_t kind)
Create pointer analysis according to specified kind and analyze the module.
Definition DDAPass.cpp:107
static OptionMultiple< PTATY > DDASelected
register this into alias analysis group
Definition Options.h:90
PTATY
Pointer analysis type list.
Definition PTATY.h:9
@ Default_PTA
default pta without any analysis
Definition PTATY.h:35
@ FlowS_DDA
Flow sensitive DDA.
Definition PTATY.h:30

◆ 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 107 of file DDAPass.cpp.

108{
109
112
114 switch (kind)
115 {
116 case PTATY::Cxt_DDA:
117 {
118 _pta = std::make_unique<ContextDDA>(pag, _client);
119 break;
120 }
121 case PTATY::FlowS_DDA:
122 {
123 _pta = std::make_unique<FlowDDA>(pag, _client);
124 break;
125 }
126 default:
127 outs() << "This pointer analysis has not been implemented yet.\n";
128 break;
129 }
130
131 if(Options::WPANum())
132 {
134 }
135 else
136 {
138 _pta->initialize();
140 _client->answerQueries(_pta.get());
142 _pta->finalize();
144 _pta->dumpCPts();
145
146 if (_pta->printStat())
147 _client->performStat(_pta.get());
148
151 }
152}
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()
Definition DDAClient.h:99
virtual void performStat(PointerAnalysis *)
Definition DDAClient.h:97
void printQueryPTS()
Print queries' pts.
Definition DDAPass.cpp:297
static const Option< u32_t > MaxContextLen
Definition Options.h:82
static const Option< u32_t > MaxPathLen
Definition Options.h:81
static const Option< bool > WPANum
Definition Options.h:89
static const Option< bool > PrintCPts
Definition Options.h:87
static const Option< bool > PrintQueryPts
Definition Options.h:88
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52
@ Cxt_DDA
context sensitive DDA
Definition PTATY.h:32

◆ selectClient()

void DDAPass::selectClient ( )
virtual

Select a client.

select a client to initialize queries

solve function pointer

allow user specify queries

Definition at line 71 of file DDAPass.cpp.

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

Member Data Documentation

◆ _client

DDAClient* SVF::DDAPass::_client
private

DDA client used.

Definition at line 96 of file DDAPass.h.

◆ _pta

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

pointer analysis to be executed.

Definition at line 95 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: