aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/AssumptionCache.cpp
diff options
context:
space:
mode:
authorMichael Kruse <llvm-project@meinersbur.de>2021-02-11 12:03:20 -0600
committerMichael Kruse <llvm-project@meinersbur.de>2021-02-11 12:17:38 -0600
commit606aa622b23855784c5db5b48b1c4800467fd851 (patch)
tree49444bd16e8be847c892478f6f86dc5af482fcdf /llvm/lib/Analysis/AssumptionCache.cpp
parentf8772da8cc9a0be65c9ba028c2b5a895c1ed4f91 (diff)
downloadllvm-606aa622b23855784c5db5b48b1c4800467fd851.zip
llvm-606aa622b23855784c5db5b48b1c4800467fd851.tar.gz
llvm-606aa622b23855784c5db5b48b1c4800467fd851.tar.bz2
Revert "[AssumptionCache] Avoid dangling llvm.assume calls in the cache"
This reverts commit b7d870eae7fdadcf10d0f177faa7409c2e37d776 and the subsequent fix "[Polly] Fix build after AssumptionCache change (D96168)" (commit e6810cab09fcbc87b6e5e4d226de0810e2f2ea38). It caused indeterminism in the output, such that e.g. the polly-x86_64-linux buildbot failed accasionally.
Diffstat (limited to 'llvm/lib/Analysis/AssumptionCache.cpp')
-rw-r--r--llvm/lib/Analysis/AssumptionCache.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/llvm/lib/Analysis/AssumptionCache.cpp b/llvm/lib/Analysis/AssumptionCache.cpp
index e2a31d6..70053fd 100644
--- a/llvm/lib/Analysis/AssumptionCache.cpp
+++ b/llvm/lib/Analysis/AssumptionCache.cpp
@@ -163,12 +163,7 @@ void AssumptionCache::unregisterAssumption(CallInst *CI) {
AffectedValues.erase(AVI);
}
- AssumeHandles.erase({CI, this});
-}
-
-void AssumptionCache::AssumeHandle::deleted() {
- AC->AssumeHandles.erase(*this);
- // 'this' now dangles!
+ erase_value(AssumeHandles, CI);
}
void AssumptionCache::AffectedValueCallbackVH::deleted() {
@@ -209,14 +204,14 @@ void AssumptionCache::scanFunction() {
for (BasicBlock &B : F)
for (Instruction &II : B)
if (match(&II, m_Intrinsic<Intrinsic::assume>()))
- AssumeHandles.insert({&II, this});
+ AssumeHandles.push_back({&II, ExprResultIdx});
// Mark the scan as complete.
Scanned = true;
// Update affected values.
- for (auto &AssumeVH : AssumeHandles)
- updateAffectedValues(AssumeVH.getAssumeCI());
+ for (auto &A : AssumeHandles)
+ updateAffectedValues(cast<CallInst>(A));
}
void AssumptionCache::registerAssumption(CallInst *CI) {
@@ -228,7 +223,7 @@ void AssumptionCache::registerAssumption(CallInst *CI) {
if (!Scanned)
return;
- AssumeHandles.insert({CI, this});
+ AssumeHandles.push_back({CI, ExprResultIdx});
#ifndef NDEBUG
assert(CI->getParent() &&
@@ -236,11 +231,20 @@ void AssumptionCache::registerAssumption(CallInst *CI) {
assert(&F == CI->getParent()->getParent() &&
"Cannot register @llvm.assume call not in this function");
- for (auto &AssumeVH : AssumeHandles) {
- assert(&F == AssumeVH.getAssumeCI()->getCaller() &&
+ // We expect the number of assumptions to be small, so in an asserts build
+ // check that we don't accumulate duplicates and that all assumptions point
+ // to the same function.
+ SmallPtrSet<Value *, 16> AssumptionSet;
+ for (auto &VH : AssumeHandles) {
+ if (!VH)
+ continue;
+
+ assert(&F == cast<Instruction>(VH)->getParent()->getParent() &&
"Cached assumption not inside this function!");
- assert(match(AssumeVH.getAssumeCI(), m_Intrinsic<Intrinsic::assume>()) &&
+ assert(match(cast<CallInst>(VH), m_Intrinsic<Intrinsic::assume>()) &&
"Cached something other than a call to @llvm.assume!");
+ assert(AssumptionSet.insert(VH).second &&
+ "Cache contains multiple copies of a call!");
}
#endif
@@ -254,8 +258,9 @@ PreservedAnalyses AssumptionPrinterPass::run(Function &F,
AssumptionCache &AC = AM.getResult<AssumptionAnalysis>(F);
OS << "Cached assumptions for function: " << F.getName() << "\n";
- for (auto &AssumeVH : AC.assumptions())
- OS << " " << *AssumeVH.getAssumeCI()->getArgOperand(0) << "\n";
+ for (auto &VH : AC.assumptions())
+ if (VH)
+ OS << " " << *cast<CallInst>(VH)->getArgOperand(0) << "\n";
return PreservedAnalyses::all();
}
@@ -301,8 +306,9 @@ void AssumptionCacheTracker::verifyAnalysis() const {
SmallPtrSet<const CallInst *, 4> AssumptionSet;
for (const auto &I : AssumptionCaches) {
- for (auto &AssumeVH : I.second->assumptions())
- AssumptionSet.insert(AssumeVH.getAssumeCI());
+ for (auto &VH : I.second->assumptions())
+ if (VH)
+ AssumptionSet.insert(cast<CallInst>(VH));
for (const BasicBlock &B : cast<Function>(*I.first))
for (const Instruction &II : B)