} // isCodeGenOnly = 1
multiclass CALL<WebAssemblyRegClass vt> {
- def CALL_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops),
- [(set vt:$dst, (WebAssemblycall1 I32:$callee))]>;
+ def CALL_#vt : I<(outs vt:$dst), (ins global:$callee, variable_ops),
+ [(set vt:$dst, (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee)))]>;
+ def CALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops),
+ [(set vt:$dst, (WebAssemblycall1 I32:$callee))]>;
}
let Uses = [SP32, SP64], isCall = 1 in {
defm : CALL<I32>;
defm : CALL<F32>;
defm : CALL<F64>;
- def CALL_VOID : I<(outs), (ins I32:$callee, variable_ops),
- [(WebAssemblycall0 I32:$callee)]>;
+ def CALL_VOID : I<(outs), (ins global:$callee, variable_ops),
+ [(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee))]>;
+ def CALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops),
+ [(WebAssemblycall0 I32:$callee)]>;
} // Uses = [SP32,SP64], isCall = 1
/*
* TODO(jfb): Add the following.
*
- * call: call function directly
- * call_indirect: call function indirectly
* addressof: obtain a function pointer value for a given function
*/
; CHECK-LABEL: (func $call_i32_nullary
; CHECK-NEXT: (result i32)
-; CHECK-NEXT: (setlocal @0 (global $i32_nullary))
-; CHECK-NEXT: (setlocal @1 (call @0))
-; CHECK-NEXT: (return @1)
+; CHECK-NEXT: (setlocal @0 (call $i32_nullary))
+; CHECK-NEXT: (return @0)
define i32 @call_i32_nullary() {
%r = call i32 @i32_nullary()
ret i32 %r
; CHECK-LABEL: (func $call_i64_nullary
; CHECK-NEXT: (result i64)
-; CHECK-NEXT: (setlocal @0 (global $i64_nullary))
-; CHECK-NEXT: (setlocal @1 (call @0))
-; CHECK-NEXT: (return @1)
+; CHECK-NEXT: (setlocal @0 (call $i64_nullary))
+; CHECK-NEXT: (return @0)
define i64 @call_i64_nullary() {
%r = call i64 @i64_nullary()
ret i64 %r
; CHECK-LABEL: (func $call_float_nullary
; CHECK-NEXT: (result f32)
-; CHECK-NEXT: (setlocal @0 (global $float_nullary))
-; CHECK-NEXT: (setlocal @1 (call @0))
-; CHECK-NEXT: (return @1)
+; CHECK-NEXT: (setlocal @0 (call $float_nullary))
+; CHECK-NEXT: (return @0)
define float @call_float_nullary() {
%r = call float @float_nullary()
ret float %r
; CHECK-LABEL: (func $call_double_nullary
; CHECK-NEXT: (result f64)
-; CHECK-NEXT: (setlocal @0 (global $double_nullary))
-; CHECK-NEXT: (setlocal @1 (call @0))
-; CHECK-NEXT: (return @1)
+; CHECK-NEXT: (setlocal @0 (call $double_nullary))
+; CHECK-NEXT: (return @0)
define double @call_double_nullary() {
%r = call double @double_nullary()
ret double %r
}
; CHECK-LABEL: (func $call_void_nullary
-; CHECK-NEXT: (setlocal @0 (global $void_nullary))
-; CHECK-NEXT: (call @0)
+; CHECK-NEXT: (call $void_nullary)
; CHECK-NEXT: (return)
define void @call_void_nullary() {
call void @void_nullary()
; CHECK-LABEL: (func $call_i32_unary
; CHECK-NEXT: (param i32) (result i32)
; CHECK-NEXT: (setlocal @0 (argument 0))
-; CHECK-NEXT: (setlocal @1 (global $i32_unary))
-; CHECK-NEXT: (setlocal @2 (call @1 @0))
-; CHECK-NEXT: (return @2)
+; CHECK-NEXT: (setlocal @1 (call $i32_unary @0))
+; CHECK-NEXT: (return @1)
define i32 @call_i32_unary(i32 %a) {
%r = call i32 @i32_unary(i32 %a)
ret i32 %r
; CHECK-NEXT: (param i32) (param i32) (result i32)
; CHECK-NEXT: (setlocal @0 (argument 1))
; CHECK-NEXT: (setlocal @1 (argument 0))
-; CHECK-NEXT: (setlocal @2 (global $i32_binary))
-; CHECK-NEXT: (setlocal @3 (call @2 @1 @0))
-; CHECK-NEXT: (return @3)
+; CHECK-NEXT: (setlocal @2 (call $i32_binary @1 @0))
+; CHECK-NEXT: (return @2)
define i32 @call_i32_binary(i32 %a, i32 %b) {
%r = call i32 @i32_binary(i32 %a, i32 %b)
ret i32 %r
}
+; CHECK-LABEL: (func $call_indirect_void
+; CHECK-NEXT: (param i32)
+; CHECK-NEXT: (setlocal @0 (argument 0))
+; CHECK-NEXT: (call_indirect @0)
+; CHECK-NEXT: (return)
+define void @call_indirect_void(void ()* %callee) {
+ call void %callee()
+ ret void
+}
+
+; CHECK-LABEL: (func $call_indirect_i32
+; CHECK-NEXT: (param i32)
+; CHECK-NEXT: (setlocal @0 (argument 0))
+; CHECK-NEXT: (setlocal @1 (call_indirect @0))
+; CHECK-NEXT: (return @1)
+define i32 @call_indirect_i32(i32 ()* %callee) {
+ %t = call i32 %callee()
+ ret i32 %t
+}
+
; FIXME test the following:
; - Functions without return.
; - More argument combinations.
; CHECK: (block $BB0_2)
; CHECK: (switch {{.*}} $BB0_2 $BB0_2 $BB0_2 $BB0_2 $BB0_2 $BB0_2 $BB0_2 $BB0_2 $BB0_3 $BB0_3 $BB0_3 $BB0_3 $BB0_3 $BB0_3 $BB0_3 $BB0_3 $BB0_4 $BB0_4 $BB0_4 $BB0_4 $BB0_4 $BB0_4 $BB0_5 $BB0_6 $BB0_7)
; CHECk: BB0_2:
-; CHECK: (setlocal {{.*}} (global $foo0))
+; CHECK: (call $foo0)
; CHECK: BB0_3:
-; CHECK: (setlocal {{.*}} (global $foo1))
+; CHECK: (call $foo1)
; CHECK: BB0_4:
-; CHECK: (setlocal {{.*}} (global $foo2))
+; CHECK: (call $foo2)
; CHECK: BB0_5:
-; CHECK: (setlocal {{.*}} (global $foo3))
+; CHECK: (call $foo3)
; CHECK: BB0_6:
-; CHECK: (setlocal {{.*}} (global $foo4))
+; CHECK: (call $foo4)
; CHECK: BB0_7:
-; CHECK: (setlocal {{.*}} (global $foo5))
+; CHECK: (call $foo5)
; CHECK: BB0_8:
; CHECK: (return)
define void @bar32(i32 %n) {
; CHECK: (block $BB1_2)
; CHECK: (switch {{.*}} $BB1_2 $BB1_2 $BB1_2 $BB1_2 $BB1_2 $BB1_2 $BB1_2 $BB1_2 $BB1_3 $BB1_3 $BB1_3 $BB1_3 $BB1_3 $BB1_3 $BB1_3 $BB1_3 $BB1_4 $BB1_4 $BB1_4 $BB1_4 $BB1_4 $BB1_4 $BB1_5 $BB1_6 $BB1_7)
; CHECk: BB1_2:
-; CHECK: (setlocal {{.*}} (global $foo0))
+; CHECK: (call $foo0)
; CHECK: BB1_3:
-; CHECK: (setlocal {{.*}} (global $foo1))
+; CHECK: (call $foo1)
; CHECK: BB1_4:
-; CHECK: (setlocal {{.*}} (global $foo2))
+; CHECK: (call $foo2)
; CHECK: BB1_5:
-; CHECK: (setlocal {{.*}} (global $foo3))
+; CHECK: (call $foo3)
; CHECK: BB1_6:
-; CHECK: (setlocal {{.*}} (global $foo4))
+; CHECK: (call $foo4)
; CHECK: BB1_7:
-; CHECK: (setlocal {{.*}} (global $foo5))
+; CHECK: (call $foo5)
; CHECK: BB1_8:
; CHECK: (return)
define void @bar64(i64 %n) {