Skip to content

Commit f131d61

Browse files
committed
[DTU] Deprecate insertEdge*/deleteEdge*
Summary: This patch converts all existing `insertEdge*/deleteEdge*` to `applyUpdates` and marks `insertEdge*/deleteEdge*` as deprecated. Reviewers: kuhar, brzycki Reviewed By: kuhar, brzycki Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58443 llvm-svn: 354652
1 parent 00ebc0c commit f131d61

File tree

9 files changed

+49
-33
lines changed

9 files changed

+49
-33
lines changed

llvm/include/llvm/Analysis/DomTreeUpdater.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ class DomTreeUpdater {
136136
/// DEBUG mode. CAUTION! This function has to be called *after* making the
137137
/// update on the actual CFG. It is illegal to submit any update that has
138138
/// already been applied. }
139-
void insertEdge(BasicBlock *From, BasicBlock *To);
139+
LLVM_ATTRIBUTE_DEPRECATED(void insertEdge(BasicBlock *From, BasicBlock *To),
140+
"Use applyUpdates() instead.");
140141

141142
/// \deprecated {Submit an edge insertion to all available trees.
142143
/// Under either Strategy, an invalid update will be discard silently.
@@ -146,7 +147,9 @@ class DomTreeUpdater {
146147
/// want to discard an invalid update.
147148
/// CAUTION! It is illegal to submit any update that has already been
148149
/// submitted. }
149-
void insertEdgeRelaxed(BasicBlock *From, BasicBlock *To);
150+
LLVM_ATTRIBUTE_DEPRECATED(void insertEdgeRelaxed(BasicBlock *From,
151+
BasicBlock *To),
152+
"Use applyUpdates() instead.");
150153

151154
/// \deprecated { Submit an edge deletion to all available trees. The Eager
152155
/// Strategy flushes this update immediately while the Lazy Strategy queues
@@ -155,7 +158,8 @@ class DomTreeUpdater {
155158
/// CAUTION! This function has to be called *after* making the update on the
156159
/// actual CFG. It is illegal to submit any update that has already been
157160
/// submitted. }
158-
void deleteEdge(BasicBlock *From, BasicBlock *To);
161+
LLVM_ATTRIBUTE_DEPRECATED(void deleteEdge(BasicBlock *From, BasicBlock *To),
162+
"Use applyUpdates() instead.");
159163

160164
/// \deprecated { Submit an edge deletion to all available trees.
161165
/// Under either Strategy, an invalid update will be discard silently.
@@ -165,7 +169,9 @@ class DomTreeUpdater {
165169
/// want to discard an invalid update.
166170
/// CAUTION! It is illegal to submit any update that has already been
167171
/// submitted. }
168-
void deleteEdgeRelaxed(BasicBlock *From, BasicBlock *To);
172+
LLVM_ATTRIBUTE_DEPRECATED(void deleteEdgeRelaxed(BasicBlock *From,
173+
BasicBlock *To),
174+
"Use applyUpdates() instead.");
169175

170176
/// Delete DelBB. DelBB will be removed from its Parent and
171177
/// erased from available trees if it exists and finally get deleted.

llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static void splitCallSite(
366366
assert(Splits.size() == 2 && "Expected exactly 2 splits!");
367367
for (unsigned i = 0; i < Splits.size(); i++) {
368368
Splits[i]->getTerminator()->eraseFromParent();
369-
DTU.deleteEdge(Splits[i], TailBB);
369+
DTU.applyUpdates({{DominatorTree::Delete, Splits[i], TailBB}});
370370
}
371371

372372
// Erase the tail block once done with musttail patching

llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI,
373373
++NumDeadCases;
374374
Changed = true;
375375
if (--SuccessorsCount[Succ] == 0)
376-
DTU.deleteEdge(BB, Succ);
376+
DTU.applyUpdates({{DominatorTree::Delete, BB, Succ}});
377377
continue;
378378
}
379379
if (State == LazyValueInfo::True) {

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) {
11591159
ConstantInt::getFalse(CondCmp->getType());
11601160
ReplaceFoldableUses(CondCmp, CI);
11611161
}
1162-
DTU->deleteEdgeRelaxed(BB, ToRemoveSucc);
1162+
DTU->applyUpdates({{DominatorTree::Delete, BB, ToRemoveSucc}});
11631163
return true;
11641164
}
11651165

@@ -1246,7 +1246,7 @@ bool JumpThreadingPass::ProcessImpliedCondition(BasicBlock *BB) {
12461246
RemoveSucc->removePredecessor(BB);
12471247
BranchInst::Create(KeepSucc, BI);
12481248
BI->eraseFromParent();
1249-
DTU->deleteEdgeRelaxed(BB, RemoveSucc);
1249+
DTU->applyUpdates({{DominatorTree::Delete, BB, RemoveSucc}});
12501250
return true;
12511251
}
12521252
CurrentBB = CurrentPred;

llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ static bool eliminateRecursiveTailCall(
678678

679679
BB->getInstList().erase(Ret); // Remove return.
680680
BB->getInstList().erase(CI); // Remove call.
681-
DTU.insertEdge(BB, OldEntry);
681+
DTU.applyUpdates({{DominatorTree::Insert, BB, OldEntry}});
682682
++NumEliminated;
683683
return true;
684684
}

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
721721
UncondBranch->eraseFromParent();
722722

723723
if (DTU)
724-
DTU->deleteEdge(Pred, BB);
724+
DTU->applyUpdates({{DominatorTree::Delete, Pred, BB}});
725725

726726
return cast<ReturnInst>(NewRet);
727727
}

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
128128
Builder.CreateBr(Destination);
129129
BI->eraseFromParent();
130130
if (DTU)
131-
DTU->deleteEdgeRelaxed(BB, OldDest);
131+
DTU->applyUpdates({{DominatorTree::Delete, BB, OldDest}},
132+
/*ForceRemoveDuplicates*/ true);
132133
return true;
133134
}
134135

@@ -204,7 +205,8 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
204205
i = SI->removeCase(i);
205206
e = SI->case_end();
206207
if (DTU)
207-
DTU->deleteEdgeRelaxed(ParentBB, DefaultDest);
208+
DTU->applyUpdates({{DominatorTree::Delete, ParentBB, DefaultDest}},
209+
/*ForceRemoveDuplicates*/ true);
208210
continue;
209211
}
210212

