Skip to content

Commit c711dc3

Browse files
authored
Merge pull request #1761 from JoelYYoung/master
Modify MTA module
2 parents 9a660b4 + 9813289 commit c711dc3

File tree

8 files changed

+362
-202
lines changed

8 files changed

+362
-202
lines changed

svf/include/MTA/LockAnalysis.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ class LockAnalysis
7272
typedef Map<CxtLock, LockSpan> CxtLockToSpan;
7373
typedef Map<CxtLock, NodeBS> CxtLockToLockSet;
7474
typedef Map<const ICFGNode*, NodeBS> LockSiteToLockSet;
75-
typedef Map<const ICFGNode*, LockSpan> InstToCxtStmtSet;
75+
typedef Map<const ICFGNode*, CxtStmtSet> InstToCxtStmtSet;
7676
typedef Map<CxtStmt, CxtLockSet> CxtStmtToCxtLockSet;
7777
typedef FIFOWorkList<CxtLockProc> CxtLockProcVec;
7878
typedef Set<CxtLockProc> CxtLockProcSet;
7979

80-
typedef Map<const ICFGNode*, CxtStmtSet> InstToCxtStmt;
81-
8280
LockAnalysis(TCT* t) : tct(t), lockTime(0),numOfTotalQueries(0), numOfLockedQueries(0), lockQueriesTime(0)
8381
{
8482
}
@@ -200,12 +198,12 @@ class LockAnalysis
200198
/// Context-sensitive statement and lock spans
201199
//@{
202200
/// Get LockSet and LockSpan
203-
inline bool hasCxtStmtfromInst(const ICFGNode* inst) const
201+
inline bool hasCxtStmtFromInst(const ICFGNode* inst) const
204202
{
205203
InstToCxtStmtSet::const_iterator it = instToCxtStmtSet.find(inst);
206204
return (it != instToCxtStmtSet.end());
207205
}
208-
inline const CxtStmtSet& getCxtStmtfromInst(const ICFGNode* inst) const
206+
inline const CxtStmtSet& getCxtStmtsFromInst(const ICFGNode* inst) const
209207
{
210208
InstToCxtStmtSet::const_iterator it = instToCxtStmtSet.find(inst);
211209
assert(it != instToCxtStmtSet.end());
@@ -271,9 +269,9 @@ class LockAnalysis
271269
/// Check if one instruction's context stmt is in a lock span
272270
inline bool hasOneCxtInLockSpan(const ICFGNode *I, LockSpan lspan) const
273271
{
274-
if(!hasCxtStmtfromInst(I))
272+
if(!hasCxtStmtFromInst(I))
275273
return false;
276-
const LockSpan ctsset = getCxtStmtfromInst(I);
274+
const LockSpan ctsset = getCxtStmtsFromInst(I);
277275
for (LockSpan::const_iterator cts = ctsset.begin(), ects = ctsset.end(); cts != ects; cts++)
278276
{
279277
if(lspan.find(*cts) != lspan.end())
@@ -286,9 +284,9 @@ class LockAnalysis
286284

287285
inline bool hasAllCxtInLockSpan(const ICFGNode *I, LockSpan lspan) const
288286
{
289-
if(!hasCxtStmtfromInst(I))
287+
if(!hasCxtStmtFromInst(I))
290288
return false;
291-
const LockSpan ctsset = getCxtStmtfromInst(I);
289+
const LockSpan ctsset = getCxtStmtsFromInst(I);
292290
for (LockSpan::const_iterator cts = ctsset.begin(), ects = ctsset.end(); cts != ects; cts++)
293291
{
294292
if (lspan.find(*cts) == lspan.end())
@@ -429,10 +427,15 @@ class LockAnalysis
429427
}
430428
//@}
431429

430+
/// Context helper functions
431+
//@{
432432
/// Push calling context
433433
void pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const FunObjVar* callee);
434434
/// Match context
435435
bool matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const FunObjVar* callee);
436+
/// If lhs is a suffix of rhs, including equal
437+
bool isContextSuffix(const CallStrCxt& lhs, const CallStrCxt& call);
438+
//@}
436439

437440
/// Whether it is a lock site
438441
inline bool isTDFork(const ICFGNode* call)

svf/include/MTA/MHP.h

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

svf/include/MTA/MTA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class MTA
6666
/// We start the pass here
6767
virtual bool runOnModule(SVFIR* module);
6868
/// Compute MHP
69-
virtual MHP* computeMHP();
69+
virtual MHP* computeMHP(TCT* tct);
7070
/// Compute locksets
7171
virtual LockAnalysis* computeLocksets(TCT* tct);
7272
/// Perform detection

0 commit comments

Comments
 (0)