Static Value-Flow Analysis
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 SVFFunction * > FunSet
 
typedef std::vector< const ICFGNode * > InstVec
 
typedef Set< const ICFGNode * > InstSet
 
typedef Set< const PTACallGraphNode * > PTACGNodeSet
 
typedef Map< CxtThread, TCTNode * > CxtThreadToNodeMap
 
typedef Map< CxtThread, CallStrCxtCxtThreadToForkCxt
 
typedef Map< CxtThread, const SVFFunction * > CxtThreadToFun
 
typedef Map< const ICFGNode *, LoopBBsInstToLoopMap
 
typedef FIFOWorkList< CxtThreadProcCxtThreadProcVec
 
typedef Set< CxtThreadProcCxtThreadProcSet
 
typedef SCCDetection< PTACallGraph * > ThreadCallGraphSCC
 
- Public Types inherited from SVF::GenericGraph< NodeTy, EdgeTy >
typedef NodeTy NodeType
 
typedef EdgeTy EdgeType
 
typedef OrderedMap< NodeID, NodeType * > IDToNodeMapTy
 NodeID to GenericNode map. More...
 
typedef IDToNodeMapTy::iterator iterator
 Node Iterators. More...
 
typedef IDToNodeMapTy::const_iterator const_iterator
 

Public Member Functions

 TCT (PointerAnalysis *p)
 Constructor. More...
 
virtual ~TCT ()
 Destructor. More...
 
SVFModulegetSVFModule () const
 Get SVFFModule. More...
 
ThreadCallGraphgetThreadCallGraph () const
 Get TCG. More...
 
PointerAnalysisgetPTA () const
 Get PTA. More...
 
TCTNodegetTCTNode (NodeID id) const
 Get TCT node. More...
 
TCTEdgehasGraphEdge (TCTNode *src, TCTNode *dst, TCTEdge::CEDGEK kind) const
 Whether we have already created this call graph edge. More...
 
TCTEdgegetGraphEdge (TCTNode *src, TCTNode *dst, TCTEdge::CEDGEK kind)
 Get call graph edge via nodes. More...
 
ThreadCreateEdgeSet::const_iterator getChildrenBegin (const TCTNode *node) const
 Get children and parent nodes. More...
 
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. More...
 
const FunSetgetEntryProcs () const
 Get marked candidate functions. More...
 
u32_t getTCTNodeNum () const
 Get Statistics. More...
 
u32_t getTCTEdgeNum () const
 
u32_t getMaxCxtSize () const
 
bool isExtCall (const ICFGNode *inst)
 Whether it is calling an external function. More...
 
bool isCallSite (const ICFGNode *inst)
 Whether it is a callsite. More...
 
bool hasTCTNode (const CxtThread &ct) const
 Find/Get TCT node. More...
 
TCTNodegetTCTNode (const CxtThread &ct) const
 
bool isCandidateFun (const PTACallGraph::FunctionSet &callees) const
 Whether it is a candidate function for indirect call. More...
 
bool isCandidateFun (const SVFFunction *fun) const
 
bool inSameCallGraphSCC (const PTACallGraphNode *src, const PTACallGraphNode *dst)
 Whether two functions in the same callgraph scc. More...
 
bool hasParentThread (NodeID tid) const
 Get parent and sibling threads. More...
 
NodeID getParentThread (NodeID tid) const
 Get parent thread. More...
 
const NodeBS getAncestorThread (NodeID tid) const
 Get all ancestor threads. More...
 
const NodeBS getSiblingThread (NodeID tid) const
 Get sibling threads. More...
 
const CallStrCxtgetCxtOfCxtThread (const CxtThread &ct) const
 get the context of a thread at its spawning site (fork site) More...
 
const SVFFunctiongetStartRoutineOfCxtThread (const CxtThread &ct) const
 get the start routine function of a thread More...
 
LoopBBsgetJoinLoop (const CallICFGNode *join)
 Get loop for join site. More...
 
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. More...
 
const LoopBBsgetLoop (const ICFGNode *inst)
 Get loop for an instruction. More...
 
const LoopBBsgetLoop (const SVFBasicBlock *bb)
 Get loop for fork/join site. More...
 
