[llvm] [CycleInfo] Reference cycles by preorder index, not pointer. NFC (PR #210271)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 17 09:52:19 PDT 2026
================
@@ -80,12 +80,17 @@ template <typename ContextT> class GenericCycleInfo {
template <typename> friend class GenericCycleInfoCompute;
private:
+ /// Sentinel for a cycle-index slot that refers to no cycle.
+ static constexpr unsigned NoCycle = ~0u;
+
/// Internal, data-only storage for a cycle. Consumers name a cycle by a
/// CycleRef handle and query it through GenericCycleInfo.
class Cycle {
public:
- /// The parent cycle. Is null for top-level cycles.
- Cycle *ParentCycle = nullptr;
+ /// Preorder index of the parent cycle, or NoCycle for a top-level
+ /// cycle. Before flatten() this holds a creation-order index into
+ /// GenericCycleInfoCompute::AllCycles.
+ unsigned ParentIndex = NoCycle;
----------------
MaskRay wrote:
`ParentIndex` (like `BlockMap`) is dual-phase: during construction it holds a creation-order index into the temporary `GenericCycleInfoCompute::AllCycles` forest, and only `flatten()` rewrites it to a preorder index. `CycleRef` is contractually a handle wrapping a *preorder* index into `Cycles`, which does not exist yet at that point — so typing the field `CycleRef` would misrepresent its value throughout construction, and `GenericCycleInfoCompute` would need `CycleRef`'s private ctor/`Index` to store and walk those `AllCycles` indices.
It also would not reduce to one sentinel: `BlockMap` is a `SmallVector<unsigned>` that uses `NoCycle` independently (and transiently holds creation-order indices too), so `NoCycle` stays either way. I'll keep `ParentIndex` as `unsigned`.
https://github.com/llvm/llvm-project/pull/210271
More information about the llvm-commits
mailing list