[llvm] [Remarks] Remove an upcast footgun. NFC (PR #142191)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 30 10:59:15 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Jon Roelofs (jroelofs)
<details>
<summary>Changes</summary>
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
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())
``````````
</details>
https://github.com/llvm/llvm-project/pull/142191
More information about the llvm-commits
mailing list