Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected 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)
 
 ~LockAnalysis ()=default
 
template<class ICFGGraph , class CGGraph >
void analyze (ICFGGraph icfg, CGGraph cg)
 
template<class ICFGGraph , class CGGraph >
void analyzeIntraProcedualLock (ICFGGraph icfg, CGGraph cg)
 
template<class ICFGGraph , class CGGraph >
bool intraForwardTraverse (ICFGGraph icfg, CGGraph cg, const ICFGNode *lock, InstSet &unlockset, InstSet &forwardInsts)
 
template<class ICFGGraph , class CGGraph >
bool intraBackwardTraverse (ICFGGraph icfg, CGGraph cg, const InstSet &unlockset, InstSet &backwardInsts)
 
template<class ICFGGraph , class CGGraph >
void collectCxtLock (ICFGGraph icfg, CGGraph cg)
 
template<class ICFGGraph , class CGGraph >
void analyzeLockSpanCxtStmt (ICFGGraph icfg, CGGraph cg)
 
template<class ICFGGraph , class CGGraph >
void collectLockUnlocksites (ICFGGraph icfg, CGGraph cg)
 
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)
 
bool hasIntraLockSet (const ICFGNode *stmt) const
 
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
 

Protected Member Functions

template<class ICFGGraph , class CGGraph >
void handleFork (ICFGGraph icfg, CGGraph cg, const CxtStmt &cts)
 Handle fork.
 
template<class ICFGGraph , class CGGraph >
void handleCall (ICFGGraph icfg, CGGraph cg, const CxtStmt &cts)
 Handle call.
 
template<class ICFGGraph , class CGGraph >
void handleRet (ICFGGraph icfg, CGGraph cg, const CxtStmt &cts)
 Handle return.
 
template<class ICFGGraph , class CGGraph >
void handleIntra (ICFGGraph icfg, CGGraph cg, const CxtStmt &cts)
 Handle intra.
 
