[llvm] [CycleInfo] Support forward declarations (PR #187029)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 17 07:21:14 PDT 2026


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/187029

Use a class instead of an alias, so that CycleInfo can be forward-declared.

We can't do the same for Cycle without further changes (a LoopInfo like CRTP scheme).

>From 37090a4ada0aacb271d2a71438bb487670c25248 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Tue, 17 Mar 2026 15:18:27 +0100
Subject: [PATCH] [CycleInfo] Support forward declarations

Use a class instead of an alias, so that CycleInfo can be
forward-declared.

We can't do the same for Cycle without further changes (a LoopInfo
like CRTP scheme).
---
 llvm/include/llvm/IR/CycleInfo.h                      | 4 +++-
 llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h  | 2 +-
 llvm/include/llvm/Transforms/Utils/ControlFlowUtils.h | 1 -
 llvm/lib/Transforms/Utils/BasicBlockUtils.cpp         | 1 +
 4 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/IR/CycleInfo.h b/llvm/include/llvm/IR/CycleInfo.h
index 79867fe3a043d..bf719fdfe9693 100644
--- a/llvm/include/llvm/IR/CycleInfo.h
+++ b/llvm/include/llvm/IR/CycleInfo.h
@@ -20,7 +20,9 @@
 
 namespace llvm {
 
-using CycleInfo = GenericCycleInfo<SSAContext>;
+// Use class instead of using to allow forward declarations.
+class CycleInfo : public GenericCycleInfo<SSAContext> {};
+
 using Cycle = CycleInfo::CycleT;
 
 } // namespace llvm
diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
index 460dcdd8a2c00..06307961cb95d 100644
--- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -19,7 +19,6 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/IR/BasicBlock.h"
-#include "llvm/IR/CycleInfo.h"
 #include "llvm/IR/Dominators.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Printable.h"
@@ -27,6 +26,7 @@
 
 namespace llvm {
 class CondBrInst;
+class CycleInfo;
 class LandingPadInst;
 class Loop;
 class PHINode;
diff --git a/llvm/include/llvm/Transforms/Utils/ControlFlowUtils.h b/llvm/include/llvm/Transforms/Utils/ControlFlowUtils.h
index 17cde82b084d8..d8c97b3b41ae9 100644
--- a/llvm/include/llvm/Transforms/Utils/ControlFlowUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/ControlFlowUtils.h
@@ -15,7 +15,6 @@
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/IR/CycleInfo.h"
 
 namespace llvm {
 
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 17aa7cc185b66..cdb3896e81778 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -24,6 +24,7 @@
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/IR/CycleInfo.h"
 #include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/Dominators.h"



More information about the llvm-commits mailing list