LLVM  8.0.0svn
DiagnosticInfo.h
Go to the documentation of this file.
1 //===- llvm/IR/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-c/Types.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/ADT/Twine.h"
23 #include "llvm/IR/DebugLoc.h"
26 #include <algorithm>
27 #include <cstdint>
28 #include <functional>
29 #include <iterator>
30 #include <string>
31 
32 namespace llvm {
33 
34 // Forward declarations.
35 class DiagnosticPrinter;
36 class Function;
37 class Instruction;
38 class LLVMContext;
39 class Module;
40 class SMDiagnostic;
41 
42 /// Defines the different supported severity of a diagnostic.
43 enum DiagnosticSeverity : char {
47  // A note attaches additional information to one of the previous diagnostic
48  // types.
50 };
51 
52 /// Defines the different supported kind of a diagnostic.
53 /// This enum should be extended with a new ID for each added concrete subclass.
80 };
81 
82 /// Get the next available kind ID for a plugin diagnostic.
83 /// Each time this function is called, it returns a different number.
84 /// Therefore, a plugin that wants to "identify" its own classes
85 /// with a dynamic identifier, just have to use this method to get a new ID
86 /// and assign it to each of its classes.
87 /// The returned ID will be greater than or equal to DK_FirstPluginKind.
88 /// Thus, the plugin identifiers will not conflict with the
89 /// DiagnosticKind values.
91 
92 /// This is the base abstract class for diagnostic reporting in
93 /// the backend.
94 /// The print method must be overloaded by the subclasses to print a
95 /// user-friendly message in the client of the backend (let us call it a
96 /// frontend).
98 private:
99  /// Kind defines the kind of report this is about.
100  const /* DiagnosticKind */ int Kind;
101  /// Severity gives the severity of the diagnostic.
102  const DiagnosticSeverity Severity;
103 
104 public:
105  DiagnosticInfo(/* DiagnosticKind */ int Kind, DiagnosticSeverity Severity)
106  : Kind(Kind), Severity(Severity) {}
107 
108  virtual ~DiagnosticInfo() = default;
109 
110  /* DiagnosticKind */ int getKind() const { return Kind; }
111  DiagnosticSeverity getSeverity() const { return Severity; }
112 
113  /// Print using the given \p DP a user-friendly message.
114  /// This is the default message that will be printed to the user.
115  /// It is used when the frontend does not directly take advantage
116  /// of the information contained in fields of the subclasses.
117  /// The printed message must not end with '.' nor start with a severity
118  /// keyword.
119  virtual void print(DiagnosticPrinter &DP) const = 0;
120 };
121 
122 using DiagnosticHandlerFunction = std::function<void(const DiagnosticInfo &)>;
123 
124 /// Diagnostic information for inline asm reporting.
125 /// This is basically a message and an optional location.
127 private:
128  /// Optional line information. 0 if not set.
129  unsigned LocCookie = 0;
130  /// Message to be reported.
131  const Twine &MsgStr;
132  /// Optional origin of the problem.
133  const Instruction *Instr = nullptr;
134 
135 public:
136  /// \p MsgStr is the message to be reported to the frontend.
137  /// This class does not copy \p MsgStr, therefore the reference must be valid
138  /// for the whole life time of the Diagnostic.
140  DiagnosticSeverity Severity = DS_Error)
141  : DiagnosticInfo(DK_InlineAsm, Severity), MsgStr(MsgStr) {}
142 
143  /// \p LocCookie if non-zero gives the line number for this report.
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  DiagnosticInfoInlineAsm(unsigned LocCookie, const Twine &MsgStr,
148  DiagnosticSeverity Severity = DS_Error)
149  : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie),
150  MsgStr(MsgStr) {}
151 
152  /// \p Instr gives the original instruction that triggered the diagnostic.
153  /// \p MsgStr gives the message.
154  /// This class does not copy \p MsgStr, therefore the reference must be valid
155  /// for the whole life time of the Diagnostic.
156  /// Same for \p I.
157  DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr,
158  DiagnosticSeverity Severity = DS_Error);
159 
160  unsigned getLocCookie() const { return LocCookie; }
161  const Twine &getMsgStr() const { return MsgStr; }
162  const Instruction *getInstruction() const { return Instr; }
163 
164  /// \see DiagnosticInfo::print.
165  void print(DiagnosticPrinter &DP) const override;
166 
167  static bool classof(const DiagnosticInfo *DI) {
168  return DI->getKind() == DK_InlineAsm;
169  }
170 };
171 
172 /// Diagnostic information for stack size etc. reporting.
173 /// This is basically a function and a size.
175 private:
176  /// The function that is concerned by this resource limit diagnostic.
177  const Function &Fn;
178 
179  /// Description of the resource type (e.g. stack size)
180  const char *ResourceName;
181 
182  /// The computed size usage
183  uint64_t ResourceSize;
184 
185  // Threshould passed
186  uint64_t ResourceLimit;
187 
188 public:
189  /// \p The function that is concerned by this stack size diagnostic.
190  /// \p The computed stack size.
191  DiagnosticInfoResourceLimit(const Function &Fn, const char *ResourceName,
192  uint64_t ResourceSize,
193  DiagnosticSeverity Severity = DS_Warning,
195  uint64_t ResourceLimit = 0)
196  : DiagnosticInfo(Kind, Severity), Fn(Fn), ResourceName(ResourceName),
197  ResourceSize(ResourceSize), ResourceLimit(ResourceLimit) {}
198 
199  const Function &getFunction() const { return Fn; }
200  const char *getResourceName() const { return ResourceName; }
201  uint64_t getResourceSize() const { return ResourceSize; }
202  uint64_t getResourceLimit() const { return ResourceLimit; }
203 
204  /// \see DiagnosticInfo::print.
205  void print(DiagnosticPrinter &DP) const override;
206 
207  static bool classof(const DiagnosticInfo *DI) {
208  return DI->getKind() == DK_ResourceLimit || DI->getKind() == DK_StackSize;
209  }
210 };
211 
213 public:
214  DiagnosticInfoStackSize(const Function &Fn, uint64_t StackSize,
215  DiagnosticSeverity Severity = DS_Warning,
216  uint64_t StackLimit = 0)
217  : DiagnosticInfoResourceLimit(Fn, "stack size", StackSize, Severity,
218  DK_StackSize, StackLimit) {}
219 
220  uint64_t getStackSize() const { return getResourceSize(); }
221  uint64_t getStackLimit() const { return getResourceLimit(); }
222 
223  static bool classof(const DiagnosticInfo *DI) {
224  return DI->getKind() == DK_StackSize;
225  }
226 };
227 
228 /// Diagnostic information for debug metadata version reporting.
229 /// This is basically a module and a version.
231 private:
232  /// The module that is concerned by this debug metadata version diagnostic.
233  const Module &M;
234  /// The actual metadata version.
235  unsigned MetadataVersion;
236 
237 public:
238  /// \p The module that is concerned by this debug metadata version diagnostic.
239  /// \p The actual metadata version.
240  DiagnosticInfoDebugMetadataVersion(const Module &M, unsigned MetadataVersion,
241  DiagnosticSeverity Severity = DS_Warning)
242  : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M),
243  MetadataVersion(MetadataVersion) {}
244 
245  const Module &getModule() const { return M; }
246  unsigned getMetadataVersion() const { return MetadataVersion; }
247 
248  /// \see DiagnosticInfo::print.
249  void print(DiagnosticPrinter &DP) const override;
250 
251  static bool classof(const DiagnosticInfo *DI) {
252  return DI->getKind() == DK_DebugMetadataVersion;
253  }
254 };
255 
256 /// Diagnostic information for stripping invalid debug metadata.
258 private:
259  /// The module that is concerned by this debug metadata version diagnostic.
260  const Module &M;
261 
262 public:
263  /// \p The module that is concerned by this debug metadata version diagnostic.
265  const Module &M, DiagnosticSeverity Severity = DS_Warning)
266  : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M) {}
267 
268  const Module &getModule() const { return M; }
269 
270  /// \see DiagnosticInfo::print.
271  void print(DiagnosticPrinter &DP) const override;
272 
273  static bool classof(const DiagnosticInfo *DI) {
274  return DI->getKind() == DK_DebugMetadataInvalid;
275  }
276 };
277 
278 /// Diagnostic information for the sample profiler.
280 public:
281  DiagnosticInfoSampleProfile(StringRef FileName, unsigned LineNum,
282  const Twine &Msg,
283  DiagnosticSeverity Severity = DS_Error)
284  : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
285  LineNum(LineNum), Msg(Msg) {}
287  DiagnosticSeverity Severity = DS_Error)
288  : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
289  Msg(Msg) {}
291  DiagnosticSeverity Severity = DS_Error)
292  : DiagnosticInfo(DK_SampleProfile, Severity), Msg(Msg) {}
293 
294  /// \see DiagnosticInfo::print.
295  void print(DiagnosticPrinter &DP) const override;
296 
297  static bool classof(const DiagnosticInfo *DI) {
298  return DI->getKind() == DK_SampleProfile;
299  }
300 
301  StringRef getFileName() const { return FileName; }
302  unsigned getLineNum() const { return LineNum; }
303  const Twine &getMsg() const { return Msg; }
304 
305 private:
306  /// Name of the input file associated with this diagnostic.
307  StringRef FileName;
308 
309  /// Line number where the diagnostic occurred. If 0, no line number will
310  /// be emitted in the message.
311  unsigned LineNum = 0;
312 
313  /// Message to report.
314  const Twine &Msg;
315 };
316 
317 /// Diagnostic information for the PGO profiler.
319 public:
320  DiagnosticInfoPGOProfile(const char *FileName, const Twine &Msg,
321  DiagnosticSeverity Severity = DS_Error)
322  : DiagnosticInfo(DK_PGOProfile, Severity), FileName(FileName), Msg(Msg) {}
323 
324  /// \see DiagnosticInfo::print.
325  void print(DiagnosticPrinter &DP) const override;
326 
327  static bool classof(const DiagnosticInfo *DI) {
328  return DI->getKind() == DK_PGOProfile;
329  }
330 
331  const char *getFileName() const { return FileName; }
332  const Twine &getMsg() const { return Msg; }
333 
334 private:
335  /// Name of the input file associated with this diagnostic.
336  const char *FileName;
337 
338  /// Message to report.
339  const Twine &Msg;
340 };
341 
343  DIFile *File = nullptr;
344  unsigned Line = 0;
345  unsigned Column = 0;
346 
347 public:
348  DiagnosticLocation() = default;
349  DiagnosticLocation(const DebugLoc &DL);
351 
352  bool isValid() const { return File; }
353  /// Return the full path to the file.
354  std::string getAbsolutePath() const;
355  /// Return the file name relative to the compilation directory.
356  StringRef getRelativePath() const;
357  unsigned getLine() const { return Line; }
358  unsigned getColumn() const { return Column; }
359 };
360 
361 /// Common features for diagnostics with an associated location.
363 public:
364  /// \p Fn is the function where the diagnostic is being emitted. \p Loc is
365  /// the location information to use in the diagnostic.
367  enum DiagnosticSeverity Severity,
368  const Function &Fn,
369  const DiagnosticLocation &Loc)
370  : DiagnosticInfo(Kind, Severity), Fn(Fn), Loc(Loc) {}
371 
372  /// Return true if location information is available for this diagnostic.
373  bool isLocationAvailable() const { return Loc.isValid(); }
374 
375  /// Return a string with the location information for this diagnostic
376  /// in the format "file:line:col". If location information is not available,
377  /// it returns "<unknown>:0:0".
378  const std::string getLocationStr() const;
379 
380  /// Return location information for this diagnostic in three parts:
381  /// the relative source file path, line number and column.
382  void getLocation(StringRef &RelativePath, unsigned &Line,
383  unsigned &Column) const;
384 
385  /// Return the absolute path tot the file.
386  std::string getAbsolutePath() const;
387 
388  const Function &getFunction() const { return Fn; }
389  DiagnosticLocation getLocation() const { return Loc; }
390 
391 private:
392  /// Function where this diagnostic is triggered.
393  const Function &Fn;
394 
395  /// Debug location where this diagnostic is triggered.
396  DiagnosticLocation Loc;
397 };
398 
399 /// Common features for diagnostics dealing with optimization remarks
400 /// that are used by both IR and MIR passes.
402 public:
403  /// Used to set IsVerbose via the stream interface.
404  struct setIsVerbose {};
405 
406  /// When an instance of this is inserted into the stream, the arguments
407  /// following will not appear in the remark printed in the compiler output
408  /// (-Rpass) but only in the optimization record file
409  /// (-fsave-optimization-record).
410  struct setExtraArgs {};
411 
412  /// Used in the streaming interface as the general argument type. It
413  /// internally converts everything into a key-value pair.
414  struct Argument {
415  std::string Key;
416  std::string Val;
417  // If set, the debug location corresponding to the value.
419 
420  explicit Argument(StringRef Str = "") : Key("String"), Val(Str) {}
421  Argument(StringRef Key, const Value *V);
422  Argument(StringRef Key, const Type *T);
423  Argument(StringRef Key, StringRef S);
424  Argument(StringRef Key, const char *S) : Argument(Key, StringRef(S)) {};
425  Argument(StringRef Key, int N);
426  Argument(StringRef Key, float N);
427  Argument(StringRef Key, long N);
428  Argument(StringRef Key, long long N);
429  Argument(StringRef Key, unsigned N);
430  Argument(StringRef Key, unsigned long N);
431  Argument(StringRef Key, unsigned long long N);
432  Argument(StringRef Key, bool B) : Key(Key), Val(B ? "true" : "false") {}
433  Argument(StringRef Key, DebugLoc dl);
434  };
435 
436  /// \p PassName is the name of the pass emitting this diagnostic. \p
437  /// RemarkName is a textual identifier for the remark (single-word,
438  /// camel-case). \p Fn is the function where the diagnostic is being emitted.
439  /// \p Loc is the location information to use in the diagnostic. If line table
440  /// information is available, the diagnostic will include the source code
441  /// location.
443  enum DiagnosticSeverity Severity,
444  const char *PassName, StringRef RemarkName,
445  const Function &Fn,
446  const DiagnosticLocation &Loc)
447  : DiagnosticInfoWithLocationBase(Kind, Severity, Fn, Loc),
448  PassName(PassName), RemarkName(RemarkName) {}
449 
450  void insert(StringRef S);
451  void insert(Argument A);
452  void insert(setIsVerbose V);
453  void insert(setExtraArgs EA);
454 
455  /// \see DiagnosticInfo::print.
456  void print(DiagnosticPrinter &DP) const override;
457 
458  /// Return true if this optimization remark is enabled by one of
459  /// of the LLVM command line flags (-pass-remarks, -pass-remarks-missed,
460  /// or -pass-remarks-analysis). Note that this only handles the LLVM
461  /// flags. We cannot access Clang flags from here (they are handled
462  /// in BackendConsumer::OptimizationRemarkHandler).
463  virtual bool isEnabled() const = 0;
464 
465  StringRef getPassName() const { return PassName; }
466  std::string getMsg() const;
467  Optional<uint64_t> getHotness() const { return Hotness; }
468  void setHotness(Optional<uint64_t> H) { Hotness = H; }
469 
470  bool isVerbose() const { return IsVerbose; }
471 
472  static bool classof(const DiagnosticInfo *DI) {
473  return (DI->getKind() >= DK_FirstRemark &&
474  DI->getKind() <= DK_LastRemark) ||
475  (DI->getKind() >= DK_FirstMachineRemark &&
476  DI->getKind() <= DK_LastMachineRemark);
477  }
478 
479  bool isPassed() const {
480  return (getKind() == DK_OptimizationRemark ||
482  }
483 
484  bool isMissed() const {
485  return (getKind() == DK_OptimizationRemarkMissed ||
487  }
488 
489  bool isAnalysis() const {
490  return (getKind() == DK_OptimizationRemarkAnalysis ||
492  }
493 
494 protected:
495  /// Name of the pass that triggers this report. If this matches the
496  /// regular expression given in -Rpass=regexp, then the remark will
497  /// be emitted.
498  const char *PassName;
499 
500  /// Textual identifier for the remark (single-word, camel-case). Can be used
501  /// by external tools reading the YAML output file for optimization remarks to
502  /// identify the remark.
504 
505  /// If profile information is available, this is the number of times the
506  /// corresponding code was executed in a profile instrumentation run.
508 
509  /// Arguments collected via the streaming interface.
511 
512  /// The remark is expected to be noisy.
513  bool IsVerbose = false;
514 
515  /// If positive, the index of the first argument that only appear in
516  /// the optimization records and not in the remark printed in the compiler
517  /// output.
518  int FirstExtraArgIndex = -1;
519 
521 };
522 
523 /// Allow the insertion operator to return the actual remark type rather than a
524 /// common base class. This allows returning the result of the insertion
525 /// directly by value, e.g. return OptimizationRemarkAnalysis(...) << "blah".
526 template <class RemarkT>
527 RemarkT &
528 operator<<(RemarkT &R,
529  typename std::enable_if<
530  std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
531  StringRef>::type S) {
532  R.insert(S);
533  return R;
534 }
535 
536 /// Also allow r-value for the remark to allow insertion into a
537 /// temporarily-constructed remark.
538 template <class RemarkT>
539 RemarkT &
540 operator<<(RemarkT &&R,
541  typename std::enable_if<
542  std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
543  StringRef>::type S) {
544  R.insert(S);
545  return R;
546 }
547 
548 template <class RemarkT>
549 RemarkT &
550 operator<<(RemarkT &R,
551  typename std::enable_if<
552  std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
554  R.insert(A);
555  return R;
556 }
557 
558 template <class RemarkT>
559 RemarkT &
560 operator<<(RemarkT &&R,
561  typename std::enable_if<
562  std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
564  R.insert(A);
565  return R;
566 }
567 
568 template <class RemarkT>
569 RemarkT &
570 operator<<(RemarkT &R,
571  typename std::enable_if<
572  std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
574  R.insert(V);
575  return R;
576 }
577 
578 template <class RemarkT>
579 RemarkT &
580 operator<<(RemarkT &&R,
581  typename std::enable_if<
582  std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
584  R.insert(V);
585  return R;
586 }
587 
588 template <class RemarkT>
589 RemarkT &
590 operator<<(RemarkT &R,
591  typename std::enable_if<
592  std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
594  R.insert(EA);
595  return R;
596 }
597 
598 /// Common features for diagnostics dealing with optimization remarks
599 /// that are used by IR passes.
601 public:
602  /// \p PassName is the name of the pass emitting this diagnostic. \p
603  /// RemarkName is a textual identifier for the remark (single-word,
604  /// camel-case). \p Fn is the function where the diagnostic is being emitted.
605  /// \p Loc is the location information to use in the diagnostic. If line table
606  /// information is available, the diagnostic will include the source code
607  /// location. \p CodeRegion is IR value (currently basic block) that the
608  /// optimization operates on. This is currently used to provide run-time
609  /// hotness information with PGO.
611  enum DiagnosticSeverity Severity,
612  const char *PassName, StringRef RemarkName,
613  const Function &Fn,
614  const DiagnosticLocation &Loc,
615  const Value *CodeRegion = nullptr)
616  : DiagnosticInfoOptimizationBase(Kind, Severity, PassName, RemarkName, Fn,
617  Loc),
618  CodeRegion(CodeRegion) {}
619 
620  /// This is ctor variant allows a pass to build an optimization remark
621  /// from an existing remark.
622  ///
623  /// This is useful when a transformation pass (e.g LV) wants to emit a remark
624  /// (\p Orig) generated by one of its analyses (e.g. LAA) as its own analysis
625  /// remark. The string \p Prepend will be emitted before the original
626  /// message.
627  DiagnosticInfoIROptimization(const char *PassName, StringRef Prepend,
628  const DiagnosticInfoIROptimization &Orig)
630  (DiagnosticKind)Orig.getKind(), Orig.getSeverity(), PassName,
631  Orig.RemarkName, Orig.getFunction(), Orig.getLocation()),
632  CodeRegion(Orig.getCodeRegion()) {
633  *this << Prepend;
634  std::copy(Orig.Args.begin(), Orig.Args.end(), std::back_inserter(Args));
635  }
636 
637  /// Legacy interface.
638  /// \p PassName is the name of the pass emitting this diagnostic.
639  /// \p Fn is the function where the diagnostic is being emitted. \p Loc is
640  /// the location information to use in the diagnostic. If line table
641  /// information is available, the diagnostic will include the source code
642  /// location. \p Msg is the message to show. Note that this class does not
643  /// copy this message, so this reference must be valid for the whole life time
644  /// of the diagnostic.
646  enum DiagnosticSeverity Severity,
647  const char *PassName, const Function &Fn,
648  const DiagnosticLocation &Loc, const Twine &Msg)
649  : DiagnosticInfoOptimizationBase(Kind, Severity, PassName, "", Fn, Loc) {
650  *this << Msg.str();
651  }
652 
653  const Value *getCodeRegion() const { return CodeRegion; }
654 
655  static bool classof(const DiagnosticInfo *DI) {
656  return DI->getKind() >= DK_FirstRemark && DI->getKind() <= DK_LastRemark;
657  }
658 
659 private:
660  /// The IR value (currently basic block) that the optimization operates on.
661  /// This is currently used to provide run-time hotness information with PGO.
662  const Value *CodeRegion;
663 };
664 
665 /// Diagnostic information for applied optimization remarks.
667 public:
668  /// \p PassName is the name of the pass emitting this diagnostic. If this name
669  /// matches the regular expression given in -Rpass=, then the diagnostic will
670  /// be emitted. \p RemarkName is a textual identifier for the remark (single-
671  /// word, camel-case). \p Loc is the debug location and \p CodeRegion is the
672  /// region that the optimization operates on (currently only block is
673  /// supported).
674  OptimizationRemark(const char *PassName, StringRef RemarkName,
675  const DiagnosticLocation &Loc, const Value *CodeRegion);
676 
677  /// Same as above, but the debug location and code region are derived from \p
678  /// Instr.
679  OptimizationRemark(const char *PassName, StringRef RemarkName,
680  const Instruction *Inst);
681 
682  /// Same as above, but the debug location and code region are derived from \p
683  /// Func.
684  OptimizationRemark(const char *PassName, StringRef RemarkName,
685  const Function *Func);
686 
687  static bool classof(const DiagnosticInfo *DI) {
688  return DI->getKind() == DK_OptimizationRemark;
689  }
690 
691  /// \see DiagnosticInfoOptimizationBase::isEnabled.
692  bool isEnabled() const override;
693 
694 private:
695  /// This is deprecated now and only used by the function API below.
696  /// \p PassName is the name of the pass emitting this diagnostic. If
697  /// this name matches the regular expression given in -Rpass=, then the
698  /// diagnostic will be emitted. \p Fn is the function where the diagnostic
699  /// is being emitted. \p Loc is the location information to use in the
700  /// diagnostic. If line table information is available, the diagnostic
701  /// will include the source code location. \p Msg is the message to show.
702  /// Note that this class does not copy this message, so this reference
703  /// must be valid for the whole life time of the diagnostic.
704  OptimizationRemark(const char *PassName, const Function &Fn,
705  const DiagnosticLocation &Loc, const Twine &Msg)
707  Fn, Loc, Msg) {}
708 };
709 
710 /// Diagnostic information for missed-optimization remarks.
712 public:
713  /// \p PassName is the name of the pass emitting this diagnostic. If this name
714  /// matches the regular expression given in -Rpass-missed=, then the
715  /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
716  /// remark (single-word, camel-case). \p Loc is the debug location and \p
717  /// CodeRegion is the region that the optimization operates on (currently only
718  /// block is supported).
719  OptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
720  const DiagnosticLocation &Loc,
721  const Value *CodeRegion);
722 
723  /// Same as above but \p Inst is used to derive code region and debug
724  /// location.
725  OptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
726  const Instruction *Inst);
727 
728  static bool classof(const DiagnosticInfo *DI) {
729  return DI->getKind() == DK_OptimizationRemarkMissed;
730  }
731 
732  /// \see DiagnosticInfoOptimizationBase::isEnabled.
733  bool isEnabled() const override;
734 
735 private:
736  /// This is deprecated now and only used by the function API below.
737  /// \p PassName is the name of the pass emitting this diagnostic. If
738  /// this name matches the regular expression given in -Rpass-missed=, then the
739  /// diagnostic will be emitted. \p Fn is the function where the diagnostic
740  /// is being emitted. \p Loc is the location information to use in the
741  /// diagnostic. If line table information is available, the diagnostic
742  /// will include the source code location. \p Msg is the message to show.
743  /// Note that this class does not copy this message, so this reference
744  /// must be valid for the whole life time of the diagnostic.
745  OptimizationRemarkMissed(const char *PassName, const Function &Fn,
746  const DiagnosticLocation &Loc, const Twine &Msg)
748  PassName, Fn, Loc, Msg) {}
749 };
750 
751 /// Diagnostic information for optimization analysis remarks.
753 public:
754  /// \p PassName is the name of the pass emitting this diagnostic. If this name
755  /// matches the regular expression given in -Rpass-analysis=, then the
756  /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
757  /// remark (single-word, camel-case). \p Loc is the debug location and \p
758  /// CodeRegion is the region that the optimization operates on (currently only
759  /// block is supported).
760  OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
761  const DiagnosticLocation &Loc,
762  const Value *CodeRegion);
763 
764  /// This is ctor variant allows a pass to build an optimization remark
765  /// from an existing remark.
766  ///
767  /// This is useful when a transformation pass (e.g LV) wants to emit a remark
768  /// (\p Orig) generated by one of its analyses (e.g. LAA) as its own analysis
769  /// remark. The string \p Prepend will be emitted before the original
770  /// message.
771  OptimizationRemarkAnalysis(const char *PassName, StringRef Prepend,
772  const OptimizationRemarkAnalysis &Orig)
773  : DiagnosticInfoIROptimization(PassName, Prepend, Orig) {}
774 
775  /// Same as above but \p Inst is used to derive code region and debug
776  /// location.
777  OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
778  const Instruction *Inst);
779 
780  static bool classof(const DiagnosticInfo *DI) {
781  return DI->getKind() == DK_OptimizationRemarkAnalysis;
782  }
783 
784  /// \see DiagnosticInfoOptimizationBase::isEnabled.
785  bool isEnabled() const override;
786 
787  static const char *AlwaysPrint;
788 
789  bool shouldAlwaysPrint() const { return getPassName() == AlwaysPrint; }
790 
791 protected:
792  OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
793  const Function &Fn, const DiagnosticLocation &Loc,
794  const Twine &Msg)
795  : DiagnosticInfoIROptimization(Kind, DS_Remark, PassName, Fn, Loc, Msg) {}
796 
797  OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
798  StringRef RemarkName,
799  const DiagnosticLocation &Loc,
800  const Value *CodeRegion);
801 
802 private:
803  /// This is deprecated now and only used by the function API below.
804  /// \p PassName is the name of the pass emitting this diagnostic. If
805  /// this name matches the regular expression given in -Rpass-analysis=, then
806  /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
807  /// is being emitted. \p Loc is the location information to use in the
808  /// diagnostic. If line table information is available, the diagnostic will
809  /// include the source code location. \p Msg is the message to show. Note that
810  /// this class does not copy this message, so this reference must be valid for
811  /// the whole life time of the diagnostic.
812  OptimizationRemarkAnalysis(const char *PassName, const Function &Fn,
813  const DiagnosticLocation &Loc, const Twine &Msg)
815  PassName, Fn, Loc, Msg) {}
816 };
817 
818 /// Diagnostic information for optimization analysis remarks related to
819 /// floating-point non-commutativity.
821 public:
822  /// \p PassName is the name of the pass emitting this diagnostic. If this name
823  /// matches the regular expression given in -Rpass-analysis=, then the
824  /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
825  /// remark (single-word, camel-case). \p Loc is the debug location and \p
826  /// CodeRegion is the region that the optimization operates on (currently only
827  /// block is supported). The front-end will append its own message related to
828  /// options that address floating-point non-commutativity.
830  StringRef RemarkName,
831  const DiagnosticLocation &Loc,
832  const Value *CodeRegion)
834  PassName, RemarkName, Loc, CodeRegion) {}
835 
836  static bool classof(const DiagnosticInfo *DI) {
838  }
839 
840 private:
841  /// This is deprecated now and only used by the function API below.
842  /// \p PassName is the name of the pass emitting this diagnostic. If
843  /// this name matches the regular expression given in -Rpass-analysis=, then
844  /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
845  /// is being emitted. \p Loc is the location information to use in the
846  /// diagnostic. If line table information is available, the diagnostic will
847  /// include the source code location. \p Msg is the message to show. The
848  /// front-end will append its own message related to options that address
849  /// floating-point non-commutativity. Note that this class does not copy this
850  /// message, so this reference must be valid for the whole life time of the
851  /// diagnostic.
852  OptimizationRemarkAnalysisFPCommute(const char *PassName, const Function &Fn,
853  const DiagnosticLocation &Loc,
854  const Twine &Msg)
856  PassName, Fn, Loc, Msg) {}
857 };
858 
859 /// Diagnostic information for optimization analysis remarks related to
860 /// pointer aliasing.
862 public:
863  /// \p PassName is the name of the pass emitting this diagnostic. If this name
864  /// matches the regular expression given in -Rpass-analysis=, then the
865  /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
866  /// remark (single-word, camel-case). \p Loc is the debug location and \p
867  /// CodeRegion is the region that the optimization operates on (currently only
868  /// block is supported). The front-end will append its own message related to
869  /// options that address pointer aliasing legality.
870  OptimizationRemarkAnalysisAliasing(const char *PassName, StringRef RemarkName,
871  const DiagnosticLocation &Loc,
872  const Value *CodeRegion)
874  PassName, RemarkName, Loc, CodeRegion) {}
875 
876  static bool classof(const DiagnosticInfo *DI) {
878  }
879 
880 private:
881  /// This is deprecated now and only used by the function API below.
882  /// \p PassName is the name of the pass emitting this diagnostic. If
883  /// this name matches the regular expression given in -Rpass-analysis=, then
884  /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
885  /// is being emitted. \p Loc is the location information to use in the
886  /// diagnostic. If line table information is available, the diagnostic will
887  /// include the source code location. \p Msg is the message to show. The
888  /// front-end will append its own message related to options that address
889  /// pointer aliasing legality. Note that this class does not copy this
890  /// message, so this reference must be valid for the whole life time of the
891  /// diagnostic.
892  OptimizationRemarkAnalysisAliasing(const char *PassName, const Function &Fn,
893  const DiagnosticLocation &Loc,
894  const Twine &Msg)
896  PassName, Fn, Loc, Msg) {}
897 };
898 
899 /// Diagnostic information for machine IR parser.
901  const SMDiagnostic &Diagnostic;
902 
903 public:
905  const SMDiagnostic &Diagnostic)
906  : DiagnosticInfo(DK_MIRParser, Severity), Diagnostic(Diagnostic) {}
907 
908  const SMDiagnostic &getDiagnostic() const { return Diagnostic; }
909 
910  void print(DiagnosticPrinter &DP) const override;
911 
912  static bool classof(const DiagnosticInfo *DI) {
913  return DI->getKind() == DK_MIRParser;
914  }
915 };
916 
917 /// Diagnostic information for ISel fallback path.
919  /// The function that is concerned by this diagnostic.
920  const Function &Fn;
921 
922 public:
924  DiagnosticSeverity Severity = DS_Warning)
925  : DiagnosticInfo(DK_ISelFallback, Severity), Fn(Fn) {}
926 
927  const Function &getFunction() const { return Fn; }
928 
929  void print(DiagnosticPrinter &DP) const override;
930 
931  static bool classof(const DiagnosticInfo *DI) {
932  return DI->getKind() == DK_ISelFallback;
933  }
934 };
935 
936 // Create wrappers for C Binding types (see CBindingWrapping.h).
938 
939 /// Diagnostic information for optimization failures.
941 public:
942  /// \p Fn is the function where the diagnostic is being emitted. \p Loc is
943  /// the location information to use in the diagnostic. If line table
944  /// information is available, the diagnostic will include the source code
945  /// location. \p Msg is the message to show. Note that this class does not
946  /// copy this message, so this reference must be valid for the whole life time
947  /// of the diagnostic.
949  const DiagnosticLocation &Loc,
950  const Twine &Msg)
951  : DiagnosticInfoIROptimization(DK_OptimizationFailure, DS_Warning,
952  nullptr, Fn, Loc, Msg) {}
953 
954  /// \p PassName is the name of the pass emitting this diagnostic. \p
955  /// RemarkName is a textual identifier for the remark (single-word,
956  /// camel-case). \p Loc is the debug location and \p CodeRegion is the
957  /// region that the optimization operates on (currently basic block is
958  /// supported).
959  DiagnosticInfoOptimizationFailure(const char *PassName, StringRef RemarkName,
960  const DiagnosticLocation &Loc,
961  const Value *CodeRegion);
962 
963  static bool classof(const DiagnosticInfo *DI) {
964  return DI->getKind() == DK_OptimizationFailure;
965  }
966 
967  /// \see DiagnosticInfoOptimizationBase::isEnabled.
968  bool isEnabled() const override;
969 };
970 
971 /// Diagnostic information for unsupported feature in backend.
973 private:
974  Twine Msg;
975 
976 public:
977  /// \p Fn is the function where the diagnostic is being emitted. \p Loc is
978  /// the location information to use in the diagnostic. If line table
979  /// information is available, the diagnostic will include the source code
980  /// location. \p Msg is the message to show. Note that this class does not
981  /// copy this message, so this reference must be valid for the whole life time
982  /// of the diagnostic.
984  const Function &Fn, const Twine &Msg,
985  const DiagnosticLocation &Loc = DiagnosticLocation(),
986  DiagnosticSeverity Severity = DS_Error)
987  : DiagnosticInfoWithLocationBase(DK_Unsupported, Severity, Fn, Loc),
988  Msg(Msg) {}
989 
990  static bool classof(const DiagnosticInfo *DI) {
991  return DI->getKind() == DK_Unsupported;
992  }
993 
994  const Twine &getMessage() const { return Msg; }
995 
996  void print(DiagnosticPrinter &DP) const override;
997 };
998 
999 namespace yaml {
1001  static void mapping(IO &io, DiagnosticInfoOptimizationBase *&OptDiag);
1002 };
1003 } // namespace yaml
1004 
1005 } // end namespace llvm
1006 
1007 #endif // LLVM_IR_DIAGNOSTICINFO_H
const char * PassName
Name of the pass that triggers this report.
DiagnosticInfoSampleProfile(StringRef FileName, const Twine &Msg, DiagnosticSeverity Severity=DS_Error)
DiagnosticInfoISelFallback(const Function &Fn, DiagnosticSeverity Severity=DS_Warning)
Diagnostic information for ISel fallback path.
DiagnosticInfoSampleProfile(StringRef FileName, unsigned LineNum, const Twine &Msg, DiagnosticSeverity Severity=DS_Error)
DiagnosticKind
Defines the different supported kind of a diagnostic.
Diagnostic information for missed-optimization remarks.
Diagnostic information for unsupported feature in backend.
DiagnosticInfoResourceLimit(const Function &Fn, const char *ResourceName, uint64_t ResourceSize, DiagnosticSeverity Severity=DS_Warning, DiagnosticKind Kind=DK_ResourceLimit, uint64_t ResourceLimit=0)
The function that is concerned by this stack size diagnostic.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
const Function & getFunction() const
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
DiagnosticInfoInlineAsm(const Twine &MsgStr, DiagnosticSeverity Severity=DS_Error)
MsgStr is the message to be reported to the frontend.
Diagnostic information for the PGO profiler.
static bool classof(const DiagnosticInfo *DI)
DiagnosticInfoMIRParser(DiagnosticSeverity Severity, const SMDiagnostic &Diagnostic)
const Twine & getMsg() const
Used to set IsVerbose via the stream interface.
Diagnostic information for machine IR parser.
unsigned getLine() const
DiagnosticInfoInlineAsm(unsigned LocCookie, const Twine &MsgStr, DiagnosticSeverity Severity=DS_Error)
LocCookie if non-zero gives the line number for this report.
A debug info location.
Definition: DebugLoc.h:34
const char * getFileName() const
static bool classof(const DiagnosticInfo *DI)
OptimizationRemarkAnalysisAliasing(const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc, const Value *CodeRegion)
PassName is the name of the pass emitting this diagnostic.
DiagnosticInfoWithLocationBase(enum DiagnosticKind Kind, enum DiagnosticSeverity Severity, const Function &Fn, const DiagnosticLocation &Loc)
Fn is the function where the diagnostic is being emitted.
When an instance of this is inserted into the stream, the arguments following will not appear in the ...
Diagnostic information for stripping invalid debug metadata.
const Twine & getMsgStr() const
virtual ~DiagnosticInfo()=default
DiagnosticLocation getLocation() const
static bool classof(const DiagnosticInfo *DI)
DiagnosticInfoIgnoringInvalidDebugMetadata(const Module &M, DiagnosticSeverity Severity=DS_Warning)
The module that is concerned by this debug metadata version diagnostic.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
DiagnosticInfoStackSize(const Function &Fn, uint64_t StackSize, DiagnosticSeverity Severity=DS_Warning, uint64_t StackLimit=0)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
Diagnostic information for optimization failures.
const SMDiagnostic & getDiagnostic() const
Diagnostic information for optimization analysis remarks.
Common features for diagnostics with an associated location.
const Function & getFunction() const
Interface for custom diagnostic printing.
DiagnosticInfo(int Kind, DiagnosticSeverity Severity)
Diagnostic information for stack size etc.
Subprogram description.
static bool classof(const DiagnosticInfo *DI)
const Instruction * getInstruction() const
bool isLocationAvailable() const
Return true if location information is available for this diagnostic.
DiagnosticInfoIROptimization(const char *PassName, StringRef Prepend, const DiagnosticInfoIROptimization &Orig)
This is ctor variant allows a pass to build an optimization remark from an existing remark...
const Twine & getMessage() const
StringRef RemarkName
Textual identifier for the remark (single-word, camel-case).
Diagnostic information for optimization analysis remarks related to pointer aliasing.
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:221
DiagnosticInfoOptimizationBase(enum DiagnosticKind Kind, enum DiagnosticSeverity Severity, const char *PassName, StringRef RemarkName, const Function &Fn, const DiagnosticLocation &Loc)
PassName is the name of the pass emitting this diagnostic.
DiagnosticInfoUnsupported(const Function &Fn, const Twine &Msg, const DiagnosticLocation &Loc=DiagnosticLocation(), DiagnosticSeverity Severity=DS_Error)
Fn is the function where the diagnostic is being emitted.
SmallVector< Argument, 4 > Args
Arguments collected via the streaming interface.
const char * getResourceName() const
This is the base abstract class for diagnostic reporting in the backend.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const Function & getFunction() const
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
static bool classof(const DiagnosticInfo *DI)
#define H(x, y, z)
Definition: MD5.cpp:57
Diagnostic information for applied optimization remarks.
static bool classof(const DiagnosticInfo *DI)
DiagnosticInfoPGOProfile(const char *FileName, const Twine &Msg, DiagnosticSeverity Severity=DS_Error)
const Value * getCodeRegion() const
Common features for diagnostics dealing with optimization remarks that are used by IR passes...
DiagnosticInfoIROptimization(enum DiagnosticKind Kind, enum DiagnosticSeverity Severity, const char *PassName, StringRef RemarkName, const Function &Fn, const DiagnosticLocation &Loc, const Value *CodeRegion=nullptr)
PassName is the name of the pass emitting this diagnostic.
OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName, const Function &Fn, const DiagnosticLocation &Loc, const Twine &Msg)
static bool classof(const DiagnosticInfo *DI)
static bool classof(const DiagnosticInfo *DI)
Used in the streaming interface as the general argument type.
static bool classof(const DiagnosticInfo *DI)
struct LLVMOpaqueDiagnosticInfo * LLVMDiagnosticInfoRef
Definition: Types.h:149
Diagnostic information for inline asm reporting.
virtual void print(DiagnosticPrinter &DP) const =0
Print using the given DP a user-friendly message.
Diagnostic information for optimization analysis remarks related to floating-point non-commutativity...
static bool classof(const DiagnosticInfo *DI)
static bool classof(const DiagnosticInfo *DI)
Common features for diagnostics dealing with optimization remarks that are used by both IR and MIR pa...
static bool classof(const DiagnosticInfo *DI)
static bool classof(const DiagnosticInfo *DI)
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
static bool classof(const DiagnosticInfo *DI)
static bool classof(const DiagnosticInfo *DI)
DiagnosticInfoDebugMetadataVersion(const Module &M, unsigned MetadataVersion, DiagnosticSeverity Severity=DS_Warning)
The module that is concerned by this debug metadata version diagnostic.
int getNextAvailablePluginDiagnosticKind()
Get the next available kind ID for a plugin diagnostic.
OptimizationRemarkAnalysisFPCommute(const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc, const Value *CodeRegion)
PassName is the name of the pass emitting this diagnostic.
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
Diagnostic information for debug metadata version reporting.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
DiagnosticInfoSampleProfile(const Twine &Msg, DiagnosticSeverity Severity=DS_Error)
DiagnosticSeverity getSeverity() const
static bool classof(const DiagnosticInfo *DI)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2039
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:18
static bool classof(const DiagnosticInfo *DI)
static bool isEnabled(StringRef Feature)
Return true if enable flag; &#39;+&#39;.
Optional< uint64_t > getHotness() const
static MemoryLocation getLocation(Instruction *I, AliasAnalysis *AA)
OptimizationRemarkAnalysis(const char *PassName, StringRef Prepend, const OptimizationRemarkAnalysis &Orig)
This is ctor variant allows a pass to build an optimization remark from an existing remark...
LLVM Value Representation.
Definition: Value.h:73
Optional< uint64_t > Hotness
If profile information is available, this is the number of times the corresponding code was executed ...
void setHotness(Optional< uint64_t > H)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Diagnostic information for the sample profiler.
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1232
std::function< void(const DiagnosticInfo &)> DiagnosticHandlerFunction
static bool classof(const DiagnosticInfo *DI)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
unsigned getColumn() const
DiagnosticInfoIROptimization(enum DiagnosticKind Kind, enum DiagnosticSeverity Severity, const char *PassName, const Function &Fn, const DiagnosticLocation &Loc, const Twine &Msg)
Legacy interface.
DiagnosticInfoOptimizationFailure(const Function &Fn, const DiagnosticLocation &Loc, const Twine &Msg)
Fn is the function where the diagnostic is being emitted.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:260