Skip to content

Commit 12f88e3

Browse files
authored
[wasm-split] Preserve explicit names for trampolines (#7805)
1 parent 96a5a0c commit 12f88e3

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

src/ir/module-splitting.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,9 @@ void ModuleSplitter::indirectReferencesToSecondaryFunctions() {
625625
}
626626
auto* call = builder.makeCall(name, args, oldFunc->getResults());
627627

628-
primary.addFunction(builder.makeFunction(newName, oldFunc->type, {}, call));
628+
auto trampoline = builder.makeFunction(newName, oldFunc->type, {}, call);
629+
trampoline->hasExplicitName = oldFunc->hasExplicitName;
630+
primary.addFunction(std::move(trampoline));
629631

630632
// Update RefFuncs to refer to it.
631633
for (auto* refFunc : relevantRefFuncs) {

test/lit/wasm-split/multi-split.wast

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,16 @@
123123

124124
;; MOD2: (import "" "C" (func $C (type $0) (result f32)))
125125

126-
;; MOD2: (import "" "trampoline_A" (func $fimport$1 (type $1) (result i32)))
126+
;; MOD2: (import "" "trampoline_A" (func $trampoline_A (type $1) (result i32)))
127127

128128
;; MOD2: (elem $0 (i32.const 0) $B)
129129

130-
;; MOD2: (elem declare func $C $fimport$1)
130+
;; MOD2: (elem declare func $C $trampoline_A)
131131

132132
;; MOD2: (func $B (type $2) (result i64)
133133
;; MOD2-NEXT: (drop
134134
;; MOD2-NEXT: (call_ref $1
135-
;; MOD2-NEXT: (ref.func $fimport$1)
135+
;; MOD2-NEXT: (ref.func $trampoline_A)
136136
;; MOD2-NEXT: )
137137
;; MOD2-NEXT: )
138138
;; MOD2-NEXT: (drop
@@ -157,16 +157,16 @@
157157

158158
;; MOD2-OPTIONS: (import "custom_env" "C" (func $C (type $0) (result f32)))
159159

160-
;; MOD2-OPTIONS: (import "custom_env" "trampoline_A" (func $fimport$1 (type $1) (result i32)))
160+
;; MOD2-OPTIONS: (import "custom_env" "trampoline_A" (func $trampoline_A (type $1) (result i32)))
161161

162162
;; MOD2-OPTIONS: (elem $0 (i32.const 0) $B)
163163

164-
;; MOD2-OPTIONS: (elem declare func $C $fimport$1)
164+
;; MOD2-OPTIONS: (elem declare func $C $trampoline_A)
165165

166166
;; MOD2-OPTIONS: (func $B (type $2) (result i64)
167167
;; MOD2-OPTIONS-NEXT: (drop
168168
;; MOD2-OPTIONS-NEXT: (call_ref $1
169-
;; MOD2-OPTIONS-NEXT: (ref.func $fimport$1)
169+
;; MOD2-OPTIONS-NEXT: (ref.func $trampoline_A)
170170
;; MOD2-OPTIONS-NEXT: )
171171
;; MOD2-OPTIONS-NEXT: )
172172
;; MOD2-OPTIONS-NEXT: (drop
@@ -208,23 +208,23 @@
208208

209209
;; MOD3: (import "" "table_6" (table $timport$0 1 funcref))
210210

211-
;; MOD3: (import "" "trampoline_A" (func $fimport$0 (type $0) (result i32)))
211+
;; MOD3: (import "" "trampoline_A" (func $trampoline_A (type $0) (result i32)))
212212

213-
;; MOD3: (import "" "trampoline_B" (func $fimport$1 (type $1) (result i64)))
213+
;; MOD3: (import "" "trampoline_B" (func $trampoline_B (type $1) (result i64)))
214214

215215
;; MOD3: (elem $0 (i32.const 0) $C)
216216

217-
;; MOD3: (elem declare func $fimport$0 $fimport$1)
217+
;; MOD3: (elem declare func $trampoline_A $trampoline_B)
218218

219219
;; MOD3: (func $C (type $2) (result f32)
220220
;; MOD3-NEXT: (drop
221221
;; MOD3-NEXT: (call_ref $0
222-
;; MOD3-NEXT: (ref.func $fimport$0)
222+
;; MOD3-NEXT: (ref.func $trampoline_A)
223223
;; MOD3-NEXT: )
224224
;; MOD3-NEXT: )
225225
;; MOD3-NEXT: (drop
226226
;; MOD3-NEXT: (call_ref $1
227-
;; MOD3-NEXT: (ref.func $fimport$1)
227+
;; MOD3-NEXT: (ref.func $trampoline_B)
228228
;; MOD3-NEXT: )
229229
;; MOD3-NEXT: )
230230
;; MOD3-NEXT: (drop
@@ -242,23 +242,23 @@
242242

243243
;; MOD3-OPTIONS: (import "custom_env" "table_6" (table $timport$0 1 funcref))
244244

245-
;; MOD3-OPTIONS: (import "custom_env" "trampoline_A" (func $fimport$0 (type $0) (result i32)))
245+
;; MOD3-OPTIONS: (import "custom_env" "trampoline_A" (func $trampoline_A (type $0) (result i32)))
246246

247-
;; MOD3-OPTIONS: (import "custom_env" "trampoline_B" (func $fimport$1 (type $1) (result i64)))
247+
;; MOD3-OPTIONS: (import "custom_env" "trampoline_B" (func $trampoline_B (type $1) (result i64)))
248248

249249
;; MOD3-OPTIONS: (elem $0 (i32.const 0) $C)
250250

251-
;; MOD3-OPTIONS: (elem declare func $fimport$0 $fimport$1)
251+
;; MOD3-OPTIONS: (elem declare func $trampoline_A $trampoline_B)
252252

253253
;; MOD3-OPTIONS: (func $C (type $2) (result f32)
254254
;; MOD3-OPTIONS-NEXT: (drop
255255
;; MOD3-OPTIONS-NEXT: (call_ref $0
256-
;; MOD3-OPTIONS-NEXT: (ref.func $fimport$0)
256+
;; MOD3-OPTIONS-NEXT: (ref.func $trampoline_A)
257257
;; MOD3-OPTIONS-NEXT: )
258258
;; MOD3-OPTIONS-NEXT: )
259259
;; MOD3-OPTIONS-NEXT: (drop
260260
;; MOD3-OPTIONS-NEXT: (call_ref $1
261-
;; MOD3-OPTIONS-NEXT: (ref.func $fimport$1)
261+
;; MOD3-OPTIONS-NEXT: (ref.func $trampoline_B)
262262
;; MOD3-OPTIONS-NEXT: )
263263
;; MOD3-OPTIONS-NEXT: )
264264
;; MOD3-OPTIONS-NEXT: (drop
@@ -311,15 +311,15 @@
311311

312312
;; PRIMARY: (export "table" (table $0))
313313

314-
;; PRIMARY: (export "trampoline_A" (func $0))
314+
;; PRIMARY: (export "trampoline_A" (func $trampoline_A))
315315

316316
;; PRIMARY: (export "table_4" (table $1))
317317

318-
;; PRIMARY: (export "trampoline_B" (func $2))
318+
;; PRIMARY: (export "trampoline_B" (func $trampoline_B))
319319

320320
;; PRIMARY: (export "table_6" (table $2))
321321

322-
;; PRIMARY: (func $0 (type $ret-i32) (result i32)
322+
;; PRIMARY: (func $trampoline_A (type $ret-i32) (result i32)
323323
;; PRIMARY-NEXT: (call_indirect $0 (type $ret-i32)
324324
;; PRIMARY-NEXT: (i32.const 0)
325325
;; PRIMARY-NEXT: )
@@ -331,7 +331,7 @@
331331
;; PRIMARY-NEXT: )
332332
;; PRIMARY-NEXT: )
333333

334-
;; PRIMARY: (func $2 (type $ret-i64) (result i64)
334+
;; PRIMARY: (func $trampoline_B (type $ret-i64) (result i64)
335335
;; PRIMARY-NEXT: (call_indirect $1 (type $ret-i64)
336336
;; PRIMARY-NEXT: (i32.const 0)
337337
;; PRIMARY-NEXT: )
@@ -361,15 +361,15 @@
361361

362362
;; PRIMARY-OPTIONS: (export "table" (table $0))
363363

364-
;; PRIMARY-OPTIONS: (export "trampoline_A" (func $0))
364+
;; PRIMARY-OPTIONS: (export "trampoline_A" (func $trampoline_A))
365365

366366
;; PRIMARY-OPTIONS: (export "table_4" (table $1))
367367

368-
;; PRIMARY-OPTIONS: (export "trampoline_B" (func $2))
368+
;; PRIMARY-OPTIONS: (export "trampoline_B" (func $trampoline_B))
369369

370370
;; PRIMARY-OPTIONS: (export "table_6" (table $2))
371371

372-
;; PRIMARY-OPTIONS: (func $0 (type $ret-i32) (result i32)
372+
;; PRIMARY-OPTIONS: (func $trampoline_A (type $ret-i32) (result i32)
373373
;; PRIMARY-OPTIONS-NEXT: (call_indirect $0 (type $ret-i32)
374374
;; PRIMARY-OPTIONS-NEXT: (i32.const 0)
375375
;; PRIMARY-OPTIONS-NEXT: )
@@ -381,7 +381,7 @@
381381
;; PRIMARY-OPTIONS-NEXT: )
382382
;; PRIMARY-OPTIONS-NEXT: )
383383

384-
;; PRIMARY-OPTIONS: (func $2 (type $ret-i64) (result i64)
384+
;; PRIMARY-OPTIONS: (func $trampoline_B (type $ret-i64) (result i64)
385385
;; PRIMARY-OPTIONS-NEXT: (call_indirect $1 (type $ret-i64)
386386
;; PRIMARY-OPTIONS-NEXT: (i32.const 0)
387387
;; PRIMARY-OPTIONS-NEXT: )

test/lit/wasm-split/passive.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
;; PRIMARY: (table $1 1 funcref)
1818

19-
;; PRIMARY: (elem $passive func $in-table $1)
19+
;; PRIMARY: (elem $passive func $in-table $trampoline_second-in-table)
2020
(elem $passive func $in-table $second-in-table)
2121

2222
;; PRIMARY: (elem $1 (table $1) (i32.const 0) func $placeholder_0)
@@ -45,7 +45,7 @@
4545
;; handle it by adding a trampoline from the segment as a new function "$1".
4646
)
4747
)
48-
;; PRIMARY: (func $1 (type $0)
48+
;; PRIMARY: (func $trampoline_second-in-table (type $0)
4949
;; PRIMARY-NEXT: (call_indirect $1 (type $0)
5050
;; PRIMARY-NEXT: (i32.const 0)
5151
;; PRIMARY-NEXT: )

test/lit/wasm-split/ref.func.wast

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
;; PRIMARY: (global $glob1 (ref func) (ref.func $prime))
1818

19-
;; PRIMARY: (global $glob2 (ref func) (ref.func $2))
19+
;; PRIMARY: (global $glob2 (ref func) (ref.func $trampoline_second))
2020

2121
;; PRIMARY: (table $table 1 1 funcref)
2222
(table $table 1 1 funcref)
@@ -27,12 +27,12 @@
2727

2828
;; PRIMARY: (table $1 2 funcref)
2929

30-
;; PRIMARY: (elem $elem (table $table) (i32.const 0) func $in-table $3)
30+
;; PRIMARY: (elem $elem (table $table) (i32.const 0) func $in-table $trampoline_second-in-table)
3131
(elem $elem (i32.const 0) $in-table $second-in-table)
3232

3333
;; PRIMARY: (elem $1 (table $1) (i32.const 0) func $placeholder_0 $placeholder_1)
3434

35-
;; PRIMARY: (elem declare func $2 $prime)
35+
;; PRIMARY: (elem declare func $prime $trampoline_second)
3636

3737
;; PRIMARY: (export "prime" (func $prime))
3838

@@ -49,7 +49,7 @@
4949
;; PRIMARY-NEXT: (ref.func $prime)
5050
;; PRIMARY-NEXT: )
5151
;; PRIMARY-NEXT: (drop
52-
;; PRIMARY-NEXT: (ref.func $2)
52+
;; PRIMARY-NEXT: (ref.func $trampoline_second)
5353
;; PRIMARY-NEXT: )
5454
;; PRIMARY-NEXT: )
5555
(func $prime
@@ -103,13 +103,13 @@
103103
;; (but we will get a placeholder, as all split-out functions do).
104104
)
105105
)
106-
;; PRIMARY: (func $2 (type $0)
106+
;; PRIMARY: (func $trampoline_second (type $0)
107107
;; PRIMARY-NEXT: (call_indirect $1 (type $0)
108108
;; PRIMARY-NEXT: (i32.const 0)
109109
;; PRIMARY-NEXT: )
110110
;; PRIMARY-NEXT: )
111111

112-
;; PRIMARY: (func $3 (type $0)
112+
;; PRIMARY: (func $trampoline_second-in-table (type $0)
113113
;; PRIMARY-NEXT: (call_indirect $1 (type $0)
114114
;; PRIMARY-NEXT: (i32.const 1)
115115
;; PRIMARY-NEXT: )

0 commit comments

Comments
 (0)