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

#include <PTACallGraph.h>

Inheritance diagram for SVF::PTACallGraph:
SVF::GenericGraph< NodeTy, EdgeTy > SVF::ThreadCallGraph

Public Types

enum  CGEK { NormCallGraph , ThdCallGraph }
 
typedef PTACallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet
 
typedef Map< const SVFFunction *, PTACallGraphNode * > FunToCallGraphNodeMap
 
typedef Map< const CallICFGNode *, CallGraphEdgeSetCallInstToCallGraphEdgesMap
 
typedef std::pair< const CallICFGNode *, const SVFFunction * > CallSitePair
 
typedef Map< CallSitePair, CallSiteIDCallSiteToIdMap
 
typedef Map< CallSiteID, CallSitePairIdToCallSiteMap
 
typedef Set< const SVFFunction * > FunctionSet
 
typedef OrderedMap< const CallICFGNode *, FunctionSetCallEdgeMap
 
typedef CallGraphEdgeSet::iterator CallGraphEdgeIter
 
typedef CallGraphEdgeSet::const_iterator CallGraphEdgeConstIter
 
- Public Types inherited from SVF::GenericGraph< NodeTy, EdgeTy >
typedef NodeTy NodeType
 
typedef EdgeTy EdgeType
 
typedef OrderedMap< NodeID, NodeType * > IDToNodeMapTy
 NodeID to GenericNode map. More...
 
typedef IDToNodeMapTy::iterator iterator
 Node Iterators. More...
 
typedef IDToNodeMapTy::const_iterator const_iterator
 

Public Member Functions

 PTACallGraph (CGEK k=NormCallGraph)
 Constructor. More...
 
 PTACallGraph (const PTACallGraph &other)
 Copy constructor. More...
 
void addCallGraphNode (const SVFFunction *fun)
 
virtual ~PTACallGraph ()
 Destructor. More...
 
CGEK getKind () const
 Return type of this callgraph. More...
 
CallEdgeMapgetIndCallMap ()
 Get callees from an indirect callsite. More...
 
bool hasIndCSCallees (const CallICFGNode *cs) const
 
const FunctionSetgetIndCSCallees (const CallICFGNode *cs) const
 
u32_t getTotalCallSiteNumber () const
 
u32_t getNumOfResolvedIndCallEdge () const
 
const CallInstToCallGraphEdgesMapgetCallInstToCallGraphEdgesMap () const
 
void verifyCallGraph ()
 Issue a warning if the function which has indirect call sites can not be reached from program entry. More...
 
PTACallGraphNodegetCallGraphNode (NodeID id) const
 Get call graph node. More...
 
PTACallGraphNodegetCallGraphNode (const SVFFunction *fun) const
 
CallSiteID addCallSite (const CallICFGNode *cs, const SVFFunction *callee)
 Add/Get CallSiteID. More...
 
CallSiteID getCallSiteID (const CallICFGNode *cs, const SVFFunction *callee) const
 
bool hasCallSiteID (const CallICFGNode *cs, const SVFFunction *callee) const
 
const CallSitePairgetCallSitePair (CallSiteID id) const
 
const CallICFGNodegetCallSite (CallSiteID id) const
 
const SVFFunctiongetCallerOfCallSite (CallSiteID id) const
 
const SVFFunctiongetCalleeOfCallSite (CallSiteID id) const
 
PTACallGraphEdgehasGraphEdge (PTACallGraphNode *src, PTACallGraphNode *dst, PTACallGraphEdge::CEDGEK kind, CallSiteID csId) const
 Whether we have already created this call graph edge. More...
 
PTACallGraphEdgegetGraphEdge (PTACallGraphNode *src, PTACallGraphNode *dst, PTACallGraphEdge::CEDGEK kind, CallSiteID csId)
 Get call graph edge via nodes. More...
 
void getCallees (const CallICFGNode *cs, FunctionSet &callees)
 Get all callees for a callsite. More...
 
bool hasCallGraphEdge (const CallICFGNode *inst) const
 Get call graph edge via call instruction. More...
 
CallGraphEdgeSet::const_iterator getCallEdgeBegin (const CallICFGNode *inst) const
 
