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

#include <TCT.h>

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

Classes

struct  FunObjVarIdCmp
 

Public Types

typedef SVFLoopAndDomInfo::LoopBBs LoopBBs
 
typedef TCTEdge::ThreadCreateEdgeSet ThreadCreateEdgeSet
 
typedef ThreadCreateEdgeSet::iterator TCTNodeIter
 
typedef OrderedSet< const FunObjVar *, FunObjVarIdCmpFunSet
 
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
 
typedef Set< const ICFGNode * > DummyForkSiteSet
 
- 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.
 
virtual 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 ()
 

Protected Member Functions

TCTNodeaddTCTNode (const CxtThread &ct)
 Add TCT node.
 
bool addTCTEdge (TCTNode *src, TCTNode *dst)
 Add TCT edge.
 
virtual void build ()
 Build TCT.
 
void reset ()
 
virtual void markRelProcs ()
 Mark relevant procedures that are backward reachable from any fork/join site.
 
virtual void markRelProcs (const FunObjVar *fun)
 
virtual void collectEntryFunInCallGraph ()
 Get entry functions that are neither called by other functions nor extern functions.
 
void collectMultiForkedThreads ()
 
virtual 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.
 
virtual 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.
 
bool addCxtOfCxtThread (NodeID pTid, const CallStrCxt &cxt, const CxtThread &ct)
 
void addStartRoutineOfCxtThread (const FunObjVar *fun, const CxtThread &ct)
 Add start routine function of a cxt thread.
 
ICFGNodecreateDummyForkSite ()
 Create and get a new dummy fork site for starter routines.
 
bool pushToCTPWorkList (const CxtThreadProc &ctp)
 WorkList helper functions.
 
CxtThreadProc popFromCTPWorkList ()
 
bool isVisitedCTPs (const CxtThreadProc &ctp) const
 

Protected 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.
 
DummyForkSiteSet dummyForkSites
 set of dummy fork sites for starter routines
 
NodeID dummyForkICFGNodeID = UINT32_MAX
 unique ID generator for dummy
 
- Protected Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
IDToNodeMapTy IDToNodeMap
 node map
 

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
 

Detailed Description

Definition at line 154 of file TCT.h.

Member Typedef Documentation

◆ CallStrCxtSet

Definition at line 177 of file TCT.h.

◆ CxtThreadProcSet

Definition at line 182 of file TCT.h.

◆ CxtThreadProcVec

Definition at line 181 of file TCT.h.

◆ CxtThreadToForkCxtSet

Definition at line 178 of file TCT.h.

◆ CxtThreadToFun

Definition at line 179 of file TCT.h.

◆ CxtThreadToNodeMap

Definition at line 176 of file TCT.h.

◆ DummyForkSiteSet

Definition at line 184 of file TCT.h.

◆ FunSet

Definition at line 172 of file TCT.h.

◆ InstSet

Definition at line 174 of file TCT.h.

◆ InstToLoopMap

Definition at line 180 of file TCT.h.

◆ InstVec

Definition at line 173 of file TCT.h.

◆ LoopBBs

Definition at line 158 of file TCT.h.

◆ PTACGNodeSet

Definition at line 175 of file TCT.h.

◆ TCTNodeIter

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

Definition at line 160 of file TCT.h.

◆ ThreadCallGraphSCC

Definition at line 183 of file TCT.h.

◆ ThreadCreateEdgeSet

Definition at line 159 of file TCT.h.

Constructor & Destructor Documentation

◆ TCT()

TCT::TCT ( PointerAnalysis p)

Constructor.

Constructor

Definition at line 44 of file TCT.cpp.

45{
46 tcg = SVFUtil::dyn_cast<ThreadCallGraph>(pta->getCallGraph());
47 assert(tcg != nullptr && "TCT::TCT: call graph is not a ThreadCallGraph!");
49 //tcg->updateJoinEdge(pta);
51 tcgSCC->find();
52 build();
53}
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:626
u32_t TCTNodeNum
Definition TCT.h:449
u32_t TCTEdgeNum
Definition TCT.h:450
PointerAnalysis * pta
Definition TCT.h:448
u32_t MaxCxtSize
Definition TCT.h:451
virtual void build()
Build TCT.
Definition TCT.cpp:409
ThreadCallGraph * tcg
Definition TCT.h:447
void updateCallGraph(PointerAnalysis *pta)
Update call graph using pointer results.
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ ~TCT()

TCT::~TCT ( )
virtual

Destructor.

Definition at line 55 of file TCT.cpp.

