Static Value-Flow Analysis
Loading...
Searching...
No Matches
Classes | 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::CallGraph SVF::GenericGraph< NodeTy, EdgeTy >

Classes

struct  CallSiteIdCmp
 

Public Types

typedef OrderedSet< const CallICFGNode *, CallSiteIdCmpInstSet
 
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::CallGraph
enum  CGEK { NormCallGraph , ThdCallGraph }
 
typedef CallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet
 
typedef Map< const FunObjVar *, CallGraphNode * > FunToCallGraphNodeMap
 
typedef Map< const CallICFGNode *, CallGraphEdgeSetCallInstToCallGraphEdgesMap
 
typedef std::pair< const CallICFGNode *, const FunObjVar * > CallSitePair
 
typedef Map< CallSitePair, CallSiteIDCallSiteToIdMap
 
typedef Map< CallSiteID, CallSitePairIdToCallSiteMap
 
typedef Set< const FunObjVar * > 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.
 
typedef IDToNodeMapTy::iterator iterator
 Node Iterators.
 
typedef IDToNodeMapTy::const_iterator const_iterator
 

Public Member Functions

 ThreadCallGraph (const CallGraph &cg)
 Constructor.
 
 ThreadCallGraph (ThreadCallGraph &cg)=delete
 
virtual ~ThreadCallGraph ()
 Destructor.
 
void updateCallGraph (PointerAnalysis *pta)
 Update call graph using pointer results.
 
void updateJoinEdge (PointerAnalysis *pta)
 Update join edge using pointer analysis results.
 
bool hasThreadForkEdge (const CallICFGNode *cs) const
 Get call graph edge via call instruction.
 
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.
 
JoinEdgeSet::const_iterator getJoinEdgeBegin (const CallICFGNode *cs) const
 
JoinEdgeSet::const_iterator getJoinEdgeEnd (const CallICFGNode *cs) const
 
void getJoinSites (const CallGraphNode *routine, InstSet &csSet)
 
- Public Member Functions inherited from SVF::CallGraph
 CallGraph (CGEK k=NormCallGraph)
 Constructor.
 
 CallGraph (const CallGraph &other)
 Copy constructor.
 
virtual ~CallGraph ()
 Destructor.
 
CGEK getKind () const
 Return type of this callgraph.
 
CallEdgeMapgetIndCallMap ()
 Get callees from an indirect callsite.
 
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.
 
void addDirectCallGraphEdge (const CallICFGNode *call, const FunObjVar *callerFun, const FunObjVar *calleeFun)
 Add direct call edges.
 
void addCallGraphNode (const FunObjVar *fun)
 
const CallGraphNodegetCallGraphNode (const std::string &name) const
 Get call graph node.
 
CallGraphNodegetCallGraphNode (NodeID id) const
 
CallGraphNodegetCallGraphNode (const FunObjVar *fun) const
 
CallSiteID getCallSiteID (const CallICFGNode *cs, const FunObjVar *callee) const
 Get CallSiteID.
 
bool hasCallSiteID (const CallICFGNode *cs, const FunObjVar *callee) const
 
const CallSitePairgetCallSitePair (CallSiteID id) const
 
const CallICFGNodegetCallSite (CallSiteID id) const
 
const FunObjVargetCallerOfCallSite (CallSiteID id) const
 
const FunObjVargetCalleeOfCallSite (CallSiteID id) const
 
CallGraphEdgehasGraphEdge (CallGraphNode *src, CallGraphNode *dst, CallGraphEdge::CEDGEK kind, CallSiteID csId) const
 Whether we have already created this call graph edge.
 
CallGraphEdgegetGraphEdge (CallGraphNode *src, CallGraphNode *dst, CallGraphEdge::CEDGEK kind, CallSiteID csId)
 Get call graph edge via nodes.
 
void getCallees (const CallICFGNode *cs, FunctionSet &callees)
 Get all callees for a callsite.
 