CallGraphEdgeSet::const_iterator getCallEdgeEnd (const CallICFGNode *inst) const
 
void addEdge (PTACallGraphEdge *edge)
 Add call graph edge. More...
 
void addDirectCallGraphEdge (const CallICFGNode *call, const SVFFunction *callerFun, const SVFFunction *calleeFun)
 Add direct/indirect call edges. More...
 
void addIndirectCallGraphEdge (const CallICFGNode *cs, const SVFFunction *callerFun, const SVFFunction *calleeFun)
 
void getAllCallSitesInvokingCallee (const SVFFunction *callee, PTACallGraphEdge::CallInstSet &csSet)
 Get callsites invoking the callee. More...
 
void getDirCallSitesInvokingCallee (const SVFFunction *callee, PTACallGraphEdge::CallInstSet &csSet)
 
void getIndCallSitesInvokingCallee (const SVFFunction *callee, PTACallGraphEdge::CallInstSet &csSet)
 
bool isReachableBetweenFunctions (const SVFFunction *srcFn, const SVFFunction *dstFn) const
 Whether its reachable between two functions. More...
 
void dump (const std::string &filename)
 Dump the graph. More...
 
void view ()
 View the graph from the debugger. More...
 
- Public Member Functions inherited from SVF::GenericGraph< NodeTy, EdgeTy >
 GenericGraph ()
 Constructor. More...
 
virtual ~GenericGraph ()
 Destructor. More...
 
void destroy ()
 Release memory. More...
 
iterator begin ()
 Iterators. More...
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
void addGNode (NodeID id, NodeType *node)
 Add a Node. More...
 
NodeTypegetGNode (NodeID id) const
 Get a node. More...
 
bool hasGNode (NodeID id) const
 Has a node. More...
 
void removeGNode (NodeType *node)
 Delete a node. More...
 
u32_t getTotalNodeNum () const
 Get total number of node/edge. More...
 
u32_t getTotalEdgeNum () const
 
void incNodeNum ()
 Increase number of node/edge. More...
 
void incEdgeNum ()
 

Protected Member Functions

void destroy ()
 Clean up memory. More...
 

Protected Attributes

FunToCallGraphNodeMap funToCallGraphNodeMap
 Call Graph node map. More...
 
CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap
 Map a call instruction to its corresponding call edges. More...
 
NodeID callGraphNodeNum
 
u32_t numOfResolvedIndCallEdge
 
CGEK kind
 
- Protected Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
IDToNodeMapTy IDToNodeMap
 node map More...
 

Private Attributes

CallEdgeMap indirectCallMap
 Indirect call map. More...
 

Static Private Attributes

static CallSiteToIdMap csToIdMap
 Call site information. More...
 
static IdToCallSiteMap idToCSMap
 Map a callsite ID to a pair of call instruction and callee. More...
 
static CallSiteID totalCallSiteNum = 1
 CallSiteIDs, start from 1;. More...
 

Additional Inherited Members

- Public Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
u32_t edgeNum
 total num of node More...
 
u32_t nodeNum
 total num of edge More...
 

Detailed Description

Definition at line 241 of file PTACallGraph.h.

Member Typedef Documentation

◆ CallEdgeMap

Definition at line 252 of file PTACallGraph.h.

◆ CallGraphEdgeConstIter

typedef CallGraphEdgeSet::const_iterator SVF::PTACallGraph::CallGraphEdgeConstIter

Definition at line 254 of file PTACallGraph.h.

◆ CallGraphEdgeIter

typedef CallGraphEdgeSet::iterator SVF::PTACallGraph::CallGraphEdgeIter

Definition at line 253 of file PTACallGraph.h.

◆ CallGraphEdgeSet

Definition at line 245 of file PTACallGraph.h.

◆ CallInstToCallGraphEdgesMap

Definition at line 247 of file PTACallGraph.h.

◆ CallSitePair

typedef std::pair<const CallICFGNode*, const SVFFunction*> SVF::PTACallGraph::CallSitePair

Definition at line 248 of file PTACallGraph.h.

◆ CallSiteToIdMap

Definition at line 249 of file PTACallGraph.h.

◆ FunctionSet

