Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes | List of all members
SVF::AndersenStat Class Reference

#include <WPAStat.h>

Inheritance diagram for SVF::AndersenStat:
SVF::PTAStat SVF::SVFStat

Public Member Functions

 AndersenStat (AndersenBase *p)
 
virtual ~AndersenStat ()
 
virtual void performStat ()
 
void collectCycleInfo (ConstraintGraph *consCG)
 
void statNullPtr ()
 
void constraintGraphStat ()
 
- Public Member Functions inherited from SVF::PTAStat
 PTAStat (PointerAnalysis *p)
 
virtual ~PTAStat ()
 
void setMemUsageBefore (u32_t vmrss, u32_t vmsize)
 
void setMemUsageAfter (u32_t vmrss, u32_t vmsize)
 
void performStat () override
 
void callgraphStat () override
 
- Public Member Functions inherited from SVF::SVFStat
 SVFStat ()
 
virtual ~SVFStat ()
 
virtual void startClk ()
 
virtual void endClk ()
 
virtual void printStat (std::string str="")
 
virtual void performStatPerQuery (NodeID)
 
virtual void printStatPerQuery (NodeID, const PointsTo &)
 

Public Attributes

u32_t _NumOfNullPtr
 
u32_t _NumOfConstantPtr
 
u32_t _NumOfBlackholePtr
 
- Public Attributes inherited from SVF::PTAStat
NodeBS localVarInRecursion
 
- Public Attributes inherited from SVF::SVFStat
NUMStatMap generalNumMap
 
NUMStatMap PTNumStatMap
 
TIMEStatMap timeStatMap
 
double startTime
 
double endTime
 

Static Public Attributes

static const charCollapseTime = "CollapseTime"
 
static u32_t _MaxPtsSize = 0
 
static u32_t _NumOfCycles = 0
 
static u32_t _NumOfPWCCycles = 0
 
static u32_t _NumOfNodesInCycles = 0
 
static u32_t _MaxNumOfNodesInSCC = 0
 
- Static Public Attributes inherited from SVF::SVFStat
static bool printGeneralStats = true
 SVF's general statistics are only printed once even if you run multiple anayses.
 
static double timeOfBuildingLLVMModule = 0
 
static double timeOfBuildingSymbolTable = 0
 
static double timeOfBuildingSVFIR = 0
 

Private Attributes

AndersenBasepta
 

Additional Inherited Members

- Public Types inherited from SVF::SVFStat
enum  ClockType { Wall , CPU }
 
typedef OrderedMap< std::string, u32_tNUMStatMap
 
typedef OrderedMap< std::string, doubleTIMEStatMap
 
- Static Public Member Functions inherited from SVF::SVFStat
static double getClk (bool mark=false)
 
- Protected Attributes inherited from SVF::PTAStat
PointerAnalysispta
 
u32_t _vmrssUsageBefore
 
u32_t _vmrssUsageAfter
 
u32_t _vmsizeUsageBefore
 
u32_t _vmsizeUsageAfter
 

Detailed Description

Statistics of Andersen's analysis

Definition at line 48 of file WPAStat.h.

Constructor & Destructor Documentation

◆ AndersenStat()

AndersenStat::AndersenStat ( AndersenBase p)

Constructor

Definition at line 49 of file AndersenStat.cpp.

49 : PTAStat(p),pta(p)
50{
51 _NumOfNullPtr = 0;
54 startClk();
55}
cJSON * p
Definition cJSON.cpp:2559
u32_t _NumOfBlackholePtr
Definition WPAStat.h:64
u32_t _NumOfNullPtr
Definition WPAStat.h:62
AndersenBase * pta
Definition WPAStat.h:52
u32_t _NumOfConstantPtr
Definition WPAStat.h:63
virtual void startClk()
Definition SVFStat.h:58

◆ ~AndersenStat()

virtual SVF::AndersenStat::~AndersenStat ( )
inlinevirtual

Definition at line 68 of file WPAStat.h.

69 {
70
71 }

Member Function Documentation

◆ collectCycleInfo()

void AndersenStat::collectCycleInfo ( ConstraintGraph consCG)

Collect cycle information

Definition at line 60 of file AndersenStat.cpp.