bool hasCallGraphEdge (const CallICFGNode *inst) const
 Get call graph edge via call instruction.
 
CallGraphEdgeSet::const_iterator getCallEdgeBegin (const CallICFGNode *inst) const
 
CallGraphEdgeSet::const_iterator getCallEdgeEnd (const CallICFGNode *inst) const
 
void addIndirectCallGraphEdge (const CallICFGNode *cs, const FunObjVar *callerFun, const FunObjVar *calleeFun)
 Add indirect call edges.
 
void getAllCallSitesInvokingCallee (const FunObjVar *callee, CallGraphEdge::CallInstSet &csSet)
 Get callsites invoking the callee.
 
void getDirCallSitesInvokingCallee (const FunObjVar *callee, CallGraphEdge::CallInstSet &csSet)
 
void getIndCallSitesInvokingCallee (const FunObjVar *callee, CallGraphEdge::CallInstSet &csSet)
 
bool isReachableBetweenFunctions (const FunObjVar *srcFn, const FunObjVar *dstFn) const
 Whether its reachable between two functions.
 
void dump (const std::string &filename)
 Dump the graph.
 
void view ()
 View the graph from the debugger.
 
- Public Member Functions inherited from SVF::GenericGraph< NodeTy, EdgeTy >
 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.
 
