Skip to content

Commit 0bc9834

Browse files
authored
[LICM] Use DomTreeUpdater version of SplitBlockPredecessors, nfc (#107190)
The DominatorTree version is marked for deprecation, so we use the DomTreeUpdater version. We also update sinkRegion() to iterate over basic blocks instead of DomTreeNodes. The loop body calls SplitBlockPredecessors. The DTU version calls DomTreeUpdater::apply_updates(), which may call DominatorTree::reset(). This invalidates the worklist of DomTreeNodes to iterate over.
1 parent 6f3c151 commit 0bc9834

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

llvm/include/llvm/Transforms/Utils/LoopUtils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ bool promoteLoopAccessesToScalars(
224224
bool AllowSpeculation, bool HasReadsOutsideSet);
225225

226226
/// Does a BFS from a given node to all of its children inside a given loop.
227-
/// The returned vector of nodes includes the starting point.
228-
SmallVector<DomTreeNode *, 16> collectChildrenInLoop(DomTreeNode *N,
229-
const Loop *CurLoop);
227+
/// The returned vector of basic blocks includes the starting point.
228+
SmallVector<BasicBlock *, 16>
229+
collectChildrenInLoop(DominatorTree *DT, DomTreeNode *N, const Loop *CurLoop);
230230

231231
/// Returns the instructions that use values defined in the loop.
232232
SmallVector<Instruction *, 8> findDefsUsedOutsideOfLoop(Loop *L);

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "llvm/Analysis/AliasSetTracker.h"
4545
#include "llvm/Analysis/AssumptionCache.h"
4646
#include "llvm/Analysis/CaptureTracking.h"
47+
#include "llvm/Analysis/DomTreeUpdater.h"
4748
#include "llvm/Analysis/GuardUtils.h"
4849
#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
4950
#include "llvm/Analysis/Loads.h"
@@ -65,9 +66,9 @@
6566
#include "llvm/IR/DebugInfoMetadata.h"
6667
#include "llvm/IR/DerivedTypes.h"
6768
#include "llvm/IR/Dominators.h"
69+
#include "llvm/IR/IRBuilder.h"
6870
#include "llvm/IR/Instructions.h"
6971
#include "llvm/IR/IntrinsicInst.h"
70-
#include "llvm/IR/IRBuilder.h"
7172
#include "llvm/IR/LLVMContext.h"
7273
#include "llvm/IR/Metadata.h"
7374
#include "llvm/IR/PatternMatch.h"
@@ -567,12 +568,11 @@ bool llvm::sinkRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
567568
// We want to visit children before parents. We will enqueue all the parents
568569
// before their children in the worklist and process the worklist in reverse
569570
// order.
570-
SmallVector<DomTreeNode *, 16> Worklist = collectChildrenInLoop(N, CurLoop);
571+
SmallVector<BasicBlock *, 16> Worklist =
572+
collectChildrenInLoop(DT, N, CurLoop);
571573

572574
bool Changed = false;
573-
for (DomTreeNode *DTN : reverse(Worklist)) {
574-
BasicBlock *BB = DTN->getBlock();
575-
// Only need to process the contents of this block if it is not part of a
575+
for (BasicBlock *BB : reverse(Worklist)) {
576576
// subloop (which would already have been processed).
577577
if (inSubLoop(BB, CurLoop, LI))
578578
continue;
@@ -1603,13 +1603,14 @@ static void splitPredecessorsOfLoopExit(PHINode *PN, DominatorTree *DT,
16031603
//
16041604
const auto &BlockColors = SafetyInfo->getBlockColors();
16051605
SmallSetVector<BasicBlock *, 8> PredBBs(pred_begin(ExitBB), pred_end(ExitBB));
1606+
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
16061607
while (!PredBBs.empty()) {
16071608
BasicBlock *PredBB = *PredBBs.begin();
16081609
assert(CurLoop->contains(PredBB) &&
16091610
"Expect all predecessors are in the loop");
16101611
if (PN->getBasicBlockIndex(PredBB) >= 0) {
16111612
BasicBlock *NewPred = SplitBlockPredecessors(
1612-
ExitBB, PredBB, ".split.loop.exit", DT, LI, MSSAU, true);
1613+
ExitBB, PredBB, ".split.loop.exit", &DTU, LI, MSSAU, true);
16131614
// Since we do not allow splitting EH-block with BlockColors in
16141615
// canSplitPredecessors(), we can simply assign predecessor's color to
16151616
// the new block.

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,21 +445,22 @@ TransformationMode llvm::hasLICMVersioningTransformation(const Loop *L) {
445445
}
446446

447447
/// Does a BFS from a given node to all of its children inside a given loop.
448-
/// The returned vector of nodes includes the starting point.
449-
SmallVector<DomTreeNode *, 16>
450-
llvm::collectChildrenInLoop(DomTreeNode *N, const Loop *CurLoop) {
451-
SmallVector<DomTreeNode *, 16> Worklist;
448+
/// The returned vector of basic blocks includes the starting point.
449+
SmallVector<BasicBlock *, 16> llvm::collectChildrenInLoop(DominatorTree *DT,
450+
DomTreeNode *N,
451+
const Loop *CurLoop) {
452+
SmallVector<BasicBlock *, 16> Worklist;
452453
auto AddRegionToWorklist = [&](DomTreeNode *DTN) {
453454
// Only include subregions in the top level loop.
454455
BasicBlock *BB = DTN->getBlock();
455456
if (CurLoop->contains(BB))
456-
Worklist.push_back(DTN);
457+
Worklist.push_back(DTN->getBlock());
457458
};
458459

459460
AddRegionToWorklist(N);
460461

461462
for (size_t I = 0; I < Worklist.size(); I++) {
462-
for (DomTreeNode *Child : Worklist[I]->children())
463+
for (DomTreeNode *Child : DT->getNode(Worklist[I])->children())
463464
AddRegionToWorklist(Child);
464465
}
465466

0 commit comments

Comments
 (0)