Static Value-Flow Analysis
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
SVF::SVFStat Class Referenceabstract

#include <SVFStat.h>

Inheritance diagram for SVF::SVFStat:
SVF::AEStat SVF::PTAStat SVF::AndersenStat SVF::CFLStat SVF::DDAStat SVF::FlowSensitiveStat SVF::ICFGStat SVF::MTAStat SVF::MemSSAStat SVF::SVFGStat SVF::VersionedFlowSensitiveStat

Public Types

enum  ClockType { Wall , CPU }
 
typedef OrderedMap< std::string, u32_tNUMStatMap
 
typedef OrderedMap< std::string, double > TIMEStatMap
 

Public Member Functions

 SVFStat ()
 
virtual ~SVFStat ()
 
virtual void startClk ()
 
virtual void endClk ()
 
virtual void performStat ()=0
 
virtual void printStat (std::string str="")
 
virtual void performStatPerQuery (NodeID)
 
virtual void printStatPerQuery (NodeID, const PointsTo &)
 
virtual void callgraphStat ()
 

Static Public Member Functions

static double getClk (bool mark=false)
 

Public Attributes

NUMStatMap generalNumMap
 
NUMStatMap PTNumStatMap
 
TIMEStatMap timeStatMap
 
double startTime
 
double endTime
 

Static Public Attributes

static bool printGeneralStats = true
 SVF's general statistics are only printed once even if you run multiple anayses. More...
 
static double timeOfBuildingLLVMModule = 0
 
static double timeOfBuildingSymbolTable = 0
 
static double timeOfBuildingSVFIR = 0
 

Private Member Functions

void branchStat ()
 

Private Attributes

std::string moduleName
 

Detailed Description

Pointer Analysis Statistics

Definition at line 40 of file SVFStat.h.

Member Typedef Documentation

◆ NUMStatMap

Definition at line 44 of file SVFStat.h.

◆ TIMEStatMap

Definition at line 46 of file SVFStat.h.

Member Enumeration Documentation

◆ ClockType

Enumerator
Wall 
CPU 

Definition at line 48 of file SVFStat.h.

49  {
50  Wall,
51  CPU,
52  };

Constructor & Destructor Documentation

◆ SVFStat()

SVFStat::SVFStat ( )

Definition at line 41 of file SVFStat.cpp.

41  : startTime(0), endTime(0)
42 {
43  assert((Options::ClockType() == ClockType::Wall || Options::ClockType() == ClockType::CPU)
44  && "PTAStat: unknown clock type!");
45 }
static const OptionMap< enum PTAStat::ClockType > ClockType
Definition: Options.h:24
double endTime
Definition: SVFStat.h:81
double startTime
Definition: SVFStat.h:80

◆ ~SVFStat()

virtual SVF::SVFStat::~SVFStat ( )
inlinevirtual

Definition at line 56 of file SVFStat.h.

56 {}

Member Function Documentation

◆ branchStat()

void SVFStat::branchStat ( )
private

Definition at line 215 of file SVFStat.cpp.

216 {
217  u32_t numOfBB_2Succ = 0;
218  u32_t numOfBB_3Succ = 0;
219  PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph();
220  for (const auto& item: *svfirCallGraph)
221  {
222  const SVFFunction* func = item.second->getFunction();
223  for (SVFFunction::const_iterator bbIt = func->begin(), bbEit = func->end();
224  bbIt != bbEit; ++bbIt)
225  {
226  const SVFBasicBlock* bb = *bbIt;
227  u32_t numOfSucc = bb->getNumSuccessors();
228  if (numOfSucc == 2)
229  numOfBB_2Succ++;
230  else if (numOfSucc > 2)
231  numOfBB_3Succ++;
232  }
233  }
234 
235  generalNumMap["BBWith2Succ"] = numOfBB_2Succ;
236  generalNumMap["BBWith3Succ"] = numOfBB_3Succ;
237 }
unsigned u32_t
Definition: CommandLine.h:18
cJSON * item
Definition: cJSON.h:222
u32_t getNumSuccessors() const
Definition: SVFValue.h:615
const_iterator end() const
Definition: SVFValue.h:440
const_iterator begin() const
Definition: SVFValue.h:435
std::vector< const SVFBasicBlock * >::const_iterator const_iterator
Definition: SVFValue.h:305
PTACallGraph * getCallGraph()
Definition: SVFIR.h:192
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition: SVFIR.h:115
NUMStatMap generalNumMap
Definition: SVFStat.h:76

