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 FunObjVar * > 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 *, CxtStmtSetInstToCxtStmtSet
 
typedef Map< CxtStmt, CxtLockSetCxtStmtToCxtLockSet
 
typedef FIFOWorkList< CxtLockProcCxtLockProcVec
 
typedef Set< CxtLockProcCxtLockProcSet
 

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 FunObjVar *fun) const
 Return true if it is a candidate function.
 
bool hasCxtStmtFromInst (const ICFGNode *inst) const
 Context-sensitive statement and lock spans.
 
const CxtStmtSetgetCxtStmtsFromInst (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 CallGraphEdge *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 FunObjVar *callee)
 Context helper functions.
 
bool matchCxt (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 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.

◆ 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 80 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 118 of file LockAnalysis.h.

119 {
120 for(InstSet::const_iterator it = stmts.begin(), eit = stmts.end(); it!=eit; ++it)
121 {
123 }
124 }
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 149 of file LockAnalysis.h.

150 {
151 CxtLock cxtlock(cxt,inst);
152 cxtLockset.insert(cxtlock);
153 DBOUT(DMTA, SVFUtil::outs() << "LockAnalysis Process new lock "; cxtlock.dump());
154 }
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:497
#define DMTA
Definition SVFType.h:518
CxtLockSet cxtLockset
Context-sensitive locks.
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52

◆ addCxtStmtToSpan()

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

Add context-sensitive statement.

Definition at line 230 of file LockAnalysis.h.

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

◆ addIntraLock()

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

Add intra-procedural lock.

Definition at line 108 of file LockAnalysis.h.

109 {
110 for(InstSet::const_iterator it = stmts.begin(), eit = stmts.end(); it!=eit; ++it)
111 {
112 instCILocksMap[*it].insert(lockSite);
113 ciLocktoSpan[lockSite].insert(*it);
114 }
115 }
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 177 of file LockAnalysis.h.

178 {
179 for(CxtLockSet::const_iterator it = lockset1.begin(), eit = lockset1.end(); it!=eit; ++it)
180 {
181 const CxtLock& lock = *it;
182 for(CxtLockSet::const_iterator lit = lockset2.begin(), elit = lockset2.end(); lit!=elit; ++lit)
183 {
185 return true;
186 }
187 }
188 return false;
189 }
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:525
#define DGENERAL
Definition SVFType.h:503
#define DOTIMESTAT(X)
Definition SVFType.h:499
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 145 of file LockAnalysis.cpp.

146{
147
148 // Identify the protected Instructions.
149 for (InstSet::const_iterator it = locksites.begin(), ie = locksites.end(); it != ie; ++it)
150 {
151 const ICFGNode* lockSite = *it;
152 assert(isCallSite(lockSite) && "Lock acquire instruction must be a CallSite");
153
154 // Perform forward traversal
158
161
163 if(forward && backward)
165 else if(forward && !backward)
167 }
168}
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 332 of file LockAnalysis.cpp.

333{
334
335 FunSet entryFuncSet = tct->getEntryProcs();
336 for (FunSet::const_iterator it = entryFuncSet.begin(), eit = entryFuncSet.end(); it != eit; ++it)
337 {
338 if (!isLockCandidateFun(*it))
339 continue;
340 CallStrCxt cxt;
341 const ICFGNode* frontInst = (*it)->getEntryBlock()->front();
344 }
345
346 while (!cxtStmtList.empty())
347 {
349
351 const ICFGNode* curInst = cts.getStmt();
353
354 DBOUT(DMTA, outs() << "\nVisit cxtStmt: ");
355 DBOUT(DMTA, cts.dump());
356
357 DBOUT(DMTA, outs() << "\nIts cxt lock sets: ");
359
360 if (isTDFork(curInst))
361 {
363 }
364 else if (isTDAcquire(curInst))
365 {
366 assert(hasCxtLock(cts) && "context-sensitive lock not found!!");
369 }
370 else if (isTDRelease(curInst))
371 {
374 }
375 else if (isCallSite(curInst) && !isExtCall(curInst))
376 {
378 }
379 else if (SVFUtil::dyn_cast<FunExitICFGNode>(curInst))
380 {
381 handleRet(cts);
382 }
383 else
384 {
386 }
387
388 }
389
390}
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.
bool isLockCandidateFun(const FunObjVar *fun) const
Return true if it is a candidate function.
void printLocks(const CxtStmt &cts)
Print locks and spans.
void handleRet(const CxtStmt &cts)
Handle return.
Set< const FunObjVar * > FunSet
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:236
std::vector< u32_t > CallStrCxt

◆ buildCandidateFuncSetforLock()

void LockAnalysis::buildCandidateFuncSetforLock ( )

Collect candidate functions for context-sensitive lock analysis

Definition at line 97 of file LockAnalysis.cpp.

98{
99
101
102 TCT::PTACGNodeSet visited;
104
105 for (InstSet::iterator it = locksites.begin(), eit = locksites.end(); it != eit; ++it)
106 {
107 const FunObjVar* fun=(*it)->getFun();
109 if (visited.find(cgnode) == visited.end())
110 {
111 worklist.push(cgnode);
112 visited.insert(cgnode);
113 }
114 }
115 for (InstSet::iterator it = unlocksites.begin(), eit = unlocksites.end(); it != eit; ++it)
116 {
117 const FunObjVar* fun = (*it)->getFun();
119 if (visited.find(cgnode) == visited.end())
120 {
121 worklist.push(cgnode);
122 visited.insert(cgnode);
123 }
124 }
125 while (!worklist.empty())
126 {
127 const CallGraphNode* node = worklist.pop();
128 lockcandidateFuncSet.insert(node->getFunction());
129 for (CallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit != neit; nit++)
130 {
131 const CallGraphNode* srcNode = (*nit)->getSrcNode();
132 if (visited.find(srcNode) == visited.end())
133 {
134 visited.insert(srcNode);
135 worklist.push(srcNode);
136 }
137 }
138 }
139}
const FunObjVar * getFunction() const
Get function of this call node.
Definition CallGraph.h:191
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
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.
Set< const CallGraphNode * > PTACGNodeSet
Definition TCT.h:163
ThreadCallGraph * getThreadCallGraph() const
Get TCG.
Definition TCT.h:190

◆ clearFlagMap()

void SVF::LockAnalysis::clearFlagMap ( )
inlineprivate

Clear flags.

Definition at line 389 of file LockAnalysis.h.

390 {
392 }

◆ collectCxtLock()

void LockAnalysis::collectCxtLock ( )

Definition at line 261 of file LockAnalysis.cpp.

262{
263 FunSet entryFuncSet = tct->getEntryProcs();
264 for (FunSet::const_iterator it = entryFuncSet.begin(), eit = entryFuncSet.end(); it != eit; ++it)
265 {
266 if (!isLockCandidateFun(*it))
267 continue;
268 CallStrCxt cxt;
269 CxtLockProc t(cxt, *it);
271 }
272
273 while (!clpList.empty())
274 {
276 CallGraphNode* cgNode = getTCG()->getCallGraphNode(clp.getProc());
277 // lzh TODO.
278 if (!isLockCandidateFun(cgNode->getFunction()))
279 continue;
280
281 for (CallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit != neit; nit++)
282 {
283 const CallGraphEdge* cgEdge = (*nit);
284
285 for (CallGraphEdge::CallInstSet::const_iterator cit = cgEdge->directCallsBegin(), ecit = cgEdge->directCallsEnd();
286 cit != ecit; ++cit)
287 {
288 DBOUT(DMTA,
289 outs() << "\nCollecting CxtLocks: handling direct call:" << **cit << "\t" << cgEdge->getSrcNode()->getFunction()->getName()
290 << "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
292 }
293 for (CallGraphEdge::CallInstSet::const_iterator ind = cgEdge->indirectCallsBegin(), eind = cgEdge->indirectCallsEnd();
294 ind != eind; ++ind)
295 {
296 DBOUT(DMTA,
297 outs() << "\nCollecting CxtLocks: handling indirect call:" << **ind << "\t"
298 << cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName()
299 << "\n");
301 }
302 }
303 }
304}
iterator OutEdgeEnd()
iterator OutEdgeBegin()
iterators
ThreadCallGraph * getTCG() const
ThreadCallGraph.
bool pushToCTPWorkList(const CxtLockProc &clp)
WorkList helper functions.
void handleCallRelation(CxtLockProc &clp, const CallGraphEdge *cgEdge, const CallICFGNode *call)
Handle call relations.
CxtLockProc popFromCTPWorkList()
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 auto& item : *PAG::getPAG()->getCallGraph())
74 {
75 const FunObjVar* F = item.second->getFunction();
76 for (auto it : *F)
77 {
78 const SVFBasicBlock* bb = it.second;
79 for (const ICFGNode* icfgNode : bb->getICFGNodeList())
80 {
81 if (isa<CallICFGNode>(icfgNode) && tcg->getThreadAPI()->isTDRelease(cast<CallICFGNode>(icfgNode)))
82 {
83 unlocksites.insert(icfgNode);
84 }
85 if (isa<CallICFGNode>(icfgNode) && tcg->getThreadAPI()->isTDAcquire(cast<CallICFGNode>(icfgNode)))
86 {
87 locksites.insert(icfgNode);
88 }
89 }
90 }
91 }
92}
cJSON * item
Definition cJSON.h:222
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 247 of file LockAnalysis.h.

