class GPU_IndexOp<string mnemonic, list<OpTrait> traits = []> :
GPU_Op<mnemonic, !listconcat(traits, [NoSideEffect])>,
- Arguments<(ins StrAttr:$dimension)>, Results<(outs Index)>;
+ Arguments<(ins StrAttr:$dimension)>, Results<(outs Index)> {
+ let verifier = [{ return ::verifyIndexOp(*this); }];
+}
def gpu_BlockDim : GPU_IndexOp<"block_dim">;
def gpu_BlockId : GPU_IndexOp<"block_id">;
>();
}
+template <typename T> static LogicalResult verifyIndexOp(T op) {
+ auto dimension = op.dimension();
+ if (dimension != "x" && dimension != "y" && dimension != "z")
+ return op.emitError("dimension \"") << dimension << "\" is invalid";
+ return success();
+}
+
#define GET_OP_CLASSES
#include "mlir/Dialect/GPU/GPUOps.cpp.inc"
: (index, index, index, index, index, index, f32) -> ()
return
}
+
+// -----
+
+func @illegal_dimension() {
+ // expected-error@+1 {{dimension "o" is invalid}}
+ %tIdX = "gpu.thread_id"() {dimension = "o"} : () -> (index)
+
+ return
+}
+
+// -----
+
+func @illegal_dimension() {
+ // expected-error@+1 {{dimension "o" is invalid}}
+ %bDimX = "gpu.block_dim"() {dimension = "o"} : () -> (index)
+
+ return
+}
+
+// -----
+
+func @illegal_dimension() {
+ // expected-error@+1 {{dimension "o" is invalid}}
+ %bIdX = "gpu.block_id"() {dimension = "o"} : () -> (index)
+
+ return
+}
+
+// -----
+
+func @illegal_dimension() {
+ // expected-error@+1 {{dimension "o" is invalid}}
+ %gDimX = "gpu.grid_dim"() {dimension = "o"} : () -> (index)
+
+ return
+}