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

#include <MHP.h>

Public Types

typedef Set< const FunObjVar * > FunSet
 
typedef FIFOWorkList< CxtThreadStmtCxtThreadStmtWorkList
 
typedef Set< CxtThreadStmtCxtThreadStmtSet
 
typedef Map< CxtThreadStmt, NodeBSThreadStmtToThreadInterleav
 
typedef Map< const ICFGNode *, CxtThreadStmtSetInstToThreadStmtSetMap
 
typedef SVFLoopAndDomInfo::LoopBBs LoopBBs
 
typedef Set< CxtStmtLockSpan
 
typedef std::pair< const FunObjVar *, const FunObjVar * > FuncPair
 
typedef Map< FuncPair, boolFuncPairToBool
 

Public Member Functions

 MHP (TCT *t)
 Constructor.
 
virtual ~MHP ()
 Destructor.
 
template<class ICFGGraph , class CGGraph >
void analyze (ICFGGraph icfg, CGGraph cg)
 
template<class ICFGGraph , class CGGraph >
void analyzeInterleaving (ICFGGraph icfg, CGGraph cg)
 Analyze thread interleaving.
 
ThreadCallGraphgetThreadCallGraph () const
 Get ThreadCallGraph.
 
TCTgetTCT () const
 Get Thread Creation Tree.
 
bool isConnectedfromMain (const FunObjVar *fun)
 Whether the function is connected from main function in thread call graph.
 
virtual bool mayHappenInParallel (const ICFGNode *i1, const ICFGNode *i2)
 Interface to query whether two instructions may happen-in-parallel.
 
virtual bool mayHappenInParallelCache (const ICFGNode *i1, const ICFGNode *i2)
 
virtual bool mayHappenInParallelInst (const ICFGNode *i1, const ICFGNode *i2)
 
virtual bool executedByTheSameThread (const ICFGNode *i1, const ICFGNode *i2)
 
const NodeBSgetInterleavingThreads (const CxtThreadStmt &cts)
 Get interleaving thread for statement inst.
 
bool hasInterleavingThreads (const CxtThreadStmt &cts) const
 
const CxtThreadStmtSetgetThreadStmtSet (const ICFGNode *inst) const
 Get/has ThreadStmt.
 
bool hasThreadStmtSet (const ICFGNode *inst) const
 
void printInterleaving ()
 Print interleaving results.
 

Public Attributes

u32_t numOfTotalQueries
 Total number of queries.
 
u32_t numOfMHPQueries
 Number of queries are answered as may-happen-in-parallel.
 
double interleavingTime
 
double interleavingQueriesTime
 

Protected Types

typedef Map< const SVFBasicBlock *, std::vector< CxtStmt > > BBToSymJoinsMap
 
typedef Map< CxtStmt, Set< const SVFBasicBlock * > > SymJoinToLoopMap
 

Protected Member Functions

const CallGraph::FunctionSetgetCallee (const CallICFGNode *inst, CallGraph::FunctionSet &callees)
 
template<class ICFGGraph , class CGGraph >
void updateNonCandidateFunInterleaving (ICFGGraph icfg, CGGraph cg)
 
template<class ICFGGraph , class CGGraph >
void handleNonCandidateFun (ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts)
 Handle non-candidate function.
 
template<class ICFGGraph , class CGGraph >
void handleFork (ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts, NodeID rootTid)
 Handle fork.
 
template<class ICFGGraph , class CGGraph >
void handleJoin (ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts, NodeID rootTid)
 Handle join.
 
template<class ICFGGraph , class CGGraph >
void handleCall (ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts, NodeID rootTid)
 Handle call.
 
template<class ICFGGraph , class CGGraph >
void handleRet (ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts)
 Handle return.
 
template<class ICFGGraph , class CGGraph >
void handleIntra (ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts)
 Handle intra.
 
void buildSymJoinKillTables ()
 
NodeBS edgeFlow (const CxtThreadStmt &cts, const ICFGNode *dst)
 
void addInterleavingThread (const CxtThreadStmt &tgr, NodeID tid)
 Add/Remove interleaving thread for statement inst.
 
void addInterleavingThread (const CxtThreadStmt &tgr, const CxtThreadStmt &src)
 
void addInterleavingBits (const CxtThreadStmt &tgr, const NodeBS &bits)
 
void rmInterleavingThread (const CxtThreadStmt &tgr, const NodeBS &tids, const ICFGNode *joinsite)
 
template<class ICFGGraph , class CGGraph >
void updateAncestorThreads (ICFGGraph icfg, CGGraph cg, NodeID tid)
 Update Ancestor and sibling threads.
 
template<class ICFGGraph , class CGGraph >
void updateSiblingThreads (ICFGGraph icfg, CGGraph cg, NodeID tid)
 
bool isRecurFullJoin (NodeID parentTid, NodeID curTid)
 Thread curTid can be fully joined by parentTid recursively.
 
bool isMustJoin (const NodeID curTid, const ICFGNode *joinsite)
 Whether a join site must join a thread t.
 
bool isMultiForkedThread (NodeID curTid)
 A thread is a multiForked thread if it is in a loop or recursion.
 
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 pushToCTSWorkList (const CxtThreadStmt &cs)
 WorkList helper functions.
 
CxtThreadStmt popFromCTSWorkList ()
 
bool isTDFork (const ICFGNode *call)
 Whether it is a fork site.
 
bool isTDJoin (const ICFGNode *call)
 Whether it is a join site.
 
NodeBS getDirAndIndJoinedTid (const CallStrCxt &cxt, const ICFGNode *call)
 Return thread id(s) which are directly or indirectly joined at this join site.
 
bool hasJoinInSymmetricLoop (const CallStrCxt &cxt, const ICFGNode *call) const
 Whether a context-sensitive join satisfies symmetric loop pattern.
 
const LoopBBsgetJoinInSymmetricLoop (const CallStrCxt &cxt, const ICFGNode *call) const
 Whether a context-sensitive join satisfies symmetric loop pattern.
 
bool isHBPair (NodeID tid1, NodeID tid2)
 Whether thread t1 happens before t2 based on ForkJoin Analysis.
 

Protected Attributes

ThreadCallGraphtcg
 TCG.
 
TCTtct
 TCT.
 
ForkJoinAnalysisfja
 ForJoin Analysis.
 
CxtThreadStmtWorkList cxtStmtList
 CxtThreadStmt worklist.
 
ThreadStmtToThreadInterleav threadStmtToThreadInterLeav
 
BBToSymJoinsMap bbToSymJoins
 Map a statement to its thread interleavings.
 
SymJoinToLoopMap symJoinLoop
 symmetric in-loop join -> its loop's blocks
 
