Skip to content

[Remarks] Remove an upcast footgun. NFC #142191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 31, 2025
Merged

Conversation

jroelofs
Copy link
Contributor

CodeRegion's were previously passed as Value*, but then immediately upcast to BasicBlock. Let's keep the type information around until the use cases for non-BasicBlock code regions actually materialize.

CodeRegion's were previously passed as Value*, but then immediately upcast to
BasicBlock. Let's keep the type information around until the use cases for
non-BasicBlock code regions actually materialize.
@llvmbot
Copy link
Member

llvmbot commented May 30, 2025

@llvm/pr-subscribers-vectorizers
@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-ir

Author: Jon Roelofs (jroelofs)

Changes

CodeRegion's were previously passed as Value*, but then immediately upcast to BasicBlock. Let's keep the type information around until the use cases for non-BasicBlock code regions actually materialize.


Full diff: https://github.com/llvm/llvm-project/pull/142191.diff

5 Files Affected:

  • (modified) llvm/include/llvm/IR/DiagnosticInfo.h (+33-37)
  • (modified) llvm/lib/Analysis/LoopAccessAnalysis.cpp (+3-3)
  • (modified) llvm/lib/CodeGen/HardwareLoops.cpp (+1-1)
  • (modified) llvm/lib/IR/DiagnosticInfo.cpp (+18-19)
  • (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+1-1)
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h
index a1113134f6a34..79595ebee97d4 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -523,7 +523,7 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
 
   /// \p PassName is the name of the pass emitting this diagnostic. \p
   /// RemarkName is a textual identifier for the remark (single-word,
-  /// camel-case). \p Fn is the function where the diagnostic is being emitted.
+  /// CamelCase). \p Fn is the function where the diagnostic is being emitted.
   /// \p Loc is the location information to use in the diagnostic. If line table
   /// information is available, the diagnostic will include the source code
   /// location.
@@ -588,7 +588,7 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
   /// be emitted.
   const char *PassName;
 
-  /// Textual identifier for the remark (single-word, camel-case). Can be used
+  /// Textual identifier for the remark (single-word, CamelCase). Can be used
   /// by external tools reading the output file for optimization remarks to
   /// identify the remark.
   StringRef RemarkName;
@@ -663,18 +663,17 @@ class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
 public:
   /// \p PassName is the name of the pass emitting this diagnostic. \p
   /// RemarkName is a textual identifier for the remark (single-word,
-  /// camel-case). \p Fn is the function where the diagnostic is being emitted.
+  /// CamelCase). \p Fn is the function where the diagnostic is being emitted.
   /// \p Loc is the location information to use in the diagnostic. If line table
   /// information is available, the diagnostic will include the source code
-  /// location. \p CodeRegion is IR value (currently basic block) that the
-  /// optimization operates on. This is currently used to provide run-time
-  /// hotness information with PGO.
+  /// location. \p CodeRegion is IR value that the optimization operates on.
+  /// This is currently used to provide run-time hotness information with PGO.
   DiagnosticInfoIROptimization(enum DiagnosticKind Kind,
                                enum DiagnosticSeverity Severity,
                                const char *PassName, StringRef RemarkName,
                                const Function &Fn,
                                const DiagnosticLocation &Loc,
-                               const Value *CodeRegion = nullptr)
+                               const BasicBlock *CodeRegion = nullptr)
       : DiagnosticInfoOptimizationBase(Kind, Severity, PassName, RemarkName, Fn,
                                        Loc),
         CodeRegion(CodeRegion) {}
@@ -712,16 +711,16 @@ class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
     *this << Msg.str();
   }
 
-  const Value *getCodeRegion() const { return CodeRegion; }
+  const BasicBlock *getCodeRegion() const { return CodeRegion; }
 
   static bool classof(const DiagnosticInfo *DI) {
     return DI->getKind() >= DK_FirstRemark && DI->getKind() <= DK_LastRemark;
   }
 
 private:
-  /// The IR value (currently basic block) that the optimization operates on.
+  /// The IR value that the optimization operates on.
   /// This is currently used to provide run-time hotness information with PGO.
