Skip to content

Commit c992690

Browse files
committed
Revert "[nfc][mlgo] Incrementally update DominatorTreeAnalysis in FunctionPropertiesAnalysis (llvm#104867)"
This seems to cause asserts in our builds: llvm/include/llvm/Support/GenericDomTreeConstruction.h:927: static void llvm::DomTreeBuilder::SemiNCAInfo<llvm::DominatorTreeBase<BasicBlock, false>>::DeleteEdge(DomTreeT &, const BatchUpdatePtr, const NodePtr, const NodePtr) [DomTreeT = llvm::DominatorTreeBase<BasicBlock, false>]: Assertion `!IsSuccessor(To, From) && "Deleted edge still exists in the CFG!"' failed. and llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp:390: DominatorTree &llvm::FunctionPropertiesUpdater::getUpdatedDominatorTree(FunctionAnalysisManager &) const: Assertion `DT.getNode(BB)' failed. See comment on the PR. > We need the dominator tree analysis for loop info analysis, which we need to get features like most nested loop and number of top level loops. Invalidating and recomputing these from scratch after each successful inlining can sometimes lead to lengthy compile times. We don't need to recompute from scratch, though, since we have some boundary information about where the changes to the CFG happen; moreover, for dom tree, the API supports incrementally updating the analysis result. > > This change addresses the dom tree part. The loop info is still recomputed from scratch. This does reduce the compile time quite significantly already, though (~5x in a specific case) > > The loop info change might be more involved and would follow in a subsequent PR. This reverts commit a2a5508 and the follow-up commit cdd11d6.
1 parent 657f26f commit c992690

File tree

3 files changed

+3
-47
lines changed

3 files changed

+3
-47
lines changed

llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
1616

1717
#include "llvm/ADT/DenseSet.h"
18-
#include "llvm/IR/Dominators.h"
1918
#include "llvm/IR/PassManager.h"
2019

2120
namespace llvm {
@@ -187,12 +186,7 @@ class FunctionPropertiesUpdater {
187186
static bool isUpdateValid(Function &F, const FunctionPropertiesInfo &FPI,
188187
FunctionAnalysisManager &FAM);
189188

190-
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
191-
192189
DenseSet<const BasicBlock *> Successors;
193-
194-
// Edges we might potentially need to remove from the dominator tree.
195-
SmallVector<DominatorTree::UpdateType, 2> DomTreeUpdates;
196190
};
197191
} // namespace llvm
198192
#endif // LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H

llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,6 @@ FunctionPropertiesUpdater::FunctionPropertiesUpdater(
326326
// with the CB BB ('Entry') between which the inlined callee will be pasted.
327327
Successors.insert(succ_begin(&CallSiteBB), succ_end(&CallSiteBB));
328328

329-
// the outcome of the inlining may be that some edges get lost (DCEd BBs
330-
// because inlining brought some constant, for example). We don't know which
331-
// edges will be removed, so we list all of them as potentially removable.
332-
for (auto *Succ : successors(&CallSiteBB))
333-
DomTreeUpdates.emplace_back(DominatorTree::UpdateKind::Delete,
334-
const_cast<BasicBlock *>(&CallSiteBB),
335-
const_cast<BasicBlock *>(Succ));
336-
337329
// Inlining only handles invoke and calls. If this is an invoke, and inlining
338330
// it pulls another invoke, the original landing pad may get split, so as to
339331
// share its content with other potential users. So the edge up to which we
@@ -344,11 +336,6 @@ FunctionPropertiesUpdater::FunctionPropertiesUpdater(
344336
if (const auto *II = dyn_cast<InvokeInst>(&CB)) {
345337
const auto *UnwindDest = II->getUnwindDest();
346338
Successors.insert(succ_begin(UnwindDest), succ_end(UnwindDest));
347-
// Same idea as above, we pretend we lose all these edges.
348-
for (auto *Succ : successors(UnwindDest))
349-
DomTreeUpdates.emplace_back(DominatorTree::UpdateKind::Delete,
350-
const_cast<BasicBlock *>(UnwindDest),
351-
const_cast<BasicBlock *>(Succ));
352339
}
353340

354341
// Exclude the CallSiteBB, if it happens to be its own successor (1-BB loop).
@@ -369,30 +356,6 @@ FunctionPropertiesUpdater::FunctionPropertiesUpdater(
369356
FPI.updateForBB(*BB, -1);
370357
}
371358

372-
DominatorTree &FunctionPropertiesUpdater::getUpdatedDominatorTree(
373-
FunctionAnalysisManager &FAM) const {
374-
auto &DT =
375-
FAM.getResult<DominatorTreeAnalysis>(const_cast<Function &>(Caller));
376-
377-
SmallVector<DominatorTree::UpdateType, 2> FinalDomTreeUpdates;
378-
379-
for (auto &Upd : DomTreeUpdates)
380-
FinalDomTreeUpdates.push_back(Upd);
381-
382-
DenseSet<const BasicBlock *> Inserted;
383-
for (auto *Succ : successors(&CallSiteBB))
384-
if (Inserted.insert(Succ).second)
385-
FinalDomTreeUpdates.push_back({DominatorTree::UpdateKind::Insert,
386-
const_cast<BasicBlock *>(&CallSiteBB),
387-
const_cast<BasicBlock *>(Succ)});
388-
389-
DT.applyUpdates(FinalDomTreeUpdates);
390-
#ifdef EXPENSIVE_CHECKS
391-
assert(DT.verify(DominatorTree::VerificationLevel::Full));
392-
#endif
393-
return DT;
394-
}
395-
396359
void FunctionPropertiesUpdater::finish(FunctionAnalysisManager &FAM) const {
397360
// Update feature values from the BBs that were copied from the callee, or
398361
// might have been modified because of inlining. The latter have been
@@ -420,7 +383,8 @@ void FunctionPropertiesUpdater::finish(FunctionAnalysisManager &FAM) const {
420383
// remove E.
421384
SetVector<const BasicBlock *> Reinclude;
422385
SetVector<const BasicBlock *> Unreachable;
423-
auto &DT = getUpdatedDominatorTree(FAM);
386+
const auto &DT =
387+
FAM.getResult<DominatorTreeAnalysis>(const_cast<Function &>(Caller));
424388

425389
if (&CallSiteBB != &*Caller.begin())
426390
Reinclude.insert(&*Caller.begin());
@@ -463,9 +427,6 @@ void FunctionPropertiesUpdater::finish(FunctionAnalysisManager &FAM) const {
463427

464428
const auto &LI = FAM.getResult<LoopAnalysis>(const_cast<Function &>(Caller));
465429
FPI.updateAggregateStats(Caller, LI);
466-
#ifdef EXPENSIVE_CHECKS
467-
assert(isUpdateValid(Caller, FPI, FAM));
468-
#endif
469430
}
470431

471432
bool FunctionPropertiesUpdater::isUpdateValid(Function &F,

llvm/lib/Analysis/MLInlineAdvisor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ void MLInlineAdvisor::onSuccessfulInlining(const MLInlineAdvice &Advice,
288288
{
289289
PreservedAnalyses PA = PreservedAnalyses::all();
290290
PA.abandon<FunctionPropertiesAnalysis>();
291+
PA.abandon<DominatorTreeAnalysis>();
291292
PA.abandon<LoopAnalysis>();
292293
FAM.invalidate(*Caller, PA);
293294
}

0 commit comments

Comments
 (0)