248 {
249 return cxtStmtToCxtLockSet;
250 }

◆ getCxtLockfromCxtStmt() [1/2]

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

Definition at line 223 of file LockAnalysis.h.

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

◆ getCxtLockfromCxtStmt() [2/2]

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

Definition at line 217 of file LockAnalysis.h.

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

◆ getCxtStmtsFromInst()

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

Definition at line 206 of file LockAnalysis.h.

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

◆ getIntraLockSet()

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

Definition at line 138 of file LockAnalysis.h.

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

◆ getLockVal()

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

Get lock value.

Definition at line 472 of file LockAnalysis.h.

473 {
474 return getTCG()->getThreadAPI()->getLockVal(call);
475 }
const SVFVar * getLockVal(const ICFGNode *inst) const
Return lock value.

◆ getNumOfCxtLocks()

u32_t SVF::LockAnalysis::getNumOfCxtLocks ( )
inline

Definition at line 314 of file LockAnalysis.h.

315 {
316 return cxtLockset.size();
317 }

◆ getSpanfromCxtLock()

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

Definition at line 260 of file LockAnalysis.h.

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

◆ getTCG()

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

ThreadCallGraph.

Definition at line 477 of file LockAnalysis.h.

478 {
479 return tct->getThreadCallGraph();
480 }

