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

#include <LockAnalysis.h>

Public Types

enum  ValDomain { Empty , TDLocked , TDUnlocked }
 semilattice Empty==>TDUnlocked==>TDLocked More...
 
typedef CxtStmt CxtLock
 
typedef CxtProc CxtLockProc
 
typedef NodeBS LockSet
 
typedef TCT::InstVec InstVec
 
typedef Set< const ICFGNode * > InstSet
 
typedef InstSet CISpan
 
typedef Map< const ICFGNode *, CISpanCILockToSpan
 
typedef Set< const SVFFunction * > FunSet
 
typedef Map< const ICFGNode *, InstSetInstToInstSetMap
 
typedef Map< CxtStmt, ValDomainCxtStmtToLockFlagMap
 
typedef FIFOWorkList< CxtStmtCxtStmtWorkList
 
typedef Set< CxtStmtLockSpan
 
typedef Set< CxtStmtCxtStmtSet
 
typedef Set< CxtLockCxtLockSet
 
typedef Map< CxtLock, LockSpanCxtLockToSpan
 
typedef Map< CxtLock, NodeBSCxtLockToLockSet
 
typedef Map< const ICFGNode *, NodeBSLockSiteToLockSet
 
typedef Map< const ICFGNode *, LockSpanInstToCxtStmtSet
 
typedef Map< CxtStmt, CxtLockSetCxtStmtToCxtLockSet
 
typedef FIFOWorkList< CxtLockProcCxtLockProcVec
 
typedef Set< CxtLockProcCxtLockProcSet
 
typedef Map< const ICFGNode *, CxtStmtSetInstToCxtStmt
 

Public Member Functions

 LockAnalysis (TCT *t)
 
void analyze ()
 
void analyzeIntraProcedualLock ()
 
bool intraForwardTraverse (const ICFGNode *lock, InstSet &unlockset, InstSet &forwardInsts)
 
bool intraBackwardTraverse (const InstSet &unlockset, InstSet &backwardInsts)
 
void collectCxtLock ()
 
void analyzeLockSpanCxtStmt ()
 
void collectLockUnlocksites ()
 
void buildCandidateFuncSetforLock ()
 
bool isIntraLock (const ICFGNode *lock) const
 Intraprocedural locks.
 
void addIntraLock (const ICFGNode *lockSite, const InstSet &stmts)
 Add intra-procedural lock.
 
void addCondIntraLock (const ICFGNode *lockSite, const InstSet &stmts)
 Add intra-procedural lock.
 
bool isInsideIntraLock (const ICFGNode *stmt) const
 Return true if a statement is inside an intra-procedural lock.
 
bool isInsideCondIntraLock (const ICFGNode *stmt) const
 Return true if a statement is inside a partial lock/unlock pair (conditional lock with unconditional unlock)
 
const InstSetgetIntraLockSet (const ICFGNode *stmt) const
 
void addCxtLock (const CallStrCxt &cxt, const ICFGNode *inst)
 Context-sensitive locks.
 
bool hasCxtLock (const CxtLock &cxtLock) const
 Get context-sensitive lock.
 
bool intersects (const CxtLockSet &lockset1, const CxtLockSet &lockset2) const
 Return true if the intersection of two locksets is not empty.
 
bool alias (const CxtLockSet &lockset1, const CxtLockSet &lockset2)
 Return true if two locksets has at least one alias lock.
 
bool isLockCandidateFun (const SVFFunction *fun) const
 Return true if it is a candidate function.
 
bool hasCxtStmtfromInst (const ICFGNode *inst) const
 Context-sensitive statement and lock spans.
 
const CxtStmtSetgetCxtStmtfromInst (const ICFGNode *inst) const
 
bool hasCxtLockfromCxtStmt (const CxtStmt &cts) const
 
const CxtLockSetgetCxtLockfromCxtStmt (const CxtStmt &cts) const
 
CxtLockSetgetCxtLockfromCxtStmt (const CxtStmt &cts)
 
bool addCxtStmtToSpan (const CxtStmt &cts, const CxtLock &cl)
 Add context-sensitive statement.
 
bool removeCxtStmtToSpan (CxtStmt &cts, const CxtLock &cl)
 Add context-sensitive statement.
 
CxtStmtToCxtLockSet getCSTCLS ()
 
void touchCxtStmt (CxtStmt &cts)
 Touch this context statement.
 
bool hasSpanfromCxtLock (const CxtLock &cl)
 
LockSpangetSpanfromCxtLock (const CxtLock &cl)
 
bool hasOneCxtInLockSpan (const ICFGNode *I, LockSpan lspan) const
 Check if one instruction's context stmt is in a lock span.
 
bool hasAllCxtInLockSpan (const ICFGNode *I, LockSpan lspan) const
 
bool isProtectedByCommonLock (const ICFGNode *i1, const ICFGNode *i2)
 
bool isProtectedByCommonCxtLock (const ICFGNode *i1, const ICFGNode *i2)
 
bool isProtectedByCommonCxtLock (const CxtStmt &cxtStmt1, const CxtStmt &cxtStmt2)
 
bool isProtectedByCommonCILock (const ICFGNode *i1, const ICFGNode *i2)
 
bool isInSameSpan (const ICFGNode *I1, const ICFGNode *I2)
 
bool isInSameCSSpan (const ICFGNode *i1, const ICFGNode *i2) const
 
bool isInSameCSSpan (const CxtStmt &cxtStmt1, const CxtStmt &cxtStmt2) const
 
bool isInSameCISpan (const ICFGNode *i1, const ICFGNode *i2) const
 
u32_t getNumOfCxtLocks ()
 
void printLocks (const CxtStmt &cts)
 Print locks and spans.
 
TCTgetTCT ()
 Get tct.
 

Public Attributes

double lockTime
 
u32_t numOfTotalQueries
 
u32_t numOfLockedQueries
 
double lockQueriesTime
 

Private Member Functions

void handleFork (const CxtStmt &cts)
 Handle fork.
 
void handleCall (const CxtStmt &cts)
 Handle call.
 
void handleRet (const CxtStmt &cts)
 Handle return.
 
void handleIntra (const CxtStmt &cts)
 Handle intra.
 
void handleCallRelation (CxtLockProc &clp, const PTACallGraphEdge *cgEdge, const CallICFGNode *call)
 Handle call relations.
 
bool isAliasedLocks (const CxtLock &cl1, const CxtLock &cl2)
 Return true it a lock matches an unlock.
 
bool isAliasedLocks (const ICFGNode *i1, const ICFGNode *i2)
 
void markCxtStmtFlag (const CxtStmt &tgr, const CxtStmt &src)
 Mark thread flags for cxtStmt.
 
bool intersect (CxtLockSet &tgrlockset, const CxtLockSet &srclockset)
 
void clearFlagMap ()
 Clear flags.
 
bool pushToCTPWorkList (const CxtLockProc &clp)
 WorkList helper functions.
 
CxtLockProc popFromCTPWorkList ()
 
bool isVisitedCTPs (const CxtLockProc &clp) const
 
bool pushToCTSWorkList (const CxtStmt &cs)
 Worklist operations.
 
CxtStmt popFromCTSWorkList ()
 