61{
62 _NumOfCycles = 0;
65 NodeSet repNodes;
66 repNodes.clear();
67 for(ConstraintGraph::iterator it = consCG->begin(), eit = consCG->end(); it!=eit; ++it)
68 {
69 // sub nodes have been removed from the constraint graph, only rep nodes are left.
70 NodeID repNode = consCG->sccRepNode(it->first);
71 NodeBS& subNodes = consCG->sccSubNodes(repNode);
72 NodeBS clone = subNodes;
73 for (NodeBS::iterator it = subNodes.begin(), eit = subNodes.end(); it != eit; ++it)
74 {
75 NodeID nodeId = *it;
77 if (SVFUtil::isa<ObjVar>(pagNode) && pta->isFieldInsensitive(nodeId))
78 {
80 clone.reset(nodeId);
81 clone.set(baseId);
82 }
83 }
84 u32_t num = clone.count();
85 if (num > 1)
86 {
87 if(repNodes.insert(repNode).second)
88 {
90 if(consCG->isPWCNode(repNode))
92 }
95 }
96 }
97 _NumOfCycles += repNodes.size();
98}
unsigned u32_t
Definition CommandLine.h:18
static u32_t _NumOfCycles
Definition WPAStat.h:58
static u32_t _NumOfNodesInCycles
Definition WPAStat.h:60
static u32_t _MaxNumOfNodesInSCC
Definition WPAStat.h:61
static u32_t _NumOfPWCCycles
Definition WPAStat.h:59
NodeID sccRepNode(NodeID id) const
SCC rep/sub nodes methods.
Definition ConsG.h:235
NodeID getBaseObjVar(NodeID id)
Definition ConsG.h:320
bool isPWCNode(NodeID nodeId)
Check/Set PWC (positive weight cycle) flag.
Definition ConsG.h:350
NodeBS & sccSubNodes(NodeID id)
Definition ConsG.h:243
iterator begin()
Iterators.
IDToNodeMapTy::iterator iterator
Node Iterators.
NodeType * getGNode(NodeID id) const
Get a node.
bool isFieldInsensitive(NodeID id) const
SVFIR * getPAG() const
iterator begin() const
Set< NodeID > NodeSet
u32_t NodeID
Definition GeneralType.h:55
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ constraintGraphStat()

void AndersenStat::constraintGraphStat ( )

Definition at line 100 of file AndersenStat.cpp.

