llvm.org GIT mirror llvm / e9b2f29
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354652 91177308-0d34-0410-b5e6-96231b3b80d8 Chijun Sima 5 months ago
9 changed file(s) with 49 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
135135 /// DEBUG mode. CAUTION! This function has to be called *after* making the
136136 /// update on the actual CFG. It is illegal to submit any update that has
137137 /// already been applied. }
138 void insertEdge(BasicBlock *From, BasicBlock *To);
138 LLVM_ATTRIBUTE_DEPRECATED(void insertEdge(BasicBlock *From, BasicBlock *To),
139 "Use applyUpdates() instead.");
139140
140141 /// \deprecated {Submit an edge insertion to all available trees.
141142 /// Under either Strategy, an invalid update will be discard silently.
145146 /// want to discard an invalid update.
146147 /// CAUTION! It is illegal to submit any update that has already been
147148 /// submitted. }
148 void insertEdgeRelaxed(BasicBlock *From, BasicBlock *To);
149 LLVM_ATTRIBUTE_DEPRECATED(void insertEdgeRelaxed(BasicBlock *From,
150 BasicBlock *To),
151 "Use applyUpdates() instead.");
149152
150153 /// \deprecated { Submit an edge deletion to all available trees. The Eager
151154 /// Strategy flushes this update immediately while the Lazy Strategy queues
154157 /// CAUTION! This function has to be called *after* making the update on the
155158 /// actual CFG. It is illegal to submit any update that has already been
156159 /// submitted. }
157 void deleteEdge(BasicBlock *From, BasicBlock *To);
160 LLVM_ATTRIBUTE_DEPRECATED(void deleteEdge(BasicBlock *From, BasicBlock *To),
161 "Use applyUpdates() instead.");
158162
159163 /// \deprecated { Submit an edge deletion to all available trees.
160164 /// Under either Strategy, an invalid update will be discard silently.
164168 /// want to discard an invalid update.
165169 /// CAUTION! It is illegal to submit any update that has already been
166170 /// submitted. }
167 void deleteEdgeRelaxed(BasicBlock *From, BasicBlock *To);
171 LLVM_ATTRIBUTE_DEPRECATED(void deleteEdgeRelaxed(BasicBlock *From,
172 BasicBlock *To),
173 "Use applyUpdates() instead.");
168174
169175 /// Delete DelBB. DelBB will be removed from its Parent and
170176 /// erased from available trees if it exists and finally get deleted.
365365 assert(Splits.size() == 2 && "Expected exactly 2 splits!");
366366 for (unsigned i = 0; i < Splits.size(); i++) {
367367 Splits[i]->getTerminator()->eraseFromParent();
368 DTU.deleteEdge(Splits[i], TailBB);
368 DTU.applyUpdates({{DominatorTree::Delete, Splits[i], TailBB}});
369369 }
370370
371371 // Erase the tail block once done with musttail patching
372372 ++NumDeadCases;
373373 Changed = true;
374374 if (--SuccessorsCount[Succ] == 0)
375 DTU.deleteEdge(BB, Succ);
375 DTU.applyUpdates({{DominatorTree::Delete, BB, Succ}});
376376 continue;
377377 }
378378 if (State == LazyValueInfo::True) {
11581158 ConstantInt::getFalse(CondCmp->getType());
11591159 ReplaceFoldableUses(CondCmp, CI);
11601160 }
1161 DTU->deleteEdgeRelaxed(BB, ToRemoveSucc);
1161 DTU->applyUpdates({{DominatorTree::Delete, BB, ToRemoveSucc}});
11621162 return true;
11631163 }
11641164
12451245 RemoveSucc->removePredecessor(BB);
12461246 BranchInst::Create(KeepSucc, BI);
12471247 BI->eraseFromParent();
1248 DTU->deleteEdgeRelaxed(BB, RemoveSucc);
1248 DTU->applyUpdates({{DominatorTree::Delete, BB, RemoveSucc}});
12491249 return true;
12501250 }
12511251 CurrentBB = CurrentPred;
677677
678678 BB->getInstList().erase(Ret); // Remove return.
679679 BB->getInstList().erase(CI); // Remove call.
680 DTU.insertEdge(BB, OldEntry);
680 DTU.applyUpdates({{DominatorTree::Insert, BB, OldEntry}});
681681 ++NumEliminated;
682682 return true;
683683 }
720720 UncondBranch->eraseFromParent();
721721
722722 if (DTU)
723 DTU->deleteEdge(Pred, BB);
723 DTU->applyUpdates({{DominatorTree::Delete, Pred, BB}});
724724
725725 return cast(NewRet);
726726 }
127127 Builder.CreateBr(Destination);
128128 BI->eraseFromParent();
129129 if (DTU)
130 DTU->deleteEdgeRelaxed(BB, OldDest);
130 DTU->applyUpdates({{DominatorTree::Delete, BB, OldDest}},
131 /*ForceRemoveDuplicates*/ true);
131132 return true;
132133 }
133134
203204 i = SI->removeCase(i);
204205 e = SI->case_end();
205206 if (DTU)
206 DTU->deleteEdgeRelaxed(ParentBB, DefaultDest);
207 DTU->applyUpdates({{DominatorTree::Delete, ParentBB, DefaultDest}},
208 /*ForceRemoveDuplicates*/ true);
207209 continue;
208210 }
209211
663665 if (PhiIt != OldPhiIt) PhiIt = &BB->front();
664666 }
665667 if (DTU)
666 DTU->deleteEdgeRelaxed(Pred, BB);
668 DTU->applyUpdates({{DominatorTree::Delete, Pred, BB}},
669 /*ForceRemoveDuplicates*/ true);
667670 }
668671
669672 /// MergeBasicBlockIntoOnlyPred - DestBB is a block with one predecessor and its
19661969 UnwindDestBB->removePredecessor(BB);
19671970 II->eraseFromParent();
19681971 if (DTU)
1969 DTU->deleteEdgeRelaxed(BB, UnwindDestBB);
1972 DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}},
1973 /*ForceRemoveDuplicates*/ true);
19701974 }
19711975
19721976 BasicBlock *llvm::changeToInvokeAndSplitBasicBlock(CallInst *CI,
21132117 UnwindDestBB->removePredecessor(II->getParent());
21142118 II->eraseFromParent();
21152119 if (DTU)
2116 DTU->deleteEdgeRelaxed(BB, UnwindDestBB);
2120 DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}},
2121 /*ForceRemoveDuplicates*/ true);
21172122 } else
21182123 changeToCall(II, DTU);
21192124 Changed = true;
22022207 TI->replaceAllUsesWith(NewTI);
22032208 TI->eraseFromParent();
22042209 if (DTU)
2205 DTU->deleteEdgeRelaxed(BB, UnwindDest);
2210 DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDest}},
2211 /*ForceRemoveDuplicates*/ true);
22062212 }
22072213
22082214 /// removeUnreachableBlocks - Remove blocks that are not reachable, even
534534 DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
535535 if (DT) {
536536 // Update the dominator tree by informing it about the new edge from the
537 // preheader to the exit.
538 DTU.insertEdge(Preheader, ExitBlock);
539 // Inform the dominator tree about the removed edge.
540 DTU.deleteEdge(Preheader, L->getHeader());
537 // preheader to the exit and the removed edge.
538 DTU.applyUpdates({{DominatorTree::Insert, Preheader, ExitBlock},
539 {DominatorTree::Delete, Preheader, L->getHeader()}});
541540 }
542541
543542 // Use a map to unique and a vector to guarantee deterministic ordering.
7070 SwitchInst *SI = dyn_cast(BB0->getTerminator());
7171 ASSERT_NE(SI, nullptr) << "Couldn't get SwitchInst.";
7272
73 DTU.insertEdgeRelaxed(BB0, BB0);
74 DTU.deleteEdgeRelaxed(BB0, BB0);
73 DTU.applyUpdates(
74 {{DominatorTree::Insert, BB0, BB0}, {DominatorTree::Delete, BB0, BB0}},
75 /*ForceRemoveDuplicates*/ true);
7576
7677 // Delete edge bb0 -> bb3 and push the update twice to verify duplicate
7778 // entries are discarded.
104105 ASSERT_FALSE(DTU.hasPendingUpdates());
105106
106107 // Invalid Insert: no edge bb1 -> bb2 after change to bb0.
107 DTU.insertEdgeRelaxed(BB1, BB2);
108108 // Invalid Delete: edge exists bb0 -> bb1 after change to bb0.
109 DTU.deleteEdgeRelaxed(BB0, BB1);
109 DTU.applyUpdates(
110 {{DominatorTree::Insert, BB1, BB2}, {DominatorTree::Delete, BB0, BB1}},
111 /*ForceRemoveDuplicates*/ true);
110112
111113 // DTU working with Eager UpdateStrategy does not need to flush.
112114 ASSERT_TRUE(DT.verify());
181183 EXPECT_EQ(F->begin()->getName(), NewEntry->getName());
182184 EXPECT_TRUE(&F->getEntryBlock() == NewEntry);
183185
184 DTU.insertEdgeRelaxed(NewEntry, BB0);
186 DTU.applyUpdates({{DominatorTree::Insert, NewEntry, BB0}},
187 /*ForceRemoveDuplicates*/ true);
185188
186189 // Changing the Entry BB requires a full recalculation of DomTree.
187190 DTU.recalculate(*F);
250253 BasicBlock *BB3 = &*FI++;
251254
252255 // Test discards of self-domination update.
253 DTU.deleteEdge(BB0, BB0);
256 DTU.applyUpdates({{DominatorTree::Delete, BB0, BB0}});
254257 ASSERT_FALSE(DTU.hasPendingDomTreeUpdates());
255258
256259 // Delete edge bb0 -> bb3 and push the update twice to verify duplicate
357360 // +-> succ
358361 //
359362 // While the final CFG form is functionally identical the updates to
360 // DTU are not. In the first case we must have DTU.insertEdge(Pred1, Succ)
361 // while in the latter case we must *NOT* have DTU.insertEdge(Pred1, Succ).
363 // DTU are not. In the first case we must have
364 // DTU.applyUpdates({{DominatorTree::Insert, Pred1, Succ}}) while in the
365 // latter case we must *NOT* have DTU.applyUpdates({{DominatorTree::Insert,
366 // Pred1, Succ}}).
362367
363368 // CFG Change: bb0 now only has bb0 -> bb1 and bb0 -> bb3. We are preparing to
364369 // remove bb2.
411416 ASSERT_TRUE(isa(BB1->getTerminator()));
412417 EXPECT_EQ(BB1->getParent(), F);
413418
414 // Update the DTU. In this case we don't call DTU.insertEdge(BB0, BB3) because
415 // the edge previously existed at the start of this test when DT was first
416 // created.
419 // Update the DTU. In this case we don't submit {DominatorTree::Insert, BB0,
420 // BB3} because the edge previously existed at the start of this test when DT
421 // was first created.
417422 Updates.push_back({DominatorTree::Delete, BB0, BB1});
418423 Updates.push_back({DominatorTree::Delete, BB1, BB3});
419424
466471 BasicBlock *BB2 = &*FI++;
467472 BasicBlock *BB3 = &*FI++;
468473 // Test discards of self-domination update.
469 DTU.deleteEdge(BB0, BB0);
474 DTU.applyUpdates({{DominatorTree::Delete, BB0, BB0}});
470475
471476 // Delete edge bb0 -> bb3 and push the update twice to verify duplicate
472477 // entries are discarded.
557562 // Insert the new edge between new_entry -> bb0. Without this the
558563 // recalculate() call below will not actually recalculate the DT as there
559564 // are no changes pending and no blocks deleted.
560 DTU.insertEdge(NewEntry, BB0);
565 DTU.applyUpdates({{DominatorTree::Insert, NewEntry, BB0}});
561566
562567 // Changing the Entry BB requires a full recalculation.
563568 DTU.recalculate(*F);