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

#include <LockAnalysis.h>

Public Types

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

Public Member Functions

 LockAnalysis (TCT *t)
 
void analyze ()
 
void analyzeIntraProcedualLock ()
 
bool intraForwardTraverse (const ICFGNode *lock, InstSet &unlockset, InstSet &forwardInsts)
 
bool intraBackwardTraverse (const InstSet &unlockset, InstSet &backwardInsts)
 
void collectCxtLock ()
 
void analyzeLockSpanCxtStmt ()
 
void collectLockUnlocksites ()
 
void buildCandidateFuncSetforLock ()
 
bool isIntraLock (const ICFGNode *lock) const
 Intraprocedural locks. More...
 
void addIntraLock (const ICFGNode *lockSite, const InstSet &stmts)
 Add intra-procedural lock. More...
 
void addCondIntraLock (const ICFGNode *lockSite, const InstSet &stmts)
 Add intra-procedural lock. More...
 
bool isInsideIntraLock (const ICFGNode *stmt) const
 Return true if a statement is inside an intra-procedural lock. More...
 
bool isInsideCondIntraLock (const ICFGNode *stmt) const
 Return true if a statement is inside a partial lock/unlock pair (conditional lock with unconditional unlock) More...
 
const InstSetgetIntraLockSet (const ICFGNode *stmt) const
 
void addCxtLock (const CallStrCxt &cxt, const ICFGNode *inst)
 Context-sensitive locks. More...
 
bool hasCxtLock (const CxtLock &cxtLock) const
 Get context-sensitive lock. More...
 
bool intersects (const CxtLockSet &lockset1, const CxtLockSet &lockset2) const
 Return true if the intersection of two locksets is not empty. More...
 
bool alias (const CxtLockSet &lockset1, const CxtLockSet &lockset2)
 Return true if two locksets has at least one alias lock. More...
 
bool isLockCandidateFun (const SVFFunction *fun) const
 Return true if it is a candidate function. More...
 
bool hasCxtStmtfromInst (const ICFGNode *inst) const
 Context-sensitive statement and lock spans. More...
 
const CxtStmtSetgetCxtStmtfromInst (const ICFGNode *inst) const
 
bool hasCxtLockfromCxtStmt (const CxtStmt &cts) const
 
const CxtLockSetgetCxtLockfromCxtStmt (const CxtStmt &cts) const
 
CxtLockSetgetCxtLockfromCxtStmt (const CxtStmt &cts)
 
bool addCxtStmtToSpan (const CxtStmt &cts, const CxtLock &cl)
 Add context-sensitive statement. More...
 
bool removeCxtStmtToSpan (CxtStmt &cts, const CxtLock &cl)
 Add context-sensitive statement. More...
 
CxtStmtToCxtLockSet getCSTCLS ()
 
void touchCxtStmt (CxtStmt &cts)
 Touch this context statement. More...
 
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. More...
 
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. More...
 
TCTgetTCT ()
 Get tct. More...
 

Public Attributes

double lockTime
 
u32_t numOfTotalQueries
 
u32_t numOfLockedQueries
 
double lockQueriesTime
 

Private Member Functions

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

Private Attributes

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

Detailed Description

Lock analysis

Definition at line 44 of file LockAnalysis.h.

Member Typedef Documentation

◆ CILockToSpan

Definition at line 63 of file LockAnalysis.h.

◆ CISpan

Definition at line 62 of file LockAnalysis.h.

◆ CxtLock

Definition at line 56 of file LockAnalysis.h.

◆ CxtLockProc

Definition at line 57 of file LockAnalysis.h.

◆ CxtLockProcSet

Definition at line 78 of file LockAnalysis.h.

◆ CxtLockProcVec

Definition at line 77 of file LockAnalysis.h.

◆ CxtLockSet

Definition at line 70 of file LockAnalysis.h.

◆ CxtLockToLockSet

Definition at line 73 of file LockAnalysis.h.

◆ CxtLockToSpan

Definition at line 72 of file LockAnalysis.h.

◆ CxtStmtSet

Definition at line 69 of file LockAnalysis.h.

◆ CxtStmtToCxtLockSet

Definition at line 76 of file LockAnalysis.h.