101{
102
103
105
106 u32_t numOfCopys = 0;
107 u32_t numOfGeps = 0;
108 // collect copy and gep edges
109 for(ConstraintEdge::ConstraintEdgeSetTy::iterator it = consCG->getDirectCGEdges().begin(),
110 eit = consCG->getDirectCGEdges().end(); it!=eit; ++it)
111 {
112 if(SVFUtil::isa<CopyCGEdge>(*it))
113 numOfCopys++;
114 else if(SVFUtil::isa<GepCGEdge>(*it))
115 numOfGeps++;
116 else
117 assert(false && "what else!!");
118 }
119
123 u32_t addrtotalIn = 0;
124 u32_t addrmaxIn = 0;
125 u32_t addrmaxOut = 0;
126 u32_t copytotalIn = 0;
127 u32_t copymaxIn = 0;
128 u32_t copymaxOut = 0;
129 u32_t loadtotalIn = 0;
130 u32_t loadmaxIn = 0;
131 u32_t loadmaxOut = 0;
133 u32_t storemaxIn = 0;
134 u32_t storemaxOut = 0;
135
136
137 for (ConstraintGraph::ConstraintNodeIDToNodeMapTy::iterator nodeIt = consCG->begin(), nodeEit = consCG->end();
138 nodeIt != nodeEit; nodeIt++)
139 {
141 if(nodeIt->second->getInEdges().empty() && nodeIt->second->getOutEdges().empty())
142 continue;
143 cgNodeNumber++;
144 if(SVFUtil::isa<ObjVar>(pta->getPAG()->getGNode(nodeIt->first)))
146
147 u32_t nCopyIn = nodeIt->second->getDirectInEdges().size();
148 if(nCopyIn > copymaxIn)
151 u32_t nCopyOut = nodeIt->second->getDirectOutEdges().size();
152 if(nCopyOut > copymaxOut)
154 u32_t nLoadIn = nodeIt->second->getLoadInEdges().size();
155 if(nLoadIn > loadmaxIn)
158 u32_t nLoadOut = nodeIt->second->getLoadOutEdges().size();
159 if(nLoadOut > loadmaxOut)
161 u32_t nStoreIn = nodeIt->second->getStoreInEdges().size();
162 if(nStoreIn > storemaxIn)
165 u32_t nStoreOut = nodeIt->second->getStoreOutEdges().size();
168 u32_t nAddrIn = nodeIt->second->getAddrInEdges().size();
169 if(nAddrIn > addrmaxIn)
172 u32_t nAddrOut = nodeIt->second->getAddrOutEdges().size();
173 if(nAddrOut > addrmaxOut)
175 }
181
182
183 PTNumStatMap["NumOfCGNode"] = totalNodeNumber;
184 PTNumStatMap["NumOfValidNode"] = cgNodeNumber;
185 PTNumStatMap["NumOfValidObjNode"] = objNodeNumber;
186 PTNumStatMap["NumOfCGEdge"] = consCG->getLoadCGEdges().size() + consCG->getStoreCGEdges().size()
188 PTNumStatMap["NumOfAddrs"] = consCG->getAddrCGEdges().size();
189 PTNumStatMap["NumOfCopys"] = numOfCopys;
190 PTNumStatMap["NumOfGeps"] = numOfGeps;
191 PTNumStatMap["NumOfLoads"] = consCG->getLoadCGEdges().size();
192 PTNumStatMap["NumOfStores"] = consCG->getStoreCGEdges().size();
193 PTNumStatMap["MaxInCopyEdge"] = copymaxIn;
194 PTNumStatMap["MaxOutCopyEdge"] = copymaxOut;
195 PTNumStatMap["MaxInLoadEdge"] = loadmaxIn;
196 PTNumStatMap["MaxOutLoadEdge"] = loadmaxOut;
197 PTNumStatMap["MaxInStoreEdge"] = storemaxIn;
198 PTNumStatMap["MaxOutStoreEdge"] = storemaxOut;
199 PTNumStatMap["MaxInAddrEdge"] = addrmaxIn;
200 PTNumStatMap["MaxOutAddrEdge"] = addrmaxOut;
201 timeStatMap["AvgIn/OutStoreEdge"] = storeavgIn;
202 timeStatMap["AvgIn/OutCopyEdge"] = copyavgIn;
203 timeStatMap["AvgIn/OutLoadEdge"] = loadavgIn;
204 timeStatMap["AvgIn/OutAddrEdge"] = addravgIn;
205 timeStatMap["AvgIn/OutEdge"] = avgIn;
206}
ConstraintGraph * getConstraintGraph()
Get constraint graph.
Definition Andersen.h:122
ConstraintEdge::ConstraintEdgeSetTy & getStoreCGEdges()
Get Store edges.
Definition ConsG.h:211
ConstraintEdge::ConstraintEdgeSetTy & getDirectCGEdges()
Get Copy/call/ret/gep edges.
Definition ConsG.h:201
ConstraintEdge::ConstraintEdgeSetTy & getLoadCGEdges()
Get Load edges.
Definition ConsG.h:206
ConstraintEdge::ConstraintEdgeSetTy & getAddrCGEdges()
Get SVFIR edge.
Definition ConsG.h:196
NUMStatMap PTNumStatMap
Definition SVFStat.h:77
TIMEStatMap timeStatMap
Definition SVFStat.h:78

◆ performStat()

void AndersenStat::performStat ( )
virtual

Start here

Implements SVF::SVFStat.

Definition at line 264 of file AndersenStat.cpp.

