Static Value-Flow Analysis
MTAStat.cpp
Go to the documentation of this file.
1 //===- MTAStat.cpp -- Statistics for MTA-------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-> <Yulei Sui>
6 //
7 
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
17 
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 /*
24  * MTAStat.cpp
25  *
26  * Created on: Jun 23, 2015
27  * Author: Yulei Sui, Peng Di
28  */
29 
30 #include "Util/Options.h"
31 #include "MTA/MTAStat.h"
32 #include "MTA/TCT.h"
33 #include "MTA/MHP.h"
34 #include "MTA/LockAnalysis.h"
35 #include "Graphs/ThreadCallGraph.h"
36 
37 using namespace SVF;
38 
39 
44 {
45  u32_t numOfForkEdge = 0;
46  u32_t numOfJoinEdge = 0;
47  u32_t numOfIndForksite = 0;
48  u32_t numOfIndForkEdge = 0;
49  for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->forksitesBegin(), eit = tcg->forksitesEnd(); it != eit; ++it)
50  {
51  bool indirectfork = false;
52  const SVFFunction* spawnee = SVFUtil::dyn_cast<SVFFunction>(tcg->getThreadAPI()->getForkedFun(*it)->getValue());
53  if(spawnee==nullptr)
54  {
55  numOfIndForksite++;
56  indirectfork = true;
57  }
58  for (ThreadCallGraph::ForkEdgeSet::const_iterator cgIt = tcg->getForkEdgeBegin(*it), ecgIt =
59  tcg->getForkEdgeEnd(*it); cgIt != ecgIt; ++cgIt)
60  {
61  numOfForkEdge++;
62  if(indirectfork)
63  numOfIndForkEdge++;
64  }
65  }
66 
67  for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->joinsitesBegin(), eit = tcg->joinsitesEnd(); it != eit; ++it)
68  {
69  for (ThreadCallGraph::JoinEdgeSet::const_iterator cgIt = tcg->getJoinEdgeBegin(*it), ecgIt =
70  tcg->getJoinEdgeEnd(*it); cgIt != ecgIt; ++cgIt)
71  {
72  numOfJoinEdge++;
73  }
74  }
75 
76 
77  PTNumStatMap.clear();
78  PTNumStatMap["NumOfForkSite"] = tcg->getNumOfForksite();
79  PTNumStatMap["NumOfForkEdge"] = numOfForkEdge;
80  PTNumStatMap["NumOfJoinEdge"] = numOfJoinEdge;
81  PTNumStatMap["NumOfJoinSite"] = tcg->getNumOfJoinsite();
82  PTNumStatMap["NumOfIndForkSite"] = numOfIndForksite;
83  PTNumStatMap["NumOfIndForkEdge"] = numOfIndForkEdge;
84  PTNumStatMap["NumOfIndCallEdge"] = tcg->getNumOfResolvedIndCallEdge();
85 
86  SVFUtil::outs() << "\n****Thread Call Graph Statistics****\n";
88 }
89 
90 
92 {
93 
94  PTNumStatMap.clear();
95  timeStatMap.clear();
96  PTNumStatMap["NumOfCandidateFun"] = tct->getMakredProcs().size();
97  PTNumStatMap["NumOfTotalFun"] = tct->getThreadCallGraph()->getTotalNodeNum();
98  PTNumStatMap["NumOfTCTNode"] = tct->getTCTNodeNum();
99  PTNumStatMap["NumOfTCTEdge"] = tct->getTCTEdgeNum();
100  PTNumStatMap["MaxCxtSize"] = tct->getMaxCxtSize();
101  timeStatMap["BuildingTCTTime"] = TCTTime;
102  SVFUtil::outs() << "\n****Thread Creation Tree Statistics****\n";
104 }
105 
112 {
113 
114  SVFIR* pag = SVFIR::getPAG();
115  if(Options::AllPairMHP())
116  {
117  Set<const ICFGNode*> instSet1;
118  Set<const ICFGNode*> instSet2;
119  SVFModule* mod = mhp->getTCT()->getSVFModule();
120  for (const SVFFunction* fun : mod->getFunctionSet())
121  {
122  if(SVFUtil::isExtCall(fun))
123  continue;
124  if(!mhp->isConnectedfromMain(fun))
125  continue;
126  for (SVFFunction::const_iterator bit = fun->begin(), ebit = fun->end(); bit != ebit; ++bit)
127  {
128  const SVFBasicBlock* bb = *bit;
129  for (const auto& icfgNode : bb->getICFGNodeList())
130  {
131  for(const SVFStmt* stmt : pag->getSVFStmtList(icfgNode))
132  {
133  if(SVFUtil::isa<LoadStmt>(stmt))
134  {
135  instSet1.insert(stmt->getICFGNode());
136  }
137  else if(SVFUtil::isa<StoreStmt>(stmt))
138  {
139  instSet1.insert(stmt->getICFGNode());
140  instSet2.insert(stmt->getICFGNode());
141  }
142  }
143  }
144  }
145  }
146 
147 
148  for(Set<const ICFGNode*>::const_iterator it1 = instSet1.begin(), eit1 = instSet1.end(); it1!=eit1; ++it1)
149  {
150  for(Set<const ICFGNode*>::const_iterator it2 = instSet2.begin(), eit2 = instSet2.end(); it2!=eit2; ++it2)
151  {
152  mhp->mayHappenInParallel(*it1,*it2);
153  }
154  }
155  }
156 
157 
158  generalNumMap.clear();
159  PTNumStatMap.clear();
160  timeStatMap.clear();
161  PTNumStatMap["TotalMHPQueries"] = mhp->numOfTotalQueries;
162  PTNumStatMap["NumOfMHPPairs"] = mhp->numOfMHPQueries;
163  PTNumStatMap["TotalLockQueries"] = lsa->numOfTotalQueries;
164  PTNumStatMap["NumOfLockedPairs"] = lsa->numOfLockedQueries;
165  PTNumStatMap["NumOfCxtLocks"] = lsa->getNumOfCxtLocks();
166  timeStatMap["InterlevAnaTime"] = mhp->interleavingTime;
167  timeStatMap["LockAnaTime"] = lsa->lockTime;
168  timeStatMap["InterlevQueryTime"] = mhp->interleavingQueriesTime;
169  timeStatMap["LockQueryTime"] = lsa->lockQueriesTime;
170  timeStatMap["MHPAnalysisTime"] = MHPTime;
171 
172  SVFUtil::outs() << "\n****MHP Stmt Pairs Statistics****\n";
174 }
175 
u32_t getTotalNodeNum() const
Get total number of node/edge.
Definition: GenericGraph.h:680
u32_t getNumOfCxtLocks()
Definition: LockAnalysis.h:316
Definition: MHP.h:46
TCT * getTCT() const
Get Thread Creation Tree.
Definition: MHP.h:80
u32_t numOfTotalQueries
Total number of queries.
Definition: MHP.h:262
virtual bool mayHappenInParallel(const ICFGNode *i1, const ICFGNode *i2)
Interface to query whether two instructions may happen-in-parallel.
Definition: MHP.cpp:614
bool isConnectedfromMain(const SVFFunction *fun)
Whether the function is connected from main function in thread call graph.
Definition: MHP.cpp:521
double interleavingQueriesTime
Definition: MHP.h:265
u32_t numOfMHPQueries
Number of queries are answered as may-happen-in-parallel.
Definition: MHP.h:263
double interleavingTime
Definition: MHP.h:264
void performTCTStat(TCT *tct)
Statistics for thread creation tree.
Definition: MTAStat.cpp:91
void performThreadCallGraphStat(ThreadCallGraph *tcg)
Statistics for thread call graph.
Definition: MTAStat.cpp:43
double TCTTime
Statistics for annotation.
Definition: MTAStat.h:66
double MHPTime
Definition: MTAStat.h:67
void performMHPPairStat(MHP *mhp, LockAnalysis *lsa)
Statistics for MHP statement pairs.
Definition: MTAStat.cpp:111
static const Option< bool > AllPairMHP
Definition: Options.h:163
u32_t getNumOfResolvedIndCallEdge() const
Definition: PTACallGraph.h:324
const std::vector< const ICFGNode * > & getICFGNodeList() const
Definition: SVFValue.h:569
std::vector< const SVFBasicBlock * >::const_iterator const_iterator
Definition: SVFValue.h:305
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition: SVFIR.h:115
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
Definition: SVFIR.h:221
const FunctionSetType & getFunctionSet() const
Definition: SVFModule.h:199
NUMStatMap generalNumMap
Definition: SVFStat.h:76
NUMStatMap PTNumStatMap
Definition: SVFStat.h:77
virtual void printStat(std::string str="")
Definition: SVFStat.cpp:66
TIMEStatMap timeStatMap
Definition: SVFStat.h:78
const SVFValue * getValue() const
Get/has methods of the components.
Definition: SVFVariables.h:83
Definition: TCT.h:154
ThreadCallGraph * getThreadCallGraph() const
Get TCG.
Definition: TCT.h:196
u32_t getMaxCxtSize() const
Definition: TCT.h:257
const FunSet & getMakredProcs() const
Get marked candidate functions.
Definition: TCT.h:236
u32_t getTCTEdgeNum() const
Definition: TCT.h:253
SVFModule * getSVFModule() const
Get SVFFModule.
Definition: TCT.h:190
u32_t getTCTNodeNum() const
Get Statistics.
Definition: TCT.h:249
const SVFVar * getForkedFun(const CallICFGNode *inst) const
Definition: ThreadAPI.cpp:170
CallSiteSet::const_iterator forksitesEnd() const
CallSiteSet::const_iterator forksitesBegin() const
Fork sites iterators.
CallSiteSet::const_iterator joinsitesEnd() const
u32_t getNumOfJoinsite() const
JoinEdgeSet::const_iterator getJoinEdgeEnd(const CallICFGNode *cs) const
ForkEdgeSet::const_iterator getForkEdgeEnd(const CallICFGNode *cs) const
ForkEdgeSet::const_iterator getForkEdgeBegin(const CallICFGNode *cs) const
CallSiteSet::const_iterator joinsitesBegin() const
Join sites iterators.
u32_t getNumOfForksite() const
Num of fork/join sites.
ThreadAPI * getThreadAPI() const
Thread API.
JoinEdgeSet::const_iterator getJoinEdgeBegin(const CallICFGNode *cs) const
bool isExtCall(const SVFFunction *fun)
Definition: SVFUtil.h:278
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50
for isBitcode
Definition: BasicTypes.h:68
unsigned u32_t
Definition: GeneralType.h:46
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96