Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
SVF::TCT Class Reference

#include <TCT.h>

Inheritance diagram for SVF::TCT:
SVF::GenericGraph< NodeTy, EdgeTy >

Public Types

typedef SVFLoopAndDomInfo::LoopBBs LoopBBs
 
typedef TCTEdge::ThreadCreateEdgeSet ThreadCreateEdgeSet
 
typedef ThreadCreateEdgeSet::iterator TCTNodeIter
 
typedef Set< const FunObjVar * > FunSet
 
typedef std::vector< const ICFGNode * > InstVec
 
typedef Set< const ICFGNode * > InstSet
 
typedef Set< const CallGraphNode * > PTACGNodeSet
 
typedef Map< CxtThread, TCTNode * > CxtThreadToNodeMap
 
typedef Set< std::pair< NodeID, CallStrCxt > > CallStrCxtSet
 
typedef Map< CxtThread, CallStrCxtSetCxtThreadToForkCxtSet
 
typedef Map< CxtThread, const FunObjVar * > CxtThreadToFun
 
typedef Map< const ICFGNode *, LoopBBsInstToLoopMap
 
typedef FIFOWorkList< CxtThreadProcCxtThreadProcVec
 
typedef Set< CxtThreadProcCxtThreadProcSet
 
typedef SCCDetection< CallGraph * > ThreadCallGraphSCC
 
- 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

 TCT (PointerAnalysis *p)
 Constructor.
 
virtual ~TCT ()
 Destructor.
 
ThreadCallGraphgetThreadCallGraph () const
 Get TCG.
 
PointerAnalysisgetPTA () const
 Get PTA.
 
TCTNodegetTCTNode (NodeID id) const
 Get TCT node.
 
TCTEdgehasGraphEdge (TCTNode *src, TCTNode *dst, TCTEdge::CEDGEK kind) const
 Whether we have already created this call graph edge.
 
TCTEdgegetGraphEdge (TCTNode *src, TCTNode *dst, TCTEdge::CEDGEK kind)
 Get call graph edge via nodes.
 
ThreadCreateEdgeSet::const_iterator getChildrenBegin (const TCTNode *node) const
 Get children and parent nodes.
 
ThreadCreateEdgeSet::const_iterator getChildrenEnd (const TCTNode *node) const
 
ThreadCreateEdgeSet::const_iterator getParentsBegin (const TCTNode *node) const
 
ThreadCreateEdgeSet::const_iterator getParentsEnd (const TCTNode *node) const
 
const FunSetgetMakredProcs () const
 Get marked candidate functions.
 
const FunSetgetEntryProcs () const
 Get marked candidate functions.
 
u32_t getTCTNodeNum () const
 Get Statistics.
 
u32_t getTCTEdgeNum () const
 
u32_t getMaxCxtSize () const
 
bool isExtCall (const ICFGNode *inst)
 Whether it is calling an external function.
 
bool isCallSite (const ICFGNode *inst)
 Whether it is a callsite.
 
bool hasTCTNode (const CxtThread &ct) const
 Find/Get TCT node.
 
TCTNodegetTCTNode (const CxtThread &ct) const
 
bool isCandidateFun (const CallGraph::FunctionSet &callees) const
 Whether it is a candidate function for indirect call.
 
bool isCandidateFun (const FunObjVar *fun) const
 
bool inSameCallGraphSCC (const CallGraphNode *src, const CallGraphNode *dst)
 Whether two functions in the same callgraph scc.
 
bool hasParentThread (NodeID tid) const
 Get parent and sibling threads.
 
NodeBS getParentThreads (NodeID tid) const
 Get parent threads.
 
const NodeBS getAncestorThreads (NodeID tid) const
 Get all ancestor threads.
 
const NodeBS getSiblingThread (NodeID tid) const
 Get sibling threads.
 
const CallStrCxtSetgetCxtOfCxtThread (const CxtThread &ct) const
 get the contexts of a thread at its spawning sites (fork sites)
 
const FunObjVargetStartRoutineOfCxtThread (const CxtThread &ct) const
 get the start routine function of a thread
 
LoopBBsgetJoinLoop (const CallICFGNode *join)
 Get loop for join site.
 
bool hasJoinLoop (const CallICFGNode *join) const
 
bool hasLoop (const SVFBasicBlock *bb) const
 
bool hasLoop (const ICFGNode *inst) const
 
bool isJoinMustExecutedInLoop (const LoopBBs &lp, const ICFGNode *join)
 Return true if a join instruction must be executed inside a loop.
 
const LoopBBsgetLoop (const ICFGNode *inst)
 Get loop for an instruction.
 
const LoopBBsgetLoop (const SVFBasicBlock *bb)
 Get loop for fork/join site.
 