void pushCxt (CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
 Push calling context. More...
 
bool matchCxt (CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
 Match context. More...
 
void pushCxt (CallStrCxt &cxt, CallSiteID csId)
 
bool isJoinSiteInRecursion (const CallICFGNode *join) const
 Whether a join site is in recursion. More...
 
void dumpCxt (CallStrCxt &cxt)
 Dump calling context. More...
 
void dump (const std::string &filename)
 Dump the graph. More...
 
void print () const
 Print TCT information. More...
 
- Public Member Functions inherited from SVF::GenericGraph< NodeTy, EdgeTy >
 GenericGraph ()
 Constructor. More...
 
virtual ~GenericGraph ()
 Destructor. More...
 
void destroy ()
 Release memory. More...
 
iterator begin ()
 Iterators. More...
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
void addGNode (NodeID id, NodeType *node)
 Add a Node. More...
 
NodeTypegetGNode (NodeID id) const
 Get a node. More...
 
bool hasGNode (NodeID id) const
 Has a node. More...
 
void removeGNode (NodeType *node)
 Delete a node. More...
 
u32_t getTotalNodeNum () const
 Get total number of node/edge. More...
 
u32_t getTotalEdgeNum () const
 
void incNodeNum ()
 Increase number of node/edge. More...
 
void incEdgeNum ()
 

Private Member Functions

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

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. More...
 
ThreadCallGraphSCCtcgSCC
 Procedures we care about during call graph traversing when creating TCT. More...
 
CxtThreadProcVec ctpList
 Thread call graph SCC. More...
 
CxtThreadProcSet visitedCTPs
 CxtThreadProc List. More...
 
CxtThreadToNodeMap ctpToNodeMap
 Record all visited ctps. More...
 
CxtThreadToForkCxt ctToForkCxtMap
 Map a ctp to its graph node. More...
 
CxtThreadToFun ctToRoutineFunMap
 Map a CxtThread to the context at its spawning site (fork site). More...
 
InstToLoopMap joinSiteToLoopMap
 Map a CxtThread to its start routine function. More...
 
Set< const ICFGNode * > inRecurJoinSites
 Fork or Join sites in recursions. More...
 

Additional Inherited Members

- Public Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
u32_t edgeNum
 total num of node More...
 
u32_t nodeNum
 total num of edge More...
 
- Protected Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
IDToNodeMapTy IDToNodeMap
 node map More...
 

Detailed Description

Definition at line 153 of file TCT.h.

Member Typedef Documentation

◆ CxtThreadProcSet

Definition at line 169 of file TCT.h.

◆ CxtThreadProcVec

Definition at line 168 of file TCT.h.

◆ CxtThreadToForkCxt

Definition at line 165 of file TCT.h.

◆ CxtThreadToFun

Definition at line 166 of file TCT.h.

◆ CxtThreadToNodeMap

Definition at line 164 of file TCT.h.

◆ FunSet

typedef Set<const SVFFunction*> SVF::TCT::FunSet

Definition at line 160 of file TCT.h.

◆ InstSet

typedef Set<const ICFGNode*> SVF::TCT::InstSet

Definition at line 162 of file TCT.h.

◆ InstToLoopMap

Definition at line 167 of file TCT.h.

◆ InstVec

typedef std::vector<const ICFGNode*> SVF::TCT::InstVec

Definition at line 161 of file TCT.h.

◆ LoopBBs

Definition at line 157 of file TCT.h.

◆ PTACGNodeSet

Definition at line 163 of file TCT.h.

◆ TCTNodeIter

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

Definition at line 159 of file TCT.h.

◆ ThreadCallGraphSCC

Definition at line 170 of file TCT.h.

◆ ThreadCreateEdgeSet

Definition at line 158 of file TCT.h.

Constructor & Destructor Documentation

◆ TCT()

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

Constructor.

Definition at line 173 of file TCT.h.

174  {
175  tcg = SVFUtil::cast<ThreadCallGraph>(pta->getCallGraph());
177  //tcg->updateJoinEdge(pta);
179  tcgSCC->find();
180  build();
181  }
cJSON * p
Definition: cJSON.cpp:2559
CallGraphSCC * getCallGraphSCC() const
Return call graph SCC.
PTACallGraph * getCallGraph() const
Return call graph.
void find(void)
Definition: SCC.h:308
ThreadCallGraphSCC * tcgSCC
Procedures we care about during call graph traversing when creating TCT.
Definition: TCT.h:590
u32_t TCTNodeNum
Definition: TCT.h:445
u32_t TCTEdgeNum
Definition: TCT.h:446
PointerAnalysis * pta
Definition: TCT.h:444
u32_t MaxCxtSize
Definition: TCT.h:447
void build()
Build TCT.
Definition: TCT.cpp:383
ThreadCallGraph * tcg
Definition: TCT.h:443
void updateCallGraph(PointerAnalysis *pta)
Update call graph using pointer results.

◆ ~TCT()

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

Destructor.

Definition at line 184 of file TCT.h.

185  {
186  destroy();
187  }
void destroy()
Clean up memory.
Definition: TCT.h:581

Member Function Documentation

◆ addCxtOfCxtThread()

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

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

Definition at line 549 of file TCT.h.

550  {
551  ctToForkCxtMap[ct] = cxt;
552  }
CxtThreadToForkCxt ctToForkCxtMap
Map a ctp to its graph node.
Definition: TCT.h:594

◆ addStartRoutineOfCxtThread()

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

Add start routine function of a cxt thread.

Definition at line 554 of file TCT.h.

555  {
556  ctToRoutineFunMap[ct] = fun;
557  }
CxtThreadToFun ctToRoutineFunMap
Map a CxtThread to the context at its spawning site (fork site).
Definition: TCT.h:595

◆ addTCTEdge()

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

Add TCT edge.

Definition at line 461 of file TCT.h.

462  {
463  if (!hasGraphEdge(src, dst, TCTEdge::ThreadCreateEdge))
464  {
465  TCTEdge* edge = new TCTEdge(src, dst, TCTEdge::ThreadCreateEdge);
466  dst->addIncomingEdge(edge);
467  src->addOutgoingEdge(edge);
468  TCTEdgeNum++;
469  return true;
470  }
471  return false;
472  }
@ ThreadCreateEdge
Definition: TCT.h:55
TCTEdge * hasGraphEdge(TCTNode *src, TCTNode *dst, TCTEdge::CEDGEK kind) const
Whether we have already created this call graph edge.
Definition: TCT.cpp:534

◆ addTCTNode()

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

Add TCT node.

Definition at line 450 of file TCT.h.

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

◆ build()

void TCT::build ( )
private

Build TCT.

Start building TCT

Definition at line 383 of file TCT.cpp.

384 {
385 
386  markRelProcs();
387 
389 
390  // the fork site of main function is initialized with nullptr.
391  // the context of main is initialized with empty
392  // start routine is empty
393 
395  for (FunSet::iterator it=entryFuncSet.begin(), eit=entryFuncSet.end(); it!=eit; ++it)
396  {
397  if (!isCandidateFun(*it))
398  continue;
399  CallStrCxt cxt;
400  TCTNode* mainTCTNode = getOrCreateTCTNode(cxt, nullptr, cxt, *it);
401  CxtThreadProc t(mainTCTNode->getId(), cxt, *it);
403  }
404 
405  while(!ctpList.empty())
406  {
408  PTACallGraphNode* cgNode = tcg->getCallGraphNode(ctp.getProc());
409  if(isCandidateFun(cgNode->getFunction()) == false)
410  continue;
411 
412  for(PTACallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit!=neit; nit++)
413  {
414  const PTACallGraphEdge* cgEdge = (*nit);
415 
416  for(PTACallGraphEdge::CallInstSet::const_iterator cit = cgEdge->directCallsBegin(),
417  ecit = cgEdge->directCallsEnd(); cit!=ecit; ++cit)
418  {
419  DBOUT(DMTA,outs() << "\nTCT handling direct call:" << **cit << "\t" << cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
420  handleCallRelation(ctp,cgEdge,*cit);
421  }
422  for(PTACallGraphEdge::CallInstSet::const_iterator ind = cgEdge->indirectCallsBegin(),
423  eind = cgEdge->indirectCallsEnd(); ind!=eind; ++ind)
424  {
425  DBOUT(DMTA,outs() << "\nTCT handling indirect call:" << **ind << "\t" << cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
426  handleCallRelation(ctp,cgEdge,*ind);
427  }
428  }
429  }
430 
432 
433  if (Options::TCTDotGraph())
434  {
435  print();
436  dump("tct");
437  }
438 
439 }
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition: SVFType.h:484
#define DMTA
Definition: SVFType.h:505
const SVFFunction * getProc() const
Return current procedure.
Definition: CxtStmt.h:327
bool empty() const
Definition: WorkList.h:146
NodeType * getSrcNode() const
Definition: GenericGraph.h:97
NodeType * getDstNode() const
Definition: GenericGraph.h:101
iterator OutEdgeEnd()
Definition: GenericGraph.h:458
iterator OutEdgeBegin()
iterators
Definition: GenericGraph.h:454
static const Option< bool > TCTDotGraph
Definition: Options.h:166
CallInstSet::const_iterator indirectCallsEnd() const
Definition: PTACallGraph.h:135
CallInstSet::const_iterator directCallsBegin() const
Iterators for direct and indirect callsites.
Definition: PTACallGraph.h:122
CallInstSet::const_iterator directCallsEnd() const
Definition: PTACallGraph.h:126
CallInstSet::const_iterator indirectCallsBegin() const
Definition: PTACallGraph.h:131
const SVFFunction * getFunction() const
Get function of this call node.
Definition: PTACallGraph.h:198
PTACallGraphEdge::CallGraphEdgeSet::const_iterator const_iterator
Definition: PTACallGraph.h:180
PTACallGraphNode * getCallGraphNode(NodeID id) const
Get call graph node.
Definition: PTACallGraph.h:339
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
bool pushToCTPWorkList(const CxtThreadProc &ctp)
WorkList helper functions.
Definition: TCT.h:561
FunSet entryFuncSet
Definition: TCT.h:588
void collectLoopInfoForJoin()
Handle join site in loop.
Definition: TCT.cpp:314
void collectEntryFunInCallGraph()
Get entry functions that are neither called by other functions nor extern functions.
Definition: TCT.cpp:186
TCTNode * getOrCreateTCTNode(const CallStrCxt &cxt, const ICFGNode *fork, const CallStrCxt &oldCxt, const SVFFunction *routine)
Get or create a tct node based on CxtThread.
Definition: TCT.h:513
void dump(const std::string &filename)
Dump the graph.
Definition: TCT.cpp:513
CxtThreadProcVec ctpList
Thread call graph SCC.
Definition: TCT.h:591
void markRelProcs()
Mark relevant procedures that are backward reachable from any fork/join site.
Definition: TCT.cpp:132
void handleCallRelation(CxtThreadProc &ctp, const PTACallGraphEdge *cgEdge, const CallICFGNode *call)
Handle call relations.
Definition: TCT.cpp:244
bool isCandidateFun(const PTACallGraph::FunctionSet &callees) const
Whether it is a candidate function for indirect call.
Definition: TCT.h:291
void print() const
Print TCT information.
Definition: TCT.cpp:522
void collectMultiForkedThreads()
Definition: TCT.cpp:206
CxtThreadProc popFromCTPWorkList()
Definition: TCT.h:570
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50
std::vector< u32_t > CallStrCxt
Definition: GeneralType.h:122

◆ collectEntryFunInCallGraph()

void TCT::collectEntryFunInCallGraph ( )
private

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

Get Main function

Definition at line 186 of file TCT.cpp.

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

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

315 {
316  for(ThreadCallGraph::CallSiteSet::const_iterator it = tcg->joinsitesBegin(), eit = tcg->joinsitesEnd(); it!=eit; ++it)
317  {
318  const ICFGNode* join = *it;
319  const SVFFunction* svffun = join->getFun();
320  const SVFBasicBlock* svfbb = join->getBB();
321 
322  if(svffun->hasLoopInfo(svfbb))
323  {
324  const LoopBBs& lp = svffun->getLoopInfo(svfbb);
325  if(!lp.empty() && isJoinMustExecutedInLoop(lp,join))
326  {
327  joinSiteToLoopMap[join] = lp;
328  }
329  }
330 
331  if(isInRecursion(join))
332  inRecurJoinSites.insert(join);
333  }
334 }
virtual const SVFFunction * getFun() const
Return the function of this ICFGNode.
Definition: ICFGNode.h:76
virtual const SVFBasicBlock * getBB() const
Return the basic block of this ICFGNode.
Definition: ICFGNode.h:82
bool hasLoopInfo(const SVFBasicBlock *bb) const
Definition: SVFValue.h:470
const LoopBBs & getLoopInfo(const SVFBasicBlock *bb) const
Definition: SVFValue.h:475
bool isInRecursion(const ICFGNode *inst) const
Whether an instruction is in a recursion.
Definition: TCT.cpp:90
InstToLoopMap joinSiteToLoopMap
Map a CxtThread to its start routine function.
Definition: TCT.h:596
bool isJoinMustExecutedInLoop(const LoopBBs &lp, const ICFGNode *join)
Return true if a join instruction must be executed inside a loop.
Definition: TCT.cpp:290
Set< const ICFGNode * > inRecurJoinSites
Fork or Join sites in recursions.
Definition: TCT.h:597
SVFLoopAndDomInfo::LoopBBs LoopBBs
Definition: TCT.h:157
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 206 of file TCT.cpp.

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

◆ destroy()

void SVF::TCT::destroy ( )
inlineprivate

Clean up memory.

Definition at line 581 of file TCT.h.

582  {
583  if(tcgSCC)
584  delete tcgSCC;
585  tcgSCC=nullptr;
586  }

◆ dump()

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

Dump the graph.

Dump call graph into dot file

Definition at line 513 of file TCT.cpp.

514 {
515  if (Options::TCTDotGraph())
516  GraphPrinter::WriteGraphToFile(outs(), filename, this);
517 }
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)
Definition: GraphPrinter.h:56

◆ dumpCxt()

void TCT::dumpCxt ( CallStrCxt cxt)

Dump calling context.

Dump calling context information

Definition at line 495 of file TCT.cpp.

496 {
497  std::string str;
498  std::stringstream rawstr(str);
499  rawstr << "[:";
500  for(CallStrCxt::const_iterator it = cxt.begin(), eit = cxt.end(); it!=eit; ++it)
501  {
502  rawstr << " ' "<< *it << " ' ";
503  rawstr << (tcg->getCallSite(*it))->valueOnlyToString();
504  rawstr << " call " << tcg->getCallSite(*it)->getCaller()->getName() << "-->" << tcg->getCalleeOfCallSite(*it)->getName() << ", \n";
505  }
506  rawstr << " ]";
507  outs() << "max cxt = " << cxt.size() << rawstr.str() << "\n";
508 }
const char *const string
Definition: cJSON.h:172
const SVFFunction * getCaller() const
Return callsite.
Definition: ICFGNode.h:470
const CallICFGNode * getCallSite(CallSiteID id) const
Definition: PTACallGraph.h:387
const SVFFunction * getCalleeOfCallSite(CallSiteID id) const
Definition: PTACallGraph.h:395
const std::string & getName() const
Definition: SVFValue.h:243

◆ getAncestorThread()

const NodeBS SVF::TCT::getAncestorThread ( 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;
336  worklist.push(getParentThread(tid));
337 
338  while(!worklist.empty())
339  {
340  NodeID t = worklist.pop();
341  if(tds.test_and_set(t))
342  {
343  if(hasParentThread(t))
344  worklist.push(getParentThread(t));
345  }
346  }
347  return tds;
348  }
NodeID getParentThread(NodeID tid) const
Get parent thread.
Definition: TCT.h:320
bool hasParentThread(NodeID tid) const
Get parent and sibling threads.
Definition: TCT.h:314
SparseBitVector NodeBS
Definition: GeneralType.h:62

◆ getChildrenBegin()

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

Get children and parent nodes.

Definition at line 217 of file TCT.h.

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

◆ getChildrenEnd()

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

Definition at line 221 of file TCT.h.

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

◆ getCxtOfCxtThread()

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

get the context of a thread at its spawning site (fork site)

Definition at line 369 of file TCT.h.

370  {
371  CxtThreadToForkCxt::const_iterator it = ctToForkCxtMap.find(ct);
372  assert(it!=ctToForkCxtMap.end() && "Cxt Thread not found!!");
373  return it->second;
374  }

◆ getEntryProcs()

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

Get marked candidate functions.

Definition at line 242 of file TCT.h.

243  {
244  return entryFuncSet;
245  }

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

552 {
553  for (TCTEdge::ThreadCreateEdgeSet::const_iterator iter = src->OutEdgeBegin(); iter != src->OutEdgeEnd(); ++iter)
554  {
555  TCTEdge* edge = (*iter);
556  if (edge->getEdgeKind() == kind && edge->getDstID() == dst->getId())
557  return edge;
558  }
559  return nullptr;
560 }
GEdgeKind getEdgeKind() const
Definition: GenericGraph.h:89
NodeID getDstID() const
Definition: GenericGraph.h:85

◆ getJoinLoop()

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

Get loop for join site.

Definition at line 385 of file TCT.h.

386  {
387  assert(tcg->getThreadAPI()->isTDJoin(join) && "not a join site");
388  InstToLoopMap::iterator it = joinSiteToLoopMap.find(join);
389  assert(it!=joinSiteToLoopMap.end() && "loop not found");
390  return it->second;
391  }
bool isTDJoin(const CallICFGNode *inst) const
Return true if this call wait for a worker thread.
Definition: ThreadAPI.cpp:138
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 374 of file TCT.cpp.

375 {
376  const SVFFunction* fun = bb->getParent();
377  return fun->getLoopInfo(bb);
378 }
const SVFFunction * getParent() const
Definition: SVFValue.h:584

◆ getMakredProcs()

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

Get marked candidate functions.

Definition at line 236 of file TCT.h.

237  {
238  return candidateFuncSet;
239  }
FunSet candidateFuncSet
Procedures that are neither called by other functions nor extern functions.
Definition: TCT.h:589

◆ getMaxCxtSize()

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

Definition at line 257 of file TCT.h.

258  {
259  return MaxCxtSize;
260  }

◆ getOrCreateTCTNode()

TCTNode* SVF::TCT::getOrCreateTCTNode ( const CallStrCxt cxt,
const ICFGNode fork,
const CallStrCxt oldCxt,
const SVFFunction routine 
)
inlineprivate

Get or create a tct node based on CxtThread.

Definition at line 513 of file TCT.h.

514  {
515  CxtThread ct(cxt,fork);
516  CxtThreadToNodeMap::const_iterator it = ctpToNodeMap.find(ct);
517  if(it!=ctpToNodeMap.end())
518  {
519  return it->second;
520  }
521 
522  addCxtOfCxtThread(oldCxt,ct);
523  addStartRoutineOfCxtThread(routine,ct);
524 
526  return addTCTNode(ct);
527  }
void setMultiForkedAttrs(CxtThread &ct)
Set multi-forked thread attributes.
Definition: TCT.h:531
void addCxtOfCxtThread(const CallStrCxt &cxt, const CxtThread &ct)
Add context for a thread at its spawning site (fork site)
Definition: TCT.h:549
TCTNode * addTCTNode(const CxtThread &ct)
Add TCT node.
Definition: TCT.h:450
void addStartRoutineOfCxtThread(const SVFFunction *fun, const CxtThread &ct)
Add start routine function of a cxt thread.
Definition: TCT.h:554

◆ getParentsBegin()

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

Definition at line 225 of file TCT.h.

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

◆ getParentsEnd()

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

Definition at line 229 of file TCT.h.

230  {
231  return node->InEdgeEnd();
232  }

◆ getParentThread()

NodeID SVF::TCT::getParentThread ( NodeID  tid) const
inline

Get parent thread.

Definition at line 320 of file TCT.h.

321  {
322  const TCTNode* node = getTCTNode(tid);
323  assert(node->getInEdges().size()<=1 && "should have at most one parent thread");
324  assert(node->getInEdges().size()==1 && "does not have a parent thread");
325  const TCTEdge* edge = *(node->getInEdges().begin());
326  return edge->getSrcID();
327  }

◆ getPTA()

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

Get PTA.

Definition at line 201 of file TCT.h.

202  {
203  return pta;
204  }

◆ getSiblingThread()

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

Get sibling threads.

Definition at line 350 of file TCT.h.

351  {
352  NodeBS tds;
353  if(hasParentThread(tid) == false)
354  return tds;
355 
356  const TCTNode* node = getTCTNode(getParentThread(tid));
357  for(ThreadCreateEdgeSet::const_iterator it = getChildrenBegin(node), eit = getChildrenEnd(node); it!=eit; ++it)
358  {
359  NodeID child = (*it)->getDstNode()->getId();
360  if(child!=tid)
361  tds.set(child);
362  }
363 
364  return tds;
365  }
cJSON * child
Definition: cJSON.cpp:2723
ThreadCreateEdgeSet::const_iterator getChildrenBegin(const TCTNode *node) const
Get children and parent nodes.
Definition: TCT.h:217
ThreadCreateEdgeSet::const_iterator getChildrenEnd(const TCTNode *node) const
Definition: TCT.h:221

◆ getStartRoutineOfCxtThread()

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

get the start routine function of a thread

Definition at line 377 of file TCT.h.

378  {
379  CxtThreadToFun::const_iterator it = ctToRoutineFunMap.find(ct);
380  assert(it!=ctToRoutineFunMap.end() && "Cxt Thread not found!!");
381  return it->second;
382  }

◆ getSVFModule()

SVFModule* SVF::TCT::getSVFModule ( ) const
inline

Get SVFFModule.

Definition at line 190 of file TCT.h.

191  {
192  return pta->getModule();
193  }
SVFModule * getModule() const
Module.

◆ getTCTEdgeNum()

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

Definition at line 253 of file TCT.h.

254  {
255  return TCTEdgeNum;
256  }

◆ getTCTNode() [1/2]

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

Definition at line 282 of file TCT.h.

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

◆ getTCTNode() [2/2]

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

Get TCT node.

Definition at line 206 of file TCT.h.

207  {
208  return getGNode(id);
209  }
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653

◆ getTCTNodeNum()

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

Get Statistics.

Definition at line 249 of file TCT.h.

250  {
251  return TCTNodeNum;
252  }

◆ getThreadCallGraph()

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

Get TCG.

Definition at line 196 of file TCT.h.

197  {
198  return tcg;
199  }

◆ handleCallRelation()

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

Handle call relations.

Handle call relations

Create spawnee TCT node

Add TCT nodes and edge

Definition at line 244 of file TCT.cpp.

245 {
246  const SVFFunction* callee = cgEdge->getDstNode()->getFunction();
247 
248  CallStrCxt cxt(ctp.getContext());
249  CallStrCxt oldCxt = cxt;
250  const CallICFGNode* callNode = cs;
251  pushCxt(cxt,callNode,callee);
252 
254  {
255  CxtThreadProc newctp(ctp.getTid(),cxt,callee);
256  if(pushToCTPWorkList(newctp))
257  {
258  DBOUT(DMTA,outs() << "TCT Process CallRet old ctp --"; ctp.dump());
259  DBOUT(DMTA,outs() << "TCT Process CallRet new ctp --"; newctp.dump());
260  }
261  }
262 
263  else if(cgEdge->getEdgeKind() == PTACallGraphEdge::TDForkEdge)
264  {
266  TCTNode* spawneeNode = getOrCreateTCTNode(cxt,callNode, oldCxt, callee);
267  CxtThreadProc newctp(spawneeNode->getId(),cxt,callee);
268 
269  if(pushToCTPWorkList(newctp))
270  {
272  if(addTCTEdge(this->getGNode(ctp.getTid()), spawneeNode))
273  {
274  DBOUT(DMTA,outs() << "Add TCT Edge from thread " << ctp.getTid() << " ";
275  this->getGNode(ctp.getTid())->getCxtThread().dump();
276  outs() << " to thread " << spawneeNode->getId() << " ";
277  spawneeNode->getCxtThread().dump();
278  outs() << "\n" );
279  }
280  DBOUT(DMTA,outs() << "TCT Process Fork old ctp --"; ctp.dump());
281  DBOUT(DMTA,outs() << "TCT Process Fork new ctp --"; newctp.dump());
282  }
283  }
284 }
const CallStrCxt & getContext() const
Return current context.
Definition: CxtStmt.h:332
NodeID getTid() const
Return current thread id.
Definition: CxtStmt.h:412
void dump() const
Dump CxtThreadProc.
Definition: CxtStmt.h:449
void dump() const
Dump CxtThread.
Definition: CxtStmt.h:279
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
Push calling context.
Definition: TCT.cpp:444
bool addTCTEdge(TCTNode *src, TCTNode *dst)
Add TCT edge.
Definition: TCT.h:461

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

535 {
536  TCTEdge edge(src, dst, kind);
537  TCTEdge* outEdge = src->hasOutgoingEdge(&edge);
538  TCTEdge* inEdge = dst->hasIncomingEdge(&edge);
539  if (outEdge && inEdge)
540  {
541  assert(outEdge == inEdge && "edges not match");
542  return outEdge;
543  }
544  else
545  return nullptr;
546 }
bool hasOutgoingEdge() const
Definition: GenericGraph.h:446

◆ hasJoinLoop()

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

Definition at line 393 of file TCT.h.

394  {
395  assert(tcg->getThreadAPI()->isTDJoin(join) && "not a join site");
396  InstToLoopMap::const_iterator it = joinSiteToLoopMap.find(join);
397  return it!=joinSiteToLoopMap.end();
398  }

◆ hasLoop() [1/2]

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

Definition at line 405 of file TCT.h.

406  {
407  return hasLoop(inst->getBB());
408  }
bool hasLoop(const SVFBasicBlock *bb) const
Definition: TCT.h:400

◆ hasLoop() [2/2]

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

Definition at line 400 of file TCT.h.

401  {
402  const SVFFunction* fun = bb->getFunction();
403  return fun->hasLoopInfo(bb);
404  }

◆ hasParentThread()

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

Get parent and sibling threads.

Has parent thread

Definition at line 314 of file TCT.h.

315  {
316  const TCTNode* node = getTCTNode(tid);
317  return node->getInEdges().size()==1;
318  }

◆ hasTCTNode()

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

Find/Get TCT node.

Definition at line 278 of file TCT.h.

279  {
280  return ctpToNodeMap.find(ct)!=ctpToNodeMap.end();
281  }

◆ inSameCallGraphSCC()

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

Whether two functions in the same callgraph scc.

Definition at line 306 of file TCT.h.

307  {
308  return (tcgSCC->repNode(src->getId()) == tcgSCC->repNode(dst->getId()));
309  }
NodeID repNode(NodeID n) const
get the rep node if not found return itself
Definition: SCC.h:139

◆ isCallSite()

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

Whether it is a callsite.

Definition at line 271 of file TCT.h.

272  {
273  return SVFUtil::isa<CallICFGNode>(inst);
274  }

◆ isCandidateFun() [1/2]

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

Whether it is a candidate function for indirect call.

Definition at line 291 of file TCT.h.

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

◆ isCandidateFun() [2/2]

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

Definition at line 301 of file TCT.h.

302  {
303  return candidateFuncSet.find(fun)!=candidateFuncSet.end();
304  }

◆ isExtCall()

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

Whether it is calling an external function.

Definition at line 264 of file TCT.h.

265  {
266  if(const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(inst))
267  return SVFUtil::isExtCall(call);
268  return false;
269  }

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

46 {
47  assert(inst && "null value instruction!!");
48 
51  worklist.push(inst);
52 
53  while(!worklist.empty())
54  {
55  const ICFGNode* inst = worklist.pop();
56  insts.insert(inst);
57  PTACallGraphNode* cgnode = tcg->getCallGraphNode(inst->getFun());
58  for(PTACallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++)
59  {
60  for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*nit)->directCallsBegin(),
61  ecit = (*nit)->directCallsEnd(); cit!=ecit; ++cit)
62  {
63  if(insts.insert(*cit).second)
64  worklist.push(*cit);
65  }
66  for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*nit)->indirectCallsBegin(),
67  ecit = (*nit)->indirectCallsEnd(); cit!=ecit; ++cit)
68  {
69  if(insts.insert(*cit).second)
70  worklist.push(*cit);
71  }
72  }
73  }
74 
75  for(const ICFGNode* i : insts)
76  {
77  if(i->getFun()->hasLoopInfo(i->getBB()))
78  return true;
79  }
80 
81 
82  return false;
83 }
iterator InEdgeBegin()
Definition: GenericGraph.h:462
iterator InEdgeEnd()
Definition: GenericGraph.h:466
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96

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

