Skip to content

Commit 1c189d7

Browse files
msifontesjpienaar
authored andcommitted
[mlir] Add number of operands verification for shape.assuming_all operation
Implemented a verification to ensure that the shape.assuming_all operation always has at least one operand.
1 parent babd3ae commit 1c189d7

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ def Shape_AssumingAllOp : Shape_Op<"assuming_all", [Commutative, NoSideEffect]>
507507
let assemblyFormat = "$inputs attr-dict";
508508

509509
let hasFolder = 1;
510+
511+
let verifier = [{ return ::verify(*this); }];
510512
}
511513

512514
def Shape_AssumingOp : Shape_Op<"assuming",

mlir/lib/Dialect/Shape/IR/Shape.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ OpFoldResult AssumingAllOp::fold(ArrayRef<Attribute> operands) {
219219
return BoolAttr::get(true, getContext());
220220
}
221221

222+
static LogicalResult verify(AssumingAllOp op) {
223+
// Ensure that AssumingAllOp contains at least one operand
224+
if (op.getNumOperands() == 0)
225+
return op.emitOpError("no operands specified");
226+
227+
return success();
228+
}
229+
222230
//===----------------------------------------------------------------------===//
223231
// BroadcastOp
224232
//===----------------------------------------------------------------------===//

mlir/test/Dialect/Shape/invalid.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,11 @@ func @yield_op_type_mismatch(%shape : !shape.shape, %init : !shape.size) {
6060
shape.yield %c0 : index
6161
}
6262
}
63+
64+
// -----
65+
66+
func @assuming_all_op_too_few_operands() {
67+
// expected-error@+1 {{no operands specified}}
68+
%w0 = shape.assuming_all
69+
return
70+
}

0 commit comments

Comments
 (0)