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

#include <ThreadCallGraph.h>

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

Public Types

typedef Set< const CallICFGNode * > InstSet
 
typedef InstSet CallSiteSet
 
typedef Set< CallSiteSet * > CtxSet
 
typedef ThreadForkEdge::ForkEdgeSet ForkEdgeSet
 
typedef Map< const CallICFGNode *, ForkEdgeSetCallInstToForkEdgesMap
 
typedef ThreadJoinEdge::JoinEdgeSet JoinEdgeSet
 
typedef Map< const CallICFGNode *, JoinEdgeSetCallInstToJoinEdgesMap
 
typedef HareParForEdge::ParForEdgeSet ParForEdgeSet
 
typedef Map< const CallICFGNode *, ParForEdgeSetCallInstToParForEdgesMap
 
- Public Types inherited from SVF::PTACallGraph
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

 ThreadCallGraph (const PTACallGraph &cg)
 Constructor. More...
 
 ThreadCallGraph (ThreadCallGraph &cg)=delete
 
virtual ~ThreadCallGraph ()
 Destructor. More...
 
void updateCallGraph (PointerAnalysis *pta)
 Update call graph using pointer results. More...
 
void updateJoinEdge (PointerAnalysis *pta)
 Update join edge using pointer analysis results. More...
 
bool hasThreadForkEdge (const CallICFGNode *cs) const
 Get call graph edge via call instruction. More...
 
ForkEdgeSet::const_iterator getForkEdgeBegin (const CallICFGNode *cs) const
 
ForkEdgeSet::const_iterator getForkEdgeEnd (const CallICFGNode *cs) const
 
bool hasThreadJoinEdge (const CallICFGNode *cs) const
 Get call graph edge via call instruction. More...
 
JoinEdgeSet::const_iterator getJoinEdgeBegin (const CallICFGNode *cs) const
 
JoinEdgeSet::const_iterator getJoinEdgeEnd (const CallICFGNode *cs) const
 
void getJoinSites (const PTACallGraphNode *routine, InstSet &csSet)
 
- Public Member Functions inherited from SVF::PTACallGraph
 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 ()
 

Static Public Member Functions

static bool classof (const ThreadCallGraph *)
 ClassOf. More...
 
static bool classof (const PTACallGraph *g)
 
ThreadAPItdAPI
 Thread API. More...
 
CallSiteSet forksites
 all thread fork sites More...
 
CallSiteSet joinsites
 all thread fork sites More...
 
CallSiteSet parForSites
 all parallel for sites More...
 
CallInstToForkEdgesMap callinstToThreadForkEdgesMap
 Map a call instruction to its corresponding fork edges. More...
 
CallInstToJoinEdgesMap callinstToThreadJoinEdgesMap
 Map a call instruction to its corresponding join edges. More...
 
CallInstToParForEdgesMap callinstToHareParForEdgesMap
 Map a call instruction to its corresponding hare_parallel_for edges. More...
 
bool isForksite (const CallICFGNode *csInst)
 
bool isJoinsite (const CallICFGNode *csInst)
 
bool isParForSite (const CallICFGNode *csInst)
 
CallSiteSet::const_iterator forksitesBegin () const
 Fork sites iterators. More...
 
CallSiteSet::const_iterator forksitesEnd () const
 
CallSiteSet::const_iterator joinsitesBegin () const
 Join sites iterators. More...
 
CallSiteSet::const_iterator joinsitesEnd () const
 
CallSiteSet::const_iterator parForSitesBegin () const
 hare_parallel_for sites iterators More...
 
CallSiteSet::const_iterator parForSitesEnd () const
 
u32_t getNumOfForksite () const
 Num of fork/join sites. More...
 
u32_t getNumOfJoinsite () const
 
u32_t getNumOfParForSite () const
 
ThreadAPIgetThreadAPI () const
 Thread API. More...
 
bool addForksite (const CallICFGNode *cs)
 Add fork sites which directly or indirectly create a thread. More...
 
bool addJoinsite (const CallICFGNode *cs)
 
bool addParForSite (const CallICFGNode *cs)
 
bool addDirectForkEdge (const CallICFGNode *cs)
 Add direct/indirect thread fork edges. More...
 