void pushCxt (CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
 Push calling context.
 
bool matchCxt (CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
 Match context.
 
bool isTDFork (const ICFGNode *call)
 Whether it is a lock site.
 
bool isTDAcquire (const ICFGNode *call)
 Whether it is a lock site.
 
bool isTDRelease (const ICFGNode *call)
 Whether it is a unlock site.
 
bool isCallSite (const ICFGNode *inst)
 Whether it is a callsite.
 
bool isExtCall (const ICFGNode *inst)
 Whether it is calling an external function.
 
const SVFVargetLockVal (const ICFGNode *call)
 Get lock value.
 
ThreadCallGraphgetTCG () const
 ThreadCallGraph.
 

Private Attributes

TCTtct
 TCT.
 
CxtStmtWorkList cxtStmtList
 context-sensitive statement worklist
 
InstToCxtStmtSet instToCxtStmtSet
 Map a statement to all its context-sensitive statements.
 
CxtLockSet cxtLockset
 Context-sensitive locks.
 
CxtLockToSpan cxtLocktoSpan
 
CxtStmtToCxtLockSet cxtStmtToCxtLockSet
 
CxtLockProcVec clpList
 Following data structures are used for collecting context-sensitive locks.
 
CxtLockProcSet visitedCTPs
 CxtLockProc List.
 
InstSet locksites
 Record all visited clps.
 
InstSet unlocksites
 
FunSet lockcandidateFuncSet
 Candidate functions which relevant to locks/unlocks.
 
CILockToSpan ciLocktoSpan
 Used for context-insensitive intra-procedural locks.
 
InstToInstSetMap instCILocksMap
 
InstToInstSetMap instTocondCILocksMap
 

Detailed Description

Lock analysis

Definition at line 44 of file LockAnalysis.h.

Member Typedef Documentation

◆ CILockToSpan

Definition at line 63 of file LockAnalysis.h.

◆ CISpan

Definition at line 62 of file LockAnalysis.h.

◆ CxtLock

Definition at line 56 of file LockAnalysis.h.

◆ CxtLockProc

Definition at line 57 of file LockAnalysis.h.

◆ CxtLockProcSet

Definition at line 78 of file LockAnalysis.h.

◆ CxtLockProcVec

Definition at line 77 of file LockAnalysis.h.

◆ CxtLockSet

Definition at line 70 of file LockAnalysis.h.

◆ CxtLockToLockSet

Definition at line 73 of file LockAnalysis.h.

◆ CxtLockToSpan

Definition at line 72 of file LockAnalysis.h.

◆ CxtStmtSet

Definition at line 69 of file LockAnalysis.h.

◆ CxtStmtToCxtLockSet

Definition at line 76 of file LockAnalysis.h.

◆ CxtStmtToLockFlagMap

Definition at line 66 of file LockAnalysis.h.

◆ CxtStmtWorkList

Definition at line 67 of file LockAnalysis.h.

◆ FunSet

Definition at line 64 of file LockAnalysis.h.

◆ InstSet

Definition at line 61 of file LockAnalysis.h.

◆ InstToCxtStmt

Definition at line 80 of file LockAnalysis.h.

◆ InstToCxtStmtSet

Definition at line 75 of file LockAnalysis.h.

◆ InstToInstSetMap

Definition at line 65 of file LockAnalysis.h.

◆ InstVec

Definition at line 60 of file LockAnalysis.h.

◆ LockSet

Definition at line 59 of file LockAnalysis.h.

◆ LockSiteToLockSet

Definition at line 74 of file LockAnalysis.h.

◆ LockSpan

Definition at line 68 of file LockAnalysis.h.

Member Enumeration Documentation

◆ ValDomain

semilattice Empty==>TDUnlocked==>TDLocked

Enumerator
Empty 
TDLocked 
TDUnlocked 

Definition at line 49 of file LockAnalysis.h.

50 {
51 Empty, // initial(dummy) state
52 TDLocked, // stmt is locked
53 TDUnlocked, // stmt is unlocked
54 };

Constructor & Destructor Documentation

◆ LockAnalysis()

SVF::LockAnalysis::LockAnalysis ( TCT t)
inline

Definition at line 82 of file LockAnalysis.h.

Member Function Documentation

◆ addCondIntraLock()

void SVF::LockAnalysis::addCondIntraLock ( const ICFGNode lockSite,
const InstSet stmts 
)
inline

Add intra-procedural lock.

Definition at line 120 of file LockAnalysis.h.

121 {
122 for(InstSet::const_iterator it = stmts.begin(), eit = stmts.end(); it!=eit; ++it)
123 {
125 }
126 }
InstToInstSetMap instTocondCILocksMap
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ addCxtLock()

void SVF::LockAnalysis::addCxtLock ( const CallStrCxt cxt,
const ICFGNode inst 
)
inline

Context-sensitive locks.

Add inter-procedural context-sensitive lock

Definition at line 151 of file LockAnalysis.h.

152 {
153 CxtLock cxtlock(cxt,inst);
154 cxtLockset.insert(cxtlock);
155 DBOUT(DMTA, SVFUtil::outs() << "LockAnalysis Process new lock "; cxtlock.dump());
156 }
#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
CxtLockSet cxtLockset
Context-sensitive locks.
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:50

◆ addCxtStmtToSpan()

bool SVF::LockAnalysis::addCxtStmtToSpan ( const CxtStmt cts,
const CxtLock cl 
)
inline

Add context-sensitive statement.

Definition at line 232 of file LockAnalysis.h.

233 {
234 cxtLocktoSpan[cl].insert(cts);
235 return cxtStmtToCxtLockSet[cts].insert(cl).second;
236 }
CxtLockToSpan cxtLocktoSpan
CxtStmtToCxtLockSet cxtStmtToCxtLockSet

◆ addIntraLock()

void SVF::LockAnalysis::addIntraLock ( const ICFGNode lockSite,
const InstSet stmts 
)
inline

Add intra-procedural lock.

Definition at line 110 of file LockAnalysis.h.

111 {
112 for(InstSet::const_iterator it = stmts.begin(), eit = stmts.end(); it!=eit; ++it)
113 {
114 instCILocksMap[*it].insert(lockSite);
115 ciLocktoSpan[lockSite].insert(*it);
116 }
117 }
InstToInstSetMap instCILocksMap
CILockToSpan ciLocktoSpan
Used for context-insensitive intra-procedural locks.

◆ alias()

bool SVF::LockAnalysis::alias ( const CxtLockSet lockset1,
const CxtLockSet lockset2 
)
inline

Return true if two locksets has at least one alias lock.

Definition at line 179 of file LockAnalysis.h.

180 {
181 for(CxtLockSet::const_iterator it = lockset1.begin(), eit = lockset1.end(); it!=eit; ++it)
182 {
183 const CxtLock& lock = *it;
184 for(CxtLockSet::const_iterator lit = lockset2.begin(), elit = lockset2.end(); lit!=elit; ++lit)
185 {
187 return true;
188 }
189 }
190 return false;
191 }
bool isAliasedLocks(const CxtLock &cl1, const CxtLock &cl2)
Return true it a lock matches an unlock.

◆ analyze()

void LockAnalysis::analyze ( )

context-sensitive forward traversal from each lock site. Generate following results (1) context-sensitive lock site, (2) maps a context-sensitive lock site to its corresponding lock span.

Definition at line 41 of file LockAnalysis.cpp.

42{
43
46
47 DOTIMESTAT(double lockStart = PTAStat::getClk(true));
48
49 DBOUT(DGENERAL, outs() << "\tIntra-procedural LockAnalysis\n");
50 DBOUT(DMTA, outs() << "\tIntra-procedural LockAnalysis\n");
52
53 DBOUT(DGENERAL, outs() << "\tCollect context-sensitive locks\n");
54 DBOUT(DMTA, outs() << "\tCollect context-sensitive locks\n");
56
57 DBOUT(DGENERAL, outs() << "\tInter-procedural LockAnalysis\n");
58 DBOUT(DMTA, outs() << "\tInter-procedural LockAnalysis\n");
60
61 DOTIMESTAT(double lockEnd = PTAStat::getClk(true));
63}
#define TIMEINTERVAL
Definition SVFType.h:512
#define DGENERAL
Definition SVFType.h:490
#define DOTIMESTAT(X)
Definition SVFType.h:486
void buildCandidateFuncSetforLock()
void analyzeIntraProcedualLock()
void collectLockUnlocksites()
static double getClk(bool mark=false)
Definition SVFStat.cpp:48

◆ analyzeIntraProcedualLock()

void LockAnalysis::analyzeIntraProcedualLock ( )

Analyze intraprocedural locks A lock is intraprocedural if its lock span is within a procedural

FIXME:Should we intersect forwardInsts and backwardInsts?

Definition at line 143 of file LockAnalysis.cpp.

144{
145
146 // Identify the protected Instructions.
147 for (InstSet::const_iterator it = locksites.begin(), ie = locksites.end(); it != ie; ++it)
148 {
149 const ICFGNode* lockSite = *it;
150 assert(isCallSite(lockSite) && "Lock acquire instruction must be a CallSite");
151
152 // Perform forward traversal
156
159
161 if(forward && backward)
163 else if(forward && !backward)
165 }
166}
bool intraBackwardTraverse(const InstSet &unlockset, InstSet &backwardInsts)
void addCondIntraLock(const ICFGNode *lockSite, const InstSet &stmts)
Add intra-procedural lock.
InstSet locksites
Record all visited clps.
void addIntraLock(const ICFGNode *lockSite, const InstSet &stmts)
Add intra-procedural lock.
Set< const ICFGNode * > InstSet
bool intraForwardTraverse(const ICFGNode *lock, InstSet &unlockset, InstSet &forwardInsts)
bool isCallSite(const ICFGNode *inst)
Whether it is a callsite.

◆ analyzeLockSpanCxtStmt()

void LockAnalysis::analyzeLockSpanCxtStmt ( )

Definition at line 330 of file LockAnalysis.cpp.

331{
332
333 FunSet entryFuncSet = tct->getEntryProcs();
334 for (FunSet::const_iterator it = entryFuncSet.begin(), eit = entryFuncSet.end(); it != eit; ++it)
335 {
336 if (!isLockCandidateFun(*it))
337 continue;
338 CallStrCxt cxt;
339 const ICFGNode* frontInst = (*it)->getEntryBlock()->front();
342 }
343
344 while (!cxtStmtList.empty())
345 {
347
349 const ICFGNode* curInst = cts.getStmt();
351
352 DBOUT(DMTA, outs() << "\nVisit cxtStmt: ");
353 DBOUT(DMTA, cts.dump());
354
355 DBOUT(DMTA, outs() << "\nIts cxt lock sets: ");
357
358 if (isTDFork(curInst))
359 {
361 }
362 else if (isTDAcquire(curInst))
363 {
364 assert(hasCxtLock(cts) && "context-sensitive lock not found!!");
367 }
368 else if (isTDRelease(curInst))
369 {
372 }
373 else if (isCallSite(curInst) && !isExtCall(curInst))
374 {
376 }
377 else if (isRetInstNode(curInst))
378 {
379 handleRet(cts);
380 }
381 else
382 {
384 }
385
386 }
387
388}
bool empty() const
Definition WorkList.h:146
bool removeCxtStmtToSpan(CxtStmt &cts, const CxtLock &cl)
Add context-sensitive statement.
CxtStmtWorkList cxtStmtList
context-sensitive statement worklist
bool isExtCall(const ICFGNode *inst)
Whether it is calling an external function.
CxtStmt popFromCTSWorkList()
void handleFork(const CxtStmt &cts)
Handle fork.
bool hasCxtLock(const CxtLock &cxtLock) const
Get context-sensitive lock.
void handleIntra(const CxtStmt &cts)
Handle intra.
bool isTDRelease(const ICFGNode *call)
Whether it is a unlock site.
bool addCxtStmtToSpan(const CxtStmt &cts, const CxtLock &cl)
Add context-sensitive statement.
bool isTDFork(const ICFGNode *call)
Whether it is a lock site.
void handleCall(const CxtStmt &cts)
Handle call.
bool pushToCTSWorkList(const CxtStmt &cs)
Worklist operations.
void touchCxtStmt(CxtStmt &cts)
Touch this context statement.
Set< const SVFFunction * > FunSet
void printLocks(const CxtStmt &cts)
Print locks and spans.
void handleRet(const CxtStmt &cts)
Handle return.
bool isLockCandidateFun(const SVFFunction *fun) const
Return true if it is a candidate function.
InstToCxtStmtSet instToCxtStmtSet
Map a statement to all its context-sensitive statements.
bool isTDAcquire(const ICFGNode *call)
Whether it is a lock site.
const FunSet & getEntryProcs() const
Get marked candidate functions.
Definition TCT.h:242
bool isRetInstNode(const ICFGNode *node)
Definition SVFUtil.cpp:389
std::vector< u32_t > CallStrCxt

◆ buildCandidateFuncSetforLock()

void LockAnalysis::buildCandidateFuncSetforLock ( )

Collect candidate functions for context-sensitive lock analysis

Definition at line 95 of file LockAnalysis.cpp.

96{
97
99
100 TCT::PTACGNodeSet visited;
102
103 for (InstSet::iterator it = locksites.begin(), eit = locksites.end(); it != eit; ++it)
104 {
105 const SVFFunction* fun=(*it)->getFun();
107 if (visited.find(cgnode) == visited.end())
108 {
109 worklist.push(cgnode);
110 visited.insert(cgnode);
111 }
112 }
113 for (InstSet::iterator it = unlocksites.begin(), eit = unlocksites.end(); it != eit; ++it)
114 {
115 const SVFFunction* fun = (*it)->getFun();
117 if (visited.find(cgnode) == visited.end())
118 {
119 worklist.push(cgnode);
120 visited.insert(cgnode);
121 }
122 }
123 while (!worklist.empty())
124 {
125 const PTACallGraphNode* node = worklist.pop();
126 lockcandidateFuncSet.insert(node->getFunction());
127 for (PTACallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit != neit; nit++)
128 {
129 const PTACallGraphNode* srcNode = (*nit)->getSrcNode();
130 if (visited.find(srcNode) == visited.end())
131 {
132 visited.insert(srcNode);
133 worklist.push(srcNode);
134 }
135 }
136 }
137}
bool push(const Data &data)
Definition WorkList.h:165
GEdgeSetTy::const_iterator const_iterator
iterator InEdgeBegin()
iterator InEdgeEnd()
FunSet lockcandidateFuncSet
Candidate functions which relevant to locks/unlocks.
const SVFFunction * getFunction() const
Get function of this call node.
PTACallGraphNode * getCallGraphNode(NodeID id) const
Get call graph node.
ThreadCallGraph * getThreadCallGraph() const
Get TCG.
Definition TCT.h:196
Set< const PTACallGraphNode * > PTACGNodeSet
Definition TCT.h:163

◆ clearFlagMap()

void SVF::LockAnalysis::clearFlagMap ( )
inlineprivate

Clear flags.

Definition at line 391 of file LockAnalysis.h.

392 {
394 }

◆ collectCxtLock()

void LockAnalysis::collectCxtLock ( )

Definition at line 259 of file LockAnalysis.cpp.

260{
261 FunSet entryFuncSet = tct->getEntryProcs();
262 for (FunSet::const_iterator it = entryFuncSet.begin(), eit = entryFuncSet.end(); it != eit; ++it)
263 {
264 if (!isLockCandidateFun(*it))
265 continue;
266 CallStrCxt cxt;
267 CxtLockProc t(cxt, *it);
269 }
270
271 while (!clpList.empty())
272 {
275 // lzh TODO.
276 if (!isLockCandidateFun(cgNode->getFunction()))
277 continue;
278
279 for (PTACallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit != neit; nit++)
280 {
281 const PTACallGraphEdge* cgEdge = (*nit);
282
283 for (PTACallGraphEdge::CallInstSet::const_iterator cit = cgEdge->directCallsBegin(), ecit = cgEdge->directCallsEnd();
284 cit != ecit; ++cit)
285 {
286 DBOUT(DMTA,
287 outs() << "\nCollecting CxtLocks: handling direct call:" << **cit << "\t" << cgEdge->getSrcNode()->getFunction()->getName()
288 << "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
290 }
291 for (PTACallGraphEdge::CallInstSet::const_iterator ind = cgEdge->indirectCallsBegin(), eind = cgEdge->indirectCallsEnd();
292 ind != eind; ++ind)
293 {
294 DBOUT(DMTA,
295 outs() << "\nCollecting CxtLocks: handling indirect call:" << **ind << "\t"
296 << cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName()
297 << "\n");
299 }
300 }
301 }
302}
ThreadCallGraph * getTCG() const
ThreadCallGraph.
bool pushToCTPWorkList(const CxtLockProc &clp)
WorkList helper functions.
CxtLockProc popFromCTPWorkList()
void handleCallRelation(CxtLockProc &clp, const PTACallGraphEdge *cgEdge, const CallICFGNode *call)
Handle call relations.
CxtLockProcVec clpList
Following data structures are used for collecting context-sensitive locks.

◆ collectLockUnlocksites()

void LockAnalysis::collectLockUnlocksites ( )

Collect lock/unlock sites

Definition at line 69 of file LockAnalysis.cpp.

70{
72
73 for (const SVFFunction* F : tct->getSVFModule()->getFunctionSet())
74 {
75 for (const SVFBasicBlock* bb : F->getBasicBlockList())
76 {
77 for (const ICFGNode* icfgNode : bb->getICFGNodeList())
78 {
79 if (isa<CallICFGNode>(icfgNode) && tcg->getThreadAPI()->isTDRelease(cast<CallICFGNode>(icfgNode)))
80 {
81 unlocksites.insert(icfgNode);
82 }
83 if (isa<CallICFGNode>(icfgNode) && tcg->getThreadAPI()->isTDAcquire(cast<CallICFGNode>(icfgNode)))
84 {
85 locksites.insert(icfgNode);
86 }
87 }
88 }
89 }
90}
#define F(f)
bool isTDRelease(const CallICFGNode *inst) const
Return true if this call release a lock.
bool isTDAcquire(const CallICFGNode *inst) const
Return true if this call acquire a lock.
ThreadAPI * getThreadAPI() const
Thread API.

◆ getCSTCLS()

CxtStmtToCxtLockSet SVF::LockAnalysis::getCSTCLS ( )
inline

Definition at line 249 of file LockAnalysis.h.

250 {
251 return cxtStmtToCxtLockSet;
252 }

◆ getCxtLockfromCxtStmt() [1/2]

CxtLockSet & SVF::LockAnalysis::getCxtLockfromCxtStmt ( const CxtStmt cts)
inline

Definition at line 225 of file LockAnalysis.h.

226 {
227 CxtStmtToCxtLockSet::iterator it = cxtStmtToCxtLockSet.find(cts);
228 assert(it != cxtStmtToCxtLockSet.end());
229 return it->second;
230 }

◆ getCxtLockfromCxtStmt() [2/2]

const CxtLockSet & SVF::LockAnalysis::getCxtLockfromCxtStmt ( const CxtStmt cts) const
inline

Definition at line 219 of file LockAnalysis.h.

220 {
221 CxtStmtToCxtLockSet::const_iterator it = cxtStmtToCxtLockSet.find(cts);
222 assert(it != cxtStmtToCxtLockSet.end());
223 return it->second;
224 }

◆ getCxtStmtfromInst()

const CxtStmtSet & SVF::LockAnalysis::getCxtStmtfromInst ( const ICFGNode inst) const
inline

Definition at line 208 of file LockAnalysis.h.

209 {
210 InstToCxtStmtSet::const_iterator it = instToCxtStmtSet.find(inst);
211 assert(it != instToCxtStmtSet.end());
212 return it->second;
213 }

◆ getIntraLockSet()

const InstSet & SVF::LockAnalysis::getIntraLockSet ( const ICFGNode stmt) const
inline

Definition at line 140 of file LockAnalysis.h.

141 {
142 InstToInstSetMap::const_iterator it = instCILocksMap.find(stmt);
143 assert(it!=instCILocksMap.end() && "intralock not found!");
144 return it->second;
145 }

◆ getLockVal()

const SVFVar * SVF::LockAnalysis::getLockVal ( const ICFGNode call)
inlineprivate

Get lock value.

Definition at line 469 of file LockAnalysis.h.

470 {
471 return getTCG()->getThreadAPI()->getLockVal(call);
472 }
const SVFVar * getLockVal(const ICFGNode *inst) const
Return lock value.

◆ getNumOfCxtLocks()

u32_t SVF::LockAnalysis::getNumOfCxtLocks ( )
inline

Definition at line 316 of file LockAnalysis.h.

317 {
318 return cxtLockset.size();
319 }

◆ getSpanfromCxtLock()

LockSpan & SVF::LockAnalysis::getSpanfromCxtLock ( const CxtLock cl)
inline

Definition at line 262 of file LockAnalysis.h.

263 {
264 assert(cxtLocktoSpan.find(cl) != cxtLocktoSpan.end());
265 return cxtLocktoSpan[cl];
266 }

◆ getTCG()

ThreadCallGraph * SVF::LockAnalysis::getTCG ( ) const
inlineprivate

ThreadCallGraph.

Definition at line 474 of file LockAnalysis.h.

475 {
476 return tct->getThreadCallGraph();
477 }

◆ getTCT()

TCT * SVF::LockAnalysis::getTCT ( )
inline

Get tct.

Definition at line 324 of file LockAnalysis.h.

325 {
326 return tct;
327 }

◆ handleCall()

void LockAnalysis::handleCall ( const CxtStmt cts)
private

Handle call.

Definition at line 428 of file LockAnalysis.cpp.

429{
430
431 const CallStrCxt& curCxt = cts.getContext();
432 const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(cts.getStmt());
433 if (getTCG()->hasCallGraphEdge(call))
434 {
435 for (PTACallGraph::CallGraphEdgeSet::const_iterator cgIt = getTCG()->getCallEdgeBegin(call), ecgIt = getTCG()->getCallEdgeEnd(call);
436 cgIt != ecgIt; ++cgIt)
437 {
438 const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getFunction();
440 continue;
442 pushCxt(newCxt, call, svfcallee);
443 const ICFGNode* svfInst = svfcallee->getEntryBlock()->front();
446 }
447 }
448}
void markCxtStmtFlag(const CxtStmt &tgr, const CxtStmt &src)
Mark thread flags for cxtStmt.
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
Push calling context.
bool isExtCall(const SVFFunction *fun)
Definition SVFUtil.h:278

◆ handleCallRelation()

void LockAnalysis::handleCallRelation ( CxtLockProc clp,
const PTACallGraphEdge cgEdge,
const CallICFGNode cs 
)
private

Handle call relations.

Handling call relations when collecting context-sensitive locks

Definition at line 308 of file LockAnalysis.cpp.

309{
310
311 CallStrCxt cxt(clp.getContext());
312 const ICFGNode* curNode = cs;
313 if (isTDAcquire(curNode))
314 {
315 addCxtLock(cxt,curNode);
316 return;
317 }
318 const SVFFunction* svfcallee = cgEdge->getDstNode()->getFunction();
319 pushCxt(cxt, SVFUtil::cast<CallICFGNode>(curNode), svfcallee);
320
323 {
324 DBOUT(DMTA, outs() << "LockAnalysis Process CallRet old clp --"; clp.dump());
325 DBOUT(DMTA, outs() << "LockAnalysis Process CallRet new clp --"; newclp.dump());
326 }
327
328}
void addCxtLock(const CallStrCxt &cxt, const ICFGNode *inst)
Context-sensitive locks.

◆ handleFork()

void LockAnalysis::handleFork ( const CxtStmt cts)
private

Handle fork.

Definition at line 407 of file LockAnalysis.cpp.

408{
409 const CallStrCxt& curCxt = cts.getContext();
410 const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(cts.getStmt());
411 if(getTCG()->hasThreadForkEdge(call))
412 {
413 for (ThreadCallGraph::ForkEdgeSet::const_iterator cgIt = getTCG()->getForkEdgeBegin(call),
414 ecgIt = getTCG()->getForkEdgeEnd(call); cgIt != ecgIt; ++cgIt)
415 {
416 const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getFunction();
419 const ICFGNode* svfInst = svfcallee->getEntryBlock()->front();
422 }
423 }
425}

◆ handleIntra()

void LockAnalysis::handleIntra ( const CxtStmt cts)
private

Handle intra.

Definition at line 502 of file LockAnalysis.cpp.

503{
504
505 const ICFGNode* curInst = cts.getStmt();
506 const CallStrCxt& curCxt = cts.getContext();
507
508 for(const ICFGEdge* outEdge : curInst->getOutEdges())
509 {
510 if(outEdge->getDstNode()->getFun() == curInst->getFun())
511 {
512 CxtStmt newCts(curCxt, outEdge->getDstNode());
514 }
515 }
516}

◆ handleRet()

void LockAnalysis::handleRet ( const CxtStmt cts)
private

Handle return.

Definition at line 451 of file LockAnalysis.cpp.

452{
453
454 const ICFGNode* curInst = cts.getStmt();
455 const CallStrCxt& curCxt = cts.getContext();
456 const SVFFunction* svffun = curInst->getFun();
458
459 for (PTACallGraphNode::const_iterator it = curFunNode->getInEdges().begin(), eit = curFunNode->getInEdges().end(); it != eit; ++it)
460 {
462 if (SVFUtil::isa<ThreadForkEdge, ThreadJoinEdge>(edge))
463 continue;
464 for (PTACallGraphEdge::CallInstSet::const_iterator cit = (edge)->directCallsBegin(), ecit = (edge)->directCallsEnd(); cit != ecit;
465 ++cit)
466 {
468 const ICFGNode* inst = *cit;
469 if (matchCxt(newCxt, SVFUtil::cast<CallICFGNode>(inst), curFunNode->getFunction()))
470 {
471 for(const ICFGEdge* outEdge : curInst->getOutEdges())
472 {
473 if(outEdge->getDstNode()->getFun() == curInst->getFun())
474 {
475 CxtStmt newCts(newCxt, outEdge->getDstNode());
477 }
478 }
479 }
480 }
481 for (PTACallGraphEdge::CallInstSet::const_iterator cit = (edge)->indirectCallsBegin(), ecit = (edge)->indirectCallsEnd();
482 cit != ecit; ++cit)
483 {
485 const ICFGNode* inst = *cit;
486 if (matchCxt(newCxt, SVFUtil::cast<CallICFGNode>(inst), curFunNode->getFunction()))
487 {
488 for(const ICFGEdge* outEdge : curInst->getOutEdges())
489 {
490 if(outEdge->getDstNode()->getFun() == curInst->getFun())
491 {
492 CxtStmt newCts(newCxt, outEdge->getDstNode());
494 }
495 }
496 }
497 }
498 }
499}
bool matchCxt(CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
Match context.

◆ hasAllCxtInLockSpan()

bool SVF::LockAnalysis::hasAllCxtInLockSpan ( const ICFGNode I,
LockSpan  lspan 
) const
inline

Definition at line 287 of file LockAnalysis.h.

288 {
289 if(!hasCxtStmtfromInst(I))
290 return false;
292 for (LockSpan::const_iterator cts = ctsset.begin(), ects = ctsset.end(); cts != ects; cts++)
293 {
294 if (lspan.find(*cts) == lspan.end())
295 {
296 return false;
297 }
298 }
299 return true;
300 }
Set< CxtStmt > LockSpan
const CxtStmtSet & getCxtStmtfromInst(const ICFGNode *inst) const
bool hasCxtStmtfromInst(const ICFGNode *inst) const
Context-sensitive statement and lock spans.

◆ hasCxtLock()

bool SVF::LockAnalysis::hasCxtLock ( const CxtLock cxtLock) const
inline

Get context-sensitive lock.

Definition at line 159 of file LockAnalysis.h.

160 {
161 return cxtLockset.find(cxtLock)!=cxtLockset.end();
162 }

◆ hasCxtLockfromCxtStmt()

bool SVF::LockAnalysis::hasCxtLockfromCxtStmt ( const CxtStmt cts) const
inline

Definition at line 214 of file LockAnalysis.h.

215 {
216 CxtStmtToCxtLockSet::const_iterator it = cxtStmtToCxtLockSet.find(cts);
217 return (it != cxtStmtToCxtLockSet.end());
218 }

◆ hasCxtStmtfromInst()

bool SVF::LockAnalysis::hasCxtStmtfromInst ( const ICFGNode inst) const
inline

Context-sensitive statement and lock spans.

Get LockSet and LockSpan

Definition at line 203 of file LockAnalysis.h.

204 {
205 InstToCxtStmtSet::const_iterator it = instToCxtStmtSet.find(inst);
206 return (it != instToCxtStmtSet.end());
207 }

◆ hasOneCxtInLockSpan()

bool SVF::LockAnalysis::hasOneCxtInLockSpan ( const ICFGNode I,
LockSpan  lspan 
) const
inline

Check if one instruction's context stmt is in a lock span.

Definition at line 272 of file LockAnalysis.h.

273 {
274 if(!hasCxtStmtfromInst(I))
275 return false;
277 for (LockSpan::const_iterator cts = ctsset.begin(), ects = ctsset.end(); cts != ects; cts++)
278 {
279 if(lspan.find(*cts) != lspan.end())
280 {
281 return true;
282 }
283 }
284 return false;
285 }

◆ hasSpanfromCxtLock()

bool SVF::LockAnalysis::hasSpanfromCxtLock ( const CxtLock cl)
inline

Definition at line 258 of file LockAnalysis.h.

259 {
260 return cxtLocktoSpan.find(cl) != cxtLocktoSpan.end();
261 }

◆ intersect()

bool SVF::LockAnalysis::intersect ( CxtLockSet tgrlockset,
const CxtLockSet srclockset 
)
inlineprivate

Definition at line 375 of file LockAnalysis.h.

376 {
378 for(CxtLockSet::const_iterator it = tgrlockset.begin(), eit = tgrlockset.end(); it!=eit; ++it)
379 {
380 if(srclockset.find(*it)==srclockset.end())
381 toBeDeleted.insert(*it);
382 }
383 for(CxtLockSet::const_iterator it = toBeDeleted.begin(), eit = toBeDeleted.end(); it!=eit; ++it)
384 {
385 tgrlockset.erase(*it);
386 }
387 return !toBeDeleted.empty();
388 }
Set< CxtLock > CxtLockSet

◆ intersects()

bool SVF::LockAnalysis::intersects ( const CxtLockSet lockset1,
const CxtLockSet lockset2 
) const
inline

Return true if the intersection of two locksets is not empty.

Definition at line 165 of file LockAnalysis.h.

166 {
167 for(CxtLockSet::const_iterator it = lockset1.begin(), eit = lockset1.end(); it!=eit; ++it)
168 {
169 const CxtLock& lock = *it;
170 for(CxtLockSet::const_iterator lit = lockset2.begin(), elit = lockset2.end(); lit!=elit; ++lit)
171 {
172 if(lock==*lit)
173 return true;
174 }
175 }
176 return false;
177 }

◆ intraBackwardTraverse()

bool LockAnalysis::intraBackwardTraverse ( const InstSet unlockSet,
InstSet backwardInsts 
)

Intra-procedural backward traversal

Definition at line 215 of file LockAnalysis.cpp.

216{
217
218 InstVec worklist;
219 for(InstSet::const_iterator it = unlockSet.begin(), eit = unlockSet.end(); it!=eit; ++it)
220 {
221 const ICFGNode* unlockSite = *it;
223 worklist.push_back(*it);
224
225 while (!worklist.empty())
226 {
227 const ICFGNode *I = worklist.back();
228 worklist.pop_back();
229
230 if(entryInst == I)
231 return false;
232
233 // Skip the visited Instructions.
234 if (backwardInsts.find(I)!=backwardInsts.end())
235 continue;
236 backwardInsts.insert(I);
237
239 {
240 DBOUT(DMTA, outs() << "LockAnalysis ci lock -- " << I->getSourceLoc()<<"\n");
241 DBOUT(DMTA, outs() << "LockAnalysis ci unlock -- " << unlockSite->getSourceLoc()<<"\n");
242 continue;
243 }
244
245 for(const ICFGEdge* inEdge : I->getInEdges())
246 {
247 if(inEdge->getSrcNode()->getFun() == I->getFun())
248 {
249 worklist.push_back(inEdge->getSrcNode());
250 }
251 }
252 }
253 }
254
255 return true;
256}
virtual const SVFFunction * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:76
TCT::InstVec InstVec
virtual const std::string getSourceLoc() const
const ICFGNode * back() const
Definition SVFValue.h:611
const SVFBasicBlock * getEntryBlock() const
Definition SVFValue.h:420

◆ intraForwardTraverse()

bool LockAnalysis::intraForwardTraverse ( const ICFGNode lockSite,
InstSet unlockSet,
InstSet forwardInsts 
)

Intra-procedural forward traversal

Definition at line 171 of file LockAnalysis.cpp.

172{
173
174 const SVFFunction* svfFun = lockSite->getFun();
175
176 InstVec worklist;
177 worklist.push_back(lockSite);
178 while (!worklist.empty())
179 {
180 const ICFGNode *I = worklist.back();
181 worklist.pop_back();
182 const ICFGNode* exitInst = svfFun->getExitBB()->back();
183 if(exitInst == I)
184 return false;
185
186 // Skip the visited Instructions.
187 if (forwardInsts.find(I)!=forwardInsts.end())
188 continue;
189 forwardInsts.insert(I);
190
191 if (isTDRelease(I) && isAliasedLocks(lockSite, I))
192 {
193 unlockSet.insert(I);
194 DBOUT(DMTA, outs() << "LockAnalysis ci lock -- " << lockSite->getSourceLoc()<<"\n");
195 DBOUT(DMTA, outs() << "LockAnalysis ci unlock -- " << I->getSourceLoc()<<"\n");
196 continue;
197 }
198
199 for(const ICFGEdge* outEdge : I->getOutEdges())
200 {
201 if(outEdge->getDstNode()->getFun() == I->getFun())
202 {
203 worklist.push_back(outEdge->getDstNode());
204 }
205 }
206 }
207
208 return true;
209}

◆ isAliasedLocks() [1/2]

bool SVF::LockAnalysis::isAliasedLocks ( const CxtLock cl1,
const CxtLock cl2 
)
inlineprivate

Return true it a lock matches an unlock.

Definition at line 345 of file LockAnalysis.h.

346 {
347 return isAliasedLocks(cl1.getStmt(), cl2.getStmt());
348 }

◆ isAliasedLocks() [2/2]

bool SVF::LockAnalysis::isAliasedLocks ( const ICFGNode i1,
const ICFGNode i2 
)
inlineprivate

todo: must alias

Definition at line 349 of file LockAnalysis.h.

350 {
352 return tct->getPTA()->alias(getLockVal(i1)->getId(), getLockVal(i2)->getId());
353 }
const SVFVar * getLockVal(const ICFGNode *call)
Get lock value.
virtual AliasResult alias(const SVFValue *V1, const SVFValue *V2)=0
Interface exposed to users of our pointer analysis, given Value infos.
PointerAnalysis * getPTA() const
Get PTA.
Definition TCT.h:201

◆ isCallSite()

bool SVF::LockAnalysis::isCallSite ( const ICFGNode inst)
inlineprivate

Whether it is a callsite.

Definition at line 459 of file LockAnalysis.h.

460 {
461 return tct->isCallSite(inst);
462 }
bool isCallSite(const ICFGNode *inst)
Whether it is a callsite.
Definition TCT.h:271

◆ isExtCall()

bool SVF::LockAnalysis::isExtCall ( const ICFGNode inst)
inlineprivate

Whether it is calling an external function.

Definition at line 464 of file LockAnalysis.h.

465 {
466 return tct->isExtCall(inst);
467 }
bool isExtCall(const ICFGNode *inst)
Whether it is calling an external function.
Definition TCT.h:264

◆ isInSameCISpan()

bool LockAnalysis::isInSameCISpan ( const ICFGNode i1,
const ICFGNode i2 
) const

Return true if two instructions are inside same context-insensitive lock span

Definition at line 656 of file LockAnalysis.cpp.

657{
659 {
662 for (InstSet::const_iterator cil1 = lockset1.begin(), ecil1 = lockset1.end(); cil1!=ecil1; ++cil1)
663 {
664 for (InstSet::const_iterator cil2=lockset2.begin(), ecil2=lockset2.end(); cil2!=ecil2; ++cil2)
665 {
666 if (*cil1==*cil2)
667 return true;
668 }
669 }
670 }
671 return false;
672}
bool isInsideCondIntraLock(const ICFGNode *stmt) const
Return true if a statement is inside a partial lock/unlock pair (conditional lock with unconditional ...
const InstSet & getIntraLockSet(const ICFGNode *stmt) const

◆ isInSameCSSpan() [1/2]

bool LockAnalysis::isInSameCSSpan ( const CxtStmt cxtStmt1,
const CxtStmt cxtStmt2 
) const

Return true if two context-sensitive instructions are inside same context-insensitive lock spa

Definition at line 677 of file LockAnalysis.cpp.

678{
680 return true;
684}
bool hasCxtLockfromCxtStmt(const CxtStmt &cts) const
const CxtLockSet & getCxtLockfromCxtStmt(const CxtStmt &cts) const
bool intersects(const CxtLockSet &lockset1, const CxtLockSet &lockset2) const
Return true if the intersection of two locksets is not empty.

◆ isInSameCSSpan() [2/2]

bool LockAnalysis::isInSameCSSpan ( const ICFGNode I1,
const ICFGNode I2 
) const

Return true if two instructions are inside at least one common context-sensitive lock span

Definition at line 688 of file LockAnalysis.cpp.

689{
691 return false;
694
695 for (CxtStmtSet::const_iterator cts1 = ctsset1.begin(), ects1 = ctsset1.end(); cts1 != ects1; cts1++)
696 {
697 const CxtStmt& cxtStmt1 = *cts1;
698 for (CxtStmtSet::const_iterator cts2 = ctsset2.begin(), ects2 = ctsset2.end(); cts2 != ects2; cts2++)
699 {
700 const CxtStmt& cxtStmt2 = *cts2;
701 if(cxtStmt1==cxtStmt2) continue;
703 return false;
704 }
705 }
706 return true;
707}
bool isInSameCSSpan(const ICFGNode *i1, const ICFGNode *i2) const
Set< CxtStmt > CxtStmtSet

◆ isInSameSpan()

bool LockAnalysis::isInSameSpan ( const ICFGNode i1,
const ICFGNode i2 
)

Return true if two instructions are inside at least one common lock span

Definition at line 638 of file LockAnalysis.cpp.

639{
640 DOTIMESTAT(double queryStart = PTAStat::getClk(true));
641
642 bool sameSpan = false;
645 else
647
648 DOTIMESTAT(double queryEnd = PTAStat::getClk(true));
650 return sameSpan;
651}
bool isInsideIntraLock(const ICFGNode *stmt) const
Return true if a statement is inside an intra-procedural lock.
bool isInSameCISpan(const ICFGNode *i1, const ICFGNode *i2) const

◆ isInsideCondIntraLock()

bool SVF::LockAnalysis::isInsideCondIntraLock ( const ICFGNode stmt) const
inline

Return true if a statement is inside a partial lock/unlock pair (conditional lock with unconditional unlock)

Definition at line 135 of file LockAnalysis.h.

136 {
138 }

◆ isInsideIntraLock()

bool SVF::LockAnalysis::isInsideIntraLock ( const ICFGNode stmt) const
inline

Return true if a statement is inside an intra-procedural lock.

Definition at line 129 of file LockAnalysis.h.

130 {
132 }

◆ isIntraLock()

bool SVF::LockAnalysis::isIntraLock ( const ICFGNode lock) const
inline

Intraprocedural locks.

Return true if the lock is an intra-procedural lock

Definition at line 103 of file LockAnalysis.h.

104 {
105 assert(locksites.find(lock)!=locksites.end() && "not a lock site?");
106 return ciLocktoSpan.find(lock)!=ciLocktoSpan.end();
107 }

◆ isLockCandidateFun()

bool SVF::LockAnalysis::isLockCandidateFun ( const SVFFunction fun) const
inline

Return true if it is a candidate function.

Definition at line 195 of file LockAnalysis.h.

196 {
197 return lockcandidateFuncSet.find(fun)!=lockcandidateFuncSet.end();
198 }

◆ isProtectedByCommonCILock()

bool LockAnalysis::isProtectedByCommonCILock ( const ICFGNode i1,
const ICFGNode i2 
)

Protected by at least one common context-insensitive lock

Definition at line 580 of file LockAnalysis.cpp.

581{
582
584 {
587 for (InstSet::const_iterator cil1 = lockset1.begin(), ecil1 = lockset1.end(); cil1!=ecil1; ++cil1)
588 {
589 for (InstSet::const_iterator cil2=lockset2.begin(), ecil2=lockset2.end(); cil2!=ecil2; ++cil2)
590 {
591 if (isAliasedLocks(*cil1, *cil2))
592 return true;
593 }
594 }
595 }
596 return false;
597}

◆ isProtectedByCommonCxtLock() [1/2]

bool LockAnalysis::isProtectedByCommonCxtLock ( const CxtStmt cxtStmt1,
const CxtStmt cxtStmt2 
)

Protected by at least one common context-sensitive lock

Definition at line 602 of file LockAnalysis.cpp.

603{
605 return true;
608 return alias(lockset1,lockset2);
609}
bool alias(const CxtLockSet &lockset1, const CxtLockSet &lockset2)
Return true if two locksets has at least one alias lock.

◆ isProtectedByCommonCxtLock() [2/2]

bool LockAnalysis::isProtectedByCommonCxtLock ( const ICFGNode i1,
const ICFGNode i2 
)

Protected by at least one common context-sensitive lock under each context

Definition at line 614 of file LockAnalysis.cpp.

615{
617 return false;
620 for (CxtStmtSet::const_iterator cts1 = ctsset1.begin(), ects1 = ctsset1.end(); cts1 != ects1; cts1++)
621 {
622 const CxtStmt& cxtStmt1 = *cts1;
623 for (CxtStmtSet::const_iterator cts2 = ctsset2.begin(), ects2 = ctsset2.end(); cts2 != ects2; cts2++)
624 {
625 const CxtStmt& cxtStmt2 = *cts2;
626 if(cxtStmt1==cxtStmt2) continue;
628 return false;
629 }
630 }
631 return true;
632}
bool isProtectedByCommonCxtLock(const ICFGNode *i1, const ICFGNode *i2)

◆ isProtectedByCommonLock()

bool LockAnalysis::isProtectedByCommonLock ( const ICFGNode i1,
const ICFGNode i2 
)

Check if two Instructions are protected by common locks echo inst may have multiple cxt stmt we check whether every cxt stmt of instructions is protected by a common lock.

Protected by at least one common lock under every context

Definition at line 563 of file LockAnalysis.cpp.

564{
566 bool commonlock = false;
567 DOTIMESTAT(double queryStart = PTAStat::getClk(true));
570 else
572 DOTIMESTAT(double queryEnd = PTAStat::getClk(true));
574 return commonlock;
575}
bool isProtectedByCommonCILock(const ICFGNode *i1, const ICFGNode *i2)

◆ isTDAcquire()

bool SVF::LockAnalysis::isTDAcquire ( const ICFGNode call)
inlineprivate

Whether it is a lock site.

Definition at line 445 of file LockAnalysis.h.

446 {
447 if(SVFUtil::isa<CallICFGNode>(call) == false)
448 return false;
449 return getTCG()->getThreadAPI()->isTDAcquire(SVFUtil::cast<CallICFGNode>(call));
450 }

◆ isTDFork()

bool SVF::LockAnalysis::isTDFork ( const ICFGNode call)
inlineprivate

Whether it is a lock site.

Definition at line 438 of file LockAnalysis.h.

439 {
440 if(SVFUtil::isa<CallICFGNode>(call) == false)
441 return false;
442 return getTCG()->getThreadAPI()->isTDFork(SVFUtil::cast<CallICFGNode>(call));
443 }
bool isTDFork(const CallICFGNode *inst) const
Return true if this call create a new thread.

◆ isTDRelease()

bool SVF::LockAnalysis::isTDRelease ( const ICFGNode call)
inlineprivate

Whether it is a unlock site.

Definition at line 452 of file LockAnalysis.h.

453 {
454 if(SVFUtil::isa<CallICFGNode>(call) == false)
455 return false;
456 return getTCG()->getThreadAPI()->isTDRelease(SVFUtil::cast<CallICFGNode>(call));
457 }

◆ isVisitedCTPs()

bool SVF::LockAnalysis::isVisitedCTPs ( const CxtLockProc clp) const
inlineprivate

Definition at line 413 of file LockAnalysis.h.

414 {
415 return visitedCTPs.find(clp) != visitedCTPs.end();
416 }
CxtLockProcSet visitedCTPs
CxtLockProc List.

◆ markCxtStmtFlag()

void SVF::LockAnalysis::markCxtStmtFlag ( const CxtStmt tgr,
const CxtStmt src 
)
inlineprivate

Mark thread flags for cxtStmt.

Transfer function for marking context-sensitive statement

Definition at line 358 of file LockAnalysis.h.

359 {
361 if(hasCxtLockfromCxtStmt(tgr)== false)
362 {
363 for(CxtLockSet::const_iterator it = srclockset.begin(), eit = srclockset.end(); it!=eit; ++it)
364 {
366 }
368 }
369 else
370 {
373 }
374 }
bool intersect(CxtLockSet &tgrlockset, const CxtLockSet &srclockset)

◆ matchCxt()

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

Match context.

partial match

Definition at line 535 of file LockAnalysis.cpp.

536{
537 const SVFFunction* svfcaller = call->getFun();
538 CallSiteID csId = getTCG()->getCallSiteID(call, callee);
539
540// /// handle calling context for candidate functions only
541// if (isLockCandidateFun(caller) == false)
542// return true;
543
545 if (cxt.empty())
546 return true;
547
548 if (tct->inSameCallGraphSCC(getTCG()->getCallGraphNode(svfcaller), getTCG()->getCallGraphNode(callee)) == false)
549 {
550 if (cxt.back() == csId)
551 cxt.pop_back();
552 else
553 return false;
554 DBOUT(DMTA, tct->dumpCxt(cxt));
555 }
556 return true;
557}
CallSiteID getCallSiteID(const CallICFGNode *cs, const SVFFunction *callee) const
Get CallSiteID.
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:496
unsigned CallSiteID
Definition GeneralType.h:58

◆ popFromCTPWorkList()

CxtLockProc SVF::LockAnalysis::popFromCTPWorkList ( )
inlineprivate

Definition at line 408 of file LockAnalysis.h.

409 {
411 return clp;
412 }

◆ popFromCTSWorkList()

CxtStmt SVF::LockAnalysis::popFromCTSWorkList ( )
inlineprivate

Definition at line 425 of file LockAnalysis.h.

426 {
427 CxtStmt clp = cxtStmtList.pop();
428 return clp;
429 }

◆ printLocks()

void LockAnalysis::printLocks ( const CxtStmt cts)

Print locks and spans.

Print context-insensitive and context-sensitive locks

Definition at line 394 of file LockAnalysis.cpp.

395{
397 outs() << "\nlock sets size = " << lockset.size() << "\n";
398 for (CxtLockSet::const_iterator it = lockset.begin(), eit = lockset.end(); it != eit; ++it)
399 {
400 (*it).dump();
401 }
402}

◆ pushCxt()

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

Push calling context.

Definition at line 519 of file LockAnalysis.cpp.

520{
521 const SVFFunction* svfcaller = call->getFun();
522 CallSiteID csId = getTCG()->getCallSiteID(call, callee);
523
524// /// handle calling context for candidate functions only
525// if (isLockCandidateFun(caller) == false)
526// return;
527
528 if (tct->inSameCallGraphSCC(getTCG()->getCallGraphNode(svfcaller), getTCG()->getCallGraphNode(callee)) == false)
529 {
530 tct->pushCxt(cxt,csId);
531 DBOUT(DMTA, tct->dumpCxt(cxt));
532 }
533}
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const SVFFunction *callee)
Push calling context.
Definition TCT.cpp:445

◆ pushToCTPWorkList()

bool SVF::LockAnalysis::pushToCTPWorkList ( const CxtLockProc clp)
inlineprivate

WorkList helper functions.

Definition at line 399 of file LockAnalysis.h.

400 {
401 if (isVisitedCTPs(clp) == false)
402 {
403 visitedCTPs.insert(clp);
404 return clpList.push(clp);
405 }
406 return false;
407 }
bool isVisitedCTPs(const CxtLockProc &clp) const

◆ pushToCTSWorkList()

bool SVF::LockAnalysis::pushToCTSWorkList ( const CxtStmt cs)
inlineprivate

Worklist operations.

Definition at line 421 of file LockAnalysis.h.

422 {
423 return cxtStmtList.push(cs);
424 }

◆ removeCxtStmtToSpan()

bool SVF::LockAnalysis::removeCxtStmtToSpan ( CxtStmt cts,
const CxtLock cl 
)
inline

Add context-sensitive statement.

Definition at line 238 of file LockAnalysis.h.

239 {
240 bool find = cxtStmtToCxtLockSet[cts].find(cl)!=cxtStmtToCxtLockSet[cts].end();
241 if(find)
242 {
243 cxtStmtToCxtLockSet[cts].erase(cl);
244 cxtLocktoSpan[cl].erase(cts);
245 }
246 return find;
247 }

◆ touchCxtStmt()

void SVF::LockAnalysis::touchCxtStmt ( CxtStmt cts)
inline

Touch this context statement.

Definition at line 254 of file LockAnalysis.h.

255 {
257 }

Member Data Documentation

◆ ciLocktoSpan

CILockToSpan SVF::LockAnalysis::ciLocktoSpan
private

Used for context-insensitive intra-procedural locks.

Definition at line 518 of file LockAnalysis.h.

◆ clpList

CxtLockProcVec SVF::LockAnalysis::clpList
private

Following data structures are used for collecting context-sensitive locks.

Definition at line 501 of file LockAnalysis.h.

◆ cxtLockset

CxtLockSet SVF::LockAnalysis::cxtLockset
private

Context-sensitive locks.

Definition at line 490 of file LockAnalysis.h.

◆ cxtLocktoSpan

CxtLockToSpan SVF::LockAnalysis::cxtLocktoSpan
private

Map a context-sensitive lock to its lock span statements Map a context-sensitive statement to its context-sensitive lock

Definition at line 495 of file LockAnalysis.h.

◆ cxtStmtList

CxtStmtWorkList SVF::LockAnalysis::cxtStmtList
private

context-sensitive statement worklist

Definition at line 483 of file LockAnalysis.h.

◆ cxtStmtToCxtLockSet

CxtStmtToCxtLockSet SVF::LockAnalysis::cxtStmtToCxtLockSet
private

Definition at line 496 of file LockAnalysis.h.

◆ instCILocksMap

InstToInstSetMap SVF::LockAnalysis::instCILocksMap
private

Definition at line 519 of file LockAnalysis.h.

◆ instTocondCILocksMap

InstToInstSetMap SVF::LockAnalysis::instTocondCILocksMap
private

Definition at line 520 of file LockAnalysis.h.

◆ instToCxtStmtSet

InstToCxtStmtSet SVF::LockAnalysis::instToCxtStmtSet
private

Map a statement to all its context-sensitive statements.

Definition at line 486 of file LockAnalysis.h.

◆ lockcandidateFuncSet

FunSet SVF::LockAnalysis::lockcandidateFuncSet
private

Candidate functions which relevant to locks/unlocks.

Definition at line 513 of file LockAnalysis.h.

◆ lockQueriesTime

double SVF::LockAnalysis::lockQueriesTime

Definition at line 528 of file LockAnalysis.h.

◆ locksites

InstSet SVF::LockAnalysis::locksites
private

Record all visited clps.

Collecting lock/unlock sites

Definition at line 507 of file LockAnalysis.h.

◆ lockTime

double SVF::LockAnalysis::lockTime

Definition at line 525 of file LockAnalysis.h.

◆ numOfLockedQueries

u32_t SVF::LockAnalysis::numOfLockedQueries

Definition at line 527 of file LockAnalysis.h.

◆ numOfTotalQueries

u32_t SVF::LockAnalysis::numOfTotalQueries

Definition at line 526 of file LockAnalysis.h.

◆ tct

TCT* SVF::LockAnalysis::tct
private

TCT.

Definition at line 480 of file LockAnalysis.h.

◆ unlocksites

InstSet SVF::LockAnalysis::unlocksites
private

Definition at line 508 of file LockAnalysis.h.

◆ visitedCTPs

CxtLockProcSet SVF::LockAnalysis::visitedCTPs
private

CxtLockProc List.

Definition at line 502 of file LockAnalysis.h.


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