◆ getTCT()

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

Get tct.

Definition at line 322 of file LockAnalysis.h.

323 {
324 return tct;
325 }

◆ handleCall()

void LockAnalysis::handleCall ( const CxtStmt cts)
private

Handle call.

Definition at line 430 of file LockAnalysis.cpp.

431{
432
433 const CallStrCxt& curCxt = cts.getContext();
434 const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(cts.getStmt());
435 if (getTCG()->hasCallGraphEdge(call))
436 {
437 for (CallGraph::CallGraphEdgeSet::const_iterator cgIt = getTCG()->getCallEdgeBegin(call), ecgIt = getTCG()->getCallEdgeEnd(call);
438 cgIt != ecgIt; ++cgIt)
439 {
440 const FunObjVar* svfcallee = (*cgIt)->getDstNode()->getFunction();
442 continue;
444 pushCxt(newCxt, call, svfcallee);
445 const ICFGNode* svfInst = svfcallee->getEntryBlock()->front();
448 }
449 }
450}
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
void markCxtStmtFlag(const CxtStmt &tgr, const CxtStmt &src)
Mark thread flags for cxtStmt.
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Context helper functions.
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:437

◆ handleCallRelation()

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

Handle call relations.

Handling call relations when collecting context-sensitive locks

Definition at line 310 of file LockAnalysis.cpp.

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

◆ handleFork()

void LockAnalysis::handleFork ( const CxtStmt cts)
private

Handle fork.

Definition at line 409 of file LockAnalysis.cpp.

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

◆ handleIntra()

void LockAnalysis::handleIntra ( const CxtStmt cts)
private

Handle intra.

Definition at line 526 of file LockAnalysis.cpp.

527{
528
529 const ICFGNode* curInst = cts.getStmt();
530 const CallStrCxt& curCxt = cts.getContext();
531
532 for(const ICFGEdge* outEdge : curInst->getOutEdges())
533 {
534 if(outEdge->getDstNode()->getFun() == curInst->getFun())
535 {
536 CxtStmt newCts(curCxt, outEdge->getDstNode());
538 }
539 }
540}

◆ handleRet()

void LockAnalysis::handleRet ( const CxtStmt cts)
private

Handle return.

Definition at line 453 of file LockAnalysis.cpp.

