Skip to content

Commit 7448451

Browse files
authored
[wasm-split] Support --placeholder-namespace for multi-split (WebAssembly#7968)
1 parent 4dcade8 commit 7448451

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

src/tools/wasm-split/split-options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ WasmSplitOptions::WasmSplitOptions()
241241
"The namespace from which to import placeholder functions into "
242242
"the primary module.",
243243
WasmSplitOption,
244-
{Mode::Split},
244+
{Mode::Split, Mode::MultiSplit},
245245
Options::Arguments::One,
246246
[&](Options* o, const std::string& argument) {
247247
placeholderNamespace = argument;

src/tools/wasm-split/wasm-split.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ void setCommonSplitConfigs(ModuleSplitting::Config& config,
232232
if (options.exportPrefix.size()) {
233233
config.newExportPrefix = options.exportPrefix;
234234
}
235-
// TODO Add more configs here
235+
if (options.placeholderNamespace.size()) {
236+
config.placeholderNamespace = options.placeholderNamespace;
237+
}
236238
}
237239

238240
void splitModule(const WasmSplitOptions& options) {
@@ -344,9 +346,6 @@ void splitModule(const WasmSplitOptions& options) {
344346
ModuleSplitting::Config config;
345347
setCommonSplitConfigs(config, options);
346348
config.secondaryFuncs.push_back(std::move(splitFuncs));
347-
if (options.placeholderNamespace.size()) {
348-
config.placeholderNamespace = options.placeholderNamespace;
349-
}
350349
config.jspi = options.jspi;
351350
auto splitResults = ModuleSplitting::splitFunctions(wasm, config);
352351
auto& secondary = *splitResults.secondaries.begin();

test/lit/help/wasm-split.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@
8484
;; CHECK-NEXT: mode, refers to the namespace from which
8585
;; CHECK-NEXT: to import the secondary memory, if any.
8686
;; CHECK-NEXT:
87-
;; CHECK-NEXT: --placeholder-namespace [split] The namespace from which to
88-
;; CHECK-NEXT: import placeholder functions into the
89-
;; CHECK-NEXT: primary module.
87+
;; CHECK-NEXT: --placeholder-namespace [split, multi-split] The namespace from
88+
;; CHECK-NEXT: which to import placeholder functions
89+
;; CHECK-NEXT: into the primary module.
9090
;; CHECK-NEXT:
9191
;; CHECK-NEXT: --jspi [split] Transform the module to support
9292
;; CHECK-NEXT: asynchronously loading the secondary

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
;; RUN: wasm-dis %t2.wasm | filecheck %s --check-prefix=MOD2-OPTIONS
1515
;; RUN: wasm-dis %t3.wasm | filecheck %s --check-prefix=MOD3-OPTIONS
1616

17+
;; Check if --placeholder-namespace option works.
18+
;; work.
19+
;; RUN: wasm-split -all -g --multi-split %s --manifest %s.manifest --out-prefix=%t --placeholder-namespace=placeholder_env -o %t.wasm
20+
;; RUN: wasm-dis %t.wasm | filecheck %s --check-prefix=PRIMARY-PLACEHOLDER-NAMESPACE
21+
1722
(module
1823
;; PRIMARY: (type $ret-i64 (func (result i64)))
1924

@@ -25,6 +30,11 @@
2530
;; PRIMARY-OPTIONS: (type $ret-f32 (func (result f32)))
2631

2732
;; PRIMARY-OPTIONS: (type $ret-i32 (func (result i32)))
33+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (type $ret-i64 (func (result i64)))
34+
35+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (type $ret-f32 (func (result f32)))
36+
37+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (type $ret-i32 (func (result i32)))
2838
(type $ret-i32 (func (result i32)))
2939
(type $ret-i64 (func (result i64)))
3040
(type $ret-f32 (func (result f32)))
@@ -343,3 +353,39 @@
343353
;; PRIMARY-OPTIONS-NEXT: (i32.const 2)
344354
;; PRIMARY-OPTIONS-NEXT: )
345355
;; PRIMARY-OPTIONS-NEXT: )
356+
357+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (import "placeholder_env" "0" (func $placeholder_0 (result i64)))
358+
359+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (import "placeholder_env" "1" (func $placeholder_1 (result f32)))
360+
361+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (import "placeholder_env" "2" (func $placeholder_2 (result i32)))
362+
363+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (table $0 3 funcref)
364+
365+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (elem $0 (i32.const 0) $placeholder_0 $placeholder_1 $placeholder_2)
366+
367+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (export "trampoline_B" (func $trampoline_B))
368+
369+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (export "trampoline_C" (func $trampoline_C))
370+
371+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (export "trampoline_A" (func $trampoline_A))
372+
373+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (export "table" (table $0))
374+
375+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (func $trampoline_B (result i64)
376+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: (call_indirect (type $ret-i64)
377+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: (i32.const 0)
378+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: )
379+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: )
380+
381+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (func $trampoline_C (result f32)
382+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: (call_indirect (type $ret-f32)
383+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: (i32.const 1)
384+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: )
385+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: )
386+
387+
;; PRIMARY-PLACEHOLDER-NAMESPACE: (func $trampoline_A (result i32)
388+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: (call_indirect (type $ret-i32)
389+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: (i32.const 2)
390+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: )
391+
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: )

0 commit comments

Comments
 (0)