[MLIR] Fix several misc issues in in Toy tutorial
authorRahul Joshi <jurahul@gmail.com>
Mon, 11 May 2020 23:53:16 +0000 (16:53 -0700)
committerJacques Pienaar <jpienaar@google.com>
Mon, 11 May 2020 23:56:47 +0000 (16:56 -0700)
Summary:
- Fix comments in several places
- Eliminate extra ' in AST dump and adjust tests accordingly

Differential Revision: https://reviews.llvm.org/D78399

32 files changed:
mlir/docs/Tutorials/Toy/Ch-1.md
mlir/docs/Tutorials/Toy/Ch-2.md
mlir/docs/Tutorials/Toy/Ch-3.md
mlir/docs/Tutorials/Toy/Ch-5.md
mlir/examples/toy/Ch1/parser/AST.cpp
mlir/examples/toy/Ch2/include/toy/Ops.td
mlir/examples/toy/Ch2/mlir/Dialect.cpp
mlir/examples/toy/Ch2/parser/AST.cpp
mlir/examples/toy/Ch3/include/toy/Ops.td
mlir/examples/toy/Ch3/mlir/Dialect.cpp
mlir/examples/toy/Ch3/parser/AST.cpp
mlir/examples/toy/Ch4/include/toy/Ops.td
mlir/examples/toy/Ch4/mlir/Dialect.cpp
mlir/examples/toy/Ch4/parser/AST.cpp
mlir/examples/toy/Ch5/include/toy/Ops.td
mlir/examples/toy/Ch5/mlir/Dialect.cpp
mlir/examples/toy/Ch5/parser/AST.cpp
mlir/examples/toy/Ch6/include/toy/Ops.td
mlir/examples/toy/Ch6/mlir/Dialect.cpp
mlir/examples/toy/Ch6/parser/AST.cpp
mlir/examples/toy/Ch7/include/toy/Ops.td
mlir/examples/toy/Ch7/mlir/Dialect.cpp
mlir/examples/toy/Ch7/parser/AST.cpp
mlir/include/mlir/ExecutionEngine/OptUtils.h
mlir/test/Examples/Toy/Ch1/ast.toy
mlir/test/Examples/Toy/Ch2/ast.toy
mlir/test/Examples/Toy/Ch3/ast.toy
mlir/test/Examples/Toy/Ch4/ast.toy
mlir/test/Examples/Toy/Ch5/ast.toy
mlir/test/Examples/Toy/Ch6/ast.toy
mlir/test/Examples/Toy/Ch7/ast.toy
mlir/test/Examples/Toy/Ch7/struct-ast.toy