◆ CxtStmtToLockFlagMap

Definition at line 66 of file LockAnalysis.h.

◆ CxtStmtWorkList

Definition at line 67 of file LockAnalysis.h.

◆ FunSet

Definition at line 64 of file LockAnalysis.h.

◆ InstSet

Definition at line 61 of file LockAnalysis.h.

◆ InstToCxtStmt

Definition at line 80 of file LockAnalysis.h.

◆ InstToCxtStmtSet

Definition at line 75 of file LockAnalysis.h.

◆ InstToInstSetMap

Definition at line 65 of file LockAnalysis.h.

◆ InstVec

Definition at line 60 of file LockAnalysis.h.

◆ LockSet

Definition at line 59 of file LockAnalysis.h.

◆ LockSiteToLockSet

Definition at line 74 of file LockAnalysis.h.

◆ LockSpan

Definition at line 68 of file LockAnalysis.h.

Member Enumeration Documentation

◆ ValDomain

semilattice Empty==>TDUnlocked==>TDLocked

Enumerator
Empty 
TDLocked 
TDUnlocked 

Definition at line 49 of file LockAnalysis.h.

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

Constructor & Destructor Documentation

◆ LockAnalysis()

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

Definition at line 82 of file LockAnalysis.h.

83  {
84  }

Member Function Documentation

◆ addCondIntraLock()

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

Add intra-procedural lock.

Definition at line 120 of file LockAnalysis.h.

121  {
122  for(InstSet::const_iterator it = stmts.begin(), eit = stmts.end(); it!=eit; ++it)
123  {
124  instTocondCILocksMap[*it].insert(lockSite);
125  }
126  }
InstToInstSetMap instTocondCILocksMap
Definition: LockAnalysis.h:520

◆ addCxtLock()

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

Context-sensitive locks.

Add inter-procedural context-sensitive lock

Definition at line 151 of file LockAnalysis.h.

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

◆ addCxtStmtToSpan()

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

Add context-sensitive statement.

Definition at line 232 of file LockAnalysis.h.

233  {
234  cxtLocktoSpan[cl].insert(cts);
235  return cxtStmtToCxtLockSet[cts].insert(cl).second;
236  }
CxtLockToSpan cxtLocktoSpan
Definition: LockAnalysis.h:495
CxtStmtToCxtLockSet cxtStmtToCxtLockSet
Definition: LockAnalysis.h:496

◆ addIntraLock()

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

Add intra-procedural lock.

Definition at line 110 of file LockAnalysis.h.

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

◆ alias()

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

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

Definition at line 179 of file LockAnalysis.h.

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

◆ 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));
62  DOTIMESTAT(lockTime += (lockEnd - lockStart) / TIMEINTERVAL);
63 }
#define TIMEINTERVAL
Definition: SVFType.h:512
#define DGENERAL
Definition: SVFType.h:490
#define DOTIMESTAT(X)
Definition: SVFType.h:486
void analyzeLockSpanCxtStmt()
void buildCandidateFuncSetforLock()
void analyzeIntraProcedualLock()
void collectLockUnlocksites()
static double getClk(bool mark=false)
Definition: SVFStat.cpp:47

◆ analyzeIntraProcedualLock()

void LockAnalysis::analyzeIntraProcedualLock ( )

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

FIXME:Should we intersect forwardInsts and backwardInsts?

Definition at line 143 of file LockAnalysis.cpp.

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

◆ analyzeLockSpanCxtStmt()

void LockAnalysis::analyzeLockSpanCxtStmt ( )

Definition at line 330 of file LockAnalysis.cpp.

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

◆ buildCandidateFuncSetforLock()

void LockAnalysis::buildCandidateFuncSetforLock ( )

Collect candidate functions for context-sensitive lock analysis

Definition at line 95 of file LockAnalysis.cpp.

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

◆ clearFlagMap()

void SVF::LockAnalysis::clearFlagMap ( )
inlineprivate

Clear flags.

Definition at line 391 of file LockAnalysis.h.

392  {
393  cxtStmtList.clear();
394  }

◆ collectCxtLock()

void LockAnalysis::collectCxtLock ( )

Definition at line 259 of file LockAnalysis.cpp.

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

◆ collectLockUnlocksites()

