@@ -96,11 +96,11 @@ class MHP
9696 // @{
9797 inline const NodeBS& getInterleavingThreads (const CxtThreadStmt& cts)
9898 {
99- return threadStmtToTheadInterLeav [cts];
99+ return threadStmtToThreadInterLeav [cts];
100100 }
101101 inline bool hasInterleavingThreads (const CxtThreadStmt& cts) const
102102 {
103- return threadStmtToTheadInterLeav .find (cts)!=threadStmtToTheadInterLeav .end ();
103+ return threadStmtToThreadInterLeav .find (cts)!=threadStmtToThreadInterLeav .end ();
104104 }
105105 // @}
106106
@@ -154,15 +154,15 @@ class MHP
154154 // @{
155155 inline void addInterleavingThread (const CxtThreadStmt& tgr, NodeID tid)
156156 {
157- if (threadStmtToTheadInterLeav [tgr].test_and_set (tid))
157+ if (threadStmtToThreadInterLeav [tgr].test_and_set (tid))
158158 {
159159 instToTSMap[tgr.getStmt ()].insert (tgr);
160160 pushToCTSWorkList (tgr);
161161 }
162162 }
163163 inline void addInterleavingThread (const CxtThreadStmt& tgr, const CxtThreadStmt& src)
164164 {
165- bool changed = threadStmtToTheadInterLeav [tgr] |= threadStmtToTheadInterLeav [src];
165+ bool changed = threadStmtToThreadInterLeav [tgr] |= threadStmtToThreadInterLeav [src];
166166 if (changed)
167167 {
168168 instToTSMap[tgr.getStmt ()].insert (tgr);
@@ -177,7 +177,7 @@ class MHP
177177 if (isMustJoin (tgr.getTid (),joinsite))
178178 joinedTids.set (*it);
179179 }
180- if (threadStmtToTheadInterLeav [tgr].intersectWithComplement (joinedTids))
180+ if (threadStmtToThreadInterLeav [tgr].intersectWithComplement (joinedTids))
181181 {
182182 pushToCTSWorkList (tgr);
183183 }
@@ -201,16 +201,28 @@ class MHP
201201 {
202202 return tct->getTCTNode (curTid)->isMultiforked ();
203203 }
204+
205+ // / Context helper functions
206+ // @{
204207 // / Push calling context
205208 inline void pushCxt (CallStrCxt& cxt, const CallICFGNode* call, const FunObjVar* callee)
206209 {
210+ // / handle calling context for candidate functions only
211+ if (tct->isCandidateFun (call->getFun ()) == false )
212+ return ;
207213 tct->pushCxt (cxt,call,callee);
208214 }
209215 // / Match context
210- inline bool matchCxt (CallStrCxt& cxt, const CallICFGNode* call, const FunObjVar* callee)
216+ inline bool matchAndPopCxt (CallStrCxt& cxt, const CallICFGNode* call, const FunObjVar* callee)
217+ {
218+ return tct->matchAndPopCxt (cxt,call,callee);
219+ }
220+ // / If lhs is a suffix of rhs, including equal
221+ inline bool isContextSuffix (const CallStrCxt& lhs, const CallStrCxt call)
211222 {
212- return tct->matchCxt (cxt ,call,callee );
223+ return tct->isContextSuffix (lhs ,call);
213224 }
225+ // @}
214226
215227 // / WorkList helper functions
216228 // @{
@@ -253,7 +265,7 @@ class MHP
253265 TCT* tct; // /< TCT
254266 ForkJoinAnalysis* fja; // /< ForJoin Analysis
255267 CxtThreadStmtWorkList cxtStmtList; // /< CxtThreadStmt worklist
256- ThreadStmtToThreadInterleav threadStmtToTheadInterLeav ; // / Map a statement to its thread interleavings
268+ ThreadStmtToThreadInterleav threadStmtToThreadInterLeav ; // / Map a statement to its thread interleavings
257269 InstToThreadStmtSetMap instToTSMap; // /< Map an instruction to its ThreadStmtSet
258270 FuncPairToBool nonCandidateFuncMHPRelMap;
259271
@@ -290,6 +302,10 @@ class ForkJoinAnalysis
290302 typedef Map<CxtStmt, LoopBBs> CxtStmtToLoopMap;
291303 typedef FIFOWorkList<CxtStmt> CxtStmtWorkList;
292304
305+ typedef Set<CxtStmt> CxtStmtSet;
306+ typedef Map<const ICFGNode*, CxtStmtSet> InstToCxtStmt;
307+
308+
293309 ForkJoinAnalysis (TCT* t) : tct(t)
294310 {
295311 collectSCEVInfo ();
@@ -337,15 +353,6 @@ class ForkJoinAnalysis
337353 return full && !partial;
338354 }
339355
340- // / Get exit instruction of the start routine function of tid's parent thread
341- inline const ICFGNode* getExitInstOfParentRoutineFun (NodeID tid) const
342- {
343- NodeID parentTid = tct->getParentThread (tid);
344- const CxtThread& parentct = tct->getTCTNode (parentTid)->getCxtThread ();
345- const FunObjVar* parentRoutine = tct->getStartRoutineOfCxtThread (parentct);
346- return parentRoutine->getExitBB ()->back ();
347- }
348-
349356 // / Get loop for join site
350357 inline LoopBBs& getJoinLoop (const CallICFGNode* inst)
351358 {
@@ -381,7 +388,7 @@ class ForkJoinAnalysis
381388 // / Whether it is a matched fork join pair
382389 bool isAliasedForkJoin (const CallICFGNode* forkSite, const CallICFGNode* joinSite)
383390 {
384- return tct->getPTA ()->alias (getForkedThread (forkSite)->getId (), getJoinedThread (joinSite)->getId ()) && isSameSCEV (forkSite,joinSite) ;
391+ return tct->getPTA ()->alias (getForkedThread (forkSite)->getId (), getJoinedThread (joinSite)->getId ());
385392 }
386393 // / Mark thread flags for cxtStmt
387394 // @{
@@ -403,7 +410,11 @@ class ForkJoinAnalysis
403410 ValDomain flag_tgr = getMarkedFlag (tgr);
404411 cxtStmtToAliveFlagMap[tgr] = flag;
405412 if (flag_tgr!=getMarkedFlag (tgr))
413+ {
414+ instToCxtStmt[tgr.getStmt ()].insert (tgr);
406415 pushToCTSWorkList (tgr);
416+ }
417+
407418 }
408419 // / Transfer function for marking context-sensitive statement
409420 void markCxtStmtFlag (const CxtStmt& tgr, const CxtStmt& src)
@@ -425,6 +436,7 @@ class ForkJoinAnalysis
425436 }
426437 if (flag_tgr!=getMarkedFlag (tgr))
427438 {
439+ instToCxtStmt[tgr.getStmt ()].insert (tgr);
428440 pushToCTSWorkList (tgr);
429441 }
430442 }
@@ -449,16 +461,27 @@ class ForkJoinAnalysis
449461 }
450462 // @}
451463
464+ // / Context helper functions
465+ // @{
452466 // / Push calling context
453467 inline void pushCxt (CallStrCxt& cxt, const CallICFGNode* call, const FunObjVar* callee)
454468 {
469+ // / handle calling context for candidate functions only
470+ if (tct->isCandidateFun (call->getFun ()) == false )
471+ return ;
455472 tct->pushCxt (cxt,call,callee);
456473 }
457474 // / Match context
458- inline bool matchCxt (CallStrCxt& cxt, const CallICFGNode* call, const FunObjVar* callee)
475+ inline bool matchAndPopCxt (CallStrCxt& cxt, const CallICFGNode* call, const FunObjVar* callee)
476+ {
477+ return tct->matchAndPopCxt (cxt,call,callee);
478+ }
479+ // / If lhs is a suffix of rhs, including equal
480+ inline bool isContextSuffix (const CallStrCxt& lhs, const CallStrCxt call)
459481 {
460- return tct->matchCxt (cxt ,call,callee );
482+ return tct->isContextSuffix (lhs ,call);
461483 }
484+ // @}
462485
463486 // / Whether it is a fork site
464487 inline bool isTDFork (const ICFGNode* call)
@@ -524,6 +547,18 @@ class ForkJoinAnalysis
524547 }
525548 // @}
526549
550+ // / Get CxtStmtSet for an instruction
551+ inline const CxtStmtSet& getCxtStmtsFromInst (const ICFGNode* inst) const
552+ {
553+ InstToCxtStmt::const_iterator it = instToCxtStmt.find (inst);
554+ assert (it!=instToCxtStmt.end () && " no CxtStmt for the instruction?" );
555+ return it->second ;
556+ }
557+ inline bool hasCxtStmtsFromInst (const ICFGNode* inst) const
558+ {
559+ return instToCxtStmt.find (inst)!=instToCxtStmt.end ();
560+ }
561+
527562 // / Add inloop join
528563 inline void addSymmetricLoopJoin (const CxtStmt& cs, LoopBBs& lp)
529564 {
@@ -539,6 +574,7 @@ class ForkJoinAnalysis
539574 ThreadPairSet HPPair; // /< threads happen-in-parallel
540575 ThreadPairSet fullJoin; // /< t1 fully joins t2 along all program path
541576 ThreadPairSet partialJoin; // /< t1 partially joins t2 along some program path(s)
577+ InstToCxtStmt instToCxtStmt; // /<Map a statement to all its context-sensitive statements
542578};
543579
544580} // End namespace SVF
0 commit comments