Skip to content

Commit 5971b3d

Browse files
committed
[Remarks] Remove an upcast footgun. NFC
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 1f1c725 commit 5971b3d

File tree

5 files changed

+56
-61
lines changed

5 files changed

+56
-61
lines changed

llvm/include/llvm/IR/DiagnosticInfo.h

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

524524
/// \p PassName is the name of the pass emitting this diagnostic. \p
525525
/// RemarkName is a textual identifier for the remark (single-word,
526-
/// camel-case). \p Fn is the function where the diagnostic is being emitted.
526+
/// CamelCase). \p Fn is the function where the diagnostic is being emitted.
527527
/// \p Loc is the location information to use in the diagnostic. If line table
528528
/// information is available, the diagnostic will include the source code
529529
/// location.
@@ -588,7 +588,7 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
588588
/// be emitted.
589589
const char *PassName;
590590

591-
/// Textual identifier for the remark (single-word, camel-case). Can be used
591+
/// Textual identifier for the remark (single-word, CamelCase). Can be used
592592
/// by external tools reading the output file for optimization remarks to
593593
/// identify the remark.
594594
StringRef RemarkName;
@@ -663,18 +663,17 @@ class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
663663
public:
664664
/// \p PassName is the name of the pass emitting this diagnostic. \p
665665
/// RemarkName is a textual identifier for the remark (single-word,
666-
/// camel-case). \p Fn is the function where the diagnostic is being emitted.
666+
/// CamelCase). \p Fn is the function where the diagnostic is being emitted.
667667
/// \p Loc is the location information to use in the diagnostic. If line table
668668
/// information is available, the diagnostic will include the source code
669-
/// location. \p CodeRegion is IR value (currently basic block) that the
670-
/// optimization operates on. This is currently used to provide run-time
671-
/// hotness information with PGO.
669+
/// location. \p CodeRegion is IR value that the optimization operates on.
670+
/// This is currently used to provide run-time hotness information with PGO.
672671
DiagnosticInfoIROptimization(enum DiagnosticKind Kind,
673672
enum DiagnosticSeverity Severity,
674673
const char *PassName, StringRef RemarkName,
675674
const Function &Fn,
676675
const DiagnosticLocation &Loc,
677-
const Value *CodeRegion = nullptr)
676+
const BasicBlock *CodeRegion = nullptr)
678677
: DiagnosticInfoOptimizationBase(Kind, Severity, PassName, RemarkName, Fn,
679678
Loc),
680679
CodeRegion(CodeRegion) {}
@@ -712,16 +711,16 @@ class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
712711
*this << Msg.str();
713712
}
714713

715-
const Value *getCodeRegion() const { return CodeRegion; }
714+
const BasicBlock *getCodeRegion() const { return CodeRegion; }
716715

717716
static bool classof(const DiagnosticInfo *DI) {
718717
return DI->getKind() >= DK_FirstRemark && DI->getKind() <= DK_LastRemark;
719718
}
720719

721720
private:
722-
/// The IR value (currently basic block) that the optimization operates on.
721+
/// The IR value that the optimization operates on.
723722
/// This is currently used to provide run-time hotness information with PGO.
724-
const Value *CodeRegion = nullptr;
723+
const BasicBlock *CodeRegion = nullptr;
725724
};
726725

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

739738
/// Same as above, but the debug location and code region are derived from \p
740739
/// Instr.
@@ -775,12 +774,11 @@ class OptimizationRemarkMissed : public DiagnosticInfoIROptimization {
775774
/// \p PassName is the name of the pass emitting this diagnostic. If this name
776775
/// matches the regular expression given in -Rpass-missed=, then the
777776
/// diagnostic will be emitted. \p RemarkName is a textual identifier for the
778-
/// remark (single-word, camel-case). \p Loc is the debug location and \p
779-
/// CodeRegion is the region that the optimization operates on (currently only
780-
/// block is supported).
777+
/// remark (single-word, CamelCase). \p Loc is the debug location and \p
778+
/// CodeRegion is the region that the optimization operates on.
781779
OptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
782780
const DiagnosticLocation &Loc,
783-
const Value *CodeRegion);
781+
const BasicBlock *CodeRegion);
784782

785783
/// Same as above but \p Inst is used to derive code region and debug
786784
/// location.
@@ -821,12 +819,11 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
821819
/// \p PassName is the name of the pass emitting this diagnostic. If this name
822820
/// matches the regular expression given in -Rpass-analysis=, then the
823821
/// diagnostic will be emitted. \p RemarkName is a textual identifier for the
824-
/// remark (single-word, camel-case). \p Loc is the debug location and \p
825-
/// CodeRegion is the region that the optimization operates on (currently only
826-
/// block is supported).
822+
/// remark (single-word, CamelCase). \p Loc is the debug location and \p
823+
/// CodeRegion is the region that the optimization operates on.
827824
OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
828825
const DiagnosticLocation &Loc,
829-
const Value *CodeRegion);
826+
const BasicBlock *CodeRegion);
830827

831828
/// This is ctor variant allows a pass to build an optimization remark
832829
/// from an existing remark.
@@ -869,7 +866,7 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
869866
OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
870867
StringRef RemarkName,
871868
const DiagnosticLocation &Loc,
872-
const Value *CodeRegion);
869+
const BasicBlock *CodeRegion);
873870

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

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

@@ -1044,12 +1041,11 @@ class DiagnosticInfoOptimizationFailure : public DiagnosticInfoIROptimization {
10441041

10451042
/// \p PassName is the name of the pass emitting this diagnostic. \p
10461043
/// RemarkName is a textual identifier for the remark (single-word,
1047-
/// camel-case). \p Loc is the debug location and \p CodeRegion is the
1048-
/// region that the optimization operates on (currently basic block is
1049-
/// supported).
1044+
/// CamelCase). \p Loc is the debug location and \p CodeRegion is the
1045+
/// region that the optimization operates on.
10501046
DiagnosticInfoOptimizationFailure(const char *PassName, StringRef RemarkName,
10511047
const DiagnosticLocation &Loc,
1052-
const Value *CodeRegion);
1048+
const BasicBlock *CodeRegion);
10531049

10541050
static bool classof(const DiagnosticInfo *DI) {
10551051
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)