Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::ICFG Class Reference

#include <ICFG.h>

Inheritance diagram for SVF::ICFG:
SVF::GenericGraph< ICFGNode, ICFGEdge >

Public Types

typedef OrderedMap< NodeID, ICFGNode * > ICFGNodeIDToNodeMapTy
typedef ICFGEdge::ICFGEdgeSetTy ICFGEdgeSetTy
typedef ICFGNodeIDToNodeMapTy::iterator iterator
typedef ICFGNodeIDToNodeMapTy::const_iterator const_iterator
typedef Map< const FunObjVar *, FunEntryICFGNode * > FunToFunEntryNodeMapTy
typedef Map< const FunObjVar *, FunExitICFGNode * > FunToFunExitNodeMapTy
typedef std::vector< const SVFLoop * > SVFLoopVec
typedef Map< const ICFGNode *, SVFLoopVec > ICFGNodeToSVFLoopVec
Public Types inherited from SVF::GenericGraph< ICFGNode, ICFGEdge >
typedef ICFGNode NodeType
typedef ICFGEdge EdgeType
typedef OrderedMap< NodeID, NodeType * > IDToNodeMapTy
 NodeID to GenericNode map.
typedef IDToNodeMapTy::iterator iterator
 Node Iterators.
typedef IDToNodeMapTy::const_iterator const_iterator

Public Member Functions

 ICFG ()
 Constructor.
 ~ICFG () override
 Destructor.
ICFGNode * getICFGNode (NodeID id) const
 Get a ICFG node.
bool hasICFGNode (NodeID id) const
 Whether has the ICFGNode.
