Skip to content

Commit

Permalink
[MLIR][Standard] Add assert operation to the standard dialect
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D83117
  • Loading branch information
frgossen committed Jul 14, 2020
1 parent dad1868 commit bcedc4f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
34 changes: 31 additions & 3 deletions mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
Original file line number Diff line number Diff line change
Expand Up @@ -379,23 +379,23 @@ 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
specified in its memref type. In the example below, the SSA value '%d' is
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
memref's affine map. In the example below, the SSA value '%s' is bound to
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)>>
```

Expand Down Expand Up @@ -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
//===----------------------------------------------------------------------===//
Expand Down
4 changes: 4 additions & 0 deletions mlir/test/Dialect/Standard/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit bcedc4f

Please sign in to comment.