Definition at line 251 of file PTACallGraph.h.

◆ FunToCallGraphNodeMap

Definition at line 246 of file PTACallGraph.h.

◆ IdToCallSiteMap

Definition at line 250 of file PTACallGraph.h.

Member Enumeration Documentation

◆ CGEK

Enumerator
NormCallGraph 
ThdCallGraph 

Definition at line 256 of file PTACallGraph.h.

Constructor & Destructor Documentation

◆ PTACallGraph() [1/2]

PTACallGraph::PTACallGraph ( CGEK  k = NormCallGraph)

Constructor.

Definition at line 109 of file PTACallGraph.cpp.

109  : kind(k)
110 {
111  callGraphNodeNum = 0;
113 }
u32_t numOfResolvedIndCallEdge
Definition: PTACallGraph.h:275

◆ PTACallGraph() [2/2]

PTACallGraph::PTACallGraph ( const PTACallGraph other)

Copy constructor.

copy call graph nodes

copy edges

Definition at line 116 of file PTACallGraph.cpp.

117 {
120  kind = other.kind;
121 
123  for (const auto& item : other)
124  {
125  const PTACallGraphNode* cgn = item.second;
126  PTACallGraphNode* callGraphNode = new PTACallGraphNode(cgn->getId(), cgn->getFunction());
127  addGNode(cgn->getId(),callGraphNode);
128  funToCallGraphNodeMap[cgn->getFunction()] = callGraphNode;
129  }
130 
132  for (const auto& item : other.callinstToCallGraphEdgesMap)
133  {
134  const CallICFGNode* cs = item.first;
135  for (const PTACallGraphEdge* edge : item.second)
136  {
140  newEdge->addDirectCallSite(cs);
141  addEdge(newEdge);
142  callinstToCallGraphEdgesMap[cs].insert(newEdge);
143  }
144  }
145 
146 }
cJSON * item
Definition: cJSON.h:222
NodeID getDstID() const
Definition: GenericGraph.h:85
NodeID getSrcID() const
get methods of the components
Definition: GenericGraph.h:81
void addGNode(NodeID id, NodeType *node)
Add a Node.
Definition: GenericGraph.h:646
void addDirectCallSite(const CallICFGNode *call)
Add direct and indirect callsite.
CallSiteID getCallSiteID() const
Get direct and indirect calls.
Definition: PTACallGraph.h:83
const SVFFunction * getFunction() const
Get function of this call node.
Definition: PTACallGraph.h:198
void addEdge(PTACallGraphEdge *edge)
Add call graph edge.
Definition: PTACallGraph.h:443
FunToCallGraphNodeMap funToCallGraphNodeMap
Call Graph node map.
Definition: PTACallGraph.h:271
PTACallGraphNode * getCallGraphNode(NodeID id) const
Get call graph node.
Definition: PTACallGraph.h:339
CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap
Map a call instruction to its corresponding call edges.
Definition: PTACallGraph.h:272
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260

◆ ~PTACallGraph()

virtual SVF::PTACallGraph::~PTACallGraph ( )
inlinevirtual

Destructor.

Definition at line 291 of file PTACallGraph.h.

292  {
293  destroy();
294  }
void destroy()
Clean up memory.

Member Function Documentation

◆ addCallGraphNode()

void PTACallGraph::addCallGraphNode ( const SVFFunction fun)

Add call graph node

Definition at line 158 of file PTACallGraph.cpp.

159 {
161  PTACallGraphNode*callGraphNode = new PTACallGraphNode(id, fun);
162  addGNode(id, callGraphNode);
163  funToCallGraphNodeMap[callGraphNode->getFunction()] = callGraphNode;
165 }
u32_t NodeID
Definition: GeneralType.h:55

◆ addCallSite()

CallSiteID SVF::PTACallGraph::addCallSite ( const CallICFGNode cs,
const SVFFunction callee 
)
inline

Add/Get CallSiteID.

Definition at line 354 of file PTACallGraph.h.

