diff --git a/src/ir/module-splitting.cpp b/src/ir/module-splitting.cpp index 35408d63c45..834d990b383 100644 --- a/src/ir/module-splitting.cpp +++ b/src/ir/module-splitting.cpp @@ -73,7 +73,6 @@ // from the IR before splitting. // #include "ir/module-splitting.h" -#include "asmjs/shared-constants.h" #include "ir/export-utils.h" #include "ir/find_all.h" #include "ir/module-utils.h" @@ -87,8 +86,6 @@ namespace wasm::ModuleSplitting { namespace { -static const Name LOAD_SECONDARY_STATUS = "load_secondary_module_status"; - template void forEachElement(Module& module, F f) { ModuleUtils::iterActiveElementSegments(module, [&](ElementSegment* segment) { Name base = ""; @@ -328,12 +325,10 @@ struct ModuleSplitter { // Other helpers void exportImportFunction(Name func, const std::set& modules); - Expression* maybeLoadSecondary(Builder& builder, Expression* callIndirect); Name getTrampoline(Name funcName); // Main splitting steps void classifyFunctions(); - void setupJSPI(); void moveSecondaryFunctions(); void thunkExportedSecondaryFunctions(); void indirectReferencesToSecondaryFunctions(); @@ -346,9 +341,6 @@ struct ModuleSplitter { : config(config), primary(primary), tableManager(primary), exportedPrimaryFuncs(initExportedPrimaryFuncs(primary)) { classifyFunctions(); - if (config.jspi) { - setupJSPI(); - } moveSecondaryFunctions(); thunkExportedSecondaryFunctions(); indirectReferencesToSecondaryFunctions(); @@ -359,25 +351,6 @@ struct ModuleSplitter { } }; -void ModuleSplitter::setupJSPI() { - // Add an imported function to load the secondary module. - auto import = Builder::makeFunction( - ModuleSplitting::LOAD_SECONDARY_MODULE, - Type(Signature(Type::none, Type::none), NonNullable, Inexact), - {}); - import->module = ENV; - import->base = ModuleSplitting::LOAD_SECONDARY_MODULE; - primary.addFunction(std::move(import)); - Builder builder(primary); - // Add a global to track whether the secondary module has been loaded yet. - primary.addGlobal(builder.makeGlobal(LOAD_SECONDARY_STATUS, - Type::i32, - builder.makeConst(int32_t(0)), - Builder::Mutable)); - primary.addExport(builder.makeExport( - LOAD_SECONDARY_STATUS, LOAD_SECONDARY_STATUS, ExternalKind::Global)); -} - std::unique_ptr ModuleSplitter::initSecondary(const Module& primary) { // Create the secondary module and copy trivial properties. auto secondary = std::make_unique(); @@ -449,12 +422,7 @@ void ModuleSplitter::classifyFunctions() { configSecondaryFuncs.insert(funcs.begin(), funcs.end()); } for (auto& func : primary.functions) { - // In JSPI mode exported functions cannot be moved to the secondary - // module since that would make them async when they may not have the JSPI - // wrapper. Exported JSPI functions can still benefit from splitting though - // since only the JSPI wrapper stub will remain in the primary module. if (func->imported() || !configSecondaryFuncs.count(func->name) || - (config.jspi && ExportUtils::isExported(primary, *func)) || segmentReferrers.count(func->name)) { primaryFuncs.insert(func->name); } else { @@ -571,20 +539,6 @@ void ModuleSplitter::thunkExportedSecondaryFunctions() { } } -Expression* ModuleSplitter::maybeLoadSecondary(Builder& builder, - Expression* callIndirect) { - if (!config.jspi) { - return callIndirect; - } - // Check if the secondary module is loaded and if it isn't, call the - // function to load it. - auto* loadSecondary = builder.makeIf( - builder.makeUnary(EqZInt32, - builder.makeGlobalGet(LOAD_SECONDARY_STATUS, Type::i32)), - builder.makeCall(ModuleSplitting::LOAD_SECONDARY_MODULE, {}, Type::none)); - return builder.makeSequence(loadSecondary, callIndirect); -} - // Helper to walk expressions in segments but NOT in globals. template static void walkSegments(Walker& walker, Module* module) { @@ -720,13 +674,12 @@ void ModuleSplitter::indirectCallsToSecondaryFunctions() { auto tableSlot = parent.tableManager.getSlot(curr->target, func->type.getHeapType()); - replaceCurrent(parent.maybeLoadSecondary( - builder, + replaceCurrent( builder.makeCallIndirect(tableSlot.tableName, tableSlot.makeExpr(parent.primary), curr->operands, func->type.getHeapType(), - curr->isReturn))); + curr->isReturn)); } }; CallIndirector callIndirector(*this); diff --git a/src/ir/module-splitting.h b/src/ir/module-splitting.h index b7abda19aeb..8260feb6b8d 100644 --- a/src/ir/module-splitting.h +++ b/src/ir/module-splitting.h @@ -48,8 +48,6 @@ namespace wasm::ModuleSplitting { -static const Name LOAD_SECONDARY_MODULE("__load_secondary_module"); - struct Config { // A vector of set of functions to split into that secondary. Each function // set belongs to a single secondary module. All others are kept in the @@ -77,9 +75,6 @@ struct Config { // false, the original function names will be used (after `newExportPrefix`) // as the new export names. bool minimizeNewExportNames = false; - // When JSPI support is enabled the secondary module loading is handled by an - // imported function. - bool jspi = false; }; struct Results { diff --git a/src/tools/wasm-split/split-options.cpp b/src/tools/wasm-split/split-options.cpp index 5e86b987d3a..2283685c5df 100644 --- a/src/tools/wasm-split/split-options.cpp +++ b/src/tools/wasm-split/split-options.cpp @@ -256,14 +256,6 @@ WasmSplitOptions::WasmSplitOptions() [&](Options* o, const std::string& argument) { placeholderNamespacePrefix = argument; }) - .add("--jspi", - "", - "Transform the module to support asynchronously loading the secondary " - "module before any placeholder functions have been called.", - WasmSplitOption, - {Mode::Split}, - Options::Arguments::Zero, - [&](Options* o, const std::string& argument) { jspi = true; }) .add( "--export-prefix", "", diff --git a/src/tools/wasm-split/split-options.h b/src/tools/wasm-split/split-options.h index f91af2957b1..7955721f5d3 100644 --- a/src/tools/wasm-split/split-options.h +++ b/src/tools/wasm-split/split-options.h @@ -50,7 +50,6 @@ struct WasmSplitOptions : ToolOptions { bool emitBinary = true; bool symbolMap = false; bool placeholderMap = false; - bool jspi = false; bool stripDebug = false; // TODO: Remove this. See the comment in wasm-binary.h. diff --git a/src/tools/wasm-split/wasm-split.cpp b/src/tools/wasm-split/wasm-split.cpp index ccb63b8b33e..f655d6f0104 100644 --- a/src/tools/wasm-split/wasm-split.cpp +++ b/src/tools/wasm-split/wasm-split.cpp @@ -308,12 +308,6 @@ void splitModule(const WasmSplitOptions& options) { std::cerr << "warning: not keeping any functions in the primary module\n"; } - if (options.jspi) { - // The load secondary module function must be kept in the main module. - keepFuncs.insert(ModuleSplitting::LOAD_SECONDARY_MODULE); - splitFuncs.erase(ModuleSplitting::LOAD_SECONDARY_MODULE); - } - // If warnings are enabled, check that any functions are being split out. if (!options.quiet && splitFuncs.size() == 0) { std::cerr @@ -352,7 +346,6 @@ void splitModule(const WasmSplitOptions& options) { setCommonSplitConfigs(config, options); config.secondaryFuncs.push_back(std::move(splitFuncs)); config.secondaryNames.push_back("deferred"); - config.jspi = options.jspi; auto splitResults = ModuleSplitting::splitFunctions(wasm, config); auto& secondary = *splitResults.secondaries.begin(); diff --git a/test/lit/help/wasm-split.test b/test/lit/help/wasm-split.test index e94060c0208..39740806aad 100644 --- a/test/lit/help/wasm-split.test +++ b/test/lit/help/wasm-split.test @@ -94,11 +94,6 @@ ;; CHECK-NEXT: --placeholder-namespace [split, multi-split] The same as ;; CHECK-NEXT: --placeholder-namespace-prefix. ;; CHECK-NEXT: -;; CHECK-NEXT: --jspi [split] Transform the module to support -;; CHECK-NEXT: asynchronously loading the secondary -;; CHECK-NEXT: module before any placeholder functions -;; CHECK-NEXT: have been called. -;; CHECK-NEXT: ;; CHECK-NEXT: --export-prefix [split, multi-split] An identifying ;; CHECK-NEXT: prefix to prepend to new export names ;; CHECK-NEXT: created by module splitting. diff --git a/test/lit/wasm-split/jspi-secondary-export.wast b/test/lit/wasm-split/jspi-secondary-export.wast deleted file mode 100644 index 36ce76fad11..00000000000 --- a/test/lit/wasm-split/jspi-secondary-export.wast +++ /dev/null @@ -1,59 +0,0 @@ -;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. -;; RUN: wasm-split %s --export-prefix='%' -g -o1 %t.1.wasm -o2 %t.2.wasm --jspi --split-funcs=foo,bar -;; RUN: wasm-dis %t.1.wasm | filecheck %s --check-prefix PRIMARY -;; RUN: wasm-dis %t.2.wasm | filecheck %s --check-prefix SECONDARY - -;; Ensure exported functions are not moved to secondary module when JSPI is -;; enabled. - -(module - ;; PRIMARY: (type $0 (func (param i32) (result i32))) - - ;; PRIMARY: (type $1 (func)) - - ;; PRIMARY: (import "env" "__load_secondary_module" (func $fimport$0)) - - ;; PRIMARY: (import "placeholder.deferred" "0" (func $placeholder_0 (param i32) (result i32))) - - ;; PRIMARY: (global $global$0 (mut i32) (i32.const 0)) - - ;; PRIMARY: (table $0 1 funcref) - - ;; PRIMARY: (elem $0 (i32.const 0) $placeholder_0) - - ;; PRIMARY: (export "foo" (func $foo)) - (export "foo" (func $foo)) - ;; PRIMARY: (export "load_secondary_module_status" (global $global$0)) - - ;; PRIMARY: (export "%table" (table $0)) - - ;; PRIMARY: (func $foo (param $0 i32) (result i32) - ;; PRIMARY-NEXT: (if - ;; PRIMARY-NEXT: (i32.eqz - ;; PRIMARY-NEXT: (global.get $global$0) - ;; PRIMARY-NEXT: ) - ;; PRIMARY-NEXT: (then - ;; PRIMARY-NEXT: (call $fimport$0) - ;; PRIMARY-NEXT: ) - ;; PRIMARY-NEXT: ) - ;; PRIMARY-NEXT: (call_indirect (type $0) - ;; PRIMARY-NEXT: (local.get $0) - ;; PRIMARY-NEXT: (i32.const 0) - ;; PRIMARY-NEXT: ) - ;; PRIMARY-NEXT: ) - (func $foo (param i32) (result i32) - (call $bar (local.get 0)) - ) - ;; SECONDARY: (type $0 (func (param i32) (result i32))) - - ;; SECONDARY: (import "primary" "%table" (table $timport$0 1 funcref)) - - ;; SECONDARY: (elem $0 (i32.const 0) $bar) - - ;; SECONDARY: (func $bar (param $0 i32) (result i32) - ;; SECONDARY-NEXT: (i32.const 0) - ;; SECONDARY-NEXT: ) - (func $bar (param i32) (result i32) - (i32.const 0) - ) -) diff --git a/test/lit/wasm-split/jspi.wast b/test/lit/wasm-split/jspi.wast deleted file mode 100644 index f821d4a2d2a..00000000000 --- a/test/lit/wasm-split/jspi.wast +++ /dev/null @@ -1,64 +0,0 @@ -;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. -;; RUN: wasm-split %s --export-prefix='%' -g -o1 %t.1.wasm -o2 %t.2.wasm --keep-funcs=foo --jspi -;; RUN: wasm-dis %t.1.wasm | filecheck %s --check-prefix PRIMARY -;; RUN: wasm-dis %t.2.wasm | filecheck %s --check-prefix SECONDARY - -;; Check that the call to bar first checks if the secondary module is loaded and -;; that bar is moved to the secondary module. - -(module - ;; PRIMARY: (type $0 (func (param i32) (result i32))) - - ;; PRIMARY: (type $1 (func)) - - ;; PRIMARY: (import "env" "__load_secondary_module" (func $fimport$0)) - - ;; PRIMARY: (import "placeholder.deferred" "0" (func $placeholder_0 (param i32) (result i32))) - - ;; PRIMARY: (global $global$0 (mut i32) (i32.const 0)) - - ;; PRIMARY: (table $0 1 funcref) - - ;; PRIMARY: (elem $0 (i32.const 0) $placeholder_0) - - ;; PRIMARY: (export "foo" (func $foo)) - (export "foo" (func $foo)) - ;; PRIMARY: (export "load_secondary_module_status" (global $global$0)) - - ;; PRIMARY: (export "%table" (table $0)) - - ;; PRIMARY: (func $foo (param $0 i32) (result i32) - ;; PRIMARY-NEXT: (if - ;; PRIMARY-NEXT: (i32.eqz - ;; PRIMARY-NEXT: (global.get $global$0) - ;; PRIMARY-NEXT: ) - ;; PRIMARY-NEXT: (then - ;; PRIMARY-NEXT: (call $fimport$0) - ;; PRIMARY-NEXT: ) - ;; PRIMARY-NEXT: ) - ;; PRIMARY-NEXT: (call_indirect (type $0) - ;; PRIMARY-NEXT: (i32.const 0) - ;; PRIMARY-NEXT: (i32.const 0) - ;; PRIMARY-NEXT: ) - ;; PRIMARY-NEXT: ) - (func $foo (param i32) (result i32) - (call $bar (i32.const 0)) - ) - ;; SECONDARY: (type $0 (func (param i32) (result i32))) - - ;; SECONDARY: (import "primary" "%table" (table $timport$0 1 funcref)) - - ;; SECONDARY: (import "primary" "foo" (func $foo (param i32) (result i32))) - - ;; SECONDARY: (elem $0 (i32.const 0) $bar) - - ;; SECONDARY: (func $bar (param $0 i32) (result i32) - ;; SECONDARY-NEXT: (call $foo - ;; SECONDARY-NEXT: (i32.const 1) - ;; SECONDARY-NEXT: ) - ;; SECONDARY-NEXT: ) - (func $bar (param i32) (result i32) - (call $foo (i32.const 1)) - ) -) -