[llvm] [CycleInfo] Store blocks using Euler tour representation (PR #208614)
Alexis Engelke via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 02:24:56 PDT 2026
================
@@ -333,20 +343,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.
+ unsigned Pos = Cycle->IdxEnd;
+ BlockLayout.insert(BlockLayout.begin() + Pos, Block);
+ for (CycleT *TLC : toplevel_cycles())
+ for (auto It = df_begin(TLC), E = df_end(TLC); It != E;) {
----------------
aengelke wrote:
NB: df_iterator is rather expensive. But addBlockToCycle is used rarely, so this is ok.
https://github.com/llvm/llvm-project/pull/208614
More information about the llvm-commits
mailing list