◆ callgraphStat()

virtual void SVF::SVFStat::callgraphStat ( )
inlinevirtual

Reimplemented in SVF::PTAStat.

Definition at line 91 of file SVFStat.h.

91 {}

◆ endClk()

virtual void SVF::SVFStat::endClk ( )
inlinevirtual

Definition at line 63 of file SVFStat.h.

64  {
65  endTime = getClk(true);
66  }
static double getClk(bool mark=false)
Definition: SVFStat.cpp:47

◆ getClk()

double SVFStat::getClk ( bool  mark = false)
static

When mark is true, real clock is always returned. When mark is false, it is only returned when Options::MarkedClocksOnly is not set. Default call for getClk is unmarked, while MarkedClocksOnly is false by default.

Definition at line 47 of file SVFStat.cpp.

48 {
49  if (Options::MarkedClocksOnly() && !mark) return 0.0;
50 
51  if (Options::ClockType() == ClockType::Wall)
52  {
53  struct timespec time;
54  clock_gettime(CLOCK_MONOTONIC, &time);
55  return (double)(time.tv_nsec + time.tv_sec * 1000000000) / 1000000.0;
56  }
57  else if (Options::ClockType() == ClockType::CPU)
58  {
59  return CLOCK_IN_MS();
60  }
61 
62  assert(false && "PTAStat::getClk: unknown clock type");
63  abort();
64 }
#define CLOCK_IN_MS()
Definition: SVFType.h:513
static const Option< bool > MarkedClocksOnly
Definition: Options.h:31

◆ performStat()

void SVFStat::performStat ( )
pure virtual

SVF's general statistics are only printed once even if you run multiple anayses

Implemented in SVF::PTAStat, SVF::SVFGStat, SVF::MemSSAStat, SVF::DDAStat, SVF::AEStat, SVF::VersionedFlowSensitiveStat, SVF::FlowSensitiveStat, SVF::AndersenStat, SVF::ICFGStat, and SVF::CFLStat.

Definition at line 109 of file SVFStat.cpp.