InstToThreadStmtSetMap instToTSMap
 Map an instruction to its ThreadStmtSet.
 
FuncPairToBool nonCandidateFuncMHPRelMap
 

Detailed Description

This class serves as a base may-happen in parallel analysis for multithreaded program Given a statement under an abstract thread, it tells which abstract threads may be alive at the same time (May-happen-in-parallel).

Definition at line 56 of file MHP.h.

Member Typedef Documentation

◆ BBToSymJoinsMap

Symmetric-join loop-exit kills, applied to EDGE flows (node states stay pure unions, so paths bypassing the join keep their interleavings).

Definition at line 171 of file MHP.h.

◆ CxtThreadStmtSet

Definition at line 62 of file MHP.h.

◆ CxtThreadStmtWorkList

Definition at line 61 of file MHP.h.

◆ FuncPair

Definition at line 69 of file MHP.h.

◆ FuncPairToBool

Definition at line 70 of file MHP.h.

◆ FunSet

Definition at line 60 of file MHP.h.

◆ InstToThreadStmtSetMap

Definition at line 64 of file MHP.h.

◆ LockSpan

Definition at line 67 of file MHP.h.

◆ LoopBBs

Definition at line 65 of file MHP.h.

◆ SymJoinToLoopMap

Definition at line 172 of file MHP.h.

◆ ThreadStmtToThreadInterleav

Definition at line 63 of file MHP.h.

Constructor & Destructor Documentation

◆ MHP()

MHP::MHP ( TCT t)

Constructor.

Constructor

Definition at line 54 of file MHP.cpp.

56{
60}
void analyzeForkJoinPair()
Definition MHP.cpp:870
TCT * tct
TCT.
Definition MHP.h:298
u32_t numOfTotalQueries
Total number of queries.
Definition MHP.h:308
ThreadCallGraph * tcg
TCG.
Definition MHP.h:297
void buildSymJoinKillTables()
Definition MHP.cpp:65
ForkJoinAnalysis * fja
ForJoin Analysis.
Definition MHP.h:299
double interleavingQueriesTime
Definition MHP.h:311
u32_t numOfMHPQueries
Number of queries are answered as may-happen-in-parallel.
Definition MHP.h:309
double interleavingTime
Definition MHP.h:310
ThreadCallGraph * getThreadCallGraph() const
Get TCG.
Definition TCT.h:193

◆ ~MHP()

MHP::~MHP ( )
virtual

Destructor.

Destructor

Definition at line 110 of file MHP.cpp.

111{
112 delete fja;
113}

Member Function Documentation

◆ addInterleavingBits()

void SVF::MHP::addInterleavingBits ( const CxtThreadStmt tgr,
const NodeBS bits 
)
inlineprotected

Definition at line 196 of file MHP.h.

197 {
199 if(changed)
200 {
201 instToTSMap[tgr.getStmt()].insert(tgr);
203 }
204 }
InstToThreadStmtSetMap instToTSMap
Map an instruction to its ThreadStmtSet.
Definition MHP.h:304
ThreadStmtToThreadInterleav threadStmtToThreadInterLeav
Definition MHP.h:301
bool pushToCTSWorkList(const CxtThreadStmt &cs)
WorkList helper functions.
Definition MHP.h:262
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ addInterleavingThread() [1/2]

void SVF::MHP::addInterleavingThread ( const CxtThreadStmt tgr,
const CxtThreadStmt src 
)
inlineprotected

Definition at line 187 of file MHP.h.

188 {
190 if(changed)
191 {
192 instToTSMap[tgr.getStmt()].insert(tgr);
194 }
195 }

◆ addInterleavingThread() [2/2]

void SVF::MHP::addInterleavingThread ( const CxtThreadStmt tgr,
NodeID  tid 
)
inlineprotected

Add/Remove interleaving thread for statement inst.

Definition at line 179 of file MHP.h.

180 {
181 if(threadStmtToThreadInterLeav[tgr].test_and_set(tid))
182 {
183 instToTSMap[tgr.getStmt()].insert(tgr);
185 }
186 }

◆ analyze()

template<class ICFGGraph , class CGGraph >
template void MHP::analyze< const SlicedICFGView *, const SlicedThreadCallGraphView * > ( ICFGGraph  icfg,
CGGraph  cg 
)

Start analysis here. One implementation for the whole program and a slice: the compute is templated on the two graphs it traverses – the ICFG (ICFG* whole / const SlicedICFGView* sliced) and the CallGraph (CallGraph* whole / const SlicedThreadCallGraphView* sliced) – and calls their GenericGraphTraits specialisations directly (no wrapper layer).

Start analysis here

Definition at line 120 of file MHP.cpp.

121{
122 DBOUT(DGENERAL, outs() << pasMsg("MHP interleaving analysis\n"));
123 DBOUT(DMTA, outs() << pasMsg("MHP interleaving analysis\n"));
125 analyzeInterleaving(icfg, cg);
128}
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:576
#define TIMEINTERVAL
Definition SVFType.h:604
#define DMTA
Definition SVFType.h:597
#define DGENERAL
Definition SVFType.h:582
#define DOTIMESTAT(X)
Definition SVFType.h:578
void analyzeInterleaving(ICFGGraph icfg, CGGraph cg)
Analyze thread interleaving.
Definition MHP.cpp:134
static double getClk(bool mark=false)
Definition SVFStat.cpp:51
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
Definition SVFUtil.cpp:105
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52

◆ analyzeInterleaving()

template<class ICFGGraph , class CGGraph >
void MHP::analyzeInterleaving ( ICFGGraph  icfg,
CGGraph  cg 
)

Analyze thread interleaving.

Analyze thread interleaving

handle non-candidate function

handle candidate function

update non-candidate functions' interleaving

Definition at line 134 of file MHP.cpp.

