[llvm] 1cd2c72 - Revert "[GlobalOpt] Preserve CFG analyses"
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 20 10:25:45 PDT 2022
Author: Arthur Eubanks
Date: 2022-06-20T10:25:10-07:00
New Revision: 1cd2c72befae87d68842c3c2c3ffe86edd63767b
URL: https://github.com/llvm/llvm-project/commit/1cd2c72befae87d68842c3c2c3ffe86edd63767b
DIFF: https://github.com/llvm/llvm-project/commit/1cd2c72befae87d68842c3c2c3ffe86edd63767b.diff
LOG: Revert "[GlobalOpt] Preserve CFG analyses"
This reverts commit cc65f3e167144c39ef9ca3a69c3148b71dcab496.
Causes crashes: https://github.com/llvm/llvm-project/issues/56131
Added:
Modified:
llvm/lib/Transforms/IPO/GlobalOpt.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 84943b0e142d2..6ea2242a88cbc 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1941,8 +1941,7 @@ OptimizeFunctions(Module &M,
function_ref<TargetTransformInfo &(Function &)> GetTTI,
function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
function_ref<DominatorTree &(Function &)> LookupDomTree,
- SmallPtrSetImpl<const Comdat *> &NotDiscardableComdats,
- function_ref<void(Function &F)> ChangedCFGCallback) {
+ SmallPtrSetImpl<const Comdat *> &NotDiscardableComdats) {
bool Changed = false;
@@ -1975,11 +1974,13 @@ OptimizeFunctions(Module &M,
// So, remove unreachable blocks from the function, because a) there's
// no point in analyzing them and b) GlobalOpt should otherwise grow
// some more complicated logic to break these cycles.
- // Notify the analysis manager that we've modified the function's CFG.
+ // Removing unreachable blocks might invalidate the dominator so we
+ // recalculate it.
if (!F.isDeclaration()) {
if (removeUnreachableBlocks(F)) {
+ auto &DT = LookupDomTree(F);
+ DT.recalculate(F);
Changed = true;
- ChangedCFGCallback(F);
}
}
@@ -2442,13 +2443,12 @@ static bool OptimizeEmptyGlobalCXXDtors(Function *CXAAtExitFn) {
return Changed;
}
-static bool
-optimizeGlobalsInModule(Module &M, const DataLayout &DL,
- function_ref<TargetLibraryInfo &(Function &)> GetTLI,
- function_ref<TargetTransformInfo &(Function &)> GetTTI,
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
- function_ref<DominatorTree &(Function &)> LookupDomTree,
- function_ref<void(Function &F)> ChangedCFGCallback) {
+static bool optimizeGlobalsInModule(
+ Module &M, const DataLayout &DL,
+ function_ref<TargetLibraryInfo &(Function &)> GetTLI,
+ function_ref<TargetTransformInfo &(Function &)> GetTTI,
+ function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
+ function_ref<DominatorTree &(Function &)> LookupDomTree) {
SmallPtrSet<const Comdat *, 8> NotDiscardableComdats;
bool Changed = false;
bool LocalChange = true;
@@ -2473,7 +2473,7 @@ optimizeGlobalsInModule(Module &M, const DataLayout &DL,
// Delete functions that are trivially dead, ccc -> fastcc
LocalChange |= OptimizeFunctions(M, GetTLI, GetTTI, GetBFI, LookupDomTree,
- NotDiscardableComdats, ChangedCFGCallback);
+ NotDiscardableComdats);
// Optimize global_ctors list.
LocalChange |=
@@ -2526,22 +2526,10 @@ PreservedAnalyses GlobalOptPass::run(Module &M, ModuleAnalysisManager &AM) {
auto GetBFI = [&FAM](Function &F) -> BlockFrequencyInfo & {
return FAM.getResult<BlockFrequencyAnalysis>(F);
};
- auto ChangedCFGCallback = [&FAM](Function &F) {
- FAM.invalidate(F, PreservedAnalyses::none());
- };
- if (!optimizeGlobalsInModule(M, DL, GetTLI, GetTTI, GetBFI, LookupDomTree,
- ChangedCFGCallback))
+ if (!optimizeGlobalsInModule(M, DL, GetTLI, GetTTI, GetBFI, LookupDomTree))
return PreservedAnalyses::all();
-
- PreservedAnalyses PA = PreservedAnalyses::none();
- // We have not removed or replaced any functions.
- PA.preserve<FunctionAnalysisManagerModuleProxy>();
- // The only place we modify the CFG is when calling
- // removeUnreachableBlocks(), but there we make sure to invalidate analyses
- // for modified functions.
- PA.preserveSet<CFGAnalyses>();
- return PA;
+ return PreservedAnalyses::none();
}
namespace {
@@ -2572,13 +2560,8 @@ struct GlobalOptLegacyPass : public ModulePass {
return this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI();
};
- auto ChangedCFGCallback = [&LookupDomTree](Function &F) {
- auto &DT = LookupDomTree(F);
- DT.recalculate(F);
- };
-
- return optimizeGlobalsInModule(M, DL, GetTLI, GetTTI, GetBFI, LookupDomTree,
- ChangedCFGCallback);
+ return optimizeGlobalsInModule(M, DL, GetTLI, GetTTI, GetBFI,
+ LookupDomTree);
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
More information about the llvm-commits
mailing list