110 {
111 
113  if(printGeneralStats == false)
114  return;
115 
116  SVFIR* pag = SVFIR::getPAG();
117  u32_t numOfFunction = 0;
118  u32_t numOfGlobal = 0;
119  u32_t numOfStack = 0;
120  u32_t numOfHeap = 0;
121  u32_t numOfHasVarArray = 0;
122  u32_t numOfHasVarStruct = 0;
123  u32_t numOfHasConstArray = 0;
124  u32_t numOfHasConstStruct = 0;
125  u32_t numOfScalar = 0;
126  u32_t numOfConstant = 0;
127  u32_t fiObjNumber = 0;
128  u32_t fsObjNumber = 0;
129  Set<SymID> memObjSet;
130  for(SVFIR::iterator it = pag->begin(), eit = pag->end(); it!=eit; ++it)
131  {
132  PAGNode* node = it->second;
133  if(ObjVar* obj = SVFUtil::dyn_cast<ObjVar>(node))
134  {
135  const MemObj* mem = obj->getMemObj();
136  if (memObjSet.insert(mem->getId()).second == false)
137  continue;
138  if(mem->isBlackHoleObj())
139  continue;
140  if(mem->isFunction())
141  numOfFunction++;
142  if(mem->isGlobalObj())
143  numOfGlobal++;
144  if(mem->isStack())
145  numOfStack++;
146  if(mem->isHeap())
147  numOfHeap++;
148  if(mem->isVarArray())
149  numOfHasVarArray++;
150  if(mem->isVarStruct())
151  numOfHasVarStruct++;
152  if(mem->isConstantArray())
153  numOfHasConstArray++;
154  if(mem->isConstantStruct())
155  numOfHasConstStruct++;
156  if(mem->getType()->isPointerTy() == false)
157  numOfScalar++;
158  if(mem->isConstDataOrConstGlobal())
159  numOfConstant++;
160 
161  if (mem->isFieldInsensitive())
162  fiObjNumber++;
163  else
164  fsObjNumber++;
165  }
166  }
167 
168 
169 
170  generalNumMap["TotalPointers"] = pag->getValueNodeNum() + pag->getFieldValNodeNum();
171  generalNumMap["TotalObjects"] = pag->getObjectNodeNum();
172  generalNumMap["TotalFieldObjects"] = pag->getFieldObjNodeNum();
174  generalNumMap["TotalSVFStmts"] = pag->getPAGEdgeNum();
175  generalNumMap["TotalPTASVFStmts"] = pag->getPTAPAGEdgeNum();
176  generalNumMap["FIObjNum"] = fiObjNumber;
177  generalNumMap["FSObjNum"] = fsObjNumber;
178 
179  generalNumMap["AddrsNum"] = pag->getSVFStmtSet(SVFStmt::Addr).size();
180  generalNumMap["LoadsNum"] = pag->getSVFStmtSet(SVFStmt::Load).size();
181  generalNumMap["StoresNum"] = pag->getSVFStmtSet(SVFStmt::Store).size();
182  generalNumMap["CopysNum"] = pag->getSVFStmtSet(SVFStmt::Copy).size();
183  generalNumMap["GepsNum"] = pag->getSVFStmtSet(SVFStmt::Gep).size();
184  generalNumMap["CallsNum"] = pag->getSVFStmtSet(SVFStmt::Call).size();
185  generalNumMap["ReturnsNum"] = pag->getSVFStmtSet(SVFStmt::Ret).size();
186 
187  generalNumMap["FunctionObjs"] = numOfFunction;
188  generalNumMap["GlobalObjs"] = numOfGlobal;
189  generalNumMap["HeapObjs"] = numOfHeap;
190  generalNumMap["StackObjs"] = numOfStack;
191 
192  generalNumMap["VarStructObj"] = numOfHasVarStruct;
193  generalNumMap["VarArrayObj"] = numOfHasVarArray;
194  generalNumMap["ConstStructObj"] = numOfHasConstStruct;
195  generalNumMap["ConstArrayObj"] = numOfHasConstArray;
196  generalNumMap["NonPtrObj"] = numOfScalar;
197  generalNumMap["ConstantObj"] = numOfConstant;
198 
199  generalNumMap["IndCallSites"] = pag->getIndirectCallsites().size();
200  generalNumMap["TotalCallSite"] = pag->getCallSiteSet().size();
201 
203  timeStatMap["SymbolTableTime"] = SVFStat::timeOfBuildingSymbolTable;
205 
206  // REFACTOR-TODO bitcastInstStat();
207  branchStat();
208 
209  printStat("General Stats");
210 
211  printGeneralStats = false;
212 }
iterator begin()
Iterators.
Definition: GenericGraph.h:627
IDToNodeMapTy::iterator iterator
Node Iterators.
Definition: GenericGraph.h:606
u32_t getValueNodeNum() const
Definition: IRGraph.h:186
u32_t getPTAPAGEdgeNum() const
Definition: IRGraph.h:211
u32_t getPAGEdgeNum() const
Definition: IRGraph.h:207
u32_t getObjectNodeNum() const
Definition: IRGraph.h:190
bool isConstantStruct() const
const SVFType * getType() const
Get obj type.
bool isConstDataOrConstGlobal() const
SymID getId() const
Get the memory object id.
bool isGlobalObj() const
bool isFieldInsensitive() const
Return true if its field limit is 0.
bool isVarArray() const
bool isBlackHoleObj() const
Whether it is a black hole object.
bool isConstantArray() const
bool isHeap() const
bool isVarStruct() const
bool isFunction() const
object attributes methods
bool isStack() const
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
Definition: SVFIR.h:350
u32_t getFieldObjNodeNum() const
Definition: SVFIR.h:338
u32_t getFieldValNodeNum() const
Node and edge statistics.
Definition: SVFIR.h:334
const CallSiteSet & getCallSiteSet() const
Get all callsites.
Definition: SVFIR.h:254
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get/set methods to get SVFStmts based on their kinds and ICFGNodes.
Definition: SVFIR.h:201
virtual void printStat(std::string str="")
Definition: SVFStat.cpp:66
void branchStat()
Definition: SVFStat.cpp:215
static bool printGeneralStats
SVF's general statistics are only printed once even if you run multiple anayses.
Definition: SVFStat.h:74
TIMEStatMap timeStatMap
Definition: SVFStat.h:78
static double timeOfBuildingLLVMModule
Definition: SVFStat.h:93
static double timeOfBuildingSymbolTable
Definition: SVFStat.h:94
static double timeOfBuildingSVFIR
Definition: SVFStat.h:95
bool isPointerTy() const
Definition: SVFType.h:249
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis.
u32_t getMaxStructSize() const
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96

◆ performStatPerQuery()

virtual void SVF::SVFStat::performStatPerQuery ( NodeID  )
inlinevirtual