355  {
356  std::pair<const CallICFGNode*, const SVFFunction*> newCS(std::make_pair(cs, callee));
357  CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS);
358  //assert(it == csToIdMap.end() && "cannot add a callsite twice");
359  if(it == csToIdMap.end())
360  {
362  csToIdMap.insert(std::make_pair(newCS, id));
363  idToCSMap.insert(std::make_pair(id, newCS));
364  return id;
365  }
366  return it->second;
367  }
static CallSiteID totalCallSiteNum
CallSiteIDs, start from 1;.
Definition: PTACallGraph.h:268
static IdToCallSiteMap idToCSMap
Map a callsite ID to a pair of call instruction and callee.
Definition: PTACallGraph.h:267
static CallSiteToIdMap csToIdMap
Call site information.
Definition: PTACallGraph.h:266
unsigned CallSiteID
Definition: GeneralType.h:58

◆ addDirectCallGraphEdge()

void PTACallGraph::addDirectCallGraphEdge ( const CallICFGNode cs,
const SVFFunction callerFun,
const SVFFunction calleeFun 
)

Add direct/indirect call edges.

Add direct call edges

Definition at line 206 of file PTACallGraph.cpp.

207 {
208 
209  PTACallGraphNode* caller = getCallGraphNode(callerFun);
210  PTACallGraphNode* callee = getCallGraphNode(calleeFun);
211 
212  CallSiteID csId = addCallSite(cs, callee->getFunction());
213 
214  if(!hasGraphEdge(caller,callee, PTACallGraphEdge::CallRetEdge,csId))
215  {
216  PTACallGraphEdge* edge = new PTACallGraphEdge(caller,callee, PTACallGraphEdge::CallRetEdge,csId);
217  edge->addDirectCallSite(cs);
218  addEdge(edge);
219  callinstToCallGraphEdgesMap[cs].insert(edge);
220  }
221 }
PTACallGraphEdge * hasGraphEdge(PTACallGraphNode *src, PTACallGraphNode *dst, PTACallGraphEdge::CEDGEK kind, CallSiteID csId) const
Whether we have already created this call graph edge.
CallSiteID addCallSite(const CallICFGNode *cs, const SVFFunction *callee)
Add/Get CallSiteID.
Definition: PTACallGraph.h:354

◆ addEdge()

void SVF::PTACallGraph::addEdge ( PTACallGraphEdge edge)
inline

Add call graph edge.

Definition at line 443 of file PTACallGraph.h.

444  {
445  edge->getDstNode()->addIncomingEdge(edge);
446  edge->getSrcNode()->addOutgoingEdge(edge);
447  }

◆ addIndirectCallGraphEdge()

void PTACallGraph::addIndirectCallGraphEdge ( const CallICFGNode cs,
const SVFFunction callerFun,
const SVFFunction calleeFun 
)

Add indirect call edge to update call graph

Definition at line 226 of file PTACallGraph.cpp.

227 {
228 
229  PTACallGraphNode* caller = getCallGraphNode(callerFun);
230  PTACallGraphNode* callee = getCallGraphNode(calleeFun);
231 
233 
234  CallSiteID csId = addCallSite(cs, callee->getFunction());
235 
236  if(!hasGraphEdge(caller,callee, PTACallGraphEdge::CallRetEdge,csId))
237  {
238  PTACallGraphEdge* edge = new PTACallGraphEdge(caller,callee, PTACallGraphEdge::CallRetEdge, csId);
239  edge->addInDirectCallSite(cs);
240  addEdge(edge);
241  callinstToCallGraphEdgesMap[cs].insert(edge);
242  }
243 }
void addInDirectCallSite(const CallICFGNode *call)

◆ destroy()

void PTACallGraph::destroy ( )
protected

Clean up memory.

Memory has been cleaned up at GenericGraph

Definition at line 151 of file PTACallGraph.cpp.

152 {
153 }

◆ dump()

void PTACallGraph::dump ( const std::string filename)

Dump the graph.

Dump call graph into dot file

Definition at line 355 of file PTACallGraph.cpp.

356 {
357  GraphPrinter::WriteGraphToFile(outs(), filename, this);
358 }
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)
Definition: GraphPrinter.h:56
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50

◆ getAllCallSitesInvokingCallee()

void PTACallGraph::getAllCallSitesInvokingCallee ( const SVFFunction callee,
PTACallGraphEdge::CallInstSet csSet 
)

