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
10 changes: 0 additions & 10 deletions src/abi/js.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ namespace wasm {

namespace ABI {

enum class LegalizationLevel { Full = 0, Minimal = 1 };

inline std::string getLegalizationPass(LegalizationLevel level) {
if (level == LegalizationLevel::Full) {
return "legalize-js-interface";
} else {
return "legalize-js-interface-minimally";
}
}

namespace wasm2js {

extern IString SCRATCH_LOAD_I32;
Expand Down
43 changes: 6 additions & 37 deletions src/passes/LegalizeJSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
// stub methods added in this pass, that thunk i64s into i32, i32 and
// vice versa as necessary.
//
// We can also legalize in a "minimal" way, that is, only JS-specific
// components, that only JS will care about, such as dynCall methods
// (wasm will never call them, as it can share the tables directly). E.g.
// is dynamic linking, where we can avoid legalizing wasm=>wasm calls
// across modules, we still want to legalize dynCalls so JS can call into the
// tables even to a signature that is not legal.
//
// Another variation also "prunes" imports and exports that we cannot yet
// legalize, like exports and imports with SIMD or multivalue. Until we write
// the logic to legalize them, removing those imports/exports still allows us to
Expand Down Expand Up @@ -65,9 +58,7 @@ struct LegalizeJSInterface : public Pass {
// Adds calls to new imports.
bool addsEffects() override { return true; }

bool full;

LegalizeJSInterface(bool full) : full(full) {}
LegalizeJSInterface() {}

void run(Module* module) override {
setTempRet0 = nullptr;
Expand All @@ -82,7 +73,7 @@ struct LegalizeJSInterface : public Pass {
if (ex->kind == ExternalKind::Function) {
// if it's an import, ignore it
auto* func = module->getFunction(ex->value);
if (isIllegal(func) && shouldBeLegalized(ex.get(), func)) {
if (isIllegal(func)) {
// Provide a legal function for the export.
auto legalName = makeLegalStub(func, module);
ex->value = legalName;
Expand Down Expand Up @@ -116,7 +107,7 @@ struct LegalizeJSInterface : public Pass {
}
// for each illegal import, we must call a legalized stub instead
for (auto* im : originalFunctions) {
if (im->imported() && isIllegal(im) && shouldBeLegalized(im)) {
if (im->imported() && isIllegal(im)) {
auto funcName = makeLegalStubForCalledImport(im, module);
illegalImportsToLegal[im->name] = funcName;
// we need to use the legalized version in the tables, as the import
Expand Down Expand Up @@ -199,24 +190,6 @@ struct LegalizeJSInterface : public Pass {

bool isDynCall(Name name) { return name.startsWith("dynCall_"); }

// Check if an export should be legalized.
bool shouldBeLegalized(Export* ex, Function* func) {
if (full) {
return true;
}
// We are doing minimal legalization - just what JS needs.
return isDynCall(ex->name);
}

// Check if an import should be legalized.
bool shouldBeLegalized(Function* im) {
if (full) {
return true;
}
// We are doing minimal legalization - just what JS needs.
return im->module == ENV && im->base.startsWith("invoke_");
}

Function* tempSetter(Module* module) {
if (!setTempRet0) {
if (exportedHelpers) {
Expand Down Expand Up @@ -367,8 +340,8 @@ struct LegalizeJSInterface : public Pass {
};

struct LegalizeAndPruneJSInterface : public LegalizeJSInterface {
// Legalize fully (true) and add pruning on top.
LegalizeAndPruneJSInterface() : LegalizeJSInterface(true) {}
// Legalize and add pruning on top.
LegalizeAndPruneJSInterface() : LegalizeJSInterface() {}

void run(Module* module) override {
LegalizeJSInterface::run(module);
Expand Down Expand Up @@ -440,11 +413,7 @@ struct LegalizeAndPruneJSInterface : public LegalizeJSInterface {

} // anonymous namespace

Pass* createLegalizeJSInterfacePass() { return new LegalizeJSInterface(true); }

Pass* createLegalizeJSInterfaceMinimallyPass() {
return new LegalizeJSInterface(false);
}
Pass* createLegalizeJSInterfacePass() { return new LegalizeJSInterface(); }

Pass* createLegalizeAndPruneJSInterfacePass() {
return new LegalizeAndPruneJSInterface();
Expand Down
4 changes: 0 additions & 4 deletions src/passes/pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ void PassRegistry::registerPasses() {
registerPass("legalize-js-interface",
"legalizes i64 types on the import/export boundary",
createLegalizeJSInterfacePass);
registerPass("legalize-js-interface-minimally",
"legalizes i64 types on the import/export boundary in a minimal "
"manner, only on things only JS will call",
createLegalizeJSInterfaceMinimallyPass);
registerPass("legalize-and-prune-js-interface",
"legalizes the import/export boundary and prunes when needed",
createLegalizeAndPruneJSInterfacePass);
Expand Down
1 change: 0 additions & 1 deletion src/passes/passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ Pass* createJSPIPass();
Pass* createJ2CLOptsPass();
Pass* createLegalizeAndPruneJSInterfacePass();
Pass* createLegalizeJSInterfacePass();
Pass* createLegalizeJSInterfaceMinimallyPass();
Pass* createLimitSegmentsPass();
Pass* createLocalCSEPass();
Pass* createLocalSubtypingPass();
Expand Down
6 changes: 2 additions & 4 deletions src/tools/wasm-emscripten-finalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,8 @@ int main(int argc, const char* argv[]) {
}

// Legalize the wasm, if BigInts don't make that moot.
if (!bigInt) {
passRunner.add(ABI::getLegalizationPass(
legalizeJavaScriptFFI ? ABI::LegalizationLevel::Full
: ABI::LegalizationLevel::Minimal));
if (!bigInt && legalizeJavaScriptFFI) {
passRunner.add("legalize-js-interface");
}

passRunner.add("strip-target-features");
Expand Down
5 changes: 0 additions & 5 deletions test/lit/help/wasm-opt.test
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,6 @@
;; CHECK-NEXT: --legalize-js-interface legalizes i64 types on the
;; CHECK-NEXT: import/export boundary
;; CHECK-NEXT:
;; CHECK-NEXT: --legalize-js-interface-minimally legalizes i64 types on the
;; CHECK-NEXT: import/export boundary in a
;; CHECK-NEXT: minimal manner, only on things
;; CHECK-NEXT: only JS will call
;; CHECK-NEXT:
;; CHECK-NEXT: --licm loop invariant code motion
;; CHECK-NEXT:
;; CHECK-NEXT: --limit-segments attempt to merge segments to fit
Expand Down
5 changes: 0 additions & 5 deletions test/lit/help/wasm2js.test
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,6 @@
;; CHECK-NEXT: --legalize-js-interface legalizes i64 types on the
;; CHECK-NEXT: import/export boundary
;; CHECK-NEXT:
;; CHECK-NEXT: --legalize-js-interface-minimally legalizes i64 types on the
;; CHECK-NEXT: import/export boundary in a
;; CHECK-NEXT: minimal manner, only on things
;; CHECK-NEXT: only JS will call
;; CHECK-NEXT:
;; CHECK-NEXT: --licm loop invariant code motion
;; CHECK-NEXT:
;; CHECK-NEXT: --limit-segments attempt to merge segments to fit
Expand Down
86 changes: 0 additions & 86 deletions test/lit/passes/legalize-js-interface-minimally.wast

This file was deleted.