[llvm] [llvm] Add NCD search on Array of basic blocks (PR #119355)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 10 05:25:32 PST 2024


================
@@ -189,3 +189,19 @@ void MachineDominatorTree::applySplitCriticalEdges() const {
   NewBBs.clear();
   CriticalEdgesToSplit.clear();
 }
+
+MachineBasicBlock *MachineDominatorTree::findNearestCommonDominator(
+    ArrayRef<MachineBasicBlock *> Blocks) const {
+  assert(!Blocks.empty());
+
+  MachineBasicBlock *NCD = Blocks.front();
+  for (MachineBasicBlock *BB : Blocks.drop_front()) {
+    NCD = Base::findNearestCommonDominator(NCD, BB);
+
+    // Stop when the root is reached.
+    if (Base::isVirtualRoot(Base::getNode(NCD)))
+      return nullptr;
+  }
----------------
paperchalice wrote:

`Base::getNode` here is unfortunate, use wrapped version here to get the latest dominator tree.
Addressed by #115111.

https://github.com/llvm/llvm-project/pull/119355


More information about the llvm-commits mailing list