diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2017-01-23 08:33:24 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2017-01-23 08:33:24 +0000 |
commit | e8c66b27662bf71e3ca6fb787380957b428f1ff8 (patch) | |
tree | f5e9a394ea279679f27839e90ea5b6b07bbf8352 /llvm/lib | |
parent | 5144703664b2d040544dfc032836234edad01a93 (diff) | |
download | bcm5719-llvm-e8c66b27662bf71e3ca6fb787380957b428f1ff8.tar.gz bcm5719-llvm-e8c66b27662bf71e3ca6fb787380957b428f1ff8.zip |
[PM] Replace the hard invalidate in JumpThreading for LVI with correct
invalidation of deleted functions in GlobalDCE.
This was always testing a bug really triggered in GlobalDCE. Right now
we have analyses with asserting value handles into IR. As long as those
remain, when *deleting* an IR unit, we cannot wait for the normal
invalidation scheme to kick in even though it was designed to work
correctly in the face of these kinds of deletions. Instead, the pass
needs to directly handle invalidating the analysis results pointing at
that IR unit.
I've tought the Inliner about this and this patch teaches GlobalDCE.
This will handle the asserting VH case in the existing test as well as
other issues of the same fundamental variety. I've moved the test into
the GlobalDCE directory and added a comment explaining what is going on.
Note that we cannot simply require LVI here because LVI is too lazy.
llvm-svn: 292773
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/IPO/GlobalDCE.cpp | 27 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 4 |
2 files changed, 25 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp index 7a04de3d12d..9304e783d49 100644 --- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp +++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp @@ -50,7 +50,14 @@ namespace { if (skipModule(M)) return false; + // We need a minimally functional dummy module analysis manager. It needs + // to at least know about the possibility of proxying a function analysis + // manager. + FunctionAnalysisManager DummyFAM; ModuleAnalysisManager DummyMAM; + DummyMAM.registerPass( + [&] { return FunctionAnalysisManagerModuleProxy(DummyFAM); }); + auto PA = Impl.run(M, DummyMAM); return !PA.areAllPreserved(); } @@ -78,7 +85,7 @@ static bool isEmptyFunction(Function *F) { return RI.getReturnValue() == nullptr; } -PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &) { +PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &MAM) { bool Changed = false; // Remove empty functions from the global ctors list. @@ -137,13 +144,29 @@ PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &) { } } + // Because we may have cached analyses for functions we take extra care when + // deleting them if there is an active proxy. If there isn't, then we get to + // assume that everything in the function AM has been cleared already. + // FIXME: Note that all of this will happen automatically when this pass + // finishes. Unfortuantely there are analyses which hold asserting VHs to + // IR units. We could make those weak VHs that would assert if ever used + // without asserting eagerly and then all of this knowledge of the analysis + // manager could go away. + FunctionAnalysisManager *FAM = nullptr; + if (auto *FAMProxy = + MAM.getCachedResult<FunctionAnalysisManagerModuleProxy>(M)) + FAM = &FAMProxy->getManager(); + // The second pass drops the bodies of functions which are dead... std::vector<Function *> DeadFunctions; for (Function &F : M) if (!AliveGlobals.count(&F)) { DeadFunctions.push_back(&F); // Keep track of dead globals - if (!F.isDeclaration()) + if (!F.isDeclaration()) { + if (FAM) + FAM->clear(F); F.deleteBody(); + } } // The third pass drops targets of aliases which are dead... diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 1870c3deb4f..ecc6a0afbad 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -149,10 +149,6 @@ PreservedAnalyses JumpThreadingPass::run(Function &F, bool Changed = runImpl(F, &TLI, &LVI, HasProfileData, std::move(BFI), std::move(BPI)); - // FIXME: We need to invalidate LVI to avoid PR28400. Is there a better - // solution? - AM.invalidate<LazyValueAnalysis>(F); - if (!Changed) return PreservedAnalyses::all(); PreservedAnalyses PA; |