Home | History | Annotate | Download | only in WebAssembly
      1 ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs | FileCheck %s
      2 
      3 ; Test varargs constructs.
      4 
      5 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
      6 target triple = "wasm32-unknown-unknown"
      7 
      8 ; Test va_start.
      9 
     10 ; TODO: Test va_start.
     11 
     12 ;define void @start(i8** %ap, ...) {
     13 ;entry:
     14 ;  %0 = bitcast i8** %ap to i8*
     15 ;  call void @llvm.va_start(i8* %0)
     16 ;  ret void
     17 ;}
     18 
     19 ; Test va_end.
     20 
     21 ; CHECK-LABEL: end:
     22 ; CHECK-NEXT: .param i32{{$}}
     23 ; CHECK-NEXT: return{{$}}
     24 define void @end(i8** %ap) {
     25 entry:
     26   %0 = bitcast i8** %ap to i8*
     27   call void @llvm.va_end(i8* %0)
     28   ret void
     29 }
     30 
     31 ; Test va_copy.
     32 
     33 ; CHECK-LABEL: copy:
     34 ; CHECK-NEXT: .param i32, i32{{$}}
     35 ; CHECK-NEXT: i32.load  $push0=, 0($1){{$}}
     36 ; CHECK-NEXT: i32.store $discard=, 0($0), $pop0{{$}}
     37 ; CHECK-NEXT: return{{$}}
     38 define void @copy(i8** %ap, i8** %bp) {
     39 entry:
     40   %0 = bitcast i8** %ap to i8*
     41   %1 = bitcast i8** %bp to i8*
     42   call void @llvm.va_copy(i8* %0, i8* %1)
     43   ret void
     44 }
     45 
     46 ; Test va_arg with an i8 argument.
     47 
     48 ; CHECK-LABEL: arg_i8:
     49 ; CHECK-NEXT: .param     i32{{$}}
     50 ; CHECK-NEXT: .result    i32{{$}}
     51 ; CHECK-NEXT: .local     i32{{$}}
     52 ; CHECK-NEXT: i32.load   $1=, 0($0){{$}}
     53 ; CHECK-NEXT: i32.const  $push0=, 4{{$}}
     54 ; CHECK-NEXT: i32.add    $push1=, $1, $pop0{{$}}
     55 ; CHECK-NEXT: i32.store  $discard=, 0($0), $pop1{{$}}
     56 ; CHECK-NEXT: i32.load   $push2=, 0($1){{$}}
     57 ; CHECK-NEXT: return     $pop2{{$}}
     58 define i8 @arg_i8(i8** %ap) {
     59 entry:
     60   %t = va_arg i8** %ap, i8
     61   ret i8 %t
     62 }
     63 
     64 ; Test va_arg with an i32 argument.
     65 
     66 ; CHECK-LABEL: arg_i32:
     67 ; CHECK-NEXT: .param     i32{{$}}
     68 ; CHECK-NEXT: .result    i32{{$}}
     69 ; CHECK-NEXT: .local     i32{{$}}
     70 ; CHECK-NEXT: i32.load   $push0=, 0($0){{$}}
     71 ; CHECK-NEXT: i32.const  $push1=, 3{{$}}
     72 ; CHECK-NEXT: i32.add    $push2=, $pop0, $pop1{{$}}
     73 ; CHECK-NEXT: i32.const  $push3=, -4{{$}}
     74 ; CHECK-NEXT: i32.and    $1=, $pop2, $pop3{{$}}
     75 ; CHECK-NEXT: i32.const  $push4=, 4{{$}}
     76 ; CHECK-NEXT: i32.add    $push5=, $1, $pop4{{$}}
     77 ; CHECK-NEXT: i32.store  $discard=, 0($0), $pop5{{$}}
     78 ; CHECK-NEXT: i32.load   $push6=, 0($1){{$}}
     79 ; CHECK-NEXT: return     $pop6{{$}}
     80 define i32 @arg_i32(i8** %ap) {
     81 entry:
     82   %t = va_arg i8** %ap, i32
     83   ret i32 %t
     84 }
     85 
     86 ; Test va_arg with an i128 argument.
     87 
     88 ; CHECK-LABEL: arg_i128:
     89 ; CHECK-NEXT: .param i32, i32{{$}}
     90 ; CHECK-NEXT: .local
     91 ; CHECK: i32.and
     92 ; CHECK: i64.load
     93 ; CHECK: i64.load
     94 ; CHECK: return{{$}}
     95 define i128 @arg_i128(i8** %ap) {
     96 entry:
     97   %t = va_arg i8** %ap, i128
     98   ret i128 %t
     99 }
    100 
    101 ; Test a varargs call with no actual arguments.
    102 
    103 declare void @callee(...)
    104 
    105 ; CHECK-LABEL: caller_none:
    106 ; CHECK-NEXT: call callee{{$}}
    107 ; CHECK-NEXT: return{{$}}
    108 define void @caller_none() {
    109   call void (...) @callee()
    110   ret void
    111 }
    112 
    113 ; CHECK-LABEL: caller_some
    114 define void @caller_some() {
    115   ; TODO: Fix interaction between register coalescer and reg stackifier,
    116   ; or disable coalescer.
    117   ;call void (...) @callee(i32 0, double 2.0)
    118   ret void
    119 }
    120 
    121 declare void @llvm.va_start(i8*)
    122 declare void @llvm.va_end(i8*)
    123 declare void @llvm.va_copy(i8*, i8*)
    124