index 7c2f499..eebbb78 100644 (file)
@@ -29,7 +29,7 @@ This tutorial is divided in the following chapters:
     with Interfaces. Here we will show how to plug dialect specific information
     into generic transformations like shape inference and inlining.
 -   [Chapter #5](Ch-5.md): Partially lowering to lower-level dialects. We'll
-    convert some our high level language specific semantics towards a generic
+    convert some of our high level language specific semantics towards a generic
     affine oriented dialect for optimization.
 -   [Chapter #6](Ch-6.md): Lowering to LLVM and code generation. Here we'll
     target LLVM IR for code generation, and detail more of the lowering
index 4265b06..1180a9f 100755 (executable)
@@ -146,8 +146,6 @@ This handling can be observed by crafting what should be an invalid IR for Toy
 and seeing it round-trip without tripping the verifier:
 
 ```mlir
-// RUN: toyc %s -emit=mlir
-
 func @main() {
   %0 = "toy.print"() : () -> tensor<2x3xf64>
 }
index d6a72b0..5353b58 100644 (file)
@@ -98,7 +98,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern<TransposeOp> {
       return failure();
 
     // Otherwise, we have a redundant transpose. Use the rewriter.
-    rewriter.replaceOp(op, {transposeInputOp.getOperand()}, {transposeInputOp});
+    rewriter.replaceOp(op, {transposeInputOp.getOperand()});
     return success();
   }
 };
index 67fc0f6..ca59da2 100644 (file)
@@ -268,8 +268,8 @@ func @main() {
   }
 
   // Multiply and store into the output buffer.
-  affine.for %arg0 = 0 to 2 {
-    affine.for %arg1 = 0 to 3 {
+  affine.for %arg0 = 0 to 3 {
+    affine.for %arg1 = 0 to 2 {
       %3 = affine.load %1[%arg0, %arg1] : memref<3x2xf64>
       %4 = affine.load %1[%arg0, %arg1] : memref<3x2xf64>
       %5 = mulf %3, %4 : f64
index 9bd7876..9315bb1 100644 (file)
@@ -201,7 +201,7 @@ void ASTDumper::dump(const VarType &type) {
 /// parameters names.
 void ASTDumper::dump(PrototypeAST *node) {
   INDENT();
-  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
+  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "\n";
   indent();
   llvm::errs() << "Params: [";
   llvm::interleaveComma(node->getArgs(), llvm::errs(),
index 4e06634..14a20a2 100644 (file)
@@ -125,7 +125,7 @@ def GenericCallOp : Toy_Op<"generic_call"> {
   // The generic call operation returns a single value of TensorType.
   let results = (outs F64Tensor);
 
-  // The return operation only emits the input in the format if it is present.
+  // Specialize assembly printing and parsing using a declarative format.
   let assemblyFormat = [{
     $callee `(` $inputs `)` attr-dict `:` functional-type($inputs, results)
   }];
index b60d792..91723c3 100644 (file)
@@ -216,10 +216,9 @@ static mlir::LogicalResult verify(ReturnOp op) {
       resultType.isa<mlir::UnrankedTensorType>())
     return mlir::success();
 
-  return op.emitError() << "type of return operand ("
-                        << *op.operand_type_begin()
+  return op.emitError() << "type of return operand (" << inputType
                         << ") doesn't match function result type ("
-                        << results.front() << ")";
+                        << resultType << ")";
 }
 
 //===----------------------------------------------------------------------===//
index 9bd7876..9315bb1 100644 (file)
@@ -201,7 +201,7 @@ void ASTDumper::dump(const VarType &type) {
 /// parameters names.
 void ASTDumper::dump(PrototypeAST *node) {
   INDENT();
-  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
+  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "\n";
   indent();
   llvm::errs() << "Params: [";
   llvm::interleaveComma(node->getArgs(), llvm::errs(),
index 5a40760..9bf9f8d 100644 (file)
@@ -124,7 +124,7 @@ def GenericCallOp : Toy_Op<"generic_call"> {
   // The generic call operation returns a single value of TensorType.
   let results = (outs F64Tensor);
 
-  // The return operation only emits the input in the format if it is present.
+  // Specialize assembly printing and parsing using a declarative format.
   let assemblyFormat = [{
     $callee `(` $inputs `)` attr-dict `:` functional-type($inputs, results)
   }];
index b60d792..91723c3 100644 (file)
@@ -216,10 +216,9 @@ static mlir::LogicalResult verify(ReturnOp op) {
       resultType.isa<mlir::UnrankedTensorType>())
     return mlir::success();
 
-  return op.emitError() << "type of return operand ("
-                        << *op.operand_type_begin()
+  return op.emitError() << "type of return operand (" << inputType
                         << ") doesn't match function result type ("
-                        << results.front() << ")";
+                        << resultType << ")";
 }
 
 //===----------------------------------------------------------------------===//
index 9bd7876..9315bb1 100644 (file)
@@ -201,7 +201,7 @@ void ASTDumper::dump(const VarType &type) {
 /// parameters names.
 void ASTDumper::dump(PrototypeAST *node) {
   INDENT();
-  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
+  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "\n";
   indent();
   llvm::errs() << "Params: [";
   llvm::interleaveComma(node->getArgs(), llvm::errs(),
index 1cd2080..13970e5 100644 (file)
@@ -149,7 +149,7 @@ def GenericCallOp : Toy_Op<"generic_call",
   // The generic call operation returns a single value of TensorType.
   let results = (outs F64Tensor);
 
-  // The return operation only emits the input in the format if it is present.
+  // Specialize assembly printing and parsing using a declarative format.
   let assemblyFormat = [{
     $callee `(` $inputs `)` attr-dict `:` functional-type($inputs, results)
   }];
index 02a7021..5a64f0f 100644 (file)
@@ -291,10 +291,9 @@ static mlir::LogicalResult verify(ReturnOp op) {
       resultType.isa<mlir::UnrankedTensorType>())
     return mlir::success();
 
-  return op.emitError() << "type of return operand ("
-                        << *op.operand_type_begin()
+  return op.emitError() << "type of return operand (" << inputType
                         << ") doesn't match function result type ("
-                        << results.front() << ")";
+                        << resultType << ")";
 }
 
 //===----------------------------------------------------------------------===//
index 9bd7876..9315bb1 100644 (file)
@@ -201,7 +201,7 @@ void ASTDumper::dump(const VarType &type) {
 /// parameters names.
 void ASTDumper::dump(PrototypeAST *node) {
   INDENT();
-  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
+  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "\n";
   indent();
   llvm::errs() << "Params: [";
   llvm::interleaveComma(node->getArgs(), llvm::errs(),
index 7e7d5d1..826e980 100644 (file)
@@ -149,7 +149,7 @@ def GenericCallOp : Toy_Op<"generic_call",
   // The generic call operation returns a single value of TensorType.
   let results = (outs F64Tensor);
 
-  // The return operation only emits the input in the format if it is present.
+  // Specialize assembly printing and parsing using a declarative format.
   let assemblyFormat = [{
     $callee `(` $inputs `)` attr-dict `:` functional-type($inputs, results)
   }];
index 02a7021..5a64f0f 100644 (file)
@@ -291,10 +291,9 @@ static mlir::LogicalResult verify(ReturnOp op) {
       resultType.isa<mlir::UnrankedTensorType>())
     return mlir::success();
 
-  return op.emitError() << "type of return operand ("
-                        << *op.operand_type_begin()
+  return op.emitError() << "type of return operand (" << inputType
                         << ") doesn't match function result type ("
-                        << results.front() << ")";
+                        << resultType << ")";
 }
 
 //===----------------------------------------------------------------------===//
index 9bd7876..9315bb1 100644 (file)
@@ -201,7 +201,7 @@ void ASTDumper::dump(const VarType &type) {
 /// parameters names.
 void ASTDumper::dump(PrototypeAST *node) {
   INDENT();
-  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
+  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "\n";
   indent();
   llvm::errs() << "Params: [";
   llvm::interleaveComma(node->getArgs(), llvm::errs(),
index dee06c1..cebf464 100644 (file)
@@ -149,7 +149,7 @@ def GenericCallOp : Toy_Op<"generic_call",
   // The generic call operation returns a single value of TensorType.
   let results = (outs F64Tensor);
 
-  // The return operation only emits the input in the format if it is present.
+  // Specialize assembly printing and parsing using a declarative format.
   let assemblyFormat = [{
     $callee `(` $inputs `)` attr-dict `:` functional-type($inputs, results)
   }];
index 02a7021..5a64f0f 100644 (file)
@@ -291,10 +291,9 @@ static mlir::LogicalResult verify(ReturnOp op) {
       resultType.isa<mlir::UnrankedTensorType>())
     return mlir::success();
 
-  return op.emitError() << "type of return operand ("
-                        << *op.operand_type_begin()
+  return op.emitError() << "type of return operand (" << inputType
                         << ") doesn't match function result type ("
-                        << results.front() << ")";
+                        << resultType << ")";
 }
 
 //===----------------------------------------------------------------------===//
index 9bd7876..9315bb1 100644 (file)
@@ -201,7 +201,7 @@ void ASTDumper::dump(const VarType &type) {
 /// parameters names.
 void ASTDumper::dump(PrototypeAST *node) {
   INDENT();
-  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
+  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "\n";
   indent();
   llvm::errs() << "Params: [";
   llvm::interleaveComma(node->getArgs(), llvm::errs(),
index b453f13..211cb81 100644 (file)
@@ -163,7 +163,7 @@ def GenericCallOp : Toy_Op<"generic_call",
   // StructType.
   let results = (outs Toy_Type);
 
-  // The return operation only emits the input in the format if it is present.
+  // Specialize assembly printing and parsing using a declarative format.
   let assemblyFormat = [{
     $callee `(` $inputs `)` attr-dict `:` functional-type($inputs, results)
   }];
index d653ede..e77a427 100644 (file)
@@ -343,10 +343,9 @@ static mlir::LogicalResult verify(ReturnOp op) {
       resultType.isa<mlir::UnrankedTensorType>())
     return mlir::success();
 
-  return op.emitError() << "type of return operand ("
-                        << *op.operand_type_begin()
+  return op.emitError() << "type of return operand (" << inputType
                         << ") doesn't match function result type ("
-                        << results.front() << ")";
+                        << resultType << ")";
 }
 
 //===----------------------------------------------------------------------===//
index 220637d..901d2f2 100644 (file)
@@ -217,7 +217,7 @@ void ASTDumper::dump(const VarType &type) {
 /// parameters names.
 void ASTDumper::dump(PrototypeAST *node) {
   INDENT();
-  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
+  llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "\n";
   indent();
   llvm::errs() << "Params: [";
   llvm::interleaveComma(node->getArgs(), llvm::errs(),
index 5387920..b33959e 100644 (file)
@@ -27,7 +27,7 @@ class TargetMachine;
 
 namespace mlir {
 
-/// Initialize LLVM passes that can be when running MLIR code using
+/// Initialize LLVM passes that can be used when running MLIR code using
 /// ExecutionEngine.
 void initializeLLVMPasses();
 
index f13d690..19f525a 100644 (file)
@@ -31,7 +31,7 @@ def main() {
 
 # CHECK: Module:
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1'
+# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1
 # CHECK-NEXT:       Params: [a, b]
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         Return
@@ -44,7 +44,7 @@ def main() {
 # CHECK-NEXT:             ]
 # CHECK-NEXT:       } // Block
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1'
+# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1
 # CHECK-NEXT:       Params: []
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         VarDecl a<> @{{.*}}ast.toy:11:3
index 5f39937..48bd443 100644 (file)
@@ -31,7 +31,7 @@ def main() {
 
 # CHECK: Module:
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1'
+# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1
 # CHECK-NEXT:       Params: [a, b]
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         Return
@@ -44,7 +44,7 @@ def main() {
 # CHECK-NEXT:             ]
 # CHECK-NEXT:       } // Block
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1'
+# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1
 # CHECK-NEXT:       Params: []
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         VarDecl a<> @{{.*}}ast.toy:11:3
index b8e4eb0..15ac242 100644 (file)
@@ -31,7 +31,7 @@ def main() {
 
 # CHECK: Module:
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1'
+# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1
 # CHECK-NEXT:       Params: [a, b]
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         Return
@@ -44,7 +44,7 @@ def main() {
 # CHECK-NEXT:             ]
 # CHECK-NEXT:       } // Block
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1'
+# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1
 # CHECK-NEXT:       Params: []
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         VarDecl a<> @{{.*}}ast.toy:11:3
index c991cc1..d665be5 100644 (file)
@@ -31,7 +31,7 @@ def main() {
 
 # CHECK: Module:
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1'
+# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1
 # CHECK-NEXT:       Params: [a, b]
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         Return
@@ -44,7 +44,7 @@ def main() {
 # CHECK-NEXT:             ]
 # CHECK-NEXT:       } // Block
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1'
+# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1
 # CHECK-NEXT:       Params: []
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         VarDecl a<> @{{.*}}ast.toy:11:3
index 4f45c30..9840ea2 100644 (file)
@@ -31,7 +31,7 @@ def main() {
 
 # CHECK: Module:
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1'
+# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1
 # CHECK-NEXT:       Params: [a, b]
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         Return
@@ -44,7 +44,7 @@ def main() {
 # CHECK-NEXT:             ]
 # CHECK-NEXT:       } // Block
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1'
+# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1
 # CHECK-NEXT:       Params: []
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         VarDecl a<> @{{.*}}ast.toy:11:3
index 38eaa1c..f5fc278 100644 (file)
@@ -31,7 +31,7 @@ def main() {
 
 # CHECK: Module:
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1'
+# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1
 # CHECK-NEXT:       Params: [a, b]
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         Return
@@ -44,7 +44,7 @@ def main() {
 # CHECK-NEXT:             ]
 # CHECK-NEXT:       } // Block
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1'
+# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1
 # CHECK-NEXT:       Params: []
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         VarDecl a<> @{{.*}}ast.toy:11:3
index 05cde03..878450a 100644 (file)
@@ -31,7 +31,7 @@ def main() {
 
 # CHECK: Module:
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1'
+# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:1
 # CHECK-NEXT:       Params: [a, b]
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         Return
@@ -44,7 +44,7 @@ def main() {
 # CHECK-NEXT:             ]
 # CHECK-NEXT:       } // Block
 # CHECK-NEXT:     Function
-# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1'
+# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:1
 # CHECK-NEXT:       Params: []
 # CHECK-NEXT:       Block {
 # CHECK-NEXT:         VarDecl a<> @{{.*}}ast.toy:11:3
index dee0d5b..d2ccc5a 100644 (file)
@@ -27,7 +27,7 @@ def main() {
 # CHECK-NEXT:    VarDecl b<> @{{.*}}struct-ast.toy:5:3
 # CHECK-NEXT:  ]
 # CHECK-NEXT:Function
-# CHECK-NEXT:  Proto 'multiply_transpose' @{{.*}}struct-ast.toy:9:1'
+# CHECK-NEXT:  Proto 'multiply_transpose' @{{.*}}struct-ast.toy:9:1
 # CHECK-NEXT:  Params: [value]
 # CHECK-NEXT:  Block {
 # CHECK-NEXT:    Return
@@ -44,7 +44,7 @@ def main() {
 # CHECK-NEXT:        ]
 # CHECK-NEXT:  }
 # CHECK-NEXT:Function
-# CHECK-NEXT:  Proto 'main' @{{.*}}struct-ast.toy:14:1'
+# CHECK-NEXT:  Proto 'main' @{{.*}}struct-ast.toy:14:1
 # CHECK-NEXT:  Params: []
 # CHECK-NEXT:  Block {
 # CHECK-NEXT:    VarDecl value<Struct> @{{.*}}struct-ast.toy:16:3