Skip to content

Commit 56a6a53

Browse files
committed
AliasSetTracker: don't merge memory locations
1 parent 8d300e6 commit 56a6a53

File tree

16 files changed

+294
-516
lines changed

16 files changed

+294
-516
lines changed

llvm/include/llvm/Analysis/AliasSetTracker.h

Lines changed: 17 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -49,99 +49,12 @@ class Value;
4949
class AliasSet : public ilist_node<AliasSet> {
5050
friend class AliasSetTracker;
5151

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;
14252
// Forwarding pointer.
14353
AliasSet *Forward = nullptr;
14454

55+
/// Memory locations in this alias set.
56+
std::vector<MemoryLocation> MemoryLocs;
57+
14558
/// All instructions without a specific address in this alias set.
14659
std::vector<AssertingVH<Instruction>> UnknownInsts;
14760

@@ -178,8 +91,6 @@ class AliasSet : public ilist_node<AliasSet> {
17891
};
17992
unsigned Alias : 1;
18093

181-
unsigned SetSize = 0;
182-
18394
void addRef() { ++RefCount; }
18495

18596
void dropRef(AliasSetTracker &AST) {
@@ -207,65 +118,19 @@ class AliasSet : public ilist_node<AliasSet> {
207118

208119
// Alias Set iteration - Allow access to all of the pointers which are part of
209120
// 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(); }
214124

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(); }
218126

219127
void print(raw_ostream &OS) const;
220128
void dump() const;
221129

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-
260130
private:
261131
// Can only be created by AliasSetTracker.
262132
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) {}
269134

270135
/// Return the real alias set this represents. If this has been merged with
271136
/// another set and is forwarding, return the ultimate destination set. This
@@ -284,16 +149,17 @@ class AliasSet : public ilist_node<AliasSet> {
284149

285150
void removeFromTracker(AliasSetTracker &AST);
286151

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);
290155
void addUnknownInst(Instruction *I, BatchAAResults &AA);
291156

292157
public:
293158
/// If the specified pointer "may" (or must) alias one of the members in the
294159
/// 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+
297163
ModRefInfo aliasesUnknownInst(const Instruction *Inst,
298164
BatchAAResults &AA) const;
299165
};
@@ -307,7 +173,7 @@ class AliasSetTracker {
307173
BatchAAResults &AA;
308174
ilist<AliasSet> AliasSets;
309175

310-
using PointerMapType = DenseMap<AssertingVH<Value>, AliasSet::PointerRec *>;
176+
using PointerMapType = DenseMap<MemoryLocation, AliasSet *>;
311177

312178
// Map from pointers to their node
313179
PointerMapType PointerMap;
@@ -371,26 +237,16 @@ class AliasSetTracker {
371237
friend class AliasSet;
372238

373239
// The total number of pointers contained in all "may" alias sets.
374-
unsigned TotalMayAliasSetSize = 0;
240+
unsigned TotalAliasSetSize = 0;
375241

376242
// A non-null value signifies this AST is saturated. A saturated AST lumps
377243
// all pointers into a single "May" set.
378244
AliasSet *AliasAnyAS = nullptr;
379245

380246
void removeAliasSet(AliasSet *AS);
381247

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-
391248
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,
394250
bool &MustAliasAll);
395251

396252
/// Merge all alias sets into a single set that is considered to alias any

0 commit comments

Comments
 (0)