static ::mlir::Attribute readAffineMapAttr(MLIRContext* context, DialectBytecodeReader &reader) { AffineMap value; if (succeeded(readAffineMap(reader, context, value))) { return getChecked([&]() { return reader.emitError(); }, context, value); } return AffineMapAttr(); } static LogicalResult write(AffineMapAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* AffineMapAttr */ 23); writeAffineMap(writer, attribute); return success(); return failure(); } static ::mlir::Attribute readArrayAttr(MLIRContext* context, DialectBytecodeReader &reader) { SmallVector value; if (succeeded(reader.readAttributes(value))) { return getChecked([&]() { return reader.emitError(); }, context, value); } return ArrayAttr(); } static LogicalResult write(ArrayAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* ArrayAttr */ 0); writer.writeAttributes(attribute.getValue()); return success(); return failure(); } static ::mlir::Attribute readCallSiteLoc(MLIRContext* context, DialectBytecodeReader &reader) { LocationAttr callee, caller; if (succeeded(reader.readAttribute(callee)) && succeeded(reader.readAttribute(caller))) { return getChecked([&]() { return reader.emitError(); }, context, callee, caller); } return CallSiteLoc(); } static LogicalResult write(CallSiteLoc attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* CallSiteLoc */ 10); writer.writeAttribute(attribute.getCallee()); writer.writeAttribute(attribute.getCaller()); return success(); return failure(); } static ::mlir::Attribute readDenseArrayAttr(MLIRContext* context, DialectBytecodeReader &reader) { Type elementType; uint64_t size; ArrayRef rawData; if (succeeded(reader.readType(elementType)) && succeeded(reader.readVarInt(size)) && succeeded(reader.readBlob(rawData))) { return getChecked([&]() { return reader.emitError(); }, context, elementType, size, rawData); } return DenseArrayAttr(); } static LogicalResult write(DenseArrayAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* DenseArrayAttr */ 17); writer.writeType(attribute.getElementType()); writer.writeVarInt(attribute.getSize()); writer.writeOwnedBlob(attribute.getRawData()); return success(); return failure(); } static ::mlir::Attribute readDenseResourceElementsAttr(MLIRContext* context, DialectBytecodeReader &reader) { ShapedType type; FailureOr rawHandle; if (succeeded(reader.readType(type)) && succeeded(readResourceHandle(reader, rawHandle))) { return getChecked([&]() { return reader.emitError(); }, context, type, *rawHandle); } return DenseResourceElementsAttr(); } static LogicalResult write(DenseResourceElementsAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* DenseResourceElementsAttr */ 16); writer.writeType(attribute.getType()); writer.writeResourceHandle(attribute.getRawHandle()); return success(); return failure(); } static ::mlir::Attribute readDenseStringElementsAttr(MLIRContext* context, DialectBytecodeReader &reader) { ShapedType type; uint64_t _isSplat; SmallVector rawStringData; if (succeeded(reader.readType(type)) && succeeded(reader.readVarInt(_isSplat)) && succeeded(readPotentiallySplatString(reader, type, _isSplat, rawStringData))) { return getChecked([&]() { return reader.emitError(); }, context, type, rawStringData); } return DenseStringElementsAttr(); } static LogicalResult write(DenseStringElementsAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* DenseStringElementsAttr */ 19); writer.writeType(attribute.getType()); writer.writeVarInt(attribute.isSplat()); writePotentiallySplatString(writer, attribute); return success(); return failure(); } static ::mlir::Attribute readDenseTypedElementsAttr(MLIRContext* context, DialectBytecodeReader &reader) { ShapedType type; SmallVector rawData; if (succeeded(reader.readType(type)) && succeeded(readDenseTypedElementsAttr(reader, type, rawData))) { return getChecked([&]() { return reader.emitError(); }, context, type, rawData); } return DenseTypedElementsAttr(); } static LogicalResult write(DenseTypedElementsAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* DenseTypedElementsAttr */ 18); writer.writeType(attribute.getType()); writeDenseTypedElementsAttr(writer, attribute); return success(); return failure(); } static ::mlir::Attribute readDictionaryAttr(MLIRContext* context, DialectBytecodeReader &reader) { SmallVector value; auto readValue = [&]() -> FailureOr { StringAttr name; Attribute value; if (succeeded(reader.readAttribute(name)) && succeeded(reader.readAttribute(value))) { return NamedAttribute(name, value); } return failure(); }; if (succeeded(reader.readList(value, readValue))) { return getChecked([&]() { return reader.emitError(); }, context, value); } return DictionaryAttr(); } static LogicalResult write(DictionaryAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* DictionaryAttr */ 1); writer.writeList(attribute.getValue(), [&](NamedAttribute attribute) { writer.writeAttribute(attribute.getName()); writer.writeAttribute(attribute.getValue()); }); return success(); return failure(); } static ::mlir::Attribute readDistinctAttr(MLIRContext* context, DialectBytecodeReader &reader) { Attribute referencedAttr; if (succeeded(reader.readAttribute(referencedAttr))) { return getChecked([&]() { return reader.emitError(); }, context, referencedAttr); } return DistinctAttr(); } static LogicalResult write(DistinctAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* DistinctAttr */ 21); writer.writeAttribute(attribute.getReferencedAttr()); return success(); return failure(); } static ::mlir::Attribute readFileLineColLoc(MLIRContext* context, DialectBytecodeReader &reader) { StringAttr filename; uint64_t start_line, start_column; if (succeeded(reader.readAttribute(filename)) && succeeded(reader.readVarInt(start_line)) && succeeded(reader.readVarInt(start_column))) { return getChecked([&]() { return reader.emitError(); }, context, filename, start_line, start_column); } return FileLineColRange(); } static ::mlir::Attribute readFileLineColRange(MLIRContext* context, DialectBytecodeReader &reader) { StringAttr filename; SmallVector rawLocData; if (succeeded(reader.readAttribute(filename)) && succeeded(readFileLineColRangeLocs(reader, rawLocData))) { return getFileLineColRange(context, filename, rawLocData); } return FileLineColRange(); } static LogicalResult write(FileLineColRange attribute, DialectBytecodeWriter &writer) { if (isStrictFileLineColLoc(attribute)) { writer.writeVarInt(/* FileLineColLoc */ 11); writer.writeAttribute(attribute.getFilename()); writer.writeVarInt(attribute.getStartLine()); writer.writeVarInt(attribute.getStartColumn()); return success(); } if (!isStrictFileLineColLoc(attribute)) { writer.writeVarInt(/* FileLineColRange */ 22); writer.writeAttribute(attribute.getFilename()); writeFileLineColRangeLocs(writer, attribute); return success(); } return failure(); } static ::mlir::Attribute readFlatSymbolRefAttr(MLIRContext* context, DialectBytecodeReader &reader) { StringAttr rootReference; if (succeeded(reader.readAttribute(rootReference))) { return getChecked([&]() { return reader.emitError(); }, context, rootReference); } return FlatSymbolRefAttr(); } static LogicalResult write(FlatSymbolRefAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* FlatSymbolRefAttr */ 4); writer.writeAttribute(attribute.getRootReference()); return success(); return failure(); } static ::mlir::Attribute readFloatAttr(MLIRContext* context, DialectBytecodeReader &reader) { Type type; FailureOr value; if (succeeded(reader.readType(type)) && succeeded(readAPFloatWithKnownSemantics(reader, type, value))) { return getChecked([&]() { return reader.emitError(); }, context, type, *value); } return FloatAttr(); } static LogicalResult write(FloatAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* FloatAttr */ 9); writer.writeType(attribute.getType()); writer.writeAPFloatWithKnownSemantics(attribute.getValue()); return success(); return failure(); } static ::mlir::Attribute readFusedLoc(MLIRContext* context, DialectBytecodeReader &reader) { SmallVector locations; auto readLocations = [&]() -> FailureOr { LocationAttr value; if (succeeded(reader.readAttribute(value))) { return Location(value); } return failure(); }; if (succeeded(reader.readList(locations, readLocations))) { return cast(getChecked([&]() { return reader.emitError(); }, context, locations, Attribute())); } return FusedLoc(); } static ::mlir::Attribute readFusedLocWithMetadata(MLIRContext* context, DialectBytecodeReader &reader) { SmallVector locations; Attribute metadata; auto readLocations = [&]() -> FailureOr { LocationAttr value; if (succeeded(reader.readAttribute(value))) { return Location(value); } return failure(); }; if (succeeded(reader.readList(locations, readLocations)) && succeeded(reader.readAttribute(metadata))) { return cast(getChecked([&]() { return reader.emitError(); }, context, locations, metadata)); } return FusedLoc(); } static LogicalResult write(FusedLoc attribute, DialectBytecodeWriter &writer) { if (!attribute.getMetadata()) { writer.writeVarInt(/* FusedLoc */ 12); writer.writeList(attribute.getLocations(), [&](Location attribute) { writer.writeAttribute((LocationAttr)attribute); }); return success(); } if (attribute.getMetadata()) { writer.writeVarInt(/* FusedLocWithMetadata */ 13); writer.writeList(attribute.getLocations(), [&](Location attribute) { writer.writeAttribute((LocationAttr)attribute); }); writer.writeAttribute(attribute.getMetadata()); return success(); } return failure(); } static ::mlir::Attribute readIntegerAttr(MLIRContext* context, DialectBytecodeReader &reader) { Type type; FailureOr value; if (succeeded(reader.readType(type)) && succeeded(readAPIntWithKnownWidth(reader, type, value))) { return getChecked([&]() { return reader.emitError(); }, context, type, *value); } return IntegerAttr(); } static LogicalResult write(IntegerAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* IntegerAttr */ 8); writer.writeType(attribute.getType()); writer.writeAPIntWithKnownWidth(attribute.getValue()); return success(); return failure(); } static ::mlir::Attribute readNameLoc(MLIRContext* context, DialectBytecodeReader &reader) { StringAttr name; LocationAttr childLoc; if (succeeded(reader.readAttribute(name)) && succeeded(reader.readAttribute(childLoc))) { return getChecked([&]() { return reader.emitError(); }, context, name, childLoc); } return NameLoc(); } static LogicalResult write(NameLoc attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* NameLoc */ 14); writer.writeAttribute(attribute.getName()); writer.writeAttribute(attribute.getChildLoc()); return success(); return failure(); } static ::mlir::Attribute readSparseElementsAttr(MLIRContext* context, DialectBytecodeReader &reader) { ShapedType type; DenseIntElementsAttr indices; DenseElementsAttr values; if (succeeded(reader.readType(type)) && succeeded(reader.readAttribute(indices)) && succeeded(reader.readAttribute(values))) { return getChecked([&]() { return reader.emitError(); }, context, type, indices, values); } return SparseElementsAttr(); } static LogicalResult write(SparseElementsAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* SparseElementsAttr */ 20); writer.writeType(attribute.getType()); writer.writeAttribute(attribute.getIndices()); writer.writeAttribute(attribute.getValues()); return success(); return failure(); } static ::mlir::Attribute readStringAttr(MLIRContext* context, DialectBytecodeReader &reader) { StringRef value; if (succeeded(reader.readString(value))) { return getChecked([&]() { return reader.emitError(); }, context, value); } return StringAttr(); } static ::mlir::Attribute readStringAttrWithType(MLIRContext* context, DialectBytecodeReader &reader) { StringRef value; Type type; if (succeeded(reader.readString(value)) && succeeded(reader.readType(type))) { return getChecked([&]() { return reader.emitError(); }, context, value, type); } return StringAttr(); } static LogicalResult write(StringAttr attribute, DialectBytecodeWriter &writer) { if (::llvm::isa(attribute.getType())) { writer.writeVarInt(/* StringAttr */ 2); writer.writeOwnedString(attribute); return success(); } if (!::llvm::isa(attribute.getType())) { writer.writeVarInt(/* StringAttrWithType */ 3); writer.writeOwnedString(attribute); writer.writeType(attribute.getType()); return success(); } return failure(); } static ::mlir::Attribute readSymbolRefAttr(MLIRContext* context, DialectBytecodeReader &reader) { StringAttr rootReference; SmallVector nestedReferences; if (succeeded(reader.readAttribute(rootReference)) && succeeded(reader.readAttributes(nestedReferences))) { return getChecked([&]() { return reader.emitError(); }, context, rootReference, nestedReferences); } return SymbolRefAttr(); } static LogicalResult write(SymbolRefAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* SymbolRefAttr */ 5); writer.writeAttribute(attribute.getRootReference()); writer.writeAttributes(attribute.getNestedReferences()); return success(); return failure(); } static ::mlir::Attribute readTypeAttr(MLIRContext* context, DialectBytecodeReader &reader) { Type value; if (succeeded(reader.readType(value))) { return getChecked([&]() { return reader.emitError(); }, context, value); } return TypeAttr(); } static LogicalResult write(TypeAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* TypeAttr */ 6); writer.writeType(attribute.getValue()); return success(); return failure(); } static ::mlir::Attribute readUnitAttr(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(UnitAttr attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* UnitAttr */ 7); return success(); return failure(); } static ::mlir::Attribute readUnknownLoc(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(UnknownLoc attribute, DialectBytecodeWriter &writer) { writer.writeVarInt(/* UnknownLoc */ 15); return success(); return failure(); } static Attribute readAttribute(MLIRContext* context, DialectBytecodeReader &reader) { uint64_t kind; if (failed(reader.readVarInt(kind))) return Attribute(); switch (kind) { case 0: return readArrayAttr(context, reader); case 1: return readDictionaryAttr(context, reader); case 2: return readStringAttr(context, reader); case 3: return readStringAttrWithType(context, reader); case 4: return readFlatSymbolRefAttr(context, reader); case 5: return readSymbolRefAttr(context, reader); case 6: return readTypeAttr(context, reader); case 7: return readUnitAttr(context, reader); case 8: return readIntegerAttr(context, reader); case 9: return readFloatAttr(context, reader); case 10: return readCallSiteLoc(context, reader); case 11: return readFileLineColLoc(context, reader); case 12: return readFusedLoc(context, reader); case 13: return readFusedLocWithMetadata(context, reader); case 14: return readNameLoc(context, reader); case 15: return readUnknownLoc(context, reader); case 16: return readDenseResourceElementsAttr(context, reader); case 17: return readDenseArrayAttr(context, reader); case 18: return readDenseTypedElementsAttr(context, reader); case 19: return readDenseStringElementsAttr(context, reader); case 20: return readSparseElementsAttr(context, reader); case 21: return readDistinctAttr(context, reader); case 22: return readFileLineColRange(context, reader); case 23: return readAffineMapAttr(context, reader); default: reader.emitError() << "unknown attribute code: " << kind; return Attribute(); } return Attribute(); } static LogicalResult writeAttribute(Attribute attribute, DialectBytecodeWriter &writer) { return TypeSwitch(attribute) .Case([&](AffineMapAttr t) { return write(t, writer); }) .Case([&](ArrayAttr t) { return write(t, writer); }) .Case([&](CallSiteLoc t) { return write(t, writer); }) .Case([&](DenseArrayAttr t) { return write(t, writer); }) .Case([&](DenseResourceElementsAttr t) { return write(t, writer); }) .Case([&](DenseStringElementsAttr t) { return write(t, writer); }) .Case([&](DenseTypedElementsAttr t) { return write(t, writer); }) .Case([&](DictionaryAttr t) { return write(t, writer); }) .Case([&](DistinctAttr t) { return write(t, writer); }) .Case([&](FileLineColRange t) { return write(t, writer); }) .Case([&](FlatSymbolRefAttr t) { return write(t, writer); }) .Case([&](FloatAttr t) { return write(t, writer); }) .Case([&](FusedLoc t) { return write(t, writer); }) .Case([&](IntegerAttr t) { return write(t, writer); }) .Case([&](NameLoc t) { return write(t, writer); }) .Case([&](SparseElementsAttr t) { return write(t, writer); }) .Case([&](StringAttr t) { return write(t, writer); }) .Case([&](SymbolRefAttr t) { return write(t, writer); }) .Case([&](TypeAttr t) { return write(t, writer); }) .Case([&](UnitAttr t) { return write(t, writer); }) .Case([&](UnknownLoc t) { return write(t, writer); }) .Default([&](Attribute) { return failure(); }); } static ::mlir::Type readBFloat16Type(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(BFloat16Type type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* BFloat16Type */ 3); return success(); return failure(); } static ::mlir::Type readComplexType(MLIRContext* context, DialectBytecodeReader &reader) { Type elementType; if (succeeded(reader.readType(elementType))) { return getChecked([&]() { return reader.emitError(); }, context, elementType); } return ComplexType(); } static LogicalResult write(ComplexType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* ComplexType */ 9); writer.writeType(type.getElementType()); return success(); return failure(); } static ::mlir::Type readFloat128Type(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float128Type type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float128Type */ 8); return success(); return failure(); } static ::mlir::Type readFloat16Type(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float16Type type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float16Type */ 4); return success(); return failure(); } static ::mlir::Type readFloat32Type(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float32Type type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float32Type */ 5); return success(); return failure(); } static ::mlir::Type readFloat4E2M1FNType(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float4E2M1FNType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float4E2M1FNType */ 29); return success(); return failure(); } static ::mlir::Type readFloat64Type(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float64Type type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float64Type */ 6); return success(); return failure(); } static ::mlir::Type readFloat6E2M3FNType(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float6E2M3FNType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float6E2M3FNType */ 30); return success(); return failure(); } static ::mlir::Type readFloat6E3M2FNType(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float6E3M2FNType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float6E3M2FNType */ 31); return success(); return failure(); } static ::mlir::Type readFloat80Type(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float80Type type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float80Type */ 7); return success(); return failure(); } static ::mlir::Type readFloat8E3M4Type(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float8E3M4Type type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float8E3M4Type */ 28); return success(); return failure(); } static ::mlir::Type readFloat8E4M3B11FNUZType(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float8E4M3B11FNUZType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float8E4M3B11FNUZType */ 27); return success(); return failure(); } static ::mlir::Type readFloat8E4M3FNType(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float8E4M3FNType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float8E4M3FNType */ 24); return success(); return failure(); } static ::mlir::Type readFloat8E4M3FNUZType(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float8E4M3FNUZType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float8E4M3FNUZType */ 26); return success(); return failure(); } static ::mlir::Type readFloat8E4M3Type(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float8E4M3Type type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float8E4M3Type */ 23); return success(); return failure(); } static ::mlir::Type readFloat8E5M2FNUZType(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float8E5M2FNUZType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float8E5M2FNUZType */ 25); return success(); return failure(); } static ::mlir::Type readFloat8E5M2Type(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float8E5M2Type type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float8E5M2Type */ 22); return success(); return failure(); } static ::mlir::Type readFloat8E8M0FNUType(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(Float8E8M0FNUType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* Float8E8M0FNUType */ 32); return success(); return failure(); } static ::mlir::Type readFloatTF32Type(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(FloatTF32Type type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* FloatTF32Type */ 21); return success(); return failure(); } static ::mlir::Type readFunctionType(MLIRContext* context, DialectBytecodeReader &reader) { SmallVector inputs, results; if (succeeded(reader.readTypes(inputs)) && succeeded(reader.readTypes(results))) { return getChecked([&]() { return reader.emitError(); }, context, inputs, results); } return FunctionType(); } static LogicalResult write(FunctionType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* FunctionType */ 2); writer.writeTypes(type.getInputs()); writer.writeTypes(type.getResults()); return success(); return failure(); } static ::mlir::Type readIndexType(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(IndexType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* IndexType */ 1); return success(); return failure(); } static ::mlir::Type readIntegerType(MLIRContext* context, DialectBytecodeReader &reader) { uint64_t _widthAndSignedness, width; IntegerType::SignednessSemantics signedness; if (succeeded(reader.readVarInt(_widthAndSignedness)) && ((width = _widthAndSignedness >> 2), true) && ((signedness = static_cast(_widthAndSignedness & 0x3)), true)) { return getChecked([&]() { return reader.emitError(); }, context, width, signedness); } return IntegerType(); } static LogicalResult write(IntegerType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* IntegerType */ 0); writer.writeVarInt(type.getWidth() << 2 | type.getSignedness()); return success(); return failure(); } static ::mlir::Type readMemRefType(MLIRContext* context, DialectBytecodeReader &reader) { SmallVector shape; Type elementType; MemRefLayoutAttrInterface layout; auto readShape = [&]() -> FailureOr { int64_t temp; if (succeeded(reader.readSignedVarInt(temp))) { return temp; } return failure(); }; if (succeeded(reader.readList(shape, readShape)) && succeeded(reader.readType(elementType)) && succeeded(reader.readAttribute(layout))) { return getChecked([&]() { return reader.emitError(); }, context, shape, elementType, layout); } return MemRefType(); } static ::mlir::Type readMemRefTypeWithMemSpace(MLIRContext* context, DialectBytecodeReader &reader) { Attribute memorySpace; SmallVector shape; Type elementType; MemRefLayoutAttrInterface layout; auto readShape = [&]() -> FailureOr { int64_t temp; if (succeeded(reader.readSignedVarInt(temp))) { return temp; } return failure(); }; if (succeeded(reader.readAttribute(memorySpace)) && succeeded(reader.readList(shape, readShape)) && succeeded(reader.readType(elementType)) && succeeded(reader.readAttribute(layout))) { return getChecked([&]() { return reader.emitError(); }, context, shape, elementType, layout, memorySpace); } return MemRefType(); } static LogicalResult write(MemRefType type, DialectBytecodeWriter &writer) { if (!type.getMemorySpace()) { writer.writeVarInt(/* MemRefType */ 10); writer.writeList(type.getShape(), [&](int64_t type) { writer.writeSignedVarInt(type); }); writer.writeType(type.getElementType()); writer.writeAttribute(type.getLayout()); return success(); } if (!!type.getMemorySpace()) { writer.writeVarInt(/* MemRefTypeWithMemSpace */ 11); writer.writeAttribute(type.getMemorySpace()); writer.writeList(type.getShape(), [&](int64_t type) { writer.writeSignedVarInt(type); }); writer.writeType(type.getElementType()); writer.writeAttribute(type.getLayout()); return success(); } return failure(); } static ::mlir::Type readNoneType(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(NoneType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* NoneType */ 12); return success(); return failure(); } static ::mlir::Type readRankedTensorType(MLIRContext* context, DialectBytecodeReader &reader) { SmallVector shape; Type elementType; auto readShape = [&]() -> FailureOr { int64_t temp; if (succeeded(reader.readSignedVarInt(temp))) { return temp; } return failure(); }; if (succeeded(reader.readList(shape, readShape)) && succeeded(reader.readType(elementType))) { return getChecked([&]() { return reader.emitError(); }, context, shape, elementType); } return RankedTensorType(); } static ::mlir::Type readRankedTensorTypeWithEncoding(MLIRContext* context, DialectBytecodeReader &reader) { Attribute encoding; SmallVector shape; Type elementType; auto readShape = [&]() -> FailureOr { int64_t temp; if (succeeded(reader.readSignedVarInt(temp))) { return temp; } return failure(); }; if (succeeded(reader.readAttribute(encoding)) && succeeded(reader.readList(shape, readShape)) && succeeded(reader.readType(elementType))) { return getChecked([&]() { return reader.emitError(); }, context, shape, elementType, encoding); } return RankedTensorType(); } static LogicalResult write(RankedTensorType type, DialectBytecodeWriter &writer) { if (!type.getEncoding()) { writer.writeVarInt(/* RankedTensorType */ 13); writer.writeList(type.getShape(), [&](int64_t type) { writer.writeSignedVarInt(type); }); writer.writeType(type.getElementType()); return success(); } if (type.getEncoding()) { writer.writeVarInt(/* RankedTensorTypeWithEncoding */ 14); writer.writeAttribute(type.getEncoding()); writer.writeList(type.getShape(), [&](int64_t type) { writer.writeSignedVarInt(type); }); writer.writeType(type.getElementType()); return success(); } return failure(); } static ::mlir::Type readTokenType(MLIRContext* context, DialectBytecodeReader &reader) { return getChecked([&]() { return reader.emitError(); }, context); } static LogicalResult write(TokenType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* TokenType */ 33); return success(); return failure(); } static ::mlir::Type readTupleType(MLIRContext* context, DialectBytecodeReader &reader) { SmallVector types; if (succeeded(reader.readTypes(types))) { return getChecked([&]() { return reader.emitError(); }, context, types); } return TupleType(); } static LogicalResult write(TupleType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* TupleType */ 15); writer.writeTypes(type.getTypes()); return success(); return failure(); } static ::mlir::Type readUnrankedMemRefType(MLIRContext* context, DialectBytecodeReader &reader) { Type elementType; if (succeeded(reader.readType(elementType))) { return getChecked([&]() { return reader.emitError(); }, context, elementType, Attribute()); } return UnrankedMemRefType(); } static ::mlir::Type readUnrankedMemRefTypeWithMemSpace(MLIRContext* context, DialectBytecodeReader &reader) { Attribute memorySpace; Type elementType; if (succeeded(reader.readAttribute(memorySpace)) && succeeded(reader.readType(elementType))) { return getChecked([&]() { return reader.emitError(); }, context, elementType, memorySpace); } return UnrankedMemRefType(); } static LogicalResult write(UnrankedMemRefType type, DialectBytecodeWriter &writer) { if (!type.getMemorySpace()) { writer.writeVarInt(/* UnrankedMemRefType */ 16); writer.writeType(type.getElementType()); return success(); } if (type.getMemorySpace()) { writer.writeVarInt(/* UnrankedMemRefTypeWithMemSpace */ 17); writer.writeAttribute(type.getMemorySpace()); writer.writeType(type.getElementType()); return success(); } return failure(); } static ::mlir::Type readUnrankedTensorType(MLIRContext* context, DialectBytecodeReader &reader) { Type elementType; if (succeeded(reader.readType(elementType))) { return getChecked([&]() { return reader.emitError(); }, context, elementType); } return UnrankedTensorType(); } static LogicalResult write(UnrankedTensorType type, DialectBytecodeWriter &writer) { writer.writeVarInt(/* UnrankedTensorType */ 18); writer.writeType(type.getElementType()); return success(); return failure(); } static ::mlir::Type readVectorType(MLIRContext* context, DialectBytecodeReader &reader) { SmallVector shape; Type elementType; auto readShape = [&]() -> FailureOr { int64_t temp; if (succeeded(reader.readSignedVarInt(temp))) { return temp; } return failure(); }; if (succeeded(reader.readList(shape, readShape)) && succeeded(reader.readType(elementType))) { return VectorType::getChecked([&]() { return reader.emitError("invalid vector type"); }, shape, elementType); } return VectorType(); } static ::mlir::Type readVectorTypeWithScalableDims(MLIRContext* context, DialectBytecodeReader &reader) { SmallVector scalableDims; SmallVector shape; Type elementType; auto readScalableDims = [&]() -> FailureOr { bool temp; if (succeeded(reader.readBool(temp))) { return temp; } return failure(); }; auto readShape = [&]() -> FailureOr { int64_t temp; if (succeeded(reader.readSignedVarInt(temp))) { return temp; } return failure(); }; if (succeeded(reader.readList(scalableDims, readScalableDims)) && succeeded(reader.readList(shape, readShape)) && succeeded(reader.readType(elementType))) { return getChecked([&]() { return reader.emitError(); }, context, shape, elementType, scalableDims); } return VectorType(); } static LogicalResult write(VectorType type, DialectBytecodeWriter &writer) { if (!type.isScalable()) { writer.writeVarInt(/* VectorType */ 19); writer.writeList(type.getShape(), [&](int64_t type) { writer.writeSignedVarInt(type); }); writer.writeType(type.getElementType()); return success(); } if (type.isScalable()) { writer.writeVarInt(/* VectorTypeWithScalableDims */ 20); writer.writeList(type.getScalableDims(), [&](bool type) { writer.writeOwnedBool(type); }); writer.writeList(type.getShape(), [&](int64_t type) { writer.writeSignedVarInt(type); }); writer.writeType(type.getElementType()); return success(); } return failure(); } static Type readType(MLIRContext* context, DialectBytecodeReader &reader) { uint64_t kind; if (failed(reader.readVarInt(kind))) return Type(); switch (kind) { case 0: return readIntegerType(context, reader); case 1: return readIndexType(context, reader); case 2: return readFunctionType(context, reader); case 3: return readBFloat16Type(context, reader); case 4: return readFloat16Type(context, reader); case 5: return readFloat32Type(context, reader); case 6: return readFloat64Type(context, reader); case 7: return readFloat80Type(context, reader); case 8: return readFloat128Type(context, reader); case 9: return readComplexType(context, reader); case 10: return readMemRefType(context, reader); case 11: return readMemRefTypeWithMemSpace(context, reader); case 12: return readNoneType(context, reader); case 13: return readRankedTensorType(context, reader); case 14: return readRankedTensorTypeWithEncoding(context, reader); case 15: return readTupleType(context, reader); case 16: return readUnrankedMemRefType(context, reader); case 17: return readUnrankedMemRefTypeWithMemSpace(context, reader); case 18: return readUnrankedTensorType(context, reader); case 19: return readVectorType(context, reader); case 20: return readVectorTypeWithScalableDims(context, reader); case 21: return readFloatTF32Type(context, reader); case 22: return readFloat8E5M2Type(context, reader); case 23: return readFloat8E4M3Type(context, reader); case 24: return readFloat8E4M3FNType(context, reader); case 25: return readFloat8E5M2FNUZType(context, reader); case 26: return readFloat8E4M3FNUZType(context, reader); case 27: return readFloat8E4M3B11FNUZType(context, reader); case 28: return readFloat8E3M4Type(context, reader); case 29: return readFloat4E2M1FNType(context, reader); case 30: return readFloat6E2M3FNType(context, reader); case 31: return readFloat6E3M2FNType(context, reader); case 32: return readFloat8E8M0FNUType(context, reader); case 33: return readTokenType(context, reader); default: reader.emitError() << "unknown attribute code: " << kind; return Type(); } return Type(); } static LogicalResult writeType(Type type, DialectBytecodeWriter &writer) { return TypeSwitch(type) .Case([&](BFloat16Type t) { return write(t, writer); }) .Case([&](ComplexType t) { return write(t, writer); }) .Case([&](Float128Type t) { return write(t, writer); }) .Case([&](Float16Type t) { return write(t, writer); }) .Case([&](Float32Type t) { return write(t, writer); }) .Case([&](Float4E2M1FNType t) { return write(t, writer); }) .Case([&](Float64Type t) { return write(t, writer); }) .Case([&](Float6E2M3FNType t) { return write(t, writer); }) .Case([&](Float6E3M2FNType t) { return write(t, writer); }) .Case([&](Float80Type t) { return write(t, writer); }) .Case([&](Float8E3M4Type t) { return write(t, writer); }) .Case([&](Float8E4M3B11FNUZType t) { return write(t, writer); }) .Case([&](Float8E4M3FNType t) { return write(t, writer); }) .Case([&](Float8E4M3FNUZType t) { return write(t, writer); }) .Case([&](Float8E4M3Type t) { return write(t, writer); }) .Case([&](Float8E5M2FNUZType t) { return write(t, writer); }) .Case([&](Float8E5M2Type t) { return write(t, writer); }) .Case([&](Float8E8M0FNUType t) { return write(t, writer); }) .Case([&](FloatTF32Type t) { return write(t, writer); }) .Case([&](FunctionType t) { return write(t, writer); }) .Case([&](IndexType t) { return write(t, writer); }) .Case([&](IntegerType t) { return write(t, writer); }) .Case([&](MemRefType t) { return write(t, writer); }) .Case([&](NoneType t) { return write(t, writer); }) .Case([&](RankedTensorType t) { return write(t, writer); }) .Case([&](TokenType t) { return write(t, writer); }) .Case([&](TupleType t) { return write(t, writer); }) .Case([&](UnrankedMemRefType t) { return write(t, writer); }) .Case([&](UnrankedTensorType t) { return write(t, writer); }) .Case([&](VectorType t) { return write(t, writer); }) .Default([&](Type) { return failure(); }); }