454{
455
456 const ICFGNode* curInst = cts.getStmt();
457 const CallStrCxt& curCxt = cts.getContext();
458 const FunObjVar* svffun = curInst->getFun();
460
461 for (CallGraphNode::const_iterator it = curFunNode->getInEdges().begin(), eit = curFunNode->getInEdges().end(); it != eit; ++it)
462 {
464 if (SVFUtil::isa<ThreadForkEdge, ThreadJoinEdge>(edge))
465 continue;
466 for (CallGraphEdge::CallInstSet::const_iterator cit = (edge)->directCallsBegin(), ecit = (edge)->directCallsEnd(); cit != ecit;
467 ++cit)
468 {
470 const ICFGNode* inst = *cit;
471 if (matchCxt(newCxt, SVFUtil::cast<CallICFGNode>(inst), curFunNode->getFunction()))
472 {
473 for(const ICFGEdge* outEdge : curInst->getOutEdges())
474 {
475 if(outEdge->getDstNode()->getFun() == inst->getFun())
476 {
477 // Iterate over callSite's call string context and use as the successor's context
478 if (!hasCxtStmtFromInst(*cit))
479 continue;
480 for (const CxtStmt& cxtStmt: getCxtStmtsFromInst(*cit))
481 {
482 CallStrCxt callSiteCxt = cxtStmt.getContext();
483 // If new context is a suffix of the call site context
485 {
486 CxtStmt newCts(callSiteCxt, outEdge->getDstNode());
488 }
489 }
490 }
491 }
492 }
493 }
494 for (CallGraphEdge::CallInstSet::const_iterator cit = (edge)->indirectCallsBegin(), ecit = (edge)->indirectCallsEnd();
495 cit != ecit; ++cit)
496 {
498 const ICFGNode* inst = *cit;
499 if (matchCxt(newCxt, SVFUtil::cast<CallICFGNode>(inst), curFunNode->getFunction()))
500 {
501 for(const ICFGEdge* outEdge : curInst->getOutEdges())
502 {
503 if(outEdge->getDstNode()->getFun() == inst->getFun())
504 {
505 // Iterate over callSite's call string context and use as the successor's context
506 if (!hasCxtStmtFromInst(*cit))
507 continue;
508 for (const CxtStmt& cxtStmt: getCxtStmtsFromInst(*cit))
509 {
510 CallStrCxt callSiteCxt = cxtStmt.getContext();
511 // If new context is a suffix of the call site context
513 {
514 CxtStmt newCts(callSiteCxt, outEdge->getDstNode());
516 }
517 }
518 }
519 }
520 }
521 }
522 }
523}
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:74
bool hasCxtStmtFromInst(const ICFGNode *inst) const
Context-sensitive statement and lock spans.
bool isContextSuffix(const CallStrCxt &lhs, const CallStrCxt &call)
If lhs is a suffix of rhs, including equal.
bool matchCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Match context.
const CxtStmtSet & getCxtStmtsFromInst(const ICFGNode *inst) const

◆ hasAllCxtInLockSpan()

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

Definition at line 285 of file LockAnalysis.h.

286 {
287 if(!hasCxtStmtFromInst(I))
288 return false;
290 for (LockSpan::const_iterator cts = ctsset.begin(), ects = ctsset.end(); cts != ects; cts++)
291 {
292 if (lspan.find(*cts) == lspan.end())
293 {
294 return false;
295 }
296 }
297 return true;
298 }
Set< CxtStmt > LockSpan

◆ hasCxtLock()

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

Get context-sensitive lock.

Definition at line 157 of file LockAnalysis.h.

158 {
159 return cxtLockset.find(cxtLock)!=cxtLockset.end();
160 }

◆ hasCxtLockfromCxtStmt()

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

Definition at line 212 of file LockAnalysis.h.

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

◆ hasCxtStmtFromInst()

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

Context-sensitive statement and lock spans.

Get LockSet and LockSpan

Definition at line 201 of file LockAnalysis.h.

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

◆ 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 270 of file LockAnalysis.h.

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

◆ hasSpanfromCxtLock()

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

Definition at line 256 of file LockAnalysis.h.

257 {
258 return cxtLocktoSpan.find(cl) != cxtLocktoSpan.end();
259 }

◆ intersect()

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

Definition at line 373 of file LockAnalysis.h.

