[Mlir-commits] [mlir] 1c189d7 - [mlir] Add number of operands verification for shape.assuming_all operation

Jacques Pienaar llvmlistbot at llvm.org
Tue Jun 9 10:02:26 PDT 2020


Author: msifontes
Date: 2020-06-09T09:59:04-07:00
New Revision: 1c189d71dbb9ea0f8dd2f396c051c4c89e0ad2df

URL: https://github.com/llvm/llvm-project/commit/1c189d71dbb9ea0f8dd2f396c051c4c89e0ad2df
DIFF: https://github.com/llvm/llvm-project/commit/1c189d71dbb9ea0f8dd2f396c051c4c89e0ad2df.diff

LOG: [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.

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
    mlir/lib/Dialect/Shape/IR/Shape.cpp
    mlir/test/Dialect/Shape/invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index c51423eacb02..2393aa1865a1 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -507,6 +507,8 @@ def Shape_AssumingAllOp : Shape_Op<"assuming_all", [Commutative, NoSideEffect]>
   let assemblyFormat = "$inputs attr-dict";
 
   let hasFolder = 1;
+
+  let verifier = [{ return ::verify(*this); }];
 }
 
 def Shape_AssumingOp : Shape_Op<"assuming",

diff  --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp
index c46df3a6c7bc..9df20e4871c7 100644
--- a/mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -219,6 +219,14 @@ OpFoldResult AssumingAllOp::fold(ArrayRef<Attribute> operands) {
   return BoolAttr::get(true, getContext());
 }
 
+static LogicalResult verify(AssumingAllOp op) {
+  // Ensure that AssumingAllOp contains at least one operand
+  if (op.getNumOperands() == 0)
+    return op.emitOpError("no operands specified");
+
+  return success();
+}
+
 //===----------------------------------------------------------------------===//
 // BroadcastOp
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/test/Dialect/Shape/invalid.mlir b/mlir/test/Dialect/Shape/invalid.mlir
index 41105dc617fc..da059a489be3 100644
--- a/mlir/test/Dialect/Shape/invalid.mlir
+++ b/mlir/test/Dialect/Shape/invalid.mlir
@@ -60,3 +60,11 @@ func @yield_op_type_mismatch(%shape : !shape.shape, %init : !shape.size) {
       shape.yield %c0 : index
   }
 }
+
+// -----
+
+func @assuming_all_op_too_few_operands() {
+  // expected-error at +1 {{no operands specified}}
+  %w0 = shape.assuming_all
+  return
+}


        


More information about the Mlir-commits mailing list