17 #include "llvm/ADT/TypeSwitch.h"
34 if (
auto intType = dyn_cast<IntegerType>(type)) {
35 return intType.getWidth();
37 if (llvm::isa<IndexType>(type)) {
38 return IndexType::kInternalStorageBitWidth;
41 <<
"expected integer or index type for IntegerAttr, but got: " << type;
47 unsigned bitWidth = getIntegerBitWidth(reader, type);
55 auto ftype = dyn_cast<FloatType>(type);
66 rawStringData.resize(isSplat ? 1 : type.getNumElements());
67 for (StringRef &value : rawStringData)
74 DenseStringElementsAttr attr) {
75 bool isSplat = attr.isSplat();
79 for (StringRef str : attr.getRawStringData())
83 #include "mlir/IR/BuiltinDialectBytecode.cpp.inc"
87 BuiltinDialectBytecodeInterface(
Dialect *dialect)
99 return ::writeAttribute(attr, writer);
111 return ::writeType(type, writer);
117 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 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.
This class defines a virtual interface for writing to a bytecode stream, providing hooks into the byt...
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...
This class provides support for representing a failure result, or a valid value of type T.
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.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.