374 {
376 for(CxtLockSet::const_iterator it = tgrlockset.begin(), eit = tgrlockset.end(); it!=eit; ++it)
377 {
378 if(srclockset.find(*it)==srclockset.end())
379 toBeDeleted.insert(*it);
380 }
381 for(CxtLockSet::const_iterator it = toBeDeleted.begin(), eit = toBeDeleted.end(); it!=eit; ++it)
382 {
383 tgrlockset.erase(*it);
384 }
385 return !toBeDeleted.empty();
386 }
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 163 of file LockAnalysis.h.

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

◆ intraBackwardTraverse()

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

Intra-procedural backward traversal

Definition at line 217 of file LockAnalysis.cpp.

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

◆ intraForwardTraverse()

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

Intra-procedural forward traversal

Definition at line 173 of file LockAnalysis.cpp.

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

◆ 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 343 of file LockAnalysis.h.

344 {
345 return isAliasedLocks(cl1.getStmt(), cl2.getStmt());
346 }

◆ isAliasedLocks() [2/2]

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

todo: must alias

Definition at line 347 of file LockAnalysis.h.

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

◆ isCallSite()

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

Whether it is a callsite.

Definition at line 462 of file LockAnalysis.h.

463 {
464 return tct->isCallSite(inst);
465 }
bool isCallSite(const ICFGNode *inst)
Whether it is a callsite.
Definition TCT.h:265

◆ isContextSuffix()

bool LockAnalysis::isContextSuffix ( const CallStrCxt lhs,
const CallStrCxt call 
)
private

If lhs is a suffix of rhs, including equal.

Definition at line 571 of file LockAnalysis.cpp.

572{
573 return tct->isContextSuffix(lhs,call);
574}
bool isContextSuffix(const CallStrCxt &lhs, const CallStrCxt &call)
If lhs is a suffix of rhs, including equal.
Definition TCT.cpp:497

◆ isExtCall()

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

Whether it is calling an external function.

Definition at line 467 of file LockAnalysis.h.

468 {
469 return tct->isExtCall(inst);
470 }
bool isExtCall(const ICFGNode *inst)
Whether it is calling an external function.
Definition TCT.h:258

◆ 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 673 of file LockAnalysis.cpp.

674{
676 {
679 for (InstSet::const_iterator cil1 = lockset1.begin(), ecil1 = lockset1.end(); cil1!=ecil1; ++cil1)
680 {
681 for (InstSet::const_iterator cil2=lockset2.begin(), ecil2=lockset2.end(); cil2!=ecil2; ++cil2)
682 {
683 if (*cil1==*cil2)
684 return true;
685 }
686 }
687 }
688 return false;
689}
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 694 of file LockAnalysis.cpp.

695{
697 return true;
701}
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 705 of file LockAnalysis.cpp.

706{
708 return false;
711
712 for (CxtStmtSet::const_iterator cts1 = ctsset1.begin(), ects1 = ctsset1.end(); cts1 != ects1; cts1++)
713 {
714 const CxtStmt& cxtStmt1 = *cts1;
715 for (CxtStmtSet::const_iterator cts2 = ctsset2.begin(), ects2 = ctsset2.end(); cts2 != ects2; cts2++)
716 {
717 const CxtStmt& cxtStmt2 = *cts2;
718 if(cxtStmt1==cxtStmt2) continue;
720 return false;
721 }
722 }
723 return true;
724}
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 655 of file LockAnalysis.cpp.

656{
657 DOTIMESTAT(double queryStart = PTAStat::getClk(true));
658
659 bool sameSpan = false;
662 else
664
665 DOTIMESTAT(double queryEnd = PTAStat::getClk(true));
667 return sameSpan;
668}
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 133 of file LockAnalysis.h.

134 {
136 }

◆ isInsideIntraLock()

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

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

Definition at line 127 of file LockAnalysis.h.

128 {
130 }

◆ 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 101 of file LockAnalysis.h.

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

◆ isLockCandidateFun()

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

Return true if it is a candidate function.

Definition at line 193 of file LockAnalysis.h.

194 {
195 return lockcandidateFuncSet.find(fun)!=lockcandidateFuncSet.end();
196 }

◆ isProtectedByCommonCILock()

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

Protected by at least one common context-insensitive lock

Definition at line 597 of file LockAnalysis.cpp.

