Static Value-Flow Analysis
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
SVF::NodeIDAllocator Class Reference

#include <NodeIDAllocator.h>

Classes

class  Clusterer
 

Public Types

enum  Strategy { DENSE , REVERSE_DENSE , SEQ , DBUG }
 Allocation strategy to use. More...
 

Public Member Functions

NodeID allocateObjectId (void)
 Allocate an object ID as determined by the strategy. More...
 
NodeID allocateGepObjectId (NodeID base, u32_t offset, u32_t maxFieldLimit)
 
NodeID allocateValueId (void)
 Allocate a value ID as determined by the strategy. More...
 
NodeID endSymbolAllocation (void)
 Notify the allocator that all symbols have had IDs allocated. More...
 
NodeID getNumObjects (void) const
 Returns the total number of memory objects. More...
 
void increaseNumOfObjAndNodes ()
 

Static Public Member Functions

static NodeIDAllocatorget (void)
 Return (singleton) allocator. More...
 
static void unset (void)
 Deletes the (singleton) allocator. More...
 

Static Public Attributes

static const NodeID blackHoleObjectId = 0
 
static const NodeID constantObjectId = 1
 
static const NodeID blackHolePointerId = 2
 
static const NodeID nullPointerId = 3
 

Private Member Functions

 NodeIDAllocator (void)
 Builds a node ID allocator with the strategy specified on the command line. More...
 

Private Attributes

enum Strategy strategy
 Strategy to allocate with. More...
 
NodeID numObjects
 
NodeID numValues
 Number of values allocated, including specials. More...
 
NodeID numSymbols
 Number of explicit symbols allocated (e.g., llvm::Values), including specials. More...
 
NodeID numNodes
 Total number of objects and values allocated. More...
 

Static Private Attributes

static NodeIDAllocatorallocator = nullptr
 Single allocator. More...
 

Friends

class SVFIRWriter
 
class SVFIRReader
 

Detailed Description

Allocates node IDs for objects and values, upon request, according to some strategy which can be user-defined. It is the job of SymbolTableInfo to tell the NodeIDAllocator when all symbols have been allocated through endSymbolAllocation.

Definition at line 20 of file NodeIDAllocator.h.

Member Enumeration Documentation

◆ Strategy

Allocation strategy to use.

Enumerator
DENSE 

Allocate objects contiguously, separate from values, and vice versa. If [****...*****] is the space of unsigned integers, we allocate as, [ssssooooooo...vvvvvvv] (o = object, v = value, s = special).

REVERSE_DENSE 

Like dense, but with order flipped: [ssssvvvvvvv...ooooooo]

SEQ 

Allocate objects objects and values sequentially, intermixed.

DBUG 

Allocate values and objects as they come in with a single counter. GEP objects are allocated as an offset from their base (see implementation of allocateGepObjectId). The purpose of this allocation strategy is human readability.

Definition at line 27 of file NodeIDAllocator.h.

28  {
32  DENSE,
37  SEQ,
42  DBUG,
43  };
@ SEQ
Allocate objects objects and values sequentially, intermixed.

Constructor & Destructor Documentation

◆ NodeIDAllocator()

SVF::NodeIDAllocator::NodeIDAllocator ( void  )
private

Builds a node ID allocator with the strategy specified on the command line.

Definition at line 46 of file NodeIDAllocator.cpp.

48 { }
NodeID numValues
Number of values allocated, including specials.
NodeID numSymbols
Number of explicit symbols allocated (e.g., llvm::Values), including specials.
enum Strategy strategy
Strategy to allocate with.
NodeID numNodes
Total number of objects and values allocated.
static const OptionMap< SVF::NodeIDAllocator::Strategy > NodeAllocStrat
Definition: Options.h:35

Member Function Documentation

◆ allocateGepObjectId()

NodeID SVF::NodeIDAllocator::allocateGepObjectId ( NodeID  base,
u32_t  offset,
u32_t  maxFieldLimit 
)

