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::PointsTo Class Reference

#include <PointsTo.h>

Classes

class  PointsToIterator
 

Public Types

enum  Type { SBV , CBV , BV }
 
typedef PointsToIterator const_iterator
 
typedef const_iterator iterator
 
typedef std::shared_ptr< std::vector< NodeID > > MappingPtr
 

Public Member Functions

 PointsTo ()
 Construct empty points-to set.
 
 PointsTo (const PointsTo &pt)
 Copy constructor.
 
 PointsTo (PointsTo &&pt) noexcept
 Move constructor.
 
 ~PointsTo ()
 
PointsTooperator= (const PointsTo &rhs)
 Copy assignment.
 
PointsTooperator= (PointsTo &&rhs) noexcept
 Move assignment.
 
bool empty () const
 Returns true if set is empty.
 
u32_t count () const
 Returns number of elements.
 
void clear ()
 Empty the set.
 
bool test (u32_t n) const
 Returns true if n is in this set.
 
bool test_and_set (u32_t n)
 
void set (u32_t n)
 Inserts n in the set.
 
void reset (u32_t n)
 Removes n from the set.
 
bool contains (const PointsTo &rhs) const
 Returns true if this set is a superset of rhs.
 
bool intersects (const PointsTo &rhs) const
 Returns true if this set and rhs share any elements.
 
int find_first ()
 
bool operator== (const PointsTo &rhs) const
 Returns true if this set and rhs contain exactly the same elements.
 
bool operator!= (const PointsTo &rhs) const
 Returns true if either this set or rhs has an element not in the other.
 
bool operator|= (const PointsTo &rhs)
 
bool operator|= (const NodeBS &rhs)
 
bool operator&= (const PointsTo &rhs)
 
bool operator-= (const PointsTo &rhs)
 
bool intersectWithComplement (const PointsTo &rhs)
 
void intersectWithComplement (const PointsTo &lhs, const PointsTo &rhs)
 Put intersection of lhs with complement of rhs into this set (overwrites).
 
NodeBS toNodeBS () const
 Returns this points-to set as a NodeBS.
 
size_t hash () const
 Return a hash of this set.
 
void checkAndRemap ()
 
const_iterator begin () const
 
const_iterator end () const
 
MappingPtr getNodeMapping () const
 

Static Public Member Functions

static MappingPtr getCurrentBestNodeMapping ()
 
static MappingPtr getCurrentBestReverseNodeMapping ()
 
static void setCurrentBestNodeMapping (MappingPtr newCurrentBestNodeMapping, MappingPtr newCurrentBestReverseNodeMapping)
 

Private Member Functions

NodeID getInternalNode (NodeID n) const
 Returns nodeMapping[n], checking for nullptr and size.
 
NodeID getExternalNode (NodeID n) const
 Returns reverseNodeMapping[n], checking for nullptr and size.
 
bool metaSame (const PointsTo &pt) const
 

Private Attributes

union { 
 
   SparseBitVector   sbv 
 Sparse bit vector backing. More...
 
   CoreBitVector   cbv 
 Core bit vector backing. More...
 
   BitVector   bv 
 Bit vector backing. More...
 
};  
 
enum Type type
 Type of this points-to set.
 
MappingPtr nodeMapping
 External nodes -> internal nodes.
 
MappingPtr reverseNodeMapping
 Internal nodes -> external nodes.
 

Static Private Attributes

static MappingPtr currentBestNodeMapping = nullptr
 Best node mapping we know of the for the analyses at hand.
 
static MappingPtr currentBestReverseNodeMapping = nullptr
 Likewise, but reversed.
 

Detailed Description

Wraps data structures to provide a points-to set. Underlying data structure can be changed globally. Includes support for mapping nodes for better internal representation.

Definition at line 28 of file PointsTo.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 39 of file PointsTo.h.

◆ iterator

Definition at line 40 of file PointsTo.h.

◆ MappingPtr

typedef std::shared_ptr<std::vector<NodeID> > SVF::PointsTo::MappingPtr

Definition at line 42 of file PointsTo.h.

Member Enumeration Documentation

◆ Type

Enumerator
SBV 
CBV 
BV 

Definition at line 31 of file PointsTo.h.

