Static Value-Flow Analysis
Loading...
Searching...
No Matches
PTAStat.cpp
Go to the documentation of this file.
1//===- PTAStat.cpp -- Base class for statistics in SVF-----------------------//
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 * PTAStat.cpp
25 *
26 * Created on: Oct 13, 2013
27 * Author: Yulei Sui
28 */
29
30#include <iomanip>
31#include "Graphs/CallGraph.h"
32#include "Util/PTAStat.h"
33#include "MemoryModel/PTATY.h"
35#include "SVFIR/SVFIR.h"
36
37using namespace SVF;
38using namespace std;
39
41 pta(p),
42 _vmrssUsageBefore(0),
43 _vmrssUsageAfter(0),
44 _vmsizeUsageBefore(0),
45 _vmsizeUsageAfter(0)
46{
47 u32_t vmrss = 0;
48 u32_t vmsize = 0;
51}
52
54{
55
57
59
60 SVFIR* pag = SVFIR::getPAG();
61 for(SVFIR::iterator it = pag->begin(), eit = pag->end(); it!=eit; ++it)
62 {
63 PAGNode* node = it->second;
64 if(SVFUtil::isa<ObjVar>(node))
65 {
67 {
69 }
70 }
71 }
72 PTNumStatMap["LocalVarInRecur"] = localVarInRecursion.count();
73
74 u32_t vmrss = 0;
75 u32_t vmsize = 0;
78 timeStatMap["MemoryUsageVmrss"] = _vmrssUsageAfter - _vmrssUsageBefore;
79 timeStatMap["MemoryUsageVmsize"] = _vmsizeUsageAfter - _vmsizeUsageBefore;
80}
81
83{
84
85 CallGraph* graph = pta->getCallGraph();
87 callgraphSCC->find();
88
89 unsigned totalNode = 0;
90 unsigned totalCycle = 0;
91 unsigned nodeInCycle = 0;
92 unsigned maxNodeInCycle = 0;
93 unsigned totalEdge = 0;
94 unsigned edgeInCycle = 0;
95
97 CallGraph::iterator it = graph->begin();
98 CallGraph::iterator eit = graph->end();
99 for (; it != eit; ++it)
100 {
101 totalNode++;
102 if(callgraphSCC->isInCycle(it->first))
103 {
104 sccRepNodeSet.insert(callgraphSCC->repNode(it->first));
105 nodeInCycle++;
106 const NodeBS& subNodes = callgraphSCC->subNodes(it->first);
107 if(subNodes.count() > maxNodeInCycle)
108 maxNodeInCycle = subNodes.count();
109 }
110
111 CallGraphNode::const_iterator edgeIt = it->second->InEdgeBegin();
112 CallGraphNode::const_iterator edgeEit = it->second->InEdgeEnd();
113 for (; edgeIt != edgeEit; ++edgeIt)
114 {
116 totalEdge+= edge->getDirectCalls().size() + edge->getIndirectCalls().size();
117 if(callgraphSCC->repNode(edge->getSrcID()) == callgraphSCC->repNode(edge->getDstID()))
118 {
119 edgeInCycle+=edge->getDirectCalls().size() + edge->getIndirectCalls().size();
120 }
121 }
122 }
123
124 totalCycle = sccRepNodeSet.size();
125
126 PTNumStatMap["TotalNode"] = totalNode;
127 PTNumStatMap["TotalCycle"] = totalCycle;
128 PTNumStatMap["NodeInCycle"] = nodeInCycle;
129 PTNumStatMap["MaxNodeInCycle"] = maxNodeInCycle;
130 PTNumStatMap["TotalEdge"] = totalEdge;
131 PTNumStatMap["CalRetPairInCycle"] = edgeInCycle;
132
134 SVFStat::printStat("PTACallGraph Stats (Andersen analysis)");
136 SVFStat::printStat("PTACallGraph Stats (Flow-sensitive analysis)");
138 SVFStat::printStat("PTACallGraph Stats (CFL-R analysis)");
140 SVFStat::printStat("PTACallGraph Stats (DDA analysis)");
141 else
142 SVFStat::printStat("PTACallGraph Stats");
143
144 delete callgraphSCC;
145}
cJSON * p
Definition cJSON.cpp:2559
CallInstSet & getDirectCalls()
Definition CallGraph.h:95
iterator begin()
Iterators.
IDToNodeMapTy::iterator iterator
Node Iterators.
GEdgeSetTy::const_iterator const_iterator
void setMemUsageBefore(u32_t vmrss, u32_t vmsize)
Definition PTAStat.h:55
void setMemUsageAfter(u32_t vmrss, u32_t vmsize)
Definition PTAStat.h:61
u32_t _vmsizeUsageBefore
Definition PTAStat.h:76
NodeBS localVarInRecursion
Definition PTAStat.h:53
PointerAnalysis * pta
Definition PTAStat.h:73
u32_t _vmsizeUsageAfter
Definition PTAStat.h:77
u32_t _vmrssUsageAfter
Definition PTAStat.h:75
PTAStat(PointerAnalysis *p)
Definition PTAStat.cpp:40
void performStat() override
Definition PTAStat.cpp:53
u32_t _vmrssUsageBefore
Definition PTAStat.h:74
void callgraphStat() override
Definition PTAStat.cpp:82
bool isLocalVarInRecursiveFun(NodeID id) const
Whether a local variable is in function recursions.
CallGraph * getCallGraph() const
Return call graph.
PTATY getAnalysisTy() const
Type of pointer analysis.
SCCDetection< CallGraph * > CallGraphSCC
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:120
NUMStatMap PTNumStatMap
Definition SVFStat.h:80
virtual void printStat(std::string str="")
Definition SVFStat.cpp:70
TIMEStatMap timeStatMap
Definition SVFStat.h:81
virtual void performStat()=0
Definition SVFStat.cpp:113
NodeID getId() const
Get ID.
Definition SVFValue.h:160
void set(unsigned Idx)
unsigned count() const
bool getMemoryUsageKB(u32_t *vmrss_kb, u32_t *vmsize_kb)
Get memory usage from system file. Return TRUE if succeed.
Definition SVFUtil.cpp:183
for isBitcode
Definition BasicTypes.h:70
Set< NodeID > NodeSet
Definition GeneralType.h:87
@ Cxt_DDA
context sensitive DDA
Definition PTATY.h:32
@ FieldS_DDA
Field sensitive DDA.
Definition PTATY.h:29
@ CFLFICI_WPA
Flow-, context-, insensitive CFL-reachability-based analysis.
Definition PTATY.h:23
@ FSDATAFLOW_WPA
Traditional Dataflow-based flow sensitive WPA.
Definition PTATY.h:19
@ Steensgaard_WPA
Steensgaard PTA.
Definition PTATY.h:16
@ FSCS_WPA
Flow-, context- sensitive WPA.
Definition PTATY.h:22
@ CFLFSCS_WPA
Flow-, context-, CFL-reachability-based analysis.
Definition PTATY.h:25
@ Andersen_BASE
Base Andersen PTA.
Definition PTATY.h:11
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned u32_t
Definition GeneralType.h:67