Allocate a GEP object ID as determined by the strategy. allocateObjectId is still fine for GEP objects, but for some strategies (DBUG, namely), GEP objects can be allocated differently (more readable, for DBUG). Regardless, numObjects is shared; there is no special numGepObjects.

Definition at line 86 of file NodeIDAllocator.cpp.

87 {
88  NodeID id = 0;
89  if (strategy == Strategy::DENSE)
90  {
91  // Nothing different to the other case.
92  id = numObjects;
93  }
94  else if (strategy == Strategy::REVERSE_DENSE)
95  {
96  id = UINT_MAX - numObjects;
97  }
98  else if (strategy == Strategy::SEQ)
99  {
100  // Everything is sequential and intermixed.
101  id = numNodes;
102  }
103  else if (strategy == Strategy::DBUG)
104  {
105  // For a gep id, base id is set at lower bits, and offset is set at higher bits
106  // e.g., 1100050 denotes base=50 and offset=10
107  // The offset is 10, not 11, because we add 1 to the offset to ensure that the
108  // high bits are never 0. For example, we do not want the gep id to be 50 when
109  // the base is 50 and the offset is 0.
110  NodeID gepMultiplier = pow(10, ceil(log10(
111  numSymbols > maxFieldLimit ?
112  numSymbols : maxFieldLimit
113  )));
114  id = (offset + 1) * gepMultiplier + base;
115  assert(id > numSymbols && "NodeIDAllocator::allocateGepObjectId: GEP allocation clashing with other nodes");
116  }
117  else
118  {
119  assert(false && "NodeIDAllocator::allocateGepObjectId: unimplemented node allocation strategy");
120  }
121 
123 
124  assert(id != 0 && "NodeIDAllocator::allocateGepObjectId: ID not allocated");
125  return id;
126 }
buffer offset
Definition: cJSON.cpp:1113
u32_t NodeID
Definition: GeneralType.h:55

◆ allocateObjectId()

NodeID SVF::NodeIDAllocator::allocateObjectId ( void  )

Allocate an object ID as determined by the strategy.

Definition at line 50 of file NodeIDAllocator.cpp.

51 {
52  NodeID id = 0;
53  if (strategy == Strategy::DENSE)
54  {
55  // We allocate objects from 0(-ish, considering the special nodes) to # of objects.
56  id = numObjects;
57  }
58  else if (strategy == Strategy::REVERSE_DENSE)
59  {
60  id = UINT_MAX - numObjects;
61  }
62  else if (strategy == Strategy::SEQ)
63  {
64  // Everything is sequential and intermixed.
65  id = numNodes;
66  }
67  else if (strategy == Strategy::DBUG)
68  {
69  // Non-GEPs just grab the next available ID.
70  // We may have "holes" because GEPs increment the total
71  // but allocate far away. This is not a problem because
72  // we don't care about the relative distances between nodes.
73  id = numNodes;
74  }
75  else
76  {
77  assert(false && "NodeIDAllocator::allocateObjectId: unimplemented node allocation strategy.");
78  }
79 
81 
82  assert(id != 0 && "NodeIDAllocator::allocateObjectId: ID not allocated");
83  return id;
84 }

◆ allocateValueId()

NodeID SVF::NodeIDAllocator::allocateValueId ( void  )

Allocate a value ID as determined by the strategy.

Definition at line 128 of file NodeIDAllocator.cpp.

129 {
130  NodeID id = 0;
131  if (strategy == Strategy::DENSE)
132  {
133  // We allocate values from UINT_MAX to UINT_MAX - # of values.
134  // TODO: UINT_MAX does not allow for an easily changeable type
135  // of NodeID (though it is already in use elsewhere).
136  id = UINT_MAX - numValues;
137  }
138  else if (strategy == Strategy::REVERSE_DENSE)
139  {
140  id = numValues;
141  }
142  else if (strategy == Strategy::SEQ)
143  {
144  // Everything is sequential and intermixed.
145  id = numNodes;
146  }
147  else if (strategy == Strategy::DBUG)
148  {
149  id = numNodes;
150  }
151  else
152  {
153  assert(false && "NodeIDAllocator::allocateValueId: unimplemented node allocation strategy");
154  }
155 
156  ++numValues;
157  ++numNodes;
158 
159  assert(id != 0 && "NodeIDAllocator::allocateValueId: ID not allocated");
160  return id;
161 }