Get callsites invoking the callee.

Get all callsite invoking this callee

Definition at line 248 of file PTACallGraph.cpp.

249 {
250  PTACallGraphNode* callGraphNode = getCallGraphNode(callee);
251  for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd();
252  it!=eit; ++it)
253  {
254  for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*it)->directCallsBegin(),
255  ecit = (*it)->directCallsEnd(); cit!=ecit; ++cit)
256  {
257  csSet.insert((*cit));
258  }
259  for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*it)->indirectCallsBegin(),
260  ecit = (*it)->indirectCallsEnd(); cit!=ecit; ++cit)
261  {
262  csSet.insert((*cit));
263  }
264  }
265 }
iterator InEdgeBegin()
Definition: GenericGraph.h:462
iterator InEdgeEnd()
Definition: GenericGraph.h:466
PTACallGraphEdge::CallGraphEdgeSet::iterator iterator
Definition: PTACallGraph.h:179

◆ getCallEdgeBegin()

CallGraphEdgeSet::const_iterator SVF::PTACallGraph::getCallEdgeBegin ( const CallICFGNode inst) const
inline

Definition at line 427 of file PTACallGraph.h.

428  {
429  CallInstToCallGraphEdgesMap::const_iterator it = callinstToCallGraphEdgesMap.find(inst);
430  assert(it!=callinstToCallGraphEdgesMap.end()
431  && "call instruction does not have a valid callee");
432  return it->second.begin();
433  }

◆ getCallEdgeEnd()

CallGraphEdgeSet::const_iterator SVF::PTACallGraph::getCallEdgeEnd ( const CallICFGNode inst) const
inline

Definition at line 434 of file PTACallGraph.h.

435  {
436  CallInstToCallGraphEdgesMap::const_iterator it = callinstToCallGraphEdgesMap.find(inst);
437  assert(it!=callinstToCallGraphEdgesMap.end()
438  && "call instruction does not have a valid callee");
439  return it->second.end();
440  }

◆ getCalleeOfCallSite()

const SVFFunction* SVF::PTACallGraph::getCalleeOfCallSite ( CallSiteID  id) const
inline

Definition at line 395 of file PTACallGraph.h.

396  {
397  return getCallSitePair(id).second;
398  }
const CallSitePair & getCallSitePair(CallSiteID id) const
Definition: PTACallGraph.h:381

◆ getCallees()

void SVF::PTACallGraph::getCallees ( const CallICFGNode cs,
FunctionSet callees 
)
inline

Get all callees for a callsite.

Definition at line 408 of file PTACallGraph.h.

409  {
410  if(hasCallGraphEdge(cs))
411  {
412  for (CallGraphEdgeSet::const_iterator it = getCallEdgeBegin(cs), eit =
413  getCallEdgeEnd(cs); it != eit; ++it)
414  {
415  callees.insert((*it)->getDstNode()->getFunction());
416  }
417  }
418  }
CallGraphEdgeSet::const_iterator getCallEdgeEnd(const CallICFGNode *inst) const
Definition: PTACallGraph.h:434
CallGraphEdgeSet::const_iterator getCallEdgeBegin(const CallICFGNode *inst) const
Definition: PTACallGraph.h:427
bool hasCallGraphEdge(const CallICFGNode *inst) const
Get call graph edge via call instruction.
Definition: PTACallGraph.h:423

◆ getCallerOfCallSite()

const SVFFunction* SVF::PTACallGraph::getCallerOfCallSite ( CallSiteID  id) const
inline

Definition at line 391 of file PTACallGraph.h.

392  {
393  return getCallSite(id)->getCaller();
394  }
const SVFFunction * getCaller() const
Return callsite.
Definition: ICFGNode.h:470
const CallICFGNode * getCallSite(CallSiteID id) const
Definition: PTACallGraph.h:387

◆ getCallGraphNode() [1/2]

PTACallGraphNode* SVF::PTACallGraph::getCallGraphNode ( const SVFFunction fun) const
inline

Definition at line 343 of file PTACallGraph.h.

