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
156private:
161
164 union
165 {
172 };
173
175 enum Type type;
180
181public:
183 {
184 public:
185 using iterator_category = std::forward_iterator_tag;
187 using difference_type = std::ptrdiff_t;
188 using pointer = u32_t *;
189 using reference = u32_t &;
190
195
198 explicit PointsToIterator(const PointsTo *pt, bool end=false);
199
202
205
207 const PointsToIterator operator++(int);
208
210 u32_t operator*() const;
211
213 bool operator==(const PointsToIterator &rhs) const;
214
216 bool operator!=(const PointsToIterator &rhs) const;
217
218 private:
219 bool atEnd() const;
220
221 private:
223 const PointsTo *pt;
226 union
227 {
231 };
232 };
233};
234
236PointsTo operator|(const PointsTo &lhs, const PointsTo &rhs);
237
239PointsTo operator&(const PointsTo &lhs, const PointsTo &rhs);
240
242PointsTo operator-(const PointsTo &lhs, const PointsTo &rhs);
243
244} // End namespace SVF
245
246template <>
247struct std::hash<SVF::PointsTo>
248{
249 size_t operator()(const SVF::PointsTo &pt) const
250 {
251 return pt.hash();
252 }
253};
254
255
256#endif // POINTSTO_H_
cJSON * n
Definition cJSON.cpp:2558
u32_t operator*() const
Dereference: *it.
Definition PointsTo.cpp:516
CoreBitVector::iterator cbvIt
Definition PointsTo.h:229
SparseBitVector ::iterator sbvIt
Definition PointsTo.h:228
const PointsTo * pt
PointsTo we are iterating over.
Definition PointsTo.h:223
BitVector::iterator bvIt
Definition PointsTo.h:230
bool operator!=(const PointsToIterator &rhs) const
Inequality: *this != rhs.
Definition PointsTo.cpp:545
PointsToIterator()=delete
Deleted because we don't want iterators with null pt.
const PointsToIterator & operator++()
Pre-increment: ++it.
Definition PointsTo.cpp:497
std::forward_iterator_tag iterator_category
Definition PointsTo.h:185
PointsToIterator & operator=(const PointsToIterator &rhs)
Definition PointsTo.cpp:455
bool operator==(const PointsToIterator &rhs) const
Equality: *this == rhs.
Definition PointsTo.cpp:529
bool test_and_set(u32_t n)
Definition PointsTo.cpp:144
bool empty() const
Returns true if set is empty.
Definition PointsTo.cpp:98
void clear()
Empty the set.
Definition PointsTo.cpp:123
static MappingPtr getCurrentBestReverseNodeMapping()
Definition PointsTo.cpp:366
MappingPtr reverseNodeMapping
Internal nodes -> external nodes.
Definition PointsTo.h:179
void reset(u32_t n)
Removes n from the set.
Definition PointsTo.cpp:166
bool operator-=(const PointsTo &rhs)
Definition PointsTo.cpp:272
PointsTo & operator=(const PointsTo &rhs)
Copy assignment.
Definition PointsTo.cpp:66
size_t hash() const
Return a hash of this set.
Definition PointsTo.cpp:320
bool operator&=(const PointsTo &rhs)
Definition PointsTo.cpp:258
static MappingPtr currentBestReverseNodeMapping
Likewise, but reversed.
Definition PointsTo.h:160
MappingPtr getNodeMapping() const
Definition PointsTo.cpp:337
BitVector bv
Bit vector backing.
Definition PointsTo.h:171
bool operator==(const PointsTo &rhs) const
Returns true if this set and rhs contain exactly the same elements.
Definition PointsTo.cpp:209
const_iterator end() const
Definition PointsTo.h:133
void checkAndRemap()
Definition PointsTo.cpp:378
CoreBitVector cbv
Core bit vector backing.
Definition PointsTo.h:169
NodeID getExternalNode(NodeID n) const
Returns reverseNodeMapping[n], checking for nullptr and size.
Definition PointsTo.cpp:349
std::shared_ptr< std::vector< NodeID > > MappingPtr
Definition PointsTo.h:43
static void setCurrentBestNodeMapping(MappingPtr newCurrentBestNodeMapping, MappingPtr newCurrentBestReverseNodeMapping)
Definition PointsTo.cpp:371
bool operator!=(const PointsTo &rhs) const
Returns true if either this set or rhs has an element not in the other.
Definition PointsTo.cpp:223
static MappingPtr currentBestNodeMapping
Best node mapping we know of the for the analyses at hand.
Definition PointsTo.h:158
u32_t count() const
Returns number of elements.
Definition PointsTo.cpp:111
bool metaSame(const PointsTo &pt) const
Definition PointsTo.cpp:356
bool operator|=(const PointsTo &rhs)
Definition PointsTo.cpp:231
enum Type type
Type of this points-to set.
Definition PointsTo.h:175
const_iterator iterator
Definition PointsTo.h:41
void set(u32_t n)
Inserts n in the set.
Definition PointsTo.cpp:157
bool contains(const PointsTo &rhs) const
Returns true if this set is a superset of rhs.
Definition PointsTo.cpp:175
PointsTo()
Construct empty points-to set.
Definition PointsTo.cpp:25
MappingPtr nodeMapping
External nodes -> internal nodes.
Definition PointsTo.h:177
NodeBS toNodeBS() const
Returns this points-to set as a NodeBS.
Definition PointsTo.cpp:313
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:189
static MappingPtr getCurrentBestNodeMapping()
Definition PointsTo.cpp:361
SparseBitVector sbv
Sparse bit vector backing.
Definition PointsTo.h:167
NodeID getInternalNode(NodeID n) const
Returns nodeMapping[n], checking for nullptr and size.
Definition PointsTo.cpp:342
bool test(u32_t n) const
Returns true if n is in this set.
Definition PointsTo.cpp:131
bool intersectWithComplement(const PointsTo &rhs)
Definition PointsTo.cpp:286
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:249