Static Value-Flow Analysis
Loading...
Searching...
No Matches
PointsTo.h
Go to the documentation of this file.
1//===- PointsTo.h -- Wrapper of set-like data structures ------------//
2
3/*
4 * PointsTo.h
5 *
6 * Abstracts away data structures to be used as points-to sets.
7 *
8 * Created on: Feb 01, 2021
9 * Author: Mohamad Barbar
10 */
11
12#ifndef POINTSTO_H_
13#define POINTSTO_H_
14
15#include <memory>
16#include <vector>
17
18#include "Util/GeneralType.h"
19#include "Util/BitVector.h"
20#include "Util/CoreBitVector.h"
22
23namespace SVF
24{
25
30{
31public:
32 enum Type
33 {
37 };
38
39 class PointsToIterator;
42
43 typedef std::shared_ptr<std::vector<NodeID>> MappingPtr;
44
45public:
47 PointsTo();
49 PointsTo(const PointsTo &pt);
52
53 ~PointsTo();
54
57
60
62 bool empty() const;
63
65 u32_t count() const;
66
68 void clear();
69
71 bool test(u32_t n) const;
72
75 bool test_and_set(u32_t n);
76
78 void set(u32_t n);
79
81 void reset(u32_t n);
82
84 bool contains(const PointsTo &rhs) const;
85
87 bool intersects(const PointsTo &rhs) const;
88
91 int find_first();
92
94 bool operator==(const PointsTo &rhs) const;
95
97 bool operator!=(const PointsTo &rhs) const;
98
101 bool operator|=(const PointsTo &rhs);
102 bool operator|=(const NodeBS &rhs);
103
106 bool operator&=(const PointsTo &rhs);
107
110 bool operator-=(const PointsTo &rhs);
111
115
117 void intersectWithComplement(const PointsTo &lhs, const PointsTo &rhs);
118
120 NodeBS toNodeBS() const;
121
123 size_t hash() const;
124
127 void checkAndRemap();
128
130 {
131 return PointsToIterator(this);
132 }
134 {
135 return PointsToIterator(this, true);
136 }
137
139
144
145private:
148
151
154 bool metaSame(const PointsTo &pt) const;
155
159 void destroyBacking();
160
161private:
166
169 union
170 {
177 };
178
180 enum Type type;
185
186public:
188 {
189 public:
190 using iterator_category = std::forward_iterator_tag;
192 using difference_type = std::ptrdiff_t;
193 using pointer = u32_t *;
194 using reference = u32_t &;
195
200
203 explicit PointsToIterator(const PointsTo *pt, bool end=false);
204
207
210
212 const PointsToIterator operator++(int);
213
215 u32_t operator*() const;
216
218 bool operator==(const PointsToIterator &rhs) const;
219
221 bool operator!=(const PointsToIterator &rhs) const;
222
223 private:
224 bool atEnd() const;
225
226 private:
228 const PointsTo *pt;
231 union
232 {
236 };
237 };
238};
239
241PointsTo operator|(const PointsTo &lhs, const PointsTo &rhs);
242
244PointsTo operator&(const PointsTo &lhs, const PointsTo &rhs);
245
247PointsTo operator-(const PointsTo &lhs, const PointsTo &rhs);
248
249} // End namespace SVF
250
251template <>
252struct std::hash<SVF::PointsTo>
253{
254 size_t operator()(const SVF::PointsTo &pt) const
255 {
256 return pt.hash();
257 }
258};
259
260
261#endif // POINTSTO_H_
cJSON * n
Definition cJSON.cpp:2558
u32_t operator*() const
Dereference: *it.
Definition PointsTo.cpp:528
CoreBitVector::iterator cbvIt
Definition PointsTo.h:234
SparseBitVector ::iterator sbvIt
Definition PointsTo.h:233
const PointsTo * pt
PointsTo we are iterating over.
Definition PointsTo.h:228
BitVector::iterator bvIt
Definition PointsTo.h:235
bool operator!=(const PointsToIterator &rhs) const
Inequality: *this != rhs.
Definition PointsTo.cpp:557
PointsToIterator()=delete
Deleted because we don't want iterators with null pt.
const PointsToIterator & operator++()
Pre-increment: ++it.
Definition PointsTo.cpp:509
std::forward_iterator_tag iterator_category
Definition PointsTo.h:190
PointsToIterator & operator=(const PointsToIterator &rhs)
Definition PointsTo.cpp:467
bool operator==(const PointsToIterator &rhs) const
Equality: *this == rhs.
Definition PointsTo.cpp:541
bool test_and_set(u32_t n)
Definition PointsTo.cpp:156
bool empty() const
Returns true if set is empty.
Definition PointsTo.cpp:110
void clear()
Empty the set.
Definition PointsTo.cpp:135
static MappingPtr getCurrentBestReverseNodeMapping()
Definition PointsTo.cpp:378
MappingPtr reverseNodeMapping
Internal nodes -> external nodes.
Definition PointsTo.h:184
void reset(u32_t n)
Removes n from the set.
Definition PointsTo.cpp:178
bool operator-=(const PointsTo &rhs)
Definition PointsTo.cpp:284
PointsTo & operator=(const PointsTo &rhs)
Copy assignment.
Definition PointsTo.cpp:71
size_t hash() const
Return a hash of this set.
Definition PointsTo.cpp:332
bool operator&=(const PointsTo &rhs)
Definition PointsTo.cpp:270
static MappingPtr currentBestReverseNodeMapping
Likewise, but reversed.
Definition PointsTo.h:165
MappingPtr getNodeMapping() const
Definition PointsTo.cpp:349
BitVector bv
Bit vector backing.
Definition PointsTo.h:176
bool operator==(const PointsTo &rhs) const
Returns true if this set and rhs contain exactly the same elements.
Definition PointsTo.cpp:221
const_iterator end() const
Definition PointsTo.h:133
void checkAndRemap()
Definition PointsTo.cpp:390
CoreBitVector cbv
Core bit vector backing.
Definition PointsTo.h:174
NodeID getExternalNode(NodeID n) const
Returns reverseNodeMapping[n], checking for nullptr and size.
Definition PointsTo.cpp:361
std::shared_ptr< std::vector< NodeID > > MappingPtr
Definition PointsTo.h:43
static void setCurrentBestNodeMapping(MappingPtr newCurrentBestNodeMapping, MappingPtr newCurrentBestReverseNodeMapping)
Definition PointsTo.cpp:383
bool operator!=(const PointsTo &rhs) const
Returns true if either this set or rhs has an element not in the other.
Definition PointsTo.cpp:235
static MappingPtr currentBestNodeMapping
Best node mapping we know of the for the analyses at hand.
Definition PointsTo.h:163
u32_t count() const
Returns number of elements.
Definition PointsTo.cpp:123
bool metaSame(const PointsTo &pt) const
Definition PointsTo.cpp:368
bool operator|=(const PointsTo &rhs)
Definition PointsTo.cpp:243
enum Type type
Type of this points-to set.
Definition PointsTo.h:180
const_iterator iterator
Definition PointsTo.h:41
void set(u32_t n)
Inserts n in the set.
Definition PointsTo.cpp:169
bool contains(const PointsTo &rhs) const
Returns true if this set is a superset of rhs.
Definition PointsTo.cpp:187
PointsTo()
Construct empty points-to set.
Definition PointsTo.cpp:25
MappingPtr nodeMapping
External nodes -> internal nodes.
Definition PointsTo.h:182
void destroyBacking()
Definition PointsTo.cpp:55
NodeBS toNodeBS() const
Returns this points-to set as a NodeBS.
Definition PointsTo.cpp:325
PointsToIterator const_iterator
Definition PointsTo.h:40
const_iterator begin() const
Definition PointsTo.h:129
bool intersects(const PointsTo &rhs) const
Returns true if this set and rhs share any elements.
Definition PointsTo.cpp:201
static MappingPtr getCurrentBestNodeMapping()
Definition PointsTo.cpp:373
SparseBitVector sbv
Sparse bit vector backing.
Definition PointsTo.h:172
NodeID getInternalNode(NodeID n) const
Returns nodeMapping[n], checking for nullptr and size.
Definition PointsTo.cpp:354
bool test(u32_t n) const
Returns true if n is in this set.
Definition PointsTo.cpp:143
bool intersectWithComplement(const PointsTo &rhs)
Definition PointsTo.cpp:298
for isBitcode
Definition BasicTypes.h:70
u32_t NodeID
Definition GeneralType.h:76
IntervalValue operator-(const IntervalValue &lhs, const IntervalValue &rhs)
Subtract IntervalValues.
IntervalValue operator&(const IntervalValue &lhs, const IntervalValue &rhs)
Bitwise AND of IntervalValues.
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
IntervalValue operator|(const IntervalValue &lhs, const IntervalValue &rhs)
Bitwise OR of IntervalValues.
unsigned u32_t
Definition GeneralType.h:67
size_t operator()(const SVF::PointsTo &pt) const
Definition PointsTo.h:254