bool addIndirectForkEdge (const CallICFGNode *cs, const SVFFunction *callee)
 
void addDirectJoinEdge (const CallICFGNode *cs, const CallSiteSet &forksite)
 Add thread join edges. More...
 
void addThreadForkEdgeSetMap (const CallICFGNode *cs, ThreadForkEdge *edge)
 map call instruction to its PTACallGraphEdge map More...
 
void addThreadJoinEdgeSetMap (const CallICFGNode *cs, ThreadJoinEdge *edge)
 map call instruction to its PTACallGraphEdge map More...
 
void addHareParForEdgeSetMap (const CallICFGNode *cs, HareParForEdge *edge)
 map call instruction to its PTACallGraphEdge map More...
 
ThreadJoinEdgehasThreadJoinEdge (const CallICFGNode *call, PTACallGraphNode *joinFunNode, PTACallGraphNode *threadRoutineFunNode, CallSiteID csId) const
 has thread join edge 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...
 
- Protected Member Functions inherited from SVF::PTACallGraph
void destroy ()
 Clean up memory. More...
 
- Protected Attributes inherited from SVF::PTACallGraph
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...
 

Detailed Description

Thread sensitive call graph

Definition at line 160 of file ThreadCallGraph.h.

Member Typedef Documentation

◆ CallInstToForkEdgesMap

Definition at line 168 of file ThreadCallGraph.h.

◆ CallInstToJoinEdgesMap

Definition at line 170 of file ThreadCallGraph.h.

◆ CallInstToParForEdgesMap

Definition at line 172 of file ThreadCallGraph.h.

◆ CallSiteSet

Definition at line 165 of file ThreadCallGraph.h.

◆ CtxSet

Definition at line 166 of file ThreadCallGraph.h.

◆ ForkEdgeSet

Definition at line 167 of file ThreadCallGraph.h.

◆ InstSet

Definition at line 164 of file ThreadCallGraph.h.

◆ JoinEdgeSet

Definition at line 169 of file ThreadCallGraph.h.

◆ ParForEdgeSet

Definition at line 171 of file ThreadCallGraph.h.

Constructor & Destructor Documentation

◆ ThreadCallGraph() [1/2]

ThreadCallGraph::ThreadCallGraph ( const PTACallGraph cg)

Constructor.

Constructor

Definition at line 42 of file ThreadCallGraph.cpp.

42  :
44 {
46  DBOUT(DGENERAL, outs() << SVFUtil::pasMsg("Building ThreadCallGraph\n"));
47 }
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition: SVFType.h:484
#define DGENERAL
Definition: SVFType.h:490
PTACallGraph(CGEK k=NormCallGraph)
Constructor.
static ThreadAPI * getThreadAPI()
Return a static reference.
Definition: ThreadAPI.h:105
ThreadAPI * tdAPI
Thread API.
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
Definition: SVFUtil.cpp:99
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50

◆ ThreadCallGraph() [2/2]

SVF::ThreadCallGraph::ThreadCallGraph ( ThreadCallGraph cg)
delete

◆ ~ThreadCallGraph()

virtual SVF::ThreadCallGraph::~ThreadCallGraph ( )
inlinevirtual

Destructor.

Definition at line 180 of file ThreadCallGraph.h.

181  {
182  }

Member Function Documentation

◆ addDirectForkEdge()

bool ThreadCallGraph::addDirectForkEdge ( const CallICFGNode cs)

Add direct/indirect thread fork edges.

Add direct fork edges

Definition at line 125 of file ThreadCallGraph.cpp.

