[llvm] 02aa795 - Revert "[JumpThreading][NFC][CompileTime] Do not recompute BPI/BFI analyzes"

James Y Knight via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 14:17:22 PDT 2022


Author: James Y Knight
Date: 2022-04-29T21:15:47Z
New Revision: 02aa795785379b34f1f82d1c4d852b915c5bfb4a

URL: https://github.com/llvm/llvm-project/commit/02aa795785379b34f1f82d1c4d852b915c5bfb4a
DIFF: https://github.com/llvm/llvm-project/commit/02aa795785379b34f1f82d1c4d852b915c5bfb4a.diff

LOG: 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.

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/Scalar/JumpThreading.h
    llvm/lib/Transforms/Scalar/JumpThreading.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
index 8b4e8b016e37f..c14855ef5f73b 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<JumpThreadingPass> {
   LazyValueInfo *LVI;
   AAResults *AA;
   DomTreeUpdater *DTU;
-  BlockFrequencyInfo *BFI;
-  BranchProbabilityInfo *BPI;
+  std::unique_ptr<BlockFrequencyInfo> BFI;
+  std::unique_ptr<BranchProbabilityInfo> BPI;
   bool HasProfileData = false;
   bool HasGuards = false;
 #ifndef LLVM_ENABLE_ABI_BREAKING_CHECKS
@@ -101,11 +101,16 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
   // 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<BlockFrequencyInfo> BFI,
+               std::unique_ptr<BranchProbabilityInfo> 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 51dacc0e66238..5ae670c002fd8 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -155,6 +155,8 @@ namespace {
       AU.addRequired<TargetLibraryInfoWrapperPass>();
       AU.addRequired<TargetTransformInfoWrapperPass>();
     }
+
+    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<AAManager>(F);
   DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
 
-  BlockFrequencyInfo *BFI = nullptr;
-  BranchProbabilityInfo *BPI = nullptr;
+  std::unique_ptr<BlockFrequencyInfo> BFI;
+  std::unique_ptr<BranchProbabilityInfo> BPI;
   if (F.hasProfileData()) {
-    BFI = &AM.getResult<BlockFrequencyAnalysis>(F);
-    BPI = &AM.getResult<BranchProbabilityAnalysis>(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<BlockFrequencyInfo> BFI_,
+                                std::unique_ptr<BranchProbabilityInfo> 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


        


More information about the llvm-commits mailing list