265{
266
267 assert(SVFUtil::isa<AndersenBase>(pta) && "not an andersen pta pass!! what else??");
268 endClk();
269
270 SVFIR* pag = pta->getPAG();
272
273 // collect constraint graph cycles
274 collectCycleInfo(consCG);
275
276 // stat null ptr number
277 statNullPtr();
278
283 for (SVFIR::iterator iter = pta->getPAG()->begin(), eiter = pta->getPAG()->end();
284 iter != eiter; ++iter)
285 {
286 NodeID node = iter->first;
287 const PointsTo& pts = pta->getPts(node);
288 u32_t size = pts.count();
290 totalPtsSize+=size;
291
293 {
295 totalTopLevPtsSize+=size;
296 }
297
298 if(size > _MaxPtsSize )
299 _MaxPtsSize = size;
300 }
301
302
304
306
307 timeStatMap["TotalTime"] = (endTime - startTime)/TIMEINTERVAL;
308 timeStatMap["SCCDetectTime"] = Andersen::timeOfSCCDetection;
309 timeStatMap["SCCMergeTime"] = Andersen::timeOfSCCMerges;
311
315
316 PTNumStatMap["TotalPointers"] = pag->getValueNodeNum() + pag->getFieldValNodeNum();
317 PTNumStatMap["TotalObjects"] = pag->getObjectNodeNum() + pag->getFieldObjNodeNum();
318
319
325
326 PTNumStatMap["NumOfSFRs"] = Andersen::numOfSfrs;
327 PTNumStatMap["NumOfFieldExpand"] = Andersen::numOfFieldExpand;
328
329 PTNumStatMap["Pointers"] = pag->getValueNodeNum();
330 PTNumStatMap["MemObjects"] = pag->getObjectNodeNum();
331 PTNumStatMap["DummyFieldPtrs"] = pag->getFieldValNodeNum();
332 PTNumStatMap["FieldObjs"] = pag->getFieldObjNodeNum();
333
334 timeStatMap["AvgPtsSetSize"] = (double)totalPtsSize/totalPointers;;
336
337 PTNumStatMap["MaxPtsSetSize"] = _MaxPtsSize;
338
339 PTNumStatMap["SolveIterations"] = pta->numOfIteration;
340
341 PTNumStatMap["IndCallSites"] = consCG->getIndirectCallsites().size();
342 PTNumStatMap["IndEdgeSolved"] = pta->getNumOfResolvedIndCallEdge();
343
344 PTNumStatMap["NumOfSCCDetect"] = Andersen::numOfSCCDetection;
345 PTNumStatMap["TotalCycleNum"] = _NumOfCycles;
346 PTNumStatMap["TotalPWCCycleNum"] = _NumOfPWCCycles;
347 PTNumStatMap["NodesInCycles"] = _NumOfNodesInCycles;
348 PTNumStatMap["MaxNodesInSCC"] = _MaxNumOfNodesInSCC;
349 PTNumStatMap["NullPointer"] = _NumOfNullPtr;
350 PTNumStatMap["PointsToConstPtr"] = _NumOfConstantPtr;
351 PTNumStatMap["PointsToBlkPtr"] = _NumOfBlackholePtr;
352
353 PTAStat::printStat("Andersen Pointer Analysis Stats");
354}
#define TIMEINTERVAL
Definition SVFType.h:512
static double timeOfSCCMerges
Definition Andersen.h:167
static u32_t numOfProcessedCopy
Number of processed Addr edge.
Definition Andersen.h:158
static u32_t numOfSCCDetection
Definition Andersen.h:165
static u32_t numOfSfrs
Number of processed Store edge.
Definition Andersen.h:162
static double timeOfUpdateCallGraph
Definition Andersen.h:173
static u32_t numOfProcessedStore
Number of processed Load edge.
Definition Andersen.h:161
static u32_t numOfProcessedAddr
Statistics.
Definition Andersen.h:157
static u32_t numOfProcessedLoad
Number of processed Gep edge.
Definition Andersen.h:160
static double timeOfSCCDetection
Definition Andersen.h:166
static u32_t numOfFieldExpand
Definition Andersen.h:163
static double timeOfProcessLoadStore
Definition Andersen.h:172
static u32_t numOfProcessedGep
Number of processed Copy edge.
Definition Andersen.h:159
static double timeOfProcessCopyGep
Definition Andersen.h:171
static double timeOfCollapse
Definition Andersen.h:168
static const char * CollapseTime
Definition WPAStat.h:55
static u32_t _MaxPtsSize
Definition WPAStat.h:57
void collectCycleInfo(ConstraintGraph *consCG)
const PointsTo & getPts(NodeID id) override
const SVFIR::CallSiteToFunPtrMap & getIndirectCallsites() const
Wrappers for invoking SVFIR methods.
Definition ConsG.h:304
u32_t getValueNodeNum() const
Definition IRGraph.h:186
u32_t getObjectNodeNum() const
Definition IRGraph.h:190
void performStat() override
Definition PTAStat.cpp:52
u32_t getNumOfResolvedIndCallEdge() const
Return number of resolved indirect call edges.
u32_t count() const
Returns number of elements.
Definition PointsTo.cpp:111
u32_t getFieldObjNodeNum() const
Definition SVFIR.h:339
bool isValidTopLevelPtr(const SVFVar *node)
Definition SVFIR.cpp:685
u32_t getFieldValNodeNum() const
Node and edge statistics.
Definition SVFIR.h:335
virtual void printStat(std::string str="")
Definition SVFStat.cpp:67
virtual void endClk()
Definition SVFStat.h:63
double endTime
Definition SVFStat.h:81
double startTime
Definition SVFStat.h:80
u32_t numOfIteration
num of iterations during constraint solving
Definition WPASolver.h:200