void LockAnalysis::collectLockUnlocksites ( )

Collect lock/unlock sites

Definition at line 69 of file LockAnalysis.cpp.

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

◆ getCSTCLS()

CxtStmtToCxtLockSet SVF::LockAnalysis::getCSTCLS ( )
inline

Definition at line 249 of file LockAnalysis.h.

250  {
251  return cxtStmtToCxtLockSet;
252  }

◆ getCxtLockfromCxtStmt() [1/2]

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

Definition at line 225 of file LockAnalysis.h.

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

◆ getCxtLockfromCxtStmt() [2/2]

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

Definition at line 219 of file LockAnalysis.h.

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

◆ getCxtStmtfromInst()

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

Definition at line 208 of file LockAnalysis.h.

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

◆ getIntraLockSet()

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

Definition at line 140 of file LockAnalysis.h.

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

◆ getLockVal()

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

Get lock value.

Definition at line 469 of file LockAnalysis.h.

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

◆ getNumOfCxtLocks()

u32_t SVF::LockAnalysis::getNumOfCxtLocks ( )
inline

Definition at line 316 of file LockAnalysis.h.

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

◆ getSpanfromCxtLock()

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

Definition at line 262 of file LockAnalysis.h.

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

◆ getTCG()

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

ThreadCallGraph.

Definition at line 474 of file LockAnalysis.h.

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

◆ getTCT()

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

Get tct.

Definition at line 324 of file LockAnalysis.h.

325  {
326  return tct;
327  }

◆ handleCall()

void LockAnalysis::handleCall ( const CxtStmt cts)
private

Handle call.

Definition at line 428 of file LockAnalysis.cpp.

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

◆ handleCallRelation()

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

Handle call relations.

Handling call relations when collecting context-sensitive locks

Definition at line 308 of file LockAnalysis.cpp.

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

◆ handleFork()

void LockAnalysis::handleFork ( const CxtStmt cts)
private

Handle fork.

Definition at line 407 of file LockAnalysis.cpp.

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

◆ handleIntra()

void LockAnalysis::handleIntra ( const CxtStmt cts)
private

Handle intra.

Definition at line 502 of file LockAnalysis.cpp.

503 {
504 
505  const ICFGNode* curInst = cts.getStmt();
506  const CallStrCxt& curCxt = cts.getContext();
507 
508  for(const ICFGEdge* outEdge : curInst->getOutEdges())
509  {
510  if(outEdge->getDstNode()->getFun() == curInst->getFun())
511  {
512  CxtStmt newCts(curCxt, outEdge->getDstNode());
513  markCxtStmtFlag(newCts, cts);
514  }
515  }
516 }
const GEdgeSetTy & getOutEdges() const
Definition: GenericGraph.h:430
virtual const SVFFunction * getFun() const
Return the function of this ICFGNode.
Definition: ICFGNode.h:76

◆ handleRet()

void LockAnalysis::handleRet ( const CxtStmt cts)
private

Handle return.

Definition at line 451 of file LockAnalysis.cpp.

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

◆ hasAllCxtInLockSpan()

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

Definition at line 287 of file LockAnalysis.h.

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

◆ hasCxtLock()

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

Get context-sensitive lock.

Definition at line 159 of file LockAnalysis.h.

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

◆ hasCxtLockfromCxtStmt()

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

Definition at line 214 of file LockAnalysis.h.

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

◆ hasCxtStmtfromInst()

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

Context-sensitive statement and lock spans.

Get LockSet and LockSpan

Definition at line 203 of file LockAnalysis.h.

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

◆ hasOneCxtInLockSpan()

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

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

Definition at line 272 of file LockAnalysis.h.

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

◆ hasSpanfromCxtLock()

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

Definition at line 258 of file LockAnalysis.h.

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

◆ intersect()

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

Definition at line 375 of file LockAnalysis.h.

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

◆ intersects()

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

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

Definition at line 165 of file LockAnalysis.h.

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

◆ intraBackwardTraverse()

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

Intra-procedural backward traversal

Definition at line 215 of file LockAnalysis.cpp.

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

◆ intraForwardTraverse()

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

Intra-procedural forward traversal

Definition at line 171 of file LockAnalysis.cpp.

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

