//===----------------------------------------------------------------------===//
static LogicalResult verify(spirv::ReturnOp returnOp) {
- auto funcOp = cast<FuncOp>(returnOp.getParentOp());
+ auto funcOp = returnOp.getParentOfType<FuncOp>();
auto numOutputs = funcOp.getType().getNumResults();
if (numOutputs != 0)
return returnOp.emitOpError("cannot be used in functions returning value")
}
static LogicalResult verify(spirv::ReturnValueOp retValOp) {
- auto funcOp = cast<FuncOp>(retValOp.getParentOp());
+ auto funcOp = retValOp.getParentOfType<FuncOp>();
auto numFnResults = funcOp.getType().getNumResults();
if (numFnResults != 1)
return retValOp.emitOpError(
// spv.Return
//===----------------------------------------------------------------------===//
+// CHECK-LABEL: func @in_selection
+func @in_selection(%cond : i1) -> () {
+ spv.selection {
+ spv.BranchConditional %cond, ^then, ^merge
+ ^then:
+ // CHECK: spv.Return
+ spv.Return
+ ^merge:
+ spv._merge
+ }
+ spv.Return
+}
+
+// CHECK-LABEL: func @in_loop
+func @in_loop(%cond : i1) -> () {
+ spv.loop {
+ spv.Branch ^header
+ ^header:
+ spv.BranchConditional %cond, ^body, ^merge
+ ^body:
+ // CHECK: spv.Return
+ spv.Return
+ ^continue:
+ spv.Branch ^header
+ ^merge:
+ spv._merge
+ }
+ spv.Return
+}
+
+// -----
+
"foo.function"() ({
// expected-error @+1 {{op must appear in a 'func' block}}
spv.Return
spv.ReturnValue %0 : i32
}
+// CHECK-LABEL: func @in_selection
+func @in_selection(%cond : i1) -> (i32) {
+ spv.selection {
+ spv.BranchConditional %cond, ^then, ^merge
+ ^then:
+ %zero = spv.constant 0 : i32
+ // CHECK: spv.ReturnValue
+ spv.ReturnValue %zero : i32
+ ^merge:
+ spv._merge
+ }
+ %one = spv.constant 1 : i32
+ spv.ReturnValue %one : i32
+}
+
+// CHECK-LABEL: func @in_loop
+func @in_loop(%cond : i1) -> (i32) {
+ spv.loop {
+ spv.Branch ^header
+ ^header:
+ spv.BranchConditional %cond, ^body, ^merge
+ ^body:
+ %zero = spv.constant 0 : i32
+ // CHECK: spv.ReturnValue
+ spv.ReturnValue %zero : i32
+ ^continue:
+ spv.Branch ^header
+ ^merge:
+ spv._merge
+ }
+ %one = spv.constant 1 : i32
+ spv.ReturnValue %one : i32
+}
+
// -----
"foo.function"() ({