Index: llvm/include/llvm/Transforms/Scalar/JumpThreading.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/JumpThreading.h +++ llvm/include/llvm/Transforms/Scalar/JumpThreading.h @@ -81,8 +81,8 @@ LazyValueInfo *LVI; AAResults *AA; DomTreeUpdater *DTU; - std::unique_ptr BFI; - std::unique_ptr BPI; + BlockFrequencyInfo *BFI; + BranchProbabilityInfo *BPI; bool HasProfileData = false; bool HasGuards = false; #ifndef LLVM_ENABLE_ABI_BREAKING_CHECKS @@ -101,16 +101,11 @@ // Glue for old PM. bool runImpl(Function &F, TargetLibraryInfo *TLI, TargetTransformInfo *TTI, LazyValueInfo *LVI, AAResults *AA, DomTreeUpdater *DTU, - bool HasProfileData, std::unique_ptr BFI, - std::unique_ptr BPI); + bool HasProfileData, BlockFrequencyInfo *BFI, + 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); Index: llvm/lib/Transforms/Scalar/JumpThreading.cpp =================================================================== --- llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -155,8 +155,6 @@ AU.addRequired(); AU.addRequired(); } - - void releaseMemory() override { Impl.releaseMemory(); } }; } // end anonymous namespace @@ -330,7 +328,7 @@ } bool Changed = Impl.runImpl(F, TLI, TTI, LVI, AA, &DTU, F.hasProfileData(), - std::move(BFI), std::move(BPI)); + BFI.get(), BPI.get()); if (PrintLVIAfterJumpThreading) { dbgs() << "LVI for function '" << F.getName() << "':\n"; LVI->printLVI(F, DTU.getDomTree(), dbgs()); @@ -350,16 +348,15 @@ auto &AA = AM.getResult(F); DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy); - std::unique_ptr BFI; - std::unique_ptr BPI; + BlockFrequencyInfo *BFI = nullptr; + BranchProbabilityInfo *BPI = nullptr; if (F.hasProfileData()) { - LoopInfo LI{DominatorTree(F)}; - BPI.reset(new BranchProbabilityInfo(F, LI, &TLI)); - BFI.reset(new BlockFrequencyInfo(F, *BPI, LI)); + BFI = &AM.getResult(F); + BPI = &AM.getResult(F); } - bool Changed = runImpl(F, &TLI, &TTI, &LVI, &AA, &DTU, F.hasProfileData(), - std::move(BFI), std::move(BPI)); + bool Changed = + runImpl(F, &TLI, &TTI, &LVI, &AA, &DTU, F.hasProfileData(), BFI, BPI); if (PrintLVIAfterJumpThreading) { dbgs() << "LVI for function '" << F.getName() << "':\n"; @@ -377,17 +374,16 @@ bool JumpThreadingPass::runImpl(Function &F, TargetLibraryInfo *TLI_, TargetTransformInfo *TTI_, LazyValueInfo *LVI_, AliasAnalysis *AA_, DomTreeUpdater *DTU_, - bool HasProfileData_, - std::unique_ptr BFI_, - std::unique_ptr BPI_) { + bool HasProfileData_, BlockFrequencyInfo *BFI_, + BranchProbabilityInfo *BPI_) { LLVM_DEBUG(dbgs() << "Jump threading on function '" << F.getName() << "'\n"); TLI = TLI_; TTI = TTI_; LVI = LVI_; AA = AA_; DTU = DTU_; - BFI.reset(); - BPI.reset(); + BFI = BFI_; + BPI = BPI_; // 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_; @@ -395,8 +391,11 @@ Intrinsic::getName(Intrinsic::experimental_guard)); HasGuards = GuardDecl && !GuardDecl->use_empty(); if (HasProfileData) { - BPI = std::move(BPI_); - BFI = std::move(BFI_); + 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?"); } // Reduce the number of instructions duplicated when optimizing strictly for