2017-12-09 05:27:00 +08:00
|
|
|
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-temporary-workarounds=false | FileCheck %s
|
|
|
|
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -fast-isel -fast-isel-abort=1 -wasm-temporary-workarounds=false | FileCheck %s
|
2015-08-25 05:59:51 +08:00
|
|
|
|
|
|
|
; Test that basic call operations assemble as expected.
|
|
|
|
|
2016-01-07 11:19:23 +08:00
|
|
|
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
|
2017-02-25 07:18:00 +08:00
|
|
|
target triple = "wasm32-unknown-unknown-wasm"
|
2015-08-25 05:59:51 +08:00
|
|
|
|
2015-08-25 06:16:48 +08:00
|
|
|
declare i32 @i32_nullary()
|
|
|
|
declare i32 @i32_unary(i32)
|
2015-09-09 09:52:45 +08:00
|
|
|
declare i32 @i32_binary(i32, i32)
|
2015-08-25 06:16:48 +08:00
|
|
|
declare i64 @i64_nullary()
|
|
|
|
declare float @float_nullary()
|
|
|
|
declare double @double_nullary()
|
2015-09-10 00:13:47 +08:00
|
|
|
declare void @void_nullary()
|
2015-08-25 06:16:48 +08:00
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: call_i32_nullary:
|
2015-11-24 00:50:18 +08:00
|
|
|
; CHECK-NEXT: .result i32{{$}}
|
2016-01-12 07:38:05 +08:00
|
|
|
; CHECK-NEXT: {{^}} i32.call $push[[NUM:[0-9]+]]=, i32_nullary@FUNCTION{{$}}
|
2015-11-19 00:12:01 +08:00
|
|
|
; CHECK-NEXT: return $pop[[NUM]]{{$}}
|
2015-08-25 06:16:48 +08:00
|
|
|
define i32 @call_i32_nullary() {
|
|
|
|
%r = call i32 @i32_nullary()
|
|
|
|
ret i32 %r
|
|
|
|
}
|
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: call_i64_nullary:
|
2015-11-24 00:50:18 +08:00
|
|
|
; CHECK-NEXT: .result i64{{$}}
|
2016-01-12 07:38:05 +08:00
|
|
|
; CHECK-NEXT: {{^}} i64.call $push[[NUM:[0-9]+]]=, i64_nullary@FUNCTION{{$}}
|
2015-11-19 00:12:01 +08:00
|
|
|
; CHECK-NEXT: return $pop[[NUM]]{{$}}
|
2015-08-25 06:16:48 +08:00
|
|
|
define i64 @call_i64_nullary() {
|
|
|
|
%r = call i64 @i64_nullary()
|
|
|
|
ret i64 %r
|
|
|
|
}
|
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: call_float_nullary:
|
2015-11-24 00:50:18 +08:00
|
|
|
; CHECK-NEXT: .result f32{{$}}
|
2016-01-12 07:38:05 +08:00
|
|
|
; CHECK-NEXT: {{^}} f32.call $push[[NUM:[0-9]+]]=, float_nullary@FUNCTION{{$}}
|
2015-11-19 00:12:01 +08:00
|
|
|
; CHECK-NEXT: return $pop[[NUM]]{{$}}
|
2015-08-25 06:16:48 +08:00
|
|
|
define float @call_float_nullary() {
|
|
|
|
%r = call float @float_nullary()
|
|
|
|
ret float %r
|
|
|
|
}
|
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: call_double_nullary:
|
2015-11-24 00:50:18 +08:00
|
|
|
; CHECK-NEXT: .result f64{{$}}
|
2016-01-12 07:38:05 +08:00
|
|
|
; CHECK-NEXT: {{^}} f64.call $push[[NUM:[0-9]+]]=, double_nullary@FUNCTION{{$}}
|
2015-11-19 00:12:01 +08:00
|
|
|
; CHECK-NEXT: return $pop[[NUM]]{{$}}
|
2015-08-25 06:16:48 +08:00
|
|
|
define double @call_double_nullary() {
|
|
|
|
%r = call double @double_nullary()
|
|
|
|
ret double %r
|
2015-08-25 05:59:51 +08:00
|
|
|
}
|
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: call_void_nullary:
|
2016-01-12 07:38:05 +08:00
|
|
|
; CHECK-NEXT: {{^}} call void_nullary@FUNCTION{{$}}
|
2015-11-19 00:12:01 +08:00
|
|
|
; CHECK-NEXT: return{{$}}
|
2015-09-10 00:13:47 +08:00
|
|
|
define void @call_void_nullary() {
|
|
|
|
call void @void_nullary()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: call_i32_unary:
|
2015-11-24 00:50:18 +08:00
|
|
|
; CHECK-NEXT: .param i32{{$}}
|
|
|
|
; CHECK-NEXT: .result i32{{$}}
|
2017-02-25 07:18:00 +08:00
|
|
|
; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
|
|
|
|
; CHECK-NEXT: {{^}} i32.call $push[[NUM:[0-9]+]]=, i32_unary@FUNCTION, $pop[[L0]]{{$}}
|
2015-11-19 00:12:01 +08:00
|
|
|
; CHECK-NEXT: return $pop[[NUM]]{{$}}
|
2015-08-25 06:16:48 +08:00
|
|
|
define i32 @call_i32_unary(i32 %a) {
|
|
|
|
%r = call i32 @i32_unary(i32 %a)
|
|
|
|
ret i32 %r
|
|
|
|
}
|
2015-08-25 05:59:51 +08:00
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: call_i32_binary:
|
2015-11-24 00:50:18 +08:00
|
|
|
; CHECK-NEXT: .param i32, i32{{$}}
|
|
|
|
; CHECK-NEXT: .result i32{{$}}
|
2017-02-25 07:18:00 +08:00
|
|
|
; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
|
|
|
|
; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
|
|
|
|
; CHECK-NEXT: {{^}} i32.call $push[[NUM:[0-9]+]]=, i32_binary@FUNCTION, $pop[[L0]], $pop[[L1]]{{$}}
|
2015-11-19 00:12:01 +08:00
|
|
|
; CHECK-NEXT: return $pop[[NUM]]{{$}}
|
2015-09-09 09:52:45 +08:00
|
|
|
define i32 @call_i32_binary(i32 %a, i32 %b) {
|
|
|
|
%r = call i32 @i32_binary(i32 %a, i32 %b)
|
|
|
|
ret i32 %r
|
|
|
|
}
|
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: call_indirect_void:
|
2015-11-24 00:50:18 +08:00
|
|
|
; CHECK-NEXT: .param i32{{$}}
|
2017-02-25 07:18:00 +08:00
|
|
|
; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
|
|
|
|
; CHECK-NEXT: {{^}} call_indirect $pop[[L0]]{{$}}
|
2015-11-19 00:12:01 +08:00
|
|
|
; CHECK-NEXT: return{{$}}
|
2015-09-29 00:22:39 +08:00
|
|
|
define void @call_indirect_void(void ()* %callee) {
|
|
|
|
call void %callee()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: call_indirect_i32:
|
2015-11-24 00:50:18 +08:00
|
|
|
; CHECK-NEXT: .param i32{{$}}
|
|
|
|
; CHECK-NEXT: .result i32{{$}}
|
2017-02-25 07:18:00 +08:00
|
|
|
; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
|
|
|
|
; CHECK-NEXT: {{^}} i32.call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]]{{$}}
|
2015-11-19 00:12:01 +08:00
|
|
|
; CHECK-NEXT: return $pop[[NUM]]{{$}}
|
2015-09-29 00:22:39 +08:00
|
|
|
define i32 @call_indirect_i32(i32 ()* %callee) {
|
|
|
|
%t = call i32 %callee()
|
|
|
|
ret i32 %t
|
|
|
|
}
|
|
|
|
|
2016-10-22 00:38:07 +08:00
|
|
|
; CHECK-LABEL: call_indirect_arg:
|
|
|
|
; CHECK-NEXT: .param i32, i32{{$}}
|
2017-02-25 07:18:00 +08:00
|
|
|
; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 1{{$}}
|
|
|
|
; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 0{{$}}
|
|
|
|
; CHECK-NEXT: {{^}} call_indirect $pop[[L0]], $pop[[L1]]{{$}}
|
2016-10-22 00:38:07 +08:00
|
|
|
; CHECK-NEXT: return{{$}}
|
|
|
|
define void @call_indirect_arg(void (i32)* %callee, i32 %arg) {
|
|
|
|
call void %callee(i32 %arg)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: call_indirect_arg_2:
|
|
|
|
; CHECK-NEXT: .param i32, i32, i32{{$}}
|
2017-02-25 07:18:00 +08:00
|
|
|
; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 1{{$}}
|
|
|
|
; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 2{{$}}
|
|
|
|
; CHECK-NEXT: get_local $push[[L2:[0-9]+]]=, 0{{$}}
|
|
|
|
; CHECK-NEXT: {{^}} i32.call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $pop[[L2]]{{$}}
|
|
|
|
; CHECK-NEXT: drop $pop[[NUM]]{{$}}
|
2016-10-22 00:38:07 +08:00
|
|
|
; CHECK-NEXT: return{{$}}
|
|
|
|
define void @call_indirect_arg_2(i32 (i32, i32)* %callee, i32 %arg, i32 %arg2) {
|
|
|
|
call i32 %callee(i32 %arg, i32 %arg2)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: tail_call_void_nullary:
|
2016-01-12 07:38:05 +08:00
|
|
|
; CHECK-NEXT: {{^}} call void_nullary@FUNCTION{{$}}
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-NEXT: return{{$}}
|
2015-10-03 04:54:23 +08:00
|
|
|
define void @tail_call_void_nullary() {
|
|
|
|
tail call void @void_nullary()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: fastcc_tail_call_void_nullary:
|
2016-01-12 07:38:05 +08:00
|
|
|
; CHECK-NEXT: {{^}} call void_nullary@FUNCTION{{$}}
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-NEXT: return{{$}}
|
2015-10-03 04:54:23 +08:00
|
|
|
define void @fastcc_tail_call_void_nullary() {
|
|
|
|
tail call fastcc void @void_nullary()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-LABEL: coldcc_tail_call_void_nullary:
|
2016-01-12 07:38:05 +08:00
|
|
|
; CHECK-NEXT: {{^}} call void_nullary@FUNCTION{{$}}
|
2015-10-06 08:27:55 +08:00
|
|
|
; CHECK-NEXT: return{{$}}
|
2015-10-03 04:54:23 +08:00
|
|
|
define void @coldcc_tail_call_void_nullary() {
|
|
|
|
tail call coldcc void @void_nullary()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2017-08-25 03:53:44 +08:00
|
|
|
; CHECK-LABEL: call_constexpr:
|
|
|
|
; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 2{{$}}
|
|
|
|
; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 3{{$}}
|
2017-12-09 05:27:00 +08:00
|
|
|
; CHECK-NEXT: call .Lbitcast@FUNCTION, $pop[[L0]], $pop[[L1]]{{$}}
|
2017-08-25 03:53:44 +08:00
|
|
|
; CHECK-NEXT: call other_void_nullary@FUNCTION{{$}}
|
|
|
|
; CHECK-NEXT: call void_nullary@FUNCTION{{$}}
|
|
|
|
; CHECK-NEXT: return{{$}}
|
|
|
|
declare void @vararg_func(...)
|
|
|
|
declare void @other_void_nullary()
|
|
|
|
define void @call_constexpr() {
|
|
|
|
bb0:
|
|
|
|
call void bitcast (void (...)* @vararg_func to void (i32, i32)*)(i32 2, i32 3)
|
|
|
|
br label %bb1
|
|
|
|
bb1:
|
|
|
|
call void select (i1 0, void ()* @void_nullary, void ()* @other_void_nullary)()
|
|
|
|
br label %bb2
|
|
|
|
bb2:
|
|
|
|
call void inttoptr (i32 ptrtoint (void ()* @void_nullary to i32) to void ()*)()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-01-20 00:52:50 +08:00
|
|
|
; TODO: test the following:
|
2015-08-25 06:16:48 +08:00
|
|
|
; - More argument combinations.
|
|
|
|
; - Tail call.
|
|
|
|
; - Interesting returns (struct, multiple).
|
|
|
|
; - Vararg.
|