19 #include "llvm/ADT/TypeSwitch.h"
37 if (
auto intType = dyn_cast<IntegerType>(type)) {
38 return intType.getWidth();
40 if (llvm::isa<IndexType>(type)) {
41 return IndexType::kInternalStorageBitWidth;
44 <<
"expected integer or index type for IntegerAttr, but got: " << type;
49 Type type, FailureOr<APInt> &val) {
50 unsigned bitWidth = getIntegerBitWidth(reader, type);
57 FailureOr<APFloat> &val) {
58 auto ftype = dyn_cast<FloatType>(type);
69 rawStringData.resize(isSplat ? 1 : type.getNumElements());
70 for (StringRef &value : rawStringData)
77 DenseStringElementsAttr attr) {
78 bool isSplat = attr.isSplat();
82 for (StringRef str : attr.getRawStringData())
89 switch (lineCols.size()) {
101 lineCols[2], lineCols[3]);
111 lineCols, [&reader](uint64_t &val) {
return reader.
readVarInt(val); });
116 if (range.getStartLine() == 0 && range.getStartColumn() == 0 &&
117 range.getEndLine() == 0 && range.getEndColumn() == 0) {
121 if (range.getStartColumn() == 0 &&
122 range.getStartLine() == range.getEndLine()) {
129 if (range.getEndColumn() == range.getStartColumn() &&
130 range.getStartLine() == range.getEndLine()) {
136 if (range.getStartLine() == range.getEndLine()) {
150 #include "mlir/IR/BuiltinDialectBytecode.cpp.inc"
154 BuiltinDialectBytecodeInterface(
Dialect *dialect)
164 LogicalResult writeAttribute(
Attribute attr,
166 return ::writeAttribute(attr, writer);
176 LogicalResult writeType(
Type type,
178 return ::writeType(type, writer);
184 dialect->addInterfaces<BuiltinDialectBytecodeInterface>();
static MLIRContext * getContext(OpFoldResult val)
Attributes are known-constant values of operations.
This class defines a virtual interface for reading a bytecode stream, providing hooks into the byteco...
virtual FailureOr< APInt > readAPIntWithKnownWidth(unsigned bitWidth)=0
Read an APInt that is known to have been encoded with the given width.
virtual LogicalResult readVarInt(uint64_t &result)=0
Read a variable width integer.
virtual InFlightDiagnostic emitError(const Twine &msg={}) const =0
Emit an error to the reader.
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.
LogicalResult readList(SmallVectorImpl< T > &result, CallbackFn &&callback)
Read out a list of elements, invoking the provided callback for each element.
This class defines a virtual interface for writing to a bytecode stream, providing hooks into the byt...
virtual void writeVarInt(uint64_t value)=0
Write a variable width integer to the output stream.
virtual void writeOwnedString(StringRef str)=0
Write a string to the bytecode, which is owned by the caller and is guaranteed to not die before the ...
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
MLIRContext is the top-level object for a collection of MLIR operations.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
void addBytecodeInterface(BuiltinDialect *dialect)
Add the interfaces necessary for encoding the builtin dialect components in bytecode.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...