From 02aa795785379b34f1f82d1c4d852b915c5bfb4a Mon Sep 17 00:00:00 2001 From: James Y Knight Date: Fri, 29 Apr 2022 20:33:08 +0000 Subject: [PATCH] Revert "[JumpThreading][NFC][CompileTime] Do not recompute BPI/BFI analyzes" This change has caused non-reproducibility of a self-build of Clang when using NewPM and providing profile data. This reverts commit 35f38583d2f2484794f579bed69566b40e732206. --- .../include/llvm/Transforms/Scalar/JumpThreading.h | 13 ++++++--- llvm/lib/Transforms/Scalar/JumpThreading.cpp | 33 +++++++++++----------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h index 8b4e8b0..c14855e 100644 --- a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h +++ b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h @@ -81,8 +81,8 @@ class JumpThreadingPass : public PassInfoMixin { LazyValueInfo *LVI; AAResults *AA; DomTreeUpdater *DTU; - BlockFrequencyInfo *BFI; - BranchProbabilityInfo *BPI; + std::unique_ptr BFI; + std::unique_ptr BPI; bool HasProfileData = false; bool HasGuards = false; #ifndef LLVM_ENABLE_ABI_BREAKING_CHECKS @@ -101,11 +101,16 @@ public: // Glue for old PM. bool runImpl(Function &F, TargetLibraryInfo *TLI, TargetTransformInfo *TTI, LazyValueInfo *LVI, AAResults *AA, DomTreeUpdater *DTU, - bool HasProfileData, BlockFrequencyInfo *BFI, - BranchProbabilityInfo *BPI); + bool HasProfileData, std::unique_ptr BFI, + std::unique_ptr BPI); PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); + void releaseMemory() { + BFI.reset(); + BPI.reset(); + } + void findLoopHeaders(Function &F); bool processBlock(BasicBlock *BB); bool maybeMergeBasicBlockIntoOnlyPred(BasicBlock *BB); diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 51dacc0..5ae670c 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -155,6 +155,8 @@ namespace { AU.addRequired(); AU.addRequired(); } + + void releaseMemory() override { Impl.releaseMemory(); } }; } // end anonymous namespace @@ -328,7 +330,7 @@ bool JumpThreading::runOnFunction(Function &F) { } bool Changed = Impl.runImpl(F, TLI, TTI, LVI, AA, &DTU, F.hasProfileData(), - BFI.get(), BPI.get()); + std::move(BFI), std::move(BPI)); if (PrintLVIAfterJumpThreading) { dbgs() << "LVI for function '" << F.getName() << "':\n"; LVI->printLVI(F, DTU.getDomTree(), dbgs()); @@ -348,15 +350,16 @@ PreservedAnalyses JumpThreadingPass::run(Function &F, auto &AA = AM.getResult(F); DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy); - BlockFrequencyInfo *BFI = nullptr; - BranchProbabilityInfo *BPI = nullptr; + std::unique_ptr BFI; + std::unique_ptr BPI; if (F.hasProfileData()) { - BFI = &AM.getResult(F); - BPI = &AM.getResult(F); + LoopInfo LI{DominatorTree(F)}; + BPI.reset(new BranchProbabilityInfo(F, LI, &TLI)); + BFI.reset(new BlockFrequencyInfo(F, *BPI, LI)); } - bool Changed = - runImpl(F, &TLI, &TTI, &LVI, &AA, &DTU, F.hasProfileData(), BFI, BPI); + bool Changed = runImpl(F, &TLI, &TTI, &LVI, &AA, &DTU, F.hasProfileData(), + std::move(BFI), std::move(BPI)); if (PrintLVIAfterJumpThreading) { dbgs() << "LVI for function '" << F.getName() << "':\n"; @@ -374,16 +377,17 @@ PreservedAnalyses JumpThreadingPass::run(Function &F, bool JumpThreadingPass::runImpl(Function &F, TargetLibraryInfo *TLI_, TargetTransformInfo *TTI_, LazyValueInfo *LVI_, AliasAnalysis *AA_, DomTreeUpdater *DTU_, - bool HasProfileData_, BlockFrequencyInfo *BFI_, - BranchProbabilityInfo *BPI_) { + bool HasProfileData_, + std::unique_ptr BFI_, + std::unique_ptr BPI_) { LLVM_DEBUG(dbgs() << "Jump threading on function '" << F.getName() << "'\n"); TLI = TLI_; TTI = TTI_; LVI = LVI_; AA = AA_; DTU = DTU_; - BFI = BFI_; - BPI = BPI_; + BFI.reset(); + BPI.reset(); // When profile data is available, we need to update edge weights after // successful jump threading, which requires both BPI and BFI being available. HasProfileData = HasProfileData_; @@ -391,11 +395,8 @@ bool JumpThreadingPass::runImpl(Function &F, TargetLibraryInfo *TLI_, Intrinsic::getName(Intrinsic::experimental_guard)); HasGuards = GuardDecl && !GuardDecl->use_empty(); if (HasProfileData) { - assert(BFI && "BFI not provided?"); - assert(BPI && "BPI not provided?"); - } else { - assert(!BFI && "BFI should not be provided?"); - assert(!BPI && "BPI should not be provided?"); + BPI = std::move(BPI_); + BFI = std::move(BFI_); } // Reduce the number of instructions duplicated when optimizing strictly for -- 2.7.4