@@ -664,7 +666,8 @@ void llvm::RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred,
664666
if (PhiIt != OldPhiIt) PhiIt = &BB->front();
665667
}
666668
if (DTU)
667-
DTU->deleteEdgeRelaxed(Pred, BB);
669+
DTU->applyUpdates({{DominatorTree::Delete, Pred, BB}},
670+
/*ForceRemoveDuplicates*/ true);
668671
}
669672

670673
/// MergeBasicBlockIntoOnlyPred - DestBB is a block with one predecessor and its
@@ -1967,7 +1970,8 @@ static void changeToCall(InvokeInst *II, DomTreeUpdater *DTU = nullptr) {
19671970
UnwindDestBB->removePredecessor(BB);
19681971
II->eraseFromParent();
19691972
if (DTU)
1970-
DTU->deleteEdgeRelaxed(BB, UnwindDestBB);
1973+
DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}},
1974+
/*ForceRemoveDuplicates*/ true);
19711975
}
19721976

19731977
BasicBlock *llvm::changeToInvokeAndSplitBasicBlock(CallInst *CI,
@@ -2114,7 +2118,8 @@ static bool markAliveBlocks(Function &F,
21142118
UnwindDestBB->removePredecessor(II->getParent());
21152119
II->eraseFromParent();
21162120
if (DTU)
2117-
DTU->deleteEdgeRelaxed(BB, UnwindDestBB);
2121+
DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}},
2122+
/*ForceRemoveDuplicates*/ true);
21182123
} else
21192124
changeToCall(II, DTU);
21202125
Changed = true;
@@ -2203,7 +2208,8 @@ void llvm::removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU) {
22032208
TI->replaceAllUsesWith(NewTI);
22042209
TI->eraseFromParent();
22052210
if (DTU)
2206-
DTU->deleteEdgeRelaxed(BB, UnwindDest);
2211+
DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDest}},
2212+
/*ForceRemoveDuplicates*/ true);
22072213
}
22082214

22092215
/// removeUnreachableBlocks - Remove blocks that are not reachable, even

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,9 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT = nullptr,
535535
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
536536
if (DT) {
537537
// Update the dominator tree by informing it about the new edge from the
538-
// preheader to the exit.
539-
DTU.insertEdge(Preheader, ExitBlock);
540-
// Inform the dominator tree about the removed edge.
541-
DTU.deleteEdge(Preheader, L->getHeader());
538+
// preheader to the exit and the removed edge.
539+
DTU.applyUpdates({{DominatorTree::Insert, Preheader, ExitBlock},
540+
{DominatorTree::Delete, Preheader, L->getHeader()}});
542541
}
543542

544543
// Use a map to unique and a vector to guarantee deterministic ordering.