91 {
92  const SVFFunction* f = inst->getFun();
95  worklist.push(f);
96 
97  while(!worklist.empty())
98  {
99  const SVFFunction* svffun = worklist.pop();
100  visits.insert(svffun);
101  if(tcgSCC->isInCycle(tcg->getCallGraphNode(svffun)->getId()))
102  return true;
103 
104  const PTACallGraphNode* cgnode = tcg->getCallGraphNode(svffun);
105 
106  for(PTACallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++)
107  {
108  for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*nit)->directCallsBegin(),
109  ecit = (*nit)->directCallsEnd(); cit!=ecit; ++cit)
110  {
111  const SVFFunction* caller = (*cit)->getFun();
112  if(visits.find(caller)==visits.end())
113  worklist.push(caller);
114  }
115  for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*nit)->indirectCallsBegin(),
116  ecit = (*nit)->indirectCallsEnd(); cit!=ecit; ++cit)
117  {
118  const SVFFunction* caller = (*cit)->getFun();
119  if(visits.find(caller)==visits.end())
120  worklist.push(caller);
121  }
122  }
123  }
124 
125  return false;
126 
127 }
bool isInCycle(NodeID n) const
whether the node is in a cycle
Definition: SCC.h:149

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

291 {
292  assert(!lp.empty() && "this is not a loop, empty basic block");
293  const SVFFunction* svffun = join->getFun();
294  const SVFBasicBlock* loopheadbb = svffun->getLoopHeader(lp);
295  const SVFBasicBlock* joinbb = join->getBB();
296  assert(loopheadbb->getParent()==joinbb->getParent() && "should inside same function");
297 
298  for (const SVFBasicBlock* svf_scc_bb : loopheadbb->getSuccessors())
299  {
300  if(svffun->loopContainsBB(lp,svf_scc_bb))
301  {
302  if(svffun->dominate(joinbb,svf_scc_bb)==false)
303  return false;
304  }
305  }
306 
307  return true;
308 }
const std::vector< const SVFBasicBlock * > & getSuccessors() const
Definition: SVFValue.h:606
bool dominate(const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
Definition: SVFValue.h:505
bool loopContainsBB(const BBList &lp, const SVFBasicBlock *bb) const
Definition: SVFValue.h:485
const SVFBasicBlock * getLoopHeader(const BBList &lp) const
Definition: SVFValue.h:480

◆ isJoinSiteInRecursion()

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

Whether a join site is in recursion.

Definition at line 428 of file TCT.h.

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

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

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

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

340 {
341  for(InstToLoopMap::const_iterator it = joinSiteToLoopMap.begin(), eit = joinSiteToLoopMap.end(); it!=eit; ++it)
342  {
343  if(bb->getParent()->getLoopHeader(it->second) == bb)
344  return true;
345  }
346 
347  return false;
348 }

◆ isVisitedCTPs()

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

Definition at line 575 of file TCT.h.

576  {
577  return visitedCTPs.find(ctp)!=visitedCTPs.end();
578  }
CxtThreadProcSet visitedCTPs
CxtThreadProc List.
Definition: TCT.h:592

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

133 {
134  for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->forksitesBegin(), eit = tcg->forksitesEnd(); it != eit; ++it)
135  {
136  const SVFFunction* svfun = (*it)->getParent()->getParent();
137  markRelProcs(svfun);
138 
139  for(ThreadCallGraph::ForkEdgeSet::const_iterator nit = tcg->getForkEdgeBegin(*it), neit = tcg->getForkEdgeEnd(*it); nit!=neit; nit++)
140  {
141  const PTACallGraphNode* forkeeNode = (*nit)->getDstNode();
142  candidateFuncSet.insert(forkeeNode->getFunction());
143  }
144 
145  }
146 
147  for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->joinsitesBegin(), eit = tcg->joinsitesEnd(); it != eit; ++it)
148  {
149  const SVFFunction* svfun = (*it)->getParent()->getParent();
150  markRelProcs(svfun);
151  }
152 
153  if(candidateFuncSet.empty())
154  writeWrnMsg("We didn't recognize any fork site, this is single thread program?");
155 }
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:66

◆ markRelProcs() [2/2]

void TCT::markRelProcs ( const SVFFunction fun)
private

Definition at line 160 of file TCT.cpp.

161 {
162  PTACallGraphNode* cgnode = tcg->getCallGraphNode(svffun);
164  PTACGNodeSet visited;
165  worklist.push(cgnode);
166  visited.insert(cgnode);
167  while(!worklist.empty())
168  {
169  const PTACallGraphNode* node = worklist.pop();
170  candidateFuncSet.insert(node->getFunction());
171  for(PTACallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit!=neit; nit++)
172  {
173  const PTACallGraphNode* srcNode = (*nit)->getSrcNode();
174  if(visited.find(srcNode)==visited.end())
175  {
176  visited.insert(srcNode);
177  worklist.push(srcNode);
178  }
179  }
180  }
181 }
Set< const PTACallGraphNode * > PTACGNodeSet
Definition: TCT.h:163

◆ matchCxt()

bool TCT::matchCxt ( CallStrCxt cxt,
const CallICFGNode call,
const SVFFunction callee 
)

Match context.

Match calling context

handle calling context for candidate functions only

partial match

Definition at line 465 of file TCT.cpp.

466 {
467 
468  const SVFFunction* caller = call->getFun();
469  CallSiteID csId = tcg->getCallSiteID(call, callee);
470 
472  if(isCandidateFun(caller) == false)
473  return true;
474 
476  if(cxt.empty())
477  return true;
478 
479  if(inSameCallGraphSCC(tcg->getCallGraphNode(caller),tcg->getCallGraphNode(callee))==false)
480  {
481  if(cxt.back() == csId)
482  cxt.pop_back();
483  else
484  return false;
485  DBOUT(DMTA,dumpCxt(cxt));
486  }
487 
488  return true;
489 }
CallSiteID getCallSiteID(const CallICFGNode *cs, const SVFFunction *callee) const
Definition: PTACallGraph.h:368
bool inSameCallGraphSCC(const PTACallGraphNode *src, const PTACallGraphNode *dst)
Whether two functions in the same callgraph scc.
Definition: TCT.h:306
void dumpCxt(CallStrCxt &cxt)
Dump calling context.
Definition: TCT.cpp:495
unsigned CallSiteID
Definition: GeneralType.h:58

