[llvm] [DominanceFrontier] Support multiple root nodes for post-dom (PR #181257)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 20 08:56:15 PST 2026


================
@@ -74,14 +74,16 @@ void DominanceFrontierBase<BlockT, IsPostDom>::dump() const {
 #endif
 
 template <class BlockT, bool IsPostDom>
-void DominanceFrontierBase<BlockT, IsPostDom>::calculate(
-    const DomTreeT &DT, const DomTreeNodeT *Node) {
-  BlockT *BB = Node->getBlock();
+void DominanceFrontierBase<BlockT, IsPostDom>::calculate(const DomTreeT &DT) {
+  // NOTE: RootNode might be virtual for `IsPostDom == true`.
+  const DomTreeNodeT *RootNode = DT.getRootNode();
+  BlockT *BB = RootNode->getBlock();
 
   std::vector<DFCalculateWorkObject<BlockT>> workList;
   SmallPtrSet<BlockT *, 32> visited;
 
-  workList.push_back(DFCalculateWorkObject<BlockT>(BB, nullptr, Node, nullptr));
+  workList.push_back(
+      DFCalculateWorkObject<BlockT>(BB, nullptr, RootNode, nullptr));
----------------
lukel97 wrote:

Ah right, I guess we still need the `if (!parentBB) continue;` bit then. In any case I still prefer keeping virtual nodes off the worklist, since I find it easier to reason about. It also lets us keep the `assert(currentBB && "Invalid work object. Missing current Basic Block");` invariant. WDYT?

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


More information about the llvm-commits mailing list