56{
58 {
59 delete dummyForkSite;
60 }
61}
DummyForkSiteSet dummyForkSites
set of dummy fork sites for starter routines
Definition TCT.h:634

Member Function Documentation

◆ addCxtOfCxtThread()

bool SVF::TCT::addCxtOfCxtThread ( NodeID  pTid,
const CallStrCxt cxt,
const CxtThread ct 
)
inlineprotected

Add context for a thread at its spawning site (fork site). Returns true if this (parent tid, context) pair was not recorded before.

Definition at line 583 of file TCT.h.

584 {
585 return ctToForkCxtsMap[ct].insert(std::make_pair(pTid, cxt)).second;
586 }
CxtThreadToForkCxtSet ctToForkCxtsMap
Map a ctp to its graph node.
Definition TCT.h:630

◆ addStartRoutineOfCxtThread()

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

Add start routine function of a cxt thread.

Definition at line 589 of file TCT.h.

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

◆ addTCTEdge()

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

Add TCT edge.

Definition at line 465 of file TCT.h.

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

◆ addTCTNode()

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

Add TCT node.

Definition at line 454 of file TCT.h.

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

◆ build()

void TCT::build ( )
protectedvirtual

Build TCT.

Start building TCT

Reimplemented in SVF::SlicedTCT.

Definition at line 409 of file TCT.cpp.