◆ popFromCTPWorkList()

CxtThreadProc SVF::TCT::popFromCTPWorkList ( )
inlineprivate

Definition at line 570 of file TCT.h.

571  {
572  CxtThreadProc ctp = ctpList.pop();
573  return ctp;
574  }

◆ print()

void TCT::print ( void  ) const

Print TCT information.

Print TCT information

Definition at line 522 of file TCT.cpp.

523 {
524  for(TCT::const_iterator it = this->begin(), eit = this->end(); it!=eit; ++it)
525  {
526  outs() << "TID " << it->first << "\t";
527  it->second->getCxtThread().dump();
528  }
529 }
iterator begin()
Iterators.
Definition: GenericGraph.h:627
IDToNodeMapTy::const_iterator const_iterator
Definition: GenericGraph.h:607

◆ pushCxt() [1/2]

void SVF::TCT::pushCxt ( CallStrCxt cxt,
CallSiteID  csId 
)
inline

Definition at line 421 of file TCT.h.

422  {
423  cxt.push_back(csId);
424  if (cxt.size() > MaxCxtSize)
425  MaxCxtSize = cxt.size();
426  }

◆ pushCxt() [2/2]

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

Push calling context.

Push calling context

handle calling context for candidate functions only

Definition at line 444 of file TCT.cpp.