-  const Value *CodeRegion = nullptr;
+  const BasicBlock *CodeRegion = nullptr;
 };
 
 /// Diagnostic information for applied optimization remarks.
@@ -730,11 +729,11 @@ class OptimizationRemark : public DiagnosticInfoIROptimization {
   /// \p PassName is the name of the pass emitting this diagnostic. If this name
   /// matches the regular expression given in -Rpass=, then the diagnostic will
   /// be emitted. \p RemarkName is a textual identifier for the remark (single-
-  /// word, camel-case). \p Loc is the debug location and \p CodeRegion is the
-  /// region that the optimization operates on (currently only block is
-  /// supported).
+  /// word, CamelCase). \p Loc is the debug location and \p CodeRegion is the
+  /// region that the optimization operates on.
   OptimizationRemark(const char *PassName, StringRef RemarkName,
-                     const DiagnosticLocation &Loc, const Value *CodeRegion);
+                     const DiagnosticLocation &Loc,
+                     const BasicBlock *CodeRegion);
 
   /// Same as above, but the debug location and code region are derived from \p
   /// Instr.
@@ -775,12 +774,11 @@ class OptimizationRemarkMissed : public DiagnosticInfoIROptimization {
   /// \p PassName is the name of the pass emitting this diagnostic. If this name
   /// matches the regular expression given in -Rpass-missed=, then the
   /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
-  /// remark (single-word, camel-case). \p Loc is the debug location and \p
-  /// CodeRegion is the region that the optimization operates on (currently only
-  /// block is supported).
+  /// remark (single-word, CamelCase). \p Loc is the debug location and \p
+  /// CodeRegion is the region that the optimization operates on.
   OptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
                            const DiagnosticLocation &Loc,
-                           const Value *CodeRegion);
+                           const BasicBlock *CodeRegion);
 
   /// Same as above but \p Inst is used to derive code region and debug
   /// location.
@@ -821,12 +819,11 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
   /// \p PassName is the name of the pass emitting this diagnostic. If this name
   /// matches the regular expression given in -Rpass-analysis=, then the
   /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
-  /// remark (single-word, camel-case). \p Loc is the debug location and \p
-  /// CodeRegion is the region that the optimization operates on (currently only
-  /// block is supported).
+  /// remark (single-word, CamelCase). \p Loc is the debug location and \p
+  /// CodeRegion is the region that the optimization operates on.
   OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
                              const DiagnosticLocation &Loc,
-                             const Value *CodeRegion);
+                             const BasicBlock *CodeRegion);
 
   /// This is ctor variant allows a pass to build an optimization remark
   /// from an existing remark.
@@ -869,7 +866,7 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
   OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
                              StringRef RemarkName,
                              const DiagnosticLocation &Loc,
-                             const Value *CodeRegion);
+                             const BasicBlock *CodeRegion);
 
 private:
   /// This is deprecated now and only used by the function API below.
@@ -895,14 +892,14 @@ class OptimizationRemarkAnalysisFPCommute : public OptimizationRemarkAnalysis {
   /// \p PassName is the name of the pass emitting this diagnostic. If this name
   /// matches the regular expression given in -Rpass-analysis=, then the
   /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
-  /// remark (single-word, camel-case). \p Loc is the debug location and \p
-  /// CodeRegion is the region that the optimization operates on (currently only
-  /// block is supported). The front-end will append its own message related to
-  /// options that address floating-point non-commutativity.
+  /// remark (single-word, CamelCase). \p Loc is the debug location and \p
+  /// CodeRegion is the region that the optimization operates on. The front-end
+  /// will append its own message related to options that address floating-point
+  /// non-commutativity.
   OptimizationRemarkAnalysisFPCommute(const char *PassName,
                                       StringRef RemarkName,
                                       const DiagnosticLocation &Loc,
-                                      const Value *CodeRegion)
+                                      const BasicBlock *CodeRegion)
       : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute,
                                    PassName, RemarkName, Loc, CodeRegion) {}
 
