Static Value-Flow Analysis
NodeIDAllocator.h
Go to the documentation of this file.
1 //===- NodeIDAllocator.h -- Allocates node IDs on request ------------------------//
2 
3 #ifndef NODEIDALLOCATOR_H_
4 #define NODEIDALLOCATOR_H_
5 
7 #include "SVFIR/SVFType.h"
8 #include "MemoryModel/PointsTo.h"
9 
10 namespace SVF
11 {
12 
13 // Forward declare for the Clusterer.
14 class BVDataPTAImpl;
15 
21 {
22  friend class SVFIRWriter;
23  friend class SVFIRReader;
24 
25 public:
27  enum Strategy
28  {
37  SEQ,
43  };
44 
50  static const NodeID blackHoleObjectId;
51  static const NodeID constantObjectId;
52  static const NodeID blackHolePointerId;
53  static const NodeID nullPointerId;
55 
57  static NodeIDAllocator *get(void);
58 
60  static void unset(void);
61 
64 
71  NodeID allocateGepObjectId(NodeID base, u32_t offset, u32_t maxFieldLimit);
72 
74  NodeID allocateValueId(void);
75 
78 
80  NodeID getNumObjects(void) const
81  {
82  return numObjects;
83  }
84 
86  {
87  ++numObjects;
88  ++numNodes;
89  }
90 
91 private:
93  NodeIDAllocator(void);
94 
95 private:
107 
109  enum Strategy strategy;
110 
113 
114 public:
117  class Clusterer
118  {
119  private:
123 
126  static const std::string NumObjects;
131  static const std::string EvalTime;
132  static const std::string TotalTime;
138  static const std::string NumRegions;
144 
145  public:
152  static std::vector<NodeID> cluster(BVDataPTAImpl *pta, const std::vector<std::pair<NodeID, unsigned>> keys, std::vector<std::pair<hclust_fast_methods, std::vector<NodeID>>> &candidates, std::string evalSubtitle="");
153 
154  // Returns a reverse node mapping for mapping generated by cluster().
155  static std::vector<NodeID> getReverseNodeMapping(const std::vector<NodeID> &nodeMapping);
156 
158  static void evaluate(const std::vector<NodeID> &nodeMap, const Map<PointsTo, unsigned> pointsToSets, Map<std::string, std::string> &stats, bool accountForOcc);
159 
162  static void printStats(std::string title, Map<std::string, std::string> &stats);
163 
164  private:
167  static inline size_t condensedIndex(size_t n, size_t i, size_t j);
168 
170  static inline unsigned requiredBits(const PointsTo &pts);
171 
173  static inline unsigned requiredBits(const size_t n);
174 
178  static inline double *getDistanceMatrix(const std::vector<std::pair<const PointsTo *, unsigned>> pointsToSets,
179  const size_t numObjects, const Map<NodeID, unsigned> &nodeMap,
180  double &distanceMatrixTime);
181 
185  static inline void traverseDendrogram(std::vector<NodeID> &nodeMap, const int *dendrogram, const size_t numObjects, unsigned &allocCounter, Set<int> &visited, const int index, const std::vector<NodeID> &regionNodeMap);
186 
191  static inline std::vector<unsigned> regionObjects(const Map<NodeID, Set<NodeID>> &graph, size_t numObjects, size_t &numLabels);
192 
193  // From all the candidates, returns the best mapping for pointsToSets (points-to set -> # occurrences).
194  static inline std::pair<hclust_fast_methods, std::vector<NodeID>> determineBestMapping(
195  const std::vector<std::pair<hclust_fast_methods, std::vector<NodeID>>> &candidates,
196  Map<PointsTo, unsigned> pointsToSets, const std::string &evalSubtitle, double &evalTime);
197 
198  };
199 };
200 
201 } // namespace SVF
202 
203 #endif // ifdef NODEIDALLOCATOR_H_
buffer offset
Definition: cJSON.cpp:1113
cJSON * n
Definition: cJSON.cpp:2558
int index
Definition: cJSON.h:170
const char *const string
Definition: cJSON.h:172
static const std::string DistanceMatrixTime
static const std::string LargestRegion
static const std::string NumNonTrivialRegionObjects
static const std::string EvalTime
Map< NodePair, std::pair< unsigned, unsigned > > DistOccMap
static const std::string TheoreticalNumWords
static std::vector< NodeID > cluster(BVDataPTAImpl *pta, const std::vector< std::pair< NodeID, unsigned >> keys, std::vector< std::pair< hclust_fast_methods, std::vector< NodeID >>> &candidates, std::string evalSubtitle="")
static const std::string BestCandidate
static std::vector< NodeID > getReverseNodeMapping(const std::vector< NodeID > &nodeMapping)
static std::pair< hclust_fast_methods, std::vector< NodeID > > determineBestMapping(const std::vector< std::pair< hclust_fast_methods, std::vector< NodeID >>> &candidates, Map< PointsTo, unsigned > pointsToSets, const std::string &evalSubtitle, double &evalTime)
static const std::string OriginalSbvNumWords
static const std::string DendrogramTraversalTime
static const std::string NewSbvNumWords
static std::vector< unsigned > regionObjects(const Map< NodeID, Set< NodeID >> &graph, size_t numObjects, size_t &numLabels)
static unsigned requiredBits(const PointsTo &pts)
Returns the minimum number of bits required to represent pts in a perfect world.
static void traverseDendrogram(std::vector< NodeID > &nodeMap, const int *dendrogram, const size_t numObjects, unsigned &allocCounter, Set< int > &visited, const int index, const std::vector< NodeID > &regionNodeMap)
static void printStats(std::string title, Map< std::string, std::string > &stats)
static const std::string NumRegions
static size_t condensedIndex(size_t n, size_t i, size_t j)
static void evaluate(const std::vector< NodeID > &nodeMap, const Map< PointsTo, unsigned > pointsToSets, Map< std::string, std::string > &stats, bool accountForOcc)
Fills in *NumWords statistics in stats..
static const std::string RegioningTime
static const std::string NumGtIntRegions
static double * getDistanceMatrix(const std::vector< std::pair< const PointsTo *, unsigned >> pointsToSets, const size_t numObjects, const Map< NodeID, unsigned > &nodeMap, double &distanceMatrixTime)
static const std::string FastClusterTime
static const std::string OriginalBvNumWords
static const std::string NewBvNumWords
static const std::string NumObjects
static const std::string TotalTime
NodeID numValues
Number of values allocated, including specials.
static const NodeID nullPointerId
NodeID allocateValueId(void)
Allocate a value ID as determined by the strategy.
static NodeIDAllocator * get(void)
Return (singleton) allocator.
NodeID numSymbols
Number of explicit symbols allocated (e.g., llvm::Values), including specials.
enum Strategy strategy
Strategy to allocate with.
static const NodeID blackHolePointerId
static NodeIDAllocator * allocator
Single allocator.
static const NodeID constantObjectId
NodeID allocateObjectId(void)
Allocate an object ID as determined by the strategy.
static const NodeID blackHoleObjectId
Strategy
Allocation strategy to use.
@ SEQ
Allocate objects objects and values sequentially, intermixed.
NodeID numNodes
Total number of objects and values allocated.
NodeID endSymbolAllocation(void)
Notify the allocator that all symbols have had IDs allocated.
NodeID allocateGepObjectId(NodeID base, u32_t offset, u32_t maxFieldLimit)
NodeIDAllocator(void)
Builds a node ID allocator with the strategy specified on the command line.
NodeID getNumObjects(void) const
Returns the total number of memory objects.
static void unset(void)
Deletes the (singleton) allocator.
hclust_fast_methods
Definition: fastcluster.h:66
for isBitcode
Definition: BasicTypes.h:68
u32_t NodeID
Definition: GeneralType.h:55
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101
unsigned u32_t
Definition: GeneralType.h:46
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96