Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 2 additions & 49 deletions src/ir/module-splitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -87,8 +86,6 @@ namespace wasm::ModuleSplitting {

namespace {

static const Name LOAD_SECONDARY_STATUS = "load_secondary_module_status";

template<class F> void forEachElement(Module& module, F f) {
ModuleUtils::iterActiveElementSegments(module, [&](ElementSegment* segment) {
Name base = "";
Expand Down Expand Up @@ -328,12 +325,10 @@ struct ModuleSplitter {

// Other helpers
void exportImportFunction(Name func, const std::set<Module*>& modules);
Expression* maybeLoadSecondary(Builder& builder, Expression* callIndirect);
Name getTrampoline(Name funcName);

// Main splitting steps
void classifyFunctions();
void setupJSPI();
void moveSecondaryFunctions();
void thunkExportedSecondaryFunctions();
void indirectReferencesToSecondaryFunctions();
Expand All @@ -346,9 +341,6 @@ struct ModuleSplitter {
: config(config), primary(primary), tableManager(primary),
exportedPrimaryFuncs(initExportedPrimaryFuncs(primary)) {
classifyFunctions();
if (config.jspi) {
setupJSPI();
}
moveSecondaryFunctions();
thunkExportedSecondaryFunctions();
indirectReferencesToSecondaryFunctions();
Expand All @@ -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<Module> ModuleSplitter::initSecondary(const Module& primary) {
// Create the secondary module and copy trivial properties.
auto secondary = std::make_unique<Module>();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<typename Walker>
static void walkSegments(Walker& walker, Module* module) {
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions src/ir/module-splitting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 0 additions & 8 deletions src/tools/wasm-split/split-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"",
Expand Down
1 change: 0 additions & 1 deletion src/tools/wasm-split/split-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 0 additions & 7 deletions src/tools/wasm-split/wasm-split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down
5 changes: 0 additions & 5 deletions test/lit/help/wasm-split.test
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
59 changes: 0 additions & 59 deletions test/lit/wasm-split/jspi-secondary-export.wast

This file was deleted.

64 changes: 0 additions & 64 deletions test/lit/wasm-split/jspi.wast

This file was deleted.

Loading