[llvm] [CycleInfo] Store blocks using Euler tour representation (PR #208614)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 12 23:35:03 PDT 2026


================
@@ -333,20 +344,73 @@ void GenericCycleInfo<ContextT>::addBlockToCycle(BlockT *Block, CycleT *Cycle) {
   if (Number >= BlockMap.size())
     BlockMap.resize(GraphTraits<FunctionT *>::getMaxNumber(Block->getParent()));
 
-  // FixMe: Appending NewBlock is fine as a set of blocks in a cycle. When
-  // printing, cycle NewBlock is at the end of list but it should be in the
-  // middle to represent actual traversal of a cycle.
-  Cycle->appendBlock(Block);
+  // Insert Block at Pos (end of Cycle's slice) and shift every later cycle's
+  // range right, keyed on IdxBegin so a nested cycle sharing end == Pos is
+  // left alone; Cycle and its ancestors then grow to contain it, below.
+  // FixMe: appended at the slice end, not the traversal-order middle.
----------------
MaskRay wrote:

Yes, that's right.  addBlockToCycle inserts the block at the end of the cycle's slice to satisfy the Euler tour requirement. But "end of slice" isn't the block's true position in the cycle's traversal order.

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


More information about the llvm-commits mailing list