◆ endSymbolAllocation()

NodeID SVF::NodeIDAllocator::endSymbolAllocation ( void  )

Notify the allocator that all symbols have had IDs allocated.

Definition at line 163 of file NodeIDAllocator.cpp.

164 {
166  return numSymbols;
167 }

◆ get()

NodeIDAllocator * SVF::NodeIDAllocator::get ( void  )
static

Return (singleton) allocator.

Definition at line 26 of file NodeIDAllocator.cpp.

27 {
28  if (allocator == nullptr)
29  {
30  allocator = new NodeIDAllocator();
31  }
32 
33  return allocator;
34 }
static NodeIDAllocator * allocator
Single allocator.
NodeIDAllocator(void)
Builds a node ID allocator with the strategy specified on the command line.

◆ getNumObjects()

NodeID SVF::NodeIDAllocator::getNumObjects ( void  ) const
inline

Returns the total number of memory objects.

Definition at line 80 of file NodeIDAllocator.h.

81  {
82  return numObjects;
83  }

◆ increaseNumOfObjAndNodes()

void SVF::NodeIDAllocator::increaseNumOfObjAndNodes ( )
inline

Definition at line 85 of file NodeIDAllocator.h.

86  {
87  ++numObjects;
88  ++numNodes;
89  }

◆ unset()

void SVF::NodeIDAllocator::unset ( void  )
static

Deletes the (singleton) allocator.

Definition at line 36 of file NodeIDAllocator.cpp.

37 {
38  if (allocator != nullptr)
39  {
40  delete allocator;
41  allocator = nullptr;
42  }
43 }

Friends And Related Function Documentation

◆ SVFIRReader

friend class SVFIRReader
friend

Definition at line 23 of file NodeIDAllocator.h.

◆ SVFIRWriter

friend class SVFIRWriter
friend

Definition at line 22 of file NodeIDAllocator.h.

Member Data Documentation

◆ allocator

NodeIDAllocator * SVF::NodeIDAllocator::allocator = nullptr
staticprivate

Single allocator.

Definition at line 112 of file NodeIDAllocator.h.

◆ blackHoleObjectId

const NodeID SVF::NodeIDAllocator::blackHoleObjectId = 0
static

These nodes, and any nodes before them are assumed allocated as objects and values. For simplicity's sake, numObjects and numVals thus start at 4 (and the other counters are set appropriately).

Definition at line 50 of file NodeIDAllocator.h.

◆ blackHolePointerId

const NodeID SVF::NodeIDAllocator::blackHolePointerId = 2
static

Definition at line 52 of file NodeIDAllocator.h.

◆ constantObjectId

const NodeID SVF::NodeIDAllocator::constantObjectId = 1
static

Definition at line 51 of file NodeIDAllocator.h.

◆ nullPointerId

const NodeID SVF::NodeIDAllocator::nullPointerId = 3
static

Definition at line 53 of file NodeIDAllocator.h.

◆ numNodes

NodeID SVF::NodeIDAllocator::numNodes
private

Total number of objects and values allocated.

Definition at line 105 of file NodeIDAllocator.h.

◆ numObjects

NodeID SVF::NodeIDAllocator::numObjects
private

These are moreso counters than amounts.

Number of memory objects allocated, including specials.

Definition at line 99 of file NodeIDAllocator.h.

◆ numSymbols

NodeID SVF::NodeIDAllocator::numSymbols
private

Number of explicit symbols allocated (e.g., llvm::Values), including specials.

Definition at line 103 of file NodeIDAllocator.h.

◆ numValues

NodeID SVF::NodeIDAllocator::numValues
private

Number of values allocated, including specials.

Definition at line 101 of file NodeIDAllocator.h.

◆ strategy

enum Strategy SVF::NodeIDAllocator::strategy
private

Strategy to allocate with.

Definition at line 105 of file NodeIDAllocator.h.


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