Skip to content

Commit 798058f

Browse files
authored
[Remarks] Remove an upcast footgun. NFC (#142191)
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.
1 parent b967561 commit 798058f

File tree

8 files changed

+121
-114
lines changed

8 files changed

+121
-114
lines changed

llvm/include/llvm/IR/DiagnosticInfo.h

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
528528

529529
/// \p PassName is the name of the pass emitting this diagnostic. \p
530530
/// RemarkName is a textual identifier for the remark (single-word,
531-
/// camel-case). \p Fn is the function where the diagnostic is being emitted.
531+
/// CamelCase). \p Fn is the function where the diagnostic is being emitted.
532532
/// \p Loc is the location information to use in the diagnostic. If line table
533533
/// information is available, the diagnostic will include the source code
534534
/// location.
@@ -593,7 +593,7 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
593593
/// be emitted.
594594
const char *PassName;
595595

596-
/// Textual identifier for the remark (single-word, camel-case). Can be used
596+
/// Textual identifier for the remark (single-word, CamelCase). Can be used
597597
/// by external tools reading the output file for optimization remarks to
598598
/// identify the remark.
599599
StringRef RemarkName;
@@ -668,18 +668,17 @@ class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
668668
public:
669669
/// \p PassName is the name of the pass emitting this diagnostic. \p
670670
/// RemarkName is a textual identifier for the remark (single-word,
671-
/// camel-case). \p Fn is the function where the diagnostic is being emitted.
671+
/// CamelCase). \p Fn is the function where the diagnostic is being emitted.
672672
/// \p Loc is the location information to use in the diagnostic. If line table
673673
/// information is available, the diagnostic will include the source code
674-
/// location. \p CodeRegion is IR value (currently basic block) that the
675-
/// optimization operates on. This is currently used to provide run-time
676-
/// hotness information with PGO.
674+
/// location. \p CodeRegion is IR value that the optimization operates on.
675+
/// This is currently used to provide run-time hotness information with PGO.
677676
DiagnosticInfoIROptimization(enum DiagnosticKind Kind,
678677
enum DiagnosticSeverity Severity,
679678
const char *PassName, StringRef RemarkName,
680679
const Function &Fn,
681680
const DiagnosticLocation &Loc,
682-
const Value *CodeRegion = nullptr)
681+
const BasicBlock *CodeRegion = nullptr)
683682
: DiagnosticInfoOptimizationBase(Kind, Severity, PassName, RemarkName, Fn,
684683
Loc),
685684
CodeRegion(CodeRegion) {}
@@ -717,16 +716,16 @@ class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
717716
*this << Msg.str();
718717
}
719718

720-
const Value *getCodeRegion() const { return CodeRegion; }
719+
const BasicBlock *getCodeRegion() const { return CodeRegion; }
721720

722721
static bool classof(const DiagnosticInfo *DI) {
723722
return DI->getKind() >= DK_FirstRemark && DI->getKind() <= DK_LastRemark;
724723
}
725724

726725
private:
727-
/// The IR value (currently basic block) that the optimization operates on.
726+
/// The IR region (currently basic block) that the optimization operates on.
728727
/// This is currently used to provide run-time hotness information with PGO.
729-
const Value *CodeRegion = nullptr;
728+
const BasicBlock *CodeRegion = nullptr;
730729
};
731730

732731
/// Diagnostic information for applied optimization remarks.
@@ -735,11 +734,11 @@ class OptimizationRemark : public DiagnosticInfoIROptimization {
735734
/// \p PassName is the name of the pass emitting this diagnostic. If this name
736735
/// matches the regular expression given in -Rpass=, then the diagnostic will
737736
/// be emitted. \p RemarkName is a textual identifier for the remark (single-
738-
/// word, camel-case). \p Loc is the debug location and \p CodeRegion is the
739-
/// region that the optimization operates on (currently only block is
740-
/// supported).
737+
/// word, CamelCase). \p Loc is the debug location and \p CodeRegion is the
738+
/// region that the optimization operates on.
741739
OptimizationRemark(const char *PassName, StringRef RemarkName,
742-
const DiagnosticLocation &Loc, const Value *CodeRegion);
740+
const DiagnosticLocation &Loc,
741+
const BasicBlock *CodeRegion);
743742