void pushCxt (CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
 Context helper functions.
 
bool matchAndPopCxt (CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
 Match context.
 
bool isContextSuffix (const CallStrCxt &lhs, const CallStrCxt &call)
 If lhs is a suffix of rhs, including equal.
 
bool isJoinSiteInRecursion (const CallICFGNode *join) const
 Whether a join site is in recursion.
 
void dumpCxt (CallStrCxt &cxt)
 Dump calling context.
 
void dump (const std::string &filename)
 Dump the graph.
 
void print () const
 Print TCT information.
 
- 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 ()
 

Private Member Functions

TCTNodeaddTCTNode (const CxtThread &ct)
 Add TCT node.
 
bool addTCTEdge (TCTNode *src, TCTNode *dst)
 Add TCT edge.
 
void build ()
 Build TCT.
 
void markRelProcs ()
 Mark relevant procedures that are backward reachable from any fork/join site.
 
void markRelProcs (const FunObjVar *fun)
 
void collectEntryFunInCallGraph ()
 Get entry functions that are neither called by other functions nor extern functions.
 
void collectMultiForkedThreads ()
 
void collectLoopInfoForJoin ()
 Handle join site in loop.
 
bool isLoopHeaderOfJoinLoop (const SVFBasicBlock *bb)
 Whether a given bb is a loop head of a inloop join site.
 
bool isLoopExitOfJoinLoop (const SVFBasicBlock *bb)
 Whether a given bb is an exit of a inloop join site.
 
bool isInLoopInstruction (const ICFGNode *inst)
 Multi-forked threads.
 
bool isInRecursion (const ICFGNode *inst) const
 Whether an instruction is in a recursion.
 
void handleCallRelation (CxtThreadProc &ctp, const CallGraphEdge *cgEdge, const CallICFGNode *call)
 Handle call relations.
 
TCTNodegetOrCreateTCTNode (const CallStrCxt &cxt, const ICFGNode *fork, const CxtThreadProc &forkSiteCtp, const FunObjVar *routine)
 Get or create a tct node based on CxtThread.
 
void setMultiForkedAttrs (CxtThread &ct)
 Set multi-forked thread attributes.
 
void addCxtOfCxtThread (NodeID pTid, const CallStrCxt &cxt, const CxtThread &ct)
 Add context for a thread at its spawning site (fork site)
 
void addStartRoutineOfCxtThread (const FunObjVar *fun, const CxtThread &ct)
 Add start routine function of a cxt thread.
 
bool pushToCTPWorkList (const CxtThreadProc &ctp)
 WorkList helper functions.
 
CxtThreadProc popFromCTPWorkList ()
 
bool isVisitedCTPs (const CxtThreadProc &ctp) const
 

Private Attributes

ThreadCallGraphtcg
 
PointerAnalysispta
 
u32_t TCTNodeNum
 
u32_t TCTEdgeNum
 
u32_t MaxCxtSize
 
FunSet entryFuncSet
 
FunSet candidateFuncSet
 Procedures that are neither called by other functions nor extern functions.
 
ThreadCallGraphSCCtcgSCC
 Procedures we care about during call graph traversing when creating TCT.
 
CxtThreadProcVec ctpList
 Thread call graph SCC.
 
CxtThreadProcSet visitedCTPs
 CxtThreadProc List.
 
CxtThreadToNodeMap ctpToNodeMap
 Record all visited ctps.
 
CxtThreadToForkCxtSet ctToForkCxtsMap
 Map a ctp to its graph node.
 
CxtThreadToFun ctToRoutineFunMap
 Map a CxtThread to the context at its spawning site (fork site).
 
InstToLoopMap joinSiteToLoopMap
 Map a CxtThread to its start routine function.
 
Set< const ICFGNode * > inRecurJoinSites
 Fork or Join sites in recursions.
 

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 Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
IDToNodeMapTy IDToNodeMap
 node map
 

Detailed Description

Definition at line 155 of file TCT.h.

Member Typedef Documentation

◆ CallStrCxtSet

Definition at line 167 of file TCT.h.

◆ CxtThreadProcSet

Definition at line 172 of file TCT.h.

◆ CxtThreadProcVec

Definition at line 171 of file TCT.h.

◆ CxtThreadToForkCxtSet

Definition at line 168 of file TCT.h.

◆ CxtThreadToFun

Definition at line 169 of file TCT.h.

◆ CxtThreadToNodeMap

Definition at line 166 of file TCT.h.

◆ FunSet

Definition at line 162 of file TCT.h.

◆ InstSet

Definition at line 164 of file TCT.h.

◆ InstToLoopMap

Definition at line 170 of file TCT.h.

◆ InstVec

Definition at line 163 of file TCT.h.

◆ LoopBBs

Definition at line 159 of file TCT.h.

◆ PTACGNodeSet

Definition at line 165 of file TCT.h.

◆ TCTNodeIter

typedef ThreadCreateEdgeSet::iterator SVF::TCT::TCTNodeIter

Definition at line 161 of file TCT.h.

◆ ThreadCallGraphSCC

Definition at line 173 of file TCT.h.

◆ ThreadCreateEdgeSet

Definition at line 160 of file TCT.h.

Constructor & Destructor Documentation

◆ TCT()

SVF::TCT::TCT ( PointerAnalysis p)
inline

Constructor.

Definition at line 176 of file TCT.h.

177 {
178 tcg = SVFUtil::dyn_cast<ThreadCallGraph>(pta->getCallGraph());
179 assert(tcg != nullptr && "TCT::TCT: call graph is not a ThreadCallGraph!");
181 //tcg->updateJoinEdge(pta);
183 tcgSCC->find();
184 build();
185 }
cJSON * p
Definition cJSON.cpp:2559
CallGraph * getCallGraph() const
Return call graph.
CallGraphSCC * getCallGraphSCC() const
Return call graph SCC.
ThreadCallGraphSCC * tcgSCC
Procedures we care about during call graph traversing when creating TCT.
Definition TCT.h:587
u32_t TCTNodeNum
Definition TCT.h:448
u32_t TCTEdgeNum
Definition TCT.h:449
PointerAnalysis * pta
Definition TCT.h:447
u32_t MaxCxtSize
Definition TCT.h:450
void build()
Build TCT.
Definition TCT.cpp:387
ThreadCallGraph * tcg
Definition TCT.h:446
void updateCallGraph(PointerAnalysis *pta)
Update call graph using pointer results.
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ ~TCT()

virtual SVF::TCT::~TCT ( )
inlinevirtual

Destructor.

Definition at line 188 of file TCT.h.

189 { }

Member Function Documentation

◆ addCxtOfCxtThread()

void SVF::TCT::addCxtOfCxtThread ( NodeID  pTid,
const CallStrCxt cxt,
const CxtThread ct 
)
inlineprivate

Add context for a thread at its spawning site (fork site)

Definition at line 552 of file TCT.h.

553 {
554 ctToForkCxtsMap[ct].insert(std::make_pair(pTid, cxt));
555 }
CxtThreadToForkCxtSet ctToForkCxtsMap
Map a ctp to its graph node.
Definition TCT.h:591

◆ addStartRoutineOfCxtThread()

void SVF::TCT::addStartRoutineOfCxtThread ( const FunObjVar fun,
const CxtThread ct 
)
inlineprivate

Add start routine function of a cxt thread.

Definition at line 558 of file TCT.h.

559 {
560 ctToRoutineFunMap[ct] = fun;
561 }
CxtThreadToFun ctToRoutineFunMap
Map a CxtThread to the context at its spawning site (fork site).
Definition TCT.h:592

◆ addTCTEdge()

bool SVF::TCT::addTCTEdge ( TCTNode src,
TCTNode dst 
)
inlineprivate

Add TCT edge.

Definition at line 464 of file TCT.h.

465 {
467 {
468 TCTEdge* edge = new TCTEdge(src, dst, TCTEdge::ThreadCreateEdge);
469 dst->addIncomingEdge(edge);
470 src->addOutgoingEdge(edge);
471 TCTEdgeNum++;
472 return true;
473 }
474 return false;
475 }
@ ThreadCreateEdge
Definition TCT.h:57
TCTEdge * hasGraphEdge(TCTNode *src, TCTNode *dst, TCTEdge::CEDGEK kind) const
Whether we have already created this call graph edge.
Definition TCT.cpp:555

◆ addTCTNode()

TCTNode * SVF::TCT::addTCTNode ( const CxtThread ct)
inlineprivate

Add TCT node.

Definition at line 453 of file TCT.h.

454 {
455 assert(ctpToNodeMap.find(ct)==ctpToNodeMap.end() && "Already has this node!!");
456 NodeID id = TCTNodeNum;
457 TCTNode* node = new TCTNode(id, ct);
458 addGNode(id, node);
459 TCTNodeNum++;
460 ctpToNodeMap[ct] = node;
461 return node;
462 }
void addGNode(NodeID id, NodeType *node)
Add a Node.
CxtThreadToNodeMap ctpToNodeMap
Record all visited ctps.
Definition TCT.h:590
u32_t NodeID
Definition GeneralType.h:76

◆ build()

void TCT::build ( )
private

Build TCT.

Start building TCT

Definition at line 387 of file TCT.cpp.

388{
389
390 markRelProcs();
391
393
394 // the fork site of main function is initialized with nullptr.
395 // the context of main is initialized with empty
396 // start routine is empty
397
399 for (FunSet::iterator it=entryFuncSet.begin(), eit=entryFuncSet.end(); it!=eit; ++it)
400 {
401 if (!isCandidateFun(*it))
402 continue;
403 CallStrCxt cxt;
404 CxtThreadProc dummyCtp(-1, cxt, nullptr);
406 CxtThreadProc t(mainTCTNode->getId(), cxt, *it);
408 }
409
410 while(!ctpList.empty())
411 {
413 CallGraphNode* cgNode = tcg->getCallGraphNode(ctp.getProc());
414 if(isCandidateFun(cgNode->getFunction()) == false)
415 continue;
416
417 for(CallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit!=neit; nit++)
418 {
419 const CallGraphEdge* cgEdge = (*nit);
420
421 for(CallGraphEdge::CallInstSet::const_iterator cit = cgEdge->directCallsBegin(),
422 ecit = cgEdge->directCallsEnd(); cit!=ecit; ++cit)
423 {
424 DBOUT(DMTA,outs() << "\nTCT handling direct call:" << **cit << "\t" << cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
426 }
427 for(CallGraphEdge::CallInstSet::const_iterator ind = cgEdge->indirectCallsBegin(),
428 eind = cgEdge->indirectCallsEnd(); ind!=eind; ++ind)
429 {
430 DBOUT(DMTA,outs() << "\nTCT handling indirect call:" << **ind << "\t" << cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
432 }
433 }
434 }
435
437
439 {
440 print();
441 dump("tct");
442 }
443
444}
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:576
#define DMTA
Definition SVFType.h:597
const FunObjVar * getFunction() const
Get function of this call node.
Definition CallGraph.h:191
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
bool empty() const
Definition WorkList.h:161
iterator OutEdgeEnd()
iterator OutEdgeBegin()
iterators
GEdgeSetTy::const_iterator const_iterator
static const Option< bool > TCTDotGraph
Definition Options.h:162
bool pushToCTPWorkList(const CxtThreadProc &ctp)
WorkList helper functions.
Definition TCT.h:565
FunSet entryFuncSet
Definition TCT.h:585
TCTNode * getOrCreateTCTNode(const CallStrCxt &cxt, const ICFGNode *fork, const CxtThreadProc &forkSiteCtp, const FunObjVar *routine)
Get or create a tct node based on CxtThread.
Definition TCT.h:516
void collectLoopInfoForJoin()
Handle join site in loop.
Definition TCT.cpp:318
void collectEntryFunInCallGraph()
Get entry functions that are neither called by other functions nor extern functions.
Definition TCT.cpp:187
void dump(const std::string &filename)
Dump the graph.
Definition TCT.cpp:535
bool isCandidateFun(const CallGraph::FunctionSet &callees) const
Whether it is a candidate function for indirect call.
Definition TCT.h:287
CxtThreadProcVec ctpList
Thread call graph SCC.
Definition TCT.h:588
void markRelProcs()
Mark relevant procedures that are backward reachable from any fork/join site.
Definition TCT.cpp:133
void print() const
Print TCT information.
Definition TCT.cpp:543
void handleCallRelation(CxtThreadProc &ctp, const CallGraphEdge *cgEdge, const CallICFGNode *call)
Handle call relations.
Definition TCT.cpp:245
void collectMultiForkedThreads()
Definition TCT.cpp:207
CxtThreadProc popFromCTPWorkList()
Definition TCT.h:574
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52
std::vector< u32_t > CallStrCxt
Definition GeneralType.h:96

◆ collectEntryFunInCallGraph()

void TCT::collectEntryFunInCallGraph ( )
private

Get entry functions that are neither called by other functions nor extern functions.

Get entry function, i.e., functions without callers, e.g., main function

Definition at line 187 of file TCT.cpp.

188{
190 for (const auto& item: *svfirCallGraph)
191 {
192 const FunObjVar* fun = item.second->getFunction();
193 if (SVFUtil::isExtCall(fun))
194 continue;
195 CallGraphNode* node = tcg->getCallGraphNode(fun);
196 if (!node->hasIncomingEdge())
197 {
198 entryFuncSet.insert(fun);
199 }
200 }
201 assert(!entryFuncSet.empty() && "Can't find any function in module!");
202}
cJSON * item
Definition cJSON.h:222
bool hasIncomingEdge() const
Has incoming/outgoing edge set.
const CallGraph * getCallGraph()
Get CG.
Definition SVFIR.h:248
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:120
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:441

◆ collectLoopInfoForJoin()

void TCT::collectLoopInfoForJoin ( )
private

Handle join site in loop.

collect loop info for join sites

Collect loop info for join sites the in-loop join site must be joined if the loop is executed

Definition at line 318 of file TCT.cpp.

319{
320 for(ThreadCallGraph::CallSiteSet::const_iterator it = tcg->joinsitesBegin(), eit = tcg->joinsitesEnd(); it!=eit; ++it)
321 {
322 const ICFGNode* join = *it;
323 const FunObjVar* svffun = join->getFun();
324 const SVFBasicBlock* svfbb = join->getBB();
325
326 if(svffun->hasLoopInfo(svfbb))
327 {
328 const LoopBBs& lp = svffun->getLoopInfo(svfbb);
329 if(!lp.empty() && isJoinMustExecutedInLoop(lp,join))
330 {
332 }
333 }
334
336 inRecurJoinSites.insert(join);
337 }
338}
bool isInRecursion(const ICFGNode *inst) const
Whether an instruction is in a recursion.
Definition TCT.cpp:91
InstToLoopMap joinSiteToLoopMap
Map a CxtThread to its start routine function.
Definition TCT.h:593
bool isJoinMustExecutedInLoop(const LoopBBs &lp, const ICFGNode *join)
Return true if a join instruction must be executed inside a loop.
Definition TCT.cpp:294
Set< const ICFGNode * > inRecurJoinSites
Fork or Join sites in recursions.
Definition TCT.h:594
SVFLoopAndDomInfo::LoopBBs LoopBBs
Definition TCT.h:159
CallSiteSet::const_iterator joinsitesEnd() const
CallSiteSet::const_iterator joinsitesBegin() const
Join sites iterators.

◆ collectMultiForkedThreads()

void TCT::collectMultiForkedThreads ( )
private

Collect multi-forked threads whose 1, cxt is in loop or recursion; 2, parent thread is a multi-forked thread.

Collect all multi-forked threads

Definition at line 207 of file TCT.cpp.

208{
209 if (this->nodeNum == 0 )
210 return;
211
212 FIFOWorkList<TCTNode*> worklist;
213 worklist.push(getTCTNode(0));
214
215 while(!worklist.empty())
216 {
217 TCTNode* node = worklist.pop();
218 const CxtThread &ct = node->getCxtThread();
219
220 if(ct.isIncycle() || ct.isInloop())
221 {
222 node->setMultiforked(true);
223 }
224 else
225 {
226 for (TCT::ThreadCreateEdgeSet::const_iterator it = node->getInEdges().begin(), eit = node->getInEdges().end(); it != eit;
227 ++it)
228 {
229 if ((*it)->getSrcNode()->isMultiforked())
230 node->setMultiforked(true);
231 }
232 }
233 for (TCT::ThreadCreateEdgeSet::const_iterator it = node->getOutEdges().begin(), eit = node->getOutEdges().end(); it != eit;
234 ++it)
235 {
236 worklist.push((*it)->getDstNode());
237 }
238 }
239}
bool push(const Data &data)
Definition WorkList.h:180
u32_t nodeNum
total num of edge
const GEdgeSetTy & getOutEdges() const
const GEdgeSetTy & getInEdges() const
const CxtThread & getCxtThread() const
Get thread creation context, <fork site, call string context>
Definition TCT.h:103
void setMultiforked(bool value)
Definition TCT.h:118
TCTNode * getTCTNode(NodeID id) const
Get TCT node.
Definition TCT.h:202

◆ dump()

void TCT::dump ( const std::string &  filename)

Dump the graph.

Dump call graph into dot file

Definition at line 535 of file TCT.cpp.

536{
538}
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)

◆ dumpCxt()

void TCT::dumpCxt ( CallStrCxt cxt)

Dump calling context.

Dump calling context information

Definition at line 517 of file TCT.cpp.

518{
519 std::string str;
520 std::stringstream rawstr(str);
521 rawstr << "[:";
522 for(CallStrCxt::const_iterator it = cxt.begin(), eit = cxt.end(); it!=eit; ++it)
523 {
524 rawstr << " ' "<< *it << " ' ";
525 rawstr << (tcg->getCallSite(*it))->valueOnlyToString();
526 rawstr << " call " << tcg->getCallSite(*it)->getCaller()->getName() << "-->" << tcg->getCalleeOfCallSite(*it)->getName() << ", \n";
527 }
528 rawstr << " ]";
529 outs() << "max cxt = " << cxt.size() << rawstr.str() << "\n";
530}
const CallICFGNode * getCallSite(CallSiteID id) const
Definition CallGraph.h:408
const FunObjVar * getCalleeOfCallSite(CallSiteID id) const
Definition CallGraph.h:413
const FunObjVar * getCaller() const
Return callsite.
Definition ICFGNode.h:453
virtual const std::string & getName() const
Definition SVFValue.h:186

◆ getAncestorThreads()

const NodeBS SVF::TCT::getAncestorThreads ( NodeID  tid) const
inline

Get all ancestor threads.

Definition at line 329 of file TCT.h.

330 {
331 NodeBS tds;
332 if(hasParentThread(tid) == false)
333 return tds;
334
335 FIFOWorkList<NodeID> worklist;
337 worklist.push(parentTid);
338
339 while(!worklist.empty())
340 {
341 NodeID t = worklist.pop();
342 if(tds.test_and_set(t))
343 {
344 if(hasParentThread(t))
346 worklist.push(parentTid);
347 }
348 }
349 return tds;
350 }
NodeBS getParentThreads(NodeID tid) const
Get parent threads.
Definition TCT.h:316
bool hasParentThread(NodeID tid) const
Get parent and sibling threads.
Definition TCT.h:310
SparseBitVector NodeBS
Definition GeneralType.h:82

◆ getChildrenBegin()

ThreadCreateEdgeSet::const_iterator SVF::TCT::getChildrenBegin ( const TCTNode node) const
inline

Get children and parent nodes.

Definition at line 213 of file TCT.h.

214 {
215 return node->OutEdgeBegin();
216 }

◆ getChildrenEnd()

ThreadCreateEdgeSet::const_iterator SVF::TCT::getChildrenEnd ( const TCTNode node) const
inline

Definition at line 217 of file TCT.h.

218 {
219 return node->OutEdgeEnd();
220 }

◆ getCxtOfCxtThread()

const CallStrCxtSet & SVF::TCT::getCxtOfCxtThread ( const CxtThread ct) const
inline

get the contexts of a thread at its spawning sites (fork sites)

Definition at line 373 of file TCT.h.

374 {
375 CxtThreadToForkCxtSet::const_iterator it = ctToForkCxtsMap.find(ct);
376 assert(it!=ctToForkCxtsMap.end() && "Cxt Thread not found!!");
377 return it->second;
378 }

◆ getEntryProcs()

const FunSet & SVF::TCT::getEntryProcs ( ) const
inline

Get marked candidate functions.

Definition at line 238 of file TCT.h.

239 {
240 return entryFuncSet;
241 }

◆ getGraphEdge()

TCTEdge * TCT::getGraphEdge ( TCTNode src,
TCTNode dst,
TCTEdge::CEDGEK  kind 
)

Get call graph edge via nodes.

get PTACallGraph edge via nodes

Definition at line 572 of file TCT.cpp.

573{
574 for (TCTEdge::ThreadCreateEdgeSet::const_iterator iter = src->OutEdgeBegin(); iter != src->OutEdgeEnd(); ++iter)
575 {
576 TCTEdge* edge = (*iter);
577 if (edge->getEdgeKind() == kind && edge->getDstID() == dst->getId())
578 return edge;
579 }
580 return nullptr;
581}
NodeID getId() const
Get ID.
Definition SVFValue.h:160

◆ getJoinLoop()

LoopBBs & SVF::TCT::getJoinLoop ( const CallICFGNode join)
inline

Get loop for join site.

Definition at line 389 of file TCT.h.

390 {
391 assert(tcg->getThreadAPI()->isTDJoin(join) && "not a join site");
392 InstToLoopMap::iterator it = joinSiteToLoopMap.find(join);
393 assert(it!=joinSiteToLoopMap.end() && "loop not found");
394 return it->second;
395 }
bool isTDJoin(const CallICFGNode *inst) const
Return true if this call wait for a worker thread.
ThreadAPI * getThreadAPI() const
Thread API.

◆ getLoop() [1/2]

const LoopBBs & SVF::TCT::getLoop ( const ICFGNode inst)

Get loop for an instruction.

◆ getLoop() [2/2]

const TCT::LoopBBs & TCT::getLoop ( const SVFBasicBlock bb)

Get loop for fork/join site.

Get loop for fork/join site

Definition at line 378 of file TCT.cpp.

379{
380 const FunObjVar* fun = bb->getParent();
381 return fun->getLoopInfo(bb);
382}
const LoopBBs & getLoopInfo(const SVFBasicBlock *bb) const
const FunObjVar * getParent() const

◆ getMakredProcs()

const FunSet & SVF::TCT::getMakredProcs ( ) const
inline

Get marked candidate functions.

Definition at line 232 of file TCT.h.

233 {
234 return candidateFuncSet;
235 }
FunSet candidateFuncSet
Procedures that are neither called by other functions nor extern functions.
Definition TCT.h:586

◆ getMaxCxtSize()

u32_t SVF::TCT::getMaxCxtSize ( ) const
inline

Definition at line 253 of file TCT.h.

254 {
255 return MaxCxtSize;
256 }

◆ getOrCreateTCTNode()

TCTNode * SVF::TCT::getOrCreateTCTNode ( const CallStrCxt cxt,
const ICFGNode fork,
const CxtThreadProc forkSiteCtp,
const FunObjVar routine 
)
inlineprivate

Get or create a tct node based on CxtThread.

Definition at line 516 of file TCT.h.

517 {
518 CxtThread ct(cxt,fork);
519 CxtThreadToNodeMap::const_iterator it = ctpToNodeMap.find(ct);
520 if(it!=ctpToNodeMap.end())
521 {
522 return it->second;
523 }
524
525 addCxtOfCxtThread(forkSiteCtp.getTid(), forkSiteCtp.getContext(), ct);
527
529 return addTCTNode(ct);
530 }
void setMultiForkedAttrs(CxtThread &ct)
Set multi-forked thread attributes.
Definition TCT.h:534
void addCxtOfCxtThread(NodeID pTid, const CallStrCxt &cxt, const CxtThread &ct)
Add context for a thread at its spawning site (fork site)
Definition TCT.h:552
void addStartRoutineOfCxtThread(const FunObjVar *fun, const CxtThread &ct)
Add start routine function of a cxt thread.
Definition TCT.h:558
TCTNode * addTCTNode(const CxtThread &ct)
Add TCT node.
Definition TCT.h:453

◆ getParentsBegin()

ThreadCreateEdgeSet::const_iterator SVF::TCT::getParentsBegin ( const TCTNode node) const
inline

Definition at line 221 of file TCT.h.

222 {
223 return node->InEdgeBegin();
224 }

◆ getParentsEnd()

ThreadCreateEdgeSet::const_iterator SVF::TCT::getParentsEnd ( const TCTNode node) const
inline

Definition at line 225 of file TCT.h.

226 {
227 return node->InEdgeEnd();
228 }

◆ getParentThreads()

NodeBS SVF::TCT::getParentThreads ( NodeID  tid) const
inline

Get parent threads.

Definition at line 316 of file TCT.h.

317 {
319 const TCTNode* node = getTCTNode(tid);
320 assert(node->getInEdges().size()>=1 && "does not have a parent thread");
321
322 for (const TCTEdge* edge : node->getInEdges())
323 {
324 parentTds.set(edge->getSrcID());
325 }
326 return parentTds;
327 }

◆ getPTA()

PointerAnalysis * SVF::TCT::getPTA ( ) const
inline

Get PTA.

Definition at line 197 of file TCT.h.

198 {
199 return pta;
200 }

◆ getSiblingThread()

const NodeBS SVF::TCT::getSiblingThread ( NodeID  tid) const
inline

Get sibling threads.

Definition at line 352 of file TCT.h.

353 {
354 NodeBS tds;
355 if(hasParentThread(tid) == false)
356 return tds;
358 {
359 const TCTNode* parentNode = getTCTNode(parentTid);
360 for(ThreadCreateEdgeSet::const_iterator it = getChildrenBegin(parentNode),
362 {
363 NodeID child = (*it)->getDstNode()->getId();
364 if(child!=tid)
365 tds.set(child);
366 }
367 }
368 return tds;
369 }
cJSON * child
Definition cJSON.cpp:2723
ThreadCreateEdgeSet::const_iterator getChildrenBegin(const TCTNode *node) const
Get children and parent nodes.
Definition TCT.h:213
ThreadCreateEdgeSet::const_iterator getChildrenEnd(const TCTNode *node) const
Definition TCT.h:217

◆ getStartRoutineOfCxtThread()

const FunObjVar * SVF::TCT::getStartRoutineOfCxtThread ( const CxtThread ct) const
inline

get the start routine function of a thread

Definition at line 381 of file TCT.h.

382 {
383 CxtThreadToFun::const_iterator it = ctToRoutineFunMap.find(ct);
384 assert(it!=ctToRoutineFunMap.end() && "Cxt Thread not found!!");
385 return it->second;
386 }

◆ getTCTEdgeNum()

u32_t SVF::TCT::getTCTEdgeNum ( ) const
inline

Definition at line 249 of file TCT.h.

250 {
251 return TCTEdgeNum;
252 }

◆ getTCTNode() [1/2]

TCTNode * SVF::TCT::getTCTNode ( const CxtThread ct) const
inline

Definition at line 278 of file TCT.h.

279 {
280 CxtThreadToNodeMap::const_iterator it = ctpToNodeMap.find(ct);
281 assert(it!=ctpToNodeMap.end() && "TCT node not found??");
282 return it->second;
283 }

◆ getTCTNode() [2/2]

TCTNode * SVF::TCT::getTCTNode ( NodeID  id) const
inline

Get TCT node.

Definition at line 202 of file TCT.h.

203 {
204 return getGNode(id);
205 }
NodeType * getGNode(NodeID id) const
Get a node.

◆ getTCTNodeNum()

u32_t SVF::TCT::getTCTNodeNum ( ) const
inline

Get Statistics.

Definition at line 245 of file TCT.h.

246 {
247 return TCTNodeNum;
248 }

◆ getThreadCallGraph()

ThreadCallGraph * SVF::TCT::getThreadCallGraph ( ) const
inline

Get TCG.

Definition at line 192 of file TCT.h.

193 {
194 return tcg;
195 }

◆ handleCallRelation()

void TCT::handleCallRelation ( CxtThreadProc ctp,
const CallGraphEdge cgEdge,
const CallICFGNode cs 
)
private

Handle call relations.

Handle call relations

handle calling context for candidate functions only

Create spawnee TCT node

Add TCT nodes and edge

Definition at line 245 of file TCT.cpp.

246{
247 const FunObjVar* callee = cgEdge->getDstNode()->getFunction();
248
249 CallStrCxt cxt(ctp.getContext());
250 CallStrCxt oldCxt = cxt;
251 const CallICFGNode* callNode = cs;
252
254 if(isCandidateFun(callNode->getFun()) == true)
256
257 if(cgEdge->getEdgeKind() == CallGraphEdge::CallRetEdge)
258 {
259 CxtThreadProc newctp(ctp.getTid(),cxt,callee);
261 {
262 DBOUT(DMTA,outs() << "TCT Process CallRet old ctp --"; ctp.dump());
263 DBOUT(DMTA,outs() << "TCT Process CallRet new ctp --"; newctp.dump());
264 }
265 }
266
267 else if(cgEdge->getEdgeKind() == CallGraphEdge::TDForkEdge)
268 {
272
274 {
276 if(addTCTEdge(this->getTCTNode(ctp.getTid()), spawneeNode))
277 {
278 DBOUT(DMTA,outs() << "Add TCT Edge from thread " << ctp.getTid() << " ";
279 this->getTCTNode(ctp.getTid())->getCxtThread().dump();
280 outs() << " to thread " << spawneeNode->getId() << " ";
281 spawneeNode->getCxtThread().dump();
282 outs() << "\n" );
283 }
284 DBOUT(DMTA,outs() << "TCT Process Fork old ctp --"; ctp.dump());
285 DBOUT(DMTA,outs() << "TCT Process Fork new ctp --"; newctp.dump());
286 }
287 }
288}
NodeID getTid() const
Return current thread id.
Definition CxtStmt.h:410
void dump() const
Dump CxtThread.
Definition CxtStmt.h:277
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
bool addTCTEdge(TCTNode *src, TCTNode *dst)
Add TCT edge.
Definition TCT.h:464
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Context helper functions.
Definition TCT.cpp:449

◆ hasGraphEdge()

TCTEdge * TCT::hasGraphEdge ( TCTNode src,
TCTNode dst,
TCTEdge::CEDGEK  kind 
) const

Whether we have already created this call graph edge.

Whether we have already created this call graph edge

Definition at line 555 of file TCT.cpp.

556{
557 TCTEdge edge(src, dst, kind);
560 if (outEdge && inEdge)
561 {
562 assert(outEdge == inEdge && "edges not match");
563 return outEdge;
564 }
565 else
566 return nullptr;
567}
bool hasOutgoingEdge() const

◆ hasJoinLoop()

bool SVF::TCT::hasJoinLoop ( const CallICFGNode join) const
inline

Definition at line 397 of file TCT.h.

398 {
399 assert(tcg->getThreadAPI()->isTDJoin(join) && "not a join site");
400 InstToLoopMap::const_iterator it = joinSiteToLoopMap.find(join);
401 return it!=joinSiteToLoopMap.end();
402 }

◆ hasLoop() [1/2]

bool SVF::TCT::hasLoop ( const ICFGNode inst) const
inline

Definition at line 409 of file TCT.h.

410 {
411 return hasLoop(inst->getBB());
412 }
bool hasLoop(const SVFBasicBlock *bb) const
Definition TCT.h:404

◆ hasLoop() [2/2]

bool SVF::TCT::hasLoop ( const SVFBasicBlock bb) const
inline

Definition at line 404 of file TCT.h.

405 {
406 const FunObjVar* fun = bb->getFunction();
407 return fun->hasLoopInfo(bb);
408 }

◆ hasParentThread()

bool SVF::TCT::hasParentThread ( NodeID  tid) const
inline

Get parent and sibling threads.

Has parent thread

Definition at line 310 of file TCT.h.

311 {
312 const TCTNode* node = getTCTNode(tid);
313 return node->getInEdges().size()==1;
314 }

◆ hasTCTNode()

bool SVF::TCT::hasTCTNode ( const CxtThread ct) const
inline

Find/Get TCT node.

Definition at line 274 of file TCT.h.

275 {
276 return ctpToNodeMap.find(ct)!=ctpToNodeMap.end();
277 }

◆ inSameCallGraphSCC()

bool SVF::TCT::inSameCallGraphSCC ( const CallGraphNode src,
const CallGraphNode dst 
)
inline

Whether two functions in the same callgraph scc.

Definition at line 302 of file TCT.h.

303 {
304 return (tcgSCC->repNode(src->getId()) == tcgSCC->repNode(dst->getId()));
305 }

◆ isCallSite()

bool SVF::TCT::isCallSite ( const ICFGNode inst)
inline

Whether it is a callsite.

Definition at line 267 of file TCT.h.

268 {
269 return SVFUtil::isa<CallICFGNode>(inst);
270 }

◆ isCandidateFun() [1/2]

bool SVF::TCT::isCandidateFun ( const CallGraph::FunctionSet callees) const
inline

Whether it is a candidate function for indirect call.

Definition at line 287 of file TCT.h.

288 {
289 for(CallGraph::FunctionSet::const_iterator cit = callees.begin(),
290 ecit = callees.end(); cit!=ecit; cit++)
291 {
292 if(candidateFuncSet.find((*cit))!=candidateFuncSet.end())
293 return true;
294 }
295 return false;
296 }

◆ isCandidateFun() [2/2]

bool SVF::TCT::isCandidateFun ( const FunObjVar fun) const
inline

Definition at line 297 of file TCT.h.

298 {
299 return candidateFuncSet.find(fun)!=candidateFuncSet.end();
300 }

◆ isContextSuffix()

bool TCT::isContextSuffix ( const CallStrCxt lhs,
const CallStrCxt call 
)

If lhs is a suffix of rhs, including equal.

If lhs is a suffix of rhs, including equal

Definition at line 497 of file TCT.cpp.

498{
499 if (lhs.size() > call.size())
500 return false;
501 bool isSuffix = true;
502 for (size_t i = 0; i < lhs.size(); ++i)
503 {
504 if (lhs[lhs.size() - 1 - i] != call[call.size() - 1 - i])
505 {
506 isSuffix = false;
507 break;
508 }
509 }
510 return isSuffix;
511}

◆ isExtCall()

bool SVF::TCT::isExtCall ( const ICFGNode inst)
inline

Whether it is calling an external function.

Definition at line 260 of file TCT.h.

261 {
262 if(const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(inst))
263 return SVFUtil::isExtCall(call);
264 return false;
265 }

◆ isInLoopInstruction()

bool TCT::isInLoopInstruction ( const ICFGNode inst)
private

Multi-forked threads.

Whether an instruction is in a loop

An instruction i is in loop (1) the instruction i itself (2) all the callsites invoke the function where i resides in

Definition at line 46 of file TCT.cpp.

47{
48 assert(inst && "null value instruction!!");
49
52 worklist.push(inst);
53
54 while(!worklist.empty())
55 {
56 const ICFGNode* inst = worklist.pop();
57 insts.insert(inst);
59 for(CallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++)
60 {
61 for(CallGraphEdge::CallInstSet::const_iterator cit = (*nit)->directCallsBegin(),
62 ecit = (*nit)->directCallsEnd(); cit!=ecit; ++cit)
63 {
64 if(insts.insert(*cit).second)
65 worklist.push(*cit);
66 }
67 for(CallGraphEdge::CallInstSet::const_iterator cit = (*nit)->indirectCallsBegin(),
68 ecit = (*nit)->indirectCallsEnd(); cit!=ecit; ++cit)
69 {
70 if(insts.insert(*cit).second)
71 worklist.push(*cit);
72 }
73 }
74 }
75
76 for(const ICFGNode* i : insts)
77 {
78 if(i->getFun()->hasLoopInfo(i->getBB()))
79 return true;
80 }
81
82
83 return false;
84}
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:75

◆ isInRecursion()

bool TCT::isInRecursion ( const ICFGNode inst) const
private

Whether an instruction is in a recursion.

An instruction i is in a recursion (1) the function f where i resides in is in a recursion (2) any caller function starting from the function f in is in a recursion

Definition at line 91 of file TCT.cpp.

92{
93 const FunObjVar* f = inst->getFun();
96 worklist.push(f);
97
98 while(!worklist.empty())
99 {
100 const FunObjVar* svffun = worklist.pop();
101 visits.insert(svffun);
102 if(tcgSCC->isInCycle(tcg->getCallGraphNode(svffun)->getId()))
103 return true;
104
106
107 for(CallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++)
108 {
109 for(CallGraphEdge::CallInstSet::const_iterator cit = (*nit)->directCallsBegin(),
110 ecit = (*nit)->directCallsEnd(); cit!=ecit; ++cit)
111 {
112 const FunObjVar* caller = (*cit)->getFun();
113 if(visits.find(caller)==visits.end())
114 worklist.push(caller);
115 }
116 for(CallGraphEdge::CallInstSet::const_iterator cit = (*nit)->indirectCallsBegin(),
117 ecit = (*nit)->indirectCallsEnd(); cit!=ecit; ++cit)
118 {
119 const FunObjVar* caller = (*cit)->getFun();
120 if(visits.find(caller)==visits.end())
121 worklist.push(caller);
122 }
123 }
124 }
125
126 return false;
127
128}

◆ isJoinMustExecutedInLoop()

bool TCT::isJoinMustExecutedInLoop ( const LoopBBs lp,
const ICFGNode join 
)

Return true if a join instruction must be executed inside a loop.

Return true if a join instruction must be executed inside a loop joinbb should post dominate the successive basic block of a loop header

Definition at line 294 of file TCT.cpp.

295{
296 assert(!lp.empty() && "this is not a loop, empty basic block");
297 const FunObjVar* svffun = join->getFun();
298 const SVFBasicBlock* loopheadbb = svffun->getLoopHeader(lp);
299 const SVFBasicBlock* joinbb = join->getBB();
300 assert(loopheadbb->getParent()==joinbb->getParent() && "should inside same function");
301
302 for (const SVFBasicBlock* svf_scc_bb : loopheadbb->getSuccessors())
303 {
304 if(svffun->loopContainsBB(lp,svf_scc_bb))
305 {
306 if(svffun->dominate(joinbb,svf_scc_bb)==false)
307 return false;
308 }
309 }
310
311 return true;
312}

◆ isJoinSiteInRecursion()

bool SVF::TCT::isJoinSiteInRecursion ( const CallICFGNode join) const
inline

Whether a join site is in recursion.

Definition at line 431 of file TCT.h.

432 {
433 assert(tcg->getThreadAPI()->isTDJoin(join) && "not a join site");
434 return inRecurJoinSites.find(join)!=inRecurJoinSites.end();
435 }

◆ isLoopExitOfJoinLoop()

bool TCT::isLoopExitOfJoinLoop ( const SVFBasicBlock bb)
private

Whether a given bb is an exit of a inloop join site.

Whether a given bb is an exit of a inloop join site

Definition at line 357 of file TCT.cpp.

358{
359 for(InstToLoopMap::const_iterator it = joinSiteToLoopMap.begin(), eit = joinSiteToLoopMap.end(); it!=eit; ++it)
360 {
361 std::vector<const SVFBasicBlock*> exitbbs;
362 it->first->getFun()->getExitBlocksOfLoop(it->first->getBB(),exitbbs);
363 while(!exitbbs.empty())
364 {
365 const SVFBasicBlock* eb = exitbbs.back();
366 exitbbs.pop_back();
367 if(eb == bb)
368 return true;
369 }
370 }
371
372 return false;
373}
const ICFGNode * back() const

◆ isLoopHeaderOfJoinLoop()

bool TCT::isLoopHeaderOfJoinLoop ( const SVFBasicBlock bb)
private

Whether a given bb is a loop head of a inloop join site.

Return true if a given bb is a loop head of a inloop join site

Definition at line 343 of file TCT.cpp.

344{
345 for(InstToLoopMap::const_iterator it = joinSiteToLoopMap.begin(), eit = joinSiteToLoopMap.end(); it!=eit; ++it)
346 {
347 if(bb->getParent()->getLoopHeader(it->second) == bb)
348 return true;
349 }
350
351 return false;
352}
const SVFBasicBlock * getLoopHeader(const BBList &lp) const

◆ isVisitedCTPs()

bool SVF::TCT::isVisitedCTPs ( const CxtThreadProc ctp) const
inlineprivate

Definition at line 579 of file TCT.h.

580 {
581 return visitedCTPs.find(ctp)!=visitedCTPs.end();
582 }
CxtThreadProcSet visitedCTPs
CxtThreadProc List.
Definition TCT.h:589

◆ markRelProcs() [1/2]

void TCT::markRelProcs ( )
private

Mark relevant procedures that are backward reachable from any fork/join site.

Mark relevant procedures that are backward reachable from any fork/join site

Definition at line 133 of file TCT.cpp.

134{
135 for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->forksitesBegin(), eit = tcg->forksitesEnd(); it != eit; ++it)
136 {
137 const FunObjVar* svfun = (*it)->getParent()->getParent();
139
140 for(ThreadCallGraph::ForkEdgeSet::const_iterator nit = tcg->getForkEdgeBegin(*it), neit = tcg->getForkEdgeEnd(*it); nit!=neit; nit++)
141 {
142 const CallGraphNode* forkeeNode = (*nit)->getDstNode();
143 candidateFuncSet.insert(forkeeNode->getFunction());
144 }
145
146 }
147
148 for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->joinsitesBegin(), eit = tcg->joinsitesEnd(); it != eit; ++it)
149 {
150 const FunObjVar* svfun = (*it)->getParent()->getParent();
152 }
153
154 if(candidateFuncSet.empty())
155 writeWrnMsg("We didn't recognize any fork site, this is single thread program?");
156}
CallSiteSet::const_iterator forksitesEnd() const
CallSiteSet::const_iterator forksitesBegin() const
Fork sites iterators.
ForkEdgeSet::const_iterator getForkEdgeEnd(const CallICFGNode *cs) const
ForkEdgeSet::const_iterator getForkEdgeBegin(const CallICFGNode *cs) const
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition SVFUtil.cpp:72

◆ markRelProcs() [2/2]

void TCT::markRelProcs ( const FunObjVar svffun)
private

Add relevant procedures that are backward reachable from svffun on Thread Call Graph

Definition at line 161 of file TCT.cpp.

162{
165 PTACGNodeSet visited;
166 worklist.push(cgnode);
167 visited.insert(cgnode);
168 while(!worklist.empty())
169 {
170 const CallGraphNode* node = worklist.pop();
171 candidateFuncSet.insert(node->getFunction());
173 {
174 const CallGraphNode* srcNode = (*nit)->getSrcNode();
175 if(visited.find(srcNode)==visited.end())
176 {
177 visited.insert(srcNode);
178 worklist.push(srcNode);
179 }
180 }
181 }
182}
iterator InEdgeBegin()
iterator InEdgeEnd()
Set< const CallGraphNode * > PTACGNodeSet
Definition TCT.h:165

◆ matchAndPopCxt()

bool TCT::matchAndPopCxt ( CallStrCxt cxt,
const CallICFGNode call,
const FunObjVar callee 
)

Match context.

Match calling context

handle calling context for candidate functions only

partial match

Definition at line 469 of file TCT.cpp.

470{
471 const FunObjVar* caller = call->getFun();
472 CallSiteID csId = tcg->getCallSiteID(call, callee);
473
475 if(isCandidateFun(caller) == false)
476 return true;
477
479 if(cxt.empty())
480 return true;
481
483 {
484 if(cxt.back() == csId)
485 cxt.pop_back();
486 else
487 return false;
488 DBOUT(DMTA,dumpCxt(cxt));
489 }
490
491 return true;
492}
CallSiteID getCallSiteID(const CallICFGNode *cs, const FunObjVar *callee) const
Get CallSiteID.
Definition CallGraph.h:389
bool inSameCallGraphSCC(const CallGraphNode *src, const CallGraphNode *dst)
Whether two functions in the same callgraph scc.
Definition TCT.h:302
void dumpCxt(CallStrCxt &cxt)
Dump calling context.
Definition TCT.cpp:517
unsigned CallSiteID
Definition GeneralType.h:78

◆ popFromCTPWorkList()

CxtThreadProc SVF::TCT::popFromCTPWorkList ( )
inlineprivate

Definition at line 574 of file TCT.h.

575 {
576 CxtThreadProc ctp = ctpList.pop();
577 return ctp;
578 }

◆ print()

void TCT::print ( ) const

Print TCT information.

Print TCT information

Definition at line 543 of file TCT.cpp.

544{
545 for(TCT::const_iterator it = this->begin(), eit = this->end(); it!=eit; ++it)
546 {
547 outs() << "TID " << it->first << "\t";
548 it->second->getCxtThread().dump();
549 }
550}
iterator begin()
Iterators.
IDToNodeMapTy::const_iterator const_iterator

◆ pushCxt()

void TCT::pushCxt ( CallStrCxt cxt,
const CallICFGNode call,
const FunObjVar callee 
)

Context helper functions.

Push calling context

Push calling context, with k limiting

Definition at line 449 of file TCT.cpp.

450{
451 const FunObjVar* caller = call->getFun();
452 CallSiteID csId = tcg->getCallSiteID(call, callee);
453
455 {
456 cxt.push_back(csId);
457 if (cxt.size() > Options::MaxContextLen())
458 cxt.erase(cxt.begin());
459 if (cxt.size() > MaxCxtSize)
460 MaxCxtSize = cxt.size();
461 DBOUT(DMTA,dumpCxt(cxt));
462 }
463}
static const Option< u32_t > MaxContextLen
Definition Options.h:81

◆ pushToCTPWorkList()

bool SVF::TCT::pushToCTPWorkList ( const CxtThreadProc ctp)
inlineprivate

WorkList helper functions.

Definition at line 565 of file TCT.h.

566 {
567 if(isVisitedCTPs(ctp)==false)
568 {
569 visitedCTPs.insert(ctp);
570 return ctpList.push(ctp);
571 }
572 return false;
573 }
bool isVisitedCTPs(const CxtThreadProc &ctp) const
Definition TCT.h:579

◆ setMultiForkedAttrs()

void SVF::TCT::setMultiForkedAttrs ( CxtThread ct)
inlineprivate

Set multi-forked thread attributes.

non-main thread

main thread

Definition at line 534 of file TCT.h.

535 {
537 if(ct.getThread() != nullptr)
538 {
539 const ICFGNode* svfInst = ct.getThread();
540 ct.setInloop(isInLoopInstruction(svfInst));
541 ct.setIncycle(isInRecursion(svfInst));
542 }
544 else
545 {
546 ct.setInloop(false);
547 ct.setIncycle(false);
548 }
549 }
bool isInLoopInstruction(const ICFGNode *inst)
Multi-forked threads.
Definition TCT.cpp:46

Member Data Documentation

◆ candidateFuncSet

FunSet SVF::TCT::candidateFuncSet
private

Procedures that are neither called by other functions nor extern functions.

Definition at line 586 of file TCT.h.

◆ ctpList

CxtThreadProcVec SVF::TCT::ctpList
private

Thread call graph SCC.

Definition at line 588 of file TCT.h.

◆ ctpToNodeMap

CxtThreadToNodeMap SVF::TCT::ctpToNodeMap
private

Record all visited ctps.

Definition at line 590 of file TCT.h.

◆ ctToForkCxtsMap

CxtThreadToForkCxtSet SVF::TCT::ctToForkCxtsMap
private

Map a ctp to its graph node.

Definition at line 591 of file TCT.h.

◆ ctToRoutineFunMap

CxtThreadToFun SVF::TCT::ctToRoutineFunMap
private

Map a CxtThread to the context at its spawning site (fork site).

Definition at line 592 of file TCT.h.

◆ entryFuncSet

FunSet SVF::TCT::entryFuncSet
private

Definition at line 585 of file TCT.h.

◆ inRecurJoinSites

Set<const ICFGNode*> SVF::TCT::inRecurJoinSites
private

Fork or Join sites in recursions.

Definition at line 594 of file TCT.h.

◆ joinSiteToLoopMap

InstToLoopMap SVF::TCT::joinSiteToLoopMap
private

Map a CxtThread to its start routine function.

map an inloop join to its loop class

Definition at line 593 of file TCT.h.

◆ MaxCxtSize

u32_t SVF::TCT::MaxCxtSize
private

Definition at line 450 of file TCT.h.

◆ pta

PointerAnalysis* SVF::TCT::pta
private

Definition at line 447 of file TCT.h.

◆ tcg

ThreadCallGraph* SVF::TCT::tcg
private

Definition at line 446 of file TCT.h.

◆ tcgSCC

ThreadCallGraphSCC* SVF::TCT::tcgSCC
private

Procedures we care about during call graph traversing when creating TCT.

Definition at line 587 of file TCT.h.

◆ TCTEdgeNum

u32_t SVF::TCT::TCTEdgeNum
private

Definition at line 449 of file TCT.h.

◆ TCTNodeNum

u32_t SVF::TCT::TCTNodeNum
private

Definition at line 448 of file TCT.h.

◆ visitedCTPs

CxtThreadProcSet SVF::TCT::visitedCTPs
private

CxtThreadProc List.

Definition at line 589 of file TCT.h.


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