126 {
127 
129  const SVFFunction* forkee = SVFUtil::dyn_cast<SVFFunction>(tdAPI->getForkedFun(cs)->getValue());
130  assert(forkee && "callee does not exist");
132  CallSiteID csId = addCallSite(cs, callee->getFunction());
133 
134  if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId))
135  {
136  assert(cs->getCaller() == caller->getFunction() && "callee instruction not inside caller??");
137 
138  ThreadForkEdge* edge = new ThreadForkEdge(caller, callee, csId);
139  edge->addDirectCallSite(cs);
140 
141  addEdge(edge);
142  addThreadForkEdgeSetMap(cs, edge);
143  return true;
144  }
145  else
146  return false;
147 }
const SVFFunction * getCaller() const
Return callsite.
Definition: ICFGNode.h:470
void addDirectCallSite(const CallICFGNode *call)
Add direct and indirect callsite.
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
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
PTACallGraphNode * getCallGraphNode(NodeID id) const
Get call graph node.
Definition: PTACallGraph.h:339
const SVFFunction * getDefFunForMultipleModule() const
Definition: SVFValue.h:393
const SVFValue * getValue() const
Get/has methods of the components.
Definition: SVFVariables.h:83
const SVFVar * getForkedFun(const CallICFGNode *inst) const
Definition: ThreadAPI.cpp:170
void addThreadForkEdgeSetMap(const CallICFGNode *cs, ThreadForkEdge *edge)
map call instruction to its PTACallGraphEdge map
unsigned CallSiteID
Definition: GeneralType.h:58

◆ addDirectJoinEdge()

void ThreadCallGraph::addDirectJoinEdge ( const CallICFGNode cs,
const CallSiteSet forkset 
)

Add thread join edges.

Add direct fork edges As join edge is a special return which is back to join site(s) rather than its fork site A ThreadJoinEdge is created from the functions where join sites reside in to the start routine function But we don't invoke addEdge() method to add the edge to src and dst, otherwise it makes a scc cycle

Definition at line 180 of file ThreadCallGraph.cpp.

181 {
182 
183  PTACallGraphNode* joinFunNode = getCallGraphNode(cs->getCaller());
184 
185  for (CallSiteSet::const_iterator it = forkset.begin(), eit = forkset.end(); it != eit; ++it)
186  {
187 
188  const SVFFunction* threadRoutineFun = SVFUtil::dyn_cast<SVFFunction>(tdAPI->getForkedFun(*it)->getValue());
189  assert(threadRoutineFun && "thread routine function does not exist");
190  PTACallGraphNode* threadRoutineFunNode = getCallGraphNode(threadRoutineFun);
191  CallSiteID csId = addCallSite(cs, threadRoutineFun);
192 
193  if (!hasThreadJoinEdge(cs,joinFunNode,threadRoutineFunNode, csId))
194  {
195  assert(cs->getCaller() == joinFunNode->getFunction() && "callee instruction not inside caller??");
196  ThreadJoinEdge* edge = new ThreadJoinEdge(joinFunNode,threadRoutineFunNode,csId);
197  edge->addDirectCallSite(cs);
198 
199  addThreadJoinEdgeSetMap(cs, edge);
200  }
201  }
202 }
bool hasThreadJoinEdge(const CallICFGNode *cs) const
Get call graph edge via call instruction.
void addThreadJoinEdgeSetMap(const CallICFGNode *cs, ThreadJoinEdge *edge)
map call instruction to its PTACallGraphEdge map

◆ addForksite()

bool SVF::ThreadCallGraph::addForksite ( const CallICFGNode cs)
inline

Add fork sites which directly or indirectly create a thread.

Definition at line 333 of file ThreadCallGraph.h.

334  {
336  return forksites.insert(cs).second;
337  }
CallSiteSet forksites
all thread fork sites
CallInstToForkEdgesMap callinstToThreadForkEdgesMap
Map a call instruction to its corresponding fork edges.

◆ addHareParForEdgeSetMap()

void SVF::ThreadCallGraph::addHareParForEdgeSetMap ( const CallICFGNode cs,
HareParForEdge edge 
)
inline

map call instruction to its PTACallGraphEdge map

Definition at line 383 of file ThreadCallGraph.h.

384  {
385  if(edge!=nullptr)
386  {
387  callinstToHareParForEdgesMap[cs].insert(edge);
388  callinstToCallGraphEdgesMap[cs].insert(edge);
389  }
390  }
CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap
Map a call instruction to its corresponding call edges.
Definition: PTACallGraph.h:272
CallInstToParForEdgesMap callinstToHareParForEdgesMap
Map a call instruction to its corresponding hare_parallel_for edges.

◆ addIndirectForkEdge()

bool ThreadCallGraph::addIndirectForkEdge ( const CallICFGNode cs,
const SVFFunction calleefun 
)

Add indirect fork edge to update call graph

Definition at line 152 of file ThreadCallGraph.cpp.