◆ isAliasedLocks() [1/2]

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

Return true it a lock matches an unlock.

Definition at line 345 of file LockAnalysis.h.

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

◆ isAliasedLocks() [2/2]

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

todo: must alias

Definition at line 349 of file LockAnalysis.h.

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

◆ isCallSite()

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

Whether it is a callsite.

Definition at line 459 of file LockAnalysis.h.

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

◆ isExtCall()

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

Whether it is calling an external function.

Definition at line 464 of file LockAnalysis.h.

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

◆ isInSameCISpan()

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

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

Definition at line 656 of file LockAnalysis.cpp.

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

◆ isInSameCSSpan() [1/2]

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

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

Definition at line 677 of file LockAnalysis.cpp.

678 {
679  if(!hasCxtLockfromCxtStmt(cxtStmt1) || !hasCxtLockfromCxtStmt(cxtStmt2))
680  return true;
681  const CxtLockSet& lockset1 = getCxtLockfromCxtStmt(cxtStmt1);
682  const CxtLockSet& lockset2 = getCxtLockfromCxtStmt(cxtStmt2);
683  return intersects(lockset1,lockset2);
684 }
bool hasCxtLockfromCxtStmt(const CxtStmt &cts) const
Definition: LockAnalysis.h:214
const CxtLockSet & getCxtLockfromCxtStmt(const CxtStmt &cts) const
Definition: LockAnalysis.h:219
bool intersects(const CxtLockSet &lockset1, const CxtLockSet &lockset2) const
Return true if the intersection of two locksets is not empty.
Definition: LockAnalysis.h:165

◆ isInSameCSSpan() [2/2]

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

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

Definition at line 688 of file LockAnalysis.cpp.

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

◆ isInSameSpan()

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

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

Definition at line 638 of file LockAnalysis.cpp.

639 {
640  DOTIMESTAT(double queryStart = PTAStat::getClk(true));
641 
642  bool sameSpan = false;
643  if (isInsideIntraLock(i1) && isInsideIntraLock(i2))
644  sameSpan = isInSameCISpan(i1, i2);
645  else
646  sameSpan = isInSameCSSpan(i1, i2);
647 
648  DOTIMESTAT(double queryEnd = PTAStat::getClk(true));
649  DOTIMESTAT(lockQueriesTime += (queryEnd - queryStart) / TIMEINTERVAL);
650  return sameSpan;
651 }
bool isInsideIntraLock(const ICFGNode *stmt) const
Return true if a statement is inside an intra-procedural lock.
Definition: LockAnalysis.h:129
bool isInSameCISpan(const ICFGNode *i1, const ICFGNode *i2) const

◆ isInsideCondIntraLock()

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

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

Definition at line 135 of file LockAnalysis.h.

136  {
137  return instTocondCILocksMap.find(stmt)!=instTocondCILocksMap.end();
138  }

◆ isInsideIntraLock()

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

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

Definition at line 129 of file LockAnalysis.h.

130  {
131  return instCILocksMap.find(stmt)!=instCILocksMap.end() || isInsideCondIntraLock(stmt);
132  }

◆ isIntraLock()

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

Intraprocedural locks.

Return true if the lock is an intra-procedural lock

Definition at line 103 of file LockAnalysis.h.

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

◆ isLockCandidateFun()

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

Return true if it is a candidate function.

Definition at line 195 of file LockAnalysis.h.

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

◆ isProtectedByCommonCILock()

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

Protected by at least one common context-insensitive lock

Definition at line 580 of file LockAnalysis.cpp.

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

◆ isProtectedByCommonCxtLock() [1/2]

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

Protected by at least one common context-sensitive lock

Definition at line 602 of file LockAnalysis.cpp.

603 {
604  if(!hasCxtLockfromCxtStmt(cxtStmt1) || !hasCxtLockfromCxtStmt(cxtStmt2))
605  return true;
606  const CxtLockSet& lockset1 = getCxtLockfromCxtStmt(cxtStmt1);
607  const CxtLockSet& lockset2 = getCxtLockfromCxtStmt(cxtStmt2);
608  return alias(lockset1,lockset2);
609 }
bool alias(const CxtLockSet &lockset1, const CxtLockSet &lockset2)
Return true if two locksets has at least one alias lock.
Definition: LockAnalysis.h:179