598{
599
601 {
604 for (InstSet::const_iterator cil1 = lockset1.begin(), ecil1 = lockset1.end(); cil1!=ecil1; ++cil1)
605 {
606 for (InstSet::const_iterator cil2=lockset2.begin(), ecil2=lockset2.end(); cil2!=ecil2; ++cil2)
607 {
608 if (isAliasedLocks(*cil1, *cil2))
609 return true;
610 }
611 }
612 }
613 return false;
614}

◆ isProtectedByCommonCxtLock() [1/2]

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

Protected by at least one common context-sensitive lock

Definition at line 619 of file LockAnalysis.cpp.

620{
622 return true;
625 return alias(lockset1,lockset2);
626}
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 631 of file LockAnalysis.cpp.

632{
634 return false;
637 for (CxtStmtSet::const_iterator cts1 = ctsset1.begin(), ects1 = ctsset1.end(); cts1 != ects1; cts1++)
638 {
639 const CxtStmt& cxtStmt1 = *cts1;
640 for (CxtStmtSet::const_iterator cts2 = ctsset2.begin(), ects2 = ctsset2.end(); cts2 != ects2; cts2++)
641 {
642 const CxtStmt& cxtStmt2 = *cts2;
643 if(cxtStmt1==cxtStmt2) continue;
645 return false;
646 }
647 }
648 return true;
649}
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 580 of file LockAnalysis.cpp.

581{
583 bool commonlock = false;
584 DOTIMESTAT(double queryStart = PTAStat::getClk(true));
587 else
589 DOTIMESTAT(double queryEnd = PTAStat::getClk(true));
591 return commonlock;
592}
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 448 of file LockAnalysis.h.

449 {
450 if(SVFUtil::isa<CallICFGNode>(call) == false)
451 return false;
452 return getTCG()->getThreadAPI()->isTDAcquire(SVFUtil::cast<CallICFGNode>(call));
453 }

◆ isTDFork()

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

Whether it is a lock site.

Definition at line 441 of file LockAnalysis.h.

442 {
443 if(SVFUtil::isa<CallICFGNode>(call) == false)
444 return false;
445 return getTCG()->getThreadAPI()->isTDFork(SVFUtil::cast<CallICFGNode>(call));
446 }
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 455 of file LockAnalysis.h.

456 {
457 if(SVFUtil::isa<CallICFGNode>(call) == false)
458 return false;
459 return getTCG()->getThreadAPI()->isTDRelease(SVFUtil::cast<CallICFGNode>(call));
460 }

◆ isVisitedCTPs()

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

Definition at line 411 of file LockAnalysis.h.

412 {
413 return visitedCTPs.find(clp) != visitedCTPs.end();
414 }
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 356 of file LockAnalysis.h.

357 {
359 if(hasCxtLockfromCxtStmt(tgr)== false)
360 {
361 for(CxtLockSet::const_iterator it = srclockset.begin(), eit = srclockset.end(); it!=eit; ++it)
362 {
364 }
366 }
367 else
368 {
371 }
372 }
bool intersect(CxtLockSet &tgrlockset, const CxtLockSet &srclockset)

◆ matchCxt()

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

Match context.

partial match

Definition at line 547 of file LockAnalysis.cpp.

548{
549 const FunObjVar* svfcaller = call->getFun();
550 CallSiteID csId = getTCG()->getCallSiteID(call, callee);
551
552// /// handle calling context for candidate functions only
553// if (isLockCandidateFun(caller) == false)
554// return true;
555
557 if (cxt.empty())
558 return true;
559
560 if (tct->inSameCallGraphSCC(getTCG()->getCallGraphNode(svfcaller), getTCG()->getCallGraphNode(callee)) == false)
561 {
562 if (cxt.back() == csId)
563 cxt.pop_back();
564 else
565 return false;
566 DBOUT(DMTA, tct->dumpCxt(cxt));
567 }
568 return true;
569}
CallSiteID getCallSiteID(const CallICFGNode *cs, const FunObjVar *callee) const
Get CallSiteID.
Definition CallGraph.h:377
bool inSameCallGraphSCC(const CallGraphNode *src, const CallGraphNode *dst)
Whether two functions in the same callgraph scc.
Definition TCT.h:300
void dumpCxt(CallStrCxt &cxt)
Dump calling context.
Definition TCT.cpp:517
unsigned CallSiteID
Definition GeneralType.h:58

◆ popFromCTPWorkList()

CxtLockProc SVF::LockAnalysis::popFromCTPWorkList ( )
inlineprivate

