[Mlir-commits] [mlir] 7c44651 - [mlir][shape] Extend shape.cstr_require with a message.

Sean Silva llvmlistbot at llvm.org
Fri Sep 18 10:21:50 PDT 2020


Author: Sean Silva
Date: 2020-09-18T10:21:10-07:00
New Revision: 7c44651360dd94e17011fd1cd7ec3c755e0363b4

URL: https://github.com/llvm/llvm-project/commit/7c44651360dd94e17011fd1cd7ec3c755e0363b4
DIFF: https://github.com/llvm/llvm-project/commit/7c44651360dd94e17011fd1cd7ec3c755e0363b4.diff

LOG: [mlir][shape] Extend shape.cstr_require with a message.

I realized when using this that one can't get very good error messages
without an additional message attribute.

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
    mlir/test/Dialect/Shape/canonicalize.mlir
    mlir/test/Dialect/Shape/ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index ed89ce36fb8a..b709d3c342e8 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -741,7 +741,7 @@ def Shape_ConstWitnessOp : Shape_Op<"const_witness", [ConstantLike, NoSideEffect
 def Shape_CstrRequireOp : Shape_Op<"cstr_require", []> {
   let summary = "Represents a runtime assertion that an i1 is `true`";
   let description = [{
-    Represents a runtime assretion that an i1 is true. It returns a
+    Represents a runtime assertion that an i1 is true. It returns a
     !shape.witness to order this assertion.
 
     For simplicity, prefer using other cstr_* ops if they are available for a
@@ -750,13 +750,17 @@ def Shape_CstrRequireOp : Shape_Op<"cstr_require", []> {
     Example:
     ```mlir
     %bool = ...
-    %w0 = shape.cstr_require %bool // Passing if `%bool` is true.
+    %w0 = shape.cstr_require %bool, "msg" // Passing if `%bool` is true.
     ```
+
+    Since this op can be used to express many 
diff erent possible assertions
+    (depending on whatever computation calculated `pred`), the `msg`
+    should clarify the nature of the assertion for users.
   }];
-  let arguments = (ins I1:$pred);
+  let arguments = (ins I1:$pred, StrAttr:$msg);
   let results = (outs Shape_WitnessType:$result);
 
-  let assemblyFormat = "$pred attr-dict";
+  let assemblyFormat = "$pred `,` $msg attr-dict";
 
   let hasFolder = 1;
 }

diff  --git a/mlir/test/Dialect/Shape/canonicalize.mlir b/mlir/test/Dialect/Shape/canonicalize.mlir
index 9c45f254ba6d..56a6ef74f54e 100644
--- a/mlir/test/Dialect/Shape/canonicalize.mlir
+++ b/mlir/test/Dialect/Shape/canonicalize.mlir
@@ -393,7 +393,7 @@ func @cstr_require_fold() {
   // CHECK-NEXT: consume.witness
   // CHECK-NEXT: return
   %true = constant true
-  %0 = shape.cstr_require %true
+  %0 = shape.cstr_require %true, "msg"
   "consume.witness"(%0) : (!shape.witness) -> ()
   return
 }
@@ -405,7 +405,7 @@ func @cstr_require_no_fold(%arg0: i1) {
   // CHECK-NEXT: shape.cstr_require
   // CHECK-NEXT: consume.witness
   // CHECK-NEXT: return
-  %0 = shape.cstr_require %arg0
+  %0 = shape.cstr_require %arg0, "msg"
   "consume.witness"(%0) : (!shape.witness) -> ()
   return
 }

diff  --git a/mlir/test/Dialect/Shape/ops.mlir b/mlir/test/Dialect/Shape/ops.mlir
index 1a431d2dbd2f..ad7d42efaa52 100644
--- a/mlir/test/Dialect/Shape/ops.mlir
+++ b/mlir/test/Dialect/Shape/ops.mlir
@@ -105,7 +105,7 @@ func @test_constraints() {
   %w1 = shape.cstr_eq %0, %1
   %w2 = shape.const_witness true
   %w3 = shape.const_witness false
-  %w4 = shape.cstr_require %true
+  %w4 = shape.cstr_require %true, "msg"
   %w_all = shape.assuming_all %w0, %w1, %w2, %w3, %w4
   shape.assuming %w_all -> !shape.shape {
     %2 = "shape.any"(%0, %1) : (!shape.shape, !shape.shape) -> !shape.shape


        


More information about the Mlir-commits mailing list