445 {
446 
447  const SVFFunction* caller = call->getFun();
448  CallSiteID csId = tcg->getCallSiteID(call, callee);
449 
451  if(isCandidateFun(caller) == false)
452  return;
453 
454  if(inSameCallGraphSCC(tcg->getCallGraphNode(caller),tcg->getCallGraphNode(callee))==false)
455  {
456  pushCxt(cxt,csId);
457  DBOUT(DMTA,dumpCxt(cxt));
458  }
459 }

◆ pushToCTPWorkList()

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

WorkList helper functions.

Definition at line 561 of file TCT.h.

562  {
563  if(isVisitedCTPs(ctp)==false)
564  {
565  visitedCTPs.insert(ctp);
566  return ctpList.push(ctp);
567  }
568  return false;
569  }
bool isVisitedCTPs(const CxtThreadProc &ctp) const
Definition: TCT.h:575

◆ setMultiForkedAttrs()

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

Set multi-forked thread attributes.

non-main thread

main thread

Definition at line 531 of file TCT.h.

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

Member Data Documentation

◆ candidateFuncSet

FunSet SVF::TCT::candidateFuncSet
private

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

Definition at line 589 of file TCT.h.

◆ ctpList

CxtThreadProcVec SVF::TCT::ctpList
private

Thread call graph SCC.

