OSDN Git Service

[llc] New diagnostic handler
[android-x86/external-llvm.git] / include / llvm / IR / DiagnosticInfo.h
1 //===- llvm/Support/DiagnosticInfo.h - Diagnostic Declaration ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the different classes involved in low level diagnostics.
11 //
12 // Diagnostics reporting is still done as part of the LLVMContext.
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_IR_DIAGNOSTICINFO_H
16 #define LLVM_IR_DIAGNOSTICINFO_H
17
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/IR/DebugLoc.h"
21 #include "llvm/Support/CBindingWrapping.h"
22 #include "llvm-c/Types.h"
23 #include <functional>
24 #include <string>
25
26 namespace llvm {
27
28 // Forward declarations.
29 class DiagnosticPrinter;
30 class Function;
31 class Instruction;
32 class LLVMContext;
33 class Module;
34 class SMDiagnostic;
35
36 /// \brief Defines the different supported severity of a diagnostic.
37 enum DiagnosticSeverity : char {
38   DS_Error,
39   DS_Warning,
40   DS_Remark,
41   // A note attaches additional information to one of the previous diagnostic
42   // types.
43   DS_Note
44 };
45
46 /// \brief Defines the different supported kind of a diagnostic.
47 /// This enum should be extended with a new ID for each added concrete subclass.
48 enum DiagnosticKind {
49   DK_Bitcode,
50   DK_InlineAsm,
51   DK_StackSize,
52   DK_Linker,
53   DK_DebugMetadataVersion,
54   DK_DebugMetadataInvalid,
55   DK_SampleProfile,
56   DK_OptimizationRemark,
57   DK_OptimizationRemarkMissed,
58   DK_OptimizationRemarkAnalysis,
59   DK_OptimizationRemarkAnalysisFPCommute,
60   DK_OptimizationRemarkAnalysisAliasing,
61   DK_OptimizationFailure,
62   DK_FirstRemark = DK_OptimizationRemark,
63   DK_LastRemark = DK_OptimizationFailure,
64   DK_MIRParser,
65   DK_PGOProfile,
66   DK_Unsupported,
67   DK_FirstPluginKind
68 };
69
70 /// \brief Get the next available kind ID for a plugin diagnostic.
71 /// Each time this function is called, it returns a different number.
72 /// Therefore, a plugin that wants to "identify" its own classes
73 /// with a dynamic identifier, just have to use this method to get a new ID
74 /// and assign it to each of its classes.
75 /// The returned ID will be greater than or equal to DK_FirstPluginKind.
76 /// Thus, the plugin identifiers will not conflict with the
77 /// DiagnosticKind values.
78 int getNextAvailablePluginDiagnosticKind();
79
80 /// \brief This is the base abstract class for diagnostic reporting in
81 /// the backend.
82 /// The print method must be overloaded by the subclasses to print a
83 /// user-friendly message in the client of the backend (let us call it a
84 /// frontend).
85 class DiagnosticInfo {
86 private:
87   /// Kind defines the kind of report this is about.
88   const /* DiagnosticKind */ int Kind;
89   /// Severity gives the severity of the diagnostic.
90   const DiagnosticSeverity Severity;
91
92 public:
93   DiagnosticInfo(/* DiagnosticKind */ int Kind, DiagnosticSeverity Severity)
94       : Kind(Kind), Severity(Severity) {}
95
96   virtual ~DiagnosticInfo() {}
97
98   /* DiagnosticKind */ int getKind() const { return Kind; }
99   DiagnosticSeverity getSeverity() const { return Severity; }
100
101   /// Print using the given \p DP a user-friendly message.
102   /// This is the default message that will be printed to the user.
103   /// It is used when the frontend does not directly take advantage
104   /// of the information contained in fields of the subclasses.
105   /// The printed message must not end with '.' nor start with a severity
106   /// keyword.
107   virtual void print(DiagnosticPrinter &DP) const = 0;
108
109   static const char *AlwaysPrint;
110 };
111
112 typedef std::function<void(const DiagnosticInfo &)> DiagnosticHandlerFunction;
113
114 /// Diagnostic information for inline asm reporting.
115 /// This is basically a message and an optional location.
116 class DiagnosticInfoInlineAsm : public DiagnosticInfo {
117 private:
118   /// Optional line information. 0 if not set.
119   unsigned LocCookie;
120   /// Message to be reported.
121   const Twine &MsgStr;
122   /// Optional origin of the problem.
123   const Instruction *Instr;
124
125 public:
126   /// \p MsgStr is the message to be reported to the frontend.
127   /// This class does not copy \p MsgStr, therefore the reference must be valid
128   /// for the whole life time of the Diagnostic.
129   DiagnosticInfoInlineAsm(const Twine &MsgStr,
130                           DiagnosticSeverity Severity = DS_Error)
131       : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr),
132         Instr(nullptr) {}
133
134   /// \p LocCookie if non-zero gives the line number for this report.
135   /// \p MsgStr gives the message.
136   /// This class does not copy \p MsgStr, therefore the reference must be valid
137   /// for the whole life time of the Diagnostic.
138   DiagnosticInfoInlineAsm(unsigned LocCookie, const Twine &MsgStr,
139                           DiagnosticSeverity Severity = DS_Error)
140       : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie),
141         MsgStr(MsgStr), Instr(nullptr) {}
142
143   /// \p Instr gives the original instruction that triggered the diagnostic.
144   /// \p MsgStr gives the message.
145   /// This class does not copy \p MsgStr, therefore the reference must be valid
146   /// for the whole life time of the Diagnostic.
147   /// Same for \p I.
148   DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr,
149                           DiagnosticSeverity Severity = DS_Error);
150
151   unsigned getLocCookie() const { return LocCookie; }
152   const Twine &getMsgStr() const { return MsgStr; }
153   const Instruction *getInstruction() const { return Instr; }
154
155   /// \see DiagnosticInfo::print.
156   void print(DiagnosticPrinter &DP) const override;
157
158   static bool classof(const DiagnosticInfo *DI) {
159     return DI->getKind() == DK_InlineAsm;
160   }
161 };
162
163 /// Diagnostic information for stack size reporting.
164 /// This is basically a function and a size.
165 class DiagnosticInfoStackSize : public DiagnosticInfo {
166 private:
167   /// The function that is concerned by this stack size diagnostic.
168   const Function &Fn;
169   /// The computed stack size.
170   unsigned StackSize;
171
172 public:
173   /// \p The function that is concerned by this stack size diagnostic.
174   /// \p The computed stack size.
175   DiagnosticInfoStackSize(const Function &Fn, unsigned StackSize,
176                           DiagnosticSeverity Severity = DS_Warning)
177       : DiagnosticInfo(DK_StackSize, Severity), Fn(Fn), StackSize(StackSize) {}
178
179   const Function &getFunction() const { return Fn; }
180   unsigned getStackSize() const { return StackSize; }
181
182   /// \see DiagnosticInfo::print.
183   void print(DiagnosticPrinter &DP) const override;
184
185   static bool classof(const DiagnosticInfo *DI) {
186     return DI->getKind() == DK_StackSize;
187   }
188 };
189
190 /// Diagnostic information for debug metadata version reporting.
191 /// This is basically a module and a version.
192 class DiagnosticInfoDebugMetadataVersion : public DiagnosticInfo {
193 private:
194   /// The module that is concerned by this debug metadata version diagnostic.
195   const Module &M;
196   /// The actual metadata version.
197   unsigned MetadataVersion;
198
199 public:
200   /// \p The module that is concerned by this debug metadata version diagnostic.
201   /// \p The actual metadata version.
202   DiagnosticInfoDebugMetadataVersion(const Module &M, unsigned MetadataVersion,
203                           DiagnosticSeverity Severity = DS_Warning)
204       : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M),
205         MetadataVersion(MetadataVersion) {}
206
207   const Module &getModule() const { return M; }
208   unsigned getMetadataVersion() const { return MetadataVersion; }
209
210   /// \see DiagnosticInfo::print.
211   void print(DiagnosticPrinter &DP) const override;
212
213   static bool classof(const DiagnosticInfo *DI) {
214     return DI->getKind() == DK_DebugMetadataVersion;
215   }
216 };
217
218 /// Diagnostic information for stripping invalid debug metadata.
219 class DiagnosticInfoIgnoringInvalidDebugMetadata : public DiagnosticInfo {
220 private:
221   /// The module that is concerned by this debug metadata version diagnostic.
222   const Module &M;
223
224 public:
225   /// \p The module that is concerned by this debug metadata version diagnostic.
226   DiagnosticInfoIgnoringInvalidDebugMetadata(
227       const Module &M, DiagnosticSeverity Severity = DS_Warning)
228       : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M) {}
229
230   const Module &getModule() const { return M; }
231
232   /// \see DiagnosticInfo::print.
233   void print(DiagnosticPrinter &DP) const override;
234
235   static bool classof(const DiagnosticInfo *DI) {
236     return DI->getKind() == DK_DebugMetadataInvalid;
237   }
238 };
239
240
241 /// Diagnostic information for the sample profiler.
242 class DiagnosticInfoSampleProfile : public DiagnosticInfo {
243 public:
244   DiagnosticInfoSampleProfile(StringRef FileName, unsigned LineNum,
245                               const Twine &Msg,
246                               DiagnosticSeverity Severity = DS_Error)
247       : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
248         LineNum(LineNum), Msg(Msg) {}
249   DiagnosticInfoSampleProfile(StringRef FileName, const Twine &Msg,
250                               DiagnosticSeverity Severity = DS_Error)
251       : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
252         LineNum(0), Msg(Msg) {}
253   DiagnosticInfoSampleProfile(const Twine &Msg,
254                               DiagnosticSeverity Severity = DS_Error)
255       : DiagnosticInfo(DK_SampleProfile, Severity), LineNum(0), Msg(Msg) {}
256
257   /// \see DiagnosticInfo::print.
258   void print(DiagnosticPrinter &DP) const override;
259
260   static bool classof(const DiagnosticInfo *DI) {
261     return DI->getKind() == DK_SampleProfile;
262   }
263
264   StringRef getFileName() const { return FileName; }
265   unsigned getLineNum() const { return LineNum; }
266   const Twine &getMsg() const { return Msg; }
267
268 private:
269   /// Name of the input file associated with this diagnostic.
270   StringRef FileName;
271
272   /// Line number where the diagnostic occurred. If 0, no line number will
273   /// be emitted in the message.
274   unsigned LineNum;
275
276   /// Message to report.
277   const Twine &Msg;
278 };
279
280 /// Diagnostic information for the PGO profiler.
281 class DiagnosticInfoPGOProfile : public DiagnosticInfo {
282 public:
283   DiagnosticInfoPGOProfile(const char *FileName, const Twine &Msg,
284                            DiagnosticSeverity Severity = DS_Error)
285       : DiagnosticInfo(DK_PGOProfile, Severity), FileName(FileName), Msg(Msg) {}
286
287   /// \see DiagnosticInfo::print.
288   void print(DiagnosticPrinter &DP) const override;
289
290   static bool classof(const DiagnosticInfo *DI) {
291     return DI->getKind() == DK_PGOProfile;
292   }
293
294   const char *getFileName() const { return FileName; }
295   const Twine &getMsg() const { return Msg; }
296
297 private:
298   /// Name of the input file associated with this diagnostic.
299   const char *FileName;
300
301   /// Message to report.
302   const Twine &Msg;
303 };
304
305 /// Common features for diagnostics with an associated DebugLoc
306 class DiagnosticInfoWithDebugLocBase : public DiagnosticInfo {
307 public:
308   /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
309   /// the location information to use in the diagnostic.
310   DiagnosticInfoWithDebugLocBase(enum DiagnosticKind Kind,
311                                  enum DiagnosticSeverity Severity,
312                                  const Function &Fn,
313                                  const DebugLoc &DLoc)
314       : DiagnosticInfo(Kind, Severity), Fn(Fn), DLoc(DLoc) {}
315
316   /// Return true if location information is available for this diagnostic.
317   bool isLocationAvailable() const;
318
319   /// Return a string with the location information for this diagnostic
320   /// in the format "file:line:col". If location information is not available,
321   /// it returns "<unknown>:0:0".
322   const std::string getLocationStr() const;
323
324   /// Return location information for this diagnostic in three parts:
325   /// the source file name, line number and column.
326   void getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const;
327
328   const Function &getFunction() const { return Fn; }
329   const DebugLoc &getDebugLoc() const { return DLoc; }
330
331 private:
332   /// Function where this diagnostic is triggered.
333   const Function &Fn;
334
335   /// Debug location where this diagnostic is triggered.
336   DebugLoc DLoc;
337 };
338
339 /// Common features for diagnostics dealing with optimization remarks.
340 class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithDebugLocBase {
341 public:
342   /// \p PassName is the name of the pass emitting this diagnostic.
343   /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
344   /// the location information to use in the diagnostic. If line table
345   /// information is available, the diagnostic will include the source code
346   /// location. \p Msg is the message to show. Note that this class does not
347   /// copy this message, so this reference must be valid for the whole life time
348   /// of the diagnostic.
349   DiagnosticInfoOptimizationBase(enum DiagnosticKind Kind,
350                                  enum DiagnosticSeverity Severity,
351                                  const char *PassName, const Function &Fn,
352                                  const DebugLoc &DLoc, const Twine &Msg)
353       : DiagnosticInfoWithDebugLocBase(Kind, Severity, Fn, DLoc),
354         PassName(PassName), Msg(Msg) {}
355
356   /// \see DiagnosticInfo::print.
357   void print(DiagnosticPrinter &DP) const override;
358
359   /// Return true if this optimization remark is enabled by one of
360   /// of the LLVM command line flags (-pass-remarks, -pass-remarks-missed,
361   /// or -pass-remarks-analysis). Note that this only handles the LLVM
362   /// flags. We cannot access Clang flags from here (they are handled
363   /// in BackendConsumer::OptimizationRemarkHandler).
364   virtual bool isEnabled() const = 0;
365
366   const char *getPassName() const { return PassName; }
367   const Twine &getMsg() const { return Msg; }
368
369   static bool classof(const DiagnosticInfo *DI) {
370     return DI->getKind() >= DK_FirstRemark &&
371            DI->getKind() <= DK_LastRemark;
372   }
373
374 private:
375   /// Name of the pass that triggers this report. If this matches the
376   /// regular expression given in -Rpass=regexp, then the remark will
377   /// be emitted.
378   const char *PassName;
379
380   /// Message to report.
381   const Twine &Msg;
382 };
383
384 /// Diagnostic information for applied optimization remarks.
385 class DiagnosticInfoOptimizationRemark : public DiagnosticInfoOptimizationBase {
386 public:
387   /// \p PassName is the name of the pass emitting this diagnostic. If
388   /// this name matches the regular expression given in -Rpass=, then the
389   /// diagnostic will be emitted. \p Fn is the function where the diagnostic
390   /// is being emitted. \p DLoc is the location information to use in the
391   /// diagnostic. If line table information is available, the diagnostic
392   /// will include the source code location. \p Msg is the message to show.
393   /// Note that this class does not copy this message, so this reference
394   /// must be valid for the whole life time of the diagnostic.
395   DiagnosticInfoOptimizationRemark(const char *PassName, const Function &Fn,
396                                    const DebugLoc &DLoc, const Twine &Msg)
397       : DiagnosticInfoOptimizationBase(DK_OptimizationRemark, DS_Remark,
398                                        PassName, Fn, DLoc, Msg) {}
399
400   static bool classof(const DiagnosticInfo *DI) {
401     return DI->getKind() == DK_OptimizationRemark;
402   }
403
404   /// \see DiagnosticInfoOptimizationBase::isEnabled.
405   bool isEnabled() const override;
406 };
407
408 /// Diagnostic information for missed-optimization remarks.
409 class DiagnosticInfoOptimizationRemarkMissed
410     : public DiagnosticInfoOptimizationBase {
411 public:
412   /// \p PassName is the name of the pass emitting this diagnostic. If
413   /// this name matches the regular expression given in -Rpass-missed=, then the
414   /// diagnostic will be emitted. \p Fn is the function where the diagnostic
415   /// is being emitted. \p DLoc is the location information to use in the
416   /// diagnostic. If line table information is available, the diagnostic
417   /// will include the source code location. \p Msg is the message to show.
418   /// Note that this class does not copy this message, so this reference
419   /// must be valid for the whole life time of the diagnostic.
420   DiagnosticInfoOptimizationRemarkMissed(const char *PassName,
421                                          const Function &Fn,
422                                          const DebugLoc &DLoc, const Twine &Msg)
423       : DiagnosticInfoOptimizationBase(DK_OptimizationRemarkMissed, DS_Remark,
424                                        PassName, Fn, DLoc, Msg) {}
425
426   static bool classof(const DiagnosticInfo *DI) {
427     return DI->getKind() == DK_OptimizationRemarkMissed;
428   }
429
430   /// \see DiagnosticInfoOptimizationBase::isEnabled.
431   bool isEnabled() const override;
432 };
433
434 /// Diagnostic information for optimization analysis remarks.
435 class DiagnosticInfoOptimizationRemarkAnalysis
436     : public DiagnosticInfoOptimizationBase {
437 public:
438   /// \p PassName is the name of the pass emitting this diagnostic. If
439   /// this name matches the regular expression given in -Rpass-analysis=, then
440   /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
441   /// is being emitted. \p DLoc is the location information to use in the
442   /// diagnostic. If line table information is available, the diagnostic will
443   /// include the source code location. \p Msg is the message to show. Note that
444   /// this class does not copy this message, so this reference must be valid for
445   /// the whole life time of the diagnostic.
446   DiagnosticInfoOptimizationRemarkAnalysis(const char *PassName,
447                                            const Function &Fn,
448                                            const DebugLoc &DLoc,
449                                            const Twine &Msg)
450       : DiagnosticInfoOptimizationBase(DK_OptimizationRemarkAnalysis, DS_Remark,
451                                        PassName, Fn, DLoc, Msg) {}
452
453   static bool classof(const DiagnosticInfo *DI) {
454     return DI->getKind() == DK_OptimizationRemarkAnalysis;
455   }
456
457   /// \see DiagnosticInfoOptimizationBase::isEnabled.
458   bool isEnabled() const override;
459
460 protected:
461   DiagnosticInfoOptimizationRemarkAnalysis(enum DiagnosticKind Kind,
462                                            const char *PassName,
463                                            const Function &Fn,
464                                            const DebugLoc &DLoc,
465                                            const Twine &Msg)
466       : DiagnosticInfoOptimizationBase(Kind, DS_Remark, PassName, Fn, DLoc,
467                                        Msg) {}
468 };
469
470 /// Diagnostic information for optimization analysis remarks related to
471 /// floating-point non-commutativity.
472 class DiagnosticInfoOptimizationRemarkAnalysisFPCommute
473     : public DiagnosticInfoOptimizationRemarkAnalysis {
474 public:
475   /// \p PassName is the name of the pass emitting this diagnostic. If
476   /// this name matches the regular expression given in -Rpass-analysis=, then
477   /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
478   /// is being emitted. \p DLoc is the location information to use in the
479   /// diagnostic. If line table information is available, the diagnostic will
480   /// include the source code location. \p Msg is the message to show. The
481   /// front-end will append its own message related to options that address
482   /// floating-point non-commutativity. Note that this class does not copy this
483   /// message, so this reference must be valid for the whole life time of the
484   /// diagnostic.
485   DiagnosticInfoOptimizationRemarkAnalysisFPCommute(const char *PassName,
486                                                     const Function &Fn,
487                                                     const DebugLoc &DLoc,
488                                                     const Twine &Msg)
489       : DiagnosticInfoOptimizationRemarkAnalysis(
490             DK_OptimizationRemarkAnalysisFPCommute, PassName, Fn, DLoc, Msg) {}
491
492   static bool classof(const DiagnosticInfo *DI) {
493     return DI->getKind() == DK_OptimizationRemarkAnalysisFPCommute;
494   }
495 };
496
497 /// Diagnostic information for optimization analysis remarks related to
498 /// pointer aliasing.
499 class DiagnosticInfoOptimizationRemarkAnalysisAliasing
500     : public DiagnosticInfoOptimizationRemarkAnalysis {
501 public:
502   /// \p PassName is the name of the pass emitting this diagnostic. If
503   /// this name matches the regular expression given in -Rpass-analysis=, then
504   /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
505   /// is being emitted. \p DLoc is the location information to use in the
506   /// diagnostic. If line table information is available, the diagnostic will
507   /// include the source code location. \p Msg is the message to show. The
508   /// front-end will append its own message related to options that address
509   /// pointer aliasing legality. Note that this class does not copy this
510   /// message, so this reference must be valid for the whole life time of the
511   /// diagnostic.
512   DiagnosticInfoOptimizationRemarkAnalysisAliasing(const char *PassName,
513                                                    const Function &Fn,
514                                                    const DebugLoc &DLoc,
515                                                    const Twine &Msg)
516       : DiagnosticInfoOptimizationRemarkAnalysis(
517             DK_OptimizationRemarkAnalysisAliasing, PassName, Fn, DLoc, Msg) {}
518
519   static bool classof(const DiagnosticInfo *DI) {
520     return DI->getKind() == DK_OptimizationRemarkAnalysisAliasing;
521   }
522 };
523
524 /// Diagnostic information for machine IR parser.
525 class DiagnosticInfoMIRParser : public DiagnosticInfo {
526   const SMDiagnostic &Diagnostic;
527
528 public:
529   DiagnosticInfoMIRParser(DiagnosticSeverity Severity,
530                           const SMDiagnostic &Diagnostic)
531       : DiagnosticInfo(DK_MIRParser, Severity), Diagnostic(Diagnostic) {}
532
533   const SMDiagnostic &getDiagnostic() const { return Diagnostic; }
534
535   void print(DiagnosticPrinter &DP) const override;
536
537   static bool classof(const DiagnosticInfo *DI) {
538     return DI->getKind() == DK_MIRParser;
539   }
540 };
541
542 // Create wrappers for C Binding types (see CBindingWrapping.h).
543 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DiagnosticInfo, LLVMDiagnosticInfoRef)
544
545 /// Emit an optimization-applied message. \p PassName is the name of the pass
546 /// emitting the message. If -Rpass= is given and \p PassName matches the
547 /// regular expression in -Rpass, then the remark will be emitted. \p Fn is
548 /// the function triggering the remark, \p DLoc is the debug location where
549 /// the diagnostic is generated. \p Msg is the message string to use.
550 void emitOptimizationRemark(LLVMContext &Ctx, const char *PassName,
551                             const Function &Fn, const DebugLoc &DLoc,
552                             const Twine &Msg);
553
554 /// Emit an optimization-missed message. \p PassName is the name of the
555 /// pass emitting the message. If -Rpass-missed= is given and \p PassName
556 /// matches the regular expression in -Rpass, then the remark will be
557 /// emitted. \p Fn is the function triggering the remark, \p DLoc is the
558 /// debug location where the diagnostic is generated. \p Msg is the
559 /// message string to use.
560 void emitOptimizationRemarkMissed(LLVMContext &Ctx, const char *PassName,
561                                   const Function &Fn, const DebugLoc &DLoc,
562                                   const Twine &Msg);
563
564 /// Emit an optimization analysis remark message. \p PassName is the name of
565 /// the pass emitting the message. If -Rpass-analysis= is given and \p
566 /// PassName matches the regular expression in -Rpass, then the remark will be
567 /// emitted. \p Fn is the function triggering the remark, \p DLoc is the debug
568 /// location where the diagnostic is generated. \p Msg is the message string
569 /// to use.
570 void emitOptimizationRemarkAnalysis(LLVMContext &Ctx, const char *PassName,
571                                     const Function &Fn, const DebugLoc &DLoc,
572                                     const Twine &Msg);
573
574 /// Emit an optimization analysis remark related to messages about
575 /// floating-point non-commutativity. \p PassName is the name of the pass
576 /// emitting the message. If -Rpass-analysis= is given and \p PassName matches
577 /// the regular expression in -Rpass, then the remark will be emitted. \p Fn is
578 /// the function triggering the remark, \p DLoc is the debug location where the
579 /// diagnostic is generated. \p Msg is the message string to use.
580 void emitOptimizationRemarkAnalysisFPCommute(LLVMContext &Ctx,
581                                              const char *PassName,
582                                              const Function &Fn,
583                                              const DebugLoc &DLoc,
584                                              const Twine &Msg);
585
586 /// Emit an optimization analysis remark related to messages about
587 /// pointer aliasing. \p PassName is the name of the pass emitting the message.
588 /// If -Rpass-analysis= is given and \p PassName matches the regular expression
589 /// in -Rpass, then the remark will be emitted. \p Fn is the function triggering
590 /// the remark, \p DLoc is the debug location where the diagnostic is generated.
591 /// \p Msg is the message string to use.
592 void emitOptimizationRemarkAnalysisAliasing(LLVMContext &Ctx,
593                                             const char *PassName,
594                                             const Function &Fn,
595                                             const DebugLoc &DLoc,
596                                             const Twine &Msg);
597
598 /// Diagnostic information for optimization failures.
599 class DiagnosticInfoOptimizationFailure
600     : public DiagnosticInfoOptimizationBase {
601 public:
602   /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
603   /// the location information to use in the diagnostic. If line table
604   /// information is available, the diagnostic will include the source code
605   /// location. \p Msg is the message to show. Note that this class does not
606   /// copy this message, so this reference must be valid for the whole life time
607   /// of the diagnostic.
608   DiagnosticInfoOptimizationFailure(const Function &Fn, const DebugLoc &DLoc,
609                                     const Twine &Msg)
610       : DiagnosticInfoOptimizationBase(DK_OptimizationFailure, DS_Warning,
611                                        nullptr, Fn, DLoc, Msg) {}
612
613   static bool classof(const DiagnosticInfo *DI) {
614     return DI->getKind() == DK_OptimizationFailure;
615   }
616
617   /// \see DiagnosticInfoOptimizationBase::isEnabled.
618   bool isEnabled() const override;
619 };
620
621 /// Diagnostic information for unsupported feature in backend.
622 class DiagnosticInfoUnsupported
623     : public DiagnosticInfoWithDebugLocBase {
624 private:
625   Twine Msg;
626
627 public:
628   /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
629   /// the location information to use in the diagnostic. If line table
630   /// information is available, the diagnostic will include the source code
631   /// location. \p Msg is the message to show. Note that this class does not
632   /// copy this message, so this reference must be valid for the whole life time
633   /// of the diagnostic.
634   DiagnosticInfoUnsupported(const Function &Fn, const Twine &Msg,
635                             DebugLoc DLoc = DebugLoc())
636       : DiagnosticInfoWithDebugLocBase(DK_Unsupported, DS_Error, Fn, DLoc),
637         Msg(Msg) {}
638
639   static bool classof(const DiagnosticInfo *DI) {
640     return DI->getKind() == DK_Unsupported;
641   }
642
643   const Twine &getMessage() const { return Msg; }
644
645   void print(DiagnosticPrinter &DP) const override;
646 };
647
648 /// Emit a warning when loop vectorization is specified but fails. \p Fn is the
649 /// function triggering the warning, \p DLoc is the debug location where the
650 /// diagnostic is generated. \p Msg is the message string to use.
651 void emitLoopVectorizeWarning(LLVMContext &Ctx, const Function &Fn,
652                               const DebugLoc &DLoc, const Twine &Msg);
653
654 /// Emit a warning when loop interleaving is specified but fails. \p Fn is the
655 /// function triggering the warning, \p DLoc is the debug location where the
656 /// diagnostic is generated. \p Msg is the message string to use.
657 void emitLoopInterleaveWarning(LLVMContext &Ctx, const Function &Fn,
658                                const DebugLoc &DLoc, const Twine &Msg);
659
660 } // end namespace llvm
661
662 #endif // LLVM_IR_DIAGNOSTICINFO_H