[Mlir-commits] [mlir] 8de6260 - [mlir:toy][NFC] Add comment blocks for toy operations.
River Riddle
llvmlistbot at llvm.org
Tue Mar 8 16:27:10 PST 2022
Author: River Riddle
Date: 2022-03-08T16:22:38-08:00
New Revision: 8de6260a204b2e2c5546e3bc10d961eddd237eb7
URL: https://github.com/llvm/llvm-project/commit/8de6260a204b2e2c5546e3bc10d961eddd237eb7
DIFF: https://github.com/llvm/llvm-project/commit/8de6260a204b2e2c5546e3bc10d961eddd237eb7.diff
LOG: [mlir:toy][NFC] Add comment blocks for toy operations.
Added:
Modified:
mlir/examples/toy/Ch2/include/toy/Ops.td
mlir/examples/toy/Ch2/mlir/Dialect.cpp
mlir/examples/toy/Ch3/include/toy/Ops.td
mlir/examples/toy/Ch3/mlir/Dialect.cpp
mlir/examples/toy/Ch4/include/toy/Ops.td
mlir/examples/toy/Ch4/mlir/Dialect.cpp
mlir/examples/toy/Ch5/include/toy/Ops.td
mlir/examples/toy/Ch5/mlir/Dialect.cpp
mlir/examples/toy/Ch6/include/toy/Ops.td
mlir/examples/toy/Ch6/mlir/Dialect.cpp
mlir/examples/toy/Ch7/include/toy/Ops.td
mlir/examples/toy/Ch7/mlir/Dialect.cpp
Removed:
################################################################################
diff --git a/mlir/examples/toy/Ch2/include/toy/Ops.td b/mlir/examples/toy/Ch2/include/toy/Ops.td
index 4e7e2312d1df6..ade3ed7e54a72 100644
--- a/mlir/examples/toy/Ch2/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch2/include/toy/Ops.td
@@ -35,6 +35,10 @@ class Toy_Op<string mnemonic, list<Trait> traits = []> :
// Toy Operations
//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+// ConstantOp
+//===----------------------------------------------------------------------===//
+
// We define a toy operation by inheriting from our base 'Toy_Op' class above.
// Here we provide the mnemonic and a list of traits for the operation. The
// constant operation is marked as 'NoSideEffect' as it is a pure operation
@@ -79,6 +83,10 @@ def ConstantOp : Toy_Op<"constant", [NoSideEffect]> {
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// AddOp
+//===----------------------------------------------------------------------===//
+
def AddOp : Toy_Op<"add"> {
let summary = "element-wise addition operation";
let description = [{
@@ -98,6 +106,10 @@ def AddOp : Toy_Op<"add"> {
];
}
+//===----------------------------------------------------------------------===//
+// GenericCallOp
+//===----------------------------------------------------------------------===//
+
def GenericCallOp : Toy_Op<"generic_call"> {
let summary = "generic call operation";
let description = [{
@@ -133,6 +145,10 @@ def GenericCallOp : Toy_Op<"generic_call"> {
];
}
+//===----------------------------------------------------------------------===//
+// MulOp
+//===----------------------------------------------------------------------===//
+
def MulOp : Toy_Op<"mul"> {
let summary = "element-wise multiplication operation";
let description = [{
@@ -152,6 +168,10 @@ def MulOp : Toy_Op<"mul"> {
];
}
+//===----------------------------------------------------------------------===//
+// PrintOp
+//===----------------------------------------------------------------------===//
+
def PrintOp : Toy_Op<"print"> {
let summary = "print operation";
let description = [{
@@ -165,6 +185,10 @@ def PrintOp : Toy_Op<"print"> {
let assemblyFormat = "$input attr-dict `:` type($input)";
}
+//===----------------------------------------------------------------------===//
+// ReshapeOp
+//===----------------------------------------------------------------------===//
+
def ReshapeOp : Toy_Op<"reshape"> {
let summary = "tensor reshape operation";
let description = [{
@@ -186,6 +210,10 @@ def ReshapeOp : Toy_Op<"reshape"> {
}];
}
+//===----------------------------------------------------------------------===//
+// ReturnOp
+//===----------------------------------------------------------------------===//
+
def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
Terminator]> {
let summary = "return operation";
@@ -224,6 +252,10 @@ def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// TransposeOp
+//===----------------------------------------------------------------------===//
+
def TransposeOp : Toy_Op<"transpose"> {
let summary = "transpose operation";
diff --git a/mlir/examples/toy/Ch2/mlir/Dialect.cpp b/mlir/examples/toy/Ch2/mlir/Dialect.cpp
index 46b55f57a0d1d..67908d4bbf091 100644
--- a/mlir/examples/toy/Ch2/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch2/mlir/Dialect.cpp
@@ -89,6 +89,7 @@ static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
//===----------------------------------------------------------------------===//
// ConstantOp
+//===----------------------------------------------------------------------===//
/// Build a constant operation.
/// The builder is passed as an argument, so is the state that this method is
@@ -158,6 +159,7 @@ mlir::LogicalResult ConstantOp::verify() {
//===----------------------------------------------------------------------===//
// AddOp
+//===----------------------------------------------------------------------===//
void AddOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -174,6 +176,7 @@ void AddOp::print(mlir::OpAsmPrinter &p) { printBinaryOp(p, *this); }
//===----------------------------------------------------------------------===//
// GenericCallOp
+//===----------------------------------------------------------------------===//
void GenericCallOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
StringRef callee, ArrayRef<mlir::Value> arguments) {
@@ -186,6 +189,7 @@ void GenericCallOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
//===----------------------------------------------------------------------===//
// MulOp
+//===----------------------------------------------------------------------===//
void MulOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -202,6 +206,7 @@ void MulOp::print(mlir::OpAsmPrinter &p) { printBinaryOp(p, *this); }
//===----------------------------------------------------------------------===//
// ReturnOp
+//===----------------------------------------------------------------------===//
mlir::LogicalResult ReturnOp::verify() {
// We know that the parent operation is a function, because of the 'HasParent'
@@ -238,6 +243,7 @@ mlir::LogicalResult ReturnOp::verify() {
//===----------------------------------------------------------------------===//
// TransposeOp
+//===----------------------------------------------------------------------===//
void TransposeOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value value) {
diff --git a/mlir/examples/toy/Ch3/include/toy/Ops.td b/mlir/examples/toy/Ch3/include/toy/Ops.td
index d995d159f6927..012481accae79 100644
--- a/mlir/examples/toy/Ch3/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch3/include/toy/Ops.td
@@ -34,6 +34,10 @@ class Toy_Op<string mnemonic, list<Trait> traits = []> :
// Toy Operations
//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+// ConstantOp
+//===----------------------------------------------------------------------===//
+
// We define a toy operation by inheriting from our base 'Toy_Op' class above.
// Here we provide the mnemonic and a list of traits for the operation. The
// constant operation is marked as 'NoSideEffect' as it is a pure operation
@@ -78,6 +82,10 @@ def ConstantOp : Toy_Op<"constant", [NoSideEffect]> {
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// AddOp
+//===----------------------------------------------------------------------===//
+
def AddOp : Toy_Op<"add", [NoSideEffect]> {
let summary = "element-wise addition operation";
let description = [{
@@ -97,6 +105,10 @@ def AddOp : Toy_Op<"add", [NoSideEffect]> {
];
}
+//===----------------------------------------------------------------------===//
+// GenericCallOp
+//===----------------------------------------------------------------------===//
+
def GenericCallOp : Toy_Op<"generic_call"> {
let summary = "generic call operation";
let description = [{
@@ -132,6 +144,10 @@ def GenericCallOp : Toy_Op<"generic_call"> {
];
}
+//===----------------------------------------------------------------------===//
+// MulOp
+//===----------------------------------------------------------------------===//
+
def MulOp : Toy_Op<"mul", [NoSideEffect]> {
let summary = "element-wise multiplication operation";
let description = [{
@@ -151,6 +167,10 @@ def MulOp : Toy_Op<"mul", [NoSideEffect]> {
];
}
+//===----------------------------------------------------------------------===//
+// PrintOp
+//===----------------------------------------------------------------------===//
+
def PrintOp : Toy_Op<"print"> {
let summary = "print operation";
let description = [{
@@ -164,6 +184,10 @@ def PrintOp : Toy_Op<"print"> {
let assemblyFormat = "$input attr-dict `:` type($input)";
}
+//===----------------------------------------------------------------------===//
+// ReshapeOp
+//===----------------------------------------------------------------------===//
+
def ReshapeOp : Toy_Op<"reshape", [NoSideEffect]> {
let summary = "tensor reshape operation";
let description = [{
@@ -188,6 +212,10 @@ def ReshapeOp : Toy_Op<"reshape", [NoSideEffect]> {
let hasCanonicalizer = 1;
}
+//===----------------------------------------------------------------------===//
+// ReturnOp
+//===----------------------------------------------------------------------===//
+
def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
Terminator]> {
let summary = "return operation";
@@ -226,6 +254,10 @@ def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// TransposeOp
+//===----------------------------------------------------------------------===//
+
def TransposeOp : Toy_Op<"transpose", [NoSideEffect]> {
let summary = "transpose operation";
diff --git a/mlir/examples/toy/Ch3/mlir/Dialect.cpp b/mlir/examples/toy/Ch3/mlir/Dialect.cpp
index 46b55f57a0d1d..67908d4bbf091 100644
--- a/mlir/examples/toy/Ch3/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch3/mlir/Dialect.cpp
@@ -89,6 +89,7 @@ static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
//===----------------------------------------------------------------------===//
// ConstantOp
+//===----------------------------------------------------------------------===//
/// Build a constant operation.
/// The builder is passed as an argument, so is the state that this method is
@@ -158,6 +159,7 @@ mlir::LogicalResult ConstantOp::verify() {
//===----------------------------------------------------------------------===//
// AddOp
+//===----------------------------------------------------------------------===//
void AddOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -174,6 +176,7 @@ void AddOp::print(mlir::OpAsmPrinter &p) { printBinaryOp(p, *this); }
//===----------------------------------------------------------------------===//
// GenericCallOp
+//===----------------------------------------------------------------------===//
void GenericCallOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
StringRef callee, ArrayRef<mlir::Value> arguments) {
@@ -186,6 +189,7 @@ void GenericCallOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
//===----------------------------------------------------------------------===//
// MulOp
+//===----------------------------------------------------------------------===//
void MulOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -202,6 +206,7 @@ void MulOp::print(mlir::OpAsmPrinter &p) { printBinaryOp(p, *this); }
//===----------------------------------------------------------------------===//
// ReturnOp
+//===----------------------------------------------------------------------===//
mlir::LogicalResult ReturnOp::verify() {
// We know that the parent operation is a function, because of the 'HasParent'
@@ -238,6 +243,7 @@ mlir::LogicalResult ReturnOp::verify() {
//===----------------------------------------------------------------------===//
// TransposeOp
+//===----------------------------------------------------------------------===//
void TransposeOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value value) {
diff --git a/mlir/examples/toy/Ch4/include/toy/Ops.td b/mlir/examples/toy/Ch4/include/toy/Ops.td
index b070b1380b130..f0e76ef8d8045 100644
--- a/mlir/examples/toy/Ch4/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch4/include/toy/Ops.td
@@ -37,6 +37,10 @@ class Toy_Op<string mnemonic, list<Trait> traits = []> :
// Toy Operations
//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+// ConstantOp
+//===----------------------------------------------------------------------===//
+
// We define a toy operation by inheriting from our base 'Toy_Op' class above.
// Here we provide the mnemonic and a list of traits for the operation. The
// constant operation is marked as 'NoSideEffect' as it is a pure operation
@@ -81,6 +85,10 @@ def ConstantOp : Toy_Op<"constant", [NoSideEffect]> {
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// AddOp
+//===----------------------------------------------------------------------===//
+
def AddOp : Toy_Op<"add",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "element-wise addition operation";
@@ -101,6 +109,10 @@ def AddOp : Toy_Op<"add",
];
}
+//===----------------------------------------------------------------------===//
+// CastOp
+//===----------------------------------------------------------------------===//
+
def CastOp : Toy_Op<"cast", [
DeclareOpInterfaceMethods<CastOpInterface>,
DeclareOpInterfaceMethods<ShapeInferenceOpInterface>,
@@ -122,6 +134,10 @@ def CastOp : Toy_Op<"cast", [
let assemblyFormat = "$input attr-dict `:` type($input) `to` type($output)";
}
+//===----------------------------------------------------------------------===//
+// GenericCallOp
+//===----------------------------------------------------------------------===//
+
def GenericCallOp : Toy_Op<"generic_call",
[DeclareOpInterfaceMethods<CallOpInterface>]> {
let summary = "generic call operation";
@@ -158,6 +174,10 @@ def GenericCallOp : Toy_Op<"generic_call",
];
}
+//===----------------------------------------------------------------------===//
+// MulOp
+//===----------------------------------------------------------------------===//
+
def MulOp : Toy_Op<"mul",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "element-wise multiplication operation";
@@ -178,6 +198,10 @@ def MulOp : Toy_Op<"mul",
];
}
+//===----------------------------------------------------------------------===//
+// PrintOp
+//===----------------------------------------------------------------------===//
+
def PrintOp : Toy_Op<"print"> {
let summary = "print operation";
let description = [{
@@ -191,6 +215,10 @@ def PrintOp : Toy_Op<"print"> {
let assemblyFormat = "$input attr-dict `:` type($input)";
}
+//===----------------------------------------------------------------------===//
+// ReshapeOp
+//===----------------------------------------------------------------------===//
+
def ReshapeOp : Toy_Op<"reshape", [NoSideEffect]> {
let summary = "tensor reshape operation";
let description = [{
@@ -215,6 +243,10 @@ def ReshapeOp : Toy_Op<"reshape", [NoSideEffect]> {
let hasCanonicalizer = 1;
}
+//===----------------------------------------------------------------------===//
+// ReturnOp
+//===----------------------------------------------------------------------===//
+
def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
Terminator]> {
let summary = "return operation";
@@ -253,6 +285,10 @@ def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// TransposeOp
+//===----------------------------------------------------------------------===//
+
def TransposeOp : Toy_Op<"transpose",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "transpose operation";
diff --git a/mlir/examples/toy/Ch4/mlir/Dialect.cpp b/mlir/examples/toy/Ch4/mlir/Dialect.cpp
index fd5afd211cd07..661d09c696d9b 100644
--- a/mlir/examples/toy/Ch4/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch4/mlir/Dialect.cpp
@@ -145,6 +145,7 @@ static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
//===----------------------------------------------------------------------===//
// ConstantOp
+//===----------------------------------------------------------------------===//
/// Build a constant operation.
/// The builder is passed as an argument, so is the state that this method is
@@ -214,6 +215,7 @@ mlir::LogicalResult ConstantOp::verify() {
//===----------------------------------------------------------------------===//
// AddOp
+//===----------------------------------------------------------------------===//
void AddOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -234,6 +236,7 @@ void AddOp::inferShapes() { getResult().setType(getOperand(0).getType()); }
//===----------------------------------------------------------------------===//
// CastOp
+//===----------------------------------------------------------------------===//
/// Infer the output shape of the CastOp, this is required by the shape
/// inference interface.
@@ -256,6 +259,7 @@ bool CastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
//===----------------------------------------------------------------------===//
// GenericCallOp
+//===----------------------------------------------------------------------===//
void GenericCallOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
StringRef callee, ArrayRef<mlir::Value> arguments) {
@@ -278,6 +282,7 @@ Operation::operand_range GenericCallOp::getArgOperands() { return inputs(); }
//===----------------------------------------------------------------------===//
// MulOp
+//===----------------------------------------------------------------------===//
void MulOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -298,6 +303,7 @@ void MulOp::inferShapes() { getResult().setType(getOperand(0).getType()); }
//===----------------------------------------------------------------------===//
// ReturnOp
+//===----------------------------------------------------------------------===//
mlir::LogicalResult ReturnOp::verify() {
// We know that the parent operation is a function, because of the 'HasParent'
@@ -334,6 +340,7 @@ mlir::LogicalResult ReturnOp::verify() {
//===----------------------------------------------------------------------===//
// TransposeOp
+//===----------------------------------------------------------------------===//
void TransposeOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value value) {
diff --git a/mlir/examples/toy/Ch5/include/toy/Ops.td b/mlir/examples/toy/Ch5/include/toy/Ops.td
index a66326825152b..1a05ef8c9c46d 100644
--- a/mlir/examples/toy/Ch5/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch5/include/toy/Ops.td
@@ -37,6 +37,10 @@ class Toy_Op<string mnemonic, list<Trait> traits = []> :
// Toy Operations
//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+// ConstantOp
+//===----------------------------------------------------------------------===//
+
// We define a toy operation by inheriting from our base 'Toy_Op' class above.
// Here we provide the mnemonic and a list of traits for the operation. The
// constant operation is marked as 'NoSideEffect' as it is a pure operation
@@ -81,6 +85,10 @@ def ConstantOp : Toy_Op<"constant", [NoSideEffect]> {
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// AddOp
+//===----------------------------------------------------------------------===//
+
def AddOp : Toy_Op<"add",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "element-wise addition operation";
@@ -101,6 +109,10 @@ def AddOp : Toy_Op<"add",
];
}
+//===----------------------------------------------------------------------===//
+// CastOp
+//===----------------------------------------------------------------------===//
+
def CastOp : Toy_Op<"cast", [
DeclareOpInterfaceMethods<CastOpInterface>,
DeclareOpInterfaceMethods<ShapeInferenceOpInterface>,
@@ -122,6 +134,10 @@ def CastOp : Toy_Op<"cast", [
let assemblyFormat = "$input attr-dict `:` type($input) `to` type($output)";
}
+//===----------------------------------------------------------------------===//
+// GenericCallOp
+//===----------------------------------------------------------------------===//
+
def GenericCallOp : Toy_Op<"generic_call",
[DeclareOpInterfaceMethods<CallOpInterface>]> {
let summary = "generic call operation";
@@ -158,6 +174,10 @@ def GenericCallOp : Toy_Op<"generic_call",
];
}
+//===----------------------------------------------------------------------===//
+// MulOp
+//===----------------------------------------------------------------------===//
+
def MulOp : Toy_Op<"mul",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "element-wise multiplication operation";
@@ -178,6 +198,10 @@ def MulOp : Toy_Op<"mul",
];
}
+//===----------------------------------------------------------------------===//
+// PrintOp
+//===----------------------------------------------------------------------===//
+
def PrintOp : Toy_Op<"print"> {
let summary = "print operation";
let description = [{
@@ -192,6 +216,10 @@ def PrintOp : Toy_Op<"print"> {
let assemblyFormat = "$input attr-dict `:` type($input)";
}
+//===----------------------------------------------------------------------===//
+// ReshapeOp
+//===----------------------------------------------------------------------===//
+
def ReshapeOp : Toy_Op<"reshape", [NoSideEffect]> {
let summary = "tensor reshape operation";
let description = [{
@@ -216,6 +244,10 @@ def ReshapeOp : Toy_Op<"reshape", [NoSideEffect]> {
let hasCanonicalizer = 1;
}
+//===----------------------------------------------------------------------===//
+// ReturnOp
+//===----------------------------------------------------------------------===//
+
def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
Terminator]> {
let summary = "return operation";
@@ -254,6 +286,10 @@ def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// TransposeOp
+//===----------------------------------------------------------------------===//
+
def TransposeOp : Toy_Op<"transpose",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "transpose operation";
diff --git a/mlir/examples/toy/Ch5/mlir/Dialect.cpp b/mlir/examples/toy/Ch5/mlir/Dialect.cpp
index 2aecfe811970a..40fdf1c8754cc 100644
--- a/mlir/examples/toy/Ch5/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch5/mlir/Dialect.cpp
@@ -145,6 +145,7 @@ static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
//===----------------------------------------------------------------------===//
// ConstantOp
+//===----------------------------------------------------------------------===//
/// Build a constant operation.
/// The builder is passed as an argument, so is the state that this method is
@@ -214,6 +215,7 @@ mlir::LogicalResult ConstantOp::verify() {
//===----------------------------------------------------------------------===//
// AddOp
+//===----------------------------------------------------------------------===//
void AddOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -234,6 +236,7 @@ void AddOp::inferShapes() { getResult().setType(getOperand(0).getType()); }
//===----------------------------------------------------------------------===//
// CastOp
+//===----------------------------------------------------------------------===//
/// Infer the output shape of the CastOp, this is required by the shape
/// inference interface.
@@ -256,6 +259,7 @@ bool CastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
//===----------------------------------------------------------------------===//
// GenericCallOp
+//===----------------------------------------------------------------------===//
void GenericCallOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
StringRef callee, ArrayRef<mlir::Value> arguments) {
@@ -278,6 +282,7 @@ Operation::operand_range GenericCallOp::getArgOperands() { return inputs(); }
//===----------------------------------------------------------------------===//
// MulOp
+//===----------------------------------------------------------------------===//
void MulOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -298,6 +303,7 @@ void MulOp::inferShapes() { getResult().setType(getOperand(0).getType()); }
//===----------------------------------------------------------------------===//
// ReturnOp
+//===----------------------------------------------------------------------===//
mlir::LogicalResult ReturnOp::verify() {
// We know that the parent operation is a function, because of the 'HasParent'
@@ -334,6 +340,7 @@ mlir::LogicalResult ReturnOp::verify() {
//===----------------------------------------------------------------------===//
// TransposeOp
+//===----------------------------------------------------------------------===//
void TransposeOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value value) {
diff --git a/mlir/examples/toy/Ch6/include/toy/Ops.td b/mlir/examples/toy/Ch6/include/toy/Ops.td
index 373fdeee2c278..a4963d8eeb784 100644
--- a/mlir/examples/toy/Ch6/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch6/include/toy/Ops.td
@@ -37,6 +37,10 @@ class Toy_Op<string mnemonic, list<Trait> traits = []> :
// Toy Operations
//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+// ConstantOp
+//===----------------------------------------------------------------------===//
+
// We define a toy operation by inheriting from our base 'Toy_Op' class above.
// Here we provide the mnemonic and a list of traits for the operation. The
// constant operation is marked as 'NoSideEffect' as it is a pure operation
@@ -81,6 +85,10 @@ def ConstantOp : Toy_Op<"constant", [NoSideEffect]> {
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// AddOp
+//===----------------------------------------------------------------------===//
+
def AddOp : Toy_Op<"add",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "element-wise addition operation";
@@ -101,6 +109,10 @@ def AddOp : Toy_Op<"add",
];
}
+//===----------------------------------------------------------------------===//
+// CastOp
+//===----------------------------------------------------------------------===//
+
def CastOp : Toy_Op<"cast", [
DeclareOpInterfaceMethods<CastOpInterface>,
DeclareOpInterfaceMethods<ShapeInferenceOpInterface>,
@@ -122,6 +134,10 @@ def CastOp : Toy_Op<"cast", [
let assemblyFormat = "$input attr-dict `:` type($input) `to` type($output)";
}
+//===----------------------------------------------------------------------===//
+// GenericCallOp
+//===----------------------------------------------------------------------===//
+
def GenericCallOp : Toy_Op<"generic_call",
[DeclareOpInterfaceMethods<CallOpInterface>]> {
let summary = "generic call operation";
@@ -158,6 +174,10 @@ def GenericCallOp : Toy_Op<"generic_call",
];
}
+//===----------------------------------------------------------------------===//
+// MulOp
+//===----------------------------------------------------------------------===//
+
def MulOp : Toy_Op<"mul",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "element-wise multiplication operation";
@@ -178,6 +198,10 @@ def MulOp : Toy_Op<"mul",
];
}
+//===----------------------------------------------------------------------===//
+// PrintOp
+//===----------------------------------------------------------------------===//
+
def PrintOp : Toy_Op<"print"> {
let summary = "print operation";
let description = [{
@@ -192,6 +216,10 @@ def PrintOp : Toy_Op<"print"> {
let assemblyFormat = "$input attr-dict `:` type($input)";
}
+//===----------------------------------------------------------------------===//
+// ReshapeOp
+//===----------------------------------------------------------------------===//
+
def ReshapeOp : Toy_Op<"reshape", [NoSideEffect]> {
let summary = "tensor reshape operation";
let description = [{
@@ -216,6 +244,10 @@ def ReshapeOp : Toy_Op<"reshape", [NoSideEffect]> {
let results = (outs StaticShapeTensorOf<[F64]>);
}
+//===----------------------------------------------------------------------===//
+// ReturnOp
+//===----------------------------------------------------------------------===//
+
def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
Terminator]> {
let summary = "return operation";
@@ -254,6 +286,10 @@ def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// TransposeOp
+//===----------------------------------------------------------------------===//
+
def TransposeOp : Toy_Op<"transpose",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "transpose operation";
diff --git a/mlir/examples/toy/Ch6/mlir/Dialect.cpp b/mlir/examples/toy/Ch6/mlir/Dialect.cpp
index 2aecfe811970a..40fdf1c8754cc 100644
--- a/mlir/examples/toy/Ch6/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch6/mlir/Dialect.cpp
@@ -145,6 +145,7 @@ static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
//===----------------------------------------------------------------------===//
// ConstantOp
+//===----------------------------------------------------------------------===//
/// Build a constant operation.
/// The builder is passed as an argument, so is the state that this method is
@@ -214,6 +215,7 @@ mlir::LogicalResult ConstantOp::verify() {
//===----------------------------------------------------------------------===//
// AddOp
+//===----------------------------------------------------------------------===//
void AddOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -234,6 +236,7 @@ void AddOp::inferShapes() { getResult().setType(getOperand(0).getType()); }
//===----------------------------------------------------------------------===//
// CastOp
+//===----------------------------------------------------------------------===//
/// Infer the output shape of the CastOp, this is required by the shape
/// inference interface.
@@ -256,6 +259,7 @@ bool CastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
//===----------------------------------------------------------------------===//
// GenericCallOp
+//===----------------------------------------------------------------------===//
void GenericCallOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
StringRef callee, ArrayRef<mlir::Value> arguments) {
@@ -278,6 +282,7 @@ Operation::operand_range GenericCallOp::getArgOperands() { return inputs(); }
//===----------------------------------------------------------------------===//
// MulOp
+//===----------------------------------------------------------------------===//
void MulOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -298,6 +303,7 @@ void MulOp::inferShapes() { getResult().setType(getOperand(0).getType()); }
//===----------------------------------------------------------------------===//
// ReturnOp
+//===----------------------------------------------------------------------===//
mlir::LogicalResult ReturnOp::verify() {
// We know that the parent operation is a function, because of the 'HasParent'
@@ -334,6 +340,7 @@ mlir::LogicalResult ReturnOp::verify() {
//===----------------------------------------------------------------------===//
// TransposeOp
+//===----------------------------------------------------------------------===//
void TransposeOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value value) {
diff --git a/mlir/examples/toy/Ch7/include/toy/Ops.td b/mlir/examples/toy/Ch7/include/toy/Ops.td
index 828b416f4581c..1e5524a4fc248 100644
--- a/mlir/examples/toy/Ch7/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch7/include/toy/Ops.td
@@ -51,6 +51,10 @@ def Toy_Type : AnyTypeOf<[F64Tensor, Toy_StructType]>;
// Toy Operations
//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+// ConstantOp
+//===----------------------------------------------------------------------===//
+
// We define a toy operation by inheriting from our base 'Toy_Op' class above.
// Here we provide the mnemonic and a list of traits for the operation. The
// constant operation is marked as 'NoSideEffect' as it is a pure operation
@@ -100,6 +104,10 @@ def ConstantOp : Toy_Op<"constant",
let hasFolder = 1;
}
+//===----------------------------------------------------------------------===//
+// AddOp
+//===----------------------------------------------------------------------===//
+
def AddOp : Toy_Op<"add",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "element-wise addition operation";
@@ -120,6 +128,10 @@ def AddOp : Toy_Op<"add",
];
}
+//===----------------------------------------------------------------------===//
+// CastOp
+//===----------------------------------------------------------------------===//
+
def CastOp : Toy_Op<"cast", [
DeclareOpInterfaceMethods<CastOpInterface>,
DeclareOpInterfaceMethods<ShapeInferenceOpInterface>,
@@ -141,6 +153,10 @@ def CastOp : Toy_Op<"cast", [
let assemblyFormat = "$input attr-dict `:` type($input) `to` type($output)";
}
+//===----------------------------------------------------------------------===//
+// GenericCallOp
+//===----------------------------------------------------------------------===//
+
def GenericCallOp : Toy_Op<"generic_call",
[DeclareOpInterfaceMethods<CallOpInterface>]> {
let summary = "generic call operation";
@@ -178,6 +194,10 @@ def GenericCallOp : Toy_Op<"generic_call",
];
}
+//===----------------------------------------------------------------------===//
+// MulOp
+//===----------------------------------------------------------------------===//
+
def MulOp : Toy_Op<"mul",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "element-wise multiplication operation";
@@ -198,6 +218,10 @@ def MulOp : Toy_Op<"mul",
];
}
+//===----------------------------------------------------------------------===//
+// PrintOp
+//===----------------------------------------------------------------------===//
+
def PrintOp : Toy_Op<"print"> {
let summary = "print operation";
let description = [{
@@ -212,6 +236,10 @@ def PrintOp : Toy_Op<"print"> {
let assemblyFormat = "$input attr-dict `:` type($input)";
}
+//===----------------------------------------------------------------------===//
+// ReshapeOp
+//===----------------------------------------------------------------------===//
+
def ReshapeOp : Toy_Op<"reshape", [NoSideEffect]> {
let summary = "tensor reshape operation";
let description = [{
@@ -236,6 +264,10 @@ def ReshapeOp : Toy_Op<"reshape", [NoSideEffect]> {
let results = (outs StaticShapeTensorOf<[F64]>);
}
+//===----------------------------------------------------------------------===//
+// ReturnOp
+//===----------------------------------------------------------------------===//
+
def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
Terminator]> {
let summary = "return operation";
@@ -274,6 +306,10 @@ def ReturnOp : Toy_Op<"return", [NoSideEffect, HasParent<"FuncOp">,
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// StructAccessOp
+//===----------------------------------------------------------------------===//
+
def StructAccessOp : Toy_Op<"struct_access", [NoSideEffect]> {
let summary = "struct access";
let description = [{
@@ -299,6 +335,10 @@ def StructAccessOp : Toy_Op<"struct_access", [NoSideEffect]> {
let hasFolder = 1;
}
+//===----------------------------------------------------------------------===//
+// StructConstantOp
+//===----------------------------------------------------------------------===//
+
def StructConstantOp : Toy_Op<"struct_constant", [ConstantLike, NoSideEffect]> {
let summary = "struct constant";
let description = [{
@@ -323,6 +363,10 @@ def StructConstantOp : Toy_Op<"struct_constant", [ConstantLike, NoSideEffect]> {
let hasFolder = 1;
}
+//===----------------------------------------------------------------------===//
+// TransposeOp
+//===----------------------------------------------------------------------===//
+
def TransposeOp : Toy_Op<"transpose",
[NoSideEffect, DeclareOpInterfaceMethods<ShapeInferenceOpInterface>]> {
let summary = "transpose operation";
diff --git a/mlir/examples/toy/Ch7/mlir/Dialect.cpp b/mlir/examples/toy/Ch7/mlir/Dialect.cpp
index a86f80f0014a0..3ea3ef2119111 100644
--- a/mlir/examples/toy/Ch7/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch7/mlir/Dialect.cpp
@@ -132,6 +132,7 @@ static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
//===----------------------------------------------------------------------===//
// ConstantOp
+//===----------------------------------------------------------------------===//
/// Build a constant operation.
/// The builder is passed as an argument, so is the state that this method is
@@ -241,6 +242,7 @@ void ConstantOp::inferShapes() { getResult().setType(value().getType()); }
//===----------------------------------------------------------------------===//
// AddOp
+//===----------------------------------------------------------------------===//
void AddOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -261,6 +263,7 @@ void AddOp::inferShapes() { getResult().setType(getOperand(0).getType()); }
//===----------------------------------------------------------------------===//
// CastOp
+//===----------------------------------------------------------------------===//
/// Infer the output shape of the CastOp, this is required by the shape
/// inference interface.
@@ -283,6 +286,7 @@ bool CastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
//===----------------------------------------------------------------------===//
// GenericCallOp
+//===----------------------------------------------------------------------===//
void GenericCallOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
StringRef callee, ArrayRef<mlir::Value> arguments) {
@@ -305,6 +309,7 @@ Operation::operand_range GenericCallOp::getArgOperands() { return inputs(); }
//===----------------------------------------------------------------------===//
// MulOp
+//===----------------------------------------------------------------------===//
void MulOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value lhs, mlir::Value rhs) {
@@ -325,6 +330,7 @@ void MulOp::inferShapes() { getResult().setType(getOperand(0).getType()); }
//===----------------------------------------------------------------------===//
// ReturnOp
+//===----------------------------------------------------------------------===//
mlir::LogicalResult ReturnOp::verify() {
// We know that the parent operation is a function, because of the 'HasParent'
@@ -361,6 +367,7 @@ mlir::LogicalResult ReturnOp::verify() {
//===----------------------------------------------------------------------===//
// StructAccessOp
+//===----------------------------------------------------------------------===//
void StructAccessOp::build(mlir::OpBuilder &b, mlir::OperationState &state,
mlir::Value input, size_t index) {
@@ -388,6 +395,7 @@ mlir::LogicalResult StructAccessOp::verify() {
//===----------------------------------------------------------------------===//
// TransposeOp
+//===----------------------------------------------------------------------===//
void TransposeOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
mlir::Value value) {
More information about the Mlir-commits
mailing list