◆ statNullPtr()

void AndersenStat::statNullPtr ( )

Stat null pointers

TODO: change the condition here to fetch the points-to set

Definition at line 210 of file AndersenStat.cpp.

211{
212
213 _NumOfNullPtr = 0;
214 for (SVFIR::iterator iter = pta->getPAG()->begin(), eiter = pta->getPAG()->end();
215 iter != eiter; ++iter)
216 {
217 NodeID pagNodeId = iter->first;
218 PAGNode* pagNode = iter->second;
219 if (SVFUtil::isa<ValVar>(pagNode) == false)
220 continue;
223 if (inComingStore.empty()==false || outGoingLoad.empty()==false)
224 {
226 const PointsTo& pts = pta->getPts(pagNodeId);
229
232
233 if(pts.empty())
234 {
235 std::string str;
236 std::stringstream rawstr(str);
237 if (!SVFUtil::isa<DummyValVar>(pagNode) && !SVFUtil::isa<DummyObjVar>(pagNode) )
238 {
239 // if a pointer is in dead function, we do not care
240 if(pagNode->getValue()->ptrInUncalledFunction() == false)
241 {
243 rawstr << "##Null Pointer : (NodeID " << pagNode->getId()
244 << ") PtrName:" << pagNode->getValue()->getName();
245 writeWrnMsg(rawstr.str());
246 //pagNode->getValue()->dump();
247 }
248 }
249 else
250 {
252 rawstr << "##Null Pointer : (NodeID " << pagNode->getId() << ")";
253 writeWrnMsg(rawstr.str());
254 }
255 }
256 }
257 }
258
259}
bool containBlackHoleNode(const PointsTo &pts)
Determine whether a points-to contains a black hole or constant node.
bool containConstantNode(const PointsTo &pts)
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
SVFStmt::SVFStmtSetTy & getIncomingEdges(SVFStmt::PEDGEK kind)
Get incoming SVFIR statements (edges)
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition SVFUtil.cpp:67

Member Data Documentation

◆ _MaxNumOfNodesInSCC

u32_t AndersenStat::_MaxNumOfNodesInSCC = 0
static

Definition at line 61 of file WPAStat.h.

◆ _MaxPtsSize

u32_t AndersenStat::_MaxPtsSize = 0
static

Definition at line 57 of file WPAStat.h.

◆ _NumOfBlackholePtr

u32_t SVF::AndersenStat::_NumOfBlackholePtr

Definition at line 64 of file WPAStat.h.

◆ _NumOfConstantPtr

u32_t SVF::AndersenStat::_NumOfConstantPtr

Definition at line 63 of file WPAStat.h.

◆ _NumOfCycles

u32_t AndersenStat::_NumOfCycles = 0
static

Definition at line 58 of file WPAStat.h.

◆ _NumOfNodesInCycles

u32_t AndersenStat::_NumOfNodesInCycles = 0
static

Definition at line 60 of file WPAStat.h.

◆ _NumOfNullPtr

u32_t SVF::AndersenStat::_NumOfNullPtr

Definition at line 62 of file WPAStat.h.

◆ _NumOfPWCCycles

u32_t AndersenStat::_NumOfPWCCycles = 0
static

Definition at line 59 of file WPAStat.h.

◆ CollapseTime

const char * AndersenStat::CollapseTime = "CollapseTime"
static

Definition at line 55 of file WPAStat.h.

◆ pta

AndersenBase* SVF::AndersenStat::pta
private

Definition at line 52 of file WPAStat.h.


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