Static Value-Flow Analysis
Loading...
Searching...
No Matches
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"
36#include "Graphs/CallGraph.h"
37
38using namespace SVF;
39
40
45{
50 for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->forksitesBegin(), eit = tcg->forksitesEnd(); it != eit; ++it)
51 {
52 bool indirectfork = false;
53 const ValVar* pValVar = tcg->getThreadAPI()->getForkedFun(*it);
54 if(!SVFUtil::isa<FunValVar>(pValVar))
55 {
57 indirectfork = true;
58 }
59 for (ThreadCallGraph::ForkEdgeSet::const_iterator cgIt = tcg->getForkEdgeBegin(*it), ecgIt =
60 tcg->getForkEdgeEnd(*it); cgIt != ecgIt; ++cgIt)
61 {
63 if(indirectfork)
65 }
66 }
67
68 for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->joinsitesBegin(), eit = tcg->joinsitesEnd(); it != eit; ++it)
69 {
70 for (ThreadCallGraph::JoinEdgeSet::const_iterator cgIt = tcg->getJoinEdgeBegin(*it), ecgIt =
71 tcg->getJoinEdgeEnd(*it); cgIt != ecgIt; ++cgIt)
72 {
74 }
75 }
76
77
78 PTNumStatMap.clear();
79 PTNumStatMap["NumOfForkSite"] = tcg->getNumOfForksite();
80 PTNumStatMap["NumOfForkEdge"] = numOfForkEdge;
81 PTNumStatMap["NumOfJoinEdge"] = numOfJoinEdge;
82 PTNumStatMap["NumOfJoinSite"] = tcg->getNumOfJoinsite();
83 PTNumStatMap["NumOfIndForkSite"] = numOfIndForksite;
84 PTNumStatMap["NumOfIndForkEdge"] = numOfIndForkEdge;
85 PTNumStatMap["NumOfIndCallEdge"] = tcg->getNumOfResolvedIndCallEdge();
86
87 SVFUtil::outs() << "\n****Thread Call Graph Statistics****\n";
89}
90
91
93{
94
95 PTNumStatMap.clear();
96 timeStatMap.clear();
97 PTNumStatMap["NumOfCandidateFun"] = tct->getMakredProcs().size();
98 PTNumStatMap["NumOfTotalFun"] = tct->getThreadCallGraph()->getTotalNodeNum();
99 PTNumStatMap["NumOfTCTNode"] = tct->getTCTNodeNum();
100 PTNumStatMap["NumOfTCTEdge"] = tct->getTCTEdgeNum();
101 PTNumStatMap["MaxCxtSize"] = tct->getMaxCxtSize();
102 timeStatMap["BuildingTCTTime"] = TCTTime;
103 SVFUtil::outs() << "\n****Thread Creation Tree Statistics****\n";
105}
106
113{
114
115 SVFIR* pag = SVFIR::getPAG();
117 {
120 SVFModule* mod = mhp->getTCT()->getSVFModule();
121 for (const SVFFunction* fun : mod->getFunctionSet())
122 {
123 if(SVFUtil::isExtCall(fun))
124 continue;
125 if(!mhp->isConnectedfromMain(fun))
126 continue;
127 for (SVFFunction::const_iterator bit = fun->begin(), ebit = fun->end(); bit != ebit; ++bit)
128 {
129 const SVFBasicBlock* bb = *bit;
130 for (const auto& icfgNode : bb->getICFGNodeList())
131 {
132 for(const SVFStmt* stmt : pag->getSVFStmtList(icfgNode))
133 {
134 if(SVFUtil::isa<LoadStmt>(stmt))
135 {
136 instSet1.insert(stmt->getICFGNode());
137 }
138 else if(SVFUtil::isa<StoreStmt>(stmt))
139 {
140 instSet1.insert(stmt->getICFGNode());
141 instSet2.insert(stmt->getICFGNode());
142 }
143 }
144 }
145 }
146 }
147
148
150 {
152 {
154 }
155 }
156 }
157
158
159 generalNumMap.clear();
160 PTNumStatMap.clear();
161 timeStatMap.clear();
162 PTNumStatMap["TotalMHPQueries"] = mhp->numOfTotalQueries;
163 PTNumStatMap["NumOfMHPPairs"] = mhp->numOfMHPQueries;
164 PTNumStatMap["TotalLockQueries"] = lsa->numOfTotalQueries;
165 PTNumStatMap["NumOfLockedPairs"] = lsa->numOfLockedQueries;
166 PTNumStatMap["NumOfCxtLocks"] = lsa->getNumOfCxtLocks();
167 timeStatMap["InterlevAnaTime"] = mhp->interleavingTime;
168 timeStatMap["LockAnaTime"] = lsa->lockTime;
169 timeStatMap["InterlevQueryTime"] = mhp->interleavingQueriesTime;
170 timeStatMap["LockQueryTime"] = lsa->lockQueriesTime;
171 timeStatMap["MHPAnalysisTime"] = MHPTime;
172
173 SVFUtil::outs() << "\n****MHP Stmt Pairs Statistics****\n";
175}
176
u32_t getTotalNodeNum() const
Get total number of node/edge.
Definition MHP.h:46
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
TCT * getTCT() const
Get Thread Creation Tree.
Definition MHP.h:80
void performTCTStat(TCT *tct)
Statistics for thread creation tree.
Definition MTAStat.cpp:92
void performThreadCallGraphStat(ThreadCallGraph *tcg)
Statistics for thread call graph.
Definition MTAStat.cpp:44
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:112
static const Option< bool > AllPairMHP
Definition Options.h:163
u32_t getNumOfResolvedIndCallEdge() const
const std::vector< const ICFGNode * > & getICFGNodeList() const
Definition SVFValue.h:580
std::vector< constSVFBasicBlock * >::const_iterator const_iterator
Definition SVFValue.h:305
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
Definition SVFIR.h:222
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
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:67
TIMEStatMap timeStatMap
Definition SVFStat.h:78
const FunSet & getMakredProcs() const
Get marked candidate functions.
Definition TCT.h:236
u32_t getMaxCxtSize() const
Definition TCT.h:257
ThreadCallGraph * getThreadCallGraph() const
Get TCG.
Definition TCT.h:196
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 ValVar * getForkedFun(const CallICFGNode *inst) const
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
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:46
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition GeneralType.h:96