MLIR  14.0.0git
Diagnostics.h
Go to the documentation of this file.
1 //===- Diagnostics.h - MLIR Diagnostics -------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines utilities for emitting diagnostics.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_IR_DIAGNOSTICS_H
14 #define MLIR_IR_DIAGNOSTICS_H
15 
16 #include "mlir/IR/Location.h"
17 #include <functional>
18 
19 namespace llvm {
20 class MemoryBuffer;
21 class SMLoc;
22 class SourceMgr;
23 } // namespace llvm
24 
25 namespace mlir {
26 class DiagnosticEngine;
27 struct LogicalResult;
28 class MLIRContext;
29 class Operation;
30 class OperationName;
31 class OpPrintingFlags;
32 class Type;
33 class Value;
34 
35 namespace detail {
36 struct DiagnosticEngineImpl;
37 } // namespace detail
38 
39 /// Defines the different supported severity of a diagnostic.
40 enum class DiagnosticSeverity {
41  Note,
42  Warning,
43  Error,
44  Remark,
45 };
46 
47 //===----------------------------------------------------------------------===//
48 // DiagnosticArgument
49 //===----------------------------------------------------------------------===//
50 
51 /// A variant type that holds a single argument for a diagnostic.
53 public:
54  /// Note: The constructors below are only exposed due to problems accessing
55  /// constructors from type traits, they should not be used directly by users.
56  // Construct from an Attribute.
57  explicit DiagnosticArgument(Attribute attr);
58  // Construct from a floating point number.
59  explicit DiagnosticArgument(double val)
60  : kind(DiagnosticArgumentKind::Double), doubleVal(val) {}
61  explicit DiagnosticArgument(float val) : DiagnosticArgument(double(val)) {}
62  // Construct from a signed integer.
63  template <typename T>
65  T val,
66  typename std::enable_if<std::is_signed<T>::value &&
67  std::numeric_limits<T>::is_integer &&
68  sizeof(T) <= sizeof(int64_t)>::type * = nullptr)
69  : kind(DiagnosticArgumentKind::Integer), opaqueVal(int64_t(val)) {}
70  // Construct from an unsigned integer.
71  template <typename T>
73  T val,
74  typename std::enable_if<std::is_unsigned<T>::value &&
75  std::numeric_limits<T>::is_integer &&
76  sizeof(T) <= sizeof(uint64_t)>::type * = nullptr)
77  : kind(DiagnosticArgumentKind::Unsigned), opaqueVal(uint64_t(val)) {}
78  // Construct from a string reference.
79  explicit DiagnosticArgument(StringRef val)
80  : kind(DiagnosticArgumentKind::String), stringVal(val) {}
81  // Construct from a Type.
82  explicit DiagnosticArgument(Type val);
83 
84  /// Enum that represents the different kinds of diagnostic arguments
85  /// supported.
87  Attribute,
88  Double,
89  Integer,
90  String,
91  Type,
92  Unsigned,
93  };
94 
95  /// Outputs this argument to a stream.
96  void print(raw_ostream &os) const;
97 
98  /// Returns the kind of this argument.
99  DiagnosticArgumentKind getKind() const { return kind; }
100 
101  /// Returns this argument as an Attribute.
102  Attribute getAsAttribute() const;
103 
104  /// Returns this argument as a double.
105  double getAsDouble() const {
106  assert(getKind() == DiagnosticArgumentKind::Double);
107  return doubleVal;
108  }
109 
110  /// Returns this argument as a signed integer.
111  int64_t getAsInteger() const {
112  assert(getKind() == DiagnosticArgumentKind::Integer);
113  return static_cast<int64_t>(opaqueVal);
114  }
115 
116  /// Returns this argument as a string.
117  StringRef getAsString() const {
118  assert(getKind() == DiagnosticArgumentKind::String);
119  return stringVal;
120  }
121 
122  /// Returns this argument as a Type.
123  Type getAsType() const;
124 
125  /// Returns this argument as an unsigned integer.
126  uint64_t getAsUnsigned() const {
127  assert(getKind() == DiagnosticArgumentKind::Unsigned);
128  return static_cast<uint64_t>(opaqueVal);
129  }
130 
131 private:
132  friend class Diagnostic;
133 
134  /// The kind of this argument.
136 
137  /// The value of this argument.
138  union {
139  double doubleVal;
140  intptr_t opaqueVal;
141  StringRef stringVal;
142  };
143 };
144 
145 inline raw_ostream &operator<<(raw_ostream &os, const DiagnosticArgument &arg) {
146  arg.print(os);
147  return os;
148 }
149 
150 //===----------------------------------------------------------------------===//
151 // Diagnostic
152 //===----------------------------------------------------------------------===//
153 
154 /// This class contains all of the information necessary to report a diagnostic
155 /// to the DiagnosticEngine. It should generally not be constructed directly,
156 /// and instead used transitively via InFlightDiagnostic.
157 class Diagnostic {
158  using NoteVector = std::vector<std::unique_ptr<Diagnostic>>;
159 
160 public:
162  : loc(loc), severity(severity) {}
163  Diagnostic(Diagnostic &&) = default;
164  Diagnostic &operator=(Diagnostic &&) = default;
165 
166  /// Returns the severity of this diagnostic.
167  DiagnosticSeverity getSeverity() const { return severity; }
168 
169  /// Returns the source location for this diagnostic.
170  Location getLocation() const { return loc; }
171 
172  /// Returns the current list of diagnostic arguments.
174  ArrayRef<DiagnosticArgument> getArguments() const { return arguments; }
175 
176  /// Stream operator for inserting new diagnostic arguments.
177  template <typename Arg>
178  typename std::enable_if<
181  Diagnostic &>::type
182  operator<<(Arg &&val) {
183  arguments.push_back(DiagnosticArgument(std::forward<Arg>(val)));
184  return *this;
185  }
186  Diagnostic &operator<<(StringAttr val);
187 
188  /// Stream in a string literal.
189  Diagnostic &operator<<(const char *val) {
190  arguments.push_back(DiagnosticArgument(val));
191  return *this;
192  }
193 
194  /// Stream in a Twine argument.
195  Diagnostic &operator<<(char val);
196  Diagnostic &operator<<(const Twine &val);
197  Diagnostic &operator<<(Twine &&val);
198 
199  /// Stream in an OperationName.
201 
202  /// Stream in an Operation.
205  return *this << *val;
206  }
207  /// Append an operation with the given printing flags.
208  Diagnostic &appendOp(Operation &val, const OpPrintingFlags &flags);
209 
210  /// Stream in a Value.
212 
213  /// Stream in a range.
214  template <typename T, typename ValueT = llvm::detail::ValueOfRange<T>>
216  Diagnostic &>
217  operator<<(T &&range) {
218  return appendRange(range);
219  }
220 
221  /// Append a range to the diagnostic. The default delimiter between elements
222  /// is ','.
223  template <typename T>
224  Diagnostic &appendRange(const T &c, const char *delim = ", ") {
225  llvm::interleave(
226  c, [this](const auto &a) { *this << a; }, [&]() { *this << delim; });
227  return *this;
228  }
229 
230  /// Append arguments to the diagnostic.
231  template <typename Arg1, typename Arg2, typename... Args>
232  Diagnostic &append(Arg1 &&arg1, Arg2 &&arg2, Args &&... args) {
233  append(std::forward<Arg1>(arg1));
234  return append(std::forward<Arg2>(arg2), std::forward<Args>(args)...);
235  }
236  /// Append one argument to the diagnostic.
237  template <typename Arg> Diagnostic &append(Arg &&arg) {
238  *this << std::forward<Arg>(arg);
239  return *this;
240  }
241 
242  /// Outputs this diagnostic to a stream.
243  void print(raw_ostream &os) const;
244 
245  /// Converts the diagnostic to a string.
246  std::string str() const;
247 
248  /// Attaches a note to this diagnostic. A new location may be optionally
249  /// provided, if not, then the location defaults to the one specified for this
250  /// diagnostic. Notes may not be attached to other notes.
251  Diagnostic &attachNote(Optional<Location> noteLoc = llvm::None);
252 
253  using note_iterator = llvm::pointee_iterator<NoteVector::iterator>;
254  using const_note_iterator =
255  llvm::pointee_iterator<NoteVector::const_iterator>;
256 
257  /// Returns the notes held by this diagnostic.
259  return llvm::make_pointee_range(notes);
260  }
262  return llvm::make_pointee_range(notes);
263  }
264 
265  /// Allow a diagnostic to be converted to 'failure'.
266  operator LogicalResult() const;
267 
268 private:
269  Diagnostic(const Diagnostic &rhs) = delete;
270  Diagnostic &operator=(const Diagnostic &rhs) = delete;
271 
272  /// The source location.
273  Location loc;
274 
275  /// The severity of this diagnostic.
276  DiagnosticSeverity severity;
277 
278  /// The current list of arguments.
280 
281  /// A list of string values used as arguments. This is used to guarantee the
282  /// liveness of non-constant strings used in diagnostics.
283  std::vector<std::unique_ptr<char[]>> strings;
284 
285  /// A list of attached notes.
286  NoteVector notes;
287 };
288 
289 inline raw_ostream &operator<<(raw_ostream &os, const Diagnostic &diag) {
290  diag.print(os);
291  return os;
292 }
293 
294 //===----------------------------------------------------------------------===//
295 // InFlightDiagnostic
296 //===----------------------------------------------------------------------===//
297 
298 /// This class represents a diagnostic that is inflight and set to be reported.
299 /// This allows for last minute modifications of the diagnostic before it is
300 /// emitted by a DiagnosticEngine.
302 public:
303  InFlightDiagnostic() = default;
305  : owner(rhs.owner), impl(std::move(rhs.impl)) {
306  // Reset the rhs diagnostic.
307  rhs.impl.reset();
308  rhs.abandon();
309  }
311  if (isInFlight())
312  report();
313  }
314 
315  /// Stream operator for new diagnostic arguments.
316  template <typename Arg> InFlightDiagnostic &operator<<(Arg &&arg) & {
317  return append(std::forward<Arg>(arg));
318  }
319  template <typename Arg> InFlightDiagnostic &&operator<<(Arg &&arg) && {
320  return std::move(append(std::forward<Arg>(arg)));
321  }
322 
323  /// Append arguments to the diagnostic.
324  template <typename... Args> InFlightDiagnostic &append(Args &&... args) & {
325  assert(isActive() && "diagnostic not active");
326  if (isInFlight())
327  impl->append(std::forward<Args>(args)...);
328  return *this;
329  }
330  template <typename... Args> InFlightDiagnostic &&append(Args &&... args) && {
331  return std::move(append(std::forward<Args>(args)...));
332  }
333 
334  /// Attaches a note to this diagnostic.
335  Diagnostic &attachNote(Optional<Location> noteLoc = llvm::None) {
336  assert(isActive() && "diagnostic not active");
337  return impl->attachNote(noteLoc);
338  }
339 
340  /// Reports the diagnostic to the engine.
341  void report();
342 
343  /// Abandons this diagnostic so that it will no longer be reported.
344  void abandon();
345 
346  /// Allow an inflight diagnostic to be converted to 'failure', otherwise
347  /// 'success' if this is an empty diagnostic.
348  operator LogicalResult() const;
349 
350 private:
351  InFlightDiagnostic &operator=(const InFlightDiagnostic &) = delete;
352  InFlightDiagnostic &operator=(InFlightDiagnostic &&) = delete;
354  : owner(owner), impl(std::move(rhs)) {}
355 
356  /// Returns true if the diagnostic is still active, i.e. it has a live
357  /// diagnostic.
358  bool isActive() const { return impl.hasValue(); }
359 
360  /// Returns true if the diagnostic is still in flight to be reported.
361  bool isInFlight() const { return owner; }
362 
363  // Allow access to the constructor.
364  friend DiagnosticEngine;
365 
366  /// The engine that this diagnostic is to report to.
367  DiagnosticEngine *owner = nullptr;
368 
369  /// The raw diagnostic that is inflight to be reported.
371 };
372 
373 //===----------------------------------------------------------------------===//
374 // DiagnosticEngine
375 //===----------------------------------------------------------------------===//
376 
377 /// This class is the main interface for diagnostics. The DiagnosticEngine
378 /// manages the registration of diagnostic handlers as well as the core API for
379 /// diagnostic emission. This class should not be constructed directly, but
380 /// instead interfaced with via an MLIRContext instance.
382 public:
383  ~DiagnosticEngine();
384 
385  // Diagnostic handler registration and use. MLIR supports the ability for the
386  // IR to carry arbitrary metadata about operation location information. If a
387  // problem is detected by the compiler, it can invoke the emitError /
388  // emitWarning / emitRemark method on an Operation and have it get reported
389  // through this interface.
390  //
391  // Tools using MLIR are encouraged to register error handlers and define a
392  // schema for their location information. If they don't, then warnings and
393  // notes will be dropped and errors will be emitted to errs.
394 
395  /// The handler type for MLIR diagnostics. This function takes a diagnostic as
396  /// input, and returns success if the handler has fully processed this
397  /// diagnostic. Returns failure otherwise.
398  using HandlerTy = std::function<LogicalResult(Diagnostic &)>;
399 
400  /// A handle to a specific registered handler object.
401  using HandlerID = uint64_t;
402 
403  /// Register a new handler for diagnostics to the engine. Diagnostics are
404  /// process by handlers in stack-like order, meaning that the last added
405  /// handlers will process diagnostics first. This function returns a unique
406  /// identifier for the registered handler, which can be used to unregister
407  /// this handler at a later time.
408  HandlerID registerHandler(const HandlerTy &handler);
409 
410  /// Set the diagnostic handler with a function that returns void. This is a
411  /// convenient wrapper for handlers that always completely process the given
412  /// diagnostic.
413  template <typename FuncTy, typename RetT = decltype(std::declval<FuncTy>()(
414  std::declval<Diagnostic &>()))>
416  registerHandler(FuncTy &&handler) {
417  return registerHandler([=](Diagnostic &diag) {
418  handler(diag);
419  return success();
420  });
421  }
422 
423  /// Erase the registered diagnostic handler with the given identifier.
424  void eraseHandler(HandlerID id);
425 
426  /// Create a new inflight diagnostic with the given location and severity.
428  assert(severity != DiagnosticSeverity::Note &&
429  "notes should not be emitted directly");
430  return InFlightDiagnostic(this, Diagnostic(loc, severity));
431  }
432 
433  /// Emit a diagnostic using the registered issue handler if present, or with
434  /// the default behavior if not. The diagnostic instance is consumed in the
435  /// process.
436  void emit(Diagnostic &&diag);
437 
438 private:
439  friend class MLIRContextImpl;
441 
442  /// The internal implementation of the DiagnosticEngine.
443  std::unique_ptr<detail::DiagnosticEngineImpl> impl;
444 };
445 
446 /// Utility method to emit an error message using this location.
448 InFlightDiagnostic emitError(Location loc, const Twine &message);
449 
450 /// Utility method to emit a warning message using this location.
452 InFlightDiagnostic emitWarning(Location loc, const Twine &message);
453 
454 /// Utility method to emit a remark message using this location.
456 InFlightDiagnostic emitRemark(Location loc, const Twine &message);
457 
458 /// Overloads of the above emission functions that take an optionally null
459 /// location. If the location is null, no diagnostic is emitted and a failure is
460 /// returned. Given that the provided location may be null, these methods take
461 /// the diagnostic arguments directly instead of relying on the returned
462 /// InFlightDiagnostic.
463 template <typename... Args>
465  if (loc)
466  return emitError(*loc).append(std::forward<Args>(args)...);
467  return failure();
468 }
469 template <typename... Args>
471  if (loc)
472  return emitWarning(*loc).append(std::forward<Args>(args)...);
473  return failure();
474 }
475 template <typename... Args>
477  if (loc)
478  return emitRemark(*loc).append(std::forward<Args>(args)...);
479  return failure();
480 }
481 
482 //===----------------------------------------------------------------------===//
483 // ScopedDiagnosticHandler
484 //===----------------------------------------------------------------------===//
485 
486 /// This diagnostic handler is a simple RAII class that registers and erases a
487 /// diagnostic handler on a given context. This class can be either be used
488 /// directly, or in conjunction with a derived diagnostic handler.
490 public:
491  explicit ScopedDiagnosticHandler(MLIRContext *ctx) : handlerID(0), ctx(ctx) {}
492  template <typename FuncTy>
493  ScopedDiagnosticHandler(MLIRContext *ctx, FuncTy &&handler)
494  : handlerID(0), ctx(ctx) {
495  setHandler(std::forward<FuncTy>(handler));
496  }
498 
499 protected:
500  /// Set the handler to manage via RAII.
501  template <typename FuncTy> void setHandler(FuncTy &&handler) {
502  auto &diagEngine = ctx->getDiagEngine();
503  if (handlerID)
504  diagEngine.eraseHandler(handlerID);
505  handlerID = diagEngine.registerHandler(std::forward<FuncTy>(handler));
506  }
507 
508 private:
509  /// The unique id for the scoped handler.
510  DiagnosticEngine::HandlerID handlerID;
511 
512  /// The context to erase the handler from.
513  MLIRContext *ctx;
514 };
515 
516 //===----------------------------------------------------------------------===//
517 // SourceMgrDiagnosticHandler
518 //===----------------------------------------------------------------------===//
519 
520 namespace detail {
521 struct SourceMgrDiagnosticHandlerImpl;
522 } // namespace detail
523 
524 /// This class is a utility diagnostic handler for use with llvm::SourceMgr.
526 public:
527  /// This type represents a functor used to filter out locations when printing
528  /// a diagnostic. It should return true if the provided location is okay to
529  /// display, false otherwise. If all locations in a diagnostic are filtered
530  /// out, the first location is used as the sole location. When deciding
531  /// whether or not to filter a location, this function should not recurse into
532  /// any nested location. This recursion is handled automatically by the
533  /// caller.
534  using ShouldShowLocFn = llvm::unique_function<bool(Location)>;
535 
536  SourceMgrDiagnosticHandler(llvm::SourceMgr &mgr, MLIRContext *ctx,
537  raw_ostream &os,
538  ShouldShowLocFn &&shouldShowLocFn = {});
539  SourceMgrDiagnosticHandler(llvm::SourceMgr &mgr, MLIRContext *ctx,
540  ShouldShowLocFn &&shouldShowLocFn = {});
542 
543  /// Emit the given diagnostic information with the held source manager.
544  void emitDiagnostic(Location loc, Twine message, DiagnosticSeverity kind,
545  bool displaySourceLine = true);
546 
547 protected:
548  /// Emit the given diagnostic with the held source manager.
549  void emitDiagnostic(Diagnostic &diag);
550 
551  /// Get a memory buffer for the given file, or nullptr if no file is
552  /// available.
553  const llvm::MemoryBuffer *getBufferForFile(StringRef filename);
554 
555  /// The source manager that we are wrapping.
556  llvm::SourceMgr &mgr;
557 
558  /// The output stream to use when printing diagnostics.
559  raw_ostream &os;
560 
561  /// A functor used when determining if a location for a diagnostic should be
562  /// shown. If null, all locations should be shown.
564 
565 private:
566  /// Convert a location into the given memory buffer into an SMLoc.
567  llvm::SMLoc convertLocToSMLoc(FileLineColLoc loc);
568 
569  /// Given a location, returns the first nested location (including 'loc') that
570  /// can be shown to the user.
571  Optional<Location> findLocToShow(Location loc);
572 
573  /// The maximum depth that a call stack will be printed.
574  /// TODO: This should be a tunable flag.
575  unsigned callStackLimit = 10;
576 
577  std::unique_ptr<detail::SourceMgrDiagnosticHandlerImpl> impl;
578 };
579 
580 //===----------------------------------------------------------------------===//
581 // SourceMgrDiagnosticVerifierHandler
582 //===----------------------------------------------------------------------===//
583 
584 namespace detail {
585 struct SourceMgrDiagnosticVerifierHandlerImpl;
586 } // namespace detail
587 
588 /// This class is a utility diagnostic handler for use with llvm::SourceMgr that
589 /// verifies that emitted diagnostics match 'expected-*' lines on the
590 /// corresponding line of the source file.
592 public:
593  SourceMgrDiagnosticVerifierHandler(llvm::SourceMgr &srcMgr, MLIRContext *ctx,
594  raw_ostream &out);
595  SourceMgrDiagnosticVerifierHandler(llvm::SourceMgr &srcMgr, MLIRContext *ctx);
597 
598  /// Returns the status of the handler and verifies that all expected
599  /// diagnostics were emitted. This return success if all diagnostics were
600  /// verified correctly, failure otherwise.
602 
603 private:
604  /// Process a single diagnostic.
605  void process(Diagnostic &diag);
606 
607  /// Process a FileLineColLoc diagnostic.
608  void process(FileLineColLoc loc, StringRef msg, DiagnosticSeverity kind);
609 
610  std::unique_ptr<detail::SourceMgrDiagnosticVerifierHandlerImpl> impl;
611 };
612 
613 //===----------------------------------------------------------------------===//
614 // ParallelDiagnosticHandler
615 //===----------------------------------------------------------------------===//
616 
617 namespace detail {
618 struct ParallelDiagnosticHandlerImpl;
619 } // namespace detail
620 
621 /// This class is a utility diagnostic handler for use when multi-threading some
622 /// part of the compiler where diagnostics may be emitted. This handler ensures
623 /// a deterministic ordering to the emitted diagnostics that mirrors that of a
624 /// single-threaded compilation.
626 public:
629 
630  /// Set the order id for the current thread. This is required to be set by
631  /// each thread that will be emitting diagnostics to this handler. The orderID
632  /// corresponds to the order in which diagnostics would be emitted when
633  /// executing synchronously. For example, if we were processing a list
634  /// of operations [a, b, c] on a single-thread. Diagnostics emitted while
635  /// processing operation 'a' would be emitted before those for 'b' or 'c'.
636  /// This corresponds 1-1 with the 'orderID'. The thread that is processing 'a'
637  /// should set the orderID to '0'; the thread processing 'b' should set it to
638  /// '1'; and so on and so forth. This provides a way for the handler to
639  /// deterministically order the diagnostics that it receives given the thread
640  /// that it is receiving on.
641  void setOrderIDForThread(size_t orderID);
642 
643  /// Remove the order id for the current thread. This removes the thread from
644  /// diagnostics tracking.
645  void eraseOrderIDForThread();
646 
647 private:
648  std::unique_ptr<detail::ParallelDiagnosticHandlerImpl> impl;
649 };
650 } // namespace mlir
651 
652 #endif
Include the generated interface declarations.
static std::string diag(llvm::Value &v)
Diagnostic & operator<<(Operation *val)
Definition: Diagnostics.h:204
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:28
InFlightDiagnostic(InFlightDiagnostic &&rhs)
Definition: Diagnostics.h:304
void setHandler(FuncTy &&handler)
Set the handler to manage via RAII.
Definition: Diagnostics.h:501
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:301
LogicalResult emitOptionalRemark(Optional< Location > loc, Args &&... args)
Definition: Diagnostics.h:476
llvm::unique_function< bool(Location)> ShouldShowLocFn
This type represents a functor used to filter out locations when printing a diagnostic.
Definition: Diagnostics.h:534
This is the implementation of the MLIRContext class, using the pImpl idiom.
This diagnostic handler is a simple RAII class that registers and erases a diagnostic handler on a gi...
Definition: Diagnostics.h:489
LogicalResult verify(Operation *op)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs, on this operation and any nested operations.
Definition: Verifier.cpp:353
uint64_t getAsUnsigned() const
Returns this argument as an unsigned integer.
Definition: Diagnostics.h:126
Location getLocation() const
Returns the source location for this diagnostic.
Definition: Diagnostics.h:170
DiagnosticArgument(T val, typename std::enable_if< std::is_unsigned< T >::value &&std::numeric_limits< T >::is_integer &&sizeof(T)<=sizeof(uint64_t)>::type *=nullptr)
Definition: Diagnostics.h:72
DiagnosticArgument(T val, typename std::enable_if< std::is_signed< T >::value &&std::numeric_limits< T >::is_integer &&sizeof(T)<=sizeof(int64_t)>::type *=nullptr)
Definition: Diagnostics.h:64
void print(OpAsmPrinter &p, FunctionLibraryOp op)
Definition: Shape.cpp:1112
int64_t getAsInteger() const
Returns this argument as a signed integer.
Definition: Diagnostics.h:111
void print(raw_ostream &os) const
Outputs this argument to a stream.
Definition: Diagnostics.cpp:57
InFlightDiagnostic emitRemark(Location loc, const Twine &message)
DiagnosticArgument(double val)
Definition: Diagnostics.h:59
DiagnosticSeverity getSeverity() const
Returns the severity of this diagnostic.
Definition: Diagnostics.h:167
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
Definition: Diagnostics.h:40
static constexpr const bool value
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:48
LogicalResult emitOptionalError(Optional< Location > loc, Args &&... args)
Overloads of the above emission functions that take an optionally null location.
Definition: Diagnostics.h:464
InFlightDiagnostic emitWarning(Location loc, const Twine &message)
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
This class contains all of the information necessary to report a diagnostic to the DiagnosticEngine...
Definition: Diagnostics.h:157
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
This class is a utility diagnostic handler for use when multi-threading some part of the compiler whe...
Definition: Diagnostics.h:625
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
InFlightDiagnostic && append(Args &&... args) &&
Definition: Diagnostics.h:330
LogicalResult emitOptionalWarning(Optional< Location > loc, Args &&... args)
Definition: Diagnostics.h:470
uint64_t HandlerID
A handle to a specific registered handler object.
Definition: Diagnostics.h:401
StringRef getAsString() const
Returns this argument as a string.
Definition: Diagnostics.h:117
raw_ostream & os
The output stream to use when printing diagnostics.
Definition: Diagnostics.h:559
void print(raw_ostream &os) const
Outputs this diagnostic to a stream.
Diagnostic & attachNote(Optional< Location > noteLoc=llvm::None)
Attaches a note to this diagnostic.
Definition: Diagnostics.h:335
InFlightDiagnostic emitError(Location loc, const Twine &message)
Attributes are known-constant values of operations.
Definition: Attributes.h:24
DiagnosticArgument(float val)
Definition: Diagnostics.h:61
DiagnosticArgumentKind
Enum that represents the different kinds of diagnostic arguments supported.
Definition: Diagnostics.h:86
Diagnostic(Location loc, DiagnosticSeverity severity)
Definition: Diagnostics.h:161
ArrayRef< DiagnosticArgument > getArguments() const
Definition: Diagnostics.h:174
MutableArrayRef< DiagnosticArgument > getArguments()
Returns the current list of diagnostic arguments.
Definition: Diagnostics.h:173
Diagnostic & append(Arg1 &&arg1, Arg2 &&arg2, Args &&... args)
Append arguments to the diagnostic.
Definition: Diagnostics.h:232
Diagnostic & appendRange(const T &c, const char *delim=", ")
Append a range to the diagnostic.
Definition: Diagnostics.h:224
DiagnosticArgumentKind getKind() const
Returns the kind of this argument.
Definition: Diagnostics.h:99
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:72
This class is a utility diagnostic handler for use with llvm::SourceMgr.
Definition: Diagnostics.h:525
This class is the main interface for diagnostics.
Definition: Diagnostics.h:381
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:84
InFlightDiagnostic && operator<<(Arg &&arg) &&
Definition: Diagnostics.h:319
A variant type that holds a single argument for a diagnostic.
Definition: Diagnostics.h:52
ScopedDiagnosticHandler(MLIRContext *ctx)
Definition: Diagnostics.h:491
This class is a utility diagnostic handler for use with llvm::SourceMgr that verifies that emitted di...
Definition: Diagnostics.h:591
InFlightDiagnostic emit(Location loc, DiagnosticSeverity severity)
Create a new inflight diagnostic with the given location and severity.
Definition: Diagnostics.h:427
Set of flags used to control the behavior of the various IR print methods (e.g.
Diagnostic & operator<<(const char *val)
Stream in a string literal.
Definition: Diagnostics.h:189
iterator_range< note_iterator > getNotes()
Returns the notes held by this diagnostic.
Definition: Diagnostics.h:258
std::function< LogicalResult(Diagnostic &)> HandlerTy
The handler type for MLIR diagnostics.
Definition: Diagnostics.h:398
ShouldShowLocFn shouldShowLocFn
A functor used when determining if a location for a diagnostic should be shown.
Definition: Diagnostics.h:563
std::enable_if_t< std::is_same< RetT, void >::value, HandlerID > registerHandler(FuncTy &&handler)
Set the diagnostic handler with a function that returns void.
Definition: Diagnostics.h:416
std::ostream & operator<<(std::ostream &out, const llvm::Twine &twine)
llvm::SourceMgr & mgr
The source manager that we are wrapping.
Definition: Diagnostics.h:556
InFlightDiagnostic & operator<<(Arg &&arg) &
Stream operator for new diagnostic arguments.
Definition: Diagnostics.h:316
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:55
InFlightDiagnostic & append(Args &&... args) &
Append arguments to the diagnostic.
Definition: Diagnostics.h:324
Diagnostic & append(Arg &&arg)
Append one argument to the diagnostic.
Definition: Diagnostics.h:237
DiagnosticArgument(StringRef val)
Definition: Diagnostics.h:79
ScopedDiagnosticHandler(MLIRContext *ctx, FuncTy &&handler)
Definition: Diagnostics.h:493
iterator_range< const_note_iterator > getNotes() const
Definition: Diagnostics.h:261
llvm::pointee_iterator< NoteVector::const_iterator > const_note_iterator
Definition: Diagnostics.h:255
llvm::pointee_iterator< NoteVector::iterator > note_iterator
Definition: Diagnostics.h:253
double getAsDouble() const
Returns this argument as a double.
Definition: Diagnostics.h:105