mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-28 23:43:25 +00:00
[WebAssembly] Support for direct call and call_indirect.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248716 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3b17c1cb31
commit
ec9e44d1d4
@ -22,8 +22,10 @@ def : I<(outs), (ins i64imm:$amt1, i64imm:$amt2),
|
||||
} // 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>;
|
||||
@ -31,14 +33,14 @@ let Uses = [SP32, SP64], isCall = 1 in {
|
||||
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
|
||||
*/
|
||||
|
@ -15,9 +15,8 @@ declare void @void_nullary()
|
||||
|
||||
; 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
|
||||
@ -25,9 +24,8 @@ define i32 @call_i32_nullary() {
|
||||
|
||||
; 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
|
||||
@ -35,9 +33,8 @@ define i64 @call_i64_nullary() {
|
||||
|
||||
; 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
|
||||
@ -45,17 +42,15 @@ define float @call_float_nullary() {
|
||||
|
||||
; 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()
|
||||
@ -65,9 +60,8 @@ define void @call_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
|
||||
@ -77,14 +71,33 @@ define i32 @call_i32_unary(i32 %a) {
|
||||
; 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.
|
||||
|
@ -22,17 +22,17 @@ declare void @foo5()
|
||||
; 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) {
|
||||
@ -102,17 +102,17 @@ sw.epilog: ; preds = %entry, %sw.bb.5, %s
|
||||
; 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user