410{
411
412 markRelProcs();
413
415
416 // the fork site of main function is initialized with nullptr.
417 // the context of main is initialized with empty
418 // start routine is empty
419
421
422 for (FunSet::iterator it=entryFuncSet.begin(), eit=entryFuncSet.end(); it!=eit; ++it)
423 {
424 if (!isCandidateFun(*it))
425 continue;
426 CallStrCxt cxt;
427 CxtThreadProc dummyCtp(-1, cxt, nullptr);
430 CxtThreadProc t(mainTCTNode->getId(), cxt, *it);
432 }
433
434 while(!ctpList.empty())
435 {
437 CallGraphNode* cgNode = tcg->getCallGraphNode(ctp.getProc());
438 if(isCandidateFun(cgNode->getFunction()) == false)
439 continue;
440
441 for(CallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit!=neit; nit++)
442 {
443 const CallGraphEdge* cgEdge = (*nit);
444
445 for(CallGraphEdge::CallInstSet::const_iterator cit = cgEdge->directCallsBegin(),
446 ecit = cgEdge->directCallsEnd(); cit!=ecit; ++cit)
447 {
448 DBOUT(DMTA,outs() << "\nTCT handling direct call:" << **cit << "\t" << cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
450 }
451 for(CallGraphEdge::CallInstSet::const_iterator ind = cgEdge->indirectCallsBegin(),
452 eind = cgEdge->indirectCallsEnd(); ind!=eind; ++ind)
453 {
454 DBOUT(DMTA,outs() << "\nTCT handling indirect call:" << **ind << "\t" << cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
456 }
457 }
458 }
459
461
463 {
464 print();
465 dump("tct");
466 }
467
468}
#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:159
bool pushToCTPWorkList(const CxtThreadProc &ctp)
WorkList helper functions.
Definition TCT.h:604
FunSet entryFuncSet
Definition TCT.h:624
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:537
virtual void collectLoopInfoForJoin()
Handle join site in loop.
Definition TCT.cpp:340
virtual void collectEntryFunInCallGraph()
Get entry functions that are neither called by other functions nor extern functions.
Definition TCT.cpp:209
ICFGNode * createDummyForkSite()
Create and get a new dummy fork site for starter routines.
Definition TCT.h:595
void dump(const std::string &filename)
Dump the graph.
Definition TCT.cpp:559
bool isCandidateFun(const CallGraph::FunctionSet &callees) const
Whether it is a candidate function for indirect call.
Definition TCT.h:288
CxtThreadProcVec ctpList
Thread call graph SCC.
Definition TCT.h:627
virtual void markRelProcs()
Mark relevant procedures that are backward reachable from any fork/join site.
Definition TCT.cpp:155
void print() const
Print TCT information.
Definition TCT.cpp:567
virtual void handleCallRelation(CxtThreadProc &ctp, const CallGraphEdge *cgEdge, const CallICFGNode *call)
Handle call relations.
Definition TCT.cpp:267
void collectMultiForkedThreads()
Definition TCT.cpp:229
CxtThreadProc popFromCTPWorkList()
Definition TCT.h:613
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52
std::vector< u32_t > CallStrCxt
Definition GeneralType.h:96

◆ collectEntryFunInCallGraph()

void TCT::collectEntryFunInCallGraph ( )
protectedvirtual

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

Reimplemented in SVF::SlicedTCT.

Definition at line 209 of file TCT.cpp.

210{
212 for (const auto& item: *svfirCallGraph)
213 {
214 const FunObjVar* fun = item.second->getFunction();
215 if (SVFUtil::isExtCall(fun))
216 continue;
217 CallGraphNode* node = tcg->getCallGraphNode(fun);
218 if (!node->hasIncomingEdge())
219 {
220 entryFuncSet.insert(fun);
221 }
222 }
223 assert(!entryFuncSet.empty() && "Can't find any function in module!");
224}
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 ( )
protectedvirtual

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

Reimplemented in SVF::SlicedTCT.

Definition at line 340 of file TCT.cpp.

341{
342 for(ThreadCallGraph::CallSiteSet::const_iterator it = tcg->joinsitesBegin(), eit = tcg->joinsitesEnd(); it!=eit; ++it)
343 {
344 const ICFGNode* join = *it;
345 const FunObjVar* svffun = join->getFun();
346 const SVFBasicBlock* svfbb = join->getBB();
347
348 if(svffun->hasLoopInfo(svfbb))
349 {
350 const LoopBBs& lp = svffun->getLoopInfo(svfbb);
351 if(!lp.empty() && isJoinMustExecutedInLoop(lp,join))
352 {
354 }
355 }
356
358 inRecurJoinSites.insert(join);
359 }
360}
bool isInRecursion(const ICFGNode *inst) const
Whether an instruction is in a recursion.
Definition TCT.cpp:113
InstToLoopMap joinSiteToLoopMap
Map a CxtThread to its start routine function.
Definition TCT.h:632
bool isJoinMustExecutedInLoop(const LoopBBs &lp, const ICFGNode *join)
Return true if a join instruction must be executed inside a loop.
Definition TCT.cpp:316
Set< const ICFGNode * > inRecurJoinSites
Fork or Join sites in recursions.
Definition TCT.h:633
SVFLoopAndDomInfo::LoopBBs LoopBBs
Definition TCT.h:158
CallSiteSet::const_iterator joinsitesEnd() const
CallSiteSet::const_iterator joinsitesBegin() const
Join sites iterators.

◆ collectMultiForkedThreads()

void TCT::collectMultiForkedThreads ( )
protected

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 229 of file TCT.cpp.

230{
231 if (this->nodeNum == 0 )
232 return;
233
234 FIFOWorkList<TCTNode*> worklist;
235 worklist.push(getTCTNode(0));
236
237 while(!worklist.empty())
238 {
239 TCTNode* node = worklist.pop();
240 const CxtThread &ct = node->getCxtThread();
241
242 if(ct.isIncycle() || ct.isInloop())
243 {
244 node->setMultiforked(true);
245 }
246 else
247 {
248 for (TCT::ThreadCreateEdgeSet::const_iterator it = node->getInEdges().begin(), eit = node->getInEdges().end(); it != eit;
249 ++it)
250 {
251 if ((*it)->getSrcNode()->isMultiforked())
252 node->setMultiforked(true);
253 }
254 }
255 for (TCT::ThreadCreateEdgeSet::const_iterator it = node->getOutEdges().begin(), eit = node->getOutEdges().end(); it != eit;
256 ++it)
257 {
258 worklist.push((*it)->getDstNode());
259 }
260 }
261}
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:102
void setMultiforked(bool value)
Definition TCT.h:117
TCTNode * getTCTNode(NodeID id) const
Get TCT node.
Definition TCT.h:203

◆ createDummyForkSite()

ICFGNode * SVF::TCT::createDummyForkSite ( )
inlineprotected

Create and get a new dummy fork site for starter routines.

Definition at line 595 of file TCT.h.

596 {
597 ICFGNode* dummyForkSite = new ICFGNode(dummyForkICFGNodeID--, SVFValue::GlobalBlock);
599 return dummyForkSite;
600 }
NodeID dummyForkICFGNodeID
unique ID generator for dummy
Definition TCT.h:635

◆ dump()

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

Dump the graph.

Dump call graph into dot file

Definition at line 559 of file TCT.cpp.

560{
562}
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 541 of file TCT.cpp.

542{
543 std::string str;
544 std::stringstream rawstr(str);
545 rawstr << "[:";
546 for(CallStrCxt::const_iterator it = cxt.begin(), eit = cxt.end(); it!=eit; ++it)
547 {
548 rawstr << " ' "<< *it << " ' ";
549 rawstr << (tcg->getCallSite(*it))->valueOnlyToString();
550 rawstr << " call " << tcg->getCallSite(*it)->getCaller()->getName() << "-->" << tcg->getCalleeOfCallSite(*it)->getName() << ", \n";
551 }
552 rawstr << " ]";
553 outs() << "max cxt = " << cxt.size() << rawstr.str() << "\n";
554}
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:184

◆ getAncestorThreads()

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

Get all ancestor threads.

Definition at line 330 of file TCT.h.

331 {
332 NodeBS tds;
333 if(hasParentThread(tid) == false)
334 return tds;
335
336 FIFOWorkList<NodeID> worklist;
338 worklist.push(parentTid);
339
340 while(!worklist.empty())
341 {
342 NodeID t = worklist.pop();
343 if(tds.test_and_set(t))
344 {
345 if(hasParentThread(t))
347 worklist.push(parentTid);
348 }
349 }
350 return tds;
351 }
NodeBS getParentThreads(NodeID tid) const
Get parent threads.
Definition TCT.h:317
bool hasParentThread(NodeID tid) const
Get parent and sibling threads.
Definition TCT.h:311
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 214 of file TCT.h.

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

◆ getChildrenEnd()

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

Definition at line 218 of file TCT.h.

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

◆ 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 374 of file TCT.h.

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

◆ getEntryProcs()

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

Get marked candidate functions.

Definition at line 239 of file TCT.h.

240 {
241 return entryFuncSet;
242 }

◆ 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 596 of file TCT.cpp.

597{
598 for (TCTEdge::ThreadCreateEdgeSet::const_iterator iter = src->OutEdgeBegin(); iter != src->OutEdgeEnd(); ++iter)
599 {
600 TCTEdge* edge = (*iter);
601 if (edge->getEdgeKind() == kind && edge->getDstID() == dst->getId())
602 return edge;
603 }
604 return nullptr;
605}
NodeID getId() const
Get ID.
Definition SVFValue.h:158

◆ getJoinLoop()

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

Get loop for join site.

Definition at line 390 of file TCT.h.

391 {
392 assert(tcg->getThreadAPI()->isTDJoin(join) && "not a join site");
393 InstToLoopMap::iterator it = joinSiteToLoopMap.find(join);
394 assert(it!=joinSiteToLoopMap.end() && "loop not found");
395 return it->second;
396 }
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 400 of file TCT.cpp.

401{
402 const FunObjVar* fun = bb->getParent();
403 return fun->getLoopInfo(bb);
404}
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 233 of file TCT.h.

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

◆ getMaxCxtSize()

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

Definition at line 254 of file TCT.h.

255 {
256 return MaxCxtSize;
257 }

◆ getOrCreateTCTNode()

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

Get or create a tct node based on CxtThread.

Definition at line 537 of file TCT.h.

538 {
539 CxtThread ct(cxt,fork);
540 CxtThreadToNodeMap::const_iterator it = ctpToNodeMap.find(ct);
541 if(it!=ctpToNodeMap.end())
542 {
543 // A second spawn context merged onto this truncated CxtThread: the
544 // node stands for multiple dynamic instances, so mark it multiforked.
545 if (addCxtOfCxtThread(forkSiteCtp.getTid(), forkSiteCtp.getContext(), ct))
546 it->second->setMultiforked(true);
547 return it->second;
548 }
549
550 addCxtOfCxtThread(forkSiteCtp.getTid(), forkSiteCtp.getContext(), ct);
552
554 return addTCTNode(ct);
555 }
void setMultiForkedAttrs(CxtThread &ct)
Set multi-forked thread attributes.
Definition TCT.h:559
bool addCxtOfCxtThread(NodeID pTid, const CallStrCxt &cxt, const CxtThread &ct)
Definition TCT.h:583
void addStartRoutineOfCxtThread(const FunObjVar *fun, const CxtThread &ct)
Add start routine function of a cxt thread.
Definition TCT.h:589
TCTNode * addTCTNode(const CxtThread &ct)
Add TCT node.
Definition TCT.h:454

◆ getParentsBegin()

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

Definition at line 222 of file TCT.h.

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

◆ getParentsEnd()

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

Definition at line 226 of file TCT.h.

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

◆ getParentThreads()

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

Get parent threads.

Definition at line 317 of file TCT.h.

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

◆ getPTA()

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

Get PTA.

Definition at line 198 of file TCT.h.

199 {
200 return pta;
201 }

◆ getSiblingThread()

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

Get sibling threads.

Definition at line 353 of file TCT.h.

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

◆ getStartRoutineOfCxtThread()

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

get the start routine function of a thread

Definition at line 382 of file TCT.h.

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

◆ getTCTEdgeNum()

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

Definition at line 250 of file TCT.h.

251 {
252 return TCTEdgeNum;
253 }

◆ getTCTNode() [1/2]

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

Definition at line 279 of file TCT.h.

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

◆ getTCTNode() [2/2]

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

Get TCT node.

Definition at line 203 of file TCT.h.

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

◆ getTCTNodeNum()

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

Get Statistics.

Definition at line 246 of file TCT.h.

247 {
248 return TCTNodeNum;
249 }

◆ getThreadCallGraph()

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

Get TCG.

Definition at line 193 of file TCT.h.

194 {
195 return tcg;
196 }

◆ handleCallRelation()

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

Handle call relations.

Handle call relations

handle calling context for candidate functions only

Create spawnee TCT node

Add TCT nodes and edge

Reimplemented in SVF::SlicedTCT.

Definition at line 267 of file TCT.cpp.

268{
269 const FunObjVar* callee = cgEdge->getDstNode()->getFunction();
270
271 CallStrCxt cxt(ctp.getContext());
272 CallStrCxt oldCxt = cxt;
273 const CallICFGNode* callNode = cs;
274
276 if(isCandidateFun(callNode->getFun()) == true)
278
279 if(cgEdge->getEdgeKind() == CallGraphEdge::CallRetEdge)
280 {
281 CxtThreadProc newctp(ctp.getTid(),cxt,callee);
283 {
284 DBOUT(DMTA,outs() << "TCT Process CallRet old ctp --"; ctp.dump());
285 DBOUT(DMTA,outs() << "TCT Process CallRet new ctp --"; newctp.dump());
286 }
287 }
288
289 else if(cgEdge->getEdgeKind() == CallGraphEdge::TDForkEdge)
290 {
294
296 {
298 if(addTCTEdge(this->getTCTNode(ctp.getTid()), spawneeNode))
299 {
300 DBOUT(DMTA,outs() << "Add TCT Edge from thread " << ctp.getTid() << " ";
301 this->getTCTNode(ctp.getTid())->getCxtThread().dump();
302 outs() << " to thread " << spawneeNode->getId() << " ";
303 spawneeNode->getCxtThread().dump();
304 outs() << "\n" );
305 }
306 DBOUT(DMTA,outs() << "TCT Process Fork old ctp --"; ctp.dump());
307 DBOUT(DMTA,outs() << "TCT Process Fork new ctp --"; newctp.dump());
308 }
309 }
310}
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:465
virtual void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Context helper functions.
Definition TCT.cpp:473

◆ 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 579 of file TCT.cpp.

580{
581 TCTEdge edge(src, dst, kind);
584 if (outEdge && inEdge)
585 {
586 assert(outEdge == inEdge && "edges not match");
587 return outEdge;
588 }
589 else
590 return nullptr;
591}
bool hasOutgoingEdge() const

◆ hasJoinLoop()

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

Definition at line 398 of file TCT.h.

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

◆ hasLoop() [1/2]

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

Definition at line 410 of file TCT.h.

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

◆ hasLoop() [2/2]

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

Definition at line 405 of file TCT.h.

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

◆ hasParentThread()

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

Get parent and sibling threads.

Has parent thread

Definition at line 311 of file TCT.h.

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

◆ hasTCTNode()

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

Find/Get TCT node.

Definition at line 275 of file TCT.h.

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

◆ inSameCallGraphSCC()

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

Whether two functions in the same callgraph scc.

Definition at line 303 of file TCT.h.

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

◆ isCallSite()

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

Whether it is a callsite.

Definition at line 268 of file TCT.h.

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

◆ 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 288 of file TCT.h.

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

◆ isCandidateFun() [2/2]

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

Definition at line 298 of file TCT.h.

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

◆ 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 521 of file TCT.cpp.

522{
523 if (lhs.size() > call.size())
524 return false;
525 bool isSuffix = true;
526 for (size_t i = 0; i < lhs.size(); ++i)
527 {
528 if (lhs[lhs.size() - 1 - i] != call[call.size() - 1 - i])
529 {
530 isSuffix = false;
531 break;
532 }
533 }
534 return isSuffix;
535}

◆ isExtCall()

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

Whether it is calling an external function.

Definition at line 261 of file TCT.h.

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

◆ isInLoopInstruction()

bool TCT::isInLoopInstruction ( const ICFGNode inst)
protected

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 68 of file TCT.cpp.

69{
70 assert(inst && "null value instruction!!");
71
74 worklist.push(inst);
75
76 while(!worklist.empty())
77 {
78 const ICFGNode* inst = worklist.pop();
79 insts.insert(inst);
81 for(CallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++)
82 {
83 for(CallGraphEdge::CallInstSet::const_iterator cit = (*nit)->directCallsBegin(),
84 ecit = (*nit)->directCallsEnd(); cit!=ecit; ++cit)
85 {
86 if(insts.insert(*cit).second)
87 worklist.push(*cit);
88 }
89 for(CallGraphEdge::CallInstSet::const_iterator cit = (*nit)->indirectCallsBegin(),
90 ecit = (*nit)->indirectCallsEnd(); cit!=ecit; ++cit)
91 {
92 if(insts.insert(*cit).second)
93 worklist.push(*cit);
94 }
95 }
96 }
97
98 for(const ICFGNode* i : insts)
99 {
100 if(i->getFun()->hasLoopInfo(i->getBB()))
101 return true;
102 }
103
104
105 return false;
106}
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:75

◆ isInRecursion()

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

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 113 of file TCT.cpp.

114{
115 const FunObjVar* f = inst->getFun();
118 worklist.push(f);
119
120 while(!worklist.empty())
121 {
122 const FunObjVar* svffun = worklist.pop();
123 visits.insert(svffun);
124 if(tcgSCC->isInCycle(tcg->getCallGraphNode(svffun)->getId()))
125 return true;
126
128
129 for(CallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++)
130 {
131 for(CallGraphEdge::CallInstSet::const_iterator cit = (*nit)->directCallsBegin(),
132 ecit = (*nit)->directCallsEnd(); cit!=ecit; ++cit)
133 {
134 const FunObjVar* caller = (*cit)->getFun();
135 if(visits.find(caller)==visits.end())
136 worklist.push(caller);
137 }
138 for(CallGraphEdge::CallInstSet::const_iterator cit = (*nit)->indirectCallsBegin(),
139 ecit = (*nit)->indirectCallsEnd(); cit!=ecit; ++cit)
140 {
141 const FunObjVar* caller = (*cit)->getFun();
142 if(visits.find(caller)==visits.end())
143 worklist.push(caller);
144 }
145 }
146 }
147
148 return false;
149
150}

◆ 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 316 of file TCT.cpp.

317{
318 assert(!lp.empty() && "this is not a loop, empty basic block");
319 const FunObjVar* svffun = join->getFun();
320 const SVFBasicBlock* loopheadbb = svffun->getLoopHeader(lp);
321 const SVFBasicBlock* joinbb = join->getBB();
322 assert(loopheadbb->getParent()==joinbb->getParent() && "should inside same function");
323
324 for (const SVFBasicBlock* svf_scc_bb : loopheadbb->getSuccessors())
325 {
326 if(svffun->loopContainsBB(lp,svf_scc_bb))
327 {
328 if(svffun->dominate(joinbb,svf_scc_bb)==false)
329 return false;
330 }
331 }
332
333 return true;
334}

◆ isJoinSiteInRecursion()

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

Whether a join site is in recursion.

Definition at line 432 of file TCT.h.

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

◆ isLoopExitOfJoinLoop()

bool TCT::isLoopExitOfJoinLoop ( const SVFBasicBlock bb)
protected

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 379 of file TCT.cpp.

380{
381 for(InstToLoopMap::const_iterator it = joinSiteToLoopMap.begin(), eit = joinSiteToLoopMap.end(); it!=eit; ++it)
382 {
383 std::vector<const SVFBasicBlock*> exitbbs;
384 it->first->getFun()->getExitBlocksOfLoop(it->first->getBB(),exitbbs);
385 while(!exitbbs.empty())
386 {
387 const SVFBasicBlock* eb = exitbbs.back();
388 exitbbs.pop_back();
389 if(eb == bb)
390 return true;
391 }
392 }
393
394 return false;
395}
const ICFGNode * back() const

◆ isLoopHeaderOfJoinLoop()

bool TCT::isLoopHeaderOfJoinLoop ( const SVFBasicBlock bb)
protected

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 365 of file TCT.cpp.

366{
367 for(InstToLoopMap::const_iterator it = joinSiteToLoopMap.begin(), eit = joinSiteToLoopMap.end(); it!=eit; ++it)
368 {
369 if(bb->getParent()->getLoopHeader(it->second) == bb)
370 return true;
371 }
372
373 return false;
374}
const SVFBasicBlock * getLoopHeader(const BBList &lp) const

◆ isVisitedCTPs()

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

Definition at line 618 of file TCT.h.

619 {
620 return visitedCTPs.find(ctp)!=visitedCTPs.end();
621 }
CxtThreadProcSet visitedCTPs
CxtThreadProc List.
Definition TCT.h:628

◆ markRelProcs() [1/2]

void TCT::markRelProcs ( )
protectedvirtual

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

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

Reimplemented in SVF::SlicedTCT.

Definition at line 155 of file TCT.cpp.

156{
157 for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->forksitesBegin(), eit = tcg->forksitesEnd(); it != eit; ++it)
158 {
159 const FunObjVar* svfun = (*it)->getParent()->getParent();
161
162 for(ThreadCallGraph::ForkEdgeSet::const_iterator nit = tcg->getForkEdgeBegin(*it), neit = tcg->getForkEdgeEnd(*it); nit!=neit; nit++)
163 {
164 const CallGraphNode* forkeeNode = (*nit)->getDstNode();
165 candidateFuncSet.insert(forkeeNode->getFunction());
166 }
167
168 }
169
170 for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->joinsitesBegin(), eit = tcg->joinsitesEnd(); it != eit; ++it)
171 {
172 const FunObjVar* svfun = (*it)->getParent()->getParent();
174 }
175
176 if(candidateFuncSet.empty())
177 writeWrnMsg("We didn't recognize any fork site, this is single thread program?");
178}
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)
protectedvirtual

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

