[llvm] [GenericDomTreeConstruction] Switch to 0-based DFS numbering (PR #207524)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 4 10:50:10 PDT 2026


================
@@ -59,19 +59,22 @@ template <typename DomTreeT> struct SemiNCAInfo {
   static constexpr bool IsPostDom = DomTreeT::IsPostDominator;
   using GraphDiffT = GraphDiff<NodePtr, IsPostDom>;
 
+  // Marks a node that hasn't been visited by DFS.
+  static constexpr unsigned Unvisited = -1u;
+
   // Information record used by Semi-NCA during tree construction.
   struct InfoRec {
-    unsigned DFSNum = 0;
+    unsigned DFSNum = Unvisited;
     unsigned Parent = 0;
     unsigned Semi = 0;
     unsigned Label = 0;
     NodePtr IDom = nullptr;
     SmallVector<unsigned, 4> ReverseChildren;
   };
----------------
aengelke wrote:

Hm, I'm unsure. This makes initialization of NodeInfos worse. I would prefer the DFSNum field to be zero-initialized and be stored as number+1. (I also think it'd be better do eventually do something about ReverseChildren so that InfoRec becomes trivial and zero-initialization can be done by memset; this moves in the opposite direction.)

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


More information about the llvm-commits mailing list