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

#include <ThreadCallGraph.h>

Inheritance diagram for SVF::ThreadCallGraph:
SVF::CallGraph SVF::GenericGraph< CallGraphNode, CallGraphEdge >

Classes

struct  CallSiteIdCmp

Public Types

typedef OrderedSet< const CallICFGNode *, CallSiteIdCmp > InstSet
typedef InstSet CallSiteSet
typedef Set< CallSiteSet * > CtxSet
typedef ThreadForkEdge::ForkEdgeSet ForkEdgeSet
typedef Map< const CallICFGNode *, ForkEdgeSet > CallInstToForkEdgesMap
typedef ThreadJoinEdge::JoinEdgeSet JoinEdgeSet
typedef Map< const CallICFGNode *, JoinEdgeSet > CallInstToJoinEdgesMap
typedef HareParForEdge::ParForEdgeSet ParForEdgeSet
typedef Map< const CallICFGNode *, ParForEdgeSet > CallInstToParForEdgesMap
Public Types inherited from SVF::CallGraph
enum  CGEK { NormCallGraph , ThdCallGraph }
typedef CallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet
typedef Map< const FunObjVar *, CallGraphNode * > FunToCallGraphNodeMap
typedef Map< const CallICFGNode *, CallGraphEdgeSet > CallInstToCallGraphEdgesMap
typedef std::pair< const CallICFGNode *, const FunObjVar * > CallSitePair
typedef Map< CallSitePair, CallSiteID > CallSiteToIdMap
typedef Map< CallSiteID, CallSitePair > IdToCallSiteMap
typedef Set< const FunObjVar * > FunctionSet
typedef OrderedMap< const CallICFGNode *, FunctionSet > CallEdgeMap
typedef CallGraphEdgeSet::iterator CallGraphEdgeIter
typedef CallGraphEdgeSet::const_iterator CallGraphEdgeConstIter
Public Types inherited from SVF::GenericGraph< CallGraphNode, CallGraphEdge >
typedef CallGraphNode NodeType
typedef CallGraphEdge 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.
CallEdgeMap & getIndCallMap ()
 Get callees from an indirect callsite.
bool hasIndCSCallees (const CallICFGNode *cs) const
const FunctionSet & getIndCSCallees (const CallICFGNode *cs) const
u32_t getTotalCallSiteNumber () const
u32_t getNumOfResolvedIndCallEdge () const
const CallInstToCallGraphEdgesMap & getCallInstToCallGraphEdgesMap () 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 CallGraphNode * getCallGraphNode (const std::string &name) const
 Get call graph node.
