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
// 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);
AU.addRequired<TargetLibraryInfoWrapperPass>();
AU.addRequired<TargetTransformInfoWrapperPass>();
}
+
+ void releaseMemory() override { Impl.releaseMemory(); }
};
} // end anonymous namespace
}
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());
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";
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_;
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