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
33 changes: 9 additions & 24 deletions src/ir/module-splitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,6 @@ struct ModuleSplitter {
// replace.
std::unordered_map<Name, std::map<size_t, Name>> placeholderMap;

// Internal name of the LOAD_SECONDARY_MODULE function.
Name internalLoadSecondaryModule;

// Map from original secondary function name to its trampoline
std::unordered_map<Name, Name> trampolineMap;

Expand Down Expand Up @@ -367,26 +364,14 @@ struct ModuleSplitter {
};

void ModuleSplitter::setupJSPI() {
// Support the first version of JSPI, where the JSPI pass added the load
// secondary module export.
// TODO: remove this when the new JSPI API is only supported.
if (auto* loadSecondary = primary.getExportOrNull(LOAD_SECONDARY_MODULE);
loadSecondary && loadSecondary->kind == ExternalKind::Function) {
internalLoadSecondaryModule = *loadSecondary->getInternalName();
// Remove the exported LOAD_SECONDARY_MODULE function since it's only needed
// internally.
primary.removeExport(LOAD_SECONDARY_MODULE);
} else {
// 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));
internalLoadSecondaryModule = ModuleSplitting::LOAD_SECONDARY_MODULE;
}
// 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,
Expand Down Expand Up @@ -600,7 +585,7 @@ Expression* ModuleSplitter::maybeLoadSecondary(Builder& builder,
auto* loadSecondary = builder.makeIf(
builder.makeUnary(EqZInt32,
builder.makeGlobalGet(LOAD_SECONDARY_STATUS, Type::i32)),
builder.makeCall(internalLoadSecondaryModule, {}, Type::none));
builder.makeCall(ModuleSplitting::LOAD_SECONDARY_MODULE, {}, Type::none));
return builder.makeSequence(loadSecondary, callIndirect);
}

Expand Down
40 changes: 3 additions & 37 deletions src/passes/JSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
//
// Convert a module to be compatible with JavaScript promise integration (JSPI).
// Promising exports will be wrapped with a function that will handle storing
// the suspsender that is passed in as the first param from a "promising"
// the suspender that is passed in as the first param from a "promising"
// `WebAssembly.Function`. Suspending imports will also be wrapped, but they
// will take the stored suspender and pass it as the first param to the imported
// function that should be created from a "suspending" `WebAssembly.Function`.
Expand All @@ -50,12 +50,6 @@
// Wrap each export in the comma-separated list. Similar to jspi-imports,
// wildcards and separate files are supported.
//
// --pass-arg=jspi-split-module
//
// Enables integration with wasm-split. A JSPI'ed function named
// `__load_secondary_module` will be injected that is used by wasm-split to
// load a secondary module.
//

namespace wasm {

Expand Down Expand Up @@ -93,22 +87,6 @@ struct JSPI : public Pass {
read_possible_response_file(getArgumentOrDefault("jspi-exports", "")));
String::Split listedExports(stateChangingExports, ",");

bool wasmSplit = hasArgument("jspi-split-module");
if (wasmSplit) {
// Make an import for the load secondary module function so a JSPI wrapper
// version will be created.
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;
module->addFunction(std::move(import));
listedImports.push_back(
ENV.toString() + "." +
ModuleSplitting::LOAD_SECONDARY_MODULE.toString());
}

// Create a global to store the suspender that is passed into exported
// functions and will then need to be passed out to the imported functions.
Name suspender = Names::getValidGlobalName(*module, "suspender");
Expand Down Expand Up @@ -168,7 +146,7 @@ struct JSPI : public Pass {
if (im->imported() &&
canChangeState(getFullFunctionName(im->module, im->base),
listedImports)) {
makeWrapperForImport(im, module, suspender, wasmSplit);
makeWrapperForImport(im, module, suspender);
}
}
}
Expand Down Expand Up @@ -221,10 +199,7 @@ struct JSPI : public Pass {
return module->addFunction(std::move(wrapperFunc))->name;
}

void makeWrapperForImport(Function* im,
Module* module,
Name suspender,
bool wasmSplit) {
void makeWrapperForImport(Function* im, Module* module, Name suspender) {
Builder builder(*module);
auto wrapperIm = std::make_unique<Function>();
wrapperIm->name = Names::getValidFunctionName(
Expand Down Expand Up @@ -278,15 +253,6 @@ struct JSPI : public Pass {
wrapperIm->type =
Type(Signature(Type(params), call->type), NonNullable, Inexact);

if (wasmSplit && im->name == ModuleSplitting::LOAD_SECONDARY_MODULE) {
// In non-debug builds the name of the JSPI wrapper function for loading
// the secondary module will be removed. Create an export of it so that
// wasm-split can find it.
module->addExport(
builder.makeExport(ModuleSplitting::LOAD_SECONDARY_MODULE,
ModuleSplitting::LOAD_SECONDARY_MODULE,
ExternalKind::Function));
}
module->removeFunction(im->name);
module->addFunction(std::move(stub));
module->addFunction(std::move(wrapperIm));
Expand Down
30 changes: 0 additions & 30 deletions test/lit/passes/jspi-split-module.wast

This file was deleted.

Loading