llvm/unittests/Analysis/DomTreeUpdaterTest.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ TEST(DomTreeUpdater, EagerUpdateBasicOperations) {
7171
SwitchInst *SI = dyn_cast<SwitchInst>(BB0->getTerminator());
7272
ASSERT_NE(SI, nullptr) << "Couldn't get SwitchInst.";
7373

74-
DTU.insertEdgeRelaxed(BB0, BB0);
75-
DTU.deleteEdgeRelaxed(BB0, BB0);
74+
DTU.applyUpdates(
75+
{{DominatorTree::Insert, BB0, BB0}, {DominatorTree::Delete, BB0, BB0}},
76+
/*ForceRemoveDuplicates*/ true);
7677

7778
// Delete edge bb0 -> bb3 and push the update twice to verify duplicate
7879
// entries are discarded.
@@ -105,9 +106,10 @@ TEST(DomTreeUpdater, EagerUpdateBasicOperations) {
105106
ASSERT_FALSE(DTU.hasPendingUpdates());
106107

107108
// Invalid Insert: no edge bb1 -> bb2 after change to bb0.
108-
DTU.insertEdgeRelaxed(BB1, BB2);
109109
// Invalid Delete: edge exists bb0 -> bb1 after change to bb0.
110-
DTU.deleteEdgeRelaxed(BB0, BB1);
110+
DTU.applyUpdates(
111+
{{DominatorTree::Insert, BB1, BB2}, {DominatorTree::Delete, BB0, BB1}},
112+
/*ForceRemoveDuplicates*/ true);
111113

112114
// DTU working with Eager UpdateStrategy does not need to flush.
113115
ASSERT_TRUE(DT.verify());
@@ -182,7 +184,8 @@ TEST(DomTreeUpdater, EagerUpdateReplaceEntryBB) {
182184
EXPECT_EQ(F->begin()->getName(), NewEntry->getName());
183185
EXPECT_TRUE(&F->getEntryBlock() == NewEntry);
184186

185-
DTU.insertEdgeRelaxed(NewEntry, BB0);
187+
DTU.applyUpdates({{DominatorTree::Insert, NewEntry, BB0}},
188+
/*ForceRemoveDuplicates*/ true);
186189

187190
// Changing the Entry BB requires a full recalculation of DomTree.
188191
DTU.recalculate(*F);
@@ -251,7 +254,7 @@ TEST(DomTreeUpdater, LazyUpdateDTBasicOperations) {
251254
BasicBlock *BB3 = &*FI++;
252255

253256
// Test discards of self-domination update.
254-
DTU.deleteEdge(BB0, BB0);
257+
DTU.applyUpdates({{DominatorTree::Delete, BB0, BB0}});
255258
ASSERT_FALSE(DTU.hasPendingDomTreeUpdates());
256259

257260
// Delete edge bb0 -> bb3 and push the update twice to verify duplicate
@@ -358,8 +361,10 @@ TEST(DomTreeUpdater, LazyUpdateDTInheritedPreds) {
358361
// +-> succ
359362
//
360363
// While the final CFG form is functionally identical the updates to
361-
// DTU are not. In the first case we must have DTU.insertEdge(Pred1, Succ)
362-
// while in the latter case we must *NOT* have DTU.insertEdge(Pred1, Succ).
364+
// DTU are not. In the first case we must have
365+
// DTU.applyUpdates({{DominatorTree::Insert, Pred1, Succ}}) while in the
366+
// latter case we must *NOT* have DTU.applyUpdates({{DominatorTree::Insert,
367+
// Pred1, Succ}}).
363368

364369
// CFG Change: bb0 now only has bb0 -> bb1 and bb0 -> bb3. We are preparing to
365370
// remove bb2.
@@ -412,9 +417,9 @@ TEST(DomTreeUpdater, LazyUpdateDTInheritedPreds) {
412417
ASSERT_TRUE(isa<UnreachableInst>(BB1->getTerminator()));
413418
EXPECT_EQ(BB1->getParent(), F);
414419

415-
// Update the DTU. In this case we don't call DTU.insertEdge(BB0, BB3) because
416-
// the edge previously existed at the start of this test when DT was first
417-
// created.
420+
// Update the DTU. In this case we don't submit {DominatorTree::Insert, BB0,
421+
// BB3} because the edge previously existed at the start of this test when DT
422+
// was first created.
418423
Updates.push_back({DominatorTree::Delete, BB0, BB1});
419424
Updates.push_back({DominatorTree::Delete, BB1, BB3});
420425

@@ -467,7 +472,7 @@ TEST(DomTreeUpdater, LazyUpdateBasicOperations) {
467472
BasicBlock *BB2 = &*FI++;
468473
BasicBlock *BB3 = &*FI++;
469474
// Test discards of self-domination update.
470-
DTU.deleteEdge(BB0, BB0);
475+
DTU.applyUpdates({{DominatorTree::Delete, BB0, BB0}});
471476

472477
// Delete edge bb0 -> bb3 and push the update twice to verify duplicate
473478
// entries are discarded.
@@ -558,7 +563,7 @@ TEST(DomTreeUpdater, LazyUpdateReplaceEntryBB) {
558563
// Insert the new edge between new_entry -> bb0. Without this the
559564
// recalculate() call below will not actually recalculate the DT as there
560565
// are no changes pending and no blocks deleted.
561-
DTU.insertEdge(NewEntry, BB0);
566+
DTU.applyUpdates({{DominatorTree::Insert, NewEntry, BB0}});
562567

563568
// Changing the Entry BB requires a full recalculation.
564569
DTU.recalculate(*F);

0 commit comments

Comments
 (0)