diff --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td --- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td +++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td @@ -741,7 +741,7 @@ 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 @@ 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 different 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 --- a/mlir/test/Dialect/Shape/canonicalize.mlir +++ b/mlir/test/Dialect/Shape/canonicalize.mlir @@ -393,7 +393,7 @@ // 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 @@ // 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 --- a/mlir/test/Dialect/Shape/ops.mlir +++ b/mlir/test/Dialect/Shape/ops.mlir @@ -105,7 +105,7 @@ %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