Skip to content

Commit ad4fa84

Browse files
committed
Simplify definition and usage of getForwardedTarget
Integrate this private method with updating the map entry in unified procedure.
1 parent b7fbb33 commit ad4fa84

File tree

2 files changed

+23
-34
lines changed

2 files changed

+23
-34
lines changed

llvm/include/llvm/Analysis/AliasSetTracker.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,6 @@ class AliasSet : public ilist_node<AliasSet> {
139139
AliasSet()
140140
: RefCount(0), AliasAny(false), Access(NoAccess), Alias(SetMustAlias) {}
141141

142-
/// Return the real alias set this represents. If this has been merged with
143-
/// another set and is forwarding, return the ultimate destination set. This
144-
/// also implements the union-find collapsing as well.
145-
AliasSet *getForwardedTarget(AliasSetTracker &AST) {
146-
if (!Forward) return this;
147-
148-
AliasSet *Dest = Forward->getForwardedTarget(AST);
149-
if (Dest != Forward) {
150-
Dest->addRef();
151-
Forward->dropRef(AST);
152-
Forward = Dest;
153-
}
154-
return Dest;
155-
}
156-
157142
void removeFromTracker(AliasSetTracker &AST);
158143

159144
void addPointer(AliasSetTracker &AST, const MemoryLocation &MemLoc,
@@ -251,6 +236,23 @@ class AliasSetTracker {
251236

252237
void removeAliasSet(AliasSet *AS);
253238

239+
// Update an alias set field to point to its real destination. If the field is
240+
// pointing to a set that has been merged with another set and is forwarding,
241+
// the field is updated to point to the set obtained by following the
242+
// forwarding links. The Forward fields of intermediate alias sets are
243+
// collapsed as well, and alias set reference counts are updated to reflect
244+
// the new situation.
245+
void collapseForwardingIn(AliasSet *&AS) {
246+
if (AS->Forward) {
247+
collapseForwardingIn(AS->Forward);
248+
// Swap out AS for AS->Forward, while updating reference counts.
249+
AliasSet *NewAS = AS->Forward;
250+
NewAS->addRef();
251+
AS->dropRef(*this);
252+
AS = NewAS;
253+
}
254+
}
255+
254256
AliasSet &addPointer(MemoryLocation Loc, AliasSet::AccessLattice E);
255257
AliasSet *mergeAliasSetsForPointer(const MemoryLocation &MemLoc,
256258
AliasSet *PtrAS, bool &MustAliasAll);

llvm/lib/Analysis/AliasSetTracker.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,9 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
276276
// alias set associated with its pointer.
277277
AliasSet *&MapEntry = PointerMap[MemLoc.Ptr];
278278
if (MapEntry) {
279-
AliasSet *AS = MapEntry->getForwardedTarget(*this);
280-
if (is_contained(AS->MemoryLocs, MemLoc)) {
281-
if (AS != MapEntry) {
282-
AS->addRef();
283-
MapEntry->dropRef(*this);
284-
MapEntry = AS;
285-
}
286-
return *AS;
287-
}
279+
collapseForwardingIn(MapEntry);
280+
if (is_contained(MapEntry->MemoryLocs, MemLoc))
281+
return *MapEntry;
288282
}
289283

290284
AliasSet *AS;
@@ -296,10 +290,8 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
296290
// consistent.
297291
// This, of course, means that we will never need a merge here.
298292
AS = AliasAnyAS;
299-
} else if (AliasSet *AliasAS = mergeAliasSetsForPointer(
300-
MemLoc,
301-
MapEntry ? MapEntry->getForwardedTarget(*this) : nullptr,
302-
MustAliasAll)) {
293+
} else if (AliasSet *AliasAS =
294+
mergeAliasSetsForPointer(MemLoc, MapEntry, MustAliasAll)) {
303295
// Add it to the alias set it aliases.
304296
AS = AliasAS;
305297
} else {
@@ -313,12 +305,7 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
313305
// Register selected alias set in pointer map (or ensure it is consistent with
314306
// earlier map entry after taking into account new merging).
315307
if (MapEntry) {
316-
if (MapEntry->Forward) {
317-
AliasSet *NewAS = MapEntry->getForwardedTarget(*this);
318-
NewAS->addRef();
319-
MapEntry->dropRef(*this);
320-
MapEntry = NewAS;
321-
}
308+
collapseForwardingIn(MapEntry);
322309
assert(MapEntry == AS && "Memory locations with same pointer value cannot "
323310
"be in different alias sets");
324311
} else {

0 commit comments

Comments
 (0)