Skip to content

Commit 3088c31

Browse files
authored
[llvm] Add NCD search on Array of basic blocks (NFC) (#119355)
Shrink-Wrap points split Part 2. RFC: https://discourse.llvm.org/t/shrink-wrap-save-restore-points-splitting/83581 Part 1: #117862 Part 3: #119357 Part 4: #119358 Part 5: #119359
1 parent 957213f commit 3088c31

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

llvm/include/llvm/Support/GenericDomTree.h

+16
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,22 @@ class DominatorTreeBase {
558558
return isPostDominator() && !A->getBlock();
559559
}
560560

561+
template <typename IteratorTy>
562+
NodeT *findNearestCommonDominator(iterator_range<IteratorTy> Nodes) const {
563+
assert(!Nodes.empty() && "Nodes list is empty!");
564+
565+
NodeT *NCD = *Nodes.begin();
566+
for (NodeT *Node : llvm::drop_begin(Nodes)) {
567+
NCD = findNearestCommonDominator(NCD, Node);
568+
569+
// Stop when the root is reached.
570+
if (isVirtualRoot(getNode(NCD)))
571+
return nullptr;
572+
}
573+
574+
return NCD;
575+
}
576+
561577
//===--------------------------------------------------------------------===//
562578
// API to update (Post)DominatorTree information based on modifications to
563579
// the CFG...

llvm/lib/CodeGen/ShrinkWrap.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,7 @@ bool ShrinkWrap::useOrDefCSROrFI(const MachineInstr &MI, RegScavenger *RS,
375375
template <typename ListOfBBs, typename DominanceAnalysis>
376376
static MachineBasicBlock *FindIDom(MachineBasicBlock &Block, ListOfBBs BBs,
377377
DominanceAnalysis &Dom, bool Strict = true) {
378-
MachineBasicBlock *IDom = &Block;
379-
for (MachineBasicBlock *BB : BBs) {
380-
IDom = Dom.findNearestCommonDominator(IDom, BB);
381-
if (!IDom)
382-
break;
383-
}
378+
MachineBasicBlock *IDom = Dom.findNearestCommonDominator(iterator_range(BBs));
384379
if (Strict && IDom == &Block)
385380
return nullptr;
386381
return IDom;

0 commit comments

Comments
 (0)