7373// from the IR before splitting.
7474//
7575#include " ir/module-splitting.h"
76- #include " asmjs/shared-constants.h"
7776#include " ir/export-utils.h"
7877#include " ir/find_all.h"
7978#include " ir/module-utils.h"
@@ -87,8 +86,6 @@ namespace wasm::ModuleSplitting {
8786
8887namespace {
8988
90- static const Name LOAD_SECONDARY_STATUS = " load_secondary_module_status" ;
91-
9289template <class F > void forEachElement (Module& module , F f) {
9390 ModuleUtils::iterActiveElementSegments (module , [&](ElementSegment* segment) {
9491 Name base = " " ;
@@ -328,12 +325,10 @@ struct ModuleSplitter {
328325
329326 // Other helpers
330327 void exportImportFunction (Name func, const std::set<Module*>& modules);
331- Expression* maybeLoadSecondary (Builder& builder, Expression* callIndirect);
332328 Name getTrampoline (Name funcName);
333329
334330 // Main splitting steps
335331 void classifyFunctions ();
336- void setupJSPI ();
337332 void moveSecondaryFunctions ();
338333 void thunkExportedSecondaryFunctions ();
339334 void indirectReferencesToSecondaryFunctions ();
@@ -346,9 +341,6 @@ struct ModuleSplitter {
346341 : config(config), primary(primary), tableManager(primary),
347342 exportedPrimaryFuncs (initExportedPrimaryFuncs(primary)) {
348343 classifyFunctions ();
349- if (config.jspi ) {
350- setupJSPI ();
351- }
352344 moveSecondaryFunctions ();
353345 thunkExportedSecondaryFunctions ();
354346 indirectReferencesToSecondaryFunctions ();
@@ -359,25 +351,6 @@ struct ModuleSplitter {
359351 }
360352};
361353
362- void ModuleSplitter::setupJSPI () {
363- // Add an imported function to load the secondary module.
364- auto import = Builder::makeFunction (
365- ModuleSplitting::LOAD_SECONDARY_MODULE,
366- Type (Signature (Type::none, Type::none), NonNullable, Inexact),
367- {});
368- import ->module = ENV;
369- import ->base = ModuleSplitting::LOAD_SECONDARY_MODULE;
370- primary.addFunction (std::move (import ));
371- Builder builder (primary);
372- // Add a global to track whether the secondary module has been loaded yet.
373- primary.addGlobal (builder.makeGlobal (LOAD_SECONDARY_STATUS,
374- Type::i32 ,
375- builder.makeConst (int32_t (0 )),
376- Builder::Mutable));
377- primary.addExport (builder.makeExport (
378- LOAD_SECONDARY_STATUS, LOAD_SECONDARY_STATUS, ExternalKind::Global));
379- }
380-
381354std::unique_ptr<Module> ModuleSplitter::initSecondary (const Module& primary) {
382355 // Create the secondary module and copy trivial properties.
383356 auto secondary = std::make_unique<Module>();
@@ -449,12 +422,7 @@ void ModuleSplitter::classifyFunctions() {
449422 configSecondaryFuncs.insert (funcs.begin (), funcs.end ());
450423 }
451424 for (auto & func : primary.functions ) {
452- // In JSPI mode exported functions cannot be moved to the secondary
453- // module since that would make them async when they may not have the JSPI
454- // wrapper. Exported JSPI functions can still benefit from splitting though
455- // since only the JSPI wrapper stub will remain in the primary module.
456425 if (func->imported () || !configSecondaryFuncs.count (func->name ) ||
457- (config.jspi && ExportUtils::isExported (primary, *func)) ||
458426 segmentReferrers.count (func->name )) {
459427 primaryFuncs.insert (func->name );
460428 } else {
@@ -571,20 +539,6 @@ void ModuleSplitter::thunkExportedSecondaryFunctions() {
571539 }
572540}
573541
574- Expression* ModuleSplitter::maybeLoadSecondary (Builder& builder,
575- Expression* callIndirect) {
576- if (!config.jspi ) {
577- return callIndirect;
578- }
579- // Check if the secondary module is loaded and if it isn't, call the
580- // function to load it.
581- auto * loadSecondary = builder.makeIf (
582- builder.makeUnary (EqZInt32,
583- builder.makeGlobalGet (LOAD_SECONDARY_STATUS, Type::i32 )),
584- builder.makeCall (ModuleSplitting::LOAD_SECONDARY_MODULE, {}, Type::none));
585- return builder.makeSequence (loadSecondary, callIndirect);
586- }
587-
588542// Helper to walk expressions in segments but NOT in globals.
589543template <typename Walker>
590544static void walkSegments (Walker& walker, Module* module ) {
@@ -720,13 +674,12 @@ void ModuleSplitter::indirectCallsToSecondaryFunctions() {
720674 auto tableSlot =
721675 parent.tableManager .getSlot (curr->target , func->type .getHeapType ());
722676
723- replaceCurrent (parent.maybeLoadSecondary (
724- builder,
677+ replaceCurrent (
725678 builder.makeCallIndirect (tableSlot.tableName ,
726679 tableSlot.makeExpr (parent.primary ),
727680 curr->operands ,
728681 func->type .getHeapType (),
729- curr->isReturn ))) ;
682+ curr->isReturn ));
730683 }
731684 };
732685 CallIndirector callIndirector (*this );
0 commit comments