[Mlir-commits] [mlir] [mlir][emitc] Add 'emitc.switch' op to the dialect (PR #102331)
Andrey Timonin
llvmlistbot at llvm.org
Thu Aug 8 02:12:10 PDT 2024
================
@@ -80,8 +80,137 @@ func.func @array_as_result(%arg: !emitc.array<4xi8>) -> (!emitc.array<4xi8>) {
}
// -----
+
func.func @ptr_to_array() {
// expected-error at +1 {{cannot emit pointer to array type '!emitc.ptr<!emitc.array<9xi16>>'}}
%v = "emitc.variable"(){value = #emitc.opaque<"NULL">} : () -> !emitc.ptr<!emitc.array<9xi16>>
return
}
+
+// -----
+
+func.func @emitc_switch() {
+ %0 = "emitc.variable"(){value = 1 : ui16} : () -> ui16
+
+ // expected-error at +1 {{'emitc.switch' op expected region to end with emitc.yield, but got emitc.call_opaque}}
+ emitc.switch %0 : ui16
+ case 2: {
+ %1 = emitc.call_opaque "func_b" () : () -> i32
+ }
+ case 5: {
+ %2 = emitc.call_opaque "func_a" () : () -> i32
+ emitc.yield
+ }
+ default: {
+ %3 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
+ %4 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
+
+ emitc.call_opaque "func2" (%3) : (f32) -> ()
+ emitc.call_opaque "func3" (%3, %4) { args = [1 : index, 0 : index] } : (f32, f32) -> ()
+ emitc.yield
+ }
+ return
+}
+
+// -----
+
+func.func @emitc_switch() {
+ %0 = "emitc.variable"(){value = 1 : ui16} : () -> ui16
+
+ // expected-error at +1 {{'emitc.switch' op expected region to end with emitc.yield, but got emitc.call_opaque}}
+ emitc.switch %0 : ui16
+ case 2: {
+ %1 = emitc.call_opaque "func_b" () : () -> i32
+ emitc.yield
+ }
+ case 5: {
+ %2 = emitc.call_opaque "func_a" () : () -> i32
+ emitc.yield
+ }
+ default: {
+ %3 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
+ %4 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
+
+ emitc.call_opaque "func2" (%3) : (f32) -> ()
+ emitc.call_opaque "func3" (%3, %4) { args = [1 : index, 0 : index] } : (f32, f32) -> ()
+ }
+ return
+}
+
+// -----
+
+func.func @emitc_switch() {
+ %0 = "emitc.variable"(){value = 1 : i8} : () -> i8
+
+ // expected-error at +1 {{'emitc.switch' op operand #0 must be integer type for switch operation, but got 'i8'}}
+ emitc.switch %0 : i8
+ case 2: {
+ %1 = emitc.call_opaque "func_b" () : () -> i32
+ emitc.yield
+ }
+ case 5: {
+ %2 = emitc.call_opaque "func_a" () : () -> i32
+ emitc.yield
+ }
+ default: {
+ %3 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
+ %4 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
+
+ emitc.call_opaque "func2" (%3) : (f32) -> ()
+ emitc.call_opaque "func3" (%3, %4) { args = [1 : index, 0 : index] } : (f32, f32) -> ()
+ emitc.yield
+ }
+ return
+}
+
+// -----
+
+func.func @emitc_switch() {
+ %0 = "emitc.variable"(){value = 1 : i1} : () -> i1
+
+ // expected-error at +1 {{'emitc.switch' op operand #0 must be integer type for switch operation, but got 'i1'}}
+ emitc.switch %0 : i1
+ case 2: {
+ %1 = emitc.call_opaque "func_b" () : () -> i32
+ emitc.yield
+ }
+ case 5: {
+ %2 = emitc.call_opaque "func_a" () : () -> i32
+ emitc.yield
+ }
+ default: {
+ %3 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
+ %4 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
+
+ emitc.call_opaque "func2" (%3) : (f32) -> ()
+ emitc.call_opaque "func3" (%3, %4) { args = [1 : index, 0 : index] } : (f32, f32) -> ()
+ emitc.yield
+ }
+ return
+}
+
+// -----
+
+func.func @emitc_switch() {
+ %0 = "emitc.variable"(){value = 1 : i16} : () -> i16
+
+ emitc.switch %0 : i16
+ case 2: {
+ %1 = emitc.call_opaque "func_b" () : () -> i32
+ emitc.yield
+ }
+ // expected-error at +1 {{custom op 'emitc.switch' expected integer value}}
+ case : {
+ %2 = emitc.call_opaque "func_a" () : () -> i32
+ emitc.yield
+ }
+ default: {
+ %3 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
+ %4 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
+
+ emitc.call_opaque "func2" (%3) : (f32) -> ()
+ emitc.call_opaque "func3" (%3, %4) { args = [1 : index, 0 : index] } : (f32, f32) -> ()
+ emitc.yield
+ }
+ return
+}
----------------
EtoAndruwa wrote:
Added.
https://github.com/llvm/llvm-project/pull/102331
More information about the Mlir-commits
mailing list