32 {
33 SBV,
34 CBV,
35 BV,
36 };

Constructor & Destructor Documentation

◆ PointsTo() [1/3]

SVF::PointsTo::PointsTo ( )

Construct empty points-to set.

Definition at line 25 of file PointsTo.cpp.

28{
29 if (type == SBV) new (&sbv) SparseBitVector<>();
30 else if (type == CBV) new (&cbv) CoreBitVector();
31 else if (type == BV) new (&bv) BitVector();
32 else assert(false && "PointsTo::PointsTo: unknown type");
33}
static const OptionMap< PointsTo::Type > PtType
Type of points-to set to use for all analyses.
Definition Options.h:50
MappingPtr reverseNodeMapping
Internal nodes -> external nodes.
Definition PointsTo.h:178
static MappingPtr currentBestReverseNodeMapping
Likewise, but reversed.
Definition PointsTo.h:159
BitVector bv
Bit vector backing.
Definition PointsTo.h:170
CoreBitVector cbv
Core bit vector backing.
Definition PointsTo.h:168
static MappingPtr currentBestNodeMapping
Best node mapping we know of the for the analyses at hand.
Definition PointsTo.h:157
enum Type type
Type of this points-to set.
Definition PointsTo.h:174
MappingPtr nodeMapping
External nodes -> internal nodes.
Definition PointsTo.h:176
SparseBitVector sbv
Sparse bit vector backing.
Definition PointsTo.h:166
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ PointsTo() [2/3]

SVF::PointsTo::PointsTo ( const PointsTo pt)

Copy constructor.

Definition at line 35 of file PointsTo.cpp.

36 : type(pt.type), nodeMapping(pt.nodeMapping),
37 reverseNodeMapping(pt.reverseNodeMapping)
38{
39 if (type == SBV) new (&sbv) SparseBitVector<>(pt.sbv);
40 else if (type == CBV) new (&cbv) CoreBitVector(pt.cbv);
41 else if (type == BV) new (&bv) BitVector(pt.bv);
42 else assert(false && "PointsTo::PointsTo&: unknown type");
43}

◆ PointsTo() [3/3]

SVF::PointsTo::PointsTo ( PointsTo &&  pt)
noexcept

Move constructor.

Definition at line 45 of file PointsTo.cpp.

46 : type(pt.type), nodeMapping(std::move(pt.nodeMapping)),
47 reverseNodeMapping(std::move(pt.reverseNodeMapping))
48{
49 if (type == SBV) new (&sbv) SparseBitVector<>(std::move(pt.sbv));
50 else if (type == CBV) new (&cbv) CoreBitVector(std::move(pt.cbv));
51 else if (type == BV) new (&bv) BitVector(std::move(pt.bv));
52 else assert(false && "PointsTo::PointsTo&&: unknown type");
53}

◆ ~PointsTo()

SVF::PointsTo::~PointsTo ( )

Definition at line 55 of file PointsTo.cpp.

56{
57 if (type == SBV) sbv.~SparseBitVector<>();
58 else if (type == CBV) cbv.~CoreBitVector();
59 else if (type == BV) bv.~BitVector();
60 else assert(false && "PointsTo::~PointsTo: unknown type");
61
62 nodeMapping = nullptr;
63 reverseNodeMapping = nullptr;
64}

Member Function Documentation

◆ begin()

const_iterator SVF::PointsTo::begin ( ) const
inline

Definition at line 128 of file PointsTo.h.

129 {
130 return PointsToIterator(this);
131 }

◆ checkAndRemap()

void SVF::PointsTo::checkAndRemap ( )

Checks if this points-to set is using the current best mapping. If not, remaps.

Definition at line 378 of file PointsTo.cpp.

379{
381 {
382 // newPt constructed with correct node mapping.
384 for (const NodeID o : *this) newPt.set(o);
385 *this = std::move(newPt);
386 }
387}
void set(u32_t n)
Inserts n in the set.
Definition PointsTo.cpp:157
PointsTo()
Construct empty points-to set.
Definition PointsTo.cpp:25
u32_t NodeID
Definition GeneralType.h:55

◆ clear()

void SVF::PointsTo::clear ( )

Empty the set.

Definition at line 123 of file PointsTo.cpp.