template<class ICFGGraph , class CGGraph >
void handleCallRelation (ICFGGraph icfg, CGGraph cg, 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.
 

Protected 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 55 of file LockAnalysis.h.

Member Typedef Documentation

◆ CILockToSpan

Definition at line 74 of file LockAnalysis.h.

◆ CISpan

Definition at line 73 of file LockAnalysis.h.

◆ CxtLock

Definition at line 67 of file LockAnalysis.h.

◆ CxtLockProc

Definition at line 68 of file LockAnalysis.h.

◆ CxtLockProcSet

Definition at line 89 of file LockAnalysis.h.

◆ CxtLockProcVec

Definition at line 88 of file LockAnalysis.h.

◆ CxtLockSet

Definition at line 81 of file LockAnalysis.h.

◆ CxtLockToLockSet

Definition at line 84 of file LockAnalysis.h.

◆ CxtLockToSpan

Definition at line 83 of file LockAnalysis.h.

◆ CxtStmtSet

Definition at line 80 of file LockAnalysis.h.

◆ CxtStmtToCxtLockSet

Definition at line 87 of file LockAnalysis.h.

◆ CxtStmtToLockFlagMap

Definition at line 77 of file LockAnalysis.h.

◆ CxtStmtWorkList

Definition at line 78 of file LockAnalysis.h.

◆ FunSet

Definition at line 75 of file LockAnalysis.h.

◆ InstSet

Definition at line 72 of file LockAnalysis.h.

◆ InstToCxtStmtSet

Definition at line 86 of file LockAnalysis.h.

◆ InstToInstSetMap

Definition at line 76 of file LockAnalysis.h.

◆ InstVec

Definition at line 71 of file LockAnalysis.h.

◆ LockSet

Definition at line 70 of file LockAnalysis.h.

◆ LockSiteToLockSet

Definition at line 85 of file LockAnalysis.h.

◆ LockSpan

Definition at line 79 of file LockAnalysis.h.

Member Enumeration Documentation

◆ ValDomain

semilattice Empty==>TDUnlocked==>TDLocked

Enumerator
Empty 
TDLocked 
TDUnlocked 

Definition at line 60 of file LockAnalysis.h.

61 {
62 Empty, // initial(dummy) state
63 TDLocked, // stmt is locked
64 TDUnlocked, // stmt is unlocked
65 };

Constructor & Destructor Documentation

◆ LockAnalysis()

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

Definition at line 91 of file LockAnalysis.h.

◆ ~LockAnalysis()

SVF::LockAnalysis::~LockAnalysis ( )
default

Member Function Documentation

◆ addCondIntraLock()

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

Add intra-procedural lock.

Definition at line 134 of file LockAnalysis.h.

135 {
136 for(InstSet::const_iterator it = stmts.begin(), eit = stmts.end(); it!=eit; ++it)
137 {
138 instTocondCILocksMap[*it].insert(lockSite);
139 }
140 }
InstToInstSetMap instTocondCILocksMap
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ addCxtLock()

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

Context-sensitive locks.

Add inter-procedural context-sensitive lock

Definition at line 173 of file LockAnalysis.h.

174 {
175 CxtLock cxtlock(cxt,inst);
176 cxtLockset.insert(cxtlock);
177 DBOUT(DMTA, SVFUtil::outs() << "LockAnalysis Process new lock "; cxtlock.dump());
178 }
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:576
#define DMTA
Definition SVFType.h:597
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 254 of file LockAnalysis.h.

255 {
256 cxtLocktoSpan[cl].insert(cts);
257 return cxtStmtToCxtLockSet[cts].insert(cl).second;
258 }
CxtLockToSpan cxtLocktoSpan
CxtStmtToCxtLockSet cxtStmtToCxtLockSet

◆ addIntraLock()

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

Add intra-procedural lock.

Definition at line 124 of file LockAnalysis.h.

125 {
126 for(InstSet::const_iterator it = stmts.begin(), eit = stmts.end(); it!=eit; ++it)
127 {
128 instCILocksMap[*it].insert(lockSite);
129 ciLocktoSpan[lockSite].insert(*it);
130 }
131 }
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 201 of file LockAnalysis.h.

202 {
203 for(CxtLockSet::const_iterator it = lockset1.begin(), eit = lockset1.end(); it!=eit; ++it)
204 {
205 const CxtLock& lock = *it;
206 for(CxtLockSet::const_iterator lit = lockset2.begin(), elit = lockset2.end(); lit!=elit; ++lit)
207 {
209 return true;
210 }
211 }
212 return false;
213 }
bool isAliasedLocks(const CxtLock &cl1, const CxtLock &cl2)
Return true it a lock matches an unlock.

◆ analyze()

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

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. One implementation for the whole program and a slice: GraphT is SVFIR* (whole) or const SlicedSVFIRView* (sliced). Per-graph queries resolve at compile time via the graph* overloads in Graphs/SlicedGraphs.h.

Definition at line 52 of file LockAnalysis.cpp.

53{
54
57
58 DOTIMESTAT(double lockStart = PTAStat::getClk(true));
59
60 DBOUT(DGENERAL, outs() << "\tIntra-procedural LockAnalysis\n");
61 DBOUT(DMTA, outs() << "\tIntra-procedural LockAnalysis\n");
63
64 DBOUT(DGENERAL, outs() << "\tCollect context-sensitive locks\n");
65 DBOUT(DMTA, outs() << "\tCollect context-sensitive locks\n");
66 collectCxtLock(icfg, cg);
67
68 DBOUT(DGENERAL, outs() << "\tInter-procedural LockAnalysis\n");
69 DBOUT(DMTA, outs() << "\tInter-procedural LockAnalysis\n");
71
72 DOTIMESTAT(double lockEnd = PTAStat::getClk(true));
74}
#define TIMEINTERVAL
Definition SVFType.h:604
#define DGENERAL
Definition SVFType.h:582
#define DOTIMESTAT(X)
Definition SVFType.h:578
void buildCandidateFuncSetforLock()
void collectLockUnlocksites(ICFGGraph icfg, CGGraph cg)
void analyzeLockSpanCxtStmt(ICFGGraph icfg, CGGraph cg)
void analyzeIntraProcedualLock(ICFGGraph icfg, CGGraph cg)
void collectCxtLock(ICFGGraph icfg, CGGraph cg)
static double getClk(bool mark=false)
Definition SVFStat.cpp:51

◆ analyzeIntraProcedualLock()

template<class ICFGGraph , class CGGraph >
void LockAnalysis::analyzeIntraProcedualLock ( ICFGGraph  icfg,
CGGraph  cg 
)

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

161{
162
163 // Identify the protected Instructions.
164 for (InstSet::const_iterator it = locksites.begin(), ie = locksites.end(); it != ie; ++it)
165 {
166 const ICFGNode* lockSite = *it;
167 assert(isCallSite(lockSite) && "Lock acquire instruction must be a CallSite");
168
169 // Perform forward traversal
173
176
178 if(forward && backward)
180 else if(forward && !backward)
182 }
183}
bool intraBackwardTraverse(ICFGGraph icfg, CGGraph cg, const InstSet &unlockset, InstSet &backwardInsts)
bool intraForwardTraverse(ICFGGraph icfg, CGGraph cg, const ICFGNode *lock, InstSet &unlockset, InstSet &forwardInsts)
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 isCallSite(const ICFGNode *inst)
Whether it is a callsite.

◆ analyzeLockSpanCxtStmt()

template<class ICFGGraph , class CGGraph >
void LockAnalysis::analyzeLockSpanCxtStmt ( ICFGGraph  icfg,
CGGraph  cg 
)

Definition at line 364 of file LockAnalysis.cpp.

365{
366
367 const TCT::FunSet& entryFuncSet = tct->getEntryProcs();
368 for (TCT::FunSet::const_iterator it = entryFuncSet.begin(), eit = entryFuncSet.end(); it != eit; ++it)
369 {
370 if (!isLockCandidateFun(*it))
371 continue;
372 CallStrCxt cxt;
375 continue;
378 }
379
380 while (!cxtStmtList.empty())
381 {
383
385 const ICFGNode* curInst = cts.getStmt();
387 continue;
389
390 DBOUT(DMTA, outs() << "\nVisit cxtStmt: ");
391 DBOUT(DMTA, cts.dump());
392
393 DBOUT(DMTA, outs() << "\nIts cxt lock sets: ");
395
396 if (isTDFork(curInst))
397 {
398 handleFork(icfg, cg, cts);
399 }
400 else if (isTDAcquire(curInst))
401 {
402 assert(hasCxtLock(cts) && "context-sensitive lock not found!!");
404 handleIntra(icfg, cg, cts);
405 }
406 else if (isTDRelease(curInst))
407 {
409 handleIntra(icfg, cg, cts);
410 }
411 else if (isCallSite(curInst) && !isExtCall(curInst))
412 {
413 handleCall(icfg, cg, cts);
414 }
415 else if (SVFUtil::dyn_cast<FunExitICFGNode>(curInst))
416 {
417 handleRet(icfg, cg, cts);
418 }
419 else
420 {
421 handleIntra(icfg, cg, cts);
422 }
423
424 }
425
426}
bool empty() const
Definition WorkList.h:161
bool removeCxtStmtToSpan(CxtStmt &cts, const CxtLock &cl)
Add context-sensitive statement.
CxtStmtWorkList cxtStmtList
context-sensitive statement worklist
void handleIntra(ICFGGraph icfg, CGGraph cg, const CxtStmt &cts)
Handle intra.
bool isExtCall(const ICFGNode *inst)
Whether it is calling an external function.
void handleFork(ICFGGraph icfg, CGGraph cg, const CxtStmt &cts)
Handle fork.
CxtStmt popFromCTSWorkList()
bool hasCxtLock(const CxtLock &cxtLock) const
Get context-sensitive lock.
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 handleRet(ICFGGraph icfg, CGGraph cg, const CxtStmt &cts)
Handle return.
void handleCall(ICFGGraph icfg, CGGraph cg, 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.
InstToCxtStmtSet instToCxtStmtSet
Map a statement to all its context-sensitive statements.
bool isTDAcquire(const ICFGNode *call)
Whether it is a lock site.
OrderedSet< const FunObjVar *, FunObjVarIdCmp > FunSet
Definition TCT.h:172
const FunSet & getEntryProcs() const
Get marked candidate functions.
Definition TCT.h:239
std::vector< u32_t > CallStrCxt
Definition GeneralType.h:96

◆ buildCandidateFuncSetforLock()

void LockAnalysis::buildCandidateFuncSetforLock ( )

Collect candidate functions for context-sensitive lock analysis

Definition at line 111 of file LockAnalysis.cpp.

112{
113
115
116 TCT::PTACGNodeSet visited;
118
119 for (InstSet::iterator it = locksites.begin(), eit = locksites.end(); it != eit; ++it)
120 {
121 const FunObjVar* fun=(*it)->getFun();
123 if (visited.find(cgnode) == visited.end())
124 {
125 worklist.push(cgnode);
126 visited.insert(cgnode);
127 }
128 }
129 for (InstSet::iterator it = unlocksites.begin(), eit = unlocksites.end(); it != eit; ++it)
130 {
131 const FunObjVar* fun = (*it)->getFun();
133 if (visited.find(cgnode) == visited.end())
134 {
135 worklist.push(cgnode);
136 visited.insert(cgnode);
137 }
138 }
139 while (!worklist.empty())
140 {
141 const CallGraphNode* node = worklist.pop();
142 lockcandidateFuncSet.insert(node->getFunction());
143 for (CallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit != neit; nit++)
144 {
145 const CallGraphNode* srcNode = (*nit)->getSrcNode();
146 if (visited.find(srcNode) == visited.end())
147 {
148 visited.insert(srcNode);
149 worklist.push(srcNode);
150 }
151 }
152 }
153}
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:180
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:175
ThreadCallGraph * getThreadCallGraph() const
Get TCG.
Definition TCT.h:193

◆ clearFlagMap()

void SVF::LockAnalysis::clearFlagMap ( )
inlineprotected

Clear flags.

Definition at line 406 of file LockAnalysis.h.

407 {
409 }

◆ collectCxtLock()

template<class ICFGGraph , class CGGraph >
void LockAnalysis::collectCxtLock ( ICFGGraph  icfg,
CGGraph  cg 
)

Definition at line 283 of file LockAnalysis.cpp.

284{
285 const TCT::FunSet& entryFuncSet = tct->getEntryProcs();
286 for (TCT::FunSet::const_iterator it = entryFuncSet.begin(), eit = entryFuncSet.end(); it != eit; ++it)
287 {
288 if (!isLockCandidateFun(*it))
289 continue;
290 CallStrCxt cxt;
291 CxtLockProc t(cxt, *it);
293 }
294
295 while (!clpList.empty())
296 {
298 CallGraphNode* cgNode = getTCG()->getCallGraphNode(clp.getProc());
299 // lzh TODO.
300 if (!isLockCandidateFun(cgNode->getFunction()))
301 continue;
302
303 for (CallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit != neit; nit++)
304 {
305 const CallGraphEdge* cgEdge = (*nit);
306
307 for (CallGraphEdge::CallInstSet::const_iterator cit = cgEdge->directCallsBegin(), ecit = cgEdge->directCallsEnd();
308 cit != ecit; ++cit)
309 {
310 DBOUT(DMTA,
311 outs() << "\nCollecting CxtLocks: handling direct call:" << **cit << "\t" << cgEdge->getSrcNode()->getFunction()->getName()
312 << "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
314 }
315 for (CallGraphEdge::CallInstSet::const_iterator ind = cgEdge->indirectCallsBegin(), eind = cgEdge->indirectCallsEnd();
316 ind != eind; ++ind)
317 {
318 DBOUT(DMTA,
319 outs() << "\nCollecting CxtLocks: handling indirect call:" << **ind << "\t"
320 << cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName()
321 << "\n");
323 }
324 }
325 }
326}
iterator OutEdgeEnd()
iterator OutEdgeBegin()
iterators
ThreadCallGraph * getTCG() const
ThreadCallGraph.
bool pushToCTPWorkList(const CxtLockProc &clp)
WorkList helper functions.
CxtLockProc popFromCTPWorkList()
void handleCallRelation(ICFGGraph icfg, CGGraph cg, CxtLockProc &clp, const CallGraphEdge *cgEdge, const CallICFGNode *call)
Handle call relations.
CxtLockProcVec clpList
Following data structures are used for collecting context-sensitive locks.

◆ collectLockUnlocksites()

template<class ICFGGraph , class CGGraph >
void LockAnalysis::collectLockUnlocksites ( ICFGGraph  icfg,
CGGraph  cg 
)

Collect lock/unlock sites

Definition at line 81 of file LockAnalysis.cpp.

82{
84
85 for (const auto& item : *GenericGraphTraits<CGGraph>::getCallGraph(cg))
86 {
87 const FunObjVar* F = item.second->getFunction();
88 for (auto it : *F)
89 {
90 const SVFBasicBlock* bb = it.second;
91 for (const ICFGNode* icfgNode : bb->getICFGNodeList())
92 {
94 continue;
95 if (isa<CallICFGNode>(icfgNode) && tcg->getThreadAPI()->isTDRelease(cast<CallICFGNode>(icfgNode)))
96 {
97 unlocksites.insert(icfgNode);
98 }
99 if (isa<CallICFGNode>(icfgNode) && tcg->getThreadAPI()->isTDAcquire(cast<CallICFGNode>(icfgNode)))
100 {
101 locksites.insert(icfgNode);
102 }
103 }
104 }
105 }
106}
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 271 of file LockAnalysis.h.

272 {
273 return cxtStmtToCxtLockSet;
274 }

◆ getCxtLockfromCxtStmt() [1/2]

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

Definition at line 247 of file LockAnalysis.h.

248 {
249 CxtStmtToCxtLockSet::iterator it = cxtStmtToCxtLockSet.find(cts);
250 assert(it != cxtStmtToCxtLockSet.end());
251 return it->second;
252 }

◆ getCxtLockfromCxtStmt() [2/2]

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

Definition at line 241 of file LockAnalysis.h.

242 {
243 CxtStmtToCxtLockSet::const_iterator it = cxtStmtToCxtLockSet.find(cts);
244 assert(it != cxtStmtToCxtLockSet.end());
245 return it->second;
246 }

◆ getCxtStmtsFromInst()

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

Definition at line 230 of file LockAnalysis.h.

231 {
232 InstToCxtStmtSet::const_iterator it = instToCxtStmtSet.find(inst);
233 assert(it != instToCxtStmtSet.end());
234 return it->second;
235 }

◆ getIntraLockSet()

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

Definition at line 162 of file LockAnalysis.h.

163 {
164 InstToInstSetMap::const_iterator it = instCILocksMap.find(stmt);
165 assert(it!=instCILocksMap.end() && "intralock not found!");
166 return it->second;
167 }

◆ getLockVal()

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

Get lock value.

Definition at line 489 of file LockAnalysis.h.

490 {
491 return getTCG()->getThreadAPI()->getLockVal(call);
492 }
const SVFVar * getLockVal(const ICFGNode *inst) const
Return lock value.

◆ getNumOfCxtLocks()

u32_t SVF::LockAnalysis::getNumOfCxtLocks ( )
inline

Definition at line 335 of file LockAnalysis.h.

336 {
337 return cxtLockset.size();
338 }

◆ getSpanfromCxtLock()

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

Definition at line 284 of file LockAnalysis.h.

285 {
286 assert(cxtLocktoSpan.find(cl) != cxtLocktoSpan.end());
287 return cxtLocktoSpan[cl];
288 }

◆ getTCG()

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

ThreadCallGraph.

Definition at line 494 of file LockAnalysis.h.

495 {
496 return tct->getThreadCallGraph();
497 }

◆ getTCT()

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

Get tct.

Definition at line 343 of file LockAnalysis.h.

344 {
345 return tct;
346 }

◆ handleCall()

template<class ICFGGraph , class CGGraph >
void LockAnalysis::handleCall ( ICFGGraph  icfg,
CGGraph  cg,
const CxtStmt cts 
)
protected

Handle call.

Definition at line 470 of file LockAnalysis.cpp.

471{
472
473 const CallStrCxt& curCxt = cts.getContext();
474 const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(cts.getStmt());
475 if (getTCG()->hasCallGraphEdge(call))
476 {
477 for (CallGraph::CallGraphEdgeSet::const_iterator cgIt = getTCG()->getCallEdgeBegin(call), ecgIt = getTCG()->getCallEdgeEnd(call);
478 cgIt != ecgIt; ++cgIt)
479 {
480 const FunObjVar* svfcallee = (*cgIt)->getDstNode()->getFunction();
482 continue;
484 pushCxt(newCxt, call, svfcallee);
487 continue;
490
491 // Return-flow rendezvous (see MHP::handleCall): forward an already
492 // computed callee-exit lockset to this callsite's return site.
493 if (svfcallee->hasBasicBlock())
494 {
495 const ICFGNode* exitInst = svfcallee->getExitBB()->back();
498 {
499 const ICFGNode* retNode = call->getRetICFGNode();
501 {
504 }
505 }
506 }
507 }
508 }
509}
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition ICFGNode.h:440
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.
bool hasCxtLockfromCxtStmt(const CxtStmt &cts) const
void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Context helper functions.
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:441

◆ handleCallRelation()

template<class ICFGGraph , class CGGraph >
void LockAnalysis::handleCallRelation ( ICFGGraph  icfg,
CGGraph  cg,
CxtLockProc clp,
const CallGraphEdge cgEdge,
const CallICFGNode cs 
)
protected

Handle call relations.

Handling call relations when collecting context-sensitive locks

Definition at line 333 of file LockAnalysis.cpp.

334{
335
336 CallStrCxt cxt(clp.getContext());
337 const ICFGNode* curNode = cs;
339 return;
340 if (isTDAcquire(curNode))
341 {
342 addCxtLock(cxt,curNode);
343 return;
344 }
345 const FunObjVar* svfcallee = cgEdge->getDstNode()->getFunction();
346 pushCxt(cxt, SVFUtil::cast<CallICFGNode>(curNode), svfcallee);
347
350 {
351 DBOUT(DMTA, outs() << "LockAnalysis Process CallRet old clp --"; clp.dump());
352 DBOUT(DMTA, outs() << "LockAnalysis Process CallRet new clp --"; newclp.dump());
353 }
354
355}
void addCxtLock(const CallStrCxt &cxt, const ICFGNode *inst)
Context-sensitive locks.

◆ handleFork()

template<class ICFGGraph , class CGGraph >
void LockAnalysis::handleFork ( ICFGGraph  icfg,
CGGraph  cg,
const CxtStmt cts 
)
protected

Handle fork.

Definition at line 446 of file LockAnalysis.cpp.

447{
448 const CallStrCxt& curCxt = cts.getContext();
449 const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(cts.getStmt());
450 if(getTCG()->hasThreadForkEdge(call))
451 {
452 for (ThreadCallGraph::ForkEdgeSet::const_iterator cgIt = getTCG()->getForkEdgeBegin(call),
453 ecgIt = getTCG()->getForkEdgeEnd(call); cgIt != ecgIt; ++cgIt)
454 {
455 const FunObjVar* svfcallee = (*cgIt)->getDstNode()->getFunction();
460 continue;
463 }
464 }
465 handleIntra(icfg, cg, cts);
466}

◆ handleIntra()

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

Handle intra.

Definition at line 594 of file LockAnalysis.cpp.

595{
596
597 const ICFGNode* curInst = cts.getStmt();
598 const CallStrCxt& curCxt = cts.getContext();
599
600 std::vector<const ICFGNode*> succ;
602 for (const ICFGNode* dst : succ)
603 {
604 if(dst->getFun() == curInst->getFun())
605 {
606 CxtStmt newCts(curCxt, dst);
608 }
609 }
610}

◆ handleRet()

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

Handle return.

Definition at line 513 of file LockAnalysis.cpp.

514{
515
516 const ICFGNode* curInst = cts.getStmt();
517 const CallStrCxt& curCxt = cts.getContext();
518 const FunObjVar* svffun = curInst->getFun();
520
521 std::vector<const CallGraphEdge*> inEdges;
523 for (const CallGraphEdge* edgeConst : inEdges)
524 {
525 if (SVFUtil::isa<ThreadForkEdge, ThreadJoinEdge>(edgeConst))
526 continue;
527 // Need non-const for directCallsBegin/End
528 CallGraphEdge* edge = const_cast<CallGraphEdge*>(edgeConst);
529 for (CallGraphEdge::CallInstSet::const_iterator cit = (edge)->directCallsBegin(), ecit = (edge)->directCallsEnd(); cit != ecit;
530 ++cit)
531 {
533 const ICFGNode* inst = *cit;
534 if (matchCxt(newCxt, SVFUtil::cast<CallICFGNode>(inst), curFunNode->getFunction()))
535 {
536 std::vector<const ICFGNode*> succ;
538 for (const ICFGNode* dst : succ)
539 {
540 if(dst->getFun() == inst->getFun())
541 {
542 // Iterate over callSite's call string context and use as the successor's context
543 if (!hasCxtStmtFromInst(*cit))
544 continue;
545 for (const CxtStmt& cxtStmt: getCxtStmtsFromInst(*cit))
546 {
547 CallStrCxt callSiteCxt = cxtStmt.getContext();
548 // If new context is a suffix of the call site context
550 {
553 }
554 }
555 }
556 }
557 }
558 }
559 for (CallGraphEdge::CallInstSet::const_iterator cit = (edge)->indirectCallsBegin(), ecit = (edge)->indirectCallsEnd();
560 cit != ecit; ++cit)
561 {
563 const ICFGNode* inst = *cit;
564 if (matchCxt(newCxt, SVFUtil::cast<CallICFGNode>(inst), curFunNode->getFunction()))
565 {
566 std::vector<const ICFGNode*> succ;
568 for (const ICFGNode* dst : succ)
569 {
570 if(dst->getFun() == inst->getFun())
571 {
572 // Iterate over callSite's call string context and use as the successor's context
573 if (!hasCxtStmtFromInst(*cit))
574 continue;
575 for (const CxtStmt& cxtStmt: getCxtStmtsFromInst(*cit))
576 {
577 CallStrCxt callSiteCxt = cxtStmt.getContext();
578 // If new context is a suffix of the call site context
580 {
583 }
584 }
585 }
586 }
587 }
588 }
589 }
590}
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:75
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 307 of file LockAnalysis.h.

308 {
309 if(!hasCxtStmtFromInst(I))
310 return false;
312 for (LockSpan::const_iterator cts = ctsset.begin(), ects = ctsset.end(); cts != ects; cts++)
313 {
314 if (lspan.find(*cts) == lspan.end())
315 {
316 return false;
317 }
318 }
319 return true;
320 }
Set< CxtStmt > LockSpan

◆ hasCxtLock()

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

Get context-sensitive lock.

Definition at line 181 of file LockAnalysis.h.

182 {
183 return cxtLockset.find(cxtLock)!=cxtLockset.end();
184 }

◆ hasCxtLockfromCxtStmt()

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

Definition at line 236 of file LockAnalysis.h.

237 {
238 CxtStmtToCxtLockSet::const_iterator it = cxtStmtToCxtLockSet.find(cts);
239 return (it != cxtStmtToCxtLockSet.end());
240 }

◆ hasCxtStmtFromInst()

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

Context-sensitive statement and lock spans.

Get LockSet and LockSpan

Definition at line 225 of file LockAnalysis.h.

226 {
227 InstToCxtStmtSet::const_iterator it = instToCxtStmtSet.find(inst);
228 return (it != instToCxtStmtSet.end());
229 }

◆ hasIntraLockSet()

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

Whether a statement has an (unconditional) intra-procedural lock set, i.e. getIntraLockSet is valid for it. A statement can be locked (isInsideIntraLock) via a conditional intra lock or a context lock without being here.

Definition at line 157 of file LockAnalysis.h.

158 {
159 return instCILocksMap.find(stmt)!=instCILocksMap.end();
160 }

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

293 {
294 if(!hasCxtStmtFromInst(I))
295 return false;
297 for (LockSpan::const_iterator cts = ctsset.begin(), ects = ctsset.end(); cts != ects; cts++)
298 {
299 if(lspan.find(*cts) != lspan.end())
300 {
301 return true;
302 }
303 }
304 return false;
305 }

◆ hasSpanfromCxtLock()

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

Definition at line 280 of file LockAnalysis.h.

281 {
282 return cxtLocktoSpan.find(cl) != cxtLocktoSpan.end();
283 }

◆ intersect()

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

Definition at line 390 of file LockAnalysis.h.

391 {
393 for(CxtLockSet::const_iterator it = tgrlockset.begin(), eit = tgrlockset.end(); it!=eit; ++it)
394 {
395 if(srclockset.find(*it)==srclockset.end())
396 toBeDeleted.insert(*it);
397 }
398 for(CxtLockSet::const_iterator it = toBeDeleted.begin(), eit = toBeDeleted.end(); it!=eit; ++it)
399 {
400 tgrlockset.erase(*it);
401 }
402 return !toBeDeleted.empty();
403 }
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 187 of file LockAnalysis.h.

188 {
189 for(CxtLockSet::const_iterator it = lockset1.begin(), eit = lockset1.end(); it!=eit; ++it)
190 {
191 const CxtLock& lock = *it;
192 for(CxtLockSet::const_iterator lit = lockset2.begin(), elit = lockset2.end(); lit!=elit; ++lit)
193 {
194 if(lock==*lit)
195 return true;
196 }
197 }
198 return false;
199 }

◆ intraBackwardTraverse()

template<class ICFGGraph , class CGGraph >
bool LockAnalysis::intraBackwardTraverse ( ICFGGraph  icfg,
CGGraph  cg,
const InstSet unlockSet,
InstSet backwardInsts 
)

Intra-procedural backward traversal

Definition at line 236 of file LockAnalysis.cpp.

237{
238
239 InstVec worklist;
240 for(InstSet::const_iterator it = unlockSet.begin(), eit = unlockSet.end(); it!=eit; ++it)
241 {
242 const ICFGNode* unlockSite = *it;
244 worklist.push_back(*it);
245
246 while (!worklist.empty())
247 {
248 const ICFGNode *I = worklist.back();
249 worklist.pop_back();
250
251 if(entryInst == I)
252 return false;
253
254 // Skip the visited Instructions.
255 if (backwardInsts.find(I)!=backwardInsts.end())
256 continue;
257 backwardInsts.insert(I);
258
260 {
261 DBOUT(DMTA, outs() << "LockAnalysis ci lock -- " << I->getSourceLoc()<<"\n");
262 DBOUT(DMTA, outs() << "LockAnalysis ci unlock -- " << unlockSite->getSourceLoc()<<"\n");
263 continue;
264 }
265
266 std::vector<const ICFGNode*> pred;
268 for (const ICFGNode* src : pred)
269 {
270 if(src->getFun() == I->getFun())
271 {
272 worklist.push_back(src);
273 }
274 }
275 }
276 }
277
278 return true;
279}
const SVFBasicBlock * getEntryBlock() const
TCT::InstVec InstVec
const ICFGNode * back() const
virtual const std::string getSourceLoc() const
Definition SVFValue.h:194

◆ intraForwardTraverse()

template<class ICFGGraph , class CGGraph >
bool LockAnalysis::intraForwardTraverse ( ICFGGraph  icfg,
CGGraph  cg,
const ICFGNode lockSite,
InstSet unlockSet,
InstSet forwardInsts 
)

Intra-procedural forward traversal

Definition at line 189 of file LockAnalysis.cpp.

190{
191
192 const FunObjVar* svfFun = lockSite->getFun();
193
194 InstVec worklist;
195 worklist.push_back(lockSite);
196 while (!worklist.empty())
197 {
198 const ICFGNode *I = worklist.back();
199 worklist.pop_back();
200 const ICFGNode* exitInst = svfFun->getExitBB()->back();
201 if(exitInst == I)
202 return false;
203
204 // Skip the visited Instructions.
205 if (forwardInsts.find(I)!=forwardInsts.end())
206 continue;
207 forwardInsts.insert(I);
208
209 if (isTDRelease(I) && isAliasedLocks(lockSite, I))
210 {
211 unlockSet.insert(I);
212 DBOUT(DMTA, outs() << "LockAnalysis ci lock -- " << lockSite->getSourceLoc()<<"\n");
213 DBOUT(DMTA, outs() << "LockAnalysis ci unlock -- " << I->getSourceLoc()<<"\n");
214 continue;
215 }
216
217 std::vector<const ICFGNode*> succ;
219 for (const ICFGNode* dst : succ)
220 {
221 if(dst->getFun() == I->getFun())
222 {
223 worklist.push_back(dst);
224 }
225 }
226 }
227
228 return true;
229}

◆ isAliasedLocks() [1/2]

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

Return true it a lock matches an unlock.

Definition at line 364 of file LockAnalysis.h.

365 {
366 return isAliasedLocks(cl1.getStmt(), cl2.getStmt());
367 }

◆ isAliasedLocks() [2/2]

bool LockAnalysis::isAliasedLocks ( const ICFGNode i1,
const ICFGNode i2 
)
protected

todo: must alias

Definition at line 357 of file LockAnalysis.cpp.

358{
360 return tct->getPTA()->alias(getLockVal(i1)->getId(), getLockVal(i2)->getId());
361}
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:198

◆ isCallSite()

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

Whether it is a callsite.

Definition at line 479 of file LockAnalysis.h.

480 {
481 return tct->isCallSite(inst);
482 }
bool isCallSite(const ICFGNode *inst)
Whether it is a callsite.
Definition TCT.h:268

◆ isContextSuffix()

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

If lhs is a suffix of rhs, including equal.

Definition at line 641 of file LockAnalysis.cpp.

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

◆ isExtCall()

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

Whether it is calling an external function.

Definition at line 484 of file LockAnalysis.h.

485 {
486 return tct->isExtCall(inst);
487 }
bool isExtCall(const ICFGNode *inst)
Whether it is calling an external function.
Definition TCT.h:261

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

755{
757 {
760 for (InstSet::const_iterator cil1 = lockset1.begin(), ecil1 = lockset1.end(); cil1!=ecil1; ++cil1)
761 {
762 for (InstSet::const_iterator cil2=lockset2.begin(), ecil2=lockset2.end(); cil2!=ecil2; ++cil2)
763 {
764 if (*cil1==*cil2)
765 return true;
766 }
767 }
768 }
769 return false;
770}
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 775 of file LockAnalysis.cpp.

776{
778 return true;
782}
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 786 of file LockAnalysis.cpp.

787{
789 return false;
792
793 for (CxtStmtSet::const_iterator cts1 = ctsset1.begin(), ects1 = ctsset1.end(); cts1 != ects1; cts1++)
794 {
795 const CxtStmt& cxtStmt1 = *cts1;
796 for (CxtStmtSet::const_iterator cts2 = ctsset2.begin(), ects2 = ctsset2.end(); cts2 != ects2; cts2++)
797 {
798 const CxtStmt& cxtStmt2 = *cts2;
799 if(cxtStmt1==cxtStmt2) continue;
801 return false;
802 }
803 }
804 return true;
805}
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 736 of file LockAnalysis.cpp.

737{
738 DOTIMESTAT(double queryStart = PTAStat::getClk(true));
739
740 bool sameSpan = false;
743 else
745
746 DOTIMESTAT(double queryEnd = PTAStat::getClk(true));
748 return sameSpan;
749}
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 149 of file LockAnalysis.h.

150 {
151 return instTocondCILocksMap.find(stmt)!=instTocondCILocksMap.end();
152 }

◆ isInsideIntraLock()

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

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

Definition at line 143 of file LockAnalysis.h.

144 {
145 return instCILocksMap.find(stmt)!=instCILocksMap.end() || isInsideCondIntraLock(stmt);
146 }

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

118 {
119 assert(locksites.find(lock)!=locksites.end() && "not a lock site?");
120 return ciLocktoSpan.find(lock)!=ciLocktoSpan.end();
121 }

◆ isLockCandidateFun()

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

Return true if it is a candidate function.

Definition at line 217 of file LockAnalysis.h.

218 {
219 return lockcandidateFuncSet.find(fun)!=lockcandidateFuncSet.end();
220 }

◆ isProtectedByCommonCILock()

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

Protected by at least one common context-insensitive lock

Definition at line 667 of file LockAnalysis.cpp.

668{
669
671 {
674 for (InstSet::const_iterator cil1 = lockset1.begin(), ecil1 = lockset1.end(); cil1!=ecil1; ++cil1)
675 {
676 for (InstSet::const_iterator cil2=lockset2.begin(), ecil2=lockset2.end(); cil2!=ecil2; ++cil2)
677 {
678 if (isAliasedLocks(*cil1, *cil2))
679 return true;
680 }
681 }
682 }
683 return false;
684}

◆ isProtectedByCommonCxtLock() [1/2]

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

Protected by at least one common context-sensitive lock

Definition at line 689 of file LockAnalysis.cpp.

690{
692 return true;
695 return alias(lockset1,lockset2);
696}
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 701 of file LockAnalysis.cpp.

702{
704 return false;
707 for (CxtStmtSet::const_iterator cts1 = ctsset1.begin(), ects1 = ctsset1.end(); cts1 != ects1; cts1++)
708 {
709 const CxtStmt& cxtStmt1 = *cts1;
710 for (CxtStmtSet::const_iterator cts2 = ctsset2.begin(), ects2 = ctsset2.end(); cts2 != ects2; cts2++)
711 {
712 const CxtStmt& cxtStmt2 = *cts2;
713 if(cxtStmt1==cxtStmt2)
714 {
715 // i1==i2 under the same context: a self-race between two dynamic
716 // instances of one statement (e.g. a thread forked in a loop).
717 // This is the ONLY pair the loop produces for such a query, so
718 // skipping it would fall through to the vacuous "protected" return
719 // below and drop a real race. The two instances are mutually
720 // excluded only if this context actually holds a (non-empty) lock.
722 return false;
723 continue;
724 }
726 return false;
727 }
728 }
729 return true;
730}
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 650 of file LockAnalysis.cpp.

651{
653 bool commonlock = false;
654 DOTIMESTAT(double queryStart = PTAStat::getClk(true));
657 else
659 DOTIMESTAT(double queryEnd = PTAStat::getClk(true));
661 return commonlock;
662}
bool isProtectedByCommonCILock(const ICFGNode *i1, const ICFGNode *i2)

◆ isTDAcquire()

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

Whether it is a lock site.

Definition at line 465 of file LockAnalysis.h.

466 {
467 if(SVFUtil::isa<CallICFGNode>(call) == false)
468 return false;
469 return getTCG()->getThreadAPI()->isTDAcquire(SVFUtil::cast<CallICFGNode>(call));
470 }

◆ isTDFork()

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

Whether it is a lock site.

Definition at line 458 of file LockAnalysis.h.

459 {
460 if(SVFUtil::isa<CallICFGNode>(call) == false)
461 return false;
462 return getTCG()->getThreadAPI()->isTDFork(SVFUtil::cast<CallICFGNode>(call));
463 }
bool isTDFork(const CallICFGNode *inst) const
Return true if this call create a new thread.

◆ isTDRelease()

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

Whether it is a unlock site.

Definition at line 472 of file LockAnalysis.h.

473 {
474 if(SVFUtil::isa<CallICFGNode>(call) == false)
475 return false;
476 return getTCG()->getThreadAPI()->isTDRelease(SVFUtil::cast<CallICFGNode>(call));
477 }

◆ isVisitedCTPs()

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

Definition at line 428 of file LockAnalysis.h.

429 {
430 return visitedCTPs.find(clp) != visitedCTPs.end();
431 }
CxtLockProcSet visitedCTPs
CxtLockProc List.

◆ markCxtStmtFlag()

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

Mark thread flags for cxtStmt.

Transfer function for marking context-sensitive statement

Definition at line 373 of file LockAnalysis.h.

374 {
376 if(hasCxtLockfromCxtStmt(tgr)== false)
377 {
378 for(CxtLockSet::const_iterator it = srclockset.begin(), eit = srclockset.end(); it!=eit; ++it)
379 {
381 }
383 }
384 else
385 {
388 }
389 }
bool intersect(CxtLockSet &tgrlockset, const CxtLockSet &srclockset)

◆ matchCxt()

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

Match context.

partial match

Definition at line 617 of file LockAnalysis.cpp.

618{
619 const FunObjVar* svfcaller = call->getFun();
620 CallSiteID csId = getTCG()->getCallSiteID(call, callee);
621
622// /// handle calling context for candidate functions only
623// if (isLockCandidateFun(caller) == false)
624// return true;
625
627 if (cxt.empty())
628 return true;
629
630 if (tct->inSameCallGraphSCC(getTCG()->getCallGraphNode(svfcaller), getTCG()->getCallGraphNode(callee)) == false)
631 {
632 if (cxt.back() == csId)
633 cxt.pop_back();
634 else
635 return false;
636 DBOUT(DMTA, tct->dumpCxt(cxt));
637 }
638 return true;
639}
CallSiteID getCallSiteID(const CallICFGNode *cs, const FunObjVar *callee) const
Get CallSiteID.
Definition CallGraph.h:389
bool inSameCallGraphSCC(const CallGraphNode *src, const CallGraphNode *dst)
Whether two functions in the same callgraph scc.
Definition TCT.h:303
void dumpCxt(CallStrCxt &cxt)
Dump calling context.
Definition TCT.cpp:541
unsigned CallSiteID
Definition GeneralType.h:78

◆ popFromCTPWorkList()

CxtLockProc SVF::LockAnalysis::popFromCTPWorkList ( )
inlineprotected

Definition at line 423 of file LockAnalysis.h.

424 {
426 return clp;
427 }

◆ popFromCTSWorkList()

CxtStmt SVF::LockAnalysis::popFromCTSWorkList ( )
inlineprotected

Definition at line 440 of file LockAnalysis.h.

441 {
442 CxtStmt clp = cxtStmtList.pop();
443 return clp;
444 }

◆ printLocks()

void LockAnalysis::printLocks ( const CxtStmt cts)

Print locks and spans.

Print context-insensitive and context-sensitive locks

Definition at line 432 of file LockAnalysis.cpp.

433{
435 outs() << "\nlock sets size = " << lockset.size() << "\n";
436 for (CxtLockSet::const_iterator it = lockset.begin(), eit = lockset.end(); it != eit; ++it)
437 {
438 (*it).dump();
439 }
440}

◆ pushCxt()

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

Context helper functions.

Push calling context

Definition at line 612 of file LockAnalysis.cpp.

613{
614 tct->pushCxt(cxt,call,callee);
615}
virtual void pushCxt(CallStrCxt &cxt, const CallICFGNode *call, const FunObjVar *callee)
Context helper functions.
Definition TCT.cpp:473

◆ pushToCTPWorkList()

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

WorkList helper functions.

Definition at line 414 of file LockAnalysis.h.

415 {
416 if (isVisitedCTPs(clp) == false)
417 {
418 visitedCTPs.insert(clp);
419 return clpList.push(clp);
420 }
421 return false;
422 }
bool isVisitedCTPs(const CxtLockProc &clp) const

◆ pushToCTSWorkList()

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

Worklist operations.

Definition at line 436 of file LockAnalysis.h.

437 {
438 return cxtStmtList.push(cs);
439 }

◆ removeCxtStmtToSpan()

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

Add context-sensitive statement.

Definition at line 260 of file LockAnalysis.h.

261 {
262 bool find = cxtStmtToCxtLockSet[cts].find(cl)!=cxtStmtToCxtLockSet[cts].end();
263 if(find)
264 {
265 cxtStmtToCxtLockSet[cts].erase(cl);
266 cxtLocktoSpan[cl].erase(cts);
267 }
268 return find;
269 }

◆ touchCxtStmt()

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

Touch this context statement.

Definition at line 276 of file LockAnalysis.h.

277 {
279 }

Member Data Documentation

◆ ciLocktoSpan

CILockToSpan SVF::LockAnalysis::ciLocktoSpan
protected

Used for context-insensitive intra-procedural locks.

Definition at line 537 of file LockAnalysis.h.

◆ clpList

CxtLockProcVec SVF::LockAnalysis::clpList
protected

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

Definition at line 520 of file LockAnalysis.h.

◆ cxtLockset

CxtLockSet SVF::LockAnalysis::cxtLockset
protected

Context-sensitive locks.

Definition at line 509 of file LockAnalysis.h.

◆ cxtLocktoSpan

CxtLockToSpan SVF::LockAnalysis::cxtLocktoSpan
protected

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

Definition at line 514 of file LockAnalysis.h.

◆ cxtStmtList

CxtStmtWorkList SVF::LockAnalysis::cxtStmtList
protected

context-sensitive statement worklist

Definition at line 503 of file LockAnalysis.h.

◆ cxtStmtToCxtLockSet

CxtStmtToCxtLockSet SVF::LockAnalysis::cxtStmtToCxtLockSet
protected

Definition at line 515 of file LockAnalysis.h.

◆ instCILocksMap

InstToInstSetMap SVF::LockAnalysis::instCILocksMap
protected

Definition at line 538 of file LockAnalysis.h.

◆ instTocondCILocksMap

InstToInstSetMap SVF::LockAnalysis::instTocondCILocksMap
protected

Definition at line 539 of file LockAnalysis.h.

◆ instToCxtStmtSet

InstToCxtStmtSet SVF::LockAnalysis::instToCxtStmtSet
protected

Map a statement to all its context-sensitive statements.

Definition at line 506 of file LockAnalysis.h.

◆ lockcandidateFuncSet

FunSet SVF::LockAnalysis::lockcandidateFuncSet
protected

Candidate functions which relevant to locks/unlocks.

Definition at line 532 of file LockAnalysis.h.

◆ lockQueriesTime

double SVF::LockAnalysis::lockQueriesTime

Definition at line 546 of file LockAnalysis.h.

◆ locksites

InstSet SVF::LockAnalysis::locksites
protected

Record all visited clps.

Collecting lock/unlock sites

Definition at line 526 of file LockAnalysis.h.

◆ lockTime

double SVF::LockAnalysis::lockTime

Definition at line 543 of file LockAnalysis.h.

◆ numOfLockedQueries

u32_t SVF::LockAnalysis::numOfLockedQueries

Definition at line 545 of file LockAnalysis.h.

◆ numOfTotalQueries

u32_t SVF::LockAnalysis::numOfTotalQueries

Definition at line 544 of file LockAnalysis.h.

◆ tct

TCT* SVF::LockAnalysis::tct
protected

TCT.

Definition at line 500 of file LockAnalysis.h.

◆ unlocksites

InstSet SVF::LockAnalysis::unlocksites
protected

Definition at line 527 of file LockAnalysis.h.

◆ visitedCTPs

CxtLockProcSet SVF::LockAnalysis::visitedCTPs
protected

CxtLockProc List.

Definition at line 521 of file LockAnalysis.h.


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