ICFGEdge * hasIntraICFGEdge (ICFGNode *src, ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
 Whether we has a SVFG edge.
ICFGEdge * hasInterICFGEdge (ICFGNode *src, ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
ICFGEdge * hasThreadICFGEdge (ICFGNode *src, ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
ICFGEdge * getICFGEdge (const ICFGNode *src, const ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
 Get a SVFG edge according to src and dst.
void dump (const std::string &file, bool simple=false)
 Dump graph into dot file.
void view ()
 View graph from the debugger.
void updateCallGraph (CallGraph *callgraph)
 update ICFG for indirect calls
bool isInLoop (const ICFGNode *node)
 Whether node is in a loop.
void addNodeToSVFLoop (const ICFGNode *node, const SVFLoop *loop)
 Insert (node, loop) to icfgNodeToSVFLoopVec.
SVFLoopVec & getSVFLoops (const ICFGNode *node)
 Get loops where a node resides.
const ICFGNodeToSVFLoopVec & getIcfgNodeToSVFLoopVec () const
FunEntryICFGNode * getFunEntryICFGNode (const FunObjVar *fun)
 Add a function entry node.
FunExitICFGNode * getFunExitICFGNode (const FunObjVar *fun)
 Add a function exit node.
GlobalICFGNode * getGlobalICFGNode () const
Public Member Functions inherited from SVF::GenericGraph< ICFGNode, ICFGEdge >
 GenericGraph ()
 Constructor.
virtual ~GenericGraph ()
 Destructor.
void destroy ()
 Release memory.
iterator begin ()
 Iterators.
iterator end ()
const_iterator begin () const
const_iterator end () const
void addGNode (NodeID id, NodeType *node)
 Add a Node.
NodeType * getGNode (NodeID id) const
 Get a node.
bool hasGNode (NodeID id) const
 Has a node.
void removeGNode (NodeType *node)
 Delete a node.
u32_t getTotalNodeNum () const
 Get total number of node/edge.
u32_t getTotalEdgeNum () const
void incNodeNum ()
 Increase number of node/edge.
void incEdgeNum ()

Public Attributes

NodeID totalICFGNode
Public Attributes inherited from SVF::GenericGraph< ICFGNode, ICFGEdge >
u32_t edgeNum
 total num of node
u32_t nodeNum
 total num of edge

Protected Member Functions

ICFGEdge * addIntraEdge (ICFGNode *srcNode, ICFGNode *dstNode)
 Add intraprocedural and interprocedural control-flow edges.
ICFGEdge * addConditionalIntraEdge (ICFGNode *srcNode, ICFGNode *dstNode, s64_t branchCondVal)
ICFGEdge * addCallEdge (ICFGNode *srcNode, ICFGNode *dstNode)
ICFGEdge * addRetEdge (ICFGNode *srcNode, ICFGNode *dstNode)
void removeICFGEdge (ICFGEdge *edge)
 Remove a ICFG edge.
void removeICFGNode (ICFGNode *node)
 Remove a ICFGNode.
void checkIntraEdgeParents (const ICFGNode *srcNode, const ICFGNode *dstNode)
 sanitize Intra edges, verify that both nodes belong to the same function.
virtual IntraICFGNode * addIntraICFGNode (const SVFBasicBlock *bb, bool isRet)
virtual CallICFGNode * addCallICFGNode (const SVFBasicBlock *bb, const SVFType *ty, const FunObjVar *calledFunc, bool isVararg, bool isvcall, s32_t vcallIdx, const std::string &funNameOfVcall)
virtual RetICFGNode * addRetICFGNode (CallICFGNode *call)
virtual FunEntryICFGNode * addFunEntryICFGNode (const FunObjVar *svfFunc)
virtual FunEntryICFGNode * addFunEntryICFGNode (FunEntryICFGNode *funEntryICFGNode)
virtual void addGlobalICFGNode (GlobalICFGNode *globalICFGNode)
virtual FunExitICFGNode * addFunExitICFGNode (const FunObjVar *svfFunc)
virtual FunExitICFGNode * addFunExitICFGNode (FunExitICFGNode *funExitICFGNode)
virtual void addICFGNode (ICFGNode *node)
 Add a ICFG node.

Private Member Functions

bool addICFGEdge (ICFGEdge *edge)
 Add ICFG edge, only used by addIntraEdge, addCallEdge, addRetEdge etc.
FunEntryICFGNode * getFunEntryBlock (const FunObjVar *fun)
 Get/Add a function entry node.
FunExitICFGNode * getFunExitBlock (const FunObjVar *fun)
 Get/Add a function exit node.

Private Attributes

FunToFunEntryNodeMapTy FunToFunEntryNodeMap
 map a function to its FunExitICFGNode
FunToFunExitNodeMapTy FunToFunExitNodeMap
 map a function to its FunEntryICFGNode
GlobalICFGNode * globalBlockNode
 unique basic block for all globals
ICFGNodeToSVFLoopVec icfgNodeToSVFLoopVec
 map ICFG node to the SVF loops where it resides

Friends

class ICFGBuilder
class ICFGSimplification
class GraphDBClient

Additional Inherited Members

Protected Attributes inherited from SVF::GenericGraph< ICFGNode, ICFGEdge >
IDToNodeMapTy IDToNodeMap
 node map

Detailed Description

Definition at line 48 of file ICFG.h.

Member Typedef Documentation

◆ const_iterator

typedef ICFGNodeIDToNodeMapTy::const_iterator SVF::ICFG::const_iterator

Definition at line 59 of file ICFG.h.

◆ FunToFunEntryNodeMapTy

Definition at line 61 of file ICFG.h.

◆ FunToFunExitNodeMapTy

Definition at line 62 of file ICFG.h.

◆ ICFGEdgeSetTy

Definition at line 57 of file ICFG.h.

◆ ICFGNodeIDToNodeMapTy

Definition at line 56 of file ICFG.h.

◆ ICFGNodeToSVFLoopVec

Definition at line 64 of file ICFG.h.

◆ iterator

typedef ICFGNodeIDToNodeMapTy::iterator SVF::ICFG::iterator

Definition at line 58 of file ICFG.h.

◆ SVFLoopVec

typedef std::vector<const SVFLoop *> SVF::ICFG::SVFLoopVec

Definition at line 63 of file ICFG.h.

Constructor & Destructor Documentation

◆ ICFG()

ICFG::ICFG ( )

Constructor.

Constructor

  • Build ICFG 1) build ICFG nodes statements for top level pointers (PAGEdges) 2) connect ICFG edges between two statements (PAGEdges)

Definition at line 208 of file ICFG.cpp.

208 : totalICFGNode(0), globalBlockNode(nullptr)
209{
210}
NodeID totalICFGNode
Definition ICFG.h:66
GlobalICFGNode * globalBlockNode
unique basic block for all globals
Definition ICFG.h:71

◆ ~ICFG()

ICFG::~ICFG ( )
override

Destructor.

Definition at line 212 of file ICFG.cpp.

213{
215 for (const auto &it: icfgNodeToSVFLoopVec)
216 {
217 for (const auto &loop: it.second)
218 {
219 loops.insert(loop);
220 }
221 }
222
223 for (const auto &it: loops)
224 {
225 delete it;
226 }
227 icfgNodeToSVFLoopVec.clear();
228}
ICFGNodeToSVFLoopVec icfgNodeToSVFLoopVec
map ICFG node to the SVF loops where it resides
Definition ICFG.h:72
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition GeneralType.h:51

Member Function Documentation

◆ addCallEdge()

ICFGEdge * ICFG::addCallEdge ( ICFGNode * srcNode,
ICFGNode * dstNode )
protected

Add interprocedural call edges between two nodes

Definition at line 375 of file ICFG.cpp.

376{
377 ICFGEdge* edge = hasInterICFGEdge(srcNode,dstNode, ICFGEdge::CallCF);
378 if (edge != nullptr)
379 {
380 assert(edge->isCallCFGEdge() && "this should be a call CFG edge!");
381 return nullptr;
382 }
383 else
384 {
385 CallCFGEdge* callEdge = new CallCFGEdge(srcNode,dstNode);
386 return (addICFGEdge(callEdge) ? callEdge : nullptr);
387 }
388}
bool isCallCFGEdge() const
Definition ICFGEdge.h:75
bool addICFGEdge(ICFGEdge *edge)
Add ICFG edge, only used by addIntraEdge, addCallEdge, addRetEdge etc.
Definition ICFG.h:252
ICFGEdge * hasInterICFGEdge(ICFGNode *src, ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
Definition ICFG.cpp:277

◆ addCallICFGNode()

virtual CallICFGNode * SVF::ICFG::addCallICFGNode ( const SVFBasicBlock * bb,
const SVFType * ty,
const FunObjVar * calledFunc,
bool isVararg,
bool isvcall,
s32_t vcallIdx,
const std::string & funNameOfVcall )
inlineprotectedvirtual

Definition at line 179 of file ICFG.h.

183 {
184
185 CallICFGNode* callICFGNode =
186 new CallICFGNode(totalICFGNode++, bb, ty, calledFunc, isVararg,
187 isvcall, vcallIdx, funNameOfVcall);
188 addICFGNode(callICFGNode);
189 return callICFGNode;
190 }
virtual void addICFGNode(ICFGNode *node)
Add a ICFG node.
Definition ICFG.cpp:230

◆ addConditionalIntraEdge()

ICFGEdge * ICFG::addConditionalIntraEdge ( ICFGNode * srcNode,
ICFGNode * dstNode,
s64_t branchCondVal )
protected

Add conditional intraprocedural edges between two nodes

Definition at line 353 of file ICFG.cpp.

354{
355
356 checkIntraEdgeParents(srcNode, dstNode);
357 ICFGEdge* edge = hasIntraICFGEdge(srcNode, dstNode, ICFGEdge::IntraCF);
358 if (edge != nullptr)
359 {
360 assert(edge->isIntraCFGEdge() && "this should be an intra CFG edge!");
361 return nullptr;
362 }
363 else
364 {
365 IntraCFGEdge* intraEdge = new IntraCFGEdge(srcNode,dstNode);
366 intraEdge->setBranchCondVal(branchCondVal);
367 return (addICFGEdge(intraEdge) ? intraEdge : nullptr);
368 }
369}
bool isIntraCFGEdge() const
Definition ICFGEdge.h:83
void checkIntraEdgeParents(const ICFGNode *srcNode, const ICFGNode *dstNode)
sanitize Intra edges, verify that both nodes belong to the same function.
Definition ICFG.h:161
ICFGEdge * hasIntraICFGEdge(ICFGNode *src, ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
Whether we has a SVFG edge.
Definition ICFG.cpp:260
void setBranchCondVal(s64_t bVal)
Definition ICFGEdge.h:170

◆ addFunEntryICFGNode() [1/2]

virtual FunEntryICFGNode * SVF::ICFG::addFunEntryICFGNode ( const FunObjVar * svfFunc)
inlineprotectedvirtual

Definition at line 200 of file ICFG.h.

201 {
202 FunEntryICFGNode* sNode = new FunEntryICFGNode(totalICFGNode++,svfFunc);
203 return addFunEntryICFGNode(sNode);
204 }
virtual FunEntryICFGNode * addFunEntryICFGNode(const FunObjVar *svfFunc)
Definition ICFG.h:200

◆ addFunEntryICFGNode() [2/2]

virtual FunEntryICFGNode * SVF::ICFG::addFunEntryICFGNode ( FunEntryICFGNode * funEntryICFGNode)
inlineprotectedvirtual

Definition at line 206 of file ICFG.h.

207 {
208 addICFGNode(funEntryICFGNode);
209 return FunToFunEntryNodeMap[funEntryICFGNode->getFun()] = funEntryICFGNode;
210 }
FunToFunEntryNodeMapTy FunToFunEntryNodeMap
map a function to its FunExitICFGNode
Definition ICFG.h:69

◆ addFunExitICFGNode() [1/2]

virtual FunExitICFGNode * SVF::ICFG::addFunExitICFGNode ( const FunObjVar * svfFunc)
inlineprotectedvirtual

Definition at line 214 of file ICFG.h.

215 {
216 const SVFBasicBlock* bb = nullptr;
217 if (svfFunc->begin() != svfFunc->end())
218 {
219 bb = svfFunc->getExitBB();
220 }
221 FunExitICFGNode* sNode = new FunExitICFGNode(totalICFGNode++, svfFunc, bb);
222 return addFunExitICFGNode(sNode);
223 }
virtual FunExitICFGNode * addFunExitICFGNode(const FunObjVar *svfFunc)
Definition ICFG.h:214

◆ addFunExitICFGNode() [2/2]

virtual FunExitICFGNode * SVF::ICFG::addFunExitICFGNode ( FunExitICFGNode * funExitICFGNode)
inlineprotectedvirtual

Definition at line 225 of file ICFG.h.

226 {
227 addICFGNode(funExitICFGNode);
228 return FunToFunExitNodeMap[funExitICFGNode->getFun()] = funExitICFGNode;
229 }
FunToFunExitNodeMapTy FunToFunExitNodeMap
map a function to its FunEntryICFGNode
Definition ICFG.h:70

◆ addGlobalICFGNode()

void ICFG::addGlobalICFGNode ( GlobalICFGNode * globalICFGNode)
protectedvirtual

Definition at line 235 of file ICFG.cpp.

236{
237 this->globalBlockNode = globalICFGNode;
238 addICFGNode(globalICFGNode);
239}

◆ addICFGEdge()

bool SVF::ICFG::addICFGEdge ( ICFGEdge * edge)
inlineprivate

Add ICFG edge, only used by addIntraEdge, addCallEdge, addRetEdge etc.

Definition at line 252 of file ICFG.h.

253 {
254 bool added1 = edge->getDstNode()->addIncomingEdge(edge);
255 bool added2 = edge->getSrcNode()->addOutgoingEdge(edge);
256 bool all_added = added1 && added2;
257 assert(all_added && "ICFGEdge not added?");
258 return all_added;
259 }

◆ addICFGNode()

void ICFG::addICFGNode ( ICFGNode * node)
protectedvirtual

Add a ICFG node.

Definition at line 230 of file ICFG.cpp.

231{
232 addGNode(node->getId(),node);
233}
void addGNode(NodeID id, NodeType *node)
NodeID getId() const
Get ID.
Definition SVFValue.h:158

◆ addIntraEdge()

ICFGEdge * ICFG::addIntraEdge ( ICFGNode * srcNode,
ICFGNode * dstNode )
protected

Add intraprocedural and interprocedural control-flow edges.

Add intraprocedural edges between two nodes

Definition at line 334 of file ICFG.cpp.

335{
336 checkIntraEdgeParents(srcNode, dstNode);
337 ICFGEdge* edge = hasIntraICFGEdge(srcNode, dstNode, ICFGEdge::IntraCF);
338 if (edge != nullptr)
339 {
340 assert(edge->isIntraCFGEdge() && "this should be an intra CFG edge!");
341 return nullptr;
342 }
343 else
344 {
345 IntraCFGEdge* intraEdge = new IntraCFGEdge(srcNode,dstNode);
346 return (addICFGEdge(intraEdge) ? intraEdge : nullptr);
347 }
348}

◆ addIntraICFGNode()

virtual IntraICFGNode * SVF::ICFG::addIntraICFGNode ( const SVFBasicBlock * bb,
bool isRet )
inlineprotectedvirtual

Definition at line 171 of file ICFG.h.

172 {
173 IntraICFGNode* intraIcfgNode =
174 new IntraICFGNode(totalICFGNode++, bb, isRet);
175 addICFGNode(intraIcfgNode);
176 return intraIcfgNode;
177 }

◆ addNodeToSVFLoop()

void SVF::ICFG::addNodeToSVFLoop ( const ICFGNode * node,
const SVFLoop * loop )
inline

Insert (node, loop) to icfgNodeToSVFLoopVec.

Definition at line 120 of file ICFG.h.

121 {
122 icfgNodeToSVFLoopVec[node].push_back(loop);
123 }

◆ addRetEdge()

ICFGEdge * ICFG::addRetEdge ( ICFGNode * srcNode,
ICFGNode * dstNode )
protected

Add interprocedural return edges between two nodes

Definition at line 393 of file ICFG.cpp.

394{
395 ICFGEdge* edge = hasInterICFGEdge(srcNode, dstNode, ICFGEdge::RetCF);
396 if (edge != nullptr)
397 {
398 assert(edge->isRetCFGEdge() && "this should be a return CFG edge!");
399 return nullptr;
400 }
401 else
402 {
403 RetCFGEdge* retEdge = new RetCFGEdge(srcNode,dstNode);
404 return (addICFGEdge(retEdge) ? retEdge : nullptr);
405 }
406}
bool isRetCFGEdge() const
Definition ICFGEdge.h:79

◆ addRetICFGNode()

virtual RetICFGNode * SVF::ICFG::addRetICFGNode ( CallICFGNode * call)
inlineprotectedvirtual

Definition at line 192 of file ICFG.h.

193 {
194 RetICFGNode* retICFGNode = new RetICFGNode(totalICFGNode++, call);
195 call->setRetICFGNode(retICFGNode);
196 addICFGNode(retICFGNode);
197 return retICFGNode;
198 }

◆ checkIntraEdgeParents()

void SVF::ICFG::checkIntraEdgeParents ( const ICFGNode * srcNode,
const ICFGNode * dstNode )
inlineprotected

sanitize Intra edges, verify that both nodes belong to the same function.

Definition at line 161 of file ICFG.h.

162 {
163 const FunObjVar* srcfun = srcNode->getFun();
164 const FunObjVar* dstfun = dstNode->getFun();
165 if(srcfun != nullptr && dstfun != nullptr)
166 {
167 assert((srcfun == dstfun) && "src and dst nodes of an intra edge should in the same function!" );
168 }
169 }

◆ dump()

void ICFG::dump ( const std::string & file,
bool simple = false )

Dump graph into dot file.

Dump ICFG

Definition at line 412 of file ICFG.cpp.

413{
414 GraphPrinter::WriteGraphToFile(outs(), file, this, simple);
415}
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)
std::ostream & outs()
Overwrite llvm::outs().
Definition SVFUtil.h:58

◆ getFunEntryBlock()

FunEntryICFGNode * SVF::ICFG::getFunEntryBlock ( const FunObjVar * fun)
inlineprivate

Get/Add a function entry node.

Definition at line 262 of file ICFG.h.

263 {
264 FunToFunEntryNodeMapTy::const_iterator it = FunToFunEntryNodeMap.find(fun);
265 if (it == FunToFunEntryNodeMap.end())
266 return nullptr;
267 return it->second;
268 }

◆ getFunEntryICFGNode()

FunEntryICFGNode * ICFG::getFunEntryICFGNode ( const FunObjVar * fun)

Add a function entry node.

Get a basic block ICFGNode TODO:: need to fix the assertions

Definition at line 243 of file ICFG.cpp.

244{
245 FunEntryICFGNode* entry = getFunEntryBlock(fun);
246 assert (entry && "fun entry not created in ICFGBuilder?");
247 return entry;
248}
FunEntryICFGNode * getFunEntryBlock(const FunObjVar *fun)
Get/Add a function entry node.
Definition ICFG.h:262

◆ getFunExitBlock()

FunExitICFGNode * SVF::ICFG::getFunExitBlock ( const FunObjVar * fun)
inlineprivate

Get/Add a function exit node.

Definition at line 271 of file ICFG.h.

272 {
273 FunToFunExitNodeMapTy::const_iterator it = FunToFunExitNodeMap.find(fun);
274 if (it == FunToFunExitNodeMap.end())
275 return nullptr;
276 return it->second;
277 }

◆ getFunExitICFGNode()

FunExitICFGNode * ICFG::getFunExitICFGNode ( const FunObjVar * fun)

Add a function exit node.

Definition at line 250 of file ICFG.cpp.

251{
252 FunExitICFGNode* exit = getFunExitBlock(fun);
253 assert (exit && "fun exit not created in ICFGBuilder?");
254 return exit;
255}
FunExitICFGNode * getFunExitBlock(const FunObjVar *fun)
Get/Add a function exit node.
Definition ICFG.h:271

◆ getGlobalICFGNode()

GlobalICFGNode * SVF::ICFG::getGlobalICFGNode ( ) const
inline

Definition at line 244 of file ICFG.h.

245 {
246 return globalBlockNode;
247 }

◆ getICFGEdge()

ICFGEdge * ICFG::getICFGEdge ( const ICFGNode * src,
const ICFGNode * dst,
ICFGEdge::ICFGEdgeK kind )

Get a SVFG edge according to src and dst.

Return the corresponding ICFGEdge

Definition at line 312 of file ICFG.cpp.

313{
314
315 ICFGEdge * edge = nullptr;
316 u32_t counter = 0;
317 for (ICFGEdge::ICFGEdgeSetTy::iterator iter = src->OutEdgeBegin();
318 iter != src->OutEdgeEnd(); ++iter)
319 {
320 if ((*iter)->getDstID() == dst->getId() && (*iter)->getEdgeKind() == kind)
321 {
322 counter++;
323 edge = (*iter);
324 }
325 }
326 assert(counter <= 1 && "there's more than one edge between two ICFG nodes");
327 return edge;
328
329}
iterator OutEdgeEnd()
iterator OutEdgeBegin()
iterators
unsigned u32_t
Definition GeneralType.h:67

◆ getICFGNode()

ICFGNode * SVF::ICFG::getICFGNode ( NodeID id) const
inline

Get a ICFG node.

Definition at line 82 of file ICFG.h.

83 {
84 return getGNode(id);
85 }
NodeType * getGNode(NodeID id) const

◆ getIcfgNodeToSVFLoopVec()

const ICFGNodeToSVFLoopVec & SVF::ICFG::getIcfgNodeToSVFLoopVec ( ) const
inline

Definition at line 133 of file ICFG.h.

134 {
136 }

◆ getSVFLoops()

SVFLoopVec & SVF::ICFG::getSVFLoops ( const ICFGNode * node)
inline

Get loops where a node resides.

Definition at line 126 of file ICFG.h.

127 {
128 auto it = icfgNodeToSVFLoopVec.find(node);
129 assert(it != icfgNodeToSVFLoopVec.end() && "node not in loop");
130 return it->second;
131 }

◆ hasICFGNode()

bool SVF::ICFG::hasICFGNode ( NodeID id) const
inline

Whether has the ICFGNode.

Definition at line 88 of file ICFG.h.

89 {
90 return hasGNode(id);
91 }

◆ hasInterICFGEdge()

ICFGEdge * ICFG::hasInterICFGEdge ( ICFGNode * src,
ICFGNode * dst,
ICFGEdge::ICFGEdgeK kind )

Whether we has an inter ICFG edge

Definition at line 277 of file ICFG.cpp.

278{
279 ICFGEdge edge(src,dst, kind);
280 ICFGEdge* outEdge = src->hasOutgoingEdge(&edge);
281 ICFGEdge* inEdge = dst->hasIncomingEdge(&edge);
282 if (outEdge && inEdge)
283 {
284 assert(outEdge == inEdge && "edges not match");
285 return outEdge;
286 }
287 else
288 return nullptr;
289}
bool hasIncomingEdge() const
Has incoming/outgoing edge set.
bool hasOutgoingEdge() const

◆ hasIntraICFGEdge()

ICFGEdge * ICFG::hasIntraICFGEdge ( ICFGNode * src,
ICFGNode * dst,
ICFGEdge::ICFGEdgeK kind )

Whether we has a SVFG edge.

Whether we has an intra ICFG edge

Definition at line 260 of file ICFG.cpp.

261{
262 ICFGEdge edge(src,dst,kind);
263 ICFGEdge* outEdge = src->hasOutgoingEdge(&edge);
264 ICFGEdge* inEdge = dst->hasIncomingEdge(&edge);
265 if (outEdge && inEdge)
266 {
267 assert(outEdge == inEdge && "edges not match");
268 return outEdge;
269 }
270 else
271 return nullptr;
272}

◆ hasThreadICFGEdge()

ICFGEdge * ICFG::hasThreadICFGEdge ( ICFGNode * src,
ICFGNode * dst,
ICFGEdge::ICFGEdgeK kind )

Whether we has an thread ICFG edge

Definition at line 294 of file ICFG.cpp.

295{
296 ICFGEdge edge(src,dst,kind);
297 ICFGEdge* outEdge = src->hasOutgoingEdge(&edge);
298 ICFGEdge* inEdge = dst->hasIncomingEdge(&edge);
299 if (outEdge && inEdge)
300 {
301 assert(outEdge == inEdge && "edges not match");
302 return outEdge;
303 }
304 else
305 return nullptr;
306}

◆ isInLoop()

bool SVF::ICFG::isInLoop ( const ICFGNode * node)
inline

Whether node is in a loop.

Definition at line 113 of file ICFG.h.

114 {
115 auto it = icfgNodeToSVFLoopVec.find(node);
116 return it != icfgNodeToSVFLoopVec.end();
117 }

◆ removeICFGEdge()

void SVF::ICFG::removeICFGEdge ( ICFGEdge * edge)
inlineprotected

Remove a ICFG edge.

Definition at line 147 of file ICFG.h.

148 {
149 edge->getDstNode()->removeIncomingEdge(edge);
150 edge->getSrcNode()->removeOutgoingEdge(edge);
151 delete edge;
152 }

◆ removeICFGNode()

void SVF::ICFG::removeICFGNode ( ICFGNode * node)
inlineprotected

Remove a ICFGNode.

Definition at line 155 of file ICFG.h.

156 {
157 removeGNode(node);
158 }

◆ updateCallGraph()

void ICFG::updateCallGraph ( CallGraph * callgraph)

update ICFG for indirect calls

Update ICFG for indirect calls

if this is an external function (no function body), connect calleeEntryNode to calleeExitNode

Remove callBlockNode to retBlockNode intraICFGEdge since we found at least one inter procedural edge

Definition at line 428 of file ICFG.cpp.

429{
430 CallGraph::CallEdgeMap::const_iterator iter = callgraph->getIndCallMap().begin();
431 CallGraph::CallEdgeMap::const_iterator eiter = callgraph->getIndCallMap().end();
432 for (; iter != eiter; iter++)
433 {
434 CallICFGNode* callBlockNode = const_cast<CallICFGNode*>(iter->first);
435 assert(callBlockNode->isIndirectCall() && "this is not an indirect call?");
436 const CallGraph::FunctionSet & functions = iter->second;
437 for (CallGraph::FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++)
438 {
439 const FunObjVar* callee = *func_iter;
440 RetICFGNode* retBlockNode = const_cast<RetICFGNode*>(callBlockNode->getRetICFGNode());
442 if (isExtCall(callee))
443 addIntraEdge(callBlockNode, retBlockNode);
444 else
445 {
446 FunEntryICFGNode* calleeEntryNode = getFunEntryBlock(callee);
447 FunExitICFGNode* calleeExitNode = getFunExitBlock(callee);
448 addCallEdge(callBlockNode, calleeEntryNode);
449 if(ICFGEdge* retEdge = addRetEdge(calleeExitNode, retBlockNode))
450 {
451 for (const SVFStmt *stmt : retBlockNode->getSVFStmts())
452 {
453 if(const RetPE *retPE = SVFUtil::dyn_cast<RetPE>(stmt))
454 {
455 if(retPE->getFunExitICFGNode() == calleeExitNode)
456 SVFUtil::cast<RetCFGEdge>(retEdge)->addRetPE(retPE);
457 }
458 }
459 }
460
462 if(ICFGEdge* edge = hasIntraICFGEdge(callBlockNode,retBlockNode, ICFGEdge::IntraCF))
463 removeICFGEdge(edge);
464 }
465
466 }
467 }
468 // dump ICFG
469 if (Options::DumpICFG())
470 {
471 dump("icfg_final");
472 }
473}
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
Definition CallGraph.h:331
Set< const FunObjVar * > FunctionSet
Definition CallGraph.h:247
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition ICFGNode.h:440
bool isIndirectCall() const
Return true if this is an indirect call.
Definition ICFGNode.h:465
const SVFStmtList & getSVFStmts() const
Definition ICFGNode.h:116
void removeICFGEdge(ICFGEdge *edge)
Remove a ICFG edge.
Definition ICFG.h:147
ICFGEdge * addCallEdge(ICFGNode *srcNode, ICFGNode *dstNode)
Definition ICFG.cpp:375
void dump(const std::string &file, bool simple=false)
Dump graph into dot file.
Definition ICFG.cpp:412
ICFGEdge * addRetEdge(ICFGNode *srcNode, ICFGNode *dstNode)
Definition ICFG.cpp:393
ICFGEdge * addIntraEdge(ICFGNode *srcNode, ICFGNode *dstNode)
Add intraprocedural and interprocedural control-flow edges.
Definition ICFG.cpp:334
static const Option< bool > DumpICFG
Definition Options.h:121
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
Definition Casting.h:360
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:524
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition Casting.h:405

◆ view()

void ICFG::view ( )

View graph from the debugger.

View ICFG

Definition at line 420 of file ICFG.cpp.

421{
422 SVF::ViewGraph(this, "Interprocedural Control-Flow Graph");
423}
void ViewGraph(const GraphType &G, const std::string &name, bool ShortNames=false, GraphProgram::Name Program=GraphProgram::DOT)

◆ GraphDBClient

friend class GraphDBClient
friend

Definition at line 52 of file ICFG.h.

◆ ICFGBuilder

friend class ICFGBuilder
friend

Definition at line 50 of file ICFG.h.

◆ ICFGSimplification

friend class ICFGSimplification
friend

Definition at line 51 of file ICFG.h.

Member Data Documentation

◆ FunToFunEntryNodeMap

FunToFunEntryNodeMapTy SVF::ICFG::FunToFunEntryNodeMap
private

map a function to its FunExitICFGNode

Definition at line 69 of file ICFG.h.

◆ FunToFunExitNodeMap

FunToFunExitNodeMapTy SVF::ICFG::FunToFunExitNodeMap
private

map a function to its FunEntryICFGNode

Definition at line 70 of file ICFG.h.

◆ globalBlockNode

GlobalICFGNode* SVF::ICFG::globalBlockNode
private

unique basic block for all globals

Definition at line 71 of file ICFG.h.

◆ icfgNodeToSVFLoopVec

ICFGNodeToSVFLoopVec SVF::ICFG::icfgNodeToSVFLoopVec
private

map ICFG node to the SVF loops where it resides

Definition at line 72 of file ICFG.h.

◆ totalICFGNode

NodeID SVF::ICFG::totalICFGNode

Definition at line 66 of file ICFG.h.


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