18
18
#include " llvm/ADT/ArrayRef.h"
19
19
#include " llvm/ADT/SmallVector.h"
20
20
#include " llvm/ADT/StringRef.h"
21
- #include " llvm/ADT/Twine.h"
22
21
#include " llvm/IR/DebugLoc.h"
23
22
#include " llvm/Support/CBindingWrapping.h"
24
23
#include " llvm/Support/ErrorHandling.h"
@@ -139,22 +138,22 @@ class DiagnosticInfo {
139
138
using DiagnosticHandlerFunction = std::function<void (const DiagnosticInfo &)>;
140
139
141
140
class DiagnosticInfoGeneric : public DiagnosticInfo {
142
- const Twine & MsgStr;
141
+ StringRef MsgStr;
143
142
const Instruction *Inst = nullptr ;
144
143
145
144
public:
146
145
// / \p MsgStr is the message to be reported to the frontend.
147
146
// / This class does not copy \p MsgStr, therefore the reference must be valid
148
147
// / for the whole life time of the Diagnostic.
149
- DiagnosticInfoGeneric (const Twine & MsgStr,
148
+ DiagnosticInfoGeneric (StringRef MsgStr,
150
149
DiagnosticSeverity Severity = DS_Error)
151
150
: DiagnosticInfo(DK_Generic, Severity), MsgStr(MsgStr) {}
152
151
153
- DiagnosticInfoGeneric (const Instruction *I, const Twine & ErrMsg,
152
+ DiagnosticInfoGeneric (const Instruction *I, StringRef ErrMsg,
154
153
DiagnosticSeverity Severity = DS_Error)
155
154
: DiagnosticInfo(DK_Generic, Severity), MsgStr(ErrMsg), Inst(I) {}
156
155
157
- const Twine & getMsgStr () const { return MsgStr; }
156
+ StringRef getMsgStr () const { return MsgStr; }
158
157
const Instruction *getInstruction () const { return Inst; }
159
158
160
159
// / \see DiagnosticInfo::print.
@@ -172,7 +171,7 @@ class DiagnosticInfoInlineAsm : public DiagnosticInfo {
172
171
// / Optional line information. 0 if not set.
173
172
uint64_t LocCookie = 0 ;
174
173
// / Message to be reported.
175
- const Twine & MsgStr;
174
+ StringRef MsgStr;
176
175
// / Optional origin of the problem.
177
176
const Instruction *Instr = nullptr ;
178
177
@@ -181,19 +180,19 @@ class DiagnosticInfoInlineAsm : public DiagnosticInfo {
181
180
// / \p MsgStr gives the message.
182
181
// / This class does not copy \p MsgStr, therefore the reference must be valid
183
182
// / for the whole life time of the Diagnostic.
184
- DiagnosticInfoInlineAsm (uint64_t LocCookie, const Twine & MsgStr,
183
+ DiagnosticInfoInlineAsm (uint64_t LocCookie, StringRef MsgStr,
185
184
DiagnosticSeverity Severity = DS_Error);
186
185
187
186
// / \p Instr gives the original instruction that triggered the diagnostic.
188
187
// / \p MsgStr gives the message.
189
188
// / This class does not copy \p MsgStr, therefore the reference must be valid
190
189
// / for the whole life time of the Diagnostic.
191
190
// / Same for \p I.
192
- DiagnosticInfoInlineAsm (const Instruction &I, const Twine & MsgStr,
191
+ DiagnosticInfoInlineAsm (const Instruction &I, StringRef MsgStr,
193
192
DiagnosticSeverity Severity = DS_Error);
194
193
195
194
uint64_t getLocCookie () const { return LocCookie; }
196
- const Twine & getMsgStr () const { return MsgStr; }
195
+ StringRef getMsgStr () const { return MsgStr; }
197
196
const Instruction *getInstruction () const { return Instr; }
198
197
199
198
// / \see DiagnosticInfo::print.
@@ -258,15 +257,15 @@ class DiagnosticInfoIgnoringInvalidDebugMetadata : public DiagnosticInfo {
258
257
class DiagnosticInfoSampleProfile : public DiagnosticInfo {
259
258
public:
260
259
DiagnosticInfoSampleProfile (StringRef FileName, unsigned LineNum,
261
- const Twine & Msg,
260
+ StringRef Msg,
262
261
DiagnosticSeverity Severity = DS_Error)
263
262
: DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
264
263
LineNum (LineNum), Msg(Msg) {}
265
- DiagnosticInfoSampleProfile (StringRef FileName, const Twine & Msg,
264
+ DiagnosticInfoSampleProfile (StringRef FileName, StringRef Msg,
266
265
DiagnosticSeverity Severity = DS_Error)
267
266
: DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
268
267
Msg(Msg) {}
269
- DiagnosticInfoSampleProfile (const Twine & Msg,
268
+ DiagnosticInfoSampleProfile (StringRef Msg,
270
269
DiagnosticSeverity Severity = DS_Error)
271
270
: DiagnosticInfo(DK_SampleProfile, Severity), Msg(Msg) {}
272
271
@@ -279,7 +278,7 @@ class DiagnosticInfoSampleProfile : public DiagnosticInfo {
279
278
280
279
StringRef getFileName () const { return FileName; }
281
280
unsigned getLineNum () const { return LineNum; }
282
- const Twine & getMsg () const { return Msg; }
281
+ StringRef getMsg () const { return Msg; }
283
282
284
283
private:
285
284
// / Name of the input file associated with this diagnostic.
@@ -290,13 +289,13 @@ class DiagnosticInfoSampleProfile : public DiagnosticInfo {
290
289
unsigned LineNum = 0 ;
291
290
292
291
// / Message to report.
293
- const Twine & Msg;
292
+ StringRef Msg;
294
293
};
295
294
296
295
// / Diagnostic information for the PGO profiler.
297
296
class DiagnosticInfoPGOProfile : public DiagnosticInfo {
298
297
public:
299
- DiagnosticInfoPGOProfile (const char *FileName, const Twine & Msg,
298
+ DiagnosticInfoPGOProfile (const char *FileName, StringRef Msg,
300
299
DiagnosticSeverity Severity = DS_Error)
301
300
: DiagnosticInfo(DK_PGOProfile, Severity), FileName(FileName), Msg(Msg) {}
302
301
@@ -308,14 +307,14 @@ class DiagnosticInfoPGOProfile : public DiagnosticInfo {
308
307
}
309
308
310
309
const char *getFileName () const { return FileName; }
311
- const Twine & getMsg () const { return Msg; }
310
+ StringRef getMsg () const { return Msg; }
312
311
313
312
private:
314
313
// / Name of the input file associated with this diagnostic.
315
314
const char *FileName;
316
315
317
316
// / Message to report.
318
- const Twine & Msg;
317
+ StringRef Msg;
319
318
};
320
319
321
320
class DiagnosticLocation {
@@ -364,7 +363,7 @@ class DiagnosticInfoWithLocationBase : public DiagnosticInfo {
364
363
365
364
// / Return the absolute path tot the file.
366
365
std::string getAbsolutePath () const ;
367
-
366
+
368
367
const Function &getFunction () const { return Fn; }
369
368
DiagnosticLocation getLocation () const { return Loc; }
370
369
@@ -379,19 +378,19 @@ class DiagnosticInfoWithLocationBase : public DiagnosticInfo {
379
378
class DiagnosticInfoGenericWithLoc : public DiagnosticInfoWithLocationBase {
380
379
private:
381
380
// / Message to be reported.
382
- const Twine & MsgStr;
381
+ StringRef MsgStr;
383
382
384
383
public:
385
384
// / \p MsgStr is the message to be reported to the frontend.
386
385
// / This class does not copy \p MsgStr, therefore the reference must be valid
387
386
// / for the whole life time of the Diagnostic.
388
- DiagnosticInfoGenericWithLoc (const Twine & MsgStr, const Function &Fn,
387
+ DiagnosticInfoGenericWithLoc (StringRef MsgStr, const Function &Fn,
389
388
const DiagnosticLocation &Loc,
390
389
DiagnosticSeverity Severity = DS_Error)
391
390
: DiagnosticInfoWithLocationBase(DK_GenericWithLoc, Severity, Fn, Loc),
392
391
MsgStr (MsgStr) {}
393
392
394
- const Twine & getMsgStr () const { return MsgStr; }
393
+ StringRef getMsgStr () const { return MsgStr; }
395
394
396
395
// / \see DiagnosticInfo::print.
397
396
void print (DiagnosticPrinter &DP) const override ;
@@ -404,20 +403,20 @@ class DiagnosticInfoGenericWithLoc : public DiagnosticInfoWithLocationBase {
404
403
class DiagnosticInfoRegAllocFailure : public DiagnosticInfoWithLocationBase {
405
404
private:
406
405
// / Message to be reported.
407
- const Twine & MsgStr;
406
+ StringRef MsgStr;
408
407
409
408
public:
410
409
// / \p MsgStr is the message to be reported to the frontend.
411
410
// / This class does not copy \p MsgStr, therefore the reference must be valid
412
411
// / for the whole life time of the Diagnostic.
413
- DiagnosticInfoRegAllocFailure (const Twine & MsgStr, const Function &Fn,
412
+ DiagnosticInfoRegAllocFailure (StringRef MsgStr, const Function &Fn,
414
413
const DiagnosticLocation &DL,
415
414
DiagnosticSeverity Severity = DS_Error);
416
415
417
- DiagnosticInfoRegAllocFailure (const Twine & MsgStr, const Function &Fn,
416
+ DiagnosticInfoRegAllocFailure (StringRef MsgStr, const Function &Fn,
418
417
DiagnosticSeverity Severity = DS_Error);
419
418
420
- const Twine & getMsgStr () const { return MsgStr; }
419
+ StringRef getMsgStr () const { return MsgStr; }
421
420
422
421
// / \see DiagnosticInfo::print.
423
422
void print (DiagnosticPrinter &DP) const override ;
@@ -707,7 +706,7 @@ class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
707
706
DiagnosticInfoIROptimization (enum DiagnosticKind Kind,
708
707
enum DiagnosticSeverity Severity,
709
708
const char *PassName, const Function &Fn,
710
- const DiagnosticLocation &Loc, const Twine & Msg)
709
+ const DiagnosticLocation &Loc, StringRef Msg)
711
710
: DiagnosticInfoOptimizationBase(Kind, Severity, PassName, " " , Fn, Loc) {
712
711
*this << Msg.str ();
713
712
}
@@ -764,7 +763,7 @@ class OptimizationRemark : public DiagnosticInfoIROptimization {
764
763
// / Note that this class does not copy this message, so this reference
765
764
// / must be valid for the whole life time of the diagnostic.
766
765
OptimizationRemark (const char *PassName, const Function &Fn,
767
- const DiagnosticLocation &Loc, const Twine & Msg)
766
+ const DiagnosticLocation &Loc, StringRef Msg)
768
767
: DiagnosticInfoIROptimization(DK_OptimizationRemark, DS_Remark, PassName,
769
768
Fn, Loc, Msg) {}
770
769
};
@@ -810,7 +809,7 @@ class OptimizationRemarkMissed : public DiagnosticInfoIROptimization {
810
809
// / Note that this class does not copy this message, so this reference
811
810
// / must be valid for the whole life time of the diagnostic.
812
811
OptimizationRemarkMissed (const char *PassName, const Function &Fn,
813
- const DiagnosticLocation &Loc, const Twine & Msg)
812
+ const DiagnosticLocation &Loc, StringRef Msg)
814
813
: DiagnosticInfoIROptimization(DK_OptimizationRemarkMissed, DS_Remark,
815
814
PassName, Fn, Loc, Msg) {}
816
815
};
@@ -863,7 +862,7 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
863
862
protected:
864
863
OptimizationRemarkAnalysis (enum DiagnosticKind Kind, const char *PassName,
865
864
const Function &Fn, const DiagnosticLocation &Loc,
866
- const Twine & Msg)
865
+ StringRef Msg)
867
866
: DiagnosticInfoIROptimization(Kind, DS_Remark, PassName, Fn, Loc, Msg) {}
868
867
869
868
OptimizationRemarkAnalysis (enum DiagnosticKind Kind, const char *PassName,
@@ -882,7 +881,7 @@ class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
882
881
// / this class does not copy this message, so this reference must be valid for
883
882
// / the whole life time of the diagnostic.
884
883
OptimizationRemarkAnalysis (const char *PassName, const Function &Fn,
885
- const DiagnosticLocation &Loc, const Twine & Msg)
884
+ const DiagnosticLocation &Loc, StringRef Msg)
886
885
: DiagnosticInfoIROptimization(DK_OptimizationRemarkAnalysis, DS_Remark,
887
886
PassName, Fn, Loc, Msg) {}
888
887
};
@@ -924,7 +923,7 @@ class OptimizationRemarkAnalysisFPCommute : public OptimizationRemarkAnalysis {
924
923
// / diagnostic.
925
924
OptimizationRemarkAnalysisFPCommute (const char *PassName, const Function &Fn,
926
925
const DiagnosticLocation &Loc,
927
- const Twine & Msg)
926
+ StringRef Msg)
928
927
: OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute,
929
928
PassName, Fn, Loc, Msg) {}
930
929
};
@@ -965,7 +964,7 @@ class OptimizationRemarkAnalysisAliasing : public OptimizationRemarkAnalysis {
965
964
// / diagnostic.
966
965
OptimizationRemarkAnalysisAliasing (const char *PassName, const Function &Fn,
967
966
const DiagnosticLocation &Loc,
968
- const Twine & Msg)
967
+ StringRef Msg)
969
968
: OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing,
970
969
PassName, Fn, Loc, Msg) {}
971
970
};
@@ -991,10 +990,10 @@ class DiagnosticInfoMIRParser : public DiagnosticInfo {
991
990
992
991
// / Diagnostic information for IR instrumentation reporting.
993
992
class DiagnosticInfoInstrumentation : public DiagnosticInfo {
994
- const Twine & Msg;
993
+ StringRef Msg;
995
994
996
995
public:
997
- DiagnosticInfoInstrumentation (const Twine & DiagMsg,
996
+ DiagnosticInfoInstrumentation (StringRef DiagMsg,
998
997
DiagnosticSeverity Severity = DS_Warning)
999
998
: DiagnosticInfo(DK_Instrumentation, Severity), Msg(DiagMsg) {}
1000
999
@@ -1038,7 +1037,7 @@ class DiagnosticInfoOptimizationFailure : public DiagnosticInfoIROptimization {
1038
1037
// / of the diagnostic.
1039
1038
DiagnosticInfoOptimizationFailure (const Function &Fn,
1040
1039
const DiagnosticLocation &Loc,
1041
- const Twine & Msg)
1040
+ StringRef Msg)
1042
1041
: DiagnosticInfoIROptimization (DK_OptimizationFailure, DS_Warning,
1043
1042
nullptr , Fn, Loc, Msg) {}
1044
1043
@@ -1062,7 +1061,7 @@ class DiagnosticInfoOptimizationFailure : public DiagnosticInfoIROptimization {
1062
1061
// / Diagnostic information for unsupported feature in backend.
1063
1062
class DiagnosticInfoUnsupported : public DiagnosticInfoWithLocationBase {
1064
1063
private:
1065
- Twine Msg;
1064
+ StringRef Msg;
1066
1065
1067
1066
public:
1068
1067
// / \p Fn is the function where the diagnostic is being emitted. \p Loc is
@@ -1072,7 +1071,7 @@ class DiagnosticInfoUnsupported : public DiagnosticInfoWithLocationBase {
1072
1071
// / copy this message, so this reference must be valid for the whole life time
1073
1072
// / of the diagnostic.
1074
1073
DiagnosticInfoUnsupported (
1075
- const Function &Fn, const Twine & Msg,
1074
+ const Function &Fn, StringRef Msg,
1076
1075
const DiagnosticLocation &Loc = DiagnosticLocation(),
1077
1076
DiagnosticSeverity Severity = DS_Error)
1078
1077
: DiagnosticInfoWithLocationBase(DK_Unsupported, Severity, Fn, Loc),
@@ -1082,15 +1081,15 @@ class DiagnosticInfoUnsupported : public DiagnosticInfoWithLocationBase {
1082
1081
return DI->getKind () == DK_Unsupported;
1083
1082
}
1084
1083
1085
- const Twine & getMessage () const { return Msg; }
1084
+ const StringRef getMessage () const { return Msg; }
1086
1085
1087
1086
void print (DiagnosticPrinter &DP) const override ;
1088
1087
};
1089
1088
1090
1089
// / Diagnostic information for MisExpect analysis.
1091
1090
class DiagnosticInfoMisExpect : public DiagnosticInfoWithLocationBase {
1092
1091
public:
1093
- DiagnosticInfoMisExpect (const Instruction *Inst, Twine & Msg);
1092
+ DiagnosticInfoMisExpect (const Instruction *Inst, StringRef Msg);
1094
1093
1095
1094
// / \see DiagnosticInfo::print.
1096
1095
void print (DiagnosticPrinter &DP) const override ;
@@ -1099,11 +1098,11 @@ class DiagnosticInfoMisExpect : public DiagnosticInfoWithLocationBase {
1099
1098
return DI->getKind () == DK_MisExpect;
1100
1099
}
1101
1100
1102
- const Twine & getMsg () const { return Msg; }
1101
+ StringRef getMsg () const { return Msg; }
1103
1102
1104
1103
private:
1105
1104
// / Message to report.
1106
- const Twine & Msg;
1105
+ StringRef Msg;
1107
1106
};
1108
1107
1109
1108
static DiagnosticSeverity getDiagnosticSeverity (SourceMgr::DiagKind DK) {
0 commit comments