|
MLIR 24.0.0git
|
This class defines a virtual interface for reading a bytecode stream, providing hooks into the bytecode reader. More...
#include "mlir/Bytecode/BytecodeImplementation.h"
Public Member Functions | |
| virtual | ~DialectBytecodeReader ()=default |
| virtual InFlightDiagnostic | emitError (const Twine &msg={}) const =0 |
| Emit an error to the reader. | |
| virtual InFlightDiagnostic | emitWarning (const Twine &msg={}) const =0 |
| Emit a warning to the reader. | |
| virtual FailureOr< const DialectVersion * > | getDialectVersion (StringRef dialectName) const =0 |
| Retrieve the dialect version by name if available. | |
| template<class T> | |
| FailureOr< const DialectVersion * > | getDialectVersion () const |
| virtual MLIRContext * | getContext () const =0 |
| Retrieve the context associated to the reader. | |
| virtual uint64_t | getBytecodeVersion () const =0 |
| Return the bytecode version being read. | |
| template<typename T, typename CallbackFn> | |
| LogicalResult | readList (SmallVectorImpl< T > &result, CallbackFn &&callback) |
| Read out a list of elements, invoking the provided callback for each element. | |
| template<typename T, typename CallbackFn> | |
| LogicalResult | readListWithKnownSize (SmallVectorImpl< T > &result, uint64_t size, CallbackFn &&callback) |
| Read out a list of elements with a known size, invoking the provided callback for each element. | |
| virtual LogicalResult | readAttribute (Attribute &result)=0 |
| Read a reference to the given attribute. | |
| virtual LogicalResult | readOptionalAttribute (Attribute &attr)=0 |
| Read an optional reference to the given attribute. | |
| template<typename T> | |
| LogicalResult | readAttributes (SmallVectorImpl< T > &attrs) |
| template<typename T> | |
| LogicalResult | readAttribute (T &result) |
| template<typename T> | |
| LogicalResult | readOptionalAttribute (T &result) |
| virtual LogicalResult | tryStartCyclicRead (Type type)=0 |
| Publish type as the result of the entry currently being read, before that entry has finished reading its own body. | |
| virtual LogicalResult | readType (Type &result)=0 |
| Read a reference to the given type. | |
| template<typename T> | |
| LogicalResult | readTypes (SmallVectorImpl< T > &types) |
| template<typename T> | |
| LogicalResult | readType (T &result) |
| template<typename ResourceT> | |
| FailureOr< ResourceT > | readResourceHandle () |
| Read a handle to a dialect resource. | |
| virtual LogicalResult | readVarInt (uint64_t &result)=0 |
| Read a variable width integer. | |
| virtual LogicalResult | readSignedVarInt (int64_t &result)=0 |
| Read a signed variable width integer. | |
| LogicalResult | readSignedVarInts (SmallVectorImpl< int64_t > &result) |
| LogicalResult | readVarIntWithFlag (uint64_t &result, bool &flag) |
| Parse a variable length encoded integer whose low bit is used to encode an unrelated flag, i.e: (integerValue << 1) | (flag ?
| |
| template<typename T> | |
| LogicalResult | readSparseArray (MutableArrayRef< T > array) |
| Read a "small" sparse array of integer <= 32 bits elements, where index/value pairs can be compressed when the array is small. | |
| virtual FailureOr< APInt > | readAPIntWithKnownWidth (unsigned bitWidth)=0 |
| Read an APInt that is known to have been encoded with the given width. | |
| virtual FailureOr< APFloat > | readAPFloatWithKnownSemantics (const llvm::fltSemantics &semantics)=0 |
| Read an APFloat that is known to have been encoded with the given semantics. | |
| virtual LogicalResult | readString (StringRef &result)=0 |
| Read a string from the bytecode. | |
| virtual LogicalResult | readBlob (ArrayRef< char > &result)=0 |
| Read a blob from the bytecode. | |
| virtual LogicalResult | readBool (bool &result)=0 |
| Read a bool from the bytecode. | |
This class defines a virtual interface for reading a bytecode stream, providing hooks into the bytecode reader.
As such, this class should only be derived and defined by the main bytecode reader, users (i.e. dialects) should generally only interact with this class via the BytecodeDialectInterface below.
Definition at line 45 of file BytecodeImplementation.h.
|
virtualdefault |
|
pure virtual |
Emit an error to the reader.
Referenced by readAttribute(), readOptionalAttribute(), readResourceHandle(), readSparseArray(), and readType().
|
pure virtual |
Emit a warning to the reader.
|
pure virtual |
Return the bytecode version being read.
|
pure virtual |
Retrieve the context associated to the reader.
|
inline |
Definition at line 59 of file BytecodeImplementation.h.
References getDialectVersion().
Referenced by getDialectVersion().
|
pure virtual |
Retrieve the dialect version by name if available.
|
pure virtual |
Read an APFloat that is known to have been encoded with the given semantics.
|
pure virtual |
Read an APInt that is known to have been encoded with the given width.
|
pure virtual |
Read a reference to the given attribute.
References result.
Referenced by readAttribute(), and readAttributes().
|
inline |
Definition at line 125 of file BytecodeImplementation.h.
References emitError(), readAttribute(), result, and success().
|
inline |
Definition at line 121 of file BytecodeImplementation.h.
References readAttribute(), and readList().
|
pure virtual |
Read a blob from the bytecode.
References result.
|
pure virtual |
Read a bool from the bytecode.
References result.
|
inline |
Read out a list of elements, invoking the provided callback for each element.
The callback function may be in any of the following forms:
Definition at line 74 of file BytecodeImplementation.h.
References readListWithKnownSize(), readVarInt(), and result.
Referenced by readAttributes(), readSignedVarInts(), and readTypes().
|
inline |
Read out a list of elements with a known size, invoking the provided callback for each element.
Unlike readList, this does not read a length prefix. The callback function may be in any of the following forms:
Definition at line 88 of file BytecodeImplementation.h.
References result, and success().
Referenced by readList().
|
pure virtual |
Read an optional reference to the given attribute.
Returns success even if the Attribute isn't present.
Referenced by readOptionalAttribute().
|
inline |
Definition at line 135 of file BytecodeImplementation.h.
References emitError(), readOptionalAttribute(), result, and success().
|
inline |
Read a handle to a dialect resource.
Definition at line 191 of file BytecodeImplementation.h.
References emitError(), readResourceHandle(), and result.
Referenced by readResourceHandle(), and mlir::readResourceHandle().
|
pure virtual |
|
inline |
Definition at line 210 of file BytecodeImplementation.h.
References readList(), readSignedVarInt(), and result.
|
inline |
Read a "small" sparse array of integer <= 32 bits elements, where index/value pairs can be compressed when the array is small.
Note that only some position of the array will be read and the ones not stored in the bytecode are gonne be left untouched. If the provided array is too small for the stored indices, an error will be returned.
Definition at line 232 of file BytecodeImplementation.h.
References emitError(), readVarInt(), readVarIntWithFlag(), and success().
|
pure virtual |
Read a string from the bytecode.
References result.
|
inline |
Definition at line 179 of file BytecodeImplementation.h.
References emitError(), readType(), result, and success().
|
pure virtual |
|
inline |
Definition at line 175 of file BytecodeImplementation.h.
References readList(), and readType().
|
pure virtual |
Read a variable width integer.
References result.
Referenced by readList(), readSparseArray(), and readVarIntWithFlag().
|
inline |
Parse a variable length encoded integer whose low bit is used to encode an unrelated flag, i.e: (integerValue << 1) | (flag ?
1 : 0).
Definition at line 217 of file BytecodeImplementation.h.
References readVarInt(), result, and success().
Referenced by readSparseArray().
|
pure virtual |
Publish type as the result of the entry currently being read, before that entry has finished reading its own body.
This is the bytecode analogue of AsmParser::tryStartCyclicParse, and it exists for the same reason: a mutable type may refer to itself, directly or through a pointer, so the body cannot be read until the type it belongs to already exists. A dialect creates the incomplete type, calls this, reads the body (a nested reference back to this same entry then resolves to the incomplete type rather than re-entering it), and then completes it. Unlike tryStartCyclicParse, which returns a guard and fails a nested parse of the same type, this publishes the type so nested reads succeed with the incomplete instance.
Contract for the dialect: call this before reading any nested entry that may refer back, and return the published instance as the read result. The read may run more than once (deferred entries are retried), so the type must be uniqued by key and completing it idempotent; publishing a different instance for the same entry fails. There is no attribute analogue yet; mutable attributes keep the fallback encoding.
Emits an error and returns failure if the reader is not inside a custom type entry, type is null or immutable, or a different instance was already published for the entry.