From 1cd2c72befae87d68842c3c2c3ffe86edd63767b Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Mon, 20 Jun 2022 10:25:10 -0700 Subject: [PATCH] Revert "[GlobalOpt] Preserve CFG analyses" This reverts commit cc65f3e167144c39ef9ca3a69c3148b71dcab496. Causes crashes: https://github.com/llvm/llvm-project/issues/56131 --- llvm/lib/Transforms/IPO/GlobalOpt.cpp | 49 ++++++++++++----------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 84943b0..6ea2242 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -1941,8 +1941,7 @@ OptimizeFunctions(Module &M, function_ref GetTTI, function_ref GetBFI, function_ref LookupDomTree, - SmallPtrSetImpl &NotDiscardableComdats, - function_ref ChangedCFGCallback) { + SmallPtrSetImpl &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 GetTLI, - function_ref GetTTI, - function_ref GetBFI, - function_ref LookupDomTree, - function_ref ChangedCFGCallback) { +static bool optimizeGlobalsInModule( + Module &M, const DataLayout &DL, + function_ref GetTLI, + function_ref GetTTI, + function_ref GetBFI, + function_ref LookupDomTree) { SmallPtrSet 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(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(); - // The only place we modify the CFG is when calling - // removeUnreachableBlocks(), but there we make sure to invalidate analyses - // for modified functions. - PA.preserveSet(); - return PA; + return PreservedAnalyses::none(); } namespace { @@ -2572,13 +2560,8 @@ struct GlobalOptLegacyPass : public ModulePass { return this->getAnalysis(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 { -- 2.7.4