Skip to content

Commit bcedc4f

Browse files
committed
[MLIR][Standard] Add assert operation to the standard dialect
Differential Revision: https://reviews.llvm.org/D83117
1 parent dad1868 commit bcedc4f

File tree

2 files changed

+35
-3
lines changed
  • mlir
    • include/mlir/Dialect/StandardOps/IR
    • test/Dialect/Standard

2 files changed

+35
-3
lines changed

mlir/include/mlir/Dialect/StandardOps/IR/Ops.td

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,23 +379,23 @@ def AllocaOp : AllocLikeOp<"alloca", AutomaticAllocationScopeResource> {
379379
operands. For example:
380380

381381
```mlir
382-
%0 = alloca() : memref<8x64xf32>
382+
%0 = alloca() : memref<8x64xf32>
383383
```
384384

385385
The optional list of dimension operands are bound to the dynamic dimensions
386386
specified in its memref type. In the example below, the SSA value '%d' is
387387
bound to the second dimension of the memref (which is dynamic).
388388

389389
```mlir
390-
%0 = alloca(%d) : memref<8x?xf32>
390+
%0 = alloca(%d) : memref<8x?xf32>
391391
```
392392

393393
The optional list of symbol operands are bound to the symbols of the
394394
memref's affine map. In the example below, the SSA value '%s' is bound to
395395
the symbol 's0' in the affine map specified in the allocs memref type.
396396

397397
```mlir
398-
%0 = alloca()[%s] : memref<8x64xf32,
398+
%0 = alloca()[%s] : memref<8x64xf32,
399399
affine_map<(d0, d1)[s0] -> ((d0 + s0), d1)>>
400400
```
401401

@@ -441,6 +441,34 @@ def AndOp : IntArithmeticOp<"and", [Commutative]> {
441441
let hasFolder = 1;
442442
}
443443

444+
//===----------------------------------------------------------------------===//
445+
// AssertOp
446+
//===----------------------------------------------------------------------===//
447+
448+
def AssertOp : Std_Op<"assert"> {
449+
let summary = "Assert operation with message attribute";
450+
let description = [{
451+
Assert operation with single boolean operand and an error message attribute.
452+
If the argument is `true` this operation has no effect.
453+
Otherwise, the program execution will abort.
454+
The provided error message may be used by a runtime to propagate the error
455+
to the user.
456+
457+
Example:
458+
459+
```mlir
460+
assert %b, "Expected ... to be true"
461+
```
462+
}];
463+
464+
let arguments = (ins I1:$arg, StrAttr:$msg);
465+
466+
let assemblyFormat = "$arg `,` $msg attr-dict";
467+
468+
// AssertOp is fully verified by its traits.
469+
let verifier = ?;
470+
}
471+
444472
//===----------------------------------------------------------------------===//
445473
// AssumeAlignmentOp
446474
//===----------------------------------------------------------------------===//

mlir/test/Dialect/Standard/ops.mlir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ func @test_index_cast_tensor_reverse(%arg0 : tensor<i64>) -> tensor<index> {
1818
return %0 : tensor<index>
1919
}
2020

21+
func @assert(%arg : i1) {
22+
assert %arg, "Some message in case this assertion fails."
23+
return
24+
}

0 commit comments

Comments
 (0)