2018-08-27 23:45:51 +08:00
|
|
|
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -verify-machineinstrs | FileCheck %s
|
|
|
|
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -verify-machineinstrs -fast-isel | FileCheck %s
|
2016-01-28 05:17:39 +08:00
|
|
|
|
|
|
|
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
|
2018-05-11 01:49:11 +08:00
|
|
|
target triple = "wasm32-unknown-unknown"
|
2016-01-28 05:17:39 +08:00
|
|
|
|
|
|
|
%SmallStruct = type { i32 }
|
|
|
|
%OddStruct = type { i32, i8, i32 }
|
|
|
|
%AlignedStruct = type { double, double }
|
|
|
|
%BigStruct = type { double, double, double, double, double, double, double, double, double, double, double, i8, i8, i8 }
|
2016-02-13 05:30:18 +08:00
|
|
|
%EmptyStruct = type { }
|
2016-01-28 05:17:39 +08:00
|
|
|
|
|
|
|
declare void @ext_func(%SmallStruct*)
|
2020-11-20 23:52:27 +08:00
|
|
|
declare void @ext_func_empty(%EmptyStruct* byval(%EmptyStruct))
|
|
|
|
declare void @ext_byval_func(%SmallStruct* byval(%SmallStruct))
|
|
|
|
declare void @ext_byval_func_align8(%SmallStruct* byval(%SmallStruct) align 8)
|
|
|
|
declare void @ext_byval_func_alignedstruct(%AlignedStruct* byval(%AlignedStruct))
|
|
|
|
declare void @ext_byval_func_empty(%EmptyStruct* byval(%EmptyStruct))
|
2016-01-28 05:17:39 +08:00
|
|
|
|
|
|
|
; CHECK-LABEL: byval_arg
|
|
|
|
define void @byval_arg(%SmallStruct* %ptr) {
|
2018-11-20 01:10:36 +08:00
|
|
|
; CHECK: .functype byval_arg (i32) -> ()
|
2016-01-28 05:17:39 +08:00
|
|
|
; Subtract 16 from SP (SP is 16-byte aligned)
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.get $push[[L2:.+]]=, __stack_pointer
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
|
2016-08-19 01:51:27 +08:00
|
|
|
; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
|
2016-01-28 05:17:39 +08:00
|
|
|
; Ensure SP is stored back before the call
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L10]]{{$}}
|
2016-01-28 05:17:39 +08:00
|
|
|
; Copy the SmallStruct argument to the stack (SP+12, original SP-4)
|
2016-05-10 12:24:02 +08:00
|
|
|
; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0)
|
2016-10-07 06:08:28 +08:00
|
|
|
; CHECK-NEXT: i32.store 12($[[SP]]), $pop[[L0]]
|
2016-01-28 05:17:39 +08:00
|
|
|
; Pass a pointer to the stack slot to the function
|
2016-05-10 12:24:02 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L5:.+]]=, 12{{$}}
|
|
|
|
; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: call ext_byval_func, $pop[[ARG]]{{$}}
|
2020-11-20 23:52:27 +08:00
|
|
|
call void @ext_byval_func(%SmallStruct* byval(%SmallStruct) %ptr)
|
2016-01-28 05:17:39 +08:00
|
|
|
; Restore the stack
|
2016-03-18 01:00:29 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L6:.+]]=, 16
|
2016-05-10 12:24:02 +08:00
|
|
|
; CHECK-NEXT: i32.add $push[[L8:.+]]=, $[[SP]], $pop[[L6]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L8]]
|
2016-01-28 05:17:39 +08:00
|
|
|
; CHECK-NEXT: return
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: byval_arg_align8
|
|
|
|
define void @byval_arg_align8(%SmallStruct* %ptr) {
|
2018-11-20 01:10:36 +08:00
|
|
|
; CHECK: .functype byval_arg_align8 (i32) -> ()
|
2016-01-28 05:17:39 +08:00
|
|
|
; Don't check the entire SP sequence, just enough to get the alignment.
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, 16
|
2016-08-19 01:51:27 +08:00
|
|
|
; CHECK-NEXT: i32.sub $push[[L11:.+]]=, {{.+}}, $pop[[L1]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L10]]{{$}}
|
2016-01-28 05:17:39 +08:00
|
|
|
; Copy the SmallStruct argument to the stack (SP+8, original SP-8)
|
2016-05-10 12:24:02 +08:00
|
|
|
; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0){{$}}
|
2016-10-07 06:08:28 +08:00
|
|
|
; CHECK-NEXT: i32.store 8($[[SP]]), $pop[[L0]]{{$}}
|
2016-01-28 05:17:39 +08:00
|
|
|
; Pass a pointer to the stack slot to the function
|
2016-05-10 12:24:02 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L5:.+]]=, 8{{$}}
|
|
|
|
; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: call ext_byval_func_align8, $pop[[ARG]]{{$}}
|
2020-11-20 23:52:27 +08:00
|
|
|
call void @ext_byval_func_align8(%SmallStruct* byval(%SmallStruct) align 8 %ptr)
|
2016-01-28 05:17:39 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: byval_arg_double
|
|
|
|
define void @byval_arg_double(%AlignedStruct* %ptr) {
|
2018-11-20 01:10:36 +08:00
|
|
|
; CHECK: .functype byval_arg_double (i32) -> ()
|
2016-01-28 05:17:39 +08:00
|
|
|
; Subtract 16 from SP (SP is 16-byte aligned)
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, 16
|
2016-08-19 01:51:27 +08:00
|
|
|
; CHECK-NEXT: i32.sub $push[[L14:.+]]=, {{.+}}, $pop[[L1]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L13:.+]]=, $[[SP:.+]]=, $pop[[L14]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L13]]
|
2016-01-28 05:17:39 +08:00
|
|
|
; Copy the AlignedStruct argument to the stack (SP+0, original SP-16)
|
|
|
|
; Just check the last load/store pair of the memcpy
|
|
|
|
; CHECK: i64.load $push[[L4:.+]]=, 0($0)
|
2016-10-07 06:08:28 +08:00
|
|
|
; CHECK-NEXT: i64.store 0($[[SP]]), $pop[[L4]]
|
2016-01-28 05:17:39 +08:00
|
|
|
; Pass a pointer to the stack slot to the function
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: call ext_byval_func_alignedstruct, $[[SP]]
|
2020-11-20 23:52:27 +08:00
|
|
|
tail call void @ext_byval_func_alignedstruct(%AlignedStruct* byval(%AlignedStruct) %ptr)
|
2016-01-28 05:17:39 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: byval_param
|
2020-11-20 23:52:27 +08:00
|
|
|
define void @byval_param(%SmallStruct* byval(%SmallStruct) align 32 %ptr) {
|
2018-11-20 01:10:36 +08:00
|
|
|
; CHECK: .functype byval_param (i32) -> ()
|
2016-01-28 05:17:39 +08:00
|
|
|
; %ptr is just a pointer to a struct, so pass it directly through
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: call ext_func, $0
|
2016-01-28 05:17:39 +08:00
|
|
|
call void @ext_func(%SmallStruct* %ptr)
|
|
|
|
ret void
|
|
|
|
}
|
2016-02-13 05:30:18 +08:00
|
|
|
|
|
|
|
; CHECK-LABEL: byval_empty_caller
|
|
|
|
define void @byval_empty_caller(%EmptyStruct* %ptr) {
|
2018-11-20 01:10:36 +08:00
|
|
|
; CHECK: .functype byval_empty_caller (i32) -> ()
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: call ext_byval_func_empty, $0
|
2020-11-20 23:52:27 +08:00
|
|
|
call void @ext_byval_func_empty(%EmptyStruct* byval(%EmptyStruct) %ptr)
|
2016-02-13 05:30:18 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: byval_empty_callee
|
2020-11-20 23:52:27 +08:00
|
|
|
define void @byval_empty_callee(%EmptyStruct* byval(%EmptyStruct) %ptr) {
|
2018-11-20 01:10:36 +08:00
|
|
|
; CHECK: .functype byval_empty_callee (i32) -> ()
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: call ext_func_empty, $0
|
2016-02-13 05:30:18 +08:00
|
|
|
call void @ext_func_empty(%EmptyStruct* %ptr)
|
|
|
|
ret void
|
|
|
|
}
|
2016-02-17 09:43:37 +08:00
|
|
|
|
|
|
|
; Call memcpy for "big" byvals.
|
|
|
|
; CHECK-LABEL: big_byval:
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.get $push[[L2:.+]]=, __stack_pointer{{$}}
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L3:.+]]=, 131072
|
2016-08-19 01:51:27 +08:00
|
|
|
; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L10]]{{$}}
|
2016-05-10 12:24:02 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L0:.+]]=, 131072
|
[WebAssembly] Replace all calls with generalized multivalue calls
Summary:
Extends the multivalue call infrastructure to tail calls, removes all
legacy calls specialized for particular result types, and removes the
CallIndirectFixup pass, since all indirect call arguments are now
fixed up directly in the post-insertion hook.
In order to keep supporting pretty-printed defs and uses in test
expectations, MCInstLower now inserts an immediate containing the
number of defs for each call and call_indirect. The InstPrinter is
updated to query this immediate if it is present and determine which
MCOperands are defs and uses accordingly.
Depends on D72902.
Reviewers: aheejin
Subscribers: dschuff, mgorny, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74192
2020-02-07 08:29:59 +08:00
|
|
|
; CHECK-NEXT: call $push[[L11:.+]]=, memcpy, $[[SP]], ${{.+}}, $pop{{.+}}
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L9:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: call big_byval_callee,
|
2016-02-17 09:43:37 +08:00
|
|
|
%big = type [131072 x i8]
|
2020-11-20 23:52:27 +08:00
|
|
|
declare void @big_byval_callee(%big* byval(%big) align 1)
|
|
|
|
define void @big_byval(%big* byval(%big) align 1 %x) {
|
|
|
|
call void @big_byval_callee(%big* byval(%big) align 1 %x)
|
2016-02-17 09:43:37 +08:00
|
|
|
ret void
|
|
|
|
}
|