153 {
155  PTACallGraphNode* callee = getCallGraphNode(calleefun);
156 
157  CallSiteID csId = addCallSite(cs, callee->getFunction());
158 
159  if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId))
160  {
161  assert(cs->getCaller() == caller->getFunction() && "callee instruction not inside caller??");
162 
163  ThreadForkEdge* edge = new ThreadForkEdge(caller, callee, csId);
164  edge->addInDirectCallSite(cs);
165 
166  addEdge(edge);
167  addThreadForkEdgeSetMap(cs, edge);
168  return true;
169  }
170  else
171  return false;
172 }
void addInDirectCallSite(const CallICFGNode *call)

◆ addJoinsite()

bool SVF::ThreadCallGraph::addJoinsite ( const CallICFGNode cs)
inline

Definition at line 338 of file ThreadCallGraph.h.

339  {
341  return joinsites.insert(cs).second;
342  }
CallSiteSet joinsites
all thread fork sites
CallInstToJoinEdgesMap callinstToThreadJoinEdgesMap
Map a call instruction to its corresponding join edges.

◆ addParForSite()

bool SVF::ThreadCallGraph::addParForSite ( const CallICFGNode cs)
inline

Definition at line 343 of file ThreadCallGraph.h.

344  {
346  return parForSites.insert(cs).second;
347  }
CallSiteSet parForSites
all parallel for sites

◆ addThreadForkEdgeSetMap()

void SVF::ThreadCallGraph::addThreadForkEdgeSetMap ( const CallICFGNode cs,
ThreadForkEdge edge 
)
inline

map call instruction to its PTACallGraphEdge map

Definition at line 363 of file ThreadCallGraph.h.

364  {
365  if(edge!=nullptr)
366  {
367  callinstToThreadForkEdgesMap[cs].insert(edge);
368  callinstToCallGraphEdgesMap[cs].insert(edge);
369  }
370  }

◆ addThreadJoinEdgeSetMap()

void SVF::ThreadCallGraph::addThreadJoinEdgeSetMap ( const CallICFGNode cs,
ThreadJoinEdge edge 
)
inline

map call instruction to its PTACallGraphEdge map

Definition at line 373 of file ThreadCallGraph.h.

374  {
375  if(edge!=nullptr)
376  {
377  callinstToThreadJoinEdgesMap[cs].insert(edge);
378  callinstToCallGraphEdgesMap[cs].insert(edge);
379  }
380  }

◆ classof() [1/2]

static bool SVF::ThreadCallGraph::classof ( const PTACallGraph g)
inlinestatic

Definition at line 190 of file ThreadCallGraph.h.

191  {
192  return g->getKind() == PTACallGraph::ThdCallGraph;
193  }

◆ classof() [2/2]

static bool SVF::ThreadCallGraph::classof ( const ThreadCallGraph )
inlinestatic

ClassOf.

Definition at line 186 of file ThreadCallGraph.h.

187  {
188  return true;
189  }

◆ forksitesBegin()

CallSiteSet::const_iterator SVF::ThreadCallGraph::forksitesBegin ( ) const
inline

Fork sites iterators.

Definition at line 275 of file ThreadCallGraph.h.

276  {
277  return forksites.begin();
278  }

◆ forksitesEnd()

CallSiteSet::const_iterator SVF::ThreadCallGraph::forksitesEnd ( ) const
inline

Definition at line 279 of file ThreadCallGraph.h.

280  {
281  return forksites.end();
282  }

◆ getForkEdgeBegin()

ForkEdgeSet::const_iterator SVF::ThreadCallGraph::getForkEdgeBegin ( const CallICFGNode cs) const
inline

Definition at line 210 of file ThreadCallGraph.h.

211  {
212  CallInstToForkEdgesMap::const_iterator it = callinstToThreadForkEdgesMap.find(cs);
213  assert(it != callinstToThreadForkEdgesMap.end() && "call instruction not found");
214  return it->second.begin();
215  }

◆ getForkEdgeEnd()

ForkEdgeSet::const_iterator SVF::ThreadCallGraph::getForkEdgeEnd ( const CallICFGNode cs) const
inline

Definition at line 216 of file ThreadCallGraph.h.

