[llvm] [CycleInfo] Represent cycles by an opaque handle. NFC (PR #210117)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 10:52:11 PDT 2026


================
@@ -149,6 +162,28 @@ template <typename ContextT> class GenericCycleInfo {
   /// The preorder index of \p C, i.e. its offset in the Cycles array.
   unsigned getCycleIndex(const CycleT &C) const { return &C - Cycles.get(); }
 
+  /// Resolve a handle to its stored cycle. The assert catches deref of an
+  /// invalid handle and (partially) of a handle from another CycleInfo.
+  CycleT &deref(Cycle C) {
+    assert(C.Index < NumCycles);
+    return Cycles[C.Index];
+  }
+  const CycleT &deref(Cycle C) const {
+    assert(C.Index < NumCycles);
+    return Cycles[C.Index];
+  }
+  /// The handle for a stored cycle.
+  Cycle ref(const CycleT &C) const { return Cycle(getCycleIndex(C)); }
+
+  /// The innermost cycle containing \p Block as a raw pointer, or null. Used
+  /// internally and during construction, where handles are not yet meaningful
+  /// because the flat array does not exist.
+  CycleT *getCyclePtr(const BlockT *Block) const {
----------------
MaskRay wrote:

Yes, when we eventually change ` SmallVector<CycleT *> BlockMap;` to an index vector.

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


More information about the llvm-commits mailing list