@@ -937,13 +934,13 @@ class OptimizationRemarkAnalysisAliasing : public OptimizationRemarkAnalysis {
   /// \p PassName is the name of the pass emitting this diagnostic. If this name
   /// matches the regular expression given in -Rpass-analysis=, then the
   /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
-  /// remark (single-word, camel-case). \p Loc is the debug location and \p
-  /// CodeRegion is the region that the optimization operates on (currently only
-  /// block is supported). The front-end will append its own message related to
-  /// options that address pointer aliasing legality.
+  /// remark (single-word, CamelCase). \p Loc is the debug location and \p
+  /// CodeRegion is the region that the optimization operates on. The front-end
+  /// will append its own message related to options that address pointer
+  /// aliasing legality.
   OptimizationRemarkAnalysisAliasing(const char *PassName, StringRef RemarkName,
                                      const DiagnosticLocation &Loc,
-                                     const Value *CodeRegion)
+                                     const BasicBlock *CodeRegion)
       : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing,
                                    PassName, RemarkName, Loc, CodeRegion) {}
 
@@ -1044,12 +1041,11 @@ class DiagnosticInfoOptimizationFailure : public DiagnosticInfoIROptimization {
 
   /// \p PassName is the name of the pass emitting this diagnostic.  \p
   /// RemarkName is a textual identifier for the remark (single-word,
-  /// camel-case).  \p Loc is the debug location and \p CodeRegion is the
-  /// region that the optimization operates on (currently basic block is
-  /// supported).
+  /// CamelCase).  \p Loc is the debug location and \p CodeRegion is the
+  /// region that the optimization operates on.
   DiagnosticInfoOptimizationFailure(const char *PassName, StringRef RemarkName,
                                     const DiagnosticLocation &Loc,
-                                    const Value *CodeRegion);
+                                    const BasicBlock *CodeRegion);
 
   static bool classof(const DiagnosticInfo *DI) {
     return DI->getKind() == DK_OptimizationFailure;
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index f377da3926b26..26e11b6bc00af 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2746,7 +2746,7 @@ OptimizationRemarkAnalysis &
 LoopAccessInfo::recordAnalysis(StringRef RemarkName, const Instruction *I) {
   assert(!Report && "Multiple reports generated");
 
-  const Value *CodeRegion = TheLoop->getHeader();
+  const BasicBlock *CodeRegion = TheLoop->getHeader();
   DebugLoc DL = TheLoop->getStartLoc();
 
   if (I) {
@@ -2757,8 +2757,8 @@ LoopAccessInfo::recordAnalysis(StringRef RemarkName, const Instruction *I) {
       DL = I->getDebugLoc();
   }
 
-  Report = std::make_unique<OptimizationRemarkAnalysis>(DEBUG_TYPE, RemarkName, DL,
-                                                   CodeRegion);
+  Report = std::make_unique<OptimizationRemarkAnalysis>(DEBUG_TYPE, RemarkName,
+                                                        DL, CodeRegion);
   return *Report;
 }
 
diff --git a/llvm/lib/CodeGen/HardwareLoops.cpp b/llvm/lib/CodeGen/HardwareLoops.cpp
index 1e3c9659e689c..628d8cc8621f2 100644
--- a/llvm/lib/CodeGen/HardwareLoops.cpp
+++ b/llvm/lib/CodeGen/HardwareLoops.cpp
@@ -90,7 +90,7 @@ static void debugHWLoopFailure(const StringRef DebugMsg,
 
 static OptimizationRemarkAnalysis
 createHWLoopAnalysis(StringRef RemarkName, Loop *L, Instruction *I) {
-  Value *CodeRegion = L->getHeader();
+  BasicBlock *CodeRegion = L->getHeader();
   DebugLoc DL = L->getStartLoc();
 
   if (I) {
diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp
index 4315f63cce4f8..0f1291b8bd8be 100644
--- a/llvm/lib/IR/DiagnosticInfo.cpp
+++ b/llvm/lib/IR/DiagnosticInfo.cpp
@@ -284,10 +284,10 @@ void DiagnosticInfoOptimizationBase::print(DiagnosticPrinter &DP) const {
 OptimizationRemark::OptimizationRemark(const char *PassName,
                                        StringRef RemarkName,
                                        const DiagnosticLocation &Loc,
-                                       const Value *CodeRegion)
-    : DiagnosticInfoIROptimization(
-          DK_OptimizationRemark, DS_Remark, PassName, RemarkName,
-          *cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
+                                       const BasicBlock *CodeRegion)
+    : DiagnosticInfoIROptimization(DK_OptimizationRemark, DS_Remark, PassName,
+                                   RemarkName, *CodeRegion->getParent(), Loc,
+                                   CodeRegion) {}
 
 OptimizationRemark::OptimizationRemark(const char *PassName,
                                        StringRef RemarkName,
@@ -315,10 +315,10 @@ bool OptimizationRemark::isEnabled() const {
 
 OptimizationRemarkMissed::OptimizationRemarkMissed(
     const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc,
-    const Value *CodeRegion)
-    : DiagnosticInfoIROptimization(
-          DK_OptimizationRemarkMissed, DS_Remark, PassName, RemarkName,
-          *cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
+    const BasicBlock *CodeRegion)
+    : DiagnosticInfoIROptimization(DK_OptimizationRemarkMissed, DS_Remark,
+                                   PassName, RemarkName,
+                                   *CodeRegion->getParent(), Loc, CodeRegion) {}
 
 OptimizationRemarkMissed::OptimizationRemarkMissed(const char *PassName,
                                                    StringRef RemarkName,
@@ -343,10 +343,10 @@ bool OptimizationRemarkMissed::isEnabled() const {
 
 OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(
     const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc,
-    const Value *CodeRegion)
-    : DiagnosticInfoIROptimization(
-          DK_OptimizationRemarkAnalysis, DS_Remark, PassName, RemarkName,
-          *cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
+    const BasicBlock *CodeRegion)
+    : DiagnosticInfoIROptimization(DK_OptimizationRemarkAnalysis, DS_Remark,
+                                   PassName, RemarkName,
+                                   *CodeRegion->getParent(), Loc, CodeRegion) {}
 
 OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName,
                                                        StringRef RemarkName,
@@ -358,10 +358,9 @@ OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName,
 
 OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(
     enum DiagnosticKind Kind, const char *PassName, StringRef RemarkName,
-    const DiagnosticLocation &Loc, const Value *CodeRegion)
+    const DiagnosticLocation &Loc, const BasicBlock *CodeRegion)
     : DiagnosticInfoIROptimization(Kind, DS_Remark, PassName, RemarkName,
-                                   *cast<BasicBlock>(CodeRegion)->getParent(),
-                                   Loc, CodeRegion) {}
+                                   *CodeRegion->getParent(), Loc, CodeRegion) {}
 
 OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName,
                                                        StringRef RemarkName,
@@ -387,10 +386,10 @@ void DiagnosticInfoSrcMgr::print(DiagnosticPrinter &DP) const {
 
 DiagnosticInfoOptimizationFailure::DiagnosticInfoOptimizationFailure(
     const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc,
-    const Value *CodeRegion)
-    : DiagnosticInfoIROptimization(
-          DK_OptimizationFailure, DS_Warning, PassName, RemarkName,
-          *cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
+    const BasicBlock *CodeRegion)
+    : DiagnosticInfoIROptimization(DK_OptimizationFailure, DS_Warning, PassName,
+                                   RemarkName, *CodeRegion->getParent(), Loc,
+                                   CodeRegion) {}
 
 bool DiagnosticInfoOptimizationFailure::isEnabled() const {
   // Only print warnings.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 2fe59a464457f..90c8da2952501 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -815,7 +815,7 @@ static void debugVectorizationMessage(const StringRef Prefix,
 static OptimizationRemarkAnalysis
 createLVAnalysis(const char *PassName, StringRef RemarkName, Loop *TheLoop,
                  Instruction *I, DebugLoc DL = {}) {
-  Value *CodeRegion = I ? I->getParent() : TheLoop->getHeader();
+  BasicBlock *CodeRegion = I ? I->getParent() : TheLoop->getHeader();
   // If debug location is attached to the instruction, use it. Otherwise if DL
   // was not provided, use the loop's.
   if (I && I->getDebugLoc())

@llvmbot
Copy link
Member

llvmbot commented May 30, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Jon Roelofs (jroelofs)

Changes

CodeRegion's were previously passed as Value*, but then immediately upcast to BasicBlock. Let's keep the type information around until the use cases for non-BasicBlock code regions actually materialize.


Full diff: https://github.com/llvm/llvm-project/pull/142191.diff

5 Files Affected:

  • (modified) llvm/include/llvm/IR/DiagnosticInfo.h (+33-37)
  • (modified) llvm/lib/Analysis/LoopAccessAnalysis.cpp (+3-3)
  • (modified) llvm/lib/CodeGen/HardwareLoops.cpp (+1-1)
  • (modified) llvm/lib/IR/DiagnosticInfo.cpp (+18-19)
  • (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+1-1)
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h
index a1113134f6a34..79595ebee97d4 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -523,7 +523,7 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
 
   /// \p PassName is the name of the pass emitting this diagnostic. \p
   /// RemarkName is a textual identifier for the remark (single-word,
-  /// camel-case). \p Fn is the function where the diagnostic is being emitted.
+  /// CamelCase). \p Fn is the function where the diagnostic is being emitted.
   /// \p Loc is the location information to use in the diagnostic. If line table
   /// information is available, the diagnostic will include the source code
   /// location.
@@ -588,7 +588,7 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
   /// be emitted.
   const char *PassName;
 
-  /// Textual identifier for the remark (single-word, camel-case). Can be used
+  /// Textual identifier for the remark (single-word, CamelCase). Can be used
   /// by external tools reading the output file for optimization remarks to
   /// identify the remark.
   StringRef RemarkName;
@@ -663,18 +663,17 @@ class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
 public:
   /// \p PassName is the name of the pass emitting this diagnostic. \p
   /// RemarkName is a textual identifier for the remark (single-word,
-  /// camel-case). \p Fn is the function where the diagnostic is being emitted.
+  /// CamelCase). \p Fn is the function where the diagnostic is being emitted.
   /// \p Loc is the location information to use in the diagnostic. If line table
   /// information is available, the diagnostic will include the source code
-  /// location. \p CodeRegion is IR value (currently basic block) that the
-  /// optimization operates on. This is currently used to provide run-time
-  /// hotness information with PGO.
+  /// location. \p CodeRegion is IR value that the optimization operates on.
+  /// This is currently used to provide run-time hotness information with PGO.
   DiagnosticInfoIROptimization(enum DiagnosticKind Kind,
                                enum DiagnosticSeverity Severity,
                                const char *PassName, StringRef RemarkName,
                                const Function &Fn,
                                const DiagnosticLocation &Loc,
-                               const Value *CodeRegion = nullptr)
+                               const BasicBlock *CodeRegion = nullptr)
       : DiagnosticInfoOptimizationBase(Kind, Severity, PassName, RemarkName, Fn,
                                        Loc),
         CodeRegion(CodeRegion) {}
@@ -712,16 +711,16 @@ class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
     *this << Msg.str();
   }
 
-  const Value *getCodeRegion() const { return CodeRegion; }
+  const BasicBlock *getCodeRegion() const { return CodeRegion; }
 
   static bool classof(const DiagnosticInfo *DI) {
     return DI->getKind() >= DK_FirstRemark && DI->getKind() <= DK_LastRemark;
   }
 
 private:
-  /// The IR value (currently basic block) that the optimization operates on.
+  /// The IR value that the optimization operates on.
   /// This is currently used to provide run-time hotness information with PGO.
-  const Value *CodeRegion = nullptr;
+  const BasicBlock *CodeRegion = nullptr;
 };
 
 /// Diagnostic information for applied optimization remarks.
@@ -730,11 +729,11 @@ class OptimizationRemark : public DiagnosticInfoIROptimization {
   /// \p PassName is the name of the pass emitting this diagnostic. If this name
   /// matches the regular expression given in -Rpass=, then the diagnostic will
   /// be emitted. \p RemarkName is a textual identifier for the remark (single-
-  /// word, camel-case). \p Loc is the debug location and \p CodeRegion is the
-  /// region that the optimization operates on (currently only block is
-  /// supported).
+  /// word, CamelCase). \p Loc is the debug location and \p CodeRegion is the
+  /// region that the optimization operates on.
   OptimizationRemark(const char *PassName, StringRef RemarkName,
-                     const DiagnosticLocation &Loc, const Value *CodeRegion);
+                     const DiagnosticLocation &Loc,
+                     const BasicBlock *CodeRegion);
 
   /// Same as above, but the debug location and code region are derived from \p
   /// Instr.
@@ -775,12 +774,11 @@ class OptimizationRemarkMissed : public DiagnosticInfoIROptimization {
   /// \p PassName is the name of the pass emitting this diagnostic. If this name
   /// matches the regular expression given in -Rpass-missed=, then the
   /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
-  /// remark (single-word, camel-case). \p Loc is the debug location and \p
-  /// CodeRegion is the region that the optimization operates on (currently only
-  /// block is supported).
+  /// remark (single-word, CamelCase). \p Loc is the debug location and \p
+  /// CodeRegion is the region that the optimization operates on.
   OptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
                            const DiagnosticLocation &Loc,
-                           const Value *CodeRegion);
+                           const BasicBlock *CodeRegion);
 
   /// Same as above but \p Inst is used to derive code region and debug
   /// location.
@@ -821,12 +819,11 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
   /// \p PassName is the name of the pass emitting this diagnostic. If this name
   /// matches the regular expression given in -Rpass-analysis=, then the
   /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
-  /// remark (single-word, camel-case). \p Loc is the debug location and \p
-  /// CodeRegion is the region that the optimization operates on (currently only
-  /// block is supported).
+  /// remark (single-word, CamelCase). \p Loc is the debug location and \p
+  /// CodeRegion is the region that the optimization operates on.
   OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
                              const DiagnosticLocation &Loc,
-                             const Value *CodeRegion);
+                             const BasicBlock *CodeRegion);
 
   /// This is ctor variant allows a pass to build an optimization remark
   /// from an existing remark.
@@ -869,7 +866,7 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
   OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
                              StringRef RemarkName,
                              const DiagnosticLocation &Loc,
-                             const Value *CodeRegion);
+                             const BasicBlock *CodeRegion);
 
 private:
   /// This is deprecated now and only used by the function API below.
@@ -895,14 +892,14 @@ class OptimizationRemarkAnalysisFPCommute : public OptimizationRemarkAnalysis {
   /// \p PassName is the name of the pass emitting this diagnostic. If this name
   /// matches the regular expression given in -Rpass-analysis=, then the
   /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
-  /// remark (single-word, camel-case). \p Loc is the debug location and \p
-  /// CodeRegion is the region that the optimization operates on (currently only
-  /// block is supported). The front-end will append its own message related to
-  /// options that address floating-point non-commutativity.
+  /// remark (single-word, CamelCase). \p Loc is the debug location and \p
+  /// CodeRegion is the region that the optimization operates on. The front-end
+  /// will append its own message related to options that address floating-point
+  /// non-commutativity.
   OptimizationRemarkAnalysisFPCommute(const char *PassName,
                                       StringRef RemarkName,
                                       const DiagnosticLocation &Loc,
-                                      const Value *CodeRegion)
+                                      const BasicBlock *CodeRegion)
       : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute,
                                    PassName, RemarkName, Loc, CodeRegion) {}
 
@@ -937,13 +934,13 @@ class OptimizationRemarkAnalysisAliasing : public OptimizationRemarkAnalysis {
   /// \p PassName is the name of the pass emitting this diagnostic. If this name
   /// matches the regular expression given in -Rpass-analysis=, then the
   /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
-  /// remark (single-word, camel-case). \p Loc is the debug location and \p
-  /// CodeRegion is the region that the optimization operates on (currently only
-  /// block is supported). The front-end will append its own message related to
-  /// options that address pointer aliasing legality.
+  /// remark (single-word, CamelCase). \p Loc is the debug location and \p
+  /// CodeRegion is the region that the optimization operates on. The front-end
+  /// will append its own message related to options that address pointer
+  /// aliasing legality.
   OptimizationRemarkAnalysisAliasing(const char *PassName, StringRef RemarkName,
                                      const DiagnosticLocation &Loc,
-                                     const Value *CodeRegion)
+                                     const BasicBlock *CodeRegion)
       : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing,
                                    PassName, RemarkName, Loc, CodeRegion) {}
 
@@ -1044,12 +1041,11 @@ class DiagnosticInfoOptimizationFailure : public DiagnosticInfoIROptimization {
 
   /// \p PassName is the name of the pass emitting this diagnostic.  \p
   /// RemarkName is a textual identifier for the remark (single-word,
-  /// camel-case).  \p Loc is the debug location and \p CodeRegion is the
-  /// region that the optimization operates on (currently basic block is
-  /// supported).
+  /// CamelCase).  \p Loc is the debug location and \p CodeRegion is the
+  /// region that the optimization operates on.
   DiagnosticInfoOptimizationFailure(const char *PassName, StringRef RemarkName,
                                     const DiagnosticLocation &Loc,
-                                    const Value *CodeRegion);
+                                    const BasicBlock *CodeRegion);
 
   static bool classof(const DiagnosticInfo *DI) {
     return DI->getKind() == DK_OptimizationFailure;
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index f377da3926b26..26e11b6bc00af 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2746,7 +2746,7 @@ OptimizationRemarkAnalysis &
 LoopAccessInfo::recordAnalysis(StringRef RemarkName, const Instruction *I) {
   assert(!Report && "Multiple reports generated");
 
-  const Value *CodeRegion = TheLoop->getHeader();
+  const BasicBlock *CodeRegion = TheLoop->getHeader();
   DebugLoc DL = TheLoop->getStartLoc();
 
   if (I) {
@@ -2757,8 +2757,8 @@ LoopAccessInfo::recordAnalysis(StringRef RemarkName, const Instruction *I) {
       DL = I->getDebugLoc();
   }
 
-  Report = std::make_unique<OptimizationRemarkAnalysis>(DEBUG_TYPE, RemarkName, DL,
-                                                   CodeRegion);
+  Report = std::make_unique<OptimizationRemarkAnalysis>(DEBUG_TYPE, RemarkName,
+                                                        DL, CodeRegion);
   return *Report;
 }
 
diff --git a/llvm/lib/CodeGen/HardwareLoops.cpp b/llvm/lib/CodeGen/HardwareLoops.cpp
index 1e3c9659e689c..628d8cc8621f2 100644
--- a/llvm/lib/CodeGen/HardwareLoops.cpp
+++ b/llvm/lib/CodeGen/HardwareLoops.cpp
@@ -90,7 +90,7 @@ static void debugHWLoopFailure(const StringRef DebugMsg,
 
 static OptimizationRemarkAnalysis
 createHWLoopAnalysis(StringRef RemarkName, Loop *L, Instruction *I) {
-  Value *CodeRegion = L->getHeader();
+  BasicBlock *CodeRegion = L->getHeader();
   DebugLoc DL = L->getStartLoc();
 
   if (I) {
diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp
index 4315f63cce4f8..0f1291b8bd8be 100644
--- a/llvm/lib/IR/DiagnosticInfo.cpp
+++ b/llvm/lib/IR/DiagnosticInfo.cpp
@@ -284,10 +284,10 @@ void DiagnosticInfoOptimizationBase::print(DiagnosticPrinter &DP) const {
 OptimizationRemark::OptimizationRemark(const char *PassName,
                                        StringRef RemarkName,
                                        const DiagnosticLocation &Loc,
-                                       const Value *CodeRegion)
-    : DiagnosticInfoIROptimization(
-          DK_OptimizationRemark, DS_Remark, PassName, RemarkName,
-          *cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
+                                       const BasicBlock *CodeRegion)
+    : DiagnosticInfoIROptimization(DK_OptimizationRemark, DS_Remark, PassName,
+                                   RemarkName, *CodeRegion->getParent(), Loc,
+                                   CodeRegion) {}
 
 OptimizationRemark::OptimizationRemark(const char *PassName,
                                        StringRef RemarkName,
@@ -315,10 +315,10 @@ bool OptimizationRemark::isEnabled() const {
 
 OptimizationRemarkMissed::OptimizationRemarkMissed(
     const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc,
-    const Value *CodeRegion)
-    : DiagnosticInfoIROptimization(
-          DK_OptimizationRemarkMissed, DS_Remark, PassName, RemarkName,
-          *cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
+    const BasicBlock *CodeRegion)
+    : DiagnosticInfoIROptimization(DK_OptimizationRemarkMissed, DS_Remark,
+                                   PassName, RemarkName,
+                                   *CodeRegion->getParent(), Loc, CodeRegion) {}
 
 OptimizationRemarkMissed::OptimizationRemarkMissed(const char *PassName,
                                                    StringRef RemarkName,
@@ -343,10 +343,10 @@ bool OptimizationRemarkMissed::isEnabled() const {
 
 OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(
     const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc,
-    const Value *CodeRegion)
-    : DiagnosticInfoIROptimization(
-          DK_OptimizationRemarkAnalysis, DS_Remark, PassName, RemarkName,
-          *cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
+    const BasicBlock *CodeRegion)
+    : DiagnosticInfoIROptimization(DK_OptimizationRemarkAnalysis, DS_Remark,
+                                   PassName, RemarkName,
+                                   *CodeRegion->getParent(), Loc, CodeRegion) {}
 
 OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName,
                                                        StringRef RemarkName,
@@ -358,10 +358,9 @@ OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName,
 
 OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(
     enum DiagnosticKind Kind, const char *PassName, StringRef RemarkName,
-    const DiagnosticLocation &Loc, const Value *CodeRegion)
+    const DiagnosticLocation &Loc, const BasicBlock *CodeRegion)
     : DiagnosticInfoIROptimization(Kind, DS_Remark, PassName, RemarkName,
-                                   *cast<BasicBlock>(CodeRegion)->getParent(),
-                                   Loc, CodeRegion) {}
+                                   *CodeRegion->getParent(), Loc, CodeRegion) {}
 
 OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName,
                                                        StringRef RemarkName,
@@ -387,10 +386,10 @@ void DiagnosticInfoSrcMgr::print(DiagnosticPrinter &DP) const {
 
 DiagnosticInfoOptimizationFailure::DiagnosticInfoOptimizationFailure(
     const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc,
-    const Value *CodeRegion)
-    : DiagnosticInfoIROptimization(
-          DK_OptimizationFailure, DS_Warning, PassName, RemarkName,
-          *cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
+    const BasicBlock *CodeRegion)
+    : DiagnosticInfoIROptimization(DK_OptimizationFailure, DS_Warning, PassName,
+                                   RemarkName, *CodeRegion->getParent(), Loc,
+                                   CodeRegion) {}
 
 bool DiagnosticInfoOptimizationFailure::isEnabled() const {
   // Only print warnings.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 2fe59a464457f..90c8da2952501 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -815,7 +815,7 @@ static void debugVectorizationMessage(const StringRef Prefix,
 static OptimizationRemarkAnalysis
 createLVAnalysis(const char *PassName, StringRef RemarkName, Loop *TheLoop,
                  Instruction *I, DebugLoc DL = {}) {
-  Value *CodeRegion = I ? I->getParent() : TheLoop->getHeader();
+  BasicBlock *CodeRegion = I ? I->getParent() : TheLoop->getHeader();
   // If debug location is attached to the instruction, use it. Otherwise if DL
   // was not provided, use the loop's.
   if (I && I->getDebugLoc())

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ,thanks with suggestions applied

jroelofs and others added 2 commits May 30, 2025 12:59
Co-authored-by: Florian Hahn <flo@fhahn.com>
Copy link

github-actions bot commented May 30, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@jroelofs jroelofs merged commit 798058f into llvm:main May 31, 2025
9 of 11 checks passed
@jroelofs jroelofs deleted the jroelofs/ore-footgun branch May 31, 2025 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants