MLIR 24.0.0git
Diagnostics.cpp File Reference
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Location.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/Types.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/SourceMgrDiagnosticVerifier.h"
#include "llvm/Support/raw_ostream.h"
#include <atomic>
#include <optional>

Go to the source code of this file.

Classes

struct  mlir::detail::DiagnosticEngineImpl
struct  mlir::detail::SourceMgrDiagnosticHandlerImpl
struct  mlir::detail::SourceMgrDiagnosticVerifierHandlerImpl
struct  mlir::detail::ThreadOrderEntry
 One entry of the thread-local nesting stack: the handler an element belongs to and its order id. More...
struct  mlir::detail::ParallelDiagnosticHandlerImpl
struct  mlir::detail::ParallelDiagnosticHandlerImpl::ThreadDiagnostic

Namespaces

namespace  mlir
 Include the generated interface declarations.
namespace  mlir::detail
 AttrTypeReplacer.

Functions

static StringRef twineToStrRef (const Twine &val, SmallVectorImpl< std::unique_ptr< char[]> > &strings)
 Convert a Twine to a StringRef.
static OpPrintingFlags adjustPrintingFlags (OpPrintingFlags flags, DiagnosticSeverity severity)
 Adjusts operation printing flags used in diagnostics for the given severity level.
static InFlightDiagnostic emitDiag (Location location, DiagnosticSeverity severity, const Twine &message)
 Helper function used to emit a diagnostic with an optionally empty twine message.
static std::optional< CallSiteLoc > getCallSiteLoc (Location loc)
 Return a processable CallSiteLoc from the given location.
static llvm::SourceMgr::DiagKind getDiagKind (DiagnosticSeverity kind)
 Given a diagnostic kind, returns the LLVM DiagKind.
static StringRef getDiagKindStr (DiagnosticSeverity kind)
 Given a diagnostic kind, return a human readable string for it.

Variables

static std::atomic< uint64_t > mlir::detail::nextHandlerUniqueID {1}
 Unique ids for parallel diagnostic handlers, so the thread-local slot below can name a handler without holding a raw pointer to it: a handler may be destroyed while a thread that skipped its erase still names it.
constexpr unsigned mlir::detail::kMaxThreadOrderEntries = 4
 How many nested parallel loops one thread tracks without a lock.
static LLVM_THREAD_LOCAL ThreadOrderEntry mlir::detail::threadOrderStack [kMaxThreadOrderEntries]
 The order ids for the current thread, one entry per enclosing parallel loop, innermost last.
static LLVM_THREAD_LOCAL unsigned mlir::detail::threadOrderDepth = 0

Function Documentation

◆ adjustPrintingFlags()

OpPrintingFlags adjustPrintingFlags ( OpPrintingFlags flags,
DiagnosticSeverity severity )
static

Adjusts operation printing flags used in diagnostics for the given severity level.

Definition at line 130 of file Diagnostics.cpp.

References mlir::OpPrintingFlags::elideLargeElementsAttrs(), mlir::Error, mlir::OpPrintingFlags::printGenericOpForm(), and mlir::OpPrintingFlags::useLocalScope().

Referenced by mlir::Diagnostic::appendOp(), and mlir::Diagnostic::operator<<().

◆ emitDiag()

InFlightDiagnostic emitDiag ( Location location,
DiagnosticSeverity severity,
const Twine & message )
static

Helper function used to emit a diagnostic with an optionally empty twine message.

If the message is empty, then it is not inserted into the diagnostic.

Definition at line 356 of file Diagnostics.cpp.

References mlir::Attribute::getContext(), mlir::MLIRContext::getDiagEngine(), and mlir::MLIRContext::shouldPrintStackTraceOnDiagnostic().

Referenced by mlir::transform::detail::checkApplyToOne(), mlir::emitError(), mlir::emitRemark(), and mlir::emitWarning().

◆ getCallSiteLoc()

std::optional< CallSiteLoc > getCallSiteLoc ( Location loc)
static

Return a processable CallSiteLoc from the given location.

Definition at line 444 of file Diagnostics.cpp.

References getCallSiteLoc().

Referenced by mlir::SourceMgrDiagnosticHandler::emitDiagnostic(), and getCallSiteLoc().

◆ getDiagKind()

llvm::SourceMgr::DiagKind getDiagKind ( DiagnosticSeverity kind)
static

Given a diagnostic kind, returns the LLVM DiagKind.

Definition at line 461 of file Diagnostics.cpp.

References mlir::Error, mlir::Note, mlir::Remark, and mlir::Warning.

Referenced by mlir::SourceMgrDiagnosticHandler::emitDiagnostic().

◆ getDiagKindStr()

StringRef getDiagKindStr ( DiagnosticSeverity kind)
static

Given a diagnostic kind, return a human readable string for it.

Definition at line 658 of file Diagnostics.cpp.

References mlir::Error, mlir::Note, mlir::Remark, and mlir::Warning.

◆ twineToStrRef()

StringRef twineToStrRef ( const Twine & val,
SmallVectorImpl< std::unique_ptr< char[]> > & strings )
static

Convert a Twine to a StringRef.

Memory used for generating the StringRef is stored in 'strings'.

Definition at line 90 of file Diagnostics.cpp.

Referenced by mlir::Diagnostic::operator<<(), and mlir::Diagnostic::operator<<().