13 #ifndef MLIR_IR_DIAGNOSTICS_H 14 #define MLIR_IR_DIAGNOSTICS_H 27 class DiagnosticEngine;
36 struct DiagnosticEngineImpl;
67 void print(raw_ostream &os)
const;
77 assert(getKind() == DiagnosticArgumentKind::Double);
84 return static_cast<int64_t
>(opaqueVal);
89 assert(getKind() == DiagnosticArgumentKind::Operation);
90 return *
reinterpret_cast<Operation *
>(opaqueVal);
100 Type getAsType()
const;
104 assert(getKind() == DiagnosticArgumentKind::Unsigned);
105 return static_cast<uint64_t
>(opaqueVal);
120 template <
typename T>
122 T val,
typename std::enable_if<std::is_signed<T>::value &&
123 std::numeric_limits<T>::is_integer &&
124 sizeof(T) <=
sizeof(int64_t)>::type * = 0)
128 template <
typename T>
130 T val,
typename std::enable_if<std::is_unsigned<T>::value &&
131 std::numeric_limits<T>::is_integer &&
132 sizeof(T) <=
sizeof(uint64_t)>::type * = 0)
139 opaqueVal(reinterpret_cast<intptr_t>(val)) {
140 assert(val &&
"expected valid operation");
174 using NoteVector = std::vector<std::unique_ptr<Diagnostic>>;
178 template <
typename IteratorTy,
typename NotePtrTy = decltype(*IteratorTy()),
179 typename ResultTy = decltype(**IteratorTy())>
180 class NoteIteratorImpl
181 :
public llvm::mapped_iterator<IteratorTy, ResultTy (*)(NotePtrTy)> {
182 static ResultTy &unwrap(NotePtrTy note) {
return *note; }
185 NoteIteratorImpl(IteratorTy it)
186 : llvm::mapped_iterator<IteratorTy, ResultTy (*)(NotePtrTy)>(it,
192 : loc(loc), severity(severity) {}
207 template <
typename Arg>
208 typename std::enable_if<!std::is_convertible<Arg, StringRef>::value,
234 return appendRange(
range);
237 return appendRange(
range);
242 template <
typename T,
template <
typename>
class Container>
246 [&]() { *
this << delim; });
251 template <
typename Arg1,
typename Arg2,
typename... Args>
253 append(std::forward<Arg1>(arg1));
254 return append(std::forward<Arg2>(arg2), std::forward<Args>(args)...);
258 *this << std::forward<Arg>(arg);
263 void print(raw_ostream &os)
const;
266 std::string str()
const;
278 return {notes.begin(), notes.end()};
281 return {notes.begin(), notes.end()};
302 std::vector<std::unique_ptr<char[]>> strings;
324 : owner(rhs.owner), impl(std::move(rhs.impl)) {
336 return append(std::forward<Arg>(arg));
339 return std::move(append(std::forward<Arg>(arg)));
344 assert(isActive() &&
"diagnostic not active");
346 impl->append(std::forward<Args>(args)...);
350 return std::move(append(std::forward<Args>(args)...));
355 assert(isActive() &&
"diagnostic not active");
356 return impl->attachNote(noteLoc);
373 : owner(owner), impl(std::move(rhs)) {}
376 bool isActive()
const {
return impl.hasValue(); }
379 bool isInFlight()
const {
return owner; }
416 using HandlerTy = std::function<LogicalResult(Diagnostic &)>;
431 template <
typename FuncTy,
typename RetT = decltype(std::declval<FuncTy>()(
432 std::declval<Diagnostic &>()))>
433 std::enable_if_t<std::is_same<RetT, void>::value,
HandlerID>
435 return registerHandler([=](
Diagnostic &diag) {
446 assert(severity != DiagnosticSeverity::Note &&
447 "notes should not be emitted directly");
460 std::unique_ptr<detail::DiagnosticEngineImpl> impl;
480 template <
typename... Args>
486 template <
typename... Args>
492 template <
typename... Args>
509 template <
typename FuncTy>
511 : handlerID(0), ctx(ctx) {
512 setHandler(std::forward<FuncTy>(handler));
518 template <
typename FuncTy>
void setHandler(FuncTy &&handler) {
519 auto &diagEngine = ctx->getDiagEngine();
521 diagEngine.eraseHandler(handlerID);
522 handlerID = diagEngine.registerHandler(std::forward<FuncTy>(handler));
538 struct SourceMgrDiagnosticHandlerImpl;
558 const llvm::MemoryBuffer *getBufferForFile(StringRef filename);
572 unsigned callStackLimit = 10;
574 std::unique_ptr<detail::SourceMgrDiagnosticHandlerImpl> impl;
582 struct SourceMgrDiagnosticVerifierHandlerImpl;
607 std::unique_ptr<detail::SourceMgrDiagnosticVerifierHandlerImpl> impl;
615 struct ParallelDiagnosticHandlerImpl;
638 void setOrderIDForThread(
size_t orderID);
642 void eraseOrderIDForThread();
645 std::unique_ptr<detail::ParallelDiagnosticHandlerImpl> impl;
Definition: InferTypeOpInterface.cpp:20
Definition: PassRegistry.cpp:413
Definition: Operation.h:27
InFlightDiagnostic(InFlightDiagnostic &&rhs)
Definition: Diagnostics.h:323
Definition: Attributes.h:139
void setHandler(FuncTy &&handler)
Set the handler to manage via RAII.
Definition: Diagnostics.h:518
Definition: Diagnostics.h:320
LogicalResult emitOptionalRemark(Optional< Location > loc, Args &&... args)
Definition: Diagnostics.h:493
Definition: MLIRContext.cpp:149
Definition: Diagnostics.h:506
uint64_t getAsUnsigned() const
Returns this argument as an unsigned integer.
Definition: Diagnostics.h:103
Location getLocation() const
Returns the source location for this diagnostic.
Definition: Diagnostics.h:200
Definition: Identifier.h:26
NoteIteratorImpl< NoteVector::iterator > note_iterator
Definition: Diagnostics.h:273
Diagnostic & appendRange(const Container< T > &c, const char *delim=", ")
Definition: Diagnostics.h:243
int64_t getAsInteger() const
Returns this argument as a signed integer.
Definition: Diagnostics.h:82
void print(raw_ostream &os) const
Outputs this argument to a stream.
Definition: Diagnostics.cpp:63
InFlightDiagnostic emitRemark(Location loc, const Twine &message)
Definition: Diagnostics.cpp:318
Operation & getAsOperation() const
Returns this argument as an operation.
Definition: Diagnostics.h:88
DiagnosticSeverity getSeverity() const
Returns the severity of this diagnostic.
Definition: Diagnostics.h:197
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
Definition: Diagnostics.h:40
Definition: Location.h:52
LogicalResult emitOptionalError(Optional< Location > loc, Args &&... args)
Definition: Diagnostics.h:481
InFlightDiagnostic emitWarning(Location loc, const Twine &message)
Definition: Diagnostics.cpp:310
LogicalResult success(bool isSuccess=true)
Definition: LogicalResult.h:25
Definition: Diagnostics.h:173
Definition: LogicalResult.h:18
Definition: Diagnostics.h:622
LogicalResult failure(bool isFailure=true)
Definition: LogicalResult.h:32
InFlightDiagnostic && append(Args &&... args) &&
Definition: Diagnostics.h:349
LogicalResult emitOptionalWarning(Optional< Location > loc, Args &&... args)
Definition: Diagnostics.h:487
uint64_t HandlerID
A handle to a specific registered handler object.
Definition: Diagnostics.h:419
StringRef getAsString() const
Returns this argument as a string.
Definition: Diagnostics.h:94
raw_ostream & os
The output stream to use when printing diagnostics.
Definition: Diagnostics.h:564
void print(raw_ostream &os) const
Outputs this diagnostic to a stream.
Definition: Diagnostics.cpp:135
Diagnostic & attachNote(Optional< Location > noteLoc=llvm::None)
Attaches a note to this diagnostic.
Definition: Diagnostics.h:354
InFlightDiagnostic emitError(Location loc, const Twine &message)
Definition: Diagnostics.cpp:302
Definition: Attributes.h:53
~InFlightDiagnostic()
Definition: Diagnostics.h:329
StringRef stringVal
Definition: Diagnostics.h:157
DiagnosticArgumentKind
Definition: Diagnostics.h:56
Diagnostic(Location loc, DiagnosticSeverity severity)
Definition: Diagnostics.h:191
ArrayRef< DiagnosticArgument > getArguments() const
Definition: Diagnostics.h:204
MutableArrayRef< DiagnosticArgument > getArguments()
Returns the current list of diagnostic arguments.
Definition: Diagnostics.h:203
Diagnostic & append(Arg1 &&arg1, Arg2 &&arg2, Args &&... args)
Append arguments to the diagnostic.
Definition: Diagnostics.h:252
DiagnosticArgumentKind getKind() const
Returns the kind of this argument.
Definition: Diagnostics.h:70
This class is a utility diagnostic handler for use with llvm::SourceMgr.
Definition: Diagnostics.h:542
Definition: Diagnostics.h:399
InFlightDiagnostic && operator<<(Arg &&arg) &&
Definition: Diagnostics.h:338
Definition: Attributes.h:137
A variant type that holds a single argument for a diagnostic.
Definition: Diagnostics.h:52
void interleave(ForwardIterator begin, ForwardIterator end, UnaryFunctor each_fn, NullaryFunctor between_fn)
Definition: STLExtras.h:43
ScopedDiagnosticHandler(MLIRContext *ctx)
Definition: Diagnostics.h:508
Definition: Diagnostics.h:588
InFlightDiagnostic emit(Location loc, DiagnosticSeverity severity)
Create a new inflight diagnostic with the given location and severity.
Definition: Diagnostics.h:445
LogicalResult verify(AffinePrefetchOp op)
Definition: AffineOps.cpp:2078
Diagnostic & operator<<(const char *val)
Stream in a string literal.
Definition: Diagnostics.h:216
iterator_range< note_iterator > getNotes()
Returns the notes held by this diagnostic.
Definition: Diagnostics.h:277
std::function< LogicalResult(Diagnostic &)> HandlerTy
Definition: Diagnostics.h:416
std::enable_if_t< std::is_same< RetT, void >::value, HandlerID > registerHandler(FuncTy &&handler)
Definition: Diagnostics.h:434
std::ostream & operator<<(std::ostream &out, const llvm::Twine &twine)
Definition: DebugStringHelper.h:36
llvm::SourceMgr & mgr
The source manager that we are wrapping.
Definition: Diagnostics.h:561
typename std::remove_reference< decltype(*std::begin(std::declval< RangeT & >()))>::type ValueOfRange
Definition: STLExtras.h:25
Definition: Location.h:126
intptr_t opaqueVal
Definition: Diagnostics.h:156
InFlightDiagnostic & operator<<(Arg &&arg) &
Stream operator for new diagnostic arguments.
Definition: Diagnostics.h:335
double doubleVal
Definition: Diagnostics.h:155
NoteIteratorImpl< NoteVector::const_iterator > const_note_iterator
Definition: Diagnostics.h:274
Definition: MLIRContext.h:34
void print(OpAsmPrinter &p, AffineIfOp op)
Definition: AffineOps.cpp:1671
InFlightDiagnostic & append(Args &&... args) &
Append arguments to the diagnostic.
Definition: Diagnostics.h:343
Definition: StandardTypes.h:63
Diagnostic & append(Arg &&arg)
Append one argument to the diagnostic.
Definition: Diagnostics.h:257
mlir::edsc::intrinsics::ValueBuilder< RangeOp > range
Definition: Intrinsics.h:23
ScopedDiagnosticHandler(MLIRContext *ctx, FuncTy &&handler)
Definition: Diagnostics.h:510
iterator_range< const_note_iterator > getNotes() const
Definition: Diagnostics.h:280
Definition: OperationSupport.h:203
double getAsDouble() const
Returns this argument as a double.
Definition: Diagnostics.h:76
Definition: Attributes.h:134