Reimplemented in SVF::DDAStat.

Definition at line 87 of file SVFStat.h.

87 {}

◆ printStat()

void SVFStat::printStat ( std::string  str = "")
virtual

Reimplemented in SVF::SVFGStat, SVF::MemSSAStat, SVF::DDAStat, and SVF::ICFGStat.

Definition at line 66 of file SVFStat.cpp.

67 {
68 
69  std::string moduleName(SVFIR::getPAG()->getModule()->getModuleIdentifier());
70  std::vector<std::string> names = SVFUtil::split(moduleName,'/');
71  if (names.size() > 1)
72  {
73  moduleName = names[names.size() - 1];
74  }
75 
76  SVFUtil::outs() << "\n*********" << statname << "***************\n";
77  SVFUtil::outs() << "################ (program : " << moduleName << ")###############\n";
78  SVFUtil::outs().flags(std::ios::left);
79  unsigned field_width = 20;
80 
81  for(NUMStatMap::iterator it = generalNumMap.begin(), eit = generalNumMap.end(); it!=eit; ++it)
82  {
83  // format out put with width 20 space
84  std::cout << std::setw(field_width) << it->first << it->second << "\n";
85  }
86 
87  if(!timeStatMap.empty())
88  SVFUtil::outs() << "----------------Time and memory stats--------------------\n";
89  for(TIMEStatMap::iterator it = timeStatMap.begin(), eit = timeStatMap.end(); it!=eit; ++it)
90  {
91  // format out put with width 20 space
92  SVFUtil::outs() << std::setw(field_width) << it->first << it->second << "\n";
93  }
94 
95  if(!PTNumStatMap.empty())
96  SVFUtil::outs() << "----------------Numbers stats----------------------------\n";
97  for(NUMStatMap::iterator it = PTNumStatMap.begin(), eit = PTNumStatMap.end(); it!=eit; ++it)
98  {
99  // format out put with width 20 space
100  SVFUtil::outs() << std::setw(field_width) << it->first << it->second << "\n";
101  }
102  SVFUtil::outs() << "#######################################################" << std::endl;
103  SVFUtil::outs().flush();
104  generalNumMap.clear();
105  PTNumStatMap.clear();
106  timeStatMap.clear();
107 }
const char *const string
Definition: cJSON.h:172
NUMStatMap PTNumStatMap
Definition: SVFStat.h:77
std::string moduleName
Definition: SVFStat.h:99
std::vector< std::string > split(const std::string &s, char separator)
Split into two substrings around the first occurrence of a separator string.
Definition: SVFUtil.h:203
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50

◆ printStatPerQuery()

virtual void SVF::SVFStat::printStatPerQuery ( NodeID  ,
const PointsTo  
)
inlinevirtual

Reimplemented in SVF::DDAStat.

Definition at line 89 of file SVFStat.h.

89 {}

◆ startClk()

virtual void SVF::SVFStat::startClk ( )
inlinevirtual

Definition at line 58 of file SVFStat.h.

59  {
60  startTime = getClk(true);
61  }

Member Data Documentation

◆ endTime

double SVF::SVFStat::endTime

Definition at line 81 of file SVFStat.h.

◆ generalNumMap

NUMStatMap SVF::SVFStat::generalNumMap

Definition at line 76 of file SVFStat.h.

◆ moduleName

std::string SVF::SVFStat::moduleName
private

Definition at line 99 of file SVFStat.h.

◆ printGeneralStats

bool SVFStat::printGeneralStats = true
static

SVF's general statistics are only printed once even if you run multiple anayses.

Definition at line 74 of file SVFStat.h.

◆ PTNumStatMap

NUMStatMap SVF::SVFStat::PTNumStatMap

Definition at line 77 of file SVFStat.h.

◆ startTime

double SVF::SVFStat::startTime

Definition at line 80 of file SVFStat.h.

◆ timeOfBuildingLLVMModule

double SVFStat::timeOfBuildingLLVMModule = 0
static

Definition at line 93 of file SVFStat.h.

◆ timeOfBuildingSVFIR

double SVFStat::timeOfBuildingSVFIR = 0
static

Definition at line 95 of file SVFStat.h.

◆ timeOfBuildingSymbolTable

double SVFStat::timeOfBuildingSymbolTable = 0
static

Definition at line 94 of file SVFStat.h.

◆ timeStatMap

TIMEStatMap SVF::SVFStat::timeStatMap

Definition at line 78 of file SVFStat.h.


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