[Mlir-commits] [mlir] bcedc4f - [MLIR][Standard] Add `assert` operation to the standard dialect
Frederik Gossen
llvmlistbot at llvm.org
Tue Jul 14 03:01:43 PDT 2020
Author: Frederik Gossen
Date: 2020-07-14T10:00:54Z
New Revision: bcedc4fa0a606b4c4384c0892c7d4da8010a676a
URL: https://github.com/llvm/llvm-project/commit/bcedc4fa0a606b4c4384c0892c7d4da8010a676a
DIFF: https://github.com/llvm/llvm-project/commit/bcedc4fa0a606b4c4384c0892c7d4da8010a676a.diff
LOG: [MLIR][Standard] Add `assert` operation to the standard dialect
Differential Revision: https://reviews.llvm.org/D83117
Added:
Modified:
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
mlir/test/Dialect/Standard/ops.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
index dd74aa137060..57293591f383 100644
--- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
+++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
@@ -379,7 +379,7 @@ def AllocaOp : AllocLikeOp<"alloca", AutomaticAllocationScopeResource> {
operands. For example:
```mlir
- %0 = alloca() : memref<8x64xf32>
+ %0 = alloca() : memref<8x64xf32>
```
The optional list of dimension operands are bound to the dynamic dimensions
@@ -387,7 +387,7 @@ def AllocaOp : AllocLikeOp<"alloca", AutomaticAllocationScopeResource> {
bound to the second dimension of the memref (which is dynamic).
```mlir
- %0 = alloca(%d) : memref<8x?xf32>
+ %0 = alloca(%d) : memref<8x?xf32>
```
The optional list of symbol operands are bound to the symbols of the
@@ -395,7 +395,7 @@ def AllocaOp : AllocLikeOp<"alloca", AutomaticAllocationScopeResource> {
the symbol 's0' in the affine map specified in the allocs memref type.
```mlir
- %0 = alloca()[%s] : memref<8x64xf32,
+ %0 = alloca()[%s] : memref<8x64xf32,
affine_map<(d0, d1)[s0] -> ((d0 + s0), d1)>>
```
@@ -441,6 +441,34 @@ def AndOp : IntArithmeticOp<"and", [Commutative]> {
let hasFolder = 1;
}
+//===----------------------------------------------------------------------===//
+// AssertOp
+//===----------------------------------------------------------------------===//
+
+def AssertOp : Std_Op<"assert"> {
+ let summary = "Assert operation with message attribute";
+ let description = [{
+ Assert operation with single boolean operand and an error message attribute.
+ If the argument is `true` this operation has no effect.
+ Otherwise, the program execution will abort.
+ The provided error message may be used by a runtime to propagate the error
+ to the user.
+
+ Example:
+
+ ```mlir
+ assert %b, "Expected ... to be true"
+ ```
+ }];
+
+ let arguments = (ins I1:$arg, StrAttr:$msg);
+
+ let assemblyFormat = "$arg `,` $msg attr-dict";
+
+ // AssertOp is fully verified by its traits.
+ let verifier = ?;
+}
+
//===----------------------------------------------------------------------===//
// AssumeAlignmentOp
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/Standard/ops.mlir b/mlir/test/Dialect/Standard/ops.mlir
index 3b098eb960ac..24da04eebaaa 100644
--- a/mlir/test/Dialect/Standard/ops.mlir
+++ b/mlir/test/Dialect/Standard/ops.mlir
@@ -18,3 +18,7 @@ func @test_index_cast_tensor_reverse(%arg0 : tensor<i64>) -> tensor<index> {
return %0 : tensor<index>
}
+func @assert(%arg : i1) {
+ assert %arg, "Some message in case this assertion fails."
+ return
+}
More information about the Mlir-commits
mailing list