summaryrefslogtreecommitdiff
path: root/test/lit/passes/inlining_all-features.wast
blob: 860f5b8f75f398635137533742ecdf1e06c90dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: foreach %s %t wasm-opt --inlining --all-features -S -o - | filecheck %s

(module
  ;; CHECK:      (type $0 (func))

  ;; CHECK:      (type $1 (func (result funcref)))

  ;; CHECK:      (elem declare func $foo)

  ;; CHECK:      (export "ref_func_test" (func $ref_func_test))
  (export "ref_func_test" (func $ref_func_test))

  ;; $foo should not be removed after being inlined, because there is 'ref.func'
  ;; instruction that refers to it
  ;; CHECK:      (func $foo (type $0)
  ;; CHECK-NEXT: )
  (func $foo)

  ;; CHECK:      (func $ref_func_test (type $1) (result funcref)
  ;; CHECK-NEXT:  (block $__inlined_func$foo
  ;; CHECK-NEXT:   (block
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (ref.func $foo)
  ;; CHECK-NEXT: )
  (func $ref_func_test (result funcref)
    (call $foo)
    (ref.func $foo)
  )
)

(module
 ;; a function reference in a global's init should be noticed, and prevent us
 ;; from removing an inlined function

 ;; CHECK:      (type $0 (func (result i32)))

 ;; CHECK:      (global $global$0 (mut funcref) (ref.func $0))
 (global $global$0 (mut funcref) (ref.func $0))

 ;; CHECK:      (func $0 (type $0) (result i32)
 ;; CHECK-NEXT:  (i32.const 1337)
 ;; CHECK-NEXT: )
 (func $0 (result i32)
  (i32.const 1337)
 )

 ;; CHECK:      (func $1 (type $0) (result i32)
 ;; CHECK-NEXT:  (block $__inlined_func$0 (result i32)
 ;; CHECK-NEXT:   (i32.const 1337)
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT: )
 (func $1 (result i32)
  (call $0)
 )
)

(module
 ;; a function reference in the start should be noticed, and prevent us
 ;; from removing an inlined function

 ;; CHECK:      (type $0 (func))

 ;; CHECK:      (start $0)
 (start $0)

 ;; CHECK:      (func $0 (type $0)
 ;; CHECK-NEXT:  (nop)
 ;; CHECK-NEXT: )
 (func $0
  (nop)
 )

 ;; CHECK:      (func $1 (type $0)
 ;; CHECK-NEXT:  (block $__inlined_func$0
 ;; CHECK-NEXT:   (nop)
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT: )
 (func $1
  (call $0)
 )
)

;; inline a return_call_ref
(module
 ;; CHECK:      (type $none_=>_none (func))
 (type $none_=>_none (func))

 ;; CHECK:      (export "func_36_invoker" (func $1))
 (export "func_36_invoker" (func $1))

 (func $0
  (return_call_ref $none_=>_none
   (ref.null $none_=>_none)
  )
 )
 ;; CHECK:      (func $1 (type $none_=>_none)
 ;; CHECK-NEXT:  (block $__inlined_func$0
 ;; CHECK-NEXT:   (block ;; (replaces unreachable CallRef we can't emit)
 ;; CHECK-NEXT:    (drop
 ;; CHECK-NEXT:     (ref.null nofunc)
 ;; CHECK-NEXT:    )
 ;; CHECK-NEXT:    (unreachable)
 ;; CHECK-NEXT:   )
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT: )
 (func $1
  (call $0)
 )
)

;; handle non-nullable parameter types (which turn into local types after
;; inlining)
(module
 (func $0 (param $non-null (ref func)) (result (ref func))
  (local.get $non-null)
 )

 ;; CHECK:      (type $0 (func (result (ref func))))

 ;; CHECK:      (elem declare func $1)

 ;; CHECK:      (func $1 (type $0) (result (ref func))
 ;; CHECK-NEXT:  (local $0 (ref func))
 ;; CHECK-NEXT:  (block $__inlined_func$0 (result (ref func))
 ;; CHECK-NEXT:   (local.set $0
 ;; CHECK-NEXT:    (ref.func $1)
 ;; CHECK-NEXT:   )
 ;; CHECK-NEXT:   (local.get $0)
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT: )
 (func $1 (result (ref func))
  (call $0
   (ref.func $1)
  )
 )
)

;; Test handling of nested inlined calls.
(module
 (func $callee-a (param i32))

 (func $callee-b (param $x i32) (result i32)
  (local.get $x)
 )

 ;; CHECK:      (type $0 (func))

 ;; CHECK:      (func $caller-with-pop-twice (type $0)
 ;; CHECK-NEXT:  (local $0 i32)
 ;; CHECK-NEXT:  (local $1 i32)
 ;; CHECK-NEXT:  (block $__inlined_func$callee-a$1
 ;; CHECK-NEXT:   (local.set $1
 ;; CHECK-NEXT:    (block $__inlined_func$callee-b (result i32)
 ;; CHECK-NEXT:     (local.set $0
 ;; CHECK-NEXT:      (i32.const 42)
 ;; CHECK-NEXT:     )
 ;; CHECK-NEXT:     (local.get $0)
 ;; CHECK-NEXT:    )
 ;; CHECK-NEXT:   )
 ;; CHECK-NEXT:   (block
 ;; CHECK-NEXT:   )
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT: )
 (func $caller-with-pop-twice
  ;; Both these calls should be inlined.
  (call $callee-a
   (call $callee-b
    (i32.const 42)
   )
  )
 )
)