124{
125 if (type == CBV) cbv.clear();
126 else if (type == SBV) sbv.clear();
127 else if (type == BV) bv.clear();
128 else assert(false && "PointsTo::clear: unknown type");
129}
void clear(void)
Empty the CBV.

◆ contains()

bool SVF::PointsTo::contains ( const PointsTo rhs) const

Returns true if this set is a superset of rhs.

Definition at line 175 of file PointsTo.cpp.

176{
177 assert(metaSame(rhs) && "PointsTo::contains: mappings of operands do not match!");
178
179 if (type == CBV) return cbv.contains(rhs.cbv);
180 else if (type == SBV) return sbv.contains(rhs.sbv);
181 else if (type == BV) return bv.contains(rhs.bv);
182 else
183 {
184 assert(false && "PointsTo::contains: unknown type");
185 abort();
186 }
187}
bool contains(const CoreBitVector &rhs) const
Returns true if this CBV is a superset of rhs.
bool metaSame(const PointsTo &pt) const
Definition PointsTo.cpp:356
bool contains(const SparseBitVector< ElementSize > &RHS) const

◆ count()

u32_t SVF::PointsTo::count ( void  ) const

Returns number of elements.

Definition at line 111 of file PointsTo.cpp.

112{
113 if (type == CBV) return cbv.count();
114 else if (type == SBV) return sbv.count();
115 else if (type == BV) return bv.count();
116 else
117 {
118 assert(false && "PointsTo::count: unknown type");
119 abort();
120 }
121}
u32_t count(void) const
Returns number of bits set.
unsigned count() const

◆ empty()

bool SVF::PointsTo::empty ( ) const

Returns true if set is empty.

Definition at line 98 of file PointsTo.cpp.

99{
100 if (type == CBV) return cbv.empty();
101 else if (type == SBV) return sbv.empty();
102 else if (type == BV) return bv.empty();
103 else
104 {
105 assert(false && "PointsTo::empty: unknown type");
106 abort();
107 }
108}
bool empty(void) const
Returns true if no bits are set.

◆ end()

const_iterator SVF::PointsTo::end ( ) const
inline

Definition at line 132 of file PointsTo.h.

133 {
134 return PointsToIterator(this, true);
135 }

◆ find_first()

int SVF::PointsTo::find_first ( )

Returns the first element the set. Returns -1 when the set is empty. TODO: should we diverge from LLVM about the int return?

Definition at line 203 of file PointsTo.cpp.

204{
205 if (count() == 0) return -1;
206 return *begin();
207}
u32_t count() const
Returns number of elements.
Definition PointsTo.cpp:111
const_iterator begin() const
Definition PointsTo.h:128

◆ getCurrentBestNodeMapping()

PointsTo::MappingPtr SVF::PointsTo::getCurrentBestNodeMapping ( )
static

Definition at line 361 of file PointsTo.cpp.

362{
364}

◆ getCurrentBestReverseNodeMapping()

PointsTo::MappingPtr SVF::PointsTo::getCurrentBestReverseNodeMapping ( )
static

Definition at line 366 of file PointsTo.cpp.

367{
369}

◆ getExternalNode()

NodeID SVF::PointsTo::getExternalNode ( NodeID  n) const
private

Returns reverseNodeMapping[n], checking for nullptr and size.

Definition at line 349 of file PointsTo.cpp.

350{
351 if (reverseNodeMapping == nullptr) return n;
353 return reverseNodeMapping->at(n);
354}
cJSON * n
Definition cJSON.cpp:2558

◆ getInternalNode()

NodeID SVF::PointsTo::getInternalNode ( NodeID  n) const
private

Returns nodeMapping[n], checking for nullptr and size.

Definition at line 342 of file PointsTo.cpp.

343{
344 if (nodeMapping == nullptr) return n;
346 return nodeMapping->at(n);
347}

◆ getNodeMapping()

PointsTo::MappingPtr SVF::PointsTo::getNodeMapping ( ) const

Definition at line 337 of file PointsTo.cpp.

338{
339 return nodeMapping;
340}

◆ hash()

size_t SVF::PointsTo::hash ( ) const

Return a hash of this set.

Definition at line 320 of file PointsTo.cpp.

321{
322 if (type == CBV) return cbv.hash();
323 else if (type == SBV)
324 {
325 std::hash<SparseBitVector<>> h;
326 return h(sbv);
327 }
328 else if (type == BV) return bv.hash();
329
330 else
331 {
332 assert(false && "PointsTo::hash: unknown type");
333 abort();
334 }
335}
size_t hash(void) const
Hash for this CBV.

◆ intersects()

bool SVF::PointsTo::intersects ( const PointsTo rhs) const

Returns true if this set and rhs share any elements.

Definition at line 189 of file PointsTo.cpp.

190{
191 assert(metaSame(rhs) && "PointsTo::intersects: mappings of operands do not match!");
192
193 if (type == CBV) return cbv.intersects(rhs.cbv);
194 else if (type == SBV) return sbv.intersects(rhs.sbv);
195 else if (type == BV) return bv.intersects(rhs.bv);
196 else
197 {
198 assert(false && "PointsTo::intersects: unknown type");
199 abort();
200 }
201}
bool intersects(const CoreBitVector &rhs) const
Returns true if this CBV and rhs share any set bits.
bool intersects(const SparseBitVector< ElementSize > *RHS) const

◆ intersectWithComplement() [1/2]

void SVF::PointsTo::intersectWithComplement ( const PointsTo lhs,
const PointsTo rhs 
)

Put intersection of lhs with complement of rhs into this set (overwrites).

Definition at line 298 of file PointsTo.cpp.

299{
300 assert(metaSame(rhs) && "PointsTo::intersectWithComplement: mappings of operands do not match!");
301 assert(metaSame(lhs) && "PointsTo::intersectWithComplement: mappings of operands do not match!");
302
303 if (type == CBV) cbv.intersectWithComplement(lhs.cbv, rhs.cbv);
304 else if (type == SBV) sbv.intersectWithComplement(lhs.sbv, rhs.sbv);
305 else if (type == BV) bv.intersectWithComplement(lhs.bv, rhs.bv);
306 else
307 {
308 assert(false && "PointsTo::intersectWithComplement(PT, PT): unknown type");
309 abort();
310 }
311}
bool intersectWithComplement(const CoreBitVector &rhs)
bool intersectWithComplement(const SparseBitVector &RHS)

◆ intersectWithComplement() [2/2]

bool SVF::PointsTo::intersectWithComplement ( const PointsTo rhs)

Put intersection of this set with complement of rhs into this set. Returns true if this set changed.

Definition at line 286 of file PointsTo.cpp.

287{
288 assert(metaSame(rhs) && "PointsTo::intersectWithComplement: mappings of operands do not match!");
289
290 if (type == CBV) return cbv.intersectWithComplement(rhs.cbv);
291 else if (type == SBV) return sbv.intersectWithComplement(rhs.sbv);
292 else if (type == BV) return bv.intersectWithComplement(rhs.bv);
293
294 assert(false && "PointsTo::intersectWithComplement(PT): unknown type");
295 abort();
296}

◆ metaSame()

bool SVF::PointsTo::metaSame ( const PointsTo pt) const
private

Returns true if this points-to set and pt have the same type, nodeMapping, and reverseNodeMapping

Definition at line 356 of file PointsTo.cpp.

357{
358 return nodeMapping == pt.nodeMapping && reverseNodeMapping == pt.reverseNodeMapping;
359}

◆ operator!=()

bool SVF::PointsTo::operator!= ( const PointsTo rhs) const

Returns true if either this set or rhs has an element not in the other.

Definition at line 223 of file PointsTo.cpp.

224{
225 // TODO: we're asserting and checking twice... should be okay...
226 assert(metaSame(rhs) && "PointsTo::!=: mappings of operands do not match!");
227
228 return !(*this == rhs);
229}

◆ operator&=()

bool SVF::PointsTo::operator&= ( const PointsTo rhs)

Put intersection of this set and rhs into this set. Returns true if this set changed.

Definition at line 258 of file PointsTo.cpp.

259{
260 assert(metaSame(rhs) && "PointsTo::&=: mappings of operands do not match!");
261
262 if (type == CBV) return cbv &= rhs.cbv;
263 else if (type == SBV) return sbv &= rhs.sbv;
264 else if (type == BV) return bv &= rhs.bv;
265 else
266 {
267 assert(false && "PointsTo::&=: unknown type");
268 abort();
269 }
270}

◆ operator-=()

bool SVF::PointsTo::operator-= ( const PointsTo rhs)

Remove elements in rhs from this set. Returns true if this set changed.

Definition at line 272 of file PointsTo.cpp.

273{
274 assert(metaSame(rhs) && "PointsTo::-=: mappings of operands do not match!");
275
276 if (type == CBV) return cbv.intersectWithComplement(rhs.cbv);
277 else if (type == SBV) return sbv.intersectWithComplement(rhs.sbv);
278 else if (type == BV) return bv.intersectWithComplement(rhs.bv);
279 else
280 {
281 assert(false && "PointsTo::-=: unknown type");
282 abort();
283 }
284}

◆ operator=() [1/2]

PointsTo & SVF::PointsTo::operator= ( const PointsTo rhs)

Copy assignment.

Definition at line 66 of file PointsTo.cpp.

67{
68 if (this == &rhs)
69 return *this;
70 this->type = rhs.type;
71 this->nodeMapping = rhs.nodeMapping;
72 this->reverseNodeMapping = rhs.reverseNodeMapping;
73 // Placement new because if type has changed, we have
74 // not constructed the new type yet.
75 if (type == SBV) new (&sbv) SparseBitVector<>(rhs.sbv);
76 else if (type == CBV) new (&cbv) CoreBitVector(rhs.cbv);
77 else if (type == BV) new (&bv) BitVector(rhs.bv);
78 else assert(false && "PointsTo::PointsTo=&: unknown type");
79
80 return *this;
81}

◆ operator=() [2/2]

PointsTo & SVF::PointsTo::operator= ( PointsTo &&  rhs)
noexcept

Move assignment.

Definition at line 83 of file PointsTo.cpp.

85{
86 this->type = rhs.type;
87 this->nodeMapping = rhs.nodeMapping;
88 this->reverseNodeMapping = rhs.reverseNodeMapping;
89 // See comment in copy assignment.
90 if (type == SBV) new (&sbv) SparseBitVector<>(std::move(rhs.sbv));
91 else if (type == CBV) new (&cbv) CoreBitVector(std::move(rhs.cbv));
92 else if (type == BV) new (&bv) BitVector(std::move(rhs.bv));
93 else assert(false && "PointsTo::PointsTo=&&: unknown type");
94
95 return *this;
96}

◆ operator==()

bool SVF::PointsTo::operator== ( const PointsTo rhs) const

Returns true if this set and rhs contain exactly the same elements.

Definition at line 209 of file PointsTo.cpp.

210{
211 assert(metaSame(rhs) && "PointsTo::==: mappings of operands do not match!");
212
213 if (type == CBV) return cbv == rhs.cbv;
214 else if (type == SBV) return sbv == rhs.sbv;
215 else if (type == BV) return bv == rhs.bv;
216 else
217 {
218 assert(false && "PointsTo::==: unknown type");
219 abort();
220 }
221}

◆ operator|=() [1/2]

bool SVF::PointsTo::operator|= ( const NodeBS rhs)

Definition at line 245 of file PointsTo.cpp.

246{
247 // TODO:
248 bool changed = false;
249 for (NodeID n : rhs)
250 {
251 if (changed) set(n);
252 else changed = test_and_set(n);
253 }
254
255 return changed;
256}
bool test_and_set(u32_t n)
Definition PointsTo.cpp:144

◆ operator|=() [2/2]

bool SVF::PointsTo::operator|= ( const PointsTo rhs)

Put union of this set and rhs into this set. Returns true if this set changed.

Definition at line 231 of file PointsTo.cpp.

232{
233 assert(metaSame(rhs) && "PointsTo::|=: mappings of operands do not match!");
234
235 if (type == CBV) return cbv |= rhs.cbv;
236 else if (type == SBV) return sbv |= rhs.sbv;
237 else if (type == BV) return bv |= rhs.bv;
238 else
239 {
240 assert(false && "PointsTo::|=: unknown type");
241 abort();
242 }
243}

◆ reset()

void SVF::PointsTo::reset ( u32_t  n)

Removes n from the set.

Definition at line 166 of file PointsTo.cpp.

