Static Value-Flow Analysis
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | 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.
 
NodeID allocateTypeId (void)
 Allocate an type ID as determined by the strategy.
 
NodeID allocateGepObjectId (NodeID base, u32_t offset, u32_t maxFieldLimit)
 
NodeID allocateValueId (void)
 Allocate a value ID as determined by the strategy.
 
NodeID endSymbolAllocation (void)
 Notify the allocator that all symbols have had IDs allocated.
 
NodeID getNumObjects (void) const
 Returns the total number of memory objects.
 
void increaseNumOfObjAndNodes ()
 
void increaseNumOfValues ()
 
int getNumOfNodes ()
 

Static Public Member Functions

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

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.
 

Private Attributes

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

Static Private Attributes

static NodeIDAllocatorallocator = nullptr
 Single allocator.
 

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 25 of file NodeIDAllocator.h.

26 {
30 DENSE,
35 SEQ,
40 DBUG,
41 };
@ 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 44 of file NodeIDAllocator.cpp.

46{ }
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 numType
Total number of svftypes.
NodeID numNodes
Total number of objects and values allocated.
static const OptionMap< SVF::NodeIDAllocator::Strategy > NodeAllocStrat
Definition Options.h:31

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 90 of file NodeIDAllocator.cpp.

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

◆ allocateObjectId()

NodeID SVF::NodeIDAllocator::allocateObjectId ( void  )

Allocate an object ID as determined by the strategy.

Definition at line 48 of file NodeIDAllocator.cpp.

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

◆ allocateTypeId()

NodeID SVF::NodeIDAllocator::allocateTypeId ( void  )

Allocate an type ID as determined by the strategy.

Definition at line 85 of file NodeIDAllocator.cpp.

86{
87 return numType++;
88}

◆ allocateValueId()

NodeID SVF::NodeIDAllocator::allocateValueId ( void  )

Allocate a value ID as determined by the strategy.

Definition at line 132 of file NodeIDAllocator.cpp.

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

◆ endSymbolAllocation()

NodeID SVF::NodeIDAllocator::endSymbolAllocation ( void  )

Notify the allocator that all symbols have had IDs allocated.

Definition at line 167 of file NodeIDAllocator.cpp.

168{
170 return numSymbols;
171}

◆ get()

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

Return (singleton) allocator.

Definition at line 24 of file NodeIDAllocator.cpp.

25{
26 if (allocator == nullptr)
27 {
29 }
30
31 return allocator;
32}
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 81 of file NodeIDAllocator.h.

82 {
83 return numObjects;
84 }

◆ getNumOfNodes()

int SVF::NodeIDAllocator::getNumOfNodes ( )
inline

Definition at line 98 of file NodeIDAllocator.h.

99 {
100 return numNodes;
101 }

◆ increaseNumOfObjAndNodes()

void SVF::NodeIDAllocator::increaseNumOfObjAndNodes ( )
inline

Definition at line 86 of file NodeIDAllocator.h.

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

◆ increaseNumOfValues()

void SVF::NodeIDAllocator::increaseNumOfValues ( )
inline

Definition at line 92 of file NodeIDAllocator.h.

93 {
94 ++numValues;
95 ++numNodes;
96 }

◆ unset()

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

Deletes the (singleton) allocator.

Definition at line 34 of file NodeIDAllocator.cpp.

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

Member Data Documentation

◆ allocator

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

Single allocator.

Definition at line 126 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 48 of file NodeIDAllocator.h.

◆ blackHolePointerId

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

Definition at line 50 of file NodeIDAllocator.h.

◆ constantObjectId

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

Definition at line 49 of file NodeIDAllocator.h.

◆ nullPointerId

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

Definition at line 51 of file NodeIDAllocator.h.

◆ numNodes

NodeID SVF::NodeIDAllocator::numNodes
private

Total number of objects and values allocated.

Definition at line 117 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 111 of file NodeIDAllocator.h.

◆ numSymbols

NodeID SVF::NodeIDAllocator::numSymbols
private

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

Definition at line 115 of file NodeIDAllocator.h.

◆ numType

NodeID SVF::NodeIDAllocator::numType
private

Total number of svftypes.

Definition at line 119 of file NodeIDAllocator.h.

◆ numValues

NodeID SVF::NodeIDAllocator::numValues
private

Number of values allocated, including specials.

Definition at line 113 of file NodeIDAllocator.h.

◆ strategy

enum Strategy SVF::NodeIDAllocator::strategy
private

Strategy to allocate with.

Definition at line 123 of file NodeIDAllocator.h.


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