Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFGStat.cpp
Go to the documentation of this file.
1//===- SVFGStat.cpp -- SVFG statistics---------------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2017> <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 * SVFGStat.cpp
25 *
26 * Created on: 28/11/2013
27 * Author: yesen
28 */
29
30#include "Graphs/SVFG.h"
31#include "Graphs/SVFGStat.h"
32#include "Graphs/PTACallGraph.h"
33
34using namespace SVF;
35using namespace std;
36
37const char* MemSSAStat::TotalTimeOfConstructMemSSA = "TotalMSSATime";
38const char* MemSSAStat::TimeOfGeneratingMemRegions = "GenRegionTime";
39const char* MemSSAStat::TimeOfCreateMUCHI = "GenMUCHITime";
40const char* MemSSAStat::TimeOfInsertingPHI = "InsertPHITime";
41const char* MemSSAStat::TimeOfSSARenaming = "SSARenameTime";
42
43const char* MemSSAStat::NumOfMaxRegion = "MaxRegSize";
44const char* MemSSAStat::NumOfAveragePtsInRegion = "AverageRegSize";
45const char* MemSSAStat::NumOfMemRegions = "MemRegions";
46const char* MemSSAStat::NumOfEntryChi = "FunEntryChi";
47const char* MemSSAStat::NumOfRetMu = "FunRetMu";
48const char* MemSSAStat::NumOfCSChi = "CSChiNode";
49const char* MemSSAStat::NumOfCSMu = "CSMuNode";
50const char* MemSSAStat::NumOfLoadMu = "LoadMuNode";
51const char* MemSSAStat::NumOfStoreChi = "StoreChiNode";
52const char* MemSSAStat::NumOfMSSAPhi = "MSSAPhi";
53
54const char* MemSSAStat::NumOfFunHasEntryChi = "FunHasEntryChi";
55const char* MemSSAStat::NumOfFunHasRetMu = "FunHasRetMu";
56const char* MemSSAStat::NumOfCSHasChi = "CSHasChi";
57const char* MemSSAStat::NumOfCSHasMu = "CSHasMu";
58const char* MemSSAStat::NumOfLoadHasMu = "LoadHasMu";
59const char* MemSSAStat::NumOfStoreHasChi = "StoreHasChi";
60const char* MemSSAStat::NumOfBBHasMSSAPhi = "BBHasMSSAPhi";
61
66{
67 mssa = memSSA;
68 startClk();
69}
70
75{
76
77 endClk();
78
81
84 MRGenerator::MRSet & mrSet = mrGenerator->getMRSet();
85 MRGenerator::MRSet::const_iterator it = mrSet.begin();
86 MRGenerator::MRSet::const_iterator eit = mrSet.end();
87 for (; it != eit; it++)
88 {
89 const MemRegion* region = *it;
94 }
95
101
112
120
121 printStat();
122
123}
124
129{
130 PTAStat::printStat("Memory SSA Statistics");
131}
132
147
168
170{
171 return scc->repNode(id);
172}
174{
175 return scc->isInCycle(id);
176}
177
179{
180 endClk();
181
182 clear();
183
184 processGraph();
185
186 timeStatMap["TotalTime"] = (endTime - startTime)/TIMEINTERVAL;
187
189
191
193
195
197
198 PTNumStatMap["TotalNode"] = numOfNodes;
199
200 PTNumStatMap["FormalIn"] = numOfFormalIn;
201 PTNumStatMap["FormalOut"] = numOfFormalOut;
202 PTNumStatMap["FormalParam"] = numOfFormalParam;
203 PTNumStatMap["FormalRet"] = numOfFormalRet;
204
205 PTNumStatMap["ActualIn"] = numOfActualIn;
206 PTNumStatMap["ActualOut"] = numOfActualOut;
207 PTNumStatMap["ActualParam"] = numOfActualParam;
208 PTNumStatMap["ActualRet"] = numOfActualRet;
209
210 PTNumStatMap["Addr"] = numOfAddr;
211 PTNumStatMap["Copy"] = numOfCopy;
212 PTNumStatMap["Gep"] = numOfGep;
213 PTNumStatMap["Store"] = numOfStore;
214 PTNumStatMap["Load"] = numOfLoad;
215
216 PTNumStatMap["PHI"] = numOfPhi;
217 PTNumStatMap["MSSAPhi"] = numOfMSSAPhi;
218
219 timeStatMap["AvgWeight"] = (totalIndInEdge == 0) ? 0 : ((double)avgWeight / totalIndInEdge);
220
221 PTNumStatMap["TotalEdge"] = totalInEdge;
222 PTNumStatMap["DirectEdge"] = totalInEdge - totalIndInEdge;
223 PTNumStatMap["IndirectEdge"] = totalIndInEdge;
224 PTNumStatMap["IndirectEdgeLabels"] = totalIndEdgeLabels;
225
226 PTNumStatMap["IndCallEdge"] = totalIndCallEdge;
227 PTNumStatMap["IndRetEdge"] = totalIndRetEdge;
228 PTNumStatMap["DirectCallEdge"] = totalDirCallEdge;
229 PTNumStatMap["DirectRetEdge"] = totalDirRetEdge;
230
231 PTNumStatMap["AvgInDegree"] = avgInDegree;
232 PTNumStatMap["AvgOutDegree"] = avgOutDegree;
233 PTNumStatMap["MaxInDegree"] = maxInDegree;
234 PTNumStatMap["MaxOutDegree"] = maxOutDegree;
235
236 PTNumStatMap["AvgIndInDeg"] = avgIndInDegree;
237 PTNumStatMap["AvgIndOutDeg"] = avgIndOutDegree;
238 PTNumStatMap["MaxIndInDeg"] = maxIndInDegree;
239 PTNumStatMap["MaxIndOutDeg"] = maxIndOutDegree;
240
241 printStat();
242}
243
245{
248
249 SVFG::SVFGNodeIDToNodeMapTy::iterator it = graph->begin();
250 SVFG::SVFGNodeIDToNodeMapTy::iterator eit = graph->end();
251 for (; it != eit; ++it)
252 {
253 numOfNodes++;
254 if (SVFUtil::isa<FormalINSVFGNode>(it->second))
256 else if (SVFUtil::isa<FormalOUTSVFGNode>(it->second))
258 else if (SVFUtil::isa<FormalParmSVFGNode>(it->second))
260 else if (SVFUtil::isa<FormalRetSVFGNode>(it->second))
262 else if (SVFUtil::isa<ActualINSVFGNode>(it->second))
264 else if (SVFUtil::isa<ActualOUTSVFGNode>(it->second))
266 else if (SVFUtil::isa<ActualParmSVFGNode>(it->second))
268 else if (SVFUtil::isa<ActualRetSVFGNode>(it->second))
270 else if (SVFUtil::isa<AddrSVFGNode>(it->second))
271 numOfAddr++;
272 else if (SVFUtil::isa<CopySVFGNode>(it->second))
273 numOfCopy++;
274 else if (SVFUtil::isa<GepSVFGNode>(it->second))
275 numOfGep++;
276 else if (SVFUtil::isa<LoadSVFGNode>(it->second))
277 numOfLoad++;
278 else if (SVFUtil::isa<StoreSVFGNode>(it->second))
279 numOfStore++;
280 else if (SVFUtil::isa<PHISVFGNode>(it->second))
281 numOfPhi++;
282 else if (SVFUtil::isa<MSSAPHISVFGNode>(it->second))
283 numOfMSSAPhi++;
284
285 SVFGNode* node = it->second;
287 }
288
289 if (numOfNodes > 0)
290 {
293 }
294
295 if (!nodeHasIndInEdge.empty())
297
298 if (!nodeHasIndOutEdge.empty())
300}
301
303{
304 // Incoming edge
306 // total in edge
307 if (inEdges.size() > maxInDegree)
308 maxInDegree = inEdges.size();
309 totalInEdge += inEdges.size();
310
311 // indirect in edge
312 u32_t indInEdges = 0;
313 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeIt = inEdges.begin();
314 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeEit = inEdges.end();
315 for (; edgeIt != edgeEit; ++edgeIt)
316 {
317 if (IndirectSVFGEdge* edge = SVFUtil::dyn_cast<IndirectSVFGEdge>(*edgeIt))
318 {
319 indInEdges++;
320 nodeHasIndInEdge.insert(node->getId());
321 // get edge's weight
322 // TODO: try a new method to calculate weight.
323 const NodeBS& cpts = edge->getPointsTo();
324 avgWeight += cpts.count();
325 totalIndEdgeLabels += cpts.count();
326 }
327
328 if (SVFUtil::isa<CallDirSVFGEdge>(*edgeIt))
330 else if (SVFUtil::isa<CallIndSVFGEdge>(*edgeIt))
332 else if (SVFUtil::isa<RetDirSVFGEdge>(*edgeIt))
334 else if (SVFUtil::isa<RetIndSVFGEdge>(*edgeIt))
336 }
337
341
342 /*-----------------------------------------------------*/
343
344 // Outgoing edge
346 // total out edge
347 if (outEdges.size() > maxOutDegree)
348 maxOutDegree = outEdges.size();
349 totalOutEdge += outEdges.size();
350
351 // indirect out edge
352 u32_t indOutEdges = 0;
353 edgeIt = outEdges.begin();
354 edgeEit = outEdges.end();
355 for (; edgeIt != edgeEit; ++edgeIt)
356 {
357 if ((*edgeIt)->isIndirectVFGEdge())
358 {
359 indOutEdges++;
360 nodeHasIndOutEdge.insert(node->getId());
361 }
362 }
363
367}
368
370{
371
372 generalNumMap.clear();
373 PTNumStatMap.clear();
374 timeStatMap.clear();
375
376 unsigned totalNode = 0;
377 unsigned totalCycle = 0;
378 unsigned nodeInCycle = 0;
379 unsigned maxNodeInCycle = 0;
380 unsigned totalEdge = 0;
381 unsigned edgeInCycle = 0;
382
383 unsigned totalDirectEdge = 0;
384 unsigned directEdgeInCycle = 0;
385 unsigned totalIndirectEdge = 0;
386 unsigned indirectEdgeInCycle = 0;
387 unsigned totalCallEdge = 0;
388 unsigned callEdgeInCycle = 0;
389 unsigned insensitiveCallEdge = 0;
390 unsigned totalRetEdge = 0;
391 unsigned retEdgeInCycle = 0;
392 unsigned insensitiveRetEdge = 0;
393
395 svfgSCC->find();
396
398 SVFG::SVFGNodeIDToNodeMapTy::iterator it = graph->begin();
399 SVFG::SVFGNodeIDToNodeMapTy::iterator eit = graph->end();
400 for (; it != eit; ++it)
401 {
402 totalNode++;
403 if(svfgSCC->isInCycle(it->first))
404 {
405 nodeInCycle++;
406 sccRepNodeSet.insert(svfgSCC->repNode(it->first));
407 const NodeBS& subNodes = svfgSCC->subNodes(it->first);
408 if(subNodes.count() > maxNodeInCycle)
409 maxNodeInCycle = subNodes.count();
410 }
411
412 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeIt = it->second->InEdgeBegin();
413 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeEit = it->second->InEdgeEnd();
414 for (; edgeIt != edgeEit; ++edgeIt)
415 {
416
417 const SVFGEdge *edge = *edgeIt;
418 totalEdge++;
419 bool eCycle = false;
420 if(getSCCRep(svfgSCC,edge->getSrcID()) == getSCCRep(svfgSCC,edge->getDstID()))
421 {
422 edgeInCycle++;
423 eCycle = true;
424 }
425
426 if (edge->isDirectVFGEdge())
427 {
429 if(eCycle)
431
432 }
433 if (edge->isIndirectVFGEdge())
434 {
436 if(eCycle)
438 }
439 if (edge->isCallVFGEdge())
440 {
442 if(eCycle)
443 {
445 }
446
448 {
450 }
451 }
452 if (edge->isRetVFGEdge())
453 {
454 totalRetEdge++;
455 if(eCycle)
456 {
458 }
459
461 {
463 }
464 }
465 }
466 }
467
468
469 totalCycle = sccRepNodeSet.size();
470
471
472 PTNumStatMap["TotalNode"] = totalNode;
473 PTNumStatMap["TotalCycle"] = totalCycle;
474 PTNumStatMap["NodeInCycle"] = nodeInCycle;
475 PTNumStatMap["MaxNodeInCycle"] = maxNodeInCycle;
476 PTNumStatMap["TotalEdge"] = totalEdge;
477 PTNumStatMap["EdgeInCycle"] = edgeInCycle;
478
479 PTNumStatMap["TotalDirEdge"] = totalDirectEdge;
480 PTNumStatMap["DirEdgeInCycle"] = directEdgeInCycle;
481 PTNumStatMap["TotalIndEdge"] = totalIndirectEdge;
482 PTNumStatMap["IndEdgeInCycle"] = indirectEdgeInCycle;
483
484 PTNumStatMap["TotalCallEdge"] = totalCallEdge;
485 PTNumStatMap["CallEdgeInCycle"] = callEdgeInCycle;
486 PTNumStatMap["InsenCallEdge"] = insensitiveCallEdge;
487
488 PTNumStatMap["TotalRetEdge"] = totalRetEdge;
489 PTNumStatMap["RetEdgeInCycle"] = retEdgeInCycle;
490 PTNumStatMap["InsenRetEdge"] = insensitiveRetEdge;
491
492
493 PTAStat::printStat("SVFG SCC Stat");
494
495 delete svfgSCC;
496
497}
498
500{
501 PTAStat::printStat("SVFG Statistics");
502}
#define TIMEINTERVAL
Definition SVFType.h:512
iterator begin()
Iterators.
const GEdgeSetTy & getOutEdges() const
const GEdgeSetTy & getInEdges() const
OrderedSet< const MemRegion *, MemRegion::equalMemRegion > MRSet
Get typedef from Pointer Analysis.
Definition MemRegion.h:141
u32_t getMRNum() const
Definition MemRegion.h:420
Memory Region class.
Definition MemRegion.h:56
u32_t getRegionSize() const
Return memory object number inside a region.
Definition MemRegion.h:122
static const char * TimeOfInsertingPHI
Time for inserting phis.
Definition SVFGStat.h:55
static const char * NumOfRetMu
Number of function return mu.
Definition SVFGStat.h:62
static const char * NumOfLoadMu
Number of load mu.
Definition SVFGStat.h:65
static const char * NumOfStoreHasChi
Number of stores which have chi.
Definition SVFGStat.h:74
static const char * TimeOfCreateMUCHI
Time for generating mu/chi for load/store/calls.
Definition SVFGStat.h:54
static const char * NumOfMSSAPhi
Number of mssa phi.
Definition SVFGStat.h:67
MemSSAStat(MemSSA *)
Definition SVFGStat.cpp:65
static const char * NumOfBBHasMSSAPhi
Number of basic blocks which have mssa phi.
Definition SVFGStat.h:75
static const char * NumOfAveragePtsInRegion
Number of average points-to set in region.
Definition SVFGStat.h:59
static const char * TimeOfGeneratingMemRegions
Time for allocating regions.
Definition SVFGStat.h:53
static const char * NumOfCSMu
Number of call site mu.
Definition SVFGStat.h:64
static const char * TotalTimeOfConstructMemSSA
Total time for constructing memory SSA.
Definition SVFGStat.h:52
static const char * NumOfStoreChi
Number of store chi.
Definition SVFGStat.h:66
static const char * TimeOfSSARenaming
Time for SSA rename.
Definition SVFGStat.h:56
virtual void performStat() override
Definition SVFGStat.cpp:74
static const char * NumOfCSChi
Number of call site chi.
Definition SVFGStat.h:63
static const char * NumOfMemRegions
Number of memory regions.
Definition SVFGStat.h:60
static const char * NumOfFunHasRetMu
Number of functions which have return mu.
Definition SVFGStat.h:70
MemSSA * mssa
Definition SVFGStat.h:88
static const char * NumOfMaxRegion
Number of max points-to set in region.
Definition SVFGStat.h:58
static const char * NumOfLoadHasMu
Number of loads which have mu.
Definition SVFGStat.h:73
virtual void printStat(std::string str="") override
Definition SVFGStat.cpp:128
static const char * NumOfEntryChi
Number of function entry chi.
Definition SVFGStat.h:61
static const char * NumOfCSHasChi
Number of call sites which have chi.
Definition SVFGStat.h:71
static const char * NumOfFunHasEntryChi
Number of functions which have entry chi.
Definition SVFGStat.h:69
static const char * NumOfCSHasMu
Number of call sites which have mu.
Definition SVFGStat.h:72
u32_t getFunEntryChiNum() const
Definition MemSSA.cpp:492
LoadToMUSetMap & getLoadToMUSetMap()
Definition MemSSA.h:405
u32_t getCallSiteChiNum() const
Definition MemSSA.cpp:543
static double timeOfGeneratingMemRegions
Statistics.
Definition MemSSA.h:107
static double timeOfInsertingPHI
Time for inserting phis.
Definition MemSSA.h:109
static double timeOfCreateMUCHI
Time for generating mu/chi for load/store/calls.
Definition MemSSA.h:108
StoreToChiSetMap & getStoreToChiSetMap()
Definition MemSSA.h:409
CallSiteToMUSetMap & getCallSiteToMuSetMap()
Definition MemSSA.h:421
u32_t getFunRetMuNum() const
Definition MemSSA.cpp:509
FunToEntryChiSetMap & getFunToEntryChiSetMap()
Definition MemSSA.h:417
static double timeOfSSARenaming
Time for SSA rename.
Definition MemSSA.h:110
BBToPhiSetMap & getBBToPhiSetMap()
Definition MemSSA.h:429
FunToReturnMuSetMap & getFunToRetMuSetMap()
Definition MemSSA.h:413
u32_t getBBPhiNum() const
Definition MemSSA.cpp:560
u32_t getCallSiteMuNum() const
Definition MemSSA.cpp:526
u32_t getStoreChiNum() const
Definition MemSSA.cpp:475
u32_t getLoadMuNum() const
Stat methods.
Definition MemSSA.cpp:458
MRGenerator * getMRGenerator()
Return MRGenerator.
Definition MemSSA.h:313
CallSiteToCHISetMap & getCallSiteToChiSetMap()
Definition MemSSA.h:425
NodeID repNode(NodeID n) const
get the rep node if not found return itself
Definition SCC.h:139
bool isInCycle(NodeID n) const
whether the node is in a cycle
Definition SCC.h:149
NodeID getId() const
Get ID.
virtual void performStat() override
Definition SVFGStat.cpp:178
int numOfActualParam
Definition SVFGStat.h:181
int totalIndEdgeLabels
Total number of l –o--> lp.
Definition SVFGStat.h:197
double connectDirSVFGEdgeTimeStart
Definition SVFGStat.h:222
int totalIndCallEdge
Definition SVFGStat.h:199
int numOfActualOut
number of actual out svfg nodes.
Definition SVFGStat.h:180
int avgOutDegree
average out degrees of SVFG nodes.
Definition SVFGStat.h:207
SCCDetection< SVFG * > SVFGSCC
Definition SVFGStat.h:97
int totalOutEdge
Total number of outgoing SVFG edges.
Definition SVFGStat.h:194
double svfgOptTimeStart
Definition SVFGStat.h:228
int totalDirCallEdge
Definition SVFGStat.h:201
int numOfFormalParam
Definition SVFGStat.h:176
int numOfFormalRet
Definition SVFGStat.h:177
double connectIndSVFGEdgeTimeStart
Definition SVFGStat.h:225
virtual void printStat(std::string str="") override
Definition SVFGStat.cpp:499
u32_t maxIndInDegree
max indirect in degrees of SVFG nodes.
Definition SVFGStat.h:213
double addAddrTakenNodeTimeEnd
Definition SVFGStat.h:220
double connectIndSVFGEdgeTimeEnd
Definition SVFGStat.h:226
int avgIndInDegree
average indirect in degrees of SVFG nodes.
Definition SVFGStat.h:211
void processGraph()
Definition SVFGStat.cpp:244
SVFG * graph
Definition SVFGStat.h:170
NodeID nodeInCycle(SVFGSCC *scc, NodeID id) const
Definition SVFGStat.cpp:173
int avgInDegree
average in degrees of SVFG nodes.
Definition SVFGStat.h:206
int numOfStore
number of store svfg nodes.
Definition SVFGStat.h:185
int numOfActualIn
number of actual in svfg nodes.
Definition SVFGStat.h:179
u32_t maxInDegree
max in degrees of SVFG nodes.
Definition SVFGStat.h:208
void calculateNodeDegrees(SVFGNode *node, NodeSet &nodeHasIndInEdge, NodeSet &nodeHasIndOutEdge)
Definition SVFGStat.cpp:302
int avgWeight
average weight.
Definition SVFGStat.h:204
int totalDirRetEdge
Definition SVFGStat.h:202
u32_t maxOutDegree
max out degrees of SVFG nodes.
Definition SVFGStat.h:209
int avgIndOutDegree
average indirect out degrees of SVFG nodes.
Definition SVFGStat.h:212
int totalInEdge
Total number of incoming SVFG edges.
Definition SVFGStat.h:193
int numOfLoad
number of load svfg nodes.
Definition SVFGStat.h:184
virtual void performSCCStat(SVFGEdgeSet insensitiveCalRetEdges)
Definition SVFGStat.cpp:369
double addTopLevelNodeTimeEnd
Definition SVFGStat.h:217
int totalIndInEdge
Total number of indirect SVFG edges.
Definition SVFGStat.h:195
NodeID getSCCRep(SVFGSCC *scc, NodeID id) const
Definition SVFGStat.cpp:169
int totalIndOutEdge
Definition SVFGStat.h:196
int numOfMSSAPhi
number of mssa phi svfg nodes.
Definition SVFGStat.h:190
double addAddrTakenNodeTimeStart
Definition SVFGStat.h:219
int numOfFormalOut
number of formal out svfg nodes.
Definition SVFGStat.h:175
int numOfNodes
number of svfg nodes.
Definition SVFGStat.h:172
int numOfFormalIn
number of formal in svfg nodes.
Definition SVFGStat.h:174
double svfgOptTimeEnd
Definition SVFGStat.h:229
double connectDirSVFGEdgeTimeEnd
Definition SVFGStat.h:223
u32_t maxIndOutDegree
max indirect out degrees of SVFG nodes.
Definition SVFGStat.h:214
int numOfActualRet
Definition SVFGStat.h:182
double addTopLevelNodeTimeStart
Definition SVFGStat.h:216
SVFGStat(SVFG *g)
Definition SVFGStat.cpp:136
int totalIndRetEdge
Definition SVFGStat.h:200
OrderedSet< const SVFGEdge * > SVFGEdgeSet
Definition SVFGStat.h:96
NUMStatMap generalNumMap
Definition SVFStat.h:76
NUMStatMap PTNumStatMap
Definition SVFStat.h:77
virtual void printStat(std::string str="")
Definition SVFStat.cpp:67
virtual void endClk()
Definition SVFStat.h:63
TIMEStatMap timeStatMap
Definition SVFStat.h:78
virtual void startClk()
Definition SVFStat.h:58
double endTime
Definition SVFStat.h:81
double startTime
Definition SVFStat.h:80
unsigned count() const
VFGEdgeSetTy SVFGEdgeSetTy
Definition VFGEdge.h:118
for isBitcode
Definition BasicTypes.h:68
Set< NodeID > NodeSet
u32_t NodeID
Definition GeneralType.h:55
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:46