summaryrefslogtreecommitdiffstats
path: root/mlir/test/Examples/Toy/Ch3
diff options
context:
space:
mode:
authorSana Damani <sdamani@gatech.edu>2019-10-15 11:40:12 -0700
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-10-15 11:40:44 -0700
commitcd45b0c8d9f0eac7e76a892a2f2e993b340e90b5 (patch)
tree92fe9cd39ff01748b1adfdcbeb9eb229c8a2773e /mlir/test/Examples/Toy/Ch3
parent4e85dafeddc14b5ddca8e819f04dbdeeac57bbfc (diff)
downloadbcm5719-llvm-cd45b0c8d9f0eac7e76a892a2f2e993b340e90b5.tar.gz
bcm5719-llvm-cd45b0c8d9f0eac7e76a892a2f2e993b340e90b5.zip
Update Chapter 3 to demonstrate pattern match and rewrite optimizations
This is using Table-driven Declarative Rewrite Rules (DRR), the previous version of the tutorial only showed the C++ patterns. Closes tensorflow/mlir#187 PiperOrigin-RevId: 274852321
Diffstat (limited to 'mlir/test/Examples/Toy/Ch3')
-rw-r--r--mlir/test/Examples/Toy/Ch3/codegen.toy31
-rw-r--r--mlir/test/Examples/Toy/Ch3/invalid.mlir6
-rw-r--r--mlir/test/Examples/Toy/Ch3/scalar.toy6
3 files changed, 20 insertions, 23 deletions
diff --git a/mlir/test/Examples/Toy/Ch3/codegen.toy b/mlir/test/Examples/Toy/Ch3/codegen.toy
index d4949cd013e..7103e549ca3 100644
--- a/mlir/test/Examples/Toy/Ch3/codegen.toy
+++ b/mlir/test/Examples/Toy/Ch3/codegen.toy
@@ -13,20 +13,19 @@ def main() {
print(d);
}
-# CHECK-LABEL: func @multiply_transpose(%arg0: !toy.array, %arg1: !toy.array)
-# CHECK-NEXT: attributes {toy.generic = true} {
-# CHECK-NEXT: %0 = "toy.transpose"(%arg1) : (!toy.array) -> !toy.array
-# CHECK-NEXT: %1 = "toy.mul"(%arg0, %0) : (!toy.array, !toy.array) -> !toy.array
-# CHECK-NEXT: "toy.return"(%1) : (!toy.array) -> ()
-# CHECK-NEXT: }
-
-# CHECK-LABEL: func @main() {
-# CHECK-NEXT: %0 = "toy.constant"() {value = dense<{{\[\[}}1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]]> : tensor<2x3xf64>} : () -> !toy.array<2, 3>
-# CHECK-NEXT: %1 = "toy.reshape"(%0) : (!toy.array<2, 3>) -> !toy.array<2, 3>
-# CHECK-NEXT: %2 = "toy.constant"() {value = dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 5.000000e+00, 6.000000e+00]> : tensor<6xf64>} : () -> !toy.array<6>
-# CHECK-NEXT: %3 = "toy.reshape"(%2) : (!toy.array<6>) -> !toy.array<2, 3>
-# CHECK-NEXT: %4 = "toy.generic_call"(%1, %3) {callee = "multiply_transpose"} : (!toy.array<2, 3>, !toy.array<2, 3>) -> !toy.array
-# CHECK-NEXT: %5 = "toy.generic_call"(%3, %1) {callee = "multiply_transpose"} : (!toy.array<2, 3>, !toy.array<2, 3>) -> !toy.array
-# CHECK-NEXT: "toy.print"(%5) : (!toy.array) -> ()
-# CHECK-NEXT: "toy.return"() : () -> ()
+# CHECK-LABEL: func @multiply_transpose(
+# CHECK-SAME: [[VAL_0:%.*]]: tensor<*xf64>, [[VAL_1:%.*]]: tensor<*xf64>)
+# CHECK-NEXT: attributes {toy.generic} {
+# CHECK-NEXT: [[VAL_2:%.*]] = "toy.transpose"([[VAL_1]]) : (tensor<*xf64>) -> tensor<*xf64>
+# CHECK-NEXT: [[VAL_3:%.*]] = "toy.mul"([[VAL_0]], [[VAL_2]]) : (tensor<*xf64>, tensor<*xf64>) -> tensor<*xf64>
+# CHECK-NEXT: "toy.return"([[VAL_3]]) : (tensor<*xf64>) -> ()
+# CHECK-LABEL: func @main() {
+# CHECK-NEXT: [[VAL_4:%.*]] = "toy.constant"() {value = dense<{{\[\[}}1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]]> : tensor<2x3xf64>} : () -> tensor<2x3xf64>
+# CHECK-NEXT: [[VAL_5:%.*]] = "toy.reshape"([[VAL_4]]) : (tensor<2x3xf64>) -> tensor<2x3xf64>
+# CHECK-NEXT: [[VAL_6:%.*]] = "toy.constant"() {value = dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 5.000000e+00, 6.000000e+00]> : tensor<6xf64>} : () -> tensor<6xf64>
+# CHECK-NEXT: [[VAL_7:%.*]] = "toy.reshape"([[VAL_6]]) : (tensor<6xf64>) -> tensor<2x3xf64>
+# CHECK-NEXT: [[VAL_8:%.*]] = "toy.generic_call"([[VAL_5]], [[VAL_7]]) {callee = @multiply_transpose} : (tensor<2x3xf64>, tensor<2x3xf64>) -> tensor<*xf64>
+# CHECK-NEXT: [[VAL_9:%.*]] = "toy.generic_call"([[VAL_7]], [[VAL_5]]) {callee = @multiply_transpose} : (tensor<2x3xf64>, tensor<2x3xf64>) -> tensor<*xf64>
+# CHECK-NEXT: "toy.print"([[VAL_9]]) : (tensor<*xf64>) -> ()
+# CHECK-NEXT: "toy.return"() : () -> ()
diff --git a/mlir/test/Examples/Toy/Ch3/invalid.mlir b/mlir/test/Examples/Toy/Ch3/invalid.mlir
index e750b52a640..558cf9c154d 100644
--- a/mlir/test/Examples/Toy/Ch3/invalid.mlir
+++ b/mlir/test/Examples/Toy/Ch3/invalid.mlir
@@ -1,11 +1,9 @@
// RUN: not toyc-ch3 %s -emit=mlir 2>&1
-
-// This IR is not "valid":
+// The following IR is not "valid":
// - toy.print should not return a value.
// - toy.print should take an argument.
// - There should be a block terminator.
-// This all round-trip since this is opaque for MLIR.
func @main() {
- %0 = "toy.print"() : () -> !toy.array<2, 3>
+ %0 = "toy.print"() : () -> tensor<2x3xf64>
}
diff --git a/mlir/test/Examples/Toy/Ch3/scalar.toy b/mlir/test/Examples/Toy/Ch3/scalar.toy
index 97863c10458..dd7ec935e88 100644
--- a/mlir/test/Examples/Toy/Ch3/scalar.toy
+++ b/mlir/test/Examples/Toy/Ch3/scalar.toy
@@ -6,9 +6,9 @@ def main() {
}
# CHECK-LABEL: func @main() {
-# CHECK-NEXT: %0 = "toy.constant"() {value = dense<5.500000e+00> : tensor<1xf64>} : () -> !toy.array<1>
-# CHECK-NEXT: %1 = "toy.reshape"(%0) : (!toy.array<1>) -> !toy.array<2, 2>
-# CHECK-NEXT: "toy.print"(%1) : (!toy.array<2, 2>) -> ()
+# CHECK-NEXT: %0 = "toy.constant"() {value = dense<5.500000e+00> : tensor<f64>} : () -> tensor<f64>
+# CHECK-NEXT: %1 = "toy.reshape"(%0) : (tensor<f64>) -> tensor<2x2xf64>
+# CHECK-NEXT: "toy.print"(%1) : (tensor<2x2xf64>) -> ()
# CHECK-NEXT: "toy.return"() : () -> ()
# CHECK-NEXT: }
OpenPOWER on IntegriCloud