744743
/// Same as above, but the debug location and code region are derived from \p
745744
/// Instr.
@@ -780,12 +779,11 @@ class OptimizationRemarkMissed : public DiagnosticInfoIROptimization {
780779
/// \p PassName is the name of the pass emitting this diagnostic. If this name
781780
/// matches the regular expression given in -Rpass-missed=, then the
782781
/// diagnostic will be emitted. \p RemarkName is a textual identifier for the
783-
/// remark (single-word, camel-case). \p Loc is the debug location and \p
784-
/// CodeRegion is the region that the optimization operates on (currently only
785-
/// block is supported).
782+
/// remark (single-word, CamelCase). \p Loc is the debug location and \p
783+
/// CodeRegion is the region that the optimization operates on.
786784
OptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
787785
const DiagnosticLocation &Loc,
788-
const Value *CodeRegion);
786+
const BasicBlock *CodeRegion);
789787

790788
/// Same as above but \p Inst is used to derive code region and debug
791789
/// location.
@@ -826,12 +824,11 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
826824
/// \p PassName is the name of the pass emitting this diagnostic. If this name
827825
/// matches the regular expression given in -Rpass-analysis=, then the
828826
/// diagnostic will be emitted. \p RemarkName is a textual identifier for the
829-
/// remark (single-word, camel-case). \p Loc is the debug location and \p
830-
/// CodeRegion is the region that the optimization operates on (currently only
831-
/// block is supported).
827+
/// remark (single-word, CamelCase). \p Loc is the debug location and \p
828+
/// CodeRegion is the region that the optimization operates on.
832829
OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
833830
const DiagnosticLocation &Loc,
834-
const Value *CodeRegion);
831+
const BasicBlock *CodeRegion);
835832

836833
/// This is ctor variant allows a pass to build an optimization remark
837834
/// from an existing remark.
@@ -874,7 +871,7 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
874871
OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
875872
StringRef RemarkName,
876873
const DiagnosticLocation &Loc,
877-
const Value *CodeRegion);
874+
const BasicBlock *CodeRegion);
878875

879876
private:
880877
/// This is deprecated now and only used by the function API below.
@@ -900,14 +897,14 @@ class OptimizationRemarkAnalysisFPCommute : public OptimizationRemarkAnalysis {
900897
/// \p PassName is the name of the pass emitting this diagnostic. If this name
901898
/// matches the regular expression given in -Rpass-analysis=, then the
902899
/// diagnostic will be emitted. \p RemarkName is a textual identifier for the
903-
/// remark (single-word, camel-case). \p Loc is the debug location and \p
904-
/// CodeRegion is the region that the optimization operates on (currently only
905-
/// block is supported). The front-end will append its own message related to
906-
/// options that address floating-point non-commutativity.
900+
/// remark (single-word, CamelCase). \p Loc is the debug location and \p
901+
/// CodeRegion is the region that the optimization operates on. The front-end
902+
/// will append its own message related to options that address floating-point
903+
/// non-commutativity.
907904
OptimizationRemarkAnalysisFPCommute(const char *PassName,
908905
StringRef RemarkName,
909906
const DiagnosticLocation &Loc,
910-
const Value *CodeRegion)
907+
const BasicBlock *CodeRegion)
911908
: OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute,
912909
PassName, RemarkName, Loc, CodeRegion) {}
913910

@@ -942,13 +939,13 @@ class OptimizationRemarkAnalysisAliasing : public OptimizationRemarkAnalysis {
942939
/// \p PassName is the name of the pass emitting this diagnostic. If this name
943940
/// matches the regular expression given in -Rpass-analysis=, then the
944941
/// diagnostic will be emitted. \p RemarkName is a textual identifier for the
945-
/// remark (single-word, camel-case). \p Loc is the debug location and \p
946-
/// CodeRegion is the region that the optimization operates on (currently only
947-
/// block is supported). The front-end will append its own message related to
948-
/// options that address pointer aliasing legality.
942+
/// remark (single-word, CamelCase). \p Loc is the debug location and \p
943+
/// CodeRegion is the region that the optimization operates on. The front-end
944+
/// will append its own message related to options that address pointer
945+
/// aliasing legality.
949946
OptimizationRemarkAnalysisAliasing(const char *PassName, StringRef RemarkName,
950947
const DiagnosticLocation &Loc,
951-
const Value *CodeRegion)
948+
const BasicBlock *CodeRegion)
952949
: OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing,
953950
PassName, RemarkName, Loc, CodeRegion) {}
954951

@@ -1049,12 +1046,11 @@ class DiagnosticInfoOptimizationFailure : public DiagnosticInfoIROptimization {
10491046

10501047
/// \p PassName is the name of the pass emitting this diagnostic. \p
10511048
/// RemarkName is a textual identifier for the remark (single-word,
1052-
/// camel-case). \p Loc is the debug location and \p CodeRegion is the
1053-
/// region that the optimization operates on (currently basic block is
1054-
/// supported).
1049+
/// CamelCase). \p Loc is the debug location and \p CodeRegion is the
1050+
/// region that the optimization operates on.
10551051
DiagnosticInfoOptimizationFailure(const char *PassName, StringRef RemarkName,
10561052
const DiagnosticLocation &Loc,
1057-
const Value *CodeRegion);
1053+
const BasicBlock *CodeRegion);
10581054

10591055
static bool classof(const DiagnosticInfo *DI) {
10601056
return DI->getKind() == DK_OptimizationFailure;

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,7 +2746,7 @@ OptimizationRemarkAnalysis &
27462746
LoopAccessInfo::recordAnalysis(StringRef RemarkName, const Instruction *I) {
27472747
assert(!Report && "Multiple reports generated");
27482748

2749-
const Value *CodeRegion = TheLoop->getHeader();
2749+
const BasicBlock *CodeRegion = TheLoop->getHeader();
27502750
DebugLoc DL = TheLoop->getStartLoc();
27512751

27522752
if (I) {
@@ -2757,8 +2757,8 @@ LoopAccessInfo::recordAnalysis(StringRef RemarkName, const Instruction *I) {
27572757
DL = I->getDebugLoc();
27582758
}
27592759

2760-
Report = std::make_unique<OptimizationRemarkAnalysis>(DEBUG_TYPE, RemarkName, DL,
2761-
CodeRegion);
2760+
Report = std::make_unique<OptimizationRemarkAnalysis>(DEBUG_TYPE, RemarkName,
2761+
DL, CodeRegion);
27622762
return *Report;
27632763
}
27642764

llvm/lib/CodeGen/HardwareLoops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static void debugHWLoopFailure(const StringRef DebugMsg,
9090

9191
static OptimizationRemarkAnalysis
9292
createHWLoopAnalysis(StringRef RemarkName, Loop *L, Instruction *I) {
93-
Value *CodeRegion = L->getHeader();
93+
BasicBlock *CodeRegion = L->getHeader();
9494
DebugLoc DL = L->getStartLoc();
9595

9696
if (I) {

llvm/lib/IR/DiagnosticInfo.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ void DiagnosticInfoOptimizationBase::print(DiagnosticPrinter &DP) const {
284284
OptimizationRemark::OptimizationRemark(const char *PassName,
285285
StringRef RemarkName,
286286
const DiagnosticLocation &Loc,
287-
const Value *CodeRegion)
288-
: DiagnosticInfoIROptimization(
289-
DK_OptimizationRemark, DS_Remark, PassName, RemarkName,
290-
*cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
287+
const BasicBlock *CodeRegion)
288+
: DiagnosticInfoIROptimization(DK_OptimizationRemark, DS_Remark, PassName,
289+
RemarkName, *CodeRegion->getParent(), Loc,
290+
CodeRegion) {}
291291

292292
OptimizationRemark::OptimizationRemark(const char *PassName,
293293
StringRef RemarkName,
@@ -315,10 +315,10 @@ bool OptimizationRemark::isEnabled() const {
315315

316316
OptimizationRemarkMissed::OptimizationRemarkMissed(
317317
const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc,
318-
const Value *CodeRegion)
319-
: DiagnosticInfoIROptimization(
320-
DK_OptimizationRemarkMissed, DS_Remark, PassName, RemarkName,
321-
*cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
318+
const BasicBlock *CodeRegion)
319+
: DiagnosticInfoIROptimization(DK_OptimizationRemarkMissed, DS_Remark,
320+
PassName, RemarkName,
321+
*CodeRegion->getParent(), Loc, CodeRegion) {}
322322

323323
OptimizationRemarkMissed::OptimizationRemarkMissed(const char *PassName,
324324
StringRef RemarkName,
@@ -343,10 +343,10 @@ bool OptimizationRemarkMissed::isEnabled() const {
343343

344344
OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(
345345
const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc,
346-
const Value *CodeRegion)
347-
: DiagnosticInfoIROptimization(
348-
DK_OptimizationRemarkAnalysis, DS_Remark, PassName, RemarkName,
349-
*cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
346+
const BasicBlock *CodeRegion)
347+
: DiagnosticInfoIROptimization(DK_OptimizationRemarkAnalysis, DS_Remark,
348+
PassName, RemarkName,
349+
*CodeRegion->getParent(), Loc, CodeRegion) {}
350350

351351
OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName,
352352
StringRef RemarkName,
@@ -358,10 +358,9 @@ OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName,
358358

359359
OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(
360360
enum DiagnosticKind Kind, const char *PassName, StringRef RemarkName,
361-
const DiagnosticLocation &Loc, const Value *CodeRegion)
361+
const DiagnosticLocation &Loc, const BasicBlock *CodeRegion)
362362
: DiagnosticInfoIROptimization(Kind, DS_Remark, PassName, RemarkName,
363-
*cast<BasicBlock>(CodeRegion)->getParent(),
364-
Loc, CodeRegion) {}
363+
*CodeRegion->getParent(), Loc, CodeRegion) {}
365364

366365
OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName,
367366
StringRef RemarkName,
@@ -387,10 +386,10 @@ void DiagnosticInfoSrcMgr::print(DiagnosticPrinter &DP) const {
387386

388387
DiagnosticInfoOptimizationFailure::DiagnosticInfoOptimizationFailure(
389388
const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc,
390-
const Value *CodeRegion)
391-
: DiagnosticInfoIROptimization(
392-
DK_OptimizationFailure, DS_Warning, PassName, RemarkName,
393-
*cast<BasicBlock>(CodeRegion)->getParent(), Loc, CodeRegion) {}
389+
const BasicBlock *CodeRegion)
390+
: DiagnosticInfoIROptimization(DK_OptimizationFailure, DS_Warning, PassName,
391+
RemarkName, *CodeRegion->getParent(), Loc,
392+
CodeRegion) {}
394393

395394
bool DiagnosticInfoOptimizationFailure::isEnabled() const {
396395
// Only print warnings.

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ static void debugVectorizationMessage(const StringRef Prefix,
815815
static OptimizationRemarkAnalysis
816816
createLVAnalysis(const char *PassName, StringRef RemarkName, Loop *TheLoop,
817817
Instruction *I, DebugLoc DL = {}) {
818-
Value *CodeRegion = I ? I->getParent() : TheLoop->getHeader();
818+
BasicBlock *CodeRegion = I ? I->getParent() : TheLoop->getHeader();
819819
// If debug location is attached to the instruction, use it. Otherwise if DL
820820
// was not provided, use the loop's.
821821
if (I && I->getDebugLoc())

0 commit comments

Comments
 (0)