Reimplemented in SVF::SlicedTCT.

Definition at line 183 of file TCT.cpp.

184{
187 PTACGNodeSet visited;
188 worklist.push(cgnode);
189 visited.insert(cgnode);
190 while(!worklist.empty())
191 {
192 const CallGraphNode* node = worklist.pop();
193 candidateFuncSet.insert(node->getFunction());
195 {
196 const CallGraphNode* srcNode = (*nit)->getSrcNode();
197 if(visited.find(srcNode)==visited.end())
198 {
199 visited.insert(srcNode);
200 worklist.push(srcNode);
201 }
202 }
203 }
204}
iterator InEdgeBegin()
iterator InEdgeEnd()
Set< const CallGraphNode * > PTACGNodeSet
Definition TCT.h:175

◆ 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 493 of file TCT.cpp.

494{
495 const FunObjVar* caller = call->getFun();
496 CallSiteID csId = tcg->getCallSiteID(call, callee);
497
499 if(isCandidateFun(caller) == false)
500 return true;
501
503 if(cxt.empty())
504 return true;
505
507 {
508 if(cxt.back() == csId)
509 cxt.pop_back();
510 else
511 return false;
512 DBOUT(DMTA,dumpCxt(cxt));
513 }
514
515 return true;
516}
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:303
void dumpCxt(CallStrCxt &cxt)
Dump calling context.
Definition TCT.cpp:541
unsigned CallSiteID
Definition GeneralType.h:78

◆ popFromCTPWorkList()

CxtThreadProc SVF::TCT::popFromCTPWorkList ( )
inlineprotected

Definition at line 613 of file TCT.h.

614 {
615 CxtThreadProc ctp = ctpList.pop();
616 return ctp;
617 }

◆ print()

void TCT::print ( ) const

Print TCT information.

Print TCT information

Definition at line 567 of file TCT.cpp.

568{
569 for(TCT::const_iterator it = this->begin(), eit = this->end(); it!=eit; ++it)
570 {
571 outs() << "TID " << it->first << "\t";
572 it->second->getCxtThread().dump();
573 }
574}
iterator begin()
Iterators.
IDToNodeMapTy::const_iterator const_iterator

◆ pushCxt()

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

Context helper functions.

Push calling context

Push calling context, with k limiting

Reimplemented in SVF::SlicedTCT.

Definition at line 473 of file TCT.cpp.

474{
475 const FunObjVar* caller = call->getFun();
476 CallSiteID csId = tcg->getCallSiteID(call, callee);
477
479 {
480 cxt.push_back(csId);
481 if (cxt.size() > Options::MaxContextLen())
482 cxt.erase(cxt.begin());
483 if (cxt.size() > MaxCxtSize)
484 MaxCxtSize = cxt.size();
485 DBOUT(DMTA,dumpCxt(cxt));
486 }
487}
static Option< u32_t > MaxContextLen
Definition Options.h:81

◆ pushToCTPWorkList()

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

WorkList helper functions.

Definition at line 604 of file TCT.h.

605 {
606 if(isVisitedCTPs(ctp)==false)
607 {
608 visitedCTPs.insert(ctp);
609 return ctpList.push(ctp);
610 }
611 return false;
612 }
bool isVisitedCTPs(const CxtThreadProc &ctp) const
Definition TCT.h:618

◆ reset()

void SVF::TCT::reset ( )
inlineprotected

Free the built graph and clear all bookkeeping so build() can run again from a clean state (SlicedTCT rebuilds the tree over a sliced view).

Definition at line 483 of file TCT.h.

484 {
485 destroy();
486 IDToNodeMap.clear();
487 ctpToNodeMap.clear();
488 ctToForkCxtsMap.clear();
489 ctToRoutineFunMap.clear();
490 candidateFuncSet.clear();
491 entryFuncSet.clear();
492 joinSiteToLoopMap.clear();
493 inRecurJoinSites.clear();
494 ctpList.clear();
495 visitedCTPs.clear();
496 TCTNodeNum = 0;
497 TCTEdgeNum = 0;
498 MaxCxtSize = 0;
499 }
IDToNodeMapTy IDToNodeMap
node map
void destroy()
Release memory.

◆ setMultiForkedAttrs()

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

Set multi-forked thread attributes.

non-main thread spawned at a real fork site. The main thread uses a synthetic dummy fork site (see createDummyForkSite); it has no real function/call-graph node, is never in a loop or recursion, and must be treated like the null (main) case – otherwise isInLoopInstruction would look up a call-graph node that does not exist.

main thread (null or dummy fork site)

Definition at line 559 of file TCT.h.

560 {
566 if(ct.getThread() != nullptr &&
567 dummyForkSites.find(ct.getThread()) == dummyForkSites.end())
568 {
569 const ICFGNode* svfInst = ct.getThread();
570 ct.setInloop(isInLoopInstruction(svfInst));
571 ct.setIncycle(isInRecursion(svfInst));
572 }
574 else
575 {
576 ct.setInloop(false);
577 ct.setIncycle(false);
578 }
579 }
bool isInLoopInstruction(const ICFGNode *inst)
Multi-forked threads.
Definition TCT.cpp:68

Member Data Documentation

◆ candidateFuncSet

FunSet SVF::TCT::candidateFuncSet
protected

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

Definition at line 625 of file TCT.h.

◆ ctpList

CxtThreadProcVec SVF::TCT::ctpList
protected

Thread call graph SCC.

Definition at line 627 of file TCT.h.

◆ ctpToNodeMap

