Skip to content

Commit db5855d

Browse files
committed
[AST] Restrict AliasSetTracker to immutable IR
This restricts usage of AliasSetTracker to IR that does not change. We used to use it during LICM where the underlying IR could change, but remaining uses all use AST as part of a separate analysis phase. This is split out from D137955, which makes use of the new guarantee to switch to BatchAA. Differential Revision: https://reviews.llvm.org/D138014
1 parent 139e08e commit db5855d

File tree

2 files changed

+4
-105
lines changed

2 files changed

+4
-105
lines changed

llvm/include/llvm/Analysis/AliasSetTracker.h

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
// of disjoint sets. Each AliasSet object constructed by the AliasSetTracker
1212
// object refers to memory disjoint from the other sets.
1313
//
14+
// An AliasSetTracker can only be used on immutable IR.
15+
//
1416
//===----------------------------------------------------------------------===//
1517

1618
#ifndef LLVM_ANALYSIS_ALIASSETTRACKER_H
@@ -321,28 +323,10 @@ inline raw_ostream& operator<<(raw_ostream &OS, const AliasSet &AS) {
321323
}
322324

323325
class AliasSetTracker {
324-
/// A CallbackVH to arrange for AliasSetTracker to be notified whenever a
325-
/// Value is deleted.
326-
class ASTCallbackVH final : public CallbackVH {
327-
AliasSetTracker *AST;
328-
329-
void deleted() override;
330-
void allUsesReplacedWith(Value *) override;
331-
332-
public:
333-
ASTCallbackVH(Value *V, AliasSetTracker *AST = nullptr);
334-
335-
ASTCallbackVH &operator=(Value *V);
336-
};
337-
/// Traits to tell DenseMap that tell us how to compare and hash the value
338-
/// handle.
339-
struct ASTCallbackVHDenseMapInfo : public DenseMapInfo<Value *> {};
340-
341326
AAResults &AA;
342327
ilist<AliasSet> AliasSets;
343328

344-
using PointerMapType = DenseMap<ASTCallbackVH, AliasSet::PointerRec *,
345-
ASTCallbackVHDenseMapInfo>;
329+
using PointerMapType = DenseMap<AssertingVH<Value>, AliasSet::PointerRec *>;
346330

347331
// Map from pointers to their node
348332
PointerMapType PointerMap;
@@ -390,18 +374,6 @@ class AliasSetTracker {
390374
/// Return the underlying alias analysis object used by this tracker.
391375
AAResults &getAliasAnalysis() const { return AA; }
392376

393-
/// This method is used to remove a pointer value from the AliasSetTracker
394-
/// entirely. It should be used when an instruction is deleted from the
395-
/// program to update the AST. If you don't use this, you would have dangling
396-
/// pointers to deleted instructions.
397-
void deleteValue(Value *PtrVal);
398-
399-
/// This method should be used whenever a preexisting value in the program is
400-
/// copied or cloned, introducing a new value. Note that it is ok for clients
401-
/// that use this method to introduce the same value multiple times: if the
402-
/// tracker already knows about a value, it will ignore the request.
403-
void copyValue(Value *From, Value *To);
404-
405377
using iterator = ilist<AliasSet>::iterator;
406378
using const_iterator = ilist<AliasSet>::const_iterator;
407379

@@ -429,7 +401,7 @@ class AliasSetTracker {
429401
/// Just like operator[] on the map, except that it creates an entry for the
430402
/// pointer if it doesn't already exist.
431403
AliasSet::PointerRec &getEntryFor(Value *V) {
432-
AliasSet::PointerRec *&Entry = PointerMap[ASTCallbackVH(V, this)];
404+
AliasSet::PointerRec *&Entry = PointerMap[V];
433405
if (!Entry)
434406
Entry = new AliasSet::PointerRec(V);
435407
return *Entry;

llvm/lib/Analysis/AliasSetTracker.cpp

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -509,57 +509,6 @@ void AliasSetTracker::add(const AliasSetTracker &AST) {
509509
}
510510
}
511511

512-
// deleteValue method - This method is used to remove a pointer value from the
513-
// AliasSetTracker entirely. It should be used when an instruction is deleted
514-
// from the program to update the AST. If you don't use this, you would have
515-
// dangling pointers to deleted instructions.
516-
//
517-
void AliasSetTracker::deleteValue(Value *PtrVal) {
518-
// First, look up the PointerRec for this pointer.
519-
PointerMapType::iterator I = PointerMap.find_as(PtrVal);
520-
if (I == PointerMap.end()) return; // Noop
521-
522-
// If we found one, remove the pointer from the alias set it is in.
523-
AliasSet::PointerRec *PtrValEnt = I->second;
524-
AliasSet *AS = PtrValEnt->getAliasSet(*this);
525-
526-
// Unlink and delete from the list of values.
527-
PtrValEnt->eraseFromList();
528-
529-
if (AS->Alias == AliasSet::SetMayAlias) {
530-
AS->SetSize--;
531-
TotalMayAliasSetSize--;
532-
}
533-
534-
// Stop using the alias set.
535-
AS->dropRef(*this);
536-
537-
PointerMap.erase(I);
538-
}
539-
540-
// copyValue - This method should be used whenever a preexisting value in the
541-
// program is copied or cloned, introducing a new value. Note that it is ok for
542-
// clients that use this method to introduce the same value multiple times: if
543-
// the tracker already knows about a value, it will ignore the request.
544-
//
545-
void AliasSetTracker::copyValue(Value *From, Value *To) {
546-
// First, look up the PointerRec for this pointer.
547-
PointerMapType::iterator I = PointerMap.find_as(From);
548-
if (I == PointerMap.end())
549-
return; // Noop
550-
assert(I->second->hasAliasSet() && "Dead entry?");
551-
552-
AliasSet::PointerRec &Entry = getEntryFor(To);
553-
if (Entry.hasAliasSet()) return; // Already in the tracker!
554-
555-
// getEntryFor above may invalidate iterator \c I, so reinitialize it.
556-
I = PointerMap.find_as(From);
557-
// Add it to the alias set it aliases...
558-
AliasSet *AS = I->second->getAliasSet(*this);
559-
AS->addPointer(*this, Entry, I->second->getSize(), I->second->getAAInfo(),
560-
true, true);
561-
}
562-
563512
AliasSet &AliasSetTracker::mergeAllAliasSets() {
564513
assert(!AliasAnyAS && (TotalMayAliasSetSize > SaturationThreshold) &&
565514
"Full merge should happen once, when the saturation threshold is "
@@ -672,28 +621,6 @@ LLVM_DUMP_METHOD void AliasSet::dump() const { print(dbgs()); }
672621
LLVM_DUMP_METHOD void AliasSetTracker::dump() const { print(dbgs()); }
673622
#endif
674623

675-
//===----------------------------------------------------------------------===//
676-
// ASTCallbackVH Class Implementation
677-
//===----------------------------------------------------------------------===//
678-
679-
void AliasSetTracker::ASTCallbackVH::deleted() {
680-
assert(AST && "ASTCallbackVH called with a null AliasSetTracker!");
681-
AST->deleteValue(getValPtr());
682-
// this now dangles!
683-
}
684-
685-
void AliasSetTracker::ASTCallbackVH::allUsesReplacedWith(Value *V) {
686-
AST->copyValue(getValPtr(), V);
687-
}
688-
689-
AliasSetTracker::ASTCallbackVH::ASTCallbackVH(Value *V, AliasSetTracker *ast)
690-
: CallbackVH(V), AST(ast) {}
691-
692-
AliasSetTracker::ASTCallbackVH &
693-
AliasSetTracker::ASTCallbackVH::operator=(Value *V) {
694-
return *this = ASTCallbackVH(V, AST);
695-
}
696-
697624
//===----------------------------------------------------------------------===//
698625
// AliasSetPrinter Pass
699626
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)