Skip to content

Commit 1ebddcd

Browse files
committed
Keep alias sets with undef pointer values in UndefPointerSets
This allows to scan only these sets when we want to check if a memory locations was already registered, but importantly, it also keeps these alias sets referenced.
1 parent 92f01a2 commit 1ebddcd

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

llvm/include/llvm/Analysis/AliasSetTracker.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ class AliasSetTracker {
184184
// Map from pointers to their node
185185
PointerMapType PointerMap;
186186

187+
// Collection of alias sets that contain undef pointer values
188+
DenseSet<AliasSet *> UndefPointerSets;
189+
std::vector<AliasSet *> UndefPointerSetsVector;
190+
187191
public:
188192
/// Create an empty collection of AliasSets, and use the specified alias
189193
/// analysis object to disambiguate load and store addresses.

llvm/lib/Analysis/AliasSetTracker.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ AliasSet::PointerVector AliasSet::getPointers() const {
228228

229229
void AliasSetTracker::clear() {
230230
PointerMap.clear();
231+
UndefPointerSets.clear();
232+
UndefPointerSetsVector.clear();
231233
AliasSets.clear();
232234
}
233235

@@ -287,7 +289,8 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
287289
// The PointerMap structure requires that all memory locations for the same
288290
// value will be in the same alias set, which does not hold for undef values.
289291
// So we keep UndefValue pointers associated with the nullptr in the pointer
290-
// map, and resort to a linear scan of all alias sets in that case.
292+
// map, and instead keep a collection with the alias sets that contain memory
293+
// locations with undef pointer values.
291294
auto [It, Inserted] = PointerMap.insert({MemLoc.Ptr, nullptr});
292295
AliasSet *&MapEntry = It->second;
293296
if (!Inserted) {
@@ -302,12 +305,27 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
302305
return *AS;
303306
}
304307
} else {
305-
for (auto &AS : *this) {
306-
if (AS.isForwardingAliasSet())
307-
continue;
308-
if (llvm::find(AS.MemoryLocs, MemLoc) != AS.MemoryLocs.end())
309-
return AS;
310-
}
308+
// Take opportunity to remove refs to forwarding alias sets from UndefPointerSets.
309+
llvm::erase_if(UndefPointerSetsVector, [this](AliasSet *&AS) {
310+
if (AS->Forward) {
311+
AliasSet *NewAS = AS->getForwardedTarget(*this);
312+
UndefPointerSets.erase(AS);
313+
AS->dropRef(*this);
314+
// Replace earlier entry in UndefPointerSetsVector with forwarded
315+
// target, but only if it is new.
316+
if (UndefPointerSets.insert(NewAS).second) {
317+
NewAS->addRef();
318+
AS = NewAS;
319+
return false;
320+
} else
321+
return true;
322+
}
323+
return false;
324+
});
325+
// Scan UndefPointerSets for MemLoc.
326+
for (AliasSet *AS : UndefPointerSetsVector)
327+
if (llvm::find(AS->MemoryLocs, MemLoc) != AS->MemoryLocs.end())
328+
return *AS;
311329
}
312330
}
313331

@@ -349,6 +367,11 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
349367
AS->addRef();
350368
MapEntry = AS;
351369
}
370+
} else {
371+
if (UndefPointerSets.insert(AS).second) {
372+
UndefPointerSetsVector.push_back(AS);
373+
AS->addRef();
374+
}
352375
}
353376
return *AS;
354377
}

0 commit comments

Comments
 (0)