[Mlir-commits] [llvm] [mlir] [LoopInfo] Store blocks using Euler tour representation (PR #211485)

Fangrui Song llvmlistbot at llvm.org
Fri Jul 24 01:50:02 PDT 2026


================
@@ -600,14 +546,63 @@ void LoopInfoBase<BlockT, LoopT>::analyze(const DomTreeBase<BlockT> &DomTree) {
     }
     // Perform a backward CFG traversal to discover and map blocks in this loop.
     if (!Backedges.empty()) {
-      LoopT *L = AllocateLoop(Header);
-      discoverAndMapSubloop(L, ArrayRef<BlockT *>(Backedges), this, DomTree);
+      HasLoops = true;
+      LoopT *L = allocateLoop(Header);
+      discoverAndMapSubloop(L, Header, Backedges, DomTree);
+    }
+  }
+  // Most functions have no loops; skip the layout construction.
+  if (!HasLoops)
+    return;
+
+  // Record each in-loop block with its innermost loop in forward CFG postorder,
+  // and build the loop list in PO.
+  SmallVector<std::pair<BlockT *, LoopT *>, 32> PO;
+  SmallVector<LoopT *, 4> LoopsPO;
+  PO.reserve(BBMap.size());
+  for (BlockT *BB : post_order(DomRoot->getBlock())) {
----------------
MaskRay wrote:

`post_order(ParentPtr)` does not compile:
```
error: cannot initialize a variable of type 'llvm::BasicBlock *' with an
       rvalue of type 'reference' (aka 'const BasicBlock *')
```

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


More information about the Mlir-commits mailing list