Definition at line 406 of file LockAnalysis.h.

407 {
409 return clp;
410 }

◆ popFromCTSWorkList()

CxtStmt SVF::LockAnalysis::popFromCTSWorkList ( )
inlineprivate

Definition at line 423 of file LockAnalysis.h.

424 {
425 CxtStmt clp = cxtStmtList.pop();
426 return clp;
427 }

◆ printLocks()

void LockAnalysis::printLocks ( const CxtStmt cts)

Print locks and spans.

Print context-insensitive and context-sensitive locks

Definition at line 396 of file LockAnalysis.cpp.

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

◆ pushCxt()

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

Context helper functions.

Push calling context

Definition at line 542 of file LockAnalysis.cpp.

543{
544 tct->pushCxt(cxt,call,callee);
545}
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Context helper functions.
Definition TCT.cpp:449

◆ pushToCTPWorkList()

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

WorkList helper functions.

Definition at line 397 of file LockAnalysis.h.

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

◆ pushToCTSWorkList()

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

Worklist operations.

Definition at line 419 of file LockAnalysis.h.

420 {
421 return cxtStmtList.push(cs);
422 }

◆ removeCxtStmtToSpan()

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

Add context-sensitive statement.

Definition at line 236 of file LockAnalysis.h.

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

◆ touchCxtStmt()

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

Touch this context statement.

Definition at line 252 of file LockAnalysis.h.

253 {
255 }

Member Data Documentation

◆ ciLocktoSpan

CILockToSpan SVF::LockAnalysis::ciLocktoSpan
private

Used for context-insensitive intra-procedural locks.

Definition at line 521 of file LockAnalysis.h.

◆ clpList

CxtLockProcVec SVF::LockAnalysis::clpList
private

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

Definition at line 504 of file LockAnalysis.h.

◆ cxtLockset

CxtLockSet SVF::LockAnalysis::cxtLockset
private

Context-sensitive locks.

Definition at line 493 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 498 of file LockAnalysis.h.

◆ cxtStmtList

CxtStmtWorkList SVF::LockAnalysis::cxtStmtList
private

context-sensitive statement worklist

Definition at line 486 of file LockAnalysis.h.

◆ cxtStmtToCxtLockSet

CxtStmtToCxtLockSet SVF::LockAnalysis::cxtStmtToCxtLockSet
private

Definition at line 499 of file LockAnalysis.h.

◆ instCILocksMap

InstToInstSetMap SVF::LockAnalysis::instCILocksMap
private

Definition at line 522 of file LockAnalysis.h.

◆ instTocondCILocksMap

InstToInstSetMap SVF::LockAnalysis::instTocondCILocksMap
private

Definition at line 523 of file LockAnalysis.h.

◆ instToCxtStmtSet

InstToCxtStmtSet SVF::LockAnalysis::instToCxtStmtSet
private

Map a statement to all its context-sensitive statements.

Definition at line 489 of file LockAnalysis.h.

◆ lockcandidateFuncSet

FunSet SVF::LockAnalysis::lockcandidateFuncSet
private

Candidate functions which relevant to locks/unlocks.

Definition at line 516 of file LockAnalysis.h.

◆ lockQueriesTime

double SVF::LockAnalysis::lockQueriesTime

Definition at line 531 of file LockAnalysis.h.

◆ locksites

InstSet SVF::LockAnalysis::locksites
private

Record all visited clps.

Collecting lock/unlock sites

Definition at line 510 of file LockAnalysis.h.

◆ lockTime

double SVF::LockAnalysis::lockTime

Definition at line 528 of file LockAnalysis.h.

◆ numOfLockedQueries

u32_t SVF::LockAnalysis::numOfLockedQueries

Definition at line 530 of file LockAnalysis.h.

◆ numOfTotalQueries

u32_t SVF::LockAnalysis::numOfTotalQueries

Definition at line 529 of file LockAnalysis.h.

◆ tct

TCT* SVF::LockAnalysis::tct
private

TCT.

Definition at line 483 of file LockAnalysis.h.

◆ unlocksites

InstSet SVF::LockAnalysis::unlocksites
private

Definition at line 511 of file LockAnalysis.h.

◆ visitedCTPs

CxtLockProcSet SVF::LockAnalysis::visitedCTPs
private

CxtLockProc List.

Definition at line 505 of file LockAnalysis.h.


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