[MLIR] Convert BytecodeDialectInterface to ods (#188852)
This PR converts `BytecodeDialectInterface` to ODS.
This commit is contained in:
93
mlir/include/mlir/Bytecode/BytecodeDialectInterface.td
Normal file
93
mlir/include/mlir/Bytecode/BytecodeDialectInterface.td
Normal file
@@ -0,0 +1,93 @@
|
||||
#ifndef MLIR_INTERFACES_BYTECODEDIALECTINTERFACE
|
||||
#define MLIR_INTERFACES_BYTECODEDIALECTINTERFACE
|
||||
|
||||
include "mlir/IR/Interfaces.td"
|
||||
|
||||
def BytecodeDialectInterface : DialectInterface<"BytecodeDialectInterface"> {
|
||||
let description = [{}];
|
||||
let cppNamespace = "::mlir";
|
||||
|
||||
let methods = [
|
||||
InterfaceMethod<[{
|
||||
Read an attribute belonging to this dialect from the given reader. This
|
||||
method should return null in the case of failure. Optionally, the dialect
|
||||
version can be accessed through the reader.
|
||||
}],
|
||||
"::mlir::Attribute", "readAttribute",
|
||||
(ins "::mlir::DialectBytecodeReader &":$reader),
|
||||
[{
|
||||
reader.emitError() << "dialect " << getDialect()->getNamespace()
|
||||
<< " does not support reading attributes from bytecode";
|
||||
return ::mlir::Attribute();
|
||||
}]
|
||||
>,
|
||||
InterfaceMethod<[{
|
||||
Read a type belonging to this dialect from the given reader. This method
|
||||
should return null in the case of failure. Optionally, the dialect version
|
||||
can be accessed thorugh the reader.
|
||||
}],
|
||||
"::mlir::Type", "readType", (ins "::mlir::DialectBytecodeReader &":$reader),
|
||||
[{
|
||||
reader.emitError() << "dialect " << getDialect()->getNamespace()
|
||||
<< " does not support reading types from bytecode";
|
||||
return ::mlir::Type();
|
||||
}]
|
||||
>,
|
||||
InterfaceMethod<[{
|
||||
Write the given attribute, which belongs to this dialect, to the given
|
||||
writer. This method may return failure to indicate that the given
|
||||
attribute could not be encoded, in which case the textual format will be
|
||||
used to encode this attribute instead.
|
||||
}],
|
||||
"::llvm::LogicalResult", "writeAttribute",
|
||||
(ins "::mlir::Attribute":$attribute, "::mlir::DialectBytecodeWriter &":$writer),
|
||||
[{
|
||||
return ::llvm::failure();
|
||||
}]
|
||||
>,
|
||||
InterfaceMethod<[{
|
||||
Write the given type, which belongs to this dialect, to the given writer.
|
||||
This method may return failure to indicate that the given type could not
|
||||
be encoded, in which case the textual format will be used to encode this
|
||||
type instead.
|
||||
}],
|
||||
"::llvm::LogicalResult", "writeType",
|
||||
(ins "::mlir::Type":$type, "::mlir::DialectBytecodeWriter &":$writer),
|
||||
[{
|
||||
return ::llvm::failure();
|
||||
}]
|
||||
>,
|
||||
InterfaceMethod<[{
|
||||
Write the version of this dialect to the given writer.
|
||||
}],
|
||||
"void", "writeVersion",
|
||||
(ins "::mlir::DialectBytecodeWriter &":$writer)
|
||||
>,
|
||||
InterfaceMethod<[{
|
||||
Read the version of this dialect from the provided reader and return it as
|
||||
a `unique_ptr` to a dialect version object.
|
||||
}],
|
||||
"std::unique_ptr<::mlir::DialectVersion>", "readVersion",
|
||||
(ins "::mlir::DialectBytecodeReader &":$reader),
|
||||
[{
|
||||
reader.emitError("Dialect does not support versioning");
|
||||
return nullptr;
|
||||
}]
|
||||
>,
|
||||
InterfaceMethod<[{
|
||||
Hook invoked after parsing completed, if a version directive was present
|
||||
and included an entry for the current dialect. This hook offers the
|
||||
opportunity to the dialect to visit the IR and upgrades constructs emitted
|
||||
by the version of the dialect corresponding to the provided version.
|
||||
}],
|
||||
"::llvm::LogicalResult", "upgradeFromVersion",
|
||||
(ins "::mlir::Operation *":$topLevelOp, "const ::mlir::DialectVersion &":$version),
|
||||
[{
|
||||
return ::llvm::success();
|
||||
}]
|
||||
>
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -421,81 +421,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// BytecodeDialectInterface
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
class BytecodeDialectInterface
|
||||
: public DialectInterface::Base<BytecodeDialectInterface> {
|
||||
public:
|
||||
using Base::Base;
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Reading
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
||||
/// Read an attribute belonging to this dialect from the given reader. This
|
||||
/// method should return null in the case of failure. Optionally, the dialect
|
||||
/// version can be accessed through the reader.
|
||||
virtual Attribute readAttribute(DialectBytecodeReader &reader) const {
|
||||
reader.emitError() << "dialect " << getDialect()->getNamespace()
|
||||
<< " does not support reading attributes from bytecode";
|
||||
return Attribute();
|
||||
}
|
||||
|
||||
/// Read a type belonging to this dialect from the given reader. This method
|
||||
/// should return null in the case of failure. Optionally, the dialect version
|
||||
/// can be accessed thorugh the reader.
|
||||
virtual Type readType(DialectBytecodeReader &reader) const {
|
||||
reader.emitError() << "dialect " << getDialect()->getNamespace()
|
||||
<< " does not support reading types from bytecode";
|
||||
return Type();
|
||||
}
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Writing
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
||||
/// Write the given attribute, which belongs to this dialect, to the given
|
||||
/// writer. This method may return failure to indicate that the given
|
||||
/// attribute could not be encoded, in which case the textual format will be
|
||||
/// used to encode this attribute instead.
|
||||
virtual LogicalResult writeAttribute(Attribute attr,
|
||||
DialectBytecodeWriter &writer) const {
|
||||
return failure();
|
||||
}
|
||||
|
||||
/// Write the given type, which belongs to this dialect, to the given writer.
|
||||
/// This method may return failure to indicate that the given type could not
|
||||
/// be encoded, in which case the textual format will be used to encode this
|
||||
/// type instead.
|
||||
virtual LogicalResult writeType(Type type,
|
||||
DialectBytecodeWriter &writer) const {
|
||||
return failure();
|
||||
}
|
||||
|
||||
/// Write the version of this dialect to the given writer.
|
||||
virtual void writeVersion(DialectBytecodeWriter &writer) const {}
|
||||
|
||||
// Read the version of this dialect from the provided reader and return it as
|
||||
// a `unique_ptr` to a dialect version object.
|
||||
virtual std::unique_ptr<DialectVersion>
|
||||
readVersion(DialectBytecodeReader &reader) const {
|
||||
reader.emitError("Dialect does not support versioning");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/// Hook invoked after parsing completed, if a version directive was present
|
||||
/// and included an entry for the current dialect. This hook offers the
|
||||
/// opportunity to the dialect to visit the IR and upgrades constructs emitted
|
||||
/// by the version of the dialect corresponding to the provided version.
|
||||
virtual LogicalResult
|
||||
upgradeFromVersion(Operation *topLevelOp,
|
||||
const DialectVersion &version) const {
|
||||
return success();
|
||||
}
|
||||
};
|
||||
|
||||
/// Helper for resource handle reading that returns LogicalResult.
|
||||
template <typename T, typename... Ts>
|
||||
static LogicalResult readResourceHandle(DialectBytecodeReader &reader,
|
||||
@@ -559,4 +484,6 @@ auto getChecked(function_ref<InFlightDiagnostic()> emitError,
|
||||
|
||||
} // namespace mlir
|
||||
|
||||
#include "mlir/Bytecode/BytecodeDialectInterface.h.inc"
|
||||
|
||||
#endif // MLIR_BYTECODE_BYTECODEIMPLEMENTATION_H
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
add_mlir_interface(BytecodeOpInterface)
|
||||
|
||||
set(LLVM_TARGET_DEFINITIONS BytecodeDialectInterface.td)
|
||||
mlir_tablegen(BytecodeDialectInterface.h.inc -gen-dialect-interface-decls)
|
||||
add_mlir_generic_tablegen_target(MLIRBytecodeDialectInterfaceIncGen)
|
||||
|
||||
@@ -403,6 +403,16 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
gentbl_cc_library(
|
||||
name = "BytecodeDialectInterfaceIncGen",
|
||||
tbl_outs = {
|
||||
"include/mlir/Bytecode/BytecodeDialectInterface.h.inc": ["-gen-dialect-interface-decls"],
|
||||
},
|
||||
tblgen = ":mlir-tblgen",
|
||||
td_file = "include/mlir/Bytecode/BytecodeDialectInterface.td",
|
||||
deps = [":OpBaseTdFiles"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "IR",
|
||||
srcs = glob([
|
||||
@@ -435,6 +445,7 @@ cc_library(
|
||||
":BuiltinOpsIncGen",
|
||||
":BuiltinTypeInterfacesIncGen",
|
||||
":BuiltinTypesIncGen",
|
||||
":BytecodeDialectInterfaceIncGen",
|
||||
":BytecodeOpInterfaceIncGen",
|
||||
":CallOpInterfacesIncGen",
|
||||
":DataLayoutInterfacesIncGen",
|
||||
@@ -5379,6 +5390,7 @@ cc_library(
|
||||
),
|
||||
includes = ["include"],
|
||||
deps = [
|
||||
":BytecodeDialectInterfaceIncGen",
|
||||
":BytecodeOpInterface",
|
||||
":CallOpInterfaces",
|
||||
":ControlFlowInterfaces",
|
||||
@@ -8695,6 +8707,7 @@ cc_library(
|
||||
],
|
||||
includes = ["include"],
|
||||
deps = [
|
||||
":BytecodeDialectInterfaceIncGen",
|
||||
":BytecodeOpInterfaceIncGen",
|
||||
":IR",
|
||||
"//llvm:Support",
|
||||
@@ -10775,6 +10788,7 @@ cc_library(
|
||||
],
|
||||
includes = ["include"],
|
||||
deps = [
|
||||
":BytecodeDialectInterfaceIncGen",
|
||||
":BytecodeOpInterface",
|
||||
":IR",
|
||||
":InferTypeOpInterface",
|
||||
@@ -11965,6 +11979,7 @@ cc_library(
|
||||
includes = ["include"],
|
||||
deps = [
|
||||
":ArithDialect",
|
||||
":BytecodeDialectInterfaceIncGen",
|
||||
":BytecodeOpInterface",
|
||||
":Dialect",
|
||||
":DialectUtils",
|
||||
|
||||
@@ -385,6 +385,7 @@ cc_library(
|
||||
"//mlir:ArithDialect",
|
||||
"//mlir:BufferizationDialect",
|
||||
"//mlir:BufferizationInterfaces",
|
||||
"//mlir:BytecodeDialectInterfaceIncGen",
|
||||
"//mlir:BytecodeOpInterface",
|
||||
"//mlir:CallOpInterfaces",
|
||||
"//mlir:CommonFolders",
|
||||
|
||||
Reference in New Issue
Block a user