◆ isProtectedByCommonCxtLock() [2/2]

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

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

Definition at line 614 of file LockAnalysis.cpp.

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

◆ isProtectedByCommonLock()

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

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

Protected by at least one common lock under every context

Definition at line 563 of file LockAnalysis.cpp.

564 {
566  bool commonlock = false;
567  DOTIMESTAT(double queryStart = PTAStat::getClk(true));
568  if (isInsideIntraLock(i1) && isInsideIntraLock(i2))
569  commonlock = isProtectedByCommonCILock(i1,i2) ;
570  else
571  commonlock = isProtectedByCommonCxtLock(i1,i2);
572  DOTIMESTAT(double queryEnd = PTAStat::getClk(true));
573  DOTIMESTAT(lockQueriesTime += (queryEnd - queryStart) / TIMEINTERVAL);
574  return commonlock;
575 }
bool isProtectedByCommonCILock(const ICFGNode *i1, const ICFGNode *i2)

◆ isTDAcquire()

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

Whether it is a lock site.

Definition at line 445 of file LockAnalysis.h.

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

◆ isTDFork()

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

Whether it is a lock site.

Definition at line 438 of file LockAnalysis.h.

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

◆ isTDRelease()

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

Whether it is a unlock site.

Definition at line 452 of file LockAnalysis.h.

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

◆ isVisitedCTPs()

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

Definition at line 413 of file LockAnalysis.h.

414  {
415  return visitedCTPs.find(clp) != visitedCTPs.end();
416  }
CxtLockProcSet visitedCTPs
CxtLockProc List.
Definition: LockAnalysis.h:502

◆ markCxtStmtFlag()

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

Mark thread flags for cxtStmt.

Transfer function for marking context-sensitive statement

Definition at line 358 of file LockAnalysis.h.

359  {
360  const CxtLockSet& srclockset = getCxtLockfromCxtStmt(src);
361  if(hasCxtLockfromCxtStmt(tgr)== false)
362  {
363  for(CxtLockSet::const_iterator it = srclockset.begin(), eit = srclockset.end(); it!=eit; ++it)
364  {
365  addCxtStmtToSpan(tgr,*it);
366  }
367  pushToCTSWorkList(tgr);
368  }
369  else
370  {
371  if(intersect(getCxtLockfromCxtStmt(tgr),srclockset))
372  pushToCTSWorkList(tgr);
373  }
374  }
bool intersect(CxtLockSet &tgrlockset, const CxtLockSet &srclockset)
Definition: LockAnalysis.h:375

◆ matchCxt()

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

Match context.

partial match

Definition at line 535 of file LockAnalysis.cpp.

536 {
537  const SVFFunction* svfcaller = call->getFun();
538  CallSiteID csId = getTCG()->getCallSiteID(call, callee);
539 
540 // /// handle calling context for candidate functions only
541 // if (isLockCandidateFun(caller) == false)
542 // return true;
543 
545  if (cxt.empty())
546  return true;
547 
548  if (tct->inSameCallGraphSCC(getTCG()->getCallGraphNode(svfcaller), getTCG()->getCallGraphNode(callee)) == false)
549  {
550  if (cxt.back() == csId)
551  cxt.pop_back();
552  else
553  return false;
554  DBOUT(DMTA, tct->dumpCxt(cxt));
555  }
556  return true;
557 }
CallSiteID getCallSiteID(const CallICFGNode *cs, const SVFFunction *callee) const
Definition: PTACallGraph.h:368
bool inSameCallGraphSCC(const PTACallGraphNode *src, const PTACallGraphNode *dst)
Whether two functions in the same callgraph scc.
Definition: TCT.h:306
void dumpCxt(CallStrCxt &cxt)
Dump calling context.
Definition: TCT.cpp:495
unsigned CallSiteID
Definition: GeneralType.h:58

◆ popFromCTPWorkList()

CxtLockProc SVF::LockAnalysis::popFromCTPWorkList ( )
inlineprivate

Definition at line 408 of file LockAnalysis.h.

409  {
410  CxtLockProc clp = clpList.pop();
411  return clp;
412  }

