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 <vector>
16
17#include "SVFIR/SVFType.h"
18#include "Util/BitVector.h"
19#include "Util/CoreBitVector.h"
21
22namespace SVF
23{
24
29{
30public:
31 enum Type
32 {
36 };
37
38 class PointsToIterator;
41
42 typedef std::shared_ptr<std::vector<NodeID>> MappingPtr;
43
44public:
46 PointsTo();
48 PointsTo(const PointsTo &pt);
51
52 ~PointsTo();
53
56
59
61 bool empty() const;
62
64 u32_t count() const;
65
67 void clear();
68
70 bool test(u32_t n) const;
71
74 bool test_and_set(u32_t n);
75
77 void set(u32_t n);
78
80 void reset(u32_t n);
81
83 bool contains(const PointsTo &rhs) const;
84
86 bool intersects(const PointsTo &rhs) const;
87
90 int find_first();
91
93 bool operator==(const PointsTo &rhs) const;
94
96 bool operator!=(const PointsTo &rhs) const;
97
100 bool operator|=(const PointsTo &rhs);
101 bool operator|=(const NodeBS &rhs);
102
105 bool operator&=(const PointsTo &rhs);
106
109 bool operator-=(const PointsTo &rhs);
110
114
116 void intersectWithComplement(const PointsTo &lhs, const PointsTo &rhs);
117
119 NodeBS toNodeBS() const;
120
122 size_t hash() const;
123
126 void checkAndRemap();
127
129 {
130 return PointsToIterator(this);
131 }
133 {
134 return PointsToIterator(this, true);
135 }
136
138
143
144private:
147
150
153 bool metaSame(const PointsTo &pt) const;
154
155private:
160
163 union
164 {
171 };
172
174 enum Type type;
179
180public:
182 {
183 public:
184 using iterator_category = std::forward_iterator_tag;
186 using difference_type = std::ptrdiff_t;
187 using pointer = u32_t *;
188 using reference = u32_t &;
189
194
197 explicit PointsToIterator(const PointsTo *pt, bool end=false);
198
201
204
206 const PointsToIterator operator++(int);
207
209 u32_t operator*() const;
210
212 bool operator==(const PointsToIterator &rhs) const;
213
215 bool operator!=(const PointsToIterator &rhs) const;
216
217 private:
218 bool atEnd() const;
219
220 private:
222 const PointsTo *pt;
225 union
226 {
230 };
231 };
232};
233
235PointsTo operator|(const PointsTo &lhs, const PointsTo &rhs);
236
238PointsTo operator&(const PointsTo &lhs, const PointsTo &rhs);
239
241PointsTo operator-(const PointsTo &lhs, const PointsTo &rhs);
242
243} // End namespace SVF
244
245template <>
246struct std::hash<SVF::PointsTo>
247{
248 size_t operator()(const SVF::PointsTo &pt) const
249 {
250 return pt.hash();
251 }
252};
253
254
255#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:228
SparseBitVector ::iterator sbvIt
Definition PointsTo.h:227
const PointsTo * pt
PointsTo we are iterating over.
Definition PointsTo.h:222
BitVector::iterator bvIt
Definition PointsTo.h:229
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:184
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:178
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:159
MappingPtr getNodeMapping() const
Definition PointsTo.cpp:337
BitVector bv
Bit vector backing.
Definition PointsTo.h:170
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:132
void checkAndRemap()
Definition PointsTo.cpp:378
CoreBitVector cbv
Core bit vector backing.
Definition PointsTo.h:168
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:42
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:157
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:174
const_iterator iterator
Definition PointsTo.h:40
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:176
NodeBS toNodeBS() const
Returns this points-to set as a NodeBS.
Definition PointsTo.cpp:313
PointsToIterator const_iterator
Definition PointsTo.h:39
const_iterator begin() const
Definition PointsTo.h:128
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:166
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:68
u32_t NodeID
Definition GeneralType.h:55
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:74
IntervalValue operator|(const IntervalValue &lhs, const IntervalValue &rhs)
Bitwise OR of IntervalValues.
unsigned u32_t
Definition GeneralType.h:46
size_t operator()(const SVF::PointsTo &pt) const
Definition PointsTo.h:248