Skip to content

Commit 31c4bdf

Browse files
authored
[CustomDescriptors] GUFA: Respect configureAll (WebAssembly#8242)
Functions in configureAll are called from outside even in closed world.
1 parent 86a01a1 commit 31c4bdf

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

src/ir/possible-contents.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,11 @@ Flower::Flower(Module& wasm, const PassOptions& options)
24542454
}
24552455
}
24562456

2457+
// configureAll functions are called from outside the module, as if exported.
2458+
for (auto func : Intrinsics(wasm).getConfigureAllFunctions()) {
2459+
calledFromOutside.insert(func);
2460+
}
2461+
24572462
// Apply changes to all functions called from outside.
24582463
for (auto funcName : calledFromOutside) {
24592464
auto* func = wasm.getFunction(funcName);
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
3+
;; RUN: foreach %s %t wasm-opt --gufa --closed-world -all -S -o - | filecheck %s
4+
5+
;; Test that configureAll is respected: referred functions are assumed to be
6+
;; called from outside the module, depsite closed world.
7+
8+
(module
9+
;; CHECK: (type $externs (array (mut externref)))
10+
(type $externs (array (mut externref)))
11+
12+
;; CHECK: (type $funcs (array (mut funcref)))
13+
(type $funcs (array (mut funcref)))
14+
15+
;; CHECK: (type $bytes (array (mut i8)))
16+
(type $bytes (array (mut i8)))
17+
18+
;; CHECK: (type $3 (func (param i32) (result i32)))
19+
20+
;; CHECK: (type $configureAll (func (param (ref null $externs) (ref null $funcs) (ref null $bytes) externref)))
21+
(type $configureAll (func (param (ref null $externs)) (param (ref null $funcs)) (param (ref null $bytes)) (param externref)))
22+
23+
;; CHECK: (type $5 (func))
24+
25+
;; CHECK: (import "wasm:js-prototypes" "configureAll" (func $configureAll (type $configureAll) (param (ref null $externs) (ref null $funcs) (ref null $bytes) externref)))
26+
(import "wasm:js-prototypes" "configureAll" (func $configureAll (type $configureAll)))
27+
28+
;; CHECK: (data $bytes "12345678")
29+
(data $bytes "12345678")
30+
31+
;; CHECK: (elem $externs externref (item (ref.null noextern)))
32+
(elem $externs externref
33+
(ref.null extern)
34+
)
35+
36+
;; CHECK: (elem $funcs func $configured)
37+
(elem $funcs funcref
38+
(ref.func $configured)
39+
)
40+
41+
;; CHECK: (elem $other func $unconfigured)
42+
(elem $other funcref
43+
(ref.func $unconfigured)
44+
)
45+
46+
;; CHECK: (start $start)
47+
(start $start)
48+
49+
;; CHECK: (func $start (type $5)
50+
;; CHECK-NEXT: (call $configureAll
51+
;; CHECK-NEXT: (array.new_elem $externs $externs
52+
;; CHECK-NEXT: (i32.const 0)
53+
;; CHECK-NEXT: (i32.const 1)
54+
;; CHECK-NEXT: )
55+
;; CHECK-NEXT: (array.new_elem $funcs $funcs
56+
;; CHECK-NEXT: (i32.const 0)
57+
;; CHECK-NEXT: (i32.const 1)
58+
;; CHECK-NEXT: )
59+
;; CHECK-NEXT: (array.new_data $bytes $bytes
60+
;; CHECK-NEXT: (i32.const 0)
61+
;; CHECK-NEXT: (i32.const 8)
62+
;; CHECK-NEXT: )
63+
;; CHECK-NEXT: (ref.null noextern)
64+
;; CHECK-NEXT: )
65+
;; CHECK-NEXT: )
66+
(func $start
67+
(call $configureAll
68+
(array.new_elem $externs $externs
69+
(i32.const 0) (i32.const 1))
70+
(array.new_elem $funcs $funcs
71+
(i32.const 0) (i32.const 1))
72+
(array.new_data $bytes $bytes
73+
(i32.const 0) (i32.const 8))
74+
(ref.null extern)
75+
)
76+
)
77+
78+
;; CHECK: (func $configured (type $3) (param $x i32) (result i32)
79+
;; CHECK-NEXT: (i32.eqz
80+
;; CHECK-NEXT: (local.get $x)
81+
;; CHECK-NEXT: )
82+
;; CHECK-NEXT: )
83+
(func $configured (param $x i32) (result i32)
84+
;; The call from outside the module, through configureAll, is the only call
85+
;; we have - without it, this would be unreachable code, and optimized away.
86+
(i32.eqz
87+
(local.get $x)
88+
)
89+
)
90+
91+
;; CHECK: (func $unconfigured (type $3) (param $x i32) (result i32)
92+
;; CHECK-NEXT: (i32.eqz
93+
;; CHECK-NEXT: (unreachable)
94+
;; CHECK-NEXT: )
95+
;; CHECK-NEXT: )
96+
(func $unconfigured (param $x i32) (result i32)
97+
;; As above, but *not* in configureAll (though it is in a table, so it is
98+
;; not entirely removed) - so we do optimize.
99+
(i32.eqz
100+
(local.get $x)
101+
)
102+
)
103+
)

0 commit comments

Comments
 (0)