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/StringRef.h"
21 #include "llvm/ADT/Twine.h"
22 #include "llvm/IR/DebugLoc.h"
23 #include "llvm/Support/CBindingWrapping.h"
29 // Forward declarations.
30 class DiagnosticPrinter;
37 /// \brief Defines the different supported severity of a diagnostic.
38 enum DiagnosticSeverity : char {
42 // A note attaches additional information to one of the previous diagnostic
47 /// \brief Defines the different supported kind of a diagnostic.
48 /// This enum should be extended with a new ID for each added concrete subclass.
55 DK_DebugMetadataVersion,
56 DK_DebugMetadataInvalid,
59 DK_OptimizationRemark,
60 DK_OptimizationRemarkMissed,
61 DK_OptimizationRemarkAnalysis,
62 DK_OptimizationRemarkAnalysisFPCommute,
63 DK_OptimizationRemarkAnalysisAliasing,
64 DK_OptimizationFailure,
65 DK_FirstRemark = DK_OptimizationRemark,
66 DK_LastRemark = DK_OptimizationFailure,
73 /// \brief Get the next available kind ID for a plugin diagnostic.
74 /// Each time this function is called, it returns a different number.
75 /// Therefore, a plugin that wants to "identify" its own classes
76 /// with a dynamic identifier, just have to use this method to get a new ID
77 /// and assign it to each of its classes.
78 /// The returned ID will be greater than or equal to DK_FirstPluginKind.
79 /// Thus, the plugin identifiers will not conflict with the
80 /// DiagnosticKind values.
81 int getNextAvailablePluginDiagnosticKind();
83 /// \brief This is the base abstract class for diagnostic reporting in
85 /// The print method must be overloaded by the subclasses to print a
86 /// user-friendly message in the client of the backend (let us call it a
88 class DiagnosticInfo {
90 /// Kind defines the kind of report this is about.
91 const /* DiagnosticKind */ int Kind;
92 /// Severity gives the severity of the diagnostic.
93 const DiagnosticSeverity Severity;
96 DiagnosticInfo(/* DiagnosticKind */ int Kind, DiagnosticSeverity Severity)
97 : Kind(Kind), Severity(Severity) {}
99 virtual ~DiagnosticInfo() {}
101 /* DiagnosticKind */ int getKind() const { return Kind; }
102 DiagnosticSeverity getSeverity() const { return Severity; }
104 /// Print using the given \p DP a user-friendly message.
105 /// This is the default message that will be printed to the user.
106 /// It is used when the frontend does not directly take advantage
107 /// of the information contained in fields of the subclasses.
108 /// The printed message must not end with '.' nor start with a severity
110 virtual void print(DiagnosticPrinter &DP) const = 0;
113 typedef std::function<void(const DiagnosticInfo &)> DiagnosticHandlerFunction;
115 /// Diagnostic information for inline asm reporting.
116 /// This is basically a message and an optional location.
117 class DiagnosticInfoInlineAsm : public DiagnosticInfo {
119 /// Optional line information. 0 if not set.
121 /// Message to be reported.
123 /// Optional origin of the problem.
124 const Instruction *Instr;
127 /// \p MsgStr is the message to be reported to the frontend.
128 /// This class does not copy \p MsgStr, therefore the reference must be valid
129 /// for the whole life time of the Diagnostic.
130 DiagnosticInfoInlineAsm(const Twine &MsgStr,
131 DiagnosticSeverity Severity = DS_Error)
132 : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr),
135 /// \p LocCookie if non-zero gives the line number for this report.
136 /// \p MsgStr gives the message.
137 /// This class does not copy \p MsgStr, therefore the reference must be valid
138 /// for the whole life time of the Diagnostic.
139 DiagnosticInfoInlineAsm(unsigned LocCookie, const Twine &MsgStr,
140 DiagnosticSeverity Severity = DS_Error)
141 : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie),
142 MsgStr(MsgStr), Instr(nullptr) {}
144 /// \p Instr gives the original instruction that triggered the diagnostic.
145 /// \p MsgStr gives the message.
146 /// This class does not copy \p MsgStr, therefore the reference must be valid
147 /// for the whole life time of the Diagnostic.
149 DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr,
150 DiagnosticSeverity Severity = DS_Error);
152 unsigned getLocCookie() const { return LocCookie; }
153 const Twine &getMsgStr() const { return MsgStr; }
154 const Instruction *getInstruction() const { return Instr; }
156 /// \see DiagnosticInfo::print.
157 void print(DiagnosticPrinter &DP) const override;
159 static bool classof(const DiagnosticInfo *DI) {
160 return DI->getKind() == DK_InlineAsm;
164 /// Diagnostic information for stack size etc. reporting.
165 /// This is basically a function and a size.
166 class DiagnosticInfoResourceLimit : public DiagnosticInfo {
168 /// The function that is concerned by this resource limit diagnostic.
171 /// Description of the resource type (e.g. stack size)
172 const char *ResourceName;
174 /// The computed size usage
175 uint64_t ResourceSize;
178 uint64_t ResourceLimit;
181 /// \p The function that is concerned by this stack size diagnostic.
182 /// \p The computed stack size.
183 DiagnosticInfoResourceLimit(const Function &Fn,
184 const char *ResourceName,
185 uint64_t ResourceSize,
186 DiagnosticSeverity Severity = DS_Warning,
187 DiagnosticKind Kind = DK_ResourceLimit,
188 uint64_t ResourceLimit = 0)
189 : DiagnosticInfo(Kind, Severity),
191 ResourceName(ResourceName),
192 ResourceSize(ResourceSize),
193 ResourceLimit(ResourceLimit) {}
195 const Function &getFunction() const { return Fn; }
196 const char *getResourceName() const { return ResourceName; }
197 uint64_t getResourceSize() const { return ResourceSize; }
198 uint64_t getResourceLimit() const { return ResourceLimit; }
200 /// \see DiagnosticInfo::print.
201 void print(DiagnosticPrinter &DP) const override;
203 static bool classof(const DiagnosticInfo *DI) {
204 return DI->getKind() == DK_ResourceLimit ||
205 DI->getKind() == DK_StackSize;
209 class DiagnosticInfoStackSize : public DiagnosticInfoResourceLimit {
211 DiagnosticInfoStackSize(const Function &Fn,
213 DiagnosticSeverity Severity = DS_Warning,
214 uint64_t StackLimit = 0)
215 : DiagnosticInfoResourceLimit(Fn, "stack size", StackSize,
216 Severity, DK_StackSize, StackLimit) {}
218 uint64_t getStackSize() const { return getResourceSize(); }
219 uint64_t getStackLimit() const { return getResourceLimit(); }
221 static bool classof(const DiagnosticInfo *DI) {
222 return DI->getKind() == DK_StackSize;
226 /// Diagnostic information for debug metadata version reporting.
227 /// This is basically a module and a version.
228 class DiagnosticInfoDebugMetadataVersion : public DiagnosticInfo {
230 /// The module that is concerned by this debug metadata version diagnostic.
232 /// The actual metadata version.
233 unsigned MetadataVersion;
236 /// \p The module that is concerned by this debug metadata version diagnostic.
237 /// \p The actual metadata version.
238 DiagnosticInfoDebugMetadataVersion(const Module &M, unsigned MetadataVersion,
239 DiagnosticSeverity Severity = DS_Warning)
240 : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M),
241 MetadataVersion(MetadataVersion) {}
243 const Module &getModule() const { return M; }
244 unsigned getMetadataVersion() const { return MetadataVersion; }
246 /// \see DiagnosticInfo::print.
247 void print(DiagnosticPrinter &DP) const override;
249 static bool classof(const DiagnosticInfo *DI) {
250 return DI->getKind() == DK_DebugMetadataVersion;
254 /// Diagnostic information for stripping invalid debug metadata.
255 class DiagnosticInfoIgnoringInvalidDebugMetadata : public DiagnosticInfo {
257 /// The module that is concerned by this debug metadata version diagnostic.
261 /// \p The module that is concerned by this debug metadata version diagnostic.
262 DiagnosticInfoIgnoringInvalidDebugMetadata(
263 const Module &M, DiagnosticSeverity Severity = DS_Warning)
264 : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M) {}
266 const Module &getModule() const { return M; }
268 /// \see DiagnosticInfo::print.
269 void print(DiagnosticPrinter &DP) const override;
271 static bool classof(const DiagnosticInfo *DI) {
272 return DI->getKind() == DK_DebugMetadataInvalid;
277 /// Diagnostic information for the sample profiler.
278 class DiagnosticInfoSampleProfile : public DiagnosticInfo {
280 DiagnosticInfoSampleProfile(StringRef FileName, unsigned LineNum,
282 DiagnosticSeverity Severity = DS_Error)
283 : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
284 LineNum(LineNum), Msg(Msg) {}
285 DiagnosticInfoSampleProfile(StringRef FileName, const Twine &Msg,
286 DiagnosticSeverity Severity = DS_Error)
287 : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
288 LineNum(0), Msg(Msg) {}
289 DiagnosticInfoSampleProfile(const Twine &Msg,
290 DiagnosticSeverity Severity = DS_Error)
291 : DiagnosticInfo(DK_SampleProfile, Severity), LineNum(0), Msg(Msg) {}
293 /// \see DiagnosticInfo::print.
294 void print(DiagnosticPrinter &DP) const override;
296 static bool classof(const DiagnosticInfo *DI) {
297 return DI->getKind() == DK_SampleProfile;
300 StringRef getFileName() const { return FileName; }
301 unsigned getLineNum() const { return LineNum; }
302 const Twine &getMsg() const { return Msg; }
305 /// Name of the input file associated with this diagnostic.
308 /// Line number where the diagnostic occurred. If 0, no line number will
309 /// be emitted in the message.
312 /// Message to report.
316 /// Diagnostic information for the PGO profiler.
317 class DiagnosticInfoPGOProfile : public DiagnosticInfo {
319 DiagnosticInfoPGOProfile(const char *FileName, const Twine &Msg,
320 DiagnosticSeverity Severity = DS_Error)
321 : DiagnosticInfo(DK_PGOProfile, Severity), FileName(FileName), Msg(Msg) {}
323 /// \see DiagnosticInfo::print.
324 void print(DiagnosticPrinter &DP) const override;
326 static bool classof(const DiagnosticInfo *DI) {
327 return DI->getKind() == DK_PGOProfile;
330 const char *getFileName() const { return FileName; }
331 const Twine &getMsg() const { return Msg; }
334 /// Name of the input file associated with this diagnostic.
335 const char *FileName;
337 /// Message to report.
341 /// Common features for diagnostics with an associated DebugLoc
342 class DiagnosticInfoWithDebugLocBase : public DiagnosticInfo {
344 /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
345 /// the location information to use in the diagnostic.
346 DiagnosticInfoWithDebugLocBase(enum DiagnosticKind Kind,
347 enum DiagnosticSeverity Severity,
349 const DebugLoc &DLoc)
350 : DiagnosticInfo(Kind, Severity), Fn(Fn), DLoc(DLoc) {}
352 /// Return true if location information is available for this diagnostic.
353 bool isLocationAvailable() const;
355 /// Return a string with the location information for this diagnostic
356 /// in the format "file:line:col". If location information is not available,
357 /// it returns "<unknown>:0:0".
358 const std::string getLocationStr() const;
360 /// Return location information for this diagnostic in three parts:
361 /// the source file name, line number and column.
362 void getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const;
364 const Function &getFunction() const { return Fn; }
365 const DebugLoc &getDebugLoc() const { return DLoc; }
368 /// Function where this diagnostic is triggered.
371 /// Debug location where this diagnostic is triggered.
375 /// Common features for diagnostics dealing with optimization remarks.
376 class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithDebugLocBase {
378 /// \p PassName is the name of the pass emitting this diagnostic.
379 /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
380 /// the location information to use in the diagnostic. If line table
381 /// information is available, the diagnostic will include the source code
382 /// location. \p Msg is the message to show. Note that this class does not
383 /// copy this message, so this reference must be valid for the whole life time
384 /// of the diagnostic.
385 DiagnosticInfoOptimizationBase(enum DiagnosticKind Kind,
386 enum DiagnosticSeverity Severity,
387 const char *PassName, const Function &Fn,
388 const DebugLoc &DLoc, const Twine &Msg,
389 Optional<uint64_t> Hotness = None)
390 : DiagnosticInfoWithDebugLocBase(Kind, Severity, Fn, DLoc),
391 PassName(PassName), Msg(Msg), Hotness(Hotness) {}
393 /// \see DiagnosticInfo::print.
394 void print(DiagnosticPrinter &DP) const override;
396 /// Return true if this optimization remark is enabled by one of
397 /// of the LLVM command line flags (-pass-remarks, -pass-remarks-missed,
398 /// or -pass-remarks-analysis). Note that this only handles the LLVM
399 /// flags. We cannot access Clang flags from here (they are handled
400 /// in BackendConsumer::OptimizationRemarkHandler).
401 virtual bool isEnabled() const = 0;
403 const char *getPassName() const { return PassName; }
404 const Twine &getMsg() const { return Msg; }
405 Optional<uint64_t> getHotness() const { return Hotness; }
407 static bool classof(const DiagnosticInfo *DI) {
408 return DI->getKind() >= DK_FirstRemark &&
409 DI->getKind() <= DK_LastRemark;
413 /// Name of the pass that triggers this report. If this matches the
414 /// regular expression given in -Rpass=regexp, then the remark will
416 const char *PassName;
418 /// Message to report.
421 /// If profile information is available, this is the number of times the
422 /// corresponding code was executed in a profile instrumentation run.
423 Optional<uint64_t> Hotness;
426 /// Diagnostic information for applied optimization remarks.
427 class DiagnosticInfoOptimizationRemark : public DiagnosticInfoOptimizationBase {
429 /// \p PassName is the name of the pass emitting this diagnostic. If
430 /// this name matches the regular expression given in -Rpass=, then the
431 /// diagnostic will be emitted. \p Fn is the function where the diagnostic
432 /// is being emitted. \p DLoc is the location information to use in the
433 /// diagnostic. If line table information is available, the diagnostic
434 /// will include the source code location. \p Msg is the message to show.
435 /// Note that this class does not copy this message, so this reference
436 /// must be valid for the whole life time of the diagnostic.
437 DiagnosticInfoOptimizationRemark(const char *PassName, const Function &Fn,
438 const DebugLoc &DLoc, const Twine &Msg,
439 Optional<uint64_t> Hotness = None)
440 : DiagnosticInfoOptimizationBase(DK_OptimizationRemark, DS_Remark,
441 PassName, Fn, DLoc, Msg, Hotness) {}
443 static bool classof(const DiagnosticInfo *DI) {
444 return DI->getKind() == DK_OptimizationRemark;
447 /// \see DiagnosticInfoOptimizationBase::isEnabled.
448 bool isEnabled() const override;
451 /// Diagnostic information for missed-optimization remarks.
452 class DiagnosticInfoOptimizationRemarkMissed
453 : public DiagnosticInfoOptimizationBase {
455 /// \p PassName is the name of the pass emitting this diagnostic. If
456 /// this name matches the regular expression given in -Rpass-missed=, then the
457 /// diagnostic will be emitted. \p Fn is the function where the diagnostic
458 /// is being emitted. \p DLoc is the location information to use in the
459 /// diagnostic. If line table information is available, the diagnostic
460 /// will include the source code location. \p Msg is the message to show.
461 /// Note that this class does not copy this message, so this reference
462 /// must be valid for the whole life time of the diagnostic.
463 DiagnosticInfoOptimizationRemarkMissed(const char *PassName,
465 const DebugLoc &DLoc, const Twine &Msg,
466 Optional<uint64_t> Hotness = None)
467 : DiagnosticInfoOptimizationBase(DK_OptimizationRemarkMissed, DS_Remark,
468 PassName, Fn, DLoc, Msg, Hotness) {}
470 static bool classof(const DiagnosticInfo *DI) {
471 return DI->getKind() == DK_OptimizationRemarkMissed;
474 /// \see DiagnosticInfoOptimizationBase::isEnabled.
475 bool isEnabled() const override;
478 /// Diagnostic information for optimization analysis remarks.
479 class DiagnosticInfoOptimizationRemarkAnalysis
480 : public DiagnosticInfoOptimizationBase {
482 /// \p PassName is the name of the pass emitting this diagnostic. If
483 /// this name matches the regular expression given in -Rpass-analysis=, then
484 /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
485 /// is being emitted. \p DLoc is the location information to use in the
486 /// diagnostic. If line table information is available, the diagnostic will
487 /// include the source code location. \p Msg is the message to show. Note that
488 /// this class does not copy this message, so this reference must be valid for
489 /// the whole life time of the diagnostic.
490 DiagnosticInfoOptimizationRemarkAnalysis(const char *PassName,
492 const DebugLoc &DLoc,
494 Optional<uint64_t> Hotness = None)
495 : DiagnosticInfoOptimizationBase(DK_OptimizationRemarkAnalysis, DS_Remark,
496 PassName, Fn, DLoc, Msg, Hotness) {}
498 static bool classof(const DiagnosticInfo *DI) {
499 return DI->getKind() == DK_OptimizationRemarkAnalysis;
502 /// \see DiagnosticInfoOptimizationBase::isEnabled.
503 bool isEnabled() const override;
505 static const char *AlwaysPrint;
507 bool shouldAlwaysPrint() const { return getPassName() == AlwaysPrint; }
510 DiagnosticInfoOptimizationRemarkAnalysis(
511 enum DiagnosticKind Kind, const char *PassName, const Function &Fn,
512 const DebugLoc &DLoc, const Twine &Msg, Optional<uint64_t> Hotness)
513 : DiagnosticInfoOptimizationBase(Kind, DS_Remark, PassName, Fn, DLoc, Msg,
517 /// Diagnostic information for optimization analysis remarks related to
518 /// floating-point non-commutativity.
519 class DiagnosticInfoOptimizationRemarkAnalysisFPCommute
520 : public DiagnosticInfoOptimizationRemarkAnalysis {
522 /// \p PassName is the name of the pass emitting this diagnostic. If
523 /// this name matches the regular expression given in -Rpass-analysis=, then
524 /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
525 /// is being emitted. \p DLoc is the location information to use in the
526 /// diagnostic. If line table information is available, the diagnostic will
527 /// include the source code location. \p Msg is the message to show. The
528 /// front-end will append its own message related to options that address
529 /// floating-point non-commutativity. Note that this class does not copy this
530 /// message, so this reference must be valid for the whole life time of the
532 DiagnosticInfoOptimizationRemarkAnalysisFPCommute(
533 const char *PassName, const Function &Fn, const DebugLoc &DLoc,
534 const Twine &Msg, Optional<uint64_t> Hotness = None)
535 : DiagnosticInfoOptimizationRemarkAnalysis(
536 DK_OptimizationRemarkAnalysisFPCommute, PassName, Fn, DLoc, Msg,
539 static bool classof(const DiagnosticInfo *DI) {
540 return DI->getKind() == DK_OptimizationRemarkAnalysisFPCommute;
544 /// Diagnostic information for optimization analysis remarks related to
545 /// pointer aliasing.
546 class DiagnosticInfoOptimizationRemarkAnalysisAliasing
547 : public DiagnosticInfoOptimizationRemarkAnalysis {
549 /// \p PassName is the name of the pass emitting this diagnostic. If
550 /// this name matches the regular expression given in -Rpass-analysis=, then
551 /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
552 /// is being emitted. \p DLoc is the location information to use in the
553 /// diagnostic. If line table information is available, the diagnostic will
554 /// include the source code location. \p Msg is the message to show. The
555 /// front-end will append its own message related to options that address
556 /// pointer aliasing legality. Note that this class does not copy this
557 /// message, so this reference must be valid for the whole life time of the
559 DiagnosticInfoOptimizationRemarkAnalysisAliasing(
560 const char *PassName, const Function &Fn, const DebugLoc &DLoc,
561 const Twine &Msg, Optional<uint64_t> Hotness = None)
562 : DiagnosticInfoOptimizationRemarkAnalysis(
563 DK_OptimizationRemarkAnalysisAliasing, PassName, Fn, DLoc, Msg,
566 static bool classof(const DiagnosticInfo *DI) {
567 return DI->getKind() == DK_OptimizationRemarkAnalysisAliasing;
571 /// Diagnostic information for machine IR parser.
572 class DiagnosticInfoMIRParser : public DiagnosticInfo {
573 const SMDiagnostic &Diagnostic;
576 DiagnosticInfoMIRParser(DiagnosticSeverity Severity,
577 const SMDiagnostic &Diagnostic)
578 : DiagnosticInfo(DK_MIRParser, Severity), Diagnostic(Diagnostic) {}
580 const SMDiagnostic &getDiagnostic() const { return Diagnostic; }
582 void print(DiagnosticPrinter &DP) const override;
584 static bool classof(const DiagnosticInfo *DI) {
585 return DI->getKind() == DK_MIRParser;
589 /// Diagnostic information for ISel fallback path.
590 class DiagnosticInfoISelFallback : public DiagnosticInfo {
591 /// The function that is concerned by this diagnostic.
595 DiagnosticInfoISelFallback(const Function &Fn,
596 DiagnosticSeverity Severity = DS_Warning)
597 : DiagnosticInfo(DK_ISelFallback, Severity), Fn(Fn) {}
599 const Function &getFunction() const { return Fn; }
601 void print(DiagnosticPrinter &DP) const override;
603 static bool classof(const DiagnosticInfo *DI) {
604 return DI->getKind() == DK_ISelFallback;
608 // Create wrappers for C Binding types (see CBindingWrapping.h).
609 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DiagnosticInfo, LLVMDiagnosticInfoRef)
611 /// Emit an optimization-applied message. \p PassName is the name of the pass
612 /// emitting the message. If -Rpass= is given and \p PassName matches the
613 /// regular expression in -Rpass, then the remark will be emitted. \p Fn is
614 /// the function triggering the remark, \p DLoc is the debug location where
615 /// the diagnostic is generated. \p Msg is the message string to use.
616 void emitOptimizationRemark(LLVMContext &Ctx, const char *PassName,
617 const Function &Fn, const DebugLoc &DLoc,
620 /// Emit an optimization-missed message. \p PassName is the name of the
621 /// pass emitting the message. If -Rpass-missed= is given and \p PassName
622 /// matches the regular expression in -Rpass, then the remark will be
623 /// emitted. \p Fn is the function triggering the remark, \p DLoc is the
624 /// debug location where the diagnostic is generated. \p Msg is the
625 /// message string to use.
626 void emitOptimizationRemarkMissed(LLVMContext &Ctx, const char *PassName,
627 const Function &Fn, const DebugLoc &DLoc,
630 /// Emit an optimization analysis remark message. \p PassName is the name of
631 /// the pass emitting the message. If -Rpass-analysis= is given and \p
632 /// PassName matches the regular expression in -Rpass, then the remark will be
633 /// emitted. \p Fn is the function triggering the remark, \p DLoc is the debug
634 /// location where the diagnostic is generated. \p Msg is the message string
636 void emitOptimizationRemarkAnalysis(LLVMContext &Ctx, const char *PassName,
637 const Function &Fn, const DebugLoc &DLoc,
640 /// Emit an optimization analysis remark related to messages about
641 /// floating-point non-commutativity. \p PassName is the name of the pass
642 /// emitting the message. If -Rpass-analysis= is given and \p PassName matches
643 /// the regular expression in -Rpass, then the remark will be emitted. \p Fn is
644 /// the function triggering the remark, \p DLoc is the debug location where the
645 /// diagnostic is generated. \p Msg is the message string to use.
646 void emitOptimizationRemarkAnalysisFPCommute(LLVMContext &Ctx,
647 const char *PassName,
649 const DebugLoc &DLoc,
652 /// Emit an optimization analysis remark related to messages about
653 /// pointer aliasing. \p PassName is the name of the pass emitting the message.
654 /// If -Rpass-analysis= is given and \p PassName matches the regular expression
655 /// in -Rpass, then the remark will be emitted. \p Fn is the function triggering
656 /// the remark, \p DLoc is the debug location where the diagnostic is generated.
657 /// \p Msg is the message string to use.
658 void emitOptimizationRemarkAnalysisAliasing(LLVMContext &Ctx,
659 const char *PassName,
661 const DebugLoc &DLoc,
664 /// Diagnostic information for optimization failures.
665 class DiagnosticInfoOptimizationFailure
666 : public DiagnosticInfoOptimizationBase {
668 /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
669 /// the location information to use in the diagnostic. If line table
670 /// information is available, the diagnostic will include the source code
671 /// location. \p Msg is the message to show. Note that this class does not
672 /// copy this message, so this reference must be valid for the whole life time
673 /// of the diagnostic.
674 DiagnosticInfoOptimizationFailure(const Function &Fn, const DebugLoc &DLoc,
676 : DiagnosticInfoOptimizationBase(DK_OptimizationFailure, DS_Warning,
677 nullptr, Fn, DLoc, Msg) {}
679 static bool classof(const DiagnosticInfo *DI) {
680 return DI->getKind() == DK_OptimizationFailure;
683 /// \see DiagnosticInfoOptimizationBase::isEnabled.
684 bool isEnabled() const override;
687 /// Diagnostic information for unsupported feature in backend.
688 class DiagnosticInfoUnsupported
689 : public DiagnosticInfoWithDebugLocBase {
694 /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
695 /// the location information to use in the diagnostic. If line table
696 /// information is available, the diagnostic will include the source code
697 /// location. \p Msg is the message to show. Note that this class does not
698 /// copy this message, so this reference must be valid for the whole life time
699 /// of the diagnostic.
700 DiagnosticInfoUnsupported(const Function &Fn, const Twine &Msg,
701 DebugLoc DLoc = DebugLoc(),
702 DiagnosticSeverity Severity = DS_Error)
703 : DiagnosticInfoWithDebugLocBase(DK_Unsupported, Severity, Fn, DLoc),
706 static bool classof(const DiagnosticInfo *DI) {
707 return DI->getKind() == DK_Unsupported;
710 const Twine &getMessage() const { return Msg; }
712 void print(DiagnosticPrinter &DP) const override;
715 /// Emit a warning when loop vectorization is specified but fails. \p Fn is the
716 /// function triggering the warning, \p DLoc is the debug location where the
717 /// diagnostic is generated. \p Msg is the message string to use.
718 void emitLoopVectorizeWarning(LLVMContext &Ctx, const Function &Fn,
719 const DebugLoc &DLoc, const Twine &Msg);
721 /// Emit a warning when loop interleaving is specified but fails. \p Fn is the
722 /// function triggering the warning, \p DLoc is the debug location where the
723 /// diagnostic is generated. \p Msg is the message string to use.
724 void emitLoopInterleaveWarning(LLVMContext &Ctx, const Function &Fn,
725 const DebugLoc &DLoc, const Twine &Msg);
727 } // end namespace llvm
729 #endif // LLVM_IR_DIAGNOSTICINFO_H