Definition at line 591 of file TCT.h.

◆ ctpToNodeMap

CxtThreadToNodeMap SVF::TCT::ctpToNodeMap
private

Record all visited ctps.

Definition at line 593 of file TCT.h.

◆ ctToForkCxtMap

CxtThreadToForkCxt SVF::TCT::ctToForkCxtMap
private

Map a ctp to its graph node.

Definition at line 594 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 595 of file TCT.h.

◆ entryFuncSet

FunSet SVF::TCT::entryFuncSet
private

Definition at line 588 of file TCT.h.

◆ inRecurJoinSites

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

Fork or Join sites in recursions.

Definition at line 597 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 596 of file TCT.h.

◆ MaxCxtSize

u32_t SVF::TCT::MaxCxtSize
private

Definition at line 447 of file TCT.h.

◆ pta

PointerAnalysis* SVF::TCT::pta
private

Definition at line 444 of file TCT.h.

◆ tcg

ThreadCallGraph* SVF::TCT::tcg
private

Definition at line 443 of file TCT.h.

◆ tcgSCC

ThreadCallGraphSCC* SVF::TCT::tcgSCC
private

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

Definition at line 590 of file TCT.h.

◆ TCTEdgeNum

u32_t SVF::TCT::TCTEdgeNum
private

Definition at line 446 of file TCT.h.

◆ TCTNodeNum

u32_t SVF::TCT::TCTNodeNum
private

Definition at line 445 of file TCT.h.

◆ visitedCTPs

CxtThreadProcSet SVF::TCT::visitedCTPs
private

CxtThreadProc List.

Definition at line 592 of file TCT.h.


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