Skip to content

Commit c454daf

Browse files
committed
fixup: clean up uses where the string *was* copied
These uses were fine, but the comment that claimed the string isn't copied are just incorrect.
1 parent 1695f88 commit c454daf

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

llvm/include/llvm/IR/DiagnosticInfo.h

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -700,13 +700,11 @@ class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
700700
/// \p Fn is the function where the diagnostic is being emitted. \p Loc is
701701
/// the location information to use in the diagnostic. If line table
702702
/// information is available, the diagnostic will include the source code
703-
/// location. \p Msg is the message to show. Note that this class does not
704-
/// copy this message, so this reference must be valid for the whole life time
705-
/// of the diagnostic.
703+
/// location. \p Msg is the message to show.
706704
DiagnosticInfoIROptimization(enum DiagnosticKind Kind,
707705
enum DiagnosticSeverity Severity,
708706
const char *PassName, const Function &Fn,
709-
const DiagnosticLocation &Loc, StringRef Msg)
707+
const DiagnosticLocation &Loc, const Twine &Msg)
710708
: DiagnosticInfoOptimizationBase(Kind, Severity, PassName, "", Fn, Loc) {
711709
*this << Msg.str();
712710
}
@@ -760,10 +758,8 @@ class OptimizationRemark : public DiagnosticInfoIROptimization {
760758
/// is being emitted. \p Loc is the location information to use in the
761759
/// diagnostic. If line table information is available, the diagnostic
762760
/// will include the source code location. \p Msg is the message to show.
763-
/// Note that this class does not copy this message, so this reference
764-
/// must be valid for the whole life time of the diagnostic.
765761
OptimizationRemark(const char *PassName, const Function &Fn,
766-
const DiagnosticLocation &Loc, StringRef Msg)
762+
const DiagnosticLocation &Loc, const Twine &Msg)
767763
: DiagnosticInfoIROptimization(DK_OptimizationRemark, DS_Remark, PassName,
768764
Fn, Loc, Msg) {}
769765
};
@@ -806,10 +802,8 @@ class OptimizationRemarkMissed : public DiagnosticInfoIROptimization {
806802
/// is being emitted. \p Loc is the location information to use in the
807803
/// diagnostic. If line table information is available, the diagnostic
808804
/// will include the source code location. \p Msg is the message to show.
809-
/// Note that this class does not copy this message, so this reference
810-
/// must be valid for the whole life time of the diagnostic.
811805
OptimizationRemarkMissed(const char *PassName, const Function &Fn,
812-
const DiagnosticLocation &Loc, StringRef Msg)
806+
const DiagnosticLocation &Loc, const Twine &Msg)
813807
: DiagnosticInfoIROptimization(DK_OptimizationRemarkMissed, DS_Remark,
814808
PassName, Fn, Loc, Msg) {}
815809
};
@@ -862,7 +856,7 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
862856
protected:
863857
OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
864858
const Function &Fn, const DiagnosticLocation &Loc,
865-
StringRef Msg)
859+
const Twine &Msg)
866860
: DiagnosticInfoIROptimization(Kind, DS_Remark, PassName, Fn, Loc, Msg) {}
867861

868862
OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
@@ -877,11 +871,9 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
877871
/// the diagnostic will be emitted. \p Fn is the function where the diagnostic
878872
/// is being emitted. \p Loc is the location information to use in the
879873
/// diagnostic. If line table information is available, the diagnostic will
880-
/// include the source code location. \p Msg is the message to show. Note that
881-
/// this class does not copy this message, so this reference must be valid for
882-
/// the whole life time of the diagnostic.
874+
/// include the source code location. \p Msg is the message to show.
883875
OptimizationRemarkAnalysis(const char *PassName, const Function &Fn,
884-
const DiagnosticLocation &Loc, StringRef Msg)
876+
const DiagnosticLocation &Loc, const Twine &Msg)
885877
: DiagnosticInfoIROptimization(DK_OptimizationRemarkAnalysis, DS_Remark,
886878
PassName, Fn, Loc, Msg) {}
887879
};
@@ -918,12 +910,10 @@ class OptimizationRemarkAnalysisFPCommute : public OptimizationRemarkAnalysis {
918910
/// diagnostic. If line table information is available, the diagnostic will
919911
/// include the source code location. \p Msg is the message to show. The
920912
/// front-end will append its own message related to options that address
921-
/// floating-point non-commutativity. Note that this class does not copy this
922-
/// message, so this reference must be valid for the whole life time of the
923-
/// diagnostic.
913+
/// floating-point non-commutativity.
924914
OptimizationRemarkAnalysisFPCommute(const char *PassName, const Function &Fn,
925915
const DiagnosticLocation &Loc,
926-
StringRef Msg)
916+
const Twine &Msg)
927917
: OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute,
928918
PassName, Fn, Loc, Msg) {}
929919
};
@@ -959,12 +949,10 @@ class OptimizationRemarkAnalysisAliasing : public OptimizationRemarkAnalysis {
959949
/// diagnostic. If line table information is available, the diagnostic will
960950
/// include the source code location. \p Msg is the message to show. The
961951
/// front-end will append its own message related to options that address
962-
/// pointer aliasing legality. Note that this class does not copy this
963-
/// message, so this reference must be valid for the whole life time of the
964-
/// diagnostic.
952+
/// pointer aliasing legality.
965953
OptimizationRemarkAnalysisAliasing(const char *PassName, const Function &Fn,
966954
const DiagnosticLocation &Loc,
967-
StringRef Msg)
955+
const Twine &Msg)
968956
: OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing,
969957
PassName, Fn, Loc, Msg) {}
970958
};
@@ -1032,12 +1020,10 @@ class DiagnosticInfoOptimizationFailure : public DiagnosticInfoIROptimization {
10321020
/// \p Fn is the function where the diagnostic is being emitted. \p Loc is
10331021
/// the location information to use in the diagnostic. If line table
10341022
/// information is available, the diagnostic will include the source code
1035-
/// location. \p Msg is the message to show. Note that this class does not
1036-
/// copy this message, so this reference must be valid for the whole life time
1037-
/// of the diagnostic.
1023+
/// location. \p Msg is the message to show.
10381024
DiagnosticInfoOptimizationFailure(const Function &Fn,
10391025
const DiagnosticLocation &Loc,
1040-
StringRef Msg)
1026+
const Twine &Msg = "")
10411027
: DiagnosticInfoIROptimization(DK_OptimizationFailure, DS_Warning,
10421028
nullptr, Fn, Loc, Msg) {}
10431029

llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,12 @@ void AMDGPUAsmPrinter::validateMCResourceInfo(Function &F) {
468468
F, "amdgpu-waves-per-eu", {0, 0}, true);
469469

470470
if (TryGetMCExprValue(OccupancyExpr, Occupancy) && Occupancy < MinWEU) {
471-
SmallString<256> Msg = formatv(
472-
"failed to meet occupancy target given by 'amdgpu-waves-per-eu' in "
473-
"'{0}': desired occupancy was {1}, final occupancy is {2}",
474-
F.getName(), MinWEU, Occupancy);
475-
DiagnosticInfoOptimizationFailure Diag(F, F.getSubprogram(), Msg);
471+
DiagnosticInfoOptimizationFailure Diag(F, F.getSubprogram());
472+
Diag << "failed to meet occupancy target given by "
473+
"'amdgpu-waves-per-eu' in '"
474+
<< F.getName() << "': desired occupancy was "
475+
<< std::to_string(MinWEU) << ", final occupancy is "
476+
<< std::to_string(Occupancy);
476477
F.getContext().diagnose(Diag);
477478
return;
478479
}
@@ -1262,12 +1263,13 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
12621263
AMDGPU::getIntegerPairAttribute(F, "amdgpu-waves-per-eu", {0, 0}, true);
12631264
uint64_t Occupancy;
12641265
if (TryGetMCExprValue(ProgInfo.Occupancy, Occupancy) && Occupancy < MinWEU) {
1265-
SmallString<256> Msg = formatv(
1266-
"failed to meet occupancy target given by 'amdgpu-waves-per-eu' in "
1267-
"'{0}'': desired occupancy was {1}, final occupancy is {2}",
1268-
F.getName(), MinWEU, Occupancy);
1269-
F.getContext().diagnose(
1270-
DiagnosticInfoOptimizationFailure(F, F.getSubprogram(), Msg));
1266+
DiagnosticInfoOptimizationFailure Diag(F, F.getSubprogram());
1267+
Diag
1268+
<< "failed to meet occupancy target given by 'amdgpu-waves-per-eu' in '"
1269+
<< F.getName(),
1270+
<< "': desired occupancy was " << std::to_string(MinWEU)
1271+
<< ", final occupancy is " << Occupancy;
1272+
F.getContext().diagnose(Diag);
12711273
}
12721274

12731275
if (isGFX11Plus(STM)) {

0 commit comments

Comments
 (0)