217  {
218  CallInstToForkEdgesMap::const_iterator it = callinstToThreadForkEdgesMap.find(cs);
219  assert(it != callinstToThreadForkEdgesMap.end() && "call instruction not found");
220  return it->second.end();
221  }

◆ getJoinEdgeBegin()

JoinEdgeSet::const_iterator SVF::ThreadCallGraph::getJoinEdgeBegin ( const CallICFGNode cs) const
inline

Definition at line 230 of file ThreadCallGraph.h.

231  {
232  CallInstToJoinEdgesMap::const_iterator it = callinstToThreadJoinEdgesMap.find(cs);
233  assert(it != callinstToThreadJoinEdgesMap.end() && "call instruction does not have a valid callee");
234  return it->second.begin();
235  }

◆ getJoinEdgeEnd()

JoinEdgeSet::const_iterator SVF::ThreadCallGraph::getJoinEdgeEnd ( const CallICFGNode cs) const
inline

Definition at line 236 of file ThreadCallGraph.h.

237  {
238  CallInstToJoinEdgesMap::const_iterator it = callinstToThreadJoinEdgesMap.find(cs);
239  assert(it != callinstToThreadJoinEdgesMap.end() && "call instruction does not have a valid callee");
240  return it->second.end();
241  }

◆ getJoinSites()

void SVF::ThreadCallGraph::getJoinSites ( const PTACallGraphNode routine,
InstSet csSet 
)
inline

Definition at line 242 of file ThreadCallGraph.h.

243  {
244  for(CallInstToJoinEdgesMap::const_iterator it = callinstToThreadJoinEdgesMap.begin(), eit = callinstToThreadJoinEdgesMap.end(); it!=eit; ++it)
245  {
246  for(JoinEdgeSet::const_iterator jit = it->second.begin(), ejit = it->second.end(); jit!=ejit; ++jit)
247  {
248  if((*jit)->getDstNode() == routine)
249  {
250  csSet.insert(it->first);
251  }
252  }
253  }
254  }

◆ getNumOfForksite()

u32_t SVF::ThreadCallGraph::getNumOfForksite ( ) const
inline

Num of fork/join sites.

Definition at line 311 of file ThreadCallGraph.h.

312  {
313  return forksites.size();
314  }

◆ getNumOfJoinsite()

u32_t SVF::ThreadCallGraph::getNumOfJoinsite ( ) const
inline

Definition at line 315 of file ThreadCallGraph.h.

316  {
317  return joinsites.size();
318  }

◆ getNumOfParForSite()

u32_t SVF::ThreadCallGraph::getNumOfParForSite ( ) const
inline

Definition at line 319 of file ThreadCallGraph.h.

320  {
321  return parForSites.size();
322  }

◆ getThreadAPI()

ThreadAPI* SVF::ThreadCallGraph::getThreadAPI ( ) const
inline

Thread API.

Definition at line 326 of file ThreadCallGraph.h.

327  {
328  return tdAPI;
329  }

◆ hasThreadForkEdge()

bool SVF::ThreadCallGraph::hasThreadForkEdge ( const CallICFGNode cs) const
inline

Get call graph edge via call instruction.

whether this call instruction has a valid call graph edge

Definition at line 205 of file ThreadCallGraph.h.

206  {
207  return callinstToThreadForkEdgesMap.find(cs) !=
209  }

◆ hasThreadJoinEdge() [1/2]

ThreadJoinEdge* SVF::ThreadCallGraph::hasThreadJoinEdge ( const CallICFGNode call,
PTACallGraphNode joinFunNode,
PTACallGraphNode threadRoutineFunNode,
CallSiteID  csId 
) const
inline

has thread join edge

Definition at line 393 of file ThreadCallGraph.h.

394  {
395  ThreadJoinEdge joinEdge(joinFunNode,threadRoutineFunNode, csId);
396  CallInstToJoinEdgesMap::const_iterator it = callinstToThreadJoinEdgesMap.find(call);
397  if(it != callinstToThreadJoinEdgesMap.end())
398  {
399  JoinEdgeSet::const_iterator jit = it->second.find(&joinEdge);
400  if(jit!=it->second.end())
401  return *jit;
402  }
403  return nullptr;
404  }

◆ hasThreadJoinEdge() [2/2]

bool SVF::ThreadCallGraph::hasThreadJoinEdge ( const CallICFGNode cs) const
inline

Get call graph edge via call instruction.

whether this call instruction has a valid call graph edge

Definition at line 226 of file ThreadCallGraph.h.

227  {
229  }

◆ isForksite()

bool SVF::ThreadCallGraph::isForksite ( const CallICFGNode csInst)
inline

Whether a callsite is a fork or join or hare_parallel_for

Definition at line 259 of file ThreadCallGraph.h.

260  {
261  return forksites.find(csInst) != forksites.end();
262  }

◆ isJoinsite()

bool SVF::ThreadCallGraph::isJoinsite ( const CallICFGNode csInst)
inline

Definition at line 263 of file ThreadCallGraph.h.

264  {
265  return joinsites.find(csInst) != joinsites.end();
266  }

◆ isParForSite()

bool SVF::ThreadCallGraph::isParForSite ( const CallICFGNode csInst)
inline

Definition at line 267 of file ThreadCallGraph.h.

268  {
269  return parForSites.find(csInst) != parForSites.end();
270  }

◆ joinsitesBegin()

CallSiteSet::const_iterator SVF::ThreadCallGraph::joinsitesBegin ( ) const
inline

Join sites iterators.

Definition at line 287 of file ThreadCallGraph.h.

288  {
289  return joinsites.begin();
290  }

◆ joinsitesEnd()

CallSiteSet::const_iterator SVF::ThreadCallGraph::joinsitesEnd ( ) const
inline

Definition at line 291 of file ThreadCallGraph.h.

292  {
293  return joinsites.end();
294  }

◆ parForSitesBegin()

CallSiteSet::const_iterator SVF::ThreadCallGraph::parForSitesBegin ( ) const
inline

hare_parallel_for sites iterators

Definition at line 299 of file ThreadCallGraph.h.

300  {
301  return parForSites.begin();
302  }

◆ parForSitesEnd()

CallSiteSet::const_iterator SVF::ThreadCallGraph::parForSitesEnd ( ) const
inline

Definition at line 303 of file ThreadCallGraph.h.

304  {
305  return parForSites.end();
306  }

◆ updateCallGraph()

void ThreadCallGraph::updateCallGraph ( PointerAnalysis pta)

Update call graph using pointer results.

Definition at line 56 of file ThreadCallGraph.cpp.

57 {
58 
59  PointerAnalysis::CallEdgeMap::const_iterator iter = pta->getIndCallMap().begin();
60  PointerAnalysis::CallEdgeMap::const_iterator eiter = pta->getIndCallMap().end();
61  for (; iter != eiter; iter++)
62  {
63  const CallICFGNode* cs = iter->first;
64  const PTACallGraph::FunctionSet &functions = iter->second;
65  for (PTACallGraph::FunctionSet::const_iterator func_iter =
66  functions.begin(); func_iter != functions.end(); func_iter++)
67  {
68  const SVFFunction* callee = *func_iter;
69  this->addIndirectCallGraphEdge(cs, cs->getCaller(), callee);
70  }
71  }
72 
73  // Fork sites
74  for (CallSiteSet::const_iterator it = forksitesBegin(), eit = forksitesEnd(); it != eit; ++it)
75  {
76  const SVFVar* forkedval = tdAPI->getForkedFun(*it);
77  if(SVFUtil::dyn_cast<SVFFunction>(forkedval->getValue())==nullptr)
78  {
79  SVFIR* pag = pta->getPAG();
80  const NodeBS targets = pta->getPts(forkedval->getId()).toNodeBS();
81  for (NodeBS::iterator ii = targets.begin(), ie = targets.end(); ii != ie; ii++)
82  {
83  if(ObjVar* objPN = SVFUtil::dyn_cast<ObjVar>(pag->getGNode(*ii)))
84  {
85  const MemObj* obj = pag->getObject(objPN);
86  if(obj->isFunction())
87  {
88  const SVFFunction* svfCallee = SVFUtil::cast<SVFFunction>(obj->getValue());
89  this->addIndirectForkEdge(*it, svfCallee);
90  }
91  }
92  }
93  }
94  }
95 }
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
const SVFValue * getValue() const
Get the reference value to this object.
bool isFunction() const
object attributes methods
void addIndirectCallGraphEdge(const CallICFGNode *cs, const SVFFunction *callerFun, const SVFFunction *calleeFun)
Set< const SVFFunction * > FunctionSet
Definition: PTACallGraph.h:251
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
SVFIR * getPAG() const
virtual const PointsTo & getPts(NodeID ptr)=0
Get points-to targets of a pointer. It needs to be implemented in child class.
NodeBS toNodeBS() const
Returns this points-to set as a NodeBS.
Definition: PointsTo.cpp:313
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
const MemObj * getObject(NodeID id) const
Definition: SVFIR.h:395
iterator end() const
iterator begin() const
CallSiteSet::const_iterator forksitesEnd() const
bool addIndirectForkEdge(const CallICFGNode *cs, const SVFFunction *callee)
CallSiteSet::const_iterator forksitesBegin() const
Fork sites iterators.

◆ updateJoinEdge()

void ThreadCallGraph::updateJoinEdge ( PointerAnalysis pta)

Update join edge using pointer analysis results.

Update join edge using pointer analysis results

Definition at line 101 of file ThreadCallGraph.cpp.

102 {
103 
104  for (CallSiteSet::const_iterator it = joinsitesBegin(), eit = joinsitesEnd(); it != eit; ++it)
105  {
106  const SVFVar* jointhread = tdAPI->getJoinedThread(*it);
107  // find its corresponding fork sites first
108  CallSiteSet forkset;
109  for (CallSiteSet::const_iterator it = forksitesBegin(), eit = forksitesEnd(); it != eit; ++it)
110  {
111  const SVFVar* forkthread = tdAPI->getForkedThread(*it);
112  if (pta->alias(jointhread->getId(), forkthread->getId()))
113  {
114  forkset.insert(*it);
115  }
116  }
117  assert(!forkset.empty() && "Can't find a forksite for this join!!");
118  addDirectJoinEdge(*it,forkset);
119  }
120 }
virtual AliasResult alias(const SVFValue *V1, const SVFValue *V2)=0
Interface exposed to users of our pointer analysis, given Value infos.
const SVFVar * getJoinedThread(const CallICFGNode *inst) const
Return arguments/attributes of pthread_join.
Definition: ThreadAPI.cpp:207
const SVFVar * getForkedThread(const CallICFGNode *inst) const
Return arguments/attributes of pthread_create / hare_parallel_for.
Definition: ThreadAPI.cpp:164
CallSiteSet::const_iterator joinsitesEnd() const
void addDirectJoinEdge(const CallICFGNode *cs, const CallSiteSet &forksite)
Add thread join edges.
CallSiteSet::const_iterator joinsitesBegin() const
Join sites iterators.

Member Data Documentation

◆ callinstToHareParForEdgesMap

CallInstToParForEdgesMap SVF::ThreadCallGraph::callinstToHareParForEdgesMap
private

Map a call instruction to its corresponding hare_parallel_for edges.

Definition at line 413 of file ThreadCallGraph.h.

◆ callinstToThreadForkEdgesMap

CallInstToForkEdgesMap SVF::ThreadCallGraph::callinstToThreadForkEdgesMap
private

Map a call instruction to its corresponding fork edges.

Definition at line 411 of file ThreadCallGraph.h.

◆ callinstToThreadJoinEdgesMap

CallInstToJoinEdgesMap SVF::ThreadCallGraph::callinstToThreadJoinEdgesMap
private

Map a call instruction to its corresponding join edges.

Definition at line 412 of file ThreadCallGraph.h.

◆ forksites

CallSiteSet SVF::ThreadCallGraph::forksites
private

all thread fork sites

Definition at line 408 of file ThreadCallGraph.h.

◆ joinsites

CallSiteSet SVF::ThreadCallGraph::joinsites
private

all thread fork sites

Definition at line 409 of file ThreadCallGraph.h.

◆ parForSites

CallSiteSet SVF::ThreadCallGraph::parForSites
private

all parallel for sites

Definition at line 410 of file ThreadCallGraph.h.

◆ tdAPI

ThreadAPI* SVF::ThreadCallGraph::tdAPI
private

Thread API.

Definition at line 407 of file ThreadCallGraph.h.


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