@@ -49,99 +49,12 @@ class Value;
49
49
class AliasSet : public ilist_node <AliasSet> {
50
50
friend class AliasSetTracker ;
51
51
52
- class PointerRec {
53
- Value *Val; // The pointer this record corresponds to.
54
- PointerRec **PrevInList = nullptr ;
55
- PointerRec *NextInList = nullptr ;
56
- AliasSet *AS = nullptr ;
57
- LocationSize Size = LocationSize::mapEmpty();
58
- AAMDNodes AAInfo;
59
-
60
- // Whether the size for this record has been set at all. This makes no
61
- // guarantees about the size being known.
62
- bool isSizeSet () const { return Size != LocationSize::mapEmpty (); }
63
-
64
- public:
65
- PointerRec (Value *V)
66
- : Val(V), AAInfo(DenseMapInfo<AAMDNodes>::getEmptyKey()) {}
67
-
68
- Value *getValue () const { return Val; }
69
-
70
- PointerRec *getNext () const { return NextInList; }
71
- bool hasAliasSet () const { return AS != nullptr ; }
72
-
73
- PointerRec** setPrevInList (PointerRec **PIL) {
74
- PrevInList = PIL;
75
- return &NextInList;
76
- }
77
-
78
- bool updateSizeAndAAInfo (LocationSize NewSize, const AAMDNodes &NewAAInfo) {
79
- bool SizeChanged = false ;
80
- if (NewSize != Size) {
81
- LocationSize OldSize = Size;
82
- Size = isSizeSet () ? Size.unionWith (NewSize) : NewSize;
83
- SizeChanged = OldSize != Size;
84
- }
85
-
86
- if (AAInfo == DenseMapInfo<AAMDNodes>::getEmptyKey ())
87
- // We don't have a AAInfo yet. Set it to NewAAInfo.
88
- AAInfo = NewAAInfo;
89
- else {
90
- AAMDNodes Intersection (AAInfo.intersect (NewAAInfo));
91
- SizeChanged |= Intersection != AAInfo;
92
- AAInfo = Intersection;
93
- }
94
- return SizeChanged;
95
- }
96
-
97
- LocationSize getSize () const {
98
- assert (isSizeSet () && " Getting an unset size!" );
99
- return Size;
100
- }
101
-
102
- // / Return the AAInfo, or null if there is no information or conflicting
103
- // / information.
104
- AAMDNodes getAAInfo () const {
105
- // If we have missing or conflicting AAInfo, return null.
106
- if (AAInfo == DenseMapInfo<AAMDNodes>::getEmptyKey () ||
107
- AAInfo == DenseMapInfo<AAMDNodes>::getTombstoneKey ())
108
- return AAMDNodes ();
109
- return AAInfo;
110
- }
111
-
112
- AliasSet *getAliasSet (AliasSetTracker &AST) {
113
- assert (AS && " No AliasSet yet!" );
114
- if (AS->Forward ) {
115
- AliasSet *OldAS = AS;
116
- AS = OldAS->getForwardedTarget (AST);
117
- AS->addRef ();
118
- OldAS->dropRef (AST);
119
- }
120
- return AS;
121
- }
122
-
123
- void setAliasSet (AliasSet *as) {
124
- assert (!AS && " Already have an alias set!" );
125
- AS = as;
126
- }
127
-
128
- void eraseFromList () {
129
- if (NextInList) NextInList->PrevInList = PrevInList;
130
- *PrevInList = NextInList;
131
- if (AS->PtrListEnd == &NextInList) {
132
- AS->PtrListEnd = PrevInList;
133
- assert (*AS->PtrListEnd == nullptr && " List not terminated right!" );
134
- }
135
- delete this ;
136
- }
137
- };
138
-
139
- // Doubly linked list of nodes.
140
- PointerRec *PtrList = nullptr ;
141
- PointerRec **PtrListEnd;
142
52
// Forwarding pointer.
143
53
AliasSet *Forward = nullptr ;
144
54
55
+ // / Memory locations in this alias set.
56
+ std::vector<MemoryLocation> MemoryLocs;
57
+
145
58
// / All instructions without a specific address in this alias set.
146
59
std::vector<AssertingVH<Instruction>> UnknownInsts;
147
60
@@ -178,8 +91,6 @@ class AliasSet : public ilist_node<AliasSet> {
178
91
};
179
92
unsigned Alias : 1 ;
180
93
181
- unsigned SetSize = 0 ;
182
-
183
94
void addRef () { ++RefCount; }
184
95
185
96
void dropRef (AliasSetTracker &AST) {
@@ -207,65 +118,19 @@ class AliasSet : public ilist_node<AliasSet> {
207
118
208
119
// Alias Set iteration - Allow access to all of the pointers which are part of
209
120
// this alias set.
210
- class iterator ;
211
- iterator begin () const { return iterator (PtrList); }
212
- iterator end () const { return iterator (); }
213
- bool empty () const { return PtrList == nullptr ; }
121
+ using iterator = std::vector<MemoryLocation>::const_iterator;
122
+ iterator begin () const { return MemoryLocs.begin (); }
123
+ iterator end () const { return MemoryLocs.end (); }
214
124
215
- // Unfortunately, ilist::size() is linear, so we have to add code to keep
216
- // track of the list's exact size.
217
- unsigned size () { return SetSize; }
125
+ unsigned size () { return MemoryLocs.size (); }
218
126
219
127
void print (raw_ostream &OS) const ;
220
128
void dump () const ;
221
129
222
- // / Define an iterator for alias sets... this is just a forward iterator.
223
- class iterator {
224
- PointerRec *CurNode;
225
-
226
- public:
227
- using iterator_category = std::forward_iterator_tag;
228
- using value_type = PointerRec;
229
- using difference_type = std::ptrdiff_t ;
230
- using pointer = value_type *;
231
- using reference = value_type &;
232
-
233
- explicit iterator (PointerRec *CN = nullptr ) : CurNode(CN) {}
234
-
235
- bool operator ==(const iterator& x) const {
236
- return CurNode == x.CurNode ;
237
- }
238
- bool operator !=(const iterator& x) const { return !operator ==(x); }
239
-
240
- value_type &operator *() const {
241
- assert (CurNode && " Dereferencing AliasSet.end()!" );
242
- return *CurNode;
243
- }
244
- value_type *operator ->() const { return &operator *(); }
245
-
246
- Value *getPointer () const { return CurNode->getValue (); }
247
- LocationSize getSize () const { return CurNode->getSize (); }
248
- AAMDNodes getAAInfo () const { return CurNode->getAAInfo (); }
249
-
250
- iterator& operator ++() { // Preincrement
251
- assert (CurNode && " Advancing past AliasSet.end()!" );
252
- CurNode = CurNode->getNext ();
253
- return *this ;
254
- }
255
- iterator operator ++(int ) { // Postincrement
256
- iterator tmp = *this ; ++*this ; return tmp;
257
- }
258
- };
259
-
260
130
private:
261
131
// Can only be created by AliasSetTracker.
262
132
AliasSet ()
263
- : PtrListEnd(&PtrList), RefCount(0 ), AliasAny(false ), Access(NoAccess),
264
- Alias (SetMustAlias) {}
265
-
266
- PointerRec *getSomePointer () const {
267
- return PtrList;
268
- }
133
+ : RefCount(0 ), AliasAny(false ), Access(NoAccess), Alias(SetMustAlias) {}
269
134
270
135
// / Return the real alias set this represents. If this has been merged with
271
136
// / another set and is forwarding, return the ultimate destination set. This
@@ -284,16 +149,17 @@ class AliasSet : public ilist_node<AliasSet> {
284
149
285
150
void removeFromTracker (AliasSetTracker &AST);
286
151
287
- void addPointer (AliasSetTracker &AST, PointerRec &Entry, LocationSize Size,
288
- const AAMDNodes &AAInfo, bool KnownMustAlias = false ,
289
- bool SkipSizeUpdate = false );
152
+ bool isMustAliasMergeWith (AliasSet &AS, BatchAAResults &BatchAA) const ;
153
+ void addPointer (AliasSetTracker &AST, const MemoryLocation &MemLoc ,
154
+ bool KnownMustAlias = false );
290
155
void addUnknownInst (Instruction *I, BatchAAResults &AA);
291
156
292
157
public:
293
158
// / If the specified pointer "may" (or must) alias one of the members in the
294
159
// / set return the appropriate AliasResult. Otherwise return NoAlias.
295
- AliasResult aliasesPointer (const Value *Ptr, LocationSize Size,
296
- const AAMDNodes &AAInfo, BatchAAResults &AA) const ;
160
+ AliasResult aliasesPointer (const MemoryLocation &MemLoc,
161
+ BatchAAResults &AA) const ;
162
+
297
163
ModRefInfo aliasesUnknownInst (const Instruction *Inst,
298
164
BatchAAResults &AA) const ;
299
165
};
@@ -307,7 +173,7 @@ class AliasSetTracker {
307
173
BatchAAResults &AA;
308
174
ilist<AliasSet> AliasSets;
309
175
310
- using PointerMapType = DenseMap<AssertingVH<Value> , AliasSet::PointerRec *>;
176
+ using PointerMapType = DenseMap<MemoryLocation , AliasSet *>;
311
177
312
178
// Map from pointers to their node
313
179
PointerMapType PointerMap;
@@ -371,26 +237,16 @@ class AliasSetTracker {
371
237
friend class AliasSet ;
372
238
373
239
// The total number of pointers contained in all "may" alias sets.
374
- unsigned TotalMayAliasSetSize = 0 ;
240
+ unsigned TotalAliasSetSize = 0 ;
375
241
376
242
// A non-null value signifies this AST is saturated. A saturated AST lumps
377
243
// all pointers into a single "May" set.
378
244
AliasSet *AliasAnyAS = nullptr ;
379
245
380
246
void removeAliasSet (AliasSet *AS);
381
247
382
- // / Just like operator[] on the map, except that it creates an entry for the
383
- // / pointer if it doesn't already exist.
384
- AliasSet::PointerRec &getEntryFor (Value *V) {
385
- AliasSet::PointerRec *&Entry = PointerMap[V];
386
- if (!Entry)
387
- Entry = new AliasSet::PointerRec (V);
388
- return *Entry;
389
- }
390
-
391
248
AliasSet &addPointer (MemoryLocation Loc, AliasSet::AccessLattice E);
392
- AliasSet *mergeAliasSetsForPointer (const Value *Ptr, LocationSize Size,
393
- const AAMDNodes &AAInfo,
249
+ AliasSet *mergeAliasSetsForPointer (const MemoryLocation &MemLoc,
394
250
bool &MustAliasAll);
395
251
396
252
// / Merge all alias sets into a single set that is considered to alias any
0 commit comments