135{
136 for (const std::pair<const NodeID, TCTNode*>& tpair : *tct)
137 {
138 const CxtThread& ct = tpair.second->getCxtThread();
139 NodeID rootTid = tpair.first;
142 CxtThreadStmt rootcts(rootTid, ct.getContext(), svfInst);
143
147
148 while (!cxtStmtList.empty())
149 {
151 const ICFGNode* curInst = cts.getStmt();
152
153 DBOUT(DMTA, outs() << "-----\nMHP analysis root thread: " << rootTid << " ");
154 DBOUT(DMTA, cts.dump());
155 DBOUT(DMTA, outs() << "current thread interleaving: < ");
157 DBOUT(DMTA, outs() << " >\n-----\n");
158
160 if (!tct->isCandidateFun(curInst->getFun()))
161 {
163 }
165 else
166 {
167 if (isTDFork(curInst))
168 {
169 handleFork(icfg, cg, cts, rootTid);
170 }
171 else if (isTDJoin(curInst))
172 {
173 handleJoin(icfg, cg, cts, rootTid);
174 }
175 else if (tct->isCallSite(curInst) && !tct->isExtCall(curInst))
176 {
177 handleCall(icfg, cg, cts, rootTid);
178 }
179 else if (SVFUtil::dyn_cast<FunExitICFGNode>(curInst))
180 {
181 handleRet(icfg, cg, cts);
182 }
183 else
184 {
185 handleIntra(icfg, cg, cts);
186 }
187 }
188 }
189 }
190
193
196}
bool empty() const
Definition WorkList.h:161
CxtThreadStmtWorkList cxtStmtList
CxtThreadStmt worklist.
Definition MHP.h:300
void handleRet(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts)
Handle return.
Definition MHP.cpp:418
void printInterleaving()
Print interleaving results.
Definition MHP.cpp:796
void updateSiblingThreads(ICFGGraph icfg, CGGraph cg, NodeID tid)
Definition MHP.cpp:565
void handleFork(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts, NodeID rootTid)
Handle fork.
Definition MHP.cpp:263
void updateAncestorThreads(ICFGGraph icfg, CGGraph cg, NodeID tid)
Update Ancestor and sibling threads.
Definition MHP.cpp:521
void handleCall(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts, NodeID rootTid)
Handle call.
Definition MHP.cpp:358
void addInterleavingThread(const CxtThreadStmt &tgr, NodeID tid)
Add/Remove interleaving thread for statement inst.
Definition MHP.h:179
const NodeBS & getInterleavingThreads(const CxtThreadStmt &cts)
Get interleaving thread for statement inst.
Definition MHP.h:112
bool isTDFork(const ICFGNode *call)
Whether it is a fork site.
Definition MHP.h:273
void handleJoin(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts, NodeID rootTid)
Handle join.
Definition MHP.cpp:294
void updateNonCandidateFunInterleaving(ICFGGraph icfg, CGGraph cg)
Definition MHP.cpp:202
void handleIntra(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts)
Handle intra.
Definition MHP.cpp:496
CxtThreadStmt popFromCTSWorkList()
Definition MHP.h:266
void handleNonCandidateFun(ICFGGraph icfg, CGGraph cg, const CxtThreadStmt &cts)
Handle non-candidate function.
Definition MHP.cpp:240
bool isTDJoin(const ICFGNode *call)
Whether it is a join site.
Definition MHP.h:279
static const Option< bool > PrintInterLev
Definition Options.h:155
bool isCallSite(const ICFGNode *inst)
Whether it is a callsite.
Definition TCT.h:268
bool isCandidateFun(const CallGraph::FunctionSet &callees) const
Whether it is a candidate function for indirect call.
Definition TCT.h:288
bool isExtCall(const ICFGNode *inst)
Whether it is calling an external function.
Definition TCT.h:261
const FunObjVar * getStartRoutineOfCxtThread(const CxtThread &ct) const
get the start routine function of a thread
Definition TCT.h:382
void dumpSet(NodeBS To, OutStream &O=SVFUtil::outs())
Dump sparse bitvector set.
Definition SVFUtil.cpp:153
u32_t NodeID
Definition GeneralType.h:76

◆ buildSymJoinKillTables()

void MHP::buildSymJoinKillTables ( )
protected

Index the SCEV-symmetric in-loop joins by their loop blocks.

Definition at line 65 of file MHP.cpp.

66{
67 for (const auto& joinAndLoop : fja->getSymmetricLoopJoins())
68 {
70 for (const SVFBasicBlock* bb : joinAndLoop.second)
71 {
72 loopBlocks.insert(bb);
73 bbToSymJoins[bb].push_back(joinAndLoop.first);
74 }
75 }
76}
BBToSymJoinsMap bbToSymJoins
Map a statement to its thread interleavings.
Definition MHP.h:302
SymJoinToLoopMap symJoinLoop
symmetric in-loop join -> its loop's blocks
Definition MHP.h:303

◆ edgeFlow()

NodeBS MHP::edgeFlow ( const CxtThreadStmt cts,
const ICFGNode dst 
)
protected

