示例01 -gen-dialect-decls
toy_dia.1.toy
include "mlir/IR/OpBase.td"
//include "mlir/IR/FunctionInterfaces.td"
//include "mlir/IR/SymbolInterfaces.td"
//include "mlir/Interfaces/SideEffectInterfaces.td"def Toy_Dialect : Dialect {let name = "toy";let summary = "A high-level dialect for analyzing and optimizing the Toy language";let description = [{The Toy language is a tensor-based languange that allowssss you to define functions.}];let cppNamespace = "toy";
}
命令:
../../../llvm-project/build_mlir_15/bin/mlir-tblgen -gen-dialect-decls ./toy_dia.1.td -I ../../../llvm-project/mlir/include
生成:
示例02 no def -gen-op-decls
源码:
toy_op.1.td:
include "mlir/IR/OpBase.td"
//include "mlir/IR/FunctionInterfaces.td"
//include "mlir/IR/SymbolInterfaces.td"
//include "mlir/Interfaces/SideEffectInterfaces.td"def Toy_Dialect : Dialect {let name = "toy";let summary = "A high-level dialect for analyzing and optimizing the Toy language";let description = [{The Toy language is a tensor-based languange that allowssss you to define functions.}];let cppNamespace = "toy";
}class Toy_Op<string mnemonic, list<Trait> traits = []> :Op<Toy_Dialect, mnemonic, traits>;
命令:
$ mlir-tblgen -gen-op-decls ./toy_op.1.td -I ../../../llvm-project/mlir/include/
生成:
示例03 -gen-op-decls
toy_dia.2.toy:
include "mlir/IR/OpBase.td"
//include "mlir/IR/FunctionInterfaces.td"
//include "mlir/IR/SymbolInterfaces.td"
//include "mlir/Interfaces/SideEffectInterfaces.td"def Toy_Dialect : Dialect {let name = "toy";let summary = "A high-level dialect for analyzing and optimizing the Toy language";let description = [{The Toy language is a tensor-based languange that allowssss you to define functions.}];let cppNamespace = "toy";
}class Toy_Op<string mnemonic, list<Trait> traits = []> :Op<Toy_Dialect, mnemonic, traits>;def ConstantOp : Toy_Op<"constant"> {
}
命令:
$ mlir-tblgen -gen-op-decls ./toy_dia.2.td -I ../../../llvm-project/mlir/include/
生成:
示例04
源码:
include "mlir/IR/OpBase.td"
//include "mlir/IR/FunctionInterfaces.td"
//include "mlir/IR/SymbolInterfaces.td"
//include "mlir/Interfaces/SideEffectInterfaces.td"def Toy_Dialect : Dialect {let name = "toy";let summary = "A high-level dialect for analyzing and optimizing the Toy language";let description = [{The Toy language is a tensor-based languange that allowssss you to define functions.}];let cppNamespace = "toy";
}class Toy_Op<string mnemonic, list<Trait> traits = []> :Op<Toy_Dialect, mnemonic, traits>;def ConstantOp : Toy_Op<"constant"> {let arguments = (ins F64ElementsAttr:$value);let results = (outs F64Tensor);
}
命令:
llvm-project/build_mlir_15/bin/mlir-tblgen -gen-op-decls ./toy_op.3.td -I ../../../llvm-project/mlir/include
生成:
$ ../../../llvm-project/build_mlir_15/bin/mlir-tblgen -gen-op-decls ./toy_op.3.td -I ../../../llvm-project/mlir/include
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|* *|
|* Op Declarations *|
|* *|
|* Automatically generated file, do not edit! *|
|* *|
\*===----------------------------------------------------------------------===*/#if defined(GET_OP_CLASSES) || defined(GET_OP_FWD_DEFINES)
#undef GET_OP_FWD_DEFINES
namespace toy {
class ConstantOp;
} // namespace toy
#endif#ifdef GET_OP_CLASSES
#undef GET_OP_CLASSES//===----------------------------------------------------------------------===//
// Local Utility Method Definitions
//===----------------------------------------------------------------------===//namespace toy {//===----------------------------------------------------------------------===//
// toy::ConstantOp declarations
//===----------------------------------------------------------------------===//class ConstantOpAdaptor {
public:ConstantOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs = nullptr, ::mlir::RegionRange regions = {});ConstantOpAdaptor(ConstantOp op);::mlir::ValueRange getOperands();std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index);::mlir::ValueRange getODSOperands(unsigned index);::mlir::DictionaryAttr getAttributes();::mlir::DenseElementsAttr valueAttr();::mlir::DenseElementsAttr value();::mlir::LogicalResult verify(::mlir::Location loc);
private:::mlir::ValueRange odsOperands;::mlir::DictionaryAttr odsAttrs;::mlir::RegionRange odsRegions;::llvm::Optional<::mlir::OperationName> odsOpName;
};
class ConstantOp : public ::mlir::Op<ConstantOp, ::mlir::OpTrait::ZeroRegions, ::mlir::OpTrait::OneResult, ::mlir::OpTrait::OneTypedResult<::mlir::TensorType>::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::ZeroOperands, ::mlir::OpTrait::OpInvariants> {
public:using Op::Op;using Op::print;using Adaptor = ConstantOpAdaptor;
public:static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() {static ::llvm::StringRef attrNames[] = {::llvm::StringRef("value")};return ::llvm::makeArrayRef(attrNames);}::mlir::StringAttr valueAttrName() {return getAttributeNameForIndex(0);}static ::mlir::StringAttr valueAttrName(::mlir::OperationName name) {return getAttributeNameForIndex(name, 0);}static constexpr ::llvm::StringLiteral getOperationName() {return ::llvm::StringLiteral("toy.constant");}std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index);::mlir::Operation::operand_range getODSOperands(unsigned index);std::pair<unsigned, unsigned> getODSResultIndexAndLength(unsigned index);::mlir::Operation::result_range getODSResults(unsigned index);::mlir::DenseElementsAttr valueAttr();::mlir::DenseElementsAttr value();void valueAttr(::mlir::DenseElementsAttr attr);static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value);static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value);static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});::mlir::LogicalResult verifyInvariantsImpl();::mlir::LogicalResult verifyInvariants();
private:::mlir::StringAttr getAttributeNameForIndex(unsigned index) {return getAttributeNameForIndex((*this)->getName(), index);}static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) {assert(index < 1 && "invalid attribute index");return name.getRegisteredInfo()->getAttributeNames()[index];}public:
};
} // namespace toy
MLIR_DECLARE_EXPLICIT_TYPE_ID(toy::ConstantOp)#endif // GET_OP_CLASSES