diff options
author | Brendan Dahl <brendan.dahl@gmail.com> | 2024-04-29 09:24:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-29 09:24:24 -0700 |
commit | 4f7c6d687e7bbf70888ba046e5ee676f0bdf5815 (patch) | |
tree | c9ace48d705cdadc6fe21d0d5eec3d4557d3f93e /src | |
parent | abd51437426c72a2d2f8195da5d5cf570941b805 (diff) | |
download | binaryen-4f7c6d687e7bbf70888ba046e5ee676f0bdf5815.tar.gz binaryen-4f7c6d687e7bbf70888ba046e5ee676f0bdf5815.tar.bz2 binaryen-4f7c6d687e7bbf70888ba046e5ee676f0bdf5815.zip |
[jspi] - Support new version of JSPI for module splitting. (#6546)
With the old version of JSPI, the JSPI pass was required to be run before
splitting and would automatically add an export to be able to find the
load_secondary_module function. Now that the pass is no longer needed,
just add an import manually for the load_secondary_module function.
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/module-splitting.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/ir/module-splitting.cpp b/src/ir/module-splitting.cpp index 27b6a0902..5843bbb18 100644 --- a/src/ir/module-splitting.cpp +++ b/src/ir/module-splitting.cpp @@ -68,6 +68,7 @@ // not yet support passive table segments anyway). #include "ir/module-splitting.h" +#include "asmjs/shared-constants.h" #include "ir/element-utils.h" #include "ir/export-utils.h" #include "ir/manipulation.h" @@ -318,12 +319,25 @@ struct ModuleSplitter { }; void ModuleSplitter::setupJSPI() { - assert(primary.getExportOrNull(LOAD_SECONDARY_MODULE) && - "The load secondary module function must exist"); - // Remove the exported LOAD_SECONDARY_MODULE function since it's only needed - // internally. - internalLoadSecondaryModule = primary.getExport(LOAD_SECONDARY_MODULE)->value; - primary.removeExport(LOAD_SECONDARY_MODULE); + // 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 (primary.getExportOrNull(LOAD_SECONDARY_MODULE)) { + internalLoadSecondaryModule = + primary.getExport(LOAD_SECONDARY_MODULE)->value; + // 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, + Signature(Type::none, Type::none), + {}); + import->module = ENV; + import->base = ModuleSplitting::LOAD_SECONDARY_MODULE; + primary.addFunction(std::move(import)); + internalLoadSecondaryModule = ModuleSplitting::LOAD_SECONDARY_MODULE; + } Builder builder(primary); // Add a global to track whether the secondary module has been loaded yet. primary.addGlobal(builder.makeGlobal(LOAD_SECONDARY_STATUS, |