CallGraphNode * getCallGraphNode (NodeID id) const
CallGraphNode * getCallGraphNode (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 CallSitePair & getCallSitePair (CallSiteID id) const
const CallICFGNode * getCallSite (CallSiteID id) const
const FunObjVar * getCallerOfCallSite (CallSiteID id) const
const FunObjVar * getCalleeOfCallSite (CallSiteID id) const
CallGraphEdge * hasGraphEdge (CallGraphNode *src, CallGraphNode *dst, CallGraphEdge::CEDGEK kind, CallSiteID csId) const
 Whether we have already created this call graph edge.
CallGraphEdge * getGraphEdge (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< CallGraphNode, CallGraphEdge >
 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 ()

Static Public Member Functions

static bool classof (const ThreadCallGraph *)
 ClassOf.
static bool classof (const CallGraph *g)
ThreadAPI * tdAPI
 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
ThreadAPI * getThreadAPI () 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
ThreadJoinEdge * hasThreadJoinEdge (const CallICFGNode *call, CallGraphNode *joinFunNode, CallGraphNode *threadRoutineFunNode, CallSiteID csId) const
 has thread join edge

Additional Inherited Members

Public Attributes inherited from SVF::GenericGraph< CallGraphNode, CallGraphEdge >
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]
CallGraphEdge * hasGraphEdge (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< CallGraphNode, CallGraphEdge >
IDToNodeMapTy IDToNodeMap
 node map

Detailed Description

Thread sensitive call graph

Definition at line 141 of file ThreadCallGraph.h.

Member Typedef Documentation

◆ CallInstToForkEdgesMap

◆ CallInstToJoinEdgesMap

◆ CallInstToParForEdgesMap

◆ CallSiteSet

Definition at line 157 of file ThreadCallGraph.h.

◆ CtxSet

Definition at line 158 of file ThreadCallGraph.h.

◆ ForkEdgeSet

◆ InstSet

◆ JoinEdgeSet

◆ ParForEdgeSet

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
CallGraph(CGEK k=NormCallGraph)
Constructor.
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:121
std::ostream & outs()
Overwrite llvm::outs().
Definition SVFUtil.h:58

◆ 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)
53 delete edge;
54}
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
161 CallGraphNode* caller = getCallGraphNode(cs->getCaller());
162 const FunValVar* funValvar = SVFUtil::dyn_cast<FunValVar>(tdAPI->getForkedFun(cs));
163 const FunObjVar* forkee = funValvar->getFunction();
164 assert(forkee && "callee does not exist");
165 CallGraphNode* callee = getCallGraphNode(forkee->getDefFunForMultipleModule());
166 CallSiteID csId = addCallSite(cs, callee->getFunction());
167
168 if (!hasGraphEdge(caller, callee, CallGraphEdge::TDForkEdge, csId))
169 {
170 assert(cs->getCaller() == caller->getFunction() && "callee instruction not inside caller??");
171
172 ThreadForkEdge* edge = new ThreadForkEdge(caller, callee, csId);
173 edge->addDirectCallSite(cs);
174
175 addEdge(edge);
176 addThreadForkEdgeSetMap(cs, edge);
177 return true;
178 }
179 else
180 return false;
181}
void addDirectCallSite(const CallICFGNode *call)
Add direct and indirect callsite.
Definition CallGraph.cpp:55
const FunObjVar * getFunction() const
Get function of this call node.
Definition CallGraph.h:191
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
const FunObjVar * getDefFunForMultipleModule() const
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
void addThreadForkEdgeSetMap(const CallICFGNode *cs, ThreadForkEdge *edge)
map call instruction to its PTACallGraphEdge map
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
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
217 CallGraphNode* joinFunNode = getCallGraphNode(cs->getCaller());
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
234 if (!hasThreadJoinEdge(cs,joinFunNode,threadRoutineFunNode, csId))
235 {
236 assert(cs->getCaller() == joinFunNode->getFunction() && "callee instruction not inside caller??");
237 ThreadJoinEdge* edge = new ThreadJoinEdge(joinFunNode,threadRoutineFunNode,csId);
238 edge->addDirectCallSite(cs);
239
240 addThreadJoinEdgeSetMap(cs, edge);
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 {
377 callinstToHareParForEdgesMap[cs].insert(edge);
378 callinstToCallGraphEdgesMap[cs].insert(edge);
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{
188 CallGraphNode* caller = getCallGraphNode(cs->getCaller());
189 CallGraphNode* callee = getCallGraphNode(calleefun);
190
191 CallSiteID csId = addCallSite(cs, callee->getFunction());
192
193 if (!hasGraphEdge(caller, callee, CallGraphEdge::TDForkEdge, csId))
194 {
195 assert(cs->getCaller() == caller->getFunction() && "callee instruction not inside caller??");
196
197 ThreadForkEdge* edge = new ThreadForkEdge(caller, callee, csId);
198 edge->addInDirectCallSite(cs);
199
200 addEdge(edge);
201 addThreadForkEdgeSetMap(cs, edge);
202 return true;
203 }
204 else
205 return false;
206}
void addInDirectCallSite(const CallICFGNode *call)
Definition CallGraph.cpp:61

◆ 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 {
357 callinstToThreadForkEdgesMap[cs].insert(edge);
358 callinstToCallGraphEdgesMap[cs].insert(edge);
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 {
367 callinstToThreadJoinEdgesMap[cs].insert(edge);
368 callinstToCallGraphEdgesMap[cs].insert(edge);
369 }
370 }

◆ classof() [1/2]

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]

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;
97 this->addIndirectCallGraphEdge(cs, cs->getCaller(), callee);
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}
bool isFunction() const
object attributes methods
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:325
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:499
const ObjVar * getObjVar(NodeID id) const
Definition SVFIR.h:150
NodeID getId() const
Get ID.
Definition SVFValue.h:158
SparseBitVectorIterator iterator
iterator begin() const
CallSiteSet::const_iterator forksitesEnd() const
CallSiteSet::const_iterator forksitesBegin() const
Fork sites iterators.
bool addIndirectForkEdge(const CallICFGNode *cs, const FunObjVar *callee)
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
SparseBitVector NodeBS
Definition GeneralType.h:82

◆ 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{
131 ThreadAPI::ForkJoinAliasCache aliasCache;
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
137 CallSiteSet forkset;
138 for (CallSiteSet::const_iterator it = forksitesBegin(), eit = forksitesEnd(); it != eit; ++it)
139 {
140 const SVFVar* forkthread = tdAPI->getForkedThread(*it);
141 if (tdAPI->isAliasedForkJoin(pta, forkthread, jointhread, aliasCache))
142 {
143 forkset.insert(*it);
144 }
145 }
149 if (forkset.empty())
150 continue;
151 addDirectJoinEdge(*it,forkset);
152 }
153}
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 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: