1 //===- llvm/IR/DiagnosticInfo.h - Diagnostic Declaration --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the different classes involved in low level diagnostics.
12 // Diagnostics reporting is still done as part of the LLVMContext.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_IR_DIAGNOSTICINFO_H
16 #define LLVM_IR_DIAGNOSTICINFO_H
18 #include "llvm-c/Types.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/ADT/Twine.h"
23 #include "llvm/IR/DebugLoc.h"
24 #include "llvm/Support/CBindingWrapping.h"
25 #include "llvm/Support/YAMLTraits.h"
31 // Forward declarations.
32 class DiagnosticPrinter;
39 /// \brief Defines the different supported severity of a diagnostic.
40 enum DiagnosticSeverity : char {
44 // A note attaches additional information to one of the previous diagnostic
49 /// \brief Defines the different supported kind of a diagnostic.
50 /// This enum should be extended with a new ID for each added concrete subclass.
56 DK_DebugMetadataVersion,
57 DK_DebugMetadataInvalid,
60 DK_OptimizationRemark,
61 DK_OptimizationRemarkMissed,
62 DK_OptimizationRemarkAnalysis,
63 DK_OptimizationRemarkAnalysisFPCommute,
64 DK_OptimizationRemarkAnalysisAliasing,
65 DK_OptimizationFailure,
66 DK_FirstRemark = DK_OptimizationRemark,
67 DK_LastRemark = DK_OptimizationFailure,
74 /// \brief Get the next available kind ID for a plugin diagnostic.
75 /// Each time this function is called, it returns a different number.
76 /// Therefore, a plugin that wants to "identify" its own classes
77 /// with a dynamic identifier, just have to use this method to get a new ID
78 /// and assign it to each of its classes.
79 /// The returned ID will be greater than or equal to DK_FirstPluginKind.
80 /// Thus, the plugin identifiers will not conflict with the
81 /// DiagnosticKind values.
82 int getNextAvailablePluginDiagnosticKind();
84 /// \brief This is the base abstract class for diagnostic reporting in
86 /// The print method must be overloaded by the subclasses to print a
87 /// user-friendly message in the client of the backend (let us call it a
89 class DiagnosticInfo {
91 /// Kind defines the kind of report this is about.
92 const /* DiagnosticKind */ int Kind;
93 /// Severity gives the severity of the diagnostic.
94 const DiagnosticSeverity Severity;
97 DiagnosticInfo(/* DiagnosticKind */ int Kind, DiagnosticSeverity Severity)
98 : Kind(Kind), Severity(Severity) {}
100 virtual ~DiagnosticInfo() {}
102 /* DiagnosticKind */ int getKind() const { return Kind; }
103 DiagnosticSeverity getSeverity() const { return Severity; }
105 /// Print using the given \p DP a user-friendly message.
106 /// This is the default message that will be printed to the user.
107 /// It is used when the frontend does not directly take advantage
108 /// of the information contained in fields of the subclasses.
109 /// The printed message must not end with '.' nor start with a severity
111 virtual void print(DiagnosticPrinter &DP) const = 0;
114 typedef std::function<void(const DiagnosticInfo &)> DiagnosticHandlerFunction;
116 /// Diagnostic information for inline asm reporting.
117 /// This is basically a message and an optional location.
118 class DiagnosticInfoInlineAsm : public DiagnosticInfo {
120 /// Optional line information. 0 if not set.
122 /// Message to be reported.
124 /// Optional origin of the problem.
125 const Instruction *Instr;
128 /// \p MsgStr is the message to be reported to the frontend.
129 /// This class does not copy \p MsgStr, therefore the reference must be valid
130 /// for the whole life time of the Diagnostic.
131 DiagnosticInfoInlineAsm(const Twine &MsgStr,
132 DiagnosticSeverity Severity = DS_Error)
133 : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr),
136 /// \p LocCookie if non-zero gives the line number for this report.
137 /// \p MsgStr gives the message.
138 /// This class does not copy \p MsgStr, therefore the reference must be valid
139 /// for the whole life time of the Diagnostic.
140 DiagnosticInfoInlineAsm(unsigned LocCookie, const Twine &MsgStr,
141 DiagnosticSeverity Severity = DS_Error)
142 : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie),
143 MsgStr(MsgStr), Instr(nullptr) {}
145 /// \p Instr gives the original instruction that triggered the diagnostic.
146 /// \p MsgStr gives the message.
147 /// This class does not copy \p MsgStr, therefore the reference must be valid
148 /// for the whole life time of the Diagnostic.
150 DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr,
151 DiagnosticSeverity Severity = DS_Error);
153 unsigned getLocCookie() const { return LocCookie; }
154 const Twine &getMsgStr() const { return MsgStr; }
155 const Instruction *getInstruction() const { return Instr; }
157 /// \see DiagnosticInfo::print.
158 void print(DiagnosticPrinter &DP) const override;
160 static bool classof(const DiagnosticInfo *DI) {
161 return DI->getKind() == DK_InlineAsm;
165 /// Diagnostic information for stack size etc. reporting.
166 /// This is basically a function and a size.
167 class DiagnosticInfoResourceLimit : public DiagnosticInfo {
169 /// The function that is concerned by this resource limit diagnostic.
172 /// Description of the resource type (e.g. stack size)
173 const char *ResourceName;
175 /// The computed size usage
176 uint64_t ResourceSize;
179 uint64_t ResourceLimit;
182 /// \p The function that is concerned by this stack size diagnostic.
183 /// \p The computed stack size.
184 DiagnosticInfoResourceLimit(const Function &Fn,
185 const char *ResourceName,
186 uint64_t ResourceSize,
187 DiagnosticSeverity Severity = DS_Warning,
188 DiagnosticKind Kind = DK_ResourceLimit,
189 uint64_t ResourceLimit = 0)
190 : DiagnosticInfo(Kind, Severity),
192 ResourceName(ResourceName),
193 ResourceSize(ResourceSize),
194 ResourceLimit(ResourceLimit) {}
196 const Function &getFunction() const { return Fn; }
197 const char *getResourceName() const { return ResourceName; }
198 uint64_t getResourceSize() const { return ResourceSize; }
199 uint64_t getResourceLimit() const { return ResourceLimit; }
201 /// \see DiagnosticInfo::print.
202 void print(DiagnosticPrinter &DP) const override;
204 static bool classof(const DiagnosticInfo *DI) {
205 return DI->getKind() == DK_ResourceLimit ||
206 DI->getKind() == DK_StackSize;
210 class DiagnosticInfoStackSize : public DiagnosticInfoResourceLimit {
212 DiagnosticInfoStackSize(const Function &Fn,
214 DiagnosticSeverity Severity = DS_Warning,
215 uint64_t StackLimit = 0)
216 : DiagnosticInfoResourceLimit(Fn, "stack size", StackSize,
217 Severity, DK_StackSize, StackLimit) {}
219 uint64_t getStackSize() const { return getResourceSize(); }
220 uint64_t getStackLimit() const { return getResourceLimit(); }
222 static bool classof(const DiagnosticInfo *DI) {
223 return DI->getKind() == DK_StackSize;
227 /// Diagnostic information for debug metadata version reporting.
228 /// This is basically a module and a version.
229 class DiagnosticInfoDebugMetadataVersion : public DiagnosticInfo {
231 /// The module that is concerned by this debug metadata version diagnostic.
233 /// The actual metadata version.
234 unsigned MetadataVersion;
237 /// \p The module that is concerned by this debug metadata version diagnostic.
238 /// \p The actual metadata version.
239 DiagnosticInfoDebugMetadataVersion(const Module &M, unsigned MetadataVersion,
240 DiagnosticSeverity Severity = DS_Warning)
241 : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M),
242 MetadataVersion(MetadataVersion) {}
244 const Module &getModule() const { return M; }
245 unsigned getMetadataVersion() const { return MetadataVersion; }
247 /// \see DiagnosticInfo::print.
248 void print(DiagnosticPrinter &DP) const override;
250 static bool classof(const DiagnosticInfo *DI) {
251 return DI->getKind() == DK_DebugMetadataVersion;
255 /// Diagnostic information for stripping invalid debug metadata.
256 class DiagnosticInfoIgnoringInvalidDebugMetadata : public DiagnosticInfo {
258 /// The module that is concerned by this debug metadata version diagnostic.
262 /// \p The module that is concerned by this debug metadata version diagnostic.
263 DiagnosticInfoIgnoringInvalidDebugMetadata(
264 const Module &M, DiagnosticSeverity Severity = DS_Warning)
265 : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M) {}
267 const Module &getModule() const { return M; }
269 /// \see DiagnosticInfo::print.
270 void print(DiagnosticPrinter &DP) const override;
272 static bool classof(const DiagnosticInfo *DI) {
273 return DI->getKind() == DK_DebugMetadataInvalid;
278 /// Diagnostic information for the sample profiler.
279 class DiagnosticInfoSampleProfile : public DiagnosticInfo {
281 DiagnosticInfoSampleProfile(StringRef FileName, unsigned LineNum,
283 DiagnosticSeverity Severity = DS_Error)
284 : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
285 LineNum(LineNum), Msg(Msg) {}
286 DiagnosticInfoSampleProfile(StringRef FileName, const Twine &Msg,
287 DiagnosticSeverity Severity = DS_Error)
288 : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
289 LineNum(0), Msg(Msg) {}
290 DiagnosticInfoSampleProfile(const Twine &Msg,
291 DiagnosticSeverity Severity = DS_Error)
292 : DiagnosticInfo(DK_SampleProfile, Severity), LineNum(0), Msg(Msg) {}
294 /// \see DiagnosticInfo::print.
295 void print(DiagnosticPrinter &DP) const override;
297 static bool classof(const DiagnosticInfo *DI) {
298 return DI->getKind() == DK_SampleProfile;
301 StringRef getFileName() const { return FileName; }
302 unsigned getLineNum() const { return LineNum; }
303 const Twine &getMsg() const { return Msg; }
306 /// Name of the input file associated with this diagnostic.
309 /// Line number where the diagnostic occurred. If 0, no line number will
310 /// be emitted in the message.
313 /// Message to report.
317 /// Diagnostic information for the PGO profiler.
318 class DiagnosticInfoPGOProfile : public DiagnosticInfo {
320 DiagnosticInfoPGOProfile(const char *FileName, const Twine &Msg,
321 DiagnosticSeverity Severity = DS_Error)
322 : DiagnosticInfo(DK_PGOProfile, Severity), FileName(FileName), Msg(Msg) {}
324 /// \see DiagnosticInfo::print.
325 void print(DiagnosticPrinter &DP) const override;
327 static bool classof(const DiagnosticInfo *DI) {
328 return DI->getKind() == DK_PGOProfile;
331 const char *getFileName() const { return FileName; }
332 const Twine &getMsg() const { return Msg; }
335 /// Name of the input file associated with this diagnostic.
336 const char *FileName;
338 /// Message to report.
342 /// Common features for diagnostics with an associated DebugLoc
343 class DiagnosticInfoWithDebugLocBase : public DiagnosticInfo {
345 /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
346 /// the location information to use in the diagnostic.
347 DiagnosticInfoWithDebugLocBase(enum DiagnosticKind Kind,
348 enum DiagnosticSeverity Severity,
350 const DebugLoc &DLoc)
351 : DiagnosticInfo(Kind, Severity), Fn(Fn), DLoc(DLoc) {}
353 /// Return true if location information is available for this diagnostic.
354 bool isLocationAvailable() const;
356 /// Return a string with the location information for this diagnostic
357 /// in the format "file:line:col". If location information is not available,
358 /// it returns "<unknown>:0:0".
359 const std::string getLocationStr() const;
361 /// Return location information for this diagnostic in three parts:
362 /// the source file name, line number and column.
363 void getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const;
365 const Function &getFunction() const { return Fn; }
366 const DebugLoc &getDebugLoc() const { return DLoc; }
369 /// Function where this diagnostic is triggered.
372 /// Debug location where this diagnostic is triggered.
376 /// Common features for diagnostics dealing with optimization remarks.
377 class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithDebugLocBase {
379 /// \brief Used to set IsVerbose via the stream interface.
380 struct setIsVerbose {};
382 /// \brief Used in the streaming interface as the general argument type. It
383 /// internally converts everything into a key-value pair.
387 // If set, the debug location corresponding to the value.
390 explicit Argument(StringRef Str = "") : Key("String"), Val(Str) {}
391 Argument(StringRef Key, Value *V);
392 Argument(StringRef Key, int N);
393 Argument(StringRef Key, unsigned N);
394 Argument(StringRef Key, bool B) : Key(Key), Val(B ? "true" : "false") {}
397 /// \p PassName is the name of the pass emitting this diagnostic. \p
398 /// RemarkName is a textual identifier for the remark. \p Fn is the function
399 /// where the diagnostic is being emitted. \p DLoc is the location information
400 /// to use in the diagnostic. If line table information is available, the
401 /// diagnostic will include the source code location. \p CodeRegion is IR
402 /// value (currently basic block) that the optimization operates on. This is
403 /// currently used to provide run-time hotness information with PGO.
404 DiagnosticInfoOptimizationBase(enum DiagnosticKind Kind,
405 enum DiagnosticSeverity Severity,
406 const char *PassName, StringRef RemarkName,
407 const Function &Fn, const DebugLoc &DLoc,
408 Value *CodeRegion = nullptr)
409 : DiagnosticInfoWithDebugLocBase(Kind, Severity, Fn, DLoc),
410 PassName(PassName), RemarkName(RemarkName), CodeRegion(CodeRegion) {}
412 /// \brief This is ctor variant allows a pass to build an optimization remark
413 /// from an existing remark.
415 /// This is useful when a transformation pass (e.g LV) wants to emit a remark
416 /// (\p Orig) generated by one of its analyses (e.g. LAA) as its own analysis
417 /// remark. The string \p Prepend will be emitted before the original
419 DiagnosticInfoOptimizationBase(const char *PassName, StringRef Prepend,
420 const DiagnosticInfoOptimizationBase &Orig)
421 : DiagnosticInfoWithDebugLocBase((DiagnosticKind)Orig.getKind(),
422 Orig.getSeverity(), Orig.getFunction(),
424 PassName(PassName), RemarkName(Orig.RemarkName),
425 CodeRegion(Orig.getCodeRegion()) {
427 std::copy(Orig.Args.begin(), Orig.Args.end(), std::back_inserter(Args));
430 /// Legacy interface.
431 /// \p PassName is the name of the pass emitting this diagnostic.
432 /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
433 /// the location information to use in the diagnostic. If line table
434 /// information is available, the diagnostic will include the source code
435 /// location. \p Msg is the message to show. Note that this class does not
436 /// copy this message, so this reference must be valid for the whole life time
437 /// of the diagnostic.
438 DiagnosticInfoOptimizationBase(enum DiagnosticKind Kind,
439 enum DiagnosticSeverity Severity,
440 const char *PassName, const Function &Fn,
441 const DebugLoc &DLoc, const Twine &Msg,
442 Optional<uint64_t> Hotness = None)
443 : DiagnosticInfoWithDebugLocBase(Kind, Severity, Fn, DLoc),
444 PassName(PassName), Hotness(Hotness) {
445 Args.push_back(Argument(Msg.str()));
448 DiagnosticInfoOptimizationBase &operator<<(StringRef S);
449 DiagnosticInfoOptimizationBase &operator<<(Argument A);
450 DiagnosticInfoOptimizationBase &operator<<(setIsVerbose V);
452 /// \see DiagnosticInfo::print.
453 void print(DiagnosticPrinter &DP) const override;
455 /// Return true if this optimization remark is enabled by one of
456 /// of the LLVM command line flags (-pass-remarks, -pass-remarks-missed,
457 /// or -pass-remarks-analysis). Note that this only handles the LLVM
458 /// flags. We cannot access Clang flags from here (they are handled
459 /// in BackendConsumer::OptimizationRemarkHandler).
460 virtual bool isEnabled() const = 0;
462 StringRef getPassName() const { return PassName; }
463 std::string getMsg() const;
464 Optional<uint64_t> getHotness() const { return Hotness; }
465 void setHotness(Optional<uint64_t> H) { Hotness = H; }
467 Value *getCodeRegion() const { return CodeRegion; }
469 bool isVerbose() const { return IsVerbose; }
471 static bool classof(const DiagnosticInfo *DI) {
472 return DI->getKind() >= DK_FirstRemark &&
473 DI->getKind() <= DK_LastRemark;
477 /// Name of the pass that triggers this report. If this matches the
478 /// regular expression given in -Rpass=regexp, then the remark will
480 const char *PassName;
482 /// Textual identifier for the remark. Can be used by external tools reading
483 /// the YAML output file for optimization remarks to identify the remark.
484 StringRef RemarkName;
486 /// If profile information is available, this is the number of times the
487 /// corresponding code was executed in a profile instrumentation run.
488 Optional<uint64_t> Hotness;
490 /// The IR value (currently basic block) that the optimization operates on.
491 /// This is currently used to provide run-time hotness information with PGO.
494 /// Arguments collected via the streaming interface.
495 SmallVector<Argument, 4> Args;
497 /// The remark is expected to be noisy.
498 bool IsVerbose = false;
500 friend struct yaml::MappingTraits<DiagnosticInfoOptimizationBase *>;
503 /// Diagnostic information for applied optimization remarks.
504 class OptimizationRemark : public DiagnosticInfoOptimizationBase {
506 /// \p PassName is the name of the pass emitting this diagnostic. If
507 /// this name matches the regular expression given in -Rpass=, then the
508 /// diagnostic will be emitted. \p Fn is the function where the diagnostic
509 /// is being emitted. \p DLoc is the location information to use in the
510 /// diagnostic. If line table information is available, the diagnostic
511 /// will include the source code location. \p Msg is the message to show.
512 /// Note that this class does not copy this message, so this reference
513 /// must be valid for the whole life time of the diagnostic.
514 OptimizationRemark(const char *PassName, const Function &Fn,
515 const DebugLoc &DLoc, const Twine &Msg,
516 Optional<uint64_t> Hotness = None)
517 : DiagnosticInfoOptimizationBase(DK_OptimizationRemark, DS_Remark,
518 PassName, Fn, DLoc, Msg, Hotness) {}
520 /// \p PassName is the name of the pass emitting this diagnostic. If this name
521 /// matches the regular expression given in -Rpass=, then the diagnostic will
522 /// be emitted. \p RemarkName is a textual identifier for the remark. \p
523 /// DLoc is the debug location and \p CodeRegion is the region that the
524 /// optimization operates on (currently on block is supported).
525 OptimizationRemark(const char *PassName, StringRef RemarkName,
526 const DebugLoc &DLoc, Value *CodeRegion);
528 /// Same as above but the debug location and code region is derived from \p
530 OptimizationRemark(const char *PassName, StringRef RemarkName,
533 static bool classof(const DiagnosticInfo *DI) {
534 return DI->getKind() == DK_OptimizationRemark;
537 /// \see DiagnosticInfoOptimizationBase::isEnabled.
538 bool isEnabled() const override;
541 /// Diagnostic information for missed-optimization remarks.
542 class OptimizationRemarkMissed : public DiagnosticInfoOptimizationBase {
544 /// \p PassName is the name of the pass emitting this diagnostic. If
545 /// this name matches the regular expression given in -Rpass-missed=, then the
546 /// diagnostic will be emitted. \p Fn is the function where the diagnostic
547 /// is being emitted. \p DLoc is the location information to use in the
548 /// diagnostic. If line table information is available, the diagnostic
549 /// will include the source code location. \p Msg is the message to show.
550 /// Note that this class does not copy this message, so this reference
551 /// must be valid for the whole life time of the diagnostic.
552 OptimizationRemarkMissed(const char *PassName, const Function &Fn,
553 const DebugLoc &DLoc, const Twine &Msg,
554 Optional<uint64_t> Hotness = None)
555 : DiagnosticInfoOptimizationBase(DK_OptimizationRemarkMissed, DS_Remark,
556 PassName, Fn, DLoc, Msg, Hotness) {}
558 /// \p PassName is the name of the pass emitting this diagnostic. If this name
559 /// matches the regular expression given in -Rpass-missed=, then the
560 /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
561 /// remark. \p DLoc is the debug location and \p CodeRegion is the region
562 /// that the optimization operates on (currently on block is supported).
563 OptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
564 const DebugLoc &DLoc, Value *CodeRegion);
566 /// \brief Same as above but \p Inst is used to derive code region and debug
568 OptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
571 static bool classof(const DiagnosticInfo *DI) {
572 return DI->getKind() == DK_OptimizationRemarkMissed;
575 /// \see DiagnosticInfoOptimizationBase::isEnabled.
576 bool isEnabled() const override;
579 /// Diagnostic information for optimization analysis remarks.
580 class OptimizationRemarkAnalysis : public DiagnosticInfoOptimizationBase {
582 /// \p PassName is the name of the pass emitting this diagnostic. If
583 /// this name matches the regular expression given in -Rpass-analysis=, then
584 /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
585 /// is being emitted. \p DLoc is the location information to use in the
586 /// diagnostic. If line table information is available, the diagnostic will
587 /// include the source code location. \p Msg is the message to show. Note that
588 /// this class does not copy this message, so this reference must be valid for
589 /// the whole life time of the diagnostic.
590 OptimizationRemarkAnalysis(const char *PassName, const Function &Fn,
591 const DebugLoc &DLoc, const Twine &Msg,
592 Optional<uint64_t> Hotness = None)
593 : DiagnosticInfoOptimizationBase(DK_OptimizationRemarkAnalysis, DS_Remark,
594 PassName, Fn, DLoc, Msg, Hotness) {}
596 /// \p PassName is the name of the pass emitting this diagnostic. If this name
597 /// matches the regular expression given in -Rpass-analysis=, then the
598 /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
599 /// remark. \p DLoc is the debug location and \p CodeRegion is the region
600 /// that the optimization operates on (currently on block is supported).
601 OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
602 const DebugLoc &DLoc, Value *CodeRegion);
604 /// \brief This is ctor variant allows a pass to build an optimization remark
605 /// from an existing remark.
607 /// This is useful when a transformation pass (e.g LV) wants to emit a remark
608 /// (\p Orig) generated by one of its analyses (e.g. LAA) as its own analysis
609 /// remark. The string \p Prepend will be emitted before the original
611 OptimizationRemarkAnalysis(const char *PassName, StringRef Prepend,
612 const OptimizationRemarkAnalysis &Orig)
613 : DiagnosticInfoOptimizationBase(PassName, Prepend, Orig) {}
615 /// \brief Same as above but \p Inst is used to derive code region and debug
617 OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
620 static bool classof(const DiagnosticInfo *DI) {
621 return DI->getKind() == DK_OptimizationRemarkAnalysis;
624 /// \see DiagnosticInfoOptimizationBase::isEnabled.
625 bool isEnabled() const override;
627 static const char *AlwaysPrint;
629 bool shouldAlwaysPrint() const { return getPassName() == AlwaysPrint; }
632 OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
633 const Function &Fn, const DebugLoc &DLoc,
634 const Twine &Msg, Optional<uint64_t> Hotness)
635 : DiagnosticInfoOptimizationBase(Kind, DS_Remark, PassName, Fn, DLoc, Msg,
638 OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
639 StringRef RemarkName, const DebugLoc &DLoc,
643 /// Diagnostic information for optimization analysis remarks related to
644 /// floating-point non-commutativity.
645 class OptimizationRemarkAnalysisFPCommute : public OptimizationRemarkAnalysis {
647 /// \p PassName is the name of the pass emitting this diagnostic. If
648 /// this name matches the regular expression given in -Rpass-analysis=, then
649 /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
650 /// is being emitted. \p DLoc is the location information to use in the
651 /// diagnostic. If line table information is available, the diagnostic will
652 /// include the source code location. \p Msg is the message to show. The
653 /// front-end will append its own message related to options that address
654 /// floating-point non-commutativity. Note that this class does not copy this
655 /// message, so this reference must be valid for the whole life time of the
657 OptimizationRemarkAnalysisFPCommute(const char *PassName, const Function &Fn,
658 const DebugLoc &DLoc, const Twine &Msg,
659 Optional<uint64_t> Hotness = None)
660 : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute,
661 PassName, Fn, DLoc, Msg, Hotness) {}
663 /// \p PassName is the name of the pass emitting this diagnostic. If this name
664 /// matches the regular expression given in -Rpass-analysis=, then the
665 /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
666 /// remark. \p DLoc is the debug location and \p CodeRegion is the region
667 /// that the optimization operates on (currently on block is supported). The
668 /// front-end will append its own message related to options that address
669 /// floating-point non-commutativity.
670 OptimizationRemarkAnalysisFPCommute(const char *PassName,
671 StringRef RemarkName,
672 const DebugLoc &DLoc, Value *CodeRegion)
673 : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute,
674 PassName, RemarkName, DLoc, CodeRegion) {}
676 static bool classof(const DiagnosticInfo *DI) {
677 return DI->getKind() == DK_OptimizationRemarkAnalysisFPCommute;
681 /// Diagnostic information for optimization analysis remarks related to
682 /// pointer aliasing.
683 class OptimizationRemarkAnalysisAliasing : public OptimizationRemarkAnalysis {
685 /// \p PassName is the name of the pass emitting this diagnostic. If
686 /// this name matches the regular expression given in -Rpass-analysis=, then
687 /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
688 /// is being emitted. \p DLoc is the location information to use in the
689 /// diagnostic. If line table information is available, the diagnostic will
690 /// include the source code location. \p Msg is the message to show. The
691 /// front-end will append its own message related to options that address
692 /// pointer aliasing legality. Note that this class does not copy this
693 /// message, so this reference must be valid for the whole life time of the
695 OptimizationRemarkAnalysisAliasing(const char *PassName, const Function &Fn,
696 const DebugLoc &DLoc, const Twine &Msg,
697 Optional<uint64_t> Hotness = None)
698 : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing,
699 PassName, Fn, DLoc, Msg, Hotness) {}
701 /// \p PassName is the name of the pass emitting this diagnostic. If this name
702 /// matches the regular expression given in -Rpass-analysis=, then the
703 /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
704 /// remark. \p DLoc is the debug location and \p CodeRegion is the region
705 /// that the optimization operates on (currently on block is supported). The
706 /// front-end will append its own message related to options that address
707 /// pointer aliasing legality.
708 OptimizationRemarkAnalysisAliasing(const char *PassName, StringRef RemarkName,
709 const DebugLoc &DLoc, Value *CodeRegion)
710 : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing,
711 PassName, RemarkName, DLoc, CodeRegion) {}
713 static bool classof(const DiagnosticInfo *DI) {
714 return DI->getKind() == DK_OptimizationRemarkAnalysisAliasing;
718 /// Diagnostic information for machine IR parser.
719 class DiagnosticInfoMIRParser : public DiagnosticInfo {
720 const SMDiagnostic &Diagnostic;
723 DiagnosticInfoMIRParser(DiagnosticSeverity Severity,
724 const SMDiagnostic &Diagnostic)
725 : DiagnosticInfo(DK_MIRParser, Severity), Diagnostic(Diagnostic) {}
727 const SMDiagnostic &getDiagnostic() const { return Diagnostic; }
729 void print(DiagnosticPrinter &DP) const override;
731 static bool classof(const DiagnosticInfo *DI) {
732 return DI->getKind() == DK_MIRParser;
736 /// Diagnostic information for ISel fallback path.
737 class DiagnosticInfoISelFallback : public DiagnosticInfo {
738 /// The function that is concerned by this diagnostic.
742 DiagnosticInfoISelFallback(const Function &Fn,
743 DiagnosticSeverity Severity = DS_Warning)
744 : DiagnosticInfo(DK_ISelFallback, Severity), Fn(Fn) {}
746 const Function &getFunction() const { return Fn; }
748 void print(DiagnosticPrinter &DP) const override;
750 static bool classof(const DiagnosticInfo *DI) {
751 return DI->getKind() == DK_ISelFallback;
755 // Create wrappers for C Binding types (see CBindingWrapping.h).
756 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DiagnosticInfo, LLVMDiagnosticInfoRef)
758 /// Emit an optimization-applied message. \p PassName is the name of the pass
759 /// emitting the message. If -Rpass= is given and \p PassName matches the
760 /// regular expression in -Rpass, then the remark will be emitted. \p Fn is
761 /// the function triggering the remark, \p DLoc is the debug location where
762 /// the diagnostic is generated. \p Msg is the message string to use.
763 void emitOptimizationRemark(LLVMContext &Ctx, const char *PassName,
764 const Function &Fn, const DebugLoc &DLoc,
767 /// Emit an optimization-missed message. \p PassName is the name of the
768 /// pass emitting the message. If -Rpass-missed= is given and \p PassName
769 /// matches the regular expression in -Rpass, then the remark will be
770 /// emitted. \p Fn is the function triggering the remark, \p DLoc is the
771 /// debug location where the diagnostic is generated. \p Msg is the
772 /// message string to use.
773 void emitOptimizationRemarkMissed(LLVMContext &Ctx, const char *PassName,
774 const Function &Fn, const DebugLoc &DLoc,
777 /// Emit an optimization analysis remark message. \p PassName is the name of
778 /// the pass emitting the message. If -Rpass-analysis= is given and \p
779 /// PassName matches the regular expression in -Rpass, then the remark will be
780 /// emitted. \p Fn is the function triggering the remark, \p DLoc is the debug
781 /// location where the diagnostic is generated. \p Msg is the message string
783 void emitOptimizationRemarkAnalysis(LLVMContext &Ctx, const char *PassName,
784 const Function &Fn, const DebugLoc &DLoc,
787 /// Emit an optimization analysis remark related to messages about
788 /// floating-point non-commutativity. \p PassName is the name of the pass
789 /// emitting the message. If -Rpass-analysis= is given and \p PassName matches
790 /// the regular expression in -Rpass, then the remark will be emitted. \p Fn is
791 /// the function triggering the remark, \p DLoc is the debug location where the
792 /// diagnostic is generated. \p Msg is the message string to use.
793 void emitOptimizationRemarkAnalysisFPCommute(LLVMContext &Ctx,
794 const char *PassName,
796 const DebugLoc &DLoc,
799 /// Emit an optimization analysis remark related to messages about
800 /// pointer aliasing. \p PassName is the name of the pass emitting the message.
801 /// If -Rpass-analysis= is given and \p PassName matches the regular expression
802 /// in -Rpass, then the remark will be emitted. \p Fn is the function triggering
803 /// the remark, \p DLoc is the debug location where the diagnostic is generated.
804 /// \p Msg is the message string to use.
805 void emitOptimizationRemarkAnalysisAliasing(LLVMContext &Ctx,
806 const char *PassName,
808 const DebugLoc &DLoc,
811 /// Diagnostic information for optimization failures.
812 class DiagnosticInfoOptimizationFailure
813 : public DiagnosticInfoOptimizationBase {
815 /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
816 /// the location information to use in the diagnostic. If line table
817 /// information is available, the diagnostic will include the source code
818 /// location. \p Msg is the message to show. Note that this class does not
819 /// copy this message, so this reference must be valid for the whole life time
820 /// of the diagnostic.
821 DiagnosticInfoOptimizationFailure(const Function &Fn, const DebugLoc &DLoc,
823 : DiagnosticInfoOptimizationBase(DK_OptimizationFailure, DS_Warning,
824 nullptr, Fn, DLoc, Msg) {}
826 static bool classof(const DiagnosticInfo *DI) {
827 return DI->getKind() == DK_OptimizationFailure;
830 /// \see DiagnosticInfoOptimizationBase::isEnabled.
831 bool isEnabled() const override;
834 /// Diagnostic information for unsupported feature in backend.
835 class DiagnosticInfoUnsupported
836 : public DiagnosticInfoWithDebugLocBase {
841 /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
842 /// the location information to use in the diagnostic. If line table
843 /// information is available, the diagnostic will include the source code
844 /// location. \p Msg is the message to show. Note that this class does not
845 /// copy this message, so this reference must be valid for the whole life time
846 /// of the diagnostic.
847 DiagnosticInfoUnsupported(const Function &Fn, const Twine &Msg,
848 DebugLoc DLoc = DebugLoc(),
849 DiagnosticSeverity Severity = DS_Error)
850 : DiagnosticInfoWithDebugLocBase(DK_Unsupported, Severity, Fn, DLoc),
853 static bool classof(const DiagnosticInfo *DI) {
854 return DI->getKind() == DK_Unsupported;
857 const Twine &getMessage() const { return Msg; }
859 void print(DiagnosticPrinter &DP) const override;
862 /// Emit a warning when loop vectorization is specified but fails. \p Fn is the
863 /// function triggering the warning, \p DLoc is the debug location where the
864 /// diagnostic is generated. \p Msg is the message string to use.
865 void emitLoopVectorizeWarning(LLVMContext &Ctx, const Function &Fn,
866 const DebugLoc &DLoc, const Twine &Msg);
868 /// Emit a warning when loop interleaving is specified but fails. \p Fn is the
869 /// function triggering the warning, \p DLoc is the debug location where the
870 /// diagnostic is generated. \p Msg is the message string to use.
871 void emitLoopInterleaveWarning(LLVMContext &Ctx, const Function &Fn,
872 const DebugLoc &DLoc, const Twine &Msg);
874 } // end namespace llvm
876 #endif // LLVM_IR_DIAGNOSTICINFO_H