344  {
345  FunToCallGraphNodeMap::const_iterator it = funToCallGraphNodeMap.find(fun);
346  assert(it!=funToCallGraphNodeMap.end() && "call graph node not found!!");
347  return it->second;
348  }

◆ getCallGraphNode() [2/2]

PTACallGraphNode* SVF::PTACallGraph::getCallGraphNode ( NodeID  id) const
inline

Get call graph node.

Definition at line 339 of file PTACallGraph.h.

340  {
341  return getGNode(id);
342  }
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653

◆ getCallInstToCallGraphEdgesMap()

const CallInstToCallGraphEdgesMap& SVF::PTACallGraph::getCallInstToCallGraphEdgesMap ( ) const
inline

Definition at line 329 of file PTACallGraph.h.

330  {
332  }

◆ getCallSite()

const CallICFGNode* SVF::PTACallGraph::getCallSite ( CallSiteID  id) const
inline

Definition at line 387 of file PTACallGraph.h.

388  {
389  return getCallSitePair(id).first;
390  }

◆ getCallSiteID()

CallSiteID SVF::PTACallGraph::getCallSiteID ( const CallICFGNode cs,
const SVFFunction callee 
) const
inline

Definition at line 368 of file PTACallGraph.h.

369  {
370  CallSitePair newCS(std::make_pair(cs, callee));
371  CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS);
372  assert(it != csToIdMap.end() && "callsite id not found! This maybe a partially resolved callgraph, please check the indCallEdge limit");
373  return it->second;
374  }
std::pair< const CallICFGNode *, const SVFFunction * > CallSitePair
Definition: PTACallGraph.h:248

◆ getCallSitePair()

const CallSitePair& SVF::PTACallGraph::getCallSitePair ( CallSiteID  id) const
inline

Definition at line 381 of file PTACallGraph.h.

382  {
383  IdToCallSiteMap::const_iterator it = idToCSMap.find(id);
384  assert(it != idToCSMap.end() && "cannot find call site for this CallSiteID");
385  return (it->second);
386  }

◆ getDirCallSitesInvokingCallee()

void PTACallGraph::getDirCallSitesInvokingCallee ( const SVFFunction callee,
PTACallGraphEdge::CallInstSet csSet 
)

Get direct callsite invoking this callee

Definition at line 270 of file PTACallGraph.cpp.

271 {
272  PTACallGraphNode* callGraphNode = getCallGraphNode(callee);
273  for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd();
274  it!=eit; ++it)
275  {
276  for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*it)->directCallsBegin(),
277  ecit = (*it)->directCallsEnd(); cit!=ecit; ++cit)
278  {
279  csSet.insert((*cit));
280  }
281  }
282 }

◆ getGraphEdge()

PTACallGraphEdge * PTACallGraph::getGraphEdge ( PTACallGraphNode src,
PTACallGraphNode dst,
PTACallGraphEdge::CEDGEK  kind,
CallSiteID  csId 
)

Get call graph edge via nodes.

get PTACallGraph edge via nodes

Definition at line 189 of file PTACallGraph.cpp.

192 {
193  for (PTACallGraphEdge::CallGraphEdgeSet::iterator iter = src->OutEdgeBegin();
194  iter != src->OutEdgeEnd(); ++iter)
195  {
196  PTACallGraphEdge* edge = (*iter);
197  if (edge->getEdgeKind() == kind && edge->getDstID() == dst->getId())
198  return edge;
199  }
200  return nullptr;
201 }
GEdgeKind getEdgeKind() const
Definition: GenericGraph.h:89
iterator OutEdgeEnd()
Definition: GenericGraph.h:458
iterator OutEdgeBegin()
iterators
Definition: GenericGraph.h:454

◆ getIndCallMap()

CallEdgeMap& SVF::PTACallGraph::getIndCallMap ( )
inline

Get callees from an indirect callsite.

Definition at line 304 of file PTACallGraph.h.

305  {
306  return indirectCallMap;
307  }
CallEdgeMap indirectCallMap
Indirect call map.
Definition: PTACallGraph.h:263

◆ getIndCallSitesInvokingCallee()

void PTACallGraph::getIndCallSitesInvokingCallee ( const SVFFunction callee,
PTACallGraphEdge::CallInstSet csSet 
)

Get indirect callsite invoking this callee

Definition at line 287 of file PTACallGraph.cpp.

288 {
289  PTACallGraphNode* callGraphNode = getCallGraphNode(callee);
290  for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd();
291  it!=eit; ++it)
292  {
293  for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*it)->indirectCallsBegin(),
294  ecit = (*it)->indirectCallsEnd(); cit!=ecit; ++cit)
295  {
296  csSet.insert((*cit));
297  }
298  }
299 }

◆ getIndCSCallees()

const FunctionSet& SVF::PTACallGraph::getIndCSCallees ( const CallICFGNode cs) const
inline

Definition at line 312 of file PTACallGraph.h.

313  {
314  CallEdgeMap::const_iterator it = indirectCallMap.find(cs);
315  assert(it!=indirectCallMap.end() && "not an indirect callsite!");
316  return it->second;
317  }

◆ getKind()

CGEK SVF::PTACallGraph::getKind ( void  ) const
inline

Return type of this callgraph.

Definition at line 297 of file PTACallGraph.h.

298  {
299  return kind;
300  }

◆ getNumOfResolvedIndCallEdge()

u32_t SVF::PTACallGraph::getNumOfResolvedIndCallEdge ( ) const
inline

Definition at line 324 of file PTACallGraph.h.

325  {
327  }

◆ getTotalCallSiteNumber()

u32_t SVF::PTACallGraph::getTotalCallSiteNumber ( ) const
inline

Definition at line 319 of file PTACallGraph.h.

320  {
321  return totalCallSiteNum;
322  }

◆ hasCallGraphEdge()

bool SVF::PTACallGraph::hasCallGraphEdge ( const CallICFGNode inst) const
inline

Get call graph edge via call instruction.

whether this call instruction has a valid call graph edge

Definition at line 423 of file PTACallGraph.h.

424  {
426  }

◆ hasCallSiteID()

bool SVF::PTACallGraph::hasCallSiteID ( const CallICFGNode cs,
const SVFFunction callee 
) const
inline

Definition at line 375 of file PTACallGraph.h.

376  {
377  CallSitePair newCS(std::make_pair(cs, callee));
378  CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS);
379  return it != csToIdMap.end();
380  }

◆ hasGraphEdge()

PTACallGraphEdge * PTACallGraph::hasGraphEdge ( PTACallGraphNode src,
PTACallGraphNode dst,
PTACallGraphEdge::CEDGEK  kind,
CallSiteID  csId 
) const

Whether we have already created this call graph edge.

Whether we have already created this call graph edge

Definition at line 170 of file PTACallGraph.cpp.

173 {
174  PTACallGraphEdge edge(src,dst,kind,csId);
175  PTACallGraphEdge* outEdge = src->hasOutgoingEdge(&edge);
176  PTACallGraphEdge* inEdge = dst->hasIncomingEdge(&edge);
177  if (outEdge && inEdge)
178  {
179  assert(outEdge == inEdge && "edges not match");
180  return outEdge;
181  }
182  else
183  return nullptr;
184 }
bool hasIncomingEdge() const
Has incoming/outgoing edge set.
Definition: GenericGraph.h:442
bool hasOutgoingEdge() const
Definition: GenericGraph.h:446

◆ hasIndCSCallees()

bool SVF::PTACallGraph::hasIndCSCallees ( const CallICFGNode cs) const
inline

Definition at line 308 of file PTACallGraph.h.

309  {
310  return (indirectCallMap.find(cs) != indirectCallMap.end());
311  }

◆ isReachableBetweenFunctions()

bool PTACallGraph::isReachableBetweenFunctions ( const SVFFunction srcFn,
const SVFFunction dstFn 
) const

Whether its reachable between two functions.

Whether its reachable between two functions

Definition at line 324 of file PTACallGraph.cpp.

325 {
326  PTACallGraphNode* dstNode = getCallGraphNode(dstFn);
327 
328  std::stack<const PTACallGraphNode*> nodeStack;
329  NodeBS visitedNodes;
330  nodeStack.push(dstNode);
331  visitedNodes.set(dstNode->getId());
332 
333  while (nodeStack.empty() == false)
334  {
335  PTACallGraphNode* node = const_cast<PTACallGraphNode*>(nodeStack.top());
336  nodeStack.pop();
337 
338  if (node->getFunction() == srcFn)
339  return true;
340 
341  for (CallGraphEdgeConstIter it = node->InEdgeBegin(), eit = node->InEdgeEnd(); it != eit; ++it)
342  {
343  PTACallGraphEdge* edge = *it;
344  if (visitedNodes.test_and_set(edge->getSrcID()))
345  nodeStack.push(edge->getSrcNode());
346  }
347  }
348 
349  return false;
350 }
NodeType * getSrcNode() const
Definition: GenericGraph.h:97
CallGraphEdgeSet::const_iterator CallGraphEdgeConstIter
Definition: PTACallGraph.h:254
bool test_and_set(unsigned Idx)
void set(unsigned Idx)

◆ verifyCallGraph()

void PTACallGraph::verifyCallGraph ( )

Issue a warning if the function which has indirect call sites can not be reached from program entry.

Issue a warning if the function which has indirect call sites can not be reached from program entry.

Definition at line 304 of file PTACallGraph.cpp.

305 {
306  CallEdgeMap::const_iterator it = indirectCallMap.begin();
307  CallEdgeMap::const_iterator eit = indirectCallMap.end();
308  for (; it != eit; ++it)
309  {
310  const FunctionSet& targets = it->second;
311  if (targets.empty() == false)
312  {
313  const CallICFGNode* cs = it->first;
314  const SVFFunction* func = cs->getCaller();
315  if (getCallGraphNode(func)->isReachableFromProgEntry() == false)
316  writeWrnMsg(func->getName() + " has indirect call site but not reachable from main");
317  }
318  }
319 }
Set< const SVFFunction * > FunctionSet
Definition: PTACallGraph.h:251
const std::string & getName() const
Definition: SVFValue.h:243
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition: SVFUtil.cpp:66

◆ view()

void PTACallGraph::view ( )

View the graph from the debugger.

Definition at line 360 of file PTACallGraph.cpp.

361 {
362  SVF::ViewGraph(this, "Call Graph");
363 }
void ViewGraph(const GraphType &G, const std::string &name, bool ShortNames=false, GraphProgram::Name Program=GraphProgram::DOT)
Definition: GraphWriter.h:371

Member Data Documentation

◆ callGraphNodeNum

NodeID SVF::PTACallGraph::callGraphNodeNum
protected

Definition at line 274 of file PTACallGraph.h.

◆ callinstToCallGraphEdgesMap

CallInstToCallGraphEdgesMap SVF::PTACallGraph::callinstToCallGraphEdgesMap
protected

Map a call instruction to its corresponding call edges.

Definition at line 272 of file PTACallGraph.h.

◆ csToIdMap

PTACallGraph::CallSiteToIdMap PTACallGraph::csToIdMap
staticprivate

Call site information.

Map a pair of call instruction and callee to a callsite ID

Definition at line 266 of file PTACallGraph.h.

◆ funToCallGraphNodeMap

FunToCallGraphNodeMap SVF::PTACallGraph::funToCallGraphNodeMap
protected

Call Graph node map.

Definition at line 271 of file PTACallGraph.h.

◆ idToCSMap

PTACallGraph::IdToCallSiteMap PTACallGraph::idToCSMap
staticprivate

Map a callsite ID to a pair of call instruction and callee.

Definition at line 267 of file PTACallGraph.h.

◆ indirectCallMap

CallEdgeMap SVF::PTACallGraph::indirectCallMap
private

Indirect call map.

Definition at line 263 of file PTACallGraph.h.

◆ kind

CGEK SVF::PTACallGraph::kind
protected

Definition at line 276 of file PTACallGraph.h.

◆ numOfResolvedIndCallEdge

u32_t SVF::PTACallGraph::numOfResolvedIndCallEdge
protected

Definition at line 275 of file PTACallGraph.h.

◆ totalCallSiteNum

CallSiteID PTACallGraph::totalCallSiteNum = 1
staticprivate

CallSiteIDs, start from 1;.

Definition at line 268 of file PTACallGraph.h.


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