13 #ifndef MLIR_IR_DIAGNOSTICS_H 14 #define MLIR_IR_DIAGNOSTICS_H 26 class DiagnosticEngine;
31 class OpPrintingFlags;
36 struct DiagnosticEngineImpl;
67 std::numeric_limits<T>::is_integer &&
68 sizeof(T) <=
sizeof(int64_t)>::type * =
nullptr)
75 std::numeric_limits<T>::is_integer &&
76 sizeof(T) <=
sizeof(uint64_t)>::type * =
nullptr)
96 void print(raw_ostream &os)
const;
106 assert(getKind() == DiagnosticArgumentKind::Double);
112 assert(getKind() == DiagnosticArgumentKind::Integer);
113 return static_cast<int64_t
>(opaqueVal);
118 assert(getKind() == DiagnosticArgumentKind::String);
123 Type getAsType()
const;
127 assert(getKind() == DiagnosticArgumentKind::Unsigned);
128 return static_cast<uint64_t
>(opaqueVal);
158 using NoteVector = std::vector<std::unique_ptr<Diagnostic>>;
162 : loc(loc), severity(severity) {}
177 template <
typename Arg>
178 typename std::enable_if<
212 template <
typename T,
typename ValueT = llvm::detail::ValueOfRange<T>>
216 return appendRange(range);
221 template <
typename T>
224 c, [
this](
const auto &a) { *
this << a; }, [&]() { *
this << delim; });
229 template <
typename Arg1,
typename Arg2,
typename... Args>
231 append(std::forward<Arg1>(arg1));
232 return append(std::forward<Arg2>(arg2), std::forward<Args>(args)...);
235 template <
typename Arg>
237 *this << std::forward<Arg>(arg);
242 void print(raw_ostream &os)
const;
245 std::string str()
const;
254 llvm::pointee_iterator<NoteVector::const_iterator>;
258 return llvm::make_pointee_range(notes);
261 return llvm::make_pointee_range(notes);
272 template <
typename T>
292 std::vector<std::unique_ptr<char[]>> strings;
314 : owner(rhs.owner),
impl(std::move(rhs.
impl)) {
325 template <
typename Arg>
327 return append(std::forward<Arg>(arg));
329 template <
typename Arg>
331 return std::move(append(std::forward<Arg>(arg)));
335 template <
typename... Args>
337 assert(isActive() &&
"diagnostic not active");
339 impl->append(std::forward<Args>(args)...);
342 template <
typename... Args>
344 return std::move(append(std::forward<Args>(args)...));
349 assert(isActive() &&
"diagnostic not active");
350 return impl->attachNote(noteLoc);
370 template <
typename T>
379 : owner(owner),
impl(std::move(rhs)) {}
383 bool isActive()
const {
return impl.has_value(); }
386 bool isInFlight()
const {
return owner; }
423 using HandlerTy = llvm::unique_function<LogicalResult(Diagnostic &)>;
438 template <
typename FuncTy,
typename RetT = decltype(std::declval<FuncTy>()(
439 std::declval<Diagnostic &>()))>
453 assert(severity != DiagnosticSeverity::Note &&
454 "notes should not be emitted directly");
468 std::unique_ptr<detail::DiagnosticEngineImpl>
impl;
488 template <
typename... Args>
494 template <
typename... Args>
500 template <
typename... Args>
517 template <
typename FuncTy>
519 : handlerID(0), ctx(ctx) {
520 setHandler(std::forward<FuncTy>(handler));
526 template <
typename FuncTy>
528 auto &diagEngine = ctx->getDiagEngine();
530 diagEngine.eraseHandler(handlerID);
531 handlerID = diagEngine.registerHandler(std::forward<FuncTy>(handler));
547 struct SourceMgrDiagnosticHandlerImpl;
571 bool displaySourceLine =
true);
579 const llvm::MemoryBuffer *getBufferForFile(StringRef filename);
593 SMLoc convertLocToSMLoc(FileLineColLoc loc);
601 unsigned callStackLimit = 10;
603 std::unique_ptr<detail::SourceMgrDiagnosticHandlerImpl>
impl;
611 struct SourceMgrDiagnosticVerifierHandlerImpl;
636 std::unique_ptr<detail::SourceMgrDiagnosticVerifierHandlerImpl>
impl;
644 struct ParallelDiagnosticHandlerImpl;
667 void setOrderIDForThread(
size_t orderID);
671 void eraseOrderIDForThread();
674 std::unique_ptr<detail::ParallelDiagnosticHandlerImpl>
impl;
Include the generated interface declarations.
static std::string diag(llvm::Value &v)
Diagnostic & operator<<(Operation *val)
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Operation is a basic unit of execution within MLIR.
InFlightDiagnostic(InFlightDiagnostic &&rhs)
void setHandler(FuncTy &&handler)
Set the handler to manage via RAII.
This class represents a diagnostic that is inflight and set to be reported.
llvm::unique_function< bool(Location)> ShouldShowLocFn
This type represents a functor used to filter out locations when printing a diagnostic.
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...
uint64_t getAsUnsigned() const
Returns this argument as an unsigned integer.
Location getLocation() const
Returns the source location for this diagnostic.
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)
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)
int64_t getAsInteger() const
Returns this argument as a signed integer.
void print(raw_ostream &os) const
Outputs this argument to a stream.
InFlightDiagnostic emitRemark(Location loc, const Twine &message)
DiagnosticArgument(double val)
DiagnosticSeverity getSeverity() const
Returns the severity of this diagnostic.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
An inlay hint that for a type annotation.
static constexpr const bool value
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
InFlightDiagnostic & append(Args &&...args) &
Append arguments to the diagnostic.
InFlightDiagnostic emitWarning(Location loc, const Twine &message)
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
This class contains all of the information necessary to report a diagnostic to the DiagnosticEngine...
This class represents an efficient way to signal success or failure.
This class is a utility diagnostic handler for use when multi-threading some part of the compiler whe...
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
This class provides support for representing a failure result, or a valid value of type T...
llvm::unique_function< LogicalResult(Diagnostic &)> HandlerTy
The handler type for MLIR diagnostics.
uint64_t HandlerID
A handle to a specific registered handler object.
LogicalResult emitOptionalWarning(Optional< Location > loc, Args &&...args)
StringRef getAsString() const
Returns this argument as a string.
raw_ostream & os
The output stream to use when printing diagnostics.
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.
InFlightDiagnostic emitError(Location loc, const Twine &message)
Attributes are known-constant values of operations.
static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer)
DiagnosticArgument(float val)
DiagnosticArgumentKind
Enum that represents the different kinds of diagnostic arguments supported.
Diagnostic(Location loc, DiagnosticSeverity severity)
ArrayRef< DiagnosticArgument > getArguments() const
MutableArrayRef< DiagnosticArgument > getArguments()
Returns the current list of diagnostic arguments.
Diagnostic & appendRange(const T &c, const char *delim=", ")
Append a range to the diagnostic.
LogicalResult emitOptionalError(Optional< Location > loc, Args &&...args)
Overloads of the above emission functions that take an optionally null location.
DiagnosticArgumentKind getKind() const
Returns the kind of this argument.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class is a utility diagnostic handler for use with llvm::SourceMgr.
LogicalResult emitOptionalRemark(Optional< Location > loc, Args &&...args)
InFlightDiagnostic && append(Args &&...args) &&
This class is the main interface for diagnostics.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
InFlightDiagnostic && operator<<(Arg &&arg) &&
A variant type that holds a single argument for a diagnostic.
ScopedDiagnosticHandler(MLIRContext *ctx)
This class is a utility diagnostic handler for use with llvm::SourceMgr that verifies that emitted di...
InFlightDiagnostic emit(Location loc, DiagnosticSeverity severity)
Create a new inflight diagnostic with the given location and severity.
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.
iterator_range< note_iterator > getNotes()
Returns the notes held by this diagnostic.
ShouldShowLocFn shouldShowLocFn
A functor used when determining if a location for a diagnostic should be shown.
std::enable_if_t< std::is_same< RetT, void >::value, HandlerID > registerHandler(FuncTy &&handler)
Set the diagnostic handler with a function that returns void.
llvm::SourceMgr & mgr
The source manager that we are wrapping.
InFlightDiagnostic & operator<<(Arg &&arg) &
Stream operator for new diagnostic arguments.
MLIRContext is the top-level object for a collection of MLIR operations.
raw_ostream & operator<<(raw_ostream &os, const Diagnostic &diag)
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs, on this operation and any nested operations.
Diagnostic & append(Arg &&arg)
Append one argument to the diagnostic.
DiagnosticArgument(StringRef val)
ScopedDiagnosticHandler(MLIRContext *ctx, FuncTy &&handler)
iterator_range< const_note_iterator > getNotes() const
This class represents success/failure for parsing-like operations that find it important to chain tog...
llvm::pointee_iterator< NoteVector::const_iterator > const_note_iterator
llvm::pointee_iterator< NoteVector::iterator > note_iterator
double getAsDouble() const
Returns this argument as a double.
Diagnostic & append(Arg1 &&arg1, Arg2 &&arg2, Args &&...args)
Append arguments to the diagnostic.