167{
169 if (type == CBV) cbv.reset(n);
170 else if (type == SBV) sbv.reset(n);
171 else if (type == BV) bv.reset(n);
172 else assert(false && "PointsTo::reset: unknown type");
173}
void reset(u32_t bit)
Resets bit in the CBV.
NodeID getInternalNode(NodeID n) const
Returns nodeMapping[n], checking for nullptr and size.
Definition PointsTo.cpp:342
void reset(unsigned Idx)

◆ set()

void SVF::PointsTo::set ( u32_t  n)

Inserts n in the set.

Definition at line 157 of file PointsTo.cpp.

158{
160 if (type == CBV) cbv.set(n);
161 else if (type == SBV) sbv.set(n);
162 else if (type == BV) bv.set(n);
163 else assert(false && "PointsTo::set: unknown type");
164}
void set(u32_t bit)
Sets bit in the CBV.
void set(unsigned Idx)

◆ setCurrentBestNodeMapping()

void SVF::PointsTo::setCurrentBestNodeMapping ( MappingPtr  newCurrentBestNodeMapping,
MappingPtr  newCurrentBestReverseNodeMapping 
)
static

◆ test()

bool SVF::PointsTo::test ( u32_t  n) const

Returns true if n is in this set.

Definition at line 131 of file PointsTo.cpp.

132{
134 if (type == CBV) return cbv.test(n);
135 else if (type == SBV) return sbv.test(n);
136 else if (type == BV) return bv.test(n);
137 else
138 {
139 assert(false && "PointsTo::test: unknown type");
140 abort();
141 }
142}
bool test(u32_t bit) const
Returns true if bit is set in this CBV.
bool test(unsigned Idx) const

◆ test_and_set()

bool SVF::PointsTo::test_and_set ( u32_t  n)

Check if n is in set. If it is, returns false. Otherwise, inserts n and returns true.

Definition at line 144 of file PointsTo.cpp.

145{
147 if (type == CBV) return cbv.test_and_set(n);
148 else if (type == SBV) return sbv.test_and_set(n);
149 else if (type == BV) return bv.test_and_set(n);
150 else
151 {
152 assert(false && "PointsTo::test_and_set: unknown type");
153 abort();
154 }
155}
bool test_and_set(u32_t bit)
bool test_and_set(unsigned Idx)

◆ toNodeBS()

NodeBS SVF::PointsTo::toNodeBS ( ) const

Returns this points-to set as a NodeBS.

Definition at line 313 of file PointsTo.cpp.

314{
315 NodeBS nbs;
316 for (const NodeID o : *this) nbs.set(o);
317 return nbs;
318}
SparseBitVector NodeBS
Definition GeneralType.h:62

Member Data Documentation

◆ [union]

union { ... } SVF::PointsTo

Holds backing data structure. TODO: std::variant when we move to C++17.

◆ bv

BitVector SVF::PointsTo::bv

Bit vector backing.

Definition at line 170 of file PointsTo.h.

◆ cbv

CoreBitVector SVF::PointsTo::cbv

Core bit vector backing.

Definition at line 168 of file PointsTo.h.

◆ currentBestNodeMapping

PointsTo::MappingPtr SVF::PointsTo::currentBestNodeMapping = nullptr
staticprivate

Best node mapping we know of the for the analyses at hand.

Definition at line 157 of file PointsTo.h.

◆ currentBestReverseNodeMapping

PointsTo::MappingPtr SVF::PointsTo::currentBestReverseNodeMapping = nullptr
staticprivate

Likewise, but reversed.

Definition at line 159 of file PointsTo.h.

◆ nodeMapping

MappingPtr SVF::PointsTo::nodeMapping
private

External nodes -> internal nodes.

Definition at line 176 of file PointsTo.h.

◆ reverseNodeMapping

MappingPtr SVF::PointsTo::reverseNodeMapping
private

Internal nodes -> external nodes.

Definition at line 178 of file PointsTo.h.

◆ sbv

SparseBitVector SVF::PointsTo::sbv

Sparse bit vector backing.

Definition at line 166 of file PointsTo.h.

◆ type

enum Type SVF::PointsTo::type
private

Type of this points-to set.

Definition at line 174 of file PointsTo.h.


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