NodeTypegetGNode (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 ()
 

Static Public Member Functions

static bool classof (const ThreadCallGraph *)
 ClassOf.
 
static bool classof (const CallGraph *g)
 
ThreadAPItdAPI
 Thread API.
 
CallSiteSet forksites
 all thread fork sites
 
CallSiteSet joinsites
 all thread fork sites
 
CallSiteSet parForSites
 all parallel for sites
 
CallInstToForkEdgesMap callinstToThreadForkEdgesMap
 Map a call instruction to its corresponding fork edges.
 
CallInstToJoinEdgesMap callinstToThreadJoinEdgesMap
 Map a call instruction to its corresponding join edges.
 
CallInstToParForEdgesMap callinstToHareParForEdgesMap
 Map a call instruction to its corresponding hare_parallel_for edges.
 
bool isForksite (const CallICFGNode *csInst)
 
bool isJoinsite (const CallICFGNode *csInst)
 
bool isParForSite (const CallICFGNode *csInst)
 
CallSiteSet::const_iterator forksitesBegin () const
 Fork sites iterators.
 
CallSiteSet::const_iterator forksitesEnd () const
 
CallSiteSet::const_iterator joinsitesBegin () const
 Join sites iterators.
 
CallSiteSet::const_iterator joinsitesEnd () const
 
CallSiteSet::const_iterator parForSitesBegin () const
 hare_parallel_for sites iterators
 
CallSiteSet::const_iterator parForSitesEnd () const
 
u32_t getNumOfForksite () const
 Num of fork/join sites.
 
u32_t getNumOfJoinsite () const
 
u32_t getNumOfParForSite () const
 
ThreadAPIgetThreadAPI () const
 Thread API.
 
bool addForksite (const CallICFGNode *cs)
 Add fork sites which directly or indirectly create a thread.
 
bool addJoinsite (const CallICFGNode *cs)
 
bool addParForSite (const CallICFGNode *cs)
 
bool addDirectForkEdge (const CallICFGNode *cs)
 Add direct/indirect thread fork edges.
 
bool addIndirectForkEdge (const CallICFGNode *cs, const FunObjVar *callee)
 
void addDirectJoinEdge (const CallICFGNode *cs, const CallSiteSet &forksite)
 Add thread join edges.
 
void addThreadForkEdgeSetMap (const CallICFGNode *cs, ThreadForkEdge *edge)
 map call instruction to its PTACallGraphEdge map
 
void addThreadJoinEdgeSetMap (const CallICFGNode *cs, ThreadJoinEdge *edge)
 map call instruction to its PTACallGraphEdge map
 
void addHareParForEdgeSetMap (const CallICFGNode *cs, HareParForEdge *edge)
 map call instruction to its PTACallGraphEdge map
 
ThreadJoinEdgehasThreadJoinEdge (const CallICFGNode *call, CallGraphNode *joinFunNode, CallGraphNode *threadRoutineFunNode, CallSiteID csId) const
 has thread join edge
 

Additional Inherited Members

- Public Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
u32_t edgeNum
 total num of node
 
u32_t nodeNum
 total num of edge
 
- Protected Member Functions inherited from SVF::CallGraph
void destroy ()
 Clean up memory.
 
CallSiteID addCallSite (const CallICFGNode *cs, const FunObjVar *callee)
 Add CallSiteID.
 
CallSiteID addCallSite (const CallICFGNode *cs, const FunObjVar *callee, const CallSiteID csid, std::pair< const CallICFGNode *, const FunObjVar * > newCS)
 
void addEdge (CallGraphEdge *edge)
 Add call graph edge.
 
void addDirectCallGraphEdge (CallGraphEdge *cgEdge)
 add direct call graph edge from database [only used this function when loading cgEdges from db results]
 
void addCallGraphNode (CallGraphNode *cgNode)
 add call graph node from database [only used this function when loading cgNodes from db results]
 
CallGraphEdgehasGraphEdge (CallGraphEdge *cgEdge) const
 Whether we have already created this call graph edge.
 
- Protected Attributes inherited from SVF::CallGraph
FunToCallGraphNodeMap funToCallGraphNodeMap
 Call Graph node map.
 
CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap
 Map a call instruction to its corresponding call edges.
 
NodeID callGraphNodeNum
 
u32_t numOfResolvedIndCallEdge
 
CGEK kind
 
- Protected Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
IDToNodeMapTy IDToNodeMap
 node map
 

Detailed Description

Thread sensitive call graph

Definition at line 141 of file ThreadCallGraph.h.

Member Typedef Documentation

◆ CallInstToForkEdgesMap

Definition at line 160 of file ThreadCallGraph.h.

◆ CallInstToJoinEdgesMap

Definition at line 162 of file ThreadCallGraph.h.

◆ CallInstToParForEdgesMap

Definition at line 164 of file ThreadCallGraph.h.

◆ CallSiteSet

Definition at line 157 of file ThreadCallGraph.h.

◆ CtxSet

Definition at line 158 of file ThreadCallGraph.h.

◆ ForkEdgeSet

Definition at line 159 of file ThreadCallGraph.h.

◆ InstSet

Definition at line 156 of file ThreadCallGraph.h.

◆ JoinEdgeSet

Definition at line 161 of file ThreadCallGraph.h.

◆ ParForEdgeSet

Definition at line 163 of file ThreadCallGraph.h.

Constructor & Destructor Documentation

◆ ThreadCallGraph() [1/2]

ThreadCallGraph::ThreadCallGraph ( const CallGraph 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:576
#define DGENERAL
Definition SVFType.h:582
static ThreadAPI * getThreadAPI()
Return a static reference.
Definition ThreadAPI.h:99
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:105
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ ThreadCallGraph() [2/2]

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

◆ ~ThreadCallGraph()

ThreadCallGraph::~ThreadCallGraph ( )
virtual

Destructor.

Definition at line 49 of file ThreadCallGraph.cpp.

50{
51 for (const auto& entry : callinstToThreadJoinEdgesMap)
52 for (ThreadJoinEdge* edge : entry.second)
54}
for(i=0;a &&(i<(size_t) count);i++)
Definition cJSON.cpp:2569
CallInstToJoinEdgesMap callinstToThreadJoinEdgesMap
Map a call instruction to its corresponding join edges.

Member Function Documentation

◆ addDirectForkEdge()

bool ThreadCallGraph::addDirectForkEdge ( const CallICFGNode cs)

Add direct/indirect thread fork edges.

Add direct fork edges

Definition at line 158 of file ThreadCallGraph.cpp.

159{
160
162 const FunValVar* funValvar = SVFUtil::dyn_cast<FunValVar>(tdAPI->getForkedFun(cs));
164 assert(forkee && "callee does not exist");
165 CallGraphNode* callee = getCallGraphNode(forkee->getDefFunForMultipleModule());
166 CallSiteID csId = addCallSite(cs, callee->getFunction());
167
169 {
170 assert(cs->getCaller() == caller->getFunction() && "callee instruction not inside caller??");
171
173 edge->addDirectCallSite(cs);
174
175 addEdge(edge);
177 return true;
178 }
179 else
180 return false;
181}
CallGraphEdge * hasGraphEdge(CallGraphEdge *cgEdge) const
Whether we have already created this call graph edge.
void addEdge(CallGraphEdge *edge)
Add call graph edge.
Definition CallGraph.h:296
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
CallSiteID addCallSite(const CallICFGNode *cs, const FunObjVar *callee)
Add CallSiteID.
Definition CallGraph.h:279
const FunObjVar * getCaller() const
Return callsite.
Definition ICFGNode.h:453
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
const ValVar * getForkedFun(const CallICFGNode *inst) const
void addThreadForkEdgeSetMap(const CallICFGNode *cs, ThreadForkEdge *edge)
map call instruction to its PTACallGraphEdge map
unsigned CallSiteID
Definition GeneralType.h:78

◆ 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 214 of file ThreadCallGraph.cpp.

215{
216
218
219 for (CallSiteSet::const_iterator it = forkset.begin(), eit = forkset.end(); it != eit; ++it)
220 {
221 // The start routine(s) joined here are exactly the targets of the fork
222 // edges already resolved for this fork site (direct, or indirect via
223 // points-to in updateCallGraph). Reuse them rather than re-resolving the
224 // fork target from getForkedFun, which is not a FunValVar for an indirect
225 // fork (function pointer). An unresolved fork site simply has no edges.
226 if (!hasThreadForkEdge(*it))
227 continue;
228 for (ForkEdgeSet::const_iterator eit2 = getForkEdgeBegin(*it),
229 eeit2 = getForkEdgeEnd(*it); eit2 != eeit2; ++eit2)
230 {
231 CallGraphNode* threadRoutineFunNode = (*eit2)->getDstNode();
232 CallSiteID csId = addCallSite(cs, threadRoutineFunNode->getFunction());
233
235 {
236 assert(cs->getCaller() == joinFunNode->getFunction() && "callee instruction not inside caller??");
238 edge->addDirectCallSite(cs);
239
241 }
242 }
243 }
244}
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
ForkEdgeSet::const_iterator getForkEdgeEnd(const CallICFGNode *cs) const
ForkEdgeSet::const_iterator getForkEdgeBegin(const CallICFGNode *cs) const
bool hasThreadForkEdge(const CallICFGNode *cs) const
Get call graph edge via call instruction.

◆ addForksite()

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

Add fork sites which directly or indirectly create a thread.

Definition at line 323 of file ThreadCallGraph.h.

324 {
326 return forksites.insert(cs).second;
327 }
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 373 of file ThreadCallGraph.h.

374 {
375 if(edge!=nullptr)
376 {
379 }
380 }
CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap
Map a call instruction to its corresponding call edges.
Definition CallGraph.h:268
CallInstToParForEdgesMap callinstToHareParForEdgesMap
Map a call instruction to its corresponding hare_parallel_for edges.

◆ addIndirectForkEdge()

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

Add indirect fork edge to update call graph

Definition at line 186 of file ThreadCallGraph.cpp.

187{
190
191 CallSiteID csId = addCallSite(cs, callee->getFunction());
192
194 {
195 assert(cs->getCaller() == caller->getFunction() && "callee instruction not inside caller??");
196
198 edge->addInDirectCallSite(cs);
199
200 addEdge(edge);
202 return true;
203 }
204 else
205 return false;
206}

◆ addJoinsite()

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

Definition at line 328 of file ThreadCallGraph.h.

329 {
331 return joinsites.insert(cs).second;
332 }
CallSiteSet joinsites
all thread fork sites

◆ addParForSite()

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

Definition at line 333 of file ThreadCallGraph.h.

334 {
336 return parForSites.insert(cs).second;
337 }
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 353 of file ThreadCallGraph.h.

354 {
355 if(edge!=nullptr)
356 {
359 }
360 }

◆ addThreadJoinEdgeSetMap()

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

map call instruction to its PTACallGraphEdge map

Definition at line 363 of file ThreadCallGraph.h.

364 {
365 if(edge!=nullptr)
366 {
369 }
370 }

◆ classof() [1/2]

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

Definition at line 180 of file ThreadCallGraph.h.

181 {
182 return g->getKind() == CallGraph::ThdCallGraph;
183 }

◆ classof() [2/2]

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

ClassOf.

Definition at line 176 of file ThreadCallGraph.h.

177 {
178 return true;
179 }

◆ forksitesBegin()

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

Fork sites iterators.

Definition at line 265 of file ThreadCallGraph.h.

266 {
267 return forksites.begin();
268 }

◆ forksitesEnd()

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

Definition at line 269 of file ThreadCallGraph.h.

270 {
271 return forksites.end();
272 }

◆ getForkEdgeBegin()

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

Definition at line 200 of file ThreadCallGraph.h.

201 {
202 CallInstToForkEdgesMap::const_iterator it = callinstToThreadForkEdgesMap.find(cs);
203 assert(it != callinstToThreadForkEdgesMap.end() && "call instruction not found");
204 return it->second.begin();
205 }

◆ getForkEdgeEnd()

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

Definition at line 206 of file ThreadCallGraph.h.

207 {
208 CallInstToForkEdgesMap::const_iterator it = callinstToThreadForkEdgesMap.find(cs);
209 assert(it != callinstToThreadForkEdgesMap.end() && "call instruction not found");
210 return it->second.end();
211 }

◆ getJoinEdgeBegin()

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

Definition at line 220 of file ThreadCallGraph.h.

221 {
222 CallInstToJoinEdgesMap::const_iterator it = callinstToThreadJoinEdgesMap.find(cs);
223 assert(it != callinstToThreadJoinEdgesMap.end() && "call instruction does not have a valid callee");
224 return it->second.begin();
225 }

◆ getJoinEdgeEnd()

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

Definition at line 226 of file ThreadCallGraph.h.

227 {
228 CallInstToJoinEdgesMap::const_iterator it = callinstToThreadJoinEdgesMap.find(cs);
229 assert(it != callinstToThreadJoinEdgesMap.end() && "call instruction does not have a valid callee");
230 return it->second.end();
231 }

◆ getJoinSites()

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

Definition at line 232 of file ThreadCallGraph.h.

233 {
234 for(CallInstToJoinEdgesMap::const_iterator it = callinstToThreadJoinEdgesMap.begin(), eit = callinstToThreadJoinEdgesMap.end(); it!=eit; ++it)
235 {
236 for(JoinEdgeSet::const_iterator jit = it->second.begin(), ejit = it->second.end(); jit!=ejit; ++jit)
237 {
238 if((*jit)->getDstNode() == routine)
239 {
240 csSet.insert(it->first);
241 }
242 }
243 }
244 }

◆ getNumOfForksite()

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

Num of fork/join sites.

Definition at line 301 of file ThreadCallGraph.h.

302 {
303 return forksites.size();
304 }

◆ getNumOfJoinsite()

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

Definition at line 305 of file ThreadCallGraph.h.

306 {
307 return joinsites.size();
308 }

◆ getNumOfParForSite()

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

Definition at line 309 of file ThreadCallGraph.h.

310 {
311 return parForSites.size();
312 }

◆ getThreadAPI()

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

Thread API.

Definition at line 316 of file ThreadCallGraph.h.

317 {
318 return tdAPI;
319 }

◆ 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 195 of file ThreadCallGraph.h.

196 {
197 return callinstToThreadForkEdgesMap.find(cs) !=
199 }

◆ hasThreadJoinEdge() [1/2]

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

has thread join edge

Definition at line 383 of file ThreadCallGraph.h.

384 {
385 ThreadJoinEdge joinEdge(joinFunNode,threadRoutineFunNode, csId);
386 CallInstToJoinEdgesMap::const_iterator it = callinstToThreadJoinEdgesMap.find(call);
387 if(it != callinstToThreadJoinEdgesMap.end())
388 {
389 JoinEdgeSet::const_iterator jit = it->second.find(&joinEdge);
390 if(jit!=it->second.end())
391 return *jit;
392 }
393 return nullptr;
394 }

◆ 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 216 of file ThreadCallGraph.h.

217 {
219 }

◆ isForksite()

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

Whether a callsite is a fork or join or hare_parallel_for

Definition at line 249 of file ThreadCallGraph.h.

250 {
251 return forksites.find(csInst) != forksites.end();
252 }

◆ isJoinsite()

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

Definition at line 253 of file ThreadCallGraph.h.

254 {
255 return joinsites.find(csInst) != joinsites.end();
256 }

◆ isParForSite()

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

Definition at line 257 of file ThreadCallGraph.h.

258 {
259 return parForSites.find(csInst) != parForSites.end();
260 }

◆ joinsitesBegin()

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

Join sites iterators.

Definition at line 277 of file ThreadCallGraph.h.

278 {
279 return joinsites.begin();
280 }

◆ joinsitesEnd()

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

Definition at line 281 of file ThreadCallGraph.h.

282 {
283 return joinsites.end();
284 }

◆ parForSitesBegin()

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

hare_parallel_for sites iterators

Definition at line 289 of file ThreadCallGraph.h.

290 {
291 return parForSites.begin();
292 }

◆ parForSitesEnd()

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

Definition at line 293 of file ThreadCallGraph.h.

294 {
295 return parForSites.end();
296 }

◆ updateCallGraph()

void ThreadCallGraph::updateCallGraph ( PointerAnalysis pta)

Update call graph using pointer results.

Definition at line 84 of file ThreadCallGraph.cpp.

85{
86
87 PointerAnalysis::CallEdgeMap::const_iterator iter = pta->getIndCallMap().begin();
88 PointerAnalysis::CallEdgeMap::const_iterator eiter = pta->getIndCallMap().end();
89 for (; iter != eiter; iter++)
90 {
91 const CallICFGNode* cs = iter->first;
92 const CallGraph::FunctionSet &functions = iter->second;
93 for (CallGraph::FunctionSet::const_iterator func_iter =
94 functions.begin(); func_iter != functions.end(); func_iter++)
95 {
96 const FunObjVar* callee = *func_iter;
98 }
99 }
100
101 // Fork sites
102 for (CallSiteSet::const_iterator it = forksitesBegin(), eit = forksitesEnd(); it != eit; ++it)
103 {
104 const ValVar* forkedval = tdAPI->getForkedFun(*it);
105 if(SVFUtil::dyn_cast<FunValVar>(forkedval)==nullptr)
106 {
107 SVFIR* pag = pta->getPAG();
108 const NodeBS targets = pta->getPts(forkedval->getId()).toNodeBS();
109 for (NodeBS::iterator ii = targets.begin(), ie = targets.end(); ii != ie; ii++)
110 {
111 if(const ObjVar* objPN = pag->getObjVar(*ii))
112 {
113 const BaseObjVar* obj = pag->getBaseObject(objPN->getId());
114 if(obj->isFunction())
115 {
116 const FunObjVar* svfCallee = SVFUtil::cast<FunObjVar>(obj)->getFunction();
117 this->addIndirectForkEdge(*it, svfCallee);
118 }
119 }
120 }
121 }
122 }
123}
void addIndirectCallGraphEdge(const CallICFGNode *cs, const FunObjVar *callerFun, const FunObjVar *calleeFun)
Add indirect call edges.
Set< const FunObjVar * > FunctionSet
Definition CallGraph.h:247
virtual const PointsTo & getPts(NodeID ptr)=0
Get points-to targets of a pointer. It needs to be implemented in child class.
SVFIR * getPAG() const
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
NodeBS toNodeBS() const
Returns this points-to set as a NodeBS.
Definition PointsTo.cpp:313
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:498
const ObjVar * getObjVar(NodeID id) const
Definition SVFIR.h:149
CallSiteSet::const_iterator forksitesEnd() const
CallSiteSet::const_iterator forksitesBegin() const
Fork sites iterators.
bool addIndirectForkEdge(const CallICFGNode *cs, const FunObjVar *callee)

◆ updateJoinEdge()

void ThreadCallGraph::updateJoinEdge ( PointerAnalysis pta)

Update join edge using pointer analysis results.

Update join edge using pointer analysis results

A join may have no statically-matchable fork site (e.g. the pthread_t alias cannot be resolved by the pre-analysis). Skip such joins rather than aborting – they simply get no join-related def-use edge.

Definition at line 129 of file ThreadCallGraph.cpp.

130{
132
133 for (CallSiteSet::const_iterator it = joinsitesBegin(), eit = joinsitesEnd(); it != eit; ++it)
134 {
135 const SVFVar* jointhread = tdAPI->getJoinedThread(*it);
136 // find its corresponding fork sites first
138 for (CallSiteSet::const_iterator it = forksitesBegin(), eit = forksitesEnd(); it != eit; ++it)
139 {
140 const SVFVar* forkthread = tdAPI->getForkedThread(*it);
142 {
143 forkset.insert(*it);
144 }
145 }
149 if (forkset.empty())
150 continue;
152 }
153}
const ValVar * getForkedThread(const CallICFGNode *inst) const
Return arguments/attributes of pthread_create / hare_parallel_for.
const SVFVar * getJoinedThread(const CallICFGNode *inst) const
Return arguments/attributes of pthread_join.
bool isAliasedForkJoin(PointerAnalysis *pta, const SVFVar *forkArg, const SVFVar *joinArg) const
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.
If fork join the same thread.
Definition ThreadAPI.h:158

Member Data Documentation

◆ callinstToHareParForEdgesMap

CallInstToParForEdgesMap SVF::ThreadCallGraph::callinstToHareParForEdgesMap
private

Map a call instruction to its corresponding hare_parallel_for edges.

Definition at line 403 of file ThreadCallGraph.h.

◆ callinstToThreadForkEdgesMap

CallInstToForkEdgesMap SVF::ThreadCallGraph::callinstToThreadForkEdgesMap
private

Map a call instruction to its corresponding fork edges.

Definition at line 401 of file ThreadCallGraph.h.

◆ callinstToThreadJoinEdgesMap

CallInstToJoinEdgesMap SVF::ThreadCallGraph::callinstToThreadJoinEdgesMap
private

Map a call instruction to its corresponding join edges.

Definition at line 402 of file ThreadCallGraph.h.

◆ forksites

CallSiteSet SVF::ThreadCallGraph::forksites
private

all thread fork sites

Definition at line 398 of file ThreadCallGraph.h.

◆ joinsites

CallSiteSet SVF::ThreadCallGraph::joinsites
private

all thread fork sites

Definition at line 399 of file ThreadCallGraph.h.

◆ parForSites

CallSiteSet SVF::ThreadCallGraph::parForSites
private

all parallel for sites

Definition at line 400 of file ThreadCallGraph.h.

◆ tdAPI

ThreadAPI* SVF::ThreadCallGraph::tdAPI
private

Thread API.

Definition at line 397 of file ThreadCallGraph.h.


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