Flow along edge cts.stmt -> dst: an edge leaving a symmetric join loop drops the joined tids (edge kill; the destination's state is never subtracted from).

Definition at line 82 of file MHP.cpp.

83{
85 const SVFBasicBlock* srcBB = cts.getStmt()->getBB();
86 const SVFBasicBlock* dstBB = dst->getBB();
87 if (srcBB == nullptr || dstBB == nullptr || srcBB == dstBB)
88 return flow;
89 BBToSymJoinsMap::const_iterator it = bbToSymJoins.find(srcBB);
90 if (it == bbToSymJoins.end())
91 return flow;
92 for (const CxtStmt& join : it->second)
93 {
94 if (join.getContext() != cts.getContext())
95 continue;
97 if (loopBlocks.find(dstBB) != loopBlocks.end())
98 continue; // edge stays inside the loop
99 if (!isMustJoin(cts.getTid(), join.getStmt()))
100 continue;
101 flow.intersectWithComplement(
102 getDirAndIndJoinedTid(join.getContext(), join.getStmt()));
103 }
104 return flow;
105}
virtual const SVFBasicBlock * getBB() const
Return the basic block of this ICFGNode.
Definition ICFGNode.h:81
bool isMustJoin(const NodeID curTid, const ICFGNode *joinsite)
Whether a join site must join a thread t.
Definition MHP.cpp:630
NodeBS getDirAndIndJoinedTid(const CallStrCxt &cxt, const ICFGNode *call)
Return thread id(s) which are directly or indirectly joined at this join site.
Definition MHP.cpp:640

◆ executedByTheSameThread()

bool MHP::executedByTheSameThread ( const ICFGNode i1,
const ICFGNode i2 
)
virtual

Definition at line 775 of file MHP.cpp.

776{
778 return true;
779
782 for (const CxtThreadStmt&ts1 : tsSet1)
783 {
784 for (const CxtThreadStmt& ts2 : tsSet2)
785 {
786 if (ts1.getTid() != ts2.getTid() || isMultiForkedThread(ts1.getTid()))
787 return false;
788 }
789 }
790 return true;
791}
bool isMultiForkedThread(NodeID curTid)
A thread is a multiForked thread if it is in a loop or recursion.
Definition MHP.h:233
Set< CxtThreadStmt > CxtThreadStmtSet
Definition MHP.h:62
const CxtThreadStmtSet & getThreadStmtSet(const ICFGNode *inst) const
Get/has ThreadStmt.
Definition MHP.h:124
bool hasThreadStmtSet(const ICFGNode *inst) const
Definition MHP.h:130

◆ getCallee()

const CallGraph::FunctionSet & SVF::MHP::getCallee ( const CallICFGNode inst,
CallGraph::FunctionSet callees 
)
inlineprotected

Definition at line 141 of file MHP.h.

142 {
143 tcg->getCallees(inst, callees);
144 return callees;
145 }
void getCallees(const CallICFGNode *cs, FunctionSet &callees)
Get all callees for a callsite.
Definition CallGraph.h:426

◆ getDirAndIndJoinedTid()

NodeBS MHP::getDirAndIndJoinedTid ( const CallStrCxt cxt,
const ICFGNode call 
)
protected

Return thread id(s) which are directly or indirectly joined at this join site.

Return thread id(s) which are directly or indirectly joined at this join site

Definition at line 640 of file MHP.cpp.

641{
642 CxtStmt cs(cxt, call);
643 return fja->getDirAndIndJoinedTid(cs);
644}
NodeBS getDirAndIndJoinedTid(const CxtStmt &cs)
Get directly and indirectly joined threadIDs based on a context-sensitive join site.
Definition MHP.cpp:1171

◆ getInterleavingThreads()

const NodeBS & SVF::MHP::getInterleavingThreads ( const CxtThreadStmt cts)
inline

Get interleaving thread for statement inst.

Definition at line 112 of file MHP.h.

113 {
115 }

◆ getJoinInSymmetricLoop()

const MHP::LoopBBs & MHP::getJoinInSymmetricLoop ( const CallStrCxt cxt,
const ICFGNode call 
) const
protected

Whether a context-sensitive join satisfies symmetric loop pattern.

Definition at line 656 of file MHP.cpp.

657{
658 CxtStmt cs(cxt, call);
659 return fja->getJoinInSymmetricLoop(cs);
660}
const LoopBBs & getJoinInSymmetricLoop(const CxtStmt &cs) const
Whether a context-sensitive join satisfies symmetric loop pattern.
Definition MHP.h:361

◆ getTCT()

TCT * SVF::MHP::getTCT ( ) const
inline

Get Thread Creation Tree.

Definition at line 95 of file MHP.h.

96 {
97 return tct;
98 }

◆ getThreadCallGraph()

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

Get ThreadCallGraph.

Definition at line 89 of file MHP.h.

90 {
91 return tcg;
92 }

◆ getThreadStmtSet()

const CxtThreadStmtSet & SVF::MHP::getThreadStmtSet ( const ICFGNode inst) const
inline

Get/has ThreadStmt.

Definition at line 124 of file MHP.h.

125 {
126 InstToThreadStmtSetMap::const_iterator it = instToTSMap.find(inst);
127 assert(it!=instToTSMap.end() && "no thread access the instruction?");
128 return it->second;
129 }

◆ handleCall()

template<class ICFGGraph , class CGGraph >
void MHP::handleCall ( ICFGGraph  icfg,
CGGraph  cg,
const CxtThreadStmt cts,
NodeID  rootTid 
)
protected

Handle call.

Handle call instruction in the current thread scope (excluding any fork site)

Propagate to the return site of the call instruction, only if the callee is a non-candidate function, while for candidate function, return site should be handled after the callee is handled.

Definition at line 358 of file MHP.cpp.

359{
360
361 const ICFGNode* call = cts.getStmt();
362 const CallStrCxt& curCxt = cts.getContext();
363 const CallICFGNode* cbn = cast<CallICFGNode>(call);
365 {
366 for (CallGraph::CallGraphEdgeSet::const_iterator cgIt = tcg->getCallEdgeBegin(cbn),
368 cgIt != ecgIt; ++cgIt)
369 {
370 const FunObjVar* svfcallee = (*cgIt)->getDstNode()->getFunction();
371 if (isExtCall(svfcallee))
372 continue;
373
375 const CallICFGNode* callicfgnode = SVFUtil::cast<CallICFGNode>(call);
380
381 // Return-flow rendezvous: if the callee's exit already has state
382 // under newCxt, forward it now (handleRet cannot see late callsites).
383 if (tct->isCandidateFun(svfcallee) && svfcallee->hasBasicBlock())
384 {
385 const ICFGNode* exitInst = svfcallee->getExitBB()->back();
388 {
389 CxtThreadStmt retCts(cts.getTid(), curCxt, cbn->getRetICFGNode());
391 }
392 }
393 }
394 }
395
399 if (const CallICFGNode *callSite = SVFUtil::cast<CallICFGNode>(call))
400 {
403 {
404 CxtThreadStmt newCts(cts.getTid(), cts.getContext(), callSite->getRetICFGNode());
406 }
407 }
408 else
409 {
410 assert(false && "cts.getStmt() is not a CallICFGNode!");
411 }
412}
CallGraphEdgeSet::const_iterator getCallEdgeBegin(const CallICFGNode *inst) const
Definition CallGraph.h:445
bool hasCallGraphEdge(const CallICFGNode *inst) const
Get call graph edge via call instruction.
Definition CallGraph.h:441
Set< const FunObjVar * > FunctionSet
Definition CallGraph.h:247
CallGraphEdgeSet::const_iterator getCallEdgeEnd(const CallICFGNode *inst) const
Definition CallGraph.h:452
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Context helper functions.
Definition MHP.h:241
const CallGraph::FunctionSet & getCallee(const CallICFGNode *inst, CallGraph::FunctionSet &callees)
Definition MHP.h:141
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:441
std::vector< u32_t > CallStrCxt
Definition GeneralType.h:96

◆ handleFork()

template<class ICFGGraph , class CGGraph >
void MHP::handleFork ( ICFGGraph  icfg,
CGGraph  cg,
const CxtThreadStmt cts,
NodeID  rootTid 
)
protected

Handle fork.

Handle fork

Definition at line 263 of file MHP.cpp.

264{
265
266 const ICFGNode* call = cts.getStmt();
267 const CallStrCxt& curCxt = cts.getContext();
268
269 assert(isTDFork(call));
270 const CallICFGNode* cbn = cast<CallICFGNode>(call);
272 {
273
274 for (ThreadCallGraph::ForkEdgeSet::const_iterator cgIt = tcg->getForkEdgeBegin(cbn),
276 cgIt != ecgIt; ++cgIt)
277 {
278 const FunObjVar* svfroutine = (*cgIt)->getDstNode()->getFunction();
282 CxtThread ct(newCxt, call);
283 CxtThreadStmt newcts(tct->getTCTNode(ct)->getId(), ct.getContext(), stmt);
285 }
286 }
287 handleIntra(icfg, cg, cts);
288}
NodeID getId() const
Get ID.
Definition SVFValue.h:158
TCTNode * getTCTNode(NodeID id) const
Get TCT node.
Definition TCT.h:203
ForkEdgeSet::const_iterator getForkEdgeEnd(const CallICFGNode *cs) const
ForkEdgeSet::const_iterator getForkEdgeBegin(const CallICFGNode *cs) const

◆ handleIntra()

template<class ICFGGraph , class CGGraph >
void MHP::handleIntra ( ICFGGraph  icfg,
CGGraph  cg,
const CxtThreadStmt cts 
)
protected

Handle intra.

Handling intraprocedural statements (successive statements on the CFG )

Definition at line 496 of file MHP.cpp.

497{
498 const SVFBasicBlock* srcBB = cts.getStmt()->getBB();
499 const bool mayExitSymJoinLoop =
500 srcBB != nullptr && bbToSymJoins.find(srcBB) != bbToSymJoins.end();
501
502 std::vector<const ICFGNode*> succ;
504 for (const ICFGNode* dst : succ)
505 {
506 if(dst->getFun() == cts.getStmt()->getFun())
507 {
508 CxtThreadStmt newCts(cts.getTid(), cts.getContext(), dst);
511 else
513 }
514 }
515}
NodeBS edgeFlow(const CxtThreadStmt &cts, const ICFGNode *dst)
Definition MHP.cpp:82
void addInterleavingBits(const CxtThreadStmt &tgr, const NodeBS &bits)
Definition MHP.h:196
const_iterator end() const

◆ handleJoin()

template<class ICFGGraph , class CGGraph >
void MHP::handleJoin ( ICFGGraph  icfg,
CGGraph  cg,
const CxtThreadStmt cts,
NodeID  rootTid 
)
protected

Handle join.

Handle join

for the join site in a loop loop which does not join the current thread we process the loop exit

Definition at line 294 of file MHP.cpp.

295{
296
297 const CallStrCxt& curCxt = cts.getContext();
298
299 assert(isTDJoin(cts.getStmt()));
300
301 const CallICFGNode* call = SVFUtil::cast<CallICFGNode>(cts.getStmt());
302
304 if (!joinedTids.empty())
305 {
306 if (fja->hasJoinLoop(call))
307 {
308 // Seed the loop exits with the flow along the exiting edge (see
309 // edgeFlow): the kill applies to the flow, not the exit's state.
311 if (hasJoinInSymmetricLoop(curCxt, call) && isMustJoin(cts.getTid(), call))
312 flow.intersectWithComplement(joinedTids);
313
314 std::vector<const SVFBasicBlock*> exitbbs;
315 call->getFun()->getExitBlocksOfLoop(call->getBB(), exitbbs);
316 while (!exitbbs.empty())
317 {
318 const SVFBasicBlock* eb = exitbbs.back();
319 exitbbs.pop_back();
320 // Seed the post-join interleaving at the loop-exit entry. The slicer
321 // retains these entries as anchors, so the seed always lands on a kept
322 // node (no runtime projection needed).
323 CxtThreadStmt newCts(cts.getTid(), curCxt, eb->front());
325 }
326 }
327 else
328 {
330 DBOUT(DMTA, outs() << "\n\t match join site " << call->toString() << " for thread " << rootTid << "\n");
331 }
332 }
335 else
336 {
337 if (fja->hasJoinLoop(call))
338 {
339 std::vector<const SVFBasicBlock*> exitbbs;
340 call->getFun()->getExitBlocksOfLoop(call->getBB(), exitbbs);
341 while (!exitbbs.empty())
342 {
343 const SVFBasicBlock* eb = exitbbs.back();
344 exitbbs.pop_back();
345 // Seed at the loop-exit entry (a retained anchor; see above).
346 CxtThreadStmt newCts(cts.getTid(), cts.getContext(), eb->front());
348 }
349 }
350 }
351 handleIntra(icfg, cg, cts);
352}
const std::string toString() const override
Definition ICFG.cpp:129
bool hasJoinLoop(const CallICFGNode *inst)
Definition MHP.h:392
void getExitBlocksOfLoop(const SVFBasicBlock *bb, BBList &exitbbs) const
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:75
void rmInterleavingThread(const CxtThreadStmt &tgr, const NodeBS &tids, const ICFGNode *joinsite)
Definition MHP.h:205
bool hasJoinInSymmetricLoop(const CallStrCxt &cxt, const ICFGNode *call) const
Whether a context-sensitive join satisfies symmetric loop pattern.
Definition MHP.cpp:649
const ICFGNode * back() const

◆ handleNonCandidateFun()

template<class ICFGGraph , class CGGraph >
void MHP::handleNonCandidateFun ( ICFGGraph  icfg,
CGGraph  cg,
const CxtThreadStmt cts 
)
protected

Handle non-candidate function.

Handle call instruction in the current thread scope (excluding any fork site)

Definition at line 240 of file MHP.cpp.

241{
242 const ICFGNode* curInst = cts.getStmt();
243 const FunObjVar* curfun = curInst->getFun();
244 assert((curInst == GenericGraphTraits<ICFGGraph>::getFunEntry(icfg, curfun)) && "curInst is not the entry of non candidate function.");
245 const CallStrCxt& curCxt = cts.getContext();
247 for (CallGraphNode::const_iterator nit = node->OutEdgeBegin(), neit = node->OutEdgeEnd(); nit != neit; nit++)
248 {
249 const FunObjVar* callee = (*nit)->getDstNode()->getFunction();
250 if (!isExtCall(callee))
251 {
255 }
256 }
257}
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
iterator OutEdgeEnd()
iterator OutEdgeBegin()
iterators
GEdgeSetTy::const_iterator const_iterator

◆ handleRet()

template<class ICFGGraph , class CGGraph >
void MHP::handleRet ( ICFGGraph  icfg,
CGGraph  cg,
const CxtThreadStmt cts 
)
protected

Handle return.

Handle return instruction in the current thread scope (excluding any join site)

Definition at line 418 of file MHP.cpp.

419{
420 CallGraphNode* curFunNode = tcg->getCallGraphNode(cts.getStmt()->getFun());
421 std::vector<const CallGraphEdge*> inEdges;
423 for (const CallGraphEdge* edgeConst : inEdges)
424 {
425 if (SVFUtil::isa<ThreadForkEdge, ThreadJoinEdge>(edgeConst))
426 continue;
427 // Need non-const for directCallsBegin/End
428 CallGraphEdge* edge = const_cast<CallGraphEdge*>(edgeConst);
429 for (CallGraphEdge::CallInstSet::const_iterator cit = (edge)->directCallsBegin(),
430 ecit = (edge)->directCallsEnd();
431 cit != ecit; ++cit)
432 {
433 CallStrCxt newCxt = cts.getContext();
434 if (matchAndPopCxt(newCxt, *cit, curFunNode->getFunction()))
435 {
436 std::vector<const ICFGNode*> succ;
438 for (const ICFGNode* dst : succ)
439 {
440 if(dst->getFun() == (*cit)->getFun())
441 {
442 // Iterate over callSite's call string context and use as the successor's context
443 if (!hasThreadStmtSet(*cit))
444 continue;
446 {
447 CallStrCxt callSiteCxt = cxtThreadStmt.getContext();
448 // If new context is a suffix of the call site context
450 {
451 CxtThreadStmt newCts(cts.getTid(), callSiteCxt, dst);
453 }
454 }
455 }
456 }
457 }
458 }
459 for (CallGraphEdge::CallInstSet::const_iterator cit = (edge)->indirectCallsBegin(),
460 ecit = (edge)->indirectCallsEnd();
461 cit != ecit; ++cit)
462 {
463 CallStrCxt newCxt = cts.getContext();
464 if (matchAndPopCxt(newCxt, *cit, curFunNode->getFunction()))
465 {
466 std::vector<const ICFGNode*> succ;
468 for (const ICFGNode* dst : succ)
469 {
470 if(dst->getFun() == (*cit)->getFun())
471 {
472 // Iterate over callSite's call string context and use as the successor's context
473 if (!hasThreadStmtSet(*cit))
474 continue;
476 {
477 CallStrCxt callSiteCxt = cxtThreadStmt.getContext();
478 // If new context is a suffix of the call site context
480 {
481 CxtThreadStmt newCts(cts.getTid(), callSiteCxt, dst);
483 }
484 }
485 }
486 }
487 }
488 }
489 }
490}
bool matchAndPopCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Match context.
Definition MHP.h:249
bool isContextSuffix(const CallStrCxt &lhs, const CallStrCxt call)
If lhs is a suffix of rhs, including equal.
Definition MHP.h:254

◆ hasInterleavingThreads()

bool SVF::MHP::hasInterleavingThreads ( const CxtThreadStmt cts) const
inline

Definition at line 116 of file MHP.h.

117 {
119 }

◆ hasJoinInSymmetricLoop()

bool MHP::hasJoinInSymmetricLoop ( const CallStrCxt cxt,
const ICFGNode call 
) const
protected

Whether a context-sensitive join satisfies symmetric loop pattern.

Whether a context-sensitive join satisfies symmetric loop pattern

Definition at line 649 of file MHP.cpp.

650{
651 CxtStmt cs(cxt, call);
652 return fja->hasJoinInSymmetricLoop(cs);
653}
bool hasJoinInSymmetricLoop(const CxtStmt &cs) const
Definition MHP.h:367

◆ hasThreadStmtSet()

bool SVF::MHP::hasThreadStmtSet ( const ICFGNode inst) const
inline

Definition at line 130 of file MHP.h.

131 {
132 return instToTSMap.find(inst)!=instToTSMap.end();
133 }

◆ isConnectedfromMain()

bool MHP::isConnectedfromMain ( const FunObjVar fun)

Whether the function is connected from main function in thread call graph.

Definition at line 670 of file MHP.cpp.

671{
674 TCT::PTACGNodeSet visited;
675 worklist.push(cgnode);
676 visited.insert(cgnode);
677 while (!worklist.empty())
678 {
679 const CallGraphNode* node = worklist.pop();
681 return true;
682 for (CallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit != neit; nit++)
683 {
684 const CallGraphNode* srcNode = (*nit)->getSrcNode();
685 if (visited.find(srcNode) == visited.end())
686 {
687 visited.insert(srcNode);
688 worklist.push(srcNode);
689 }
690 }
691 }
692 return false;
693}
const FunObjVar * getFunction() const
Get function of this call node.
Definition CallGraph.h:191
bool push(const Data &data)
Definition WorkList.h:180
iterator InEdgeBegin()
iterator InEdgeEnd()
Set< const CallGraphNode * > PTACGNodeSet
Definition TCT.h:175
bool isProgEntryFunction(const FunObjVar *)
Program entry function e.g. main.
Definition SVFUtil.cpp:446

◆ isContextSuffix()

bool SVF::MHP::isContextSuffix ( const CallStrCxt lhs,
const CallStrCxt  call 
)
inlineprotected

If lhs is a suffix of rhs, including equal.

Definition at line 254 of file MHP.h.

255 {
256 return tct->isContextSuffix(lhs,call);
257 }
bool isContextSuffix(const CallStrCxt &lhs, const CallStrCxt &call)
If lhs is a suffix of rhs, including equal.
Definition TCT.cpp:521

◆ isHBPair()

bool MHP::isHBPair ( NodeID  tid1,
NodeID  tid2 
)
protected

Whether thread t1 happens before t2 based on ForkJoin Analysis.

Whether two thread t1 happens-fore t2

Definition at line 665 of file MHP.cpp.

666{
667 return fja->isHBPair(tid1, tid2);
668}
bool isHBPair(NodeID tid1, NodeID tid2)
Whether thread t1 happens-before thread t2.
Definition MHP.h:373

◆ isMultiForkedThread()

bool SVF::MHP::isMultiForkedThread ( NodeID  curTid)
inlineprotected

A thread is a multiForked thread if it is in a loop or recursion.

Definition at line 233 of file MHP.h.

234 {
236 }
bool isMultiforked() const
Definition TCT.h:121

◆ isMustJoin()

bool MHP::isMustJoin ( const NodeID  curTid,
const ICFGNode joinsite 
)
protected

Whether a join site must join a thread t.

A join site must join t if (1) t is not a multiforked thread (2) the join site of t is not in recursion

Definition at line 630 of file MHP.cpp.

631{
632 const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(joinsite);
633 assert(call && isTDJoin(call) && "not a join site!");
635}
bool isJoinSiteInRecursion(const CallICFGNode *join) const
Whether a join site is in recursion.
Definition TCT.h:432

◆ isRecurFullJoin()

bool MHP::isRecurFullJoin ( NodeID  parentTid,
NodeID  curTid 
)
protected

Thread curTid can be fully joined by parentTid recursively.

Whether curTid can be fully joined by parentTid recursively

Definition at line 595 of file MHP.cpp.

596{
597 if (parentTid == curTid)
598 return true;
599
602 worklist.push(curNode);
603 while (!worklist.empty())
604 {
605 const TCTNode* node = worklist.pop();
606 for (TCTEdge* edge : node->getInEdges())
607 {
608 NodeID srcID = edge->getSrcID();
609 if (fja->isFullJoin(srcID, node->getId()))
610 {
611 if (srcID == parentTid)
612 return true;
613 else
614 worklist.push(edge->getSrcNode());
615 }
616 else
617 {
618 return false;
619 }
620 }
621 }
622 return false;
623}
bool isFullJoin(NodeID tid1, NodeID tid2)
Whether t1 fully joins t2.
Definition MHP.h:380

◆ isTDFork()

bool SVF::MHP::isTDFork ( const ICFGNode call)
inlineprotected

Whether it is a fork site.

Definition at line 273 of file MHP.h.

274 {
275 const CallICFGNode* fork = SVFUtil::dyn_cast<CallICFGNode>(call);
276 return fork && tcg->getThreadAPI()->isTDFork(fork);
277 }
bool isTDFork(const CallICFGNode *inst) const
Return true if this call create a new thread.
ThreadAPI * getThreadAPI() const
Thread API.

◆ isTDJoin()

bool SVF::MHP::isTDJoin ( const ICFGNode call)
inlineprotected

Whether it is a join site.

Definition at line 279 of file MHP.h.

280 {
281 const CallICFGNode* join = SVFUtil::dyn_cast<CallICFGNode>(call);
282 return join && tcg->getThreadAPI()->isTDJoin(join);
283 }
bool isTDJoin(const CallICFGNode *inst) const
Return true if this call wait for a worker thread.

◆ matchAndPopCxt()

bool SVF::MHP::matchAndPopCxt ( CallStrCxt cxt,
const CallICFGNode call,
const FunObjVar callee 
)
inlineprotected

Match context.

Definition at line 249 of file MHP.h.

250 {
251 return tct->matchAndPopCxt(cxt,call,callee);
252 }
bool matchAndPopCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Match context.
Definition TCT.cpp:493

◆ mayHappenInParallel()

bool MHP::mayHappenInParallel ( const ICFGNode i1,
const ICFGNode i2 
)
virtual

Interface to query whether two instructions may happen-in-parallel.

Definition at line 763 of file MHP.cpp.

764{
766
767 DOTIMESTAT(double queryStart = PTAStat::getClk(true));
768 bool mhp = mayHappenInParallelCache(i1, i2);
769 DOTIMESTAT(double queryEnd = PTAStat::getClk(true));
771
772 return mhp;
773}
virtual bool mayHappenInParallelCache(const ICFGNode *i1, const ICFGNode *i2)
Definition MHP.cpp:741

◆ mayHappenInParallelCache()

bool MHP::mayHappenInParallelCache ( const ICFGNode i1,
const ICFGNode i2 
)
virtual

Definition at line 741 of file MHP.cpp.

742{
743 if (!tct->isCandidateFun(i1->getFun()) && !tct->isCandidateFun(i2->getFun()))
744 {
745 FuncPair funpair = std::make_pair(i1->getFun(), i2->getFun());
746 FuncPairToBool::const_iterator it = nonCandidateFuncMHPRelMap.find(funpair);
747 if (it == nonCandidateFuncMHPRelMap.end())
748 {
749 bool mhp = mayHappenInParallelInst(i1, i2);
751 return mhp;
752 }
753 else
754 {
755 if (it->second)
757 return it->second;
758 }
759 }
761}
FuncPairToBool nonCandidateFuncMHPRelMap
Definition MHP.h:305
std::pair< const FunObjVar *, const FunObjVar * > FuncPair
Definition MHP.h:69
virtual bool mayHappenInParallelInst(const ICFGNode *i1, const ICFGNode *i2)
Definition MHP.cpp:705

◆ mayHappenInParallelInst()

bool MHP::mayHappenInParallelInst ( const ICFGNode i1,
const ICFGNode i2 
)
virtual

Answer MHP queries For a pair of ThreadStmts (t1,s1) = <l1> (t2,s2) = <l2> They may happen in parallel if (1) t1 == t2 and t1 inloop/incycle (2) t1!=t2 and t1 \in l2 and t2 \in l1

TODO: Any instruction in dead function is assumed no MHP with others

Definition at line 705 of file MHP.cpp.

706{
707
710 return false;
711
714 for (const CxtThreadStmt& ts1 : tsSet1)
715 {
717 for (const CxtThreadStmt& ts2 : tsSet2)
718 {
720 if (ts1.getTid() != ts2.getTid())
721 {
722 if (l1.test(ts2.getTid()) && l2.test(ts1.getTid()))
723 {
725 return true;
726 }
727 }
728 else
729 {
730 if (isMultiForkedThread(ts1.getTid()))
731 {
733 return true;
734 }
735 }
736 }
737 }
738 return false;
739}

◆ popFromCTSWorkList()

CxtThreadStmt SVF::MHP::popFromCTSWorkList ( )
inlineprotected

Definition at line 266 of file MHP.h.

267 {
268 CxtThreadStmt ctp = cxtStmtList.pop();
269 return ctp;
270 }

◆ printInterleaving()

void MHP::printInterleaving ( )

Print interleaving results.

Print interleaving results

Definition at line 796 of file MHP.cpp.

797{
798 for (const auto& pair : threadStmtToThreadInterLeav)
799 {
800 outs() << "( t" << pair.first.getTid()
801 << pair.first.getStmt()->toString() << " ) ==> [";
802 for (unsigned i : pair.second)
803 {
804 outs() << " " << i << " ";
805 }
806 outs() << "]\n";
807 }
808}

◆ pushCxt()

void SVF::MHP::pushCxt ( CallStrCxt cxt,
const CallICFGNode call,
const FunObjVar callee 
)
inlineprotected

Context helper functions.

Push calling context

handle calling context for candidate functions only

Definition at line 241 of file MHP.h.

242 {
244 if(tct->isCandidateFun(call->getFun()) == false)
245 return;
246 tct->pushCxt(cxt,call,callee);
247 }
virtual void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Context helper functions.
Definition TCT.cpp:473

◆ pushToCTSWorkList()

bool SVF::MHP::pushToCTSWorkList ( const CxtThreadStmt cs)
inlineprotected

WorkList helper functions.

Definition at line 262 of file MHP.h.

263 {
264 return cxtStmtList.push(cs);
265 }

◆ rmInterleavingThread()

void SVF::MHP::rmInterleavingThread ( const CxtThreadStmt tgr,
const NodeBS tids,
const ICFGNode joinsite 
)
inlineprotected

Definition at line 205 of file MHP.h.

206 {
208 for(NodeBS::iterator it = tids.begin(), eit = tids.end(); it!=eit; ++it)
209 {
210 if(isMustJoin(tgr.getTid(),joinsite))
211 joinedTids.set(*it);
212 }
213 if(threadStmtToThreadInterLeav[tgr].intersectWithComplement(joinedTids))
214 {
216 }
217 }
SparseBitVectorIterator iterator
void set(unsigned Idx)
SparseBitVector NodeBS
Definition GeneralType.h:82

◆ updateAncestorThreads()

template<class ICFGGraph , class CGGraph >
void MHP::updateAncestorThreads ( ICFGGraph  icfg,
CGGraph  cg,
NodeID  curTid 
)
protected

Update Ancestor and sibling threads.

Update interleavings of ancestor threads according to TCT

Definition at line 521 of file MHP.cpp.

522{
524 DBOUT(DMTA, outs() << "##Ancestor thread of " << curTid << " is : ");
526 DBOUT(DMTA, outs() << "\n");
528
529 for (const unsigned tid : ancestorAndSelfTids)
530 {
531 const CxtThread& ct = tct->getTCTNode(tid)->getCxtThread();
532 if (const ICFGNode* forkInst = ct.getThread())
533 {
534 // Mark the fork site's successors under the graph, so a sliced run
535 // marks kept successors (a marker on a removed node would strand).
536 std::vector<const ICFGNode*> succ;
538 for(const ICFGNode* dst : succ)
539 {
540 // Ensure dst node is in the same function as forkInst
541 if(dst->getFun() == forkInst->getFun())
542 {
543 for (const auto& forkSiteCxt : tct->getCxtOfCxtThread(ct))
544 {
545 CxtThreadStmt cts(forkSiteCxt.first, forkSiteCxt.second, dst);
547 }
548 }
549 }
550 }
551 }
552}
const CxtThread & getCxtThread() const
Get thread creation context, <fork site, call string context>
Definition TCT.h:102
const NodeBS getAncestorThreads(NodeID tid) const
Get all ancestor threads.
Definition TCT.h:330

◆ updateNonCandidateFunInterleaving()

template<class ICFGGraph , class CGGraph >
void MHP::updateNonCandidateFunInterleaving ( ICFGGraph  icfg,
CGGraph  cg 
)
protected

Update non-candidate functions' interleaving. Copy interleaving threads of the entry inst to other insts.

Update non-candidate functions' interleaving

Definition at line 202 of file MHP.cpp.

203{
204 // Copy each non-candidate function entry's interleaving to the function's
205 // other nodes under the graph. Runs after the worklist has drained, so
206 // addInterleavingThread's push is inert.
207 for (const auto& item : *GenericGraphTraits<CGGraph>::getCallGraph(cg))
208 {
209 const FunObjVar* fun = item.second->getFunction();
210 if (tct->isCandidateFun(fun) || isExtCall(fun))
211 continue;
212
215 continue;
216
218
219 std::vector<const ICFGNode*> funICFGNodes;
221
222 for (const CxtThreadStmt& cts : tsSet)
223 {
224 const CallStrCxt& curCxt = cts.getContext();
225 for (const ICFGNode* curNode : funICFGNodes)
226 {
227 if (curNode == entryNode)
228 continue;
231 }
232 }
233 }
234}
cJSON * item
Definition cJSON.h:222

◆ updateSiblingThreads()

template<class ICFGGraph , class CGGraph >
void MHP::updateSiblingThreads ( ICFGGraph  icfg,
CGGraph  cg,
NodeID  curTid 
)
protected

Update interleavings of sibling threads according to TCT

Exclude sibling thread that never happen in parallel based on ForkJoinAnalysis

The interleaving of a thread t is not unnecessary to be updated if (1) t HB Sibling and t fully joins curTid recursively or (2) Sibling HB t

Definition at line 565 of file MHP.cpp.

566{
569 for (const unsigned tid : ancestorAndSelfTids)
570 {
572 for (const unsigned stid : siblingTds)
573 {
574 if ((isHBPair(tid, stid) && isRecurFullJoin(tid, curTid)) || isHBPair(stid, tid))
575 continue;
576
579 // The entry node under the graph: the same node the sibling thread's
580 // own propagation starts from (see analyzeInterleaving's root cts).
582 CxtThreadStmt cts(stid, ct.getContext(), stmt);
584 }
585
586 DBOUT(DMTA, outs() << "##Sibling thread of " << curTid << " is : ");
588 DBOUT(DMTA, outs() << "\n");
589 }
590}
bool isRecurFullJoin(NodeID parentTid, NodeID curTid)
Thread curTid can be fully joined by parentTid recursively.
Definition MHP.cpp:595
bool isHBPair(NodeID tid1, NodeID tid2)
Whether thread t1 happens before t2 based on ForkJoin Analysis.
Definition MHP.cpp:665
const NodeBS getSiblingThread(NodeID tid) const
Get sibling threads.
Definition TCT.h:353

Member Data Documentation

◆ bbToSymJoins

BBToSymJoinsMap SVF::MHP::bbToSymJoins
protected

Map a statement to its thread interleavings.

loop block -> symmetric in-loop joins of that loop

Definition at line 302 of file MHP.h.

◆ cxtStmtList

CxtThreadStmtWorkList SVF::MHP::cxtStmtList
protected

CxtThreadStmt worklist.

Definition at line 300 of file MHP.h.

◆ fja

ForkJoinAnalysis* SVF::MHP::fja
protected

ForJoin Analysis.

Definition at line 299 of file MHP.h.

◆ instToTSMap

InstToThreadStmtSetMap SVF::MHP::instToTSMap
protected

Map an instruction to its ThreadStmtSet.

Definition at line 304 of file MHP.h.

◆ interleavingQueriesTime

double SVF::MHP::interleavingQueriesTime

Definition at line 311 of file MHP.h.

◆ interleavingTime

double SVF::MHP::interleavingTime

Definition at line 310 of file MHP.h.

◆ nonCandidateFuncMHPRelMap

FuncPairToBool SVF::MHP::nonCandidateFuncMHPRelMap
protected

Definition at line 305 of file MHP.h.

◆ numOfMHPQueries

u32_t SVF::MHP::numOfMHPQueries

Number of queries are answered as may-happen-in-parallel.

Definition at line 309 of file MHP.h.

◆ numOfTotalQueries

u32_t SVF::MHP::numOfTotalQueries

Total number of queries.

Definition at line 308 of file MHP.h.

◆ symJoinLoop

SymJoinToLoopMap SVF::MHP::symJoinLoop
protected

symmetric in-loop join -> its loop's blocks

Definition at line 303 of file MHP.h.

◆ tcg

ThreadCallGraph* SVF::MHP::tcg
protected

TCG.

Definition at line 297 of file MHP.h.

◆ tct

TCT* SVF::MHP::tct
protected

TCT.

Definition at line 298 of file MHP.h.

◆ threadStmtToThreadInterLeav

ThreadStmtToThreadInterleav SVF::MHP::threadStmtToThreadInterLeav
protected

Definition at line 301 of file MHP.h.


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