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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 19 20:58:41 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:

Instead of pushing a null block/virtual root onto the worklist, could you just check if the root is virtual at the start here and push its children on? e.g.


```suggestion
  if (DT.isVirtualRoot(RootNode)) {
    for (DomTreeNodeT *IDominee : *RootNode)
      workList.push_back(DFCalculateWorkObject<BlockT>(
          IDominee->getBlock(), nullptr, IDominee, nullptr));
  } else
    workList.push_back(
        DFCalculateWorkObject<BlockT>(BB, nullptr, RootNode, nullptr));
```

That way you wouldn't need to check `if (currentBB)` on line 104 or `!parentBB` on line 138

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


More information about the llvm-commits mailing list