◆ popFromCTSWorkList()

CxtStmt SVF::LockAnalysis::popFromCTSWorkList ( )
inlineprivate

Definition at line 425 of file LockAnalysis.h.

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

◆ printLocks()

void LockAnalysis::printLocks ( const CxtStmt cts)

Print locks and spans.

Print context-insensitive and context-sensitive locks

Definition at line 394 of file LockAnalysis.cpp.

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

◆ pushCxt()

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

Push calling context.

Definition at line 519 of file LockAnalysis.cpp.

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

◆ pushToCTPWorkList()

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

WorkList helper functions.

Definition at line 399 of file LockAnalysis.h.

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

◆ pushToCTSWorkList()

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

Worklist operations.

Definition at line 421 of file LockAnalysis.h.

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

◆ removeCxtStmtToSpan()

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

Add context-sensitive statement.

Definition at line 238 of file LockAnalysis.h.

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

◆ touchCxtStmt()

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

Touch this context statement.

Definition at line 254 of file LockAnalysis.h.

255  {
256  cxtStmtToCxtLockSet[cts];
257  }

Member Data Documentation

◆ ciLocktoSpan

CILockToSpan SVF::LockAnalysis::ciLocktoSpan
private

Used for context-insensitive intra-procedural locks.

Definition at line 518 of file LockAnalysis.h.

◆ clpList

CxtLockProcVec SVF::LockAnalysis::clpList
private

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

Definition at line 501 of file LockAnalysis.h.

◆ cxtLockset

CxtLockSet SVF::LockAnalysis::cxtLockset
private

Context-sensitive locks.

Definition at line 490 of file LockAnalysis.h.

◆ cxtLocktoSpan

CxtLockToSpan SVF::LockAnalysis::cxtLocktoSpan
private

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

Definition at line 495 of file LockAnalysis.h.

◆ cxtStmtList

CxtStmtWorkList SVF::LockAnalysis::cxtStmtList
private

context-sensitive statement worklist

Definition at line 483 of file LockAnalysis.h.

◆ cxtStmtToCxtLockSet

CxtStmtToCxtLockSet SVF::LockAnalysis::cxtStmtToCxtLockSet
private

Definition at line 496 of file LockAnalysis.h.

◆ instCILocksMap

InstToInstSetMap SVF::LockAnalysis::instCILocksMap
private

Definition at line 519 of file LockAnalysis.h.

◆ instTocondCILocksMap

InstToInstSetMap SVF::LockAnalysis::instTocondCILocksMap
private

Definition at line 520 of file LockAnalysis.h.

◆ instToCxtStmtSet

InstToCxtStmtSet SVF::LockAnalysis::instToCxtStmtSet
private

Map a statement to all its context-sensitive statements.

Definition at line 486 of file LockAnalysis.h.

◆ lockcandidateFuncSet

FunSet SVF::LockAnalysis::lockcandidateFuncSet
private

Candidate functions which relevant to locks/unlocks.

Definition at line 513 of file LockAnalysis.h.

◆ lockQueriesTime

double SVF::LockAnalysis::lockQueriesTime

Definition at line 528 of file LockAnalysis.h.

◆ locksites

InstSet SVF::LockAnalysis::locksites
private

Record all visited clps.

Collecting lock/unlock sites

Definition at line 507 of file LockAnalysis.h.

◆ lockTime

double SVF::LockAnalysis::lockTime

Definition at line 525 of file LockAnalysis.h.

◆ numOfLockedQueries

u32_t SVF::LockAnalysis::numOfLockedQueries

Definition at line 527 of file LockAnalysis.h.

◆ numOfTotalQueries

u32_t SVF::LockAnalysis::numOfTotalQueries

Definition at line 526 of file LockAnalysis.h.

◆ tct

TCT* SVF::LockAnalysis::tct
private

TCT.

Definition at line 480 of file LockAnalysis.h.

◆ unlocksites

InstSet SVF::LockAnalysis::unlocksites
private

Definition at line 508 of file LockAnalysis.h.

◆ visitedCTPs

CxtLockProcSet SVF::LockAnalysis::visitedCTPs
private

CxtLockProc List.

Definition at line 502 of file LockAnalysis.h.


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