Skip to content

Commit 02aa795

Browse files
committed
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 35f3858.
1 parent 0314dba commit 02aa795

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

llvm/include/llvm/Transforms/Scalar/JumpThreading.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
8181
LazyValueInfo *LVI;
8282
AAResults *AA;
8383
DomTreeUpdater *DTU;
84-
BlockFrequencyInfo *BFI;
85-
BranchProbabilityInfo *BPI;
84+
std::unique_ptr<BlockFrequencyInfo> BFI;
85+
std::unique_ptr<BranchProbabilityInfo> BPI;
8686
bool HasProfileData = false;
8787
bool HasGuards = false;
8888
#ifndef LLVM_ENABLE_ABI_BREAKING_CHECKS
@@ -101,11 +101,16 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
101101
// Glue for old PM.
102102
bool runImpl(Function &F, TargetLibraryInfo *TLI, TargetTransformInfo *TTI,
103103
LazyValueInfo *LVI, AAResults *AA, DomTreeUpdater *DTU,
104-
bool HasProfileData, BlockFrequencyInfo *BFI,
105-
BranchProbabilityInfo *BPI);
104+
bool HasProfileData, std::unique_ptr<BlockFrequencyInfo> BFI,
105+
std::unique_ptr<BranchProbabilityInfo> BPI);
106106

107107
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
108108

109+
void releaseMemory() {
110+
BFI.reset();
111+
BPI.reset();
112+
}
113+
109114
void findLoopHeaders(Function &F);
110115
bool processBlock(BasicBlock *BB);
111116
bool maybeMergeBasicBlockIntoOnlyPred(BasicBlock *BB);

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ namespace {
155155
AU.addRequired<TargetLibraryInfoWrapperPass>();
156156
AU.addRequired<TargetTransformInfoWrapperPass>();
157157
}
158+
159+
void releaseMemory() override { Impl.releaseMemory(); }
158160
};
159161

160162
} // end anonymous namespace
@@ -328,7 +330,7 @@ bool JumpThreading::runOnFunction(Function &F) {
328330
}
329331

330332
bool Changed = Impl.runImpl(F, TLI, TTI, LVI, AA, &DTU, F.hasProfileData(),
331-
BFI.get(), BPI.get());
333+
std::move(BFI), std::move(BPI));
332334
if (PrintLVIAfterJumpThreading) {
333335
dbgs() << "LVI for function '" << F.getName() << "':\n";
334336
LVI->printLVI(F, DTU.getDomTree(), dbgs());
@@ -348,15 +350,16 @@ PreservedAnalyses JumpThreadingPass::run(Function &F,
348350
auto &AA = AM.getResult<AAManager>(F);
349351
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
350352

351-
BlockFrequencyInfo *BFI = nullptr;
352-
BranchProbabilityInfo *BPI = nullptr;
353+
std::unique_ptr<BlockFrequencyInfo> BFI;
354+
std::unique_ptr<BranchProbabilityInfo> BPI;
353355
if (F.hasProfileData()) {
354-
BFI = &AM.getResult<BlockFrequencyAnalysis>(F);
355-
BPI = &AM.getResult<BranchProbabilityAnalysis>(F);
356+
LoopInfo LI{DominatorTree(F)};
357+
BPI.reset(new BranchProbabilityInfo(F, LI, &TLI));
358+
BFI.reset(new BlockFrequencyInfo(F, *BPI, LI));
356359
}
357360

358-
bool Changed =
359-
runImpl(F, &TLI, &TTI, &LVI, &AA, &DTU, F.hasProfileData(), BFI, BPI);
361+
bool Changed = runImpl(F, &TLI, &TTI, &LVI, &AA, &DTU, F.hasProfileData(),
362+
std::move(BFI), std::move(BPI));
360363

361364
if (PrintLVIAfterJumpThreading) {
362365
dbgs() << "LVI for function '" << F.getName() << "':\n";
@@ -374,28 +377,26 @@ PreservedAnalyses JumpThreadingPass::run(Function &F,
374377
bool JumpThreadingPass::runImpl(Function &F, TargetLibraryInfo *TLI_,
375378
TargetTransformInfo *TTI_, LazyValueInfo *LVI_,
376379
AliasAnalysis *AA_, DomTreeUpdater *DTU_,
377-
bool HasProfileData_, BlockFrequencyInfo *BFI_,
378-
BranchProbabilityInfo *BPI_) {
380+
bool HasProfileData_,
381+
std::unique_ptr<BlockFrequencyInfo> BFI_,
382+
std::unique_ptr<BranchProbabilityInfo> BPI_) {
379383
LLVM_DEBUG(dbgs() << "Jump threading on function '" << F.getName() << "'\n");
380384
TLI = TLI_;
381385
TTI = TTI_;
382386
LVI = LVI_;
383387
AA = AA_;
384388
DTU = DTU_;
385-
BFI = BFI_;
386-
BPI = BPI_;
389+
BFI.reset();
390+
BPI.reset();
387391
// When profile data is available, we need to update edge weights after
388392
// successful jump threading, which requires both BPI and BFI being available.
389393
HasProfileData = HasProfileData_;
390394
auto *GuardDecl = F.getParent()->getFunction(
391395
Intrinsic::getName(Intrinsic::experimental_guard));
392396
HasGuards = GuardDecl && !GuardDecl->use_empty();
393397
if (HasProfileData) {
394-
assert(BFI && "BFI not provided?");
395-
assert(BPI && "BPI not provided?");
396-
} else {
397-
assert(!BFI && "BFI should not be provided?");
398-
assert(!BPI && "BPI should not be provided?");
398+
BPI = std::move(BPI_);
399+
BFI = std::move(BFI_);
399400
}
400401

401402
// Reduce the number of instructions duplicated when optimizing strictly for

0 commit comments

Comments
 (0)