CxtThreadToNodeMap SVF::TCT::ctpToNodeMap
protected

Record all visited ctps.

Definition at line 629 of file TCT.h.

◆ ctToForkCxtsMap

CxtThreadToForkCxtSet SVF::TCT::ctToForkCxtsMap
protected

Map a ctp to its graph node.

Definition at line 630 of file TCT.h.

◆ ctToRoutineFunMap

CxtThreadToFun SVF::TCT::ctToRoutineFunMap
protected

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

Definition at line 631 of file TCT.h.

◆ dummyForkICFGNodeID

NodeID SVF::TCT::dummyForkICFGNodeID = UINT32_MAX
protected

unique ID generator for dummy

Definition at line 635 of file TCT.h.

◆ dummyForkSites

DummyForkSiteSet SVF::TCT::dummyForkSites
protected

set of dummy fork sites for starter routines

Definition at line 634 of file TCT.h.

◆ entryFuncSet

FunSet SVF::TCT::entryFuncSet
protected

Definition at line 624 of file TCT.h.

◆ inRecurJoinSites

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

Fork or Join sites in recursions.

Definition at line 633 of file TCT.h.

◆ joinSiteToLoopMap

InstToLoopMap SVF::TCT::joinSiteToLoopMap
protected

Map a CxtThread to its start routine function.

map an inloop join to its loop class

Definition at line 632 of file TCT.h.

◆ MaxCxtSize

u32_t SVF::TCT::MaxCxtSize
protected

Definition at line 451 of file TCT.h.

◆ pta

PointerAnalysis* SVF::TCT::pta
protected

Definition at line 448 of file TCT.h.

◆ tcg

ThreadCallGraph* SVF::TCT::tcg
protected

Definition at line 447 of file TCT.h.

◆ tcgSCC

ThreadCallGraphSCC* SVF::TCT::tcgSCC
protected

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

Definition at line 626 of file TCT.h.

◆ TCTEdgeNum

u32_t SVF::TCT::TCTEdgeNum
protected

Definition at line 450 of file TCT.h.

◆ TCTNodeNum

u32_t SVF::TCT::TCTNodeNum
protected

Definition at line 449 of file TCT.h.

◆ visitedCTPs

CxtThreadProcSet SVF::TCT::visitedCTPs
protected

CxtThreadProc List.

Definition at line 628 of file TCT.h.


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