Skip to content
Merged
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
17 changes: 8 additions & 9 deletions src/ir/module-splitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,18 +997,17 @@ void ModuleSplitter::indirectCallsToSecondaryFunctions() {
// Return if the current module is the same module as the call's target,
// because we don't need a call_indirect within the same module.
Module* currModule = getModule();
if (currModule != &parent.primary &&
Copy link
Copy Markdown
Member Author

@aheejin aheejin May 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currModule != &parent.primary is not necessary because we already filter out when the callee's module is the primary module at the top of the function:

// Return if the call's target is not in one of the secondary module.
if (!parent.allSecondaryFuncs.contains(curr->target)) {
return;
}

So if currModule == calleeModule here, that means currModule is not a primary module anyway.

parent.secondaries.at(parent.funcToSecondaryIndex.at(curr->target))
.get() == currModule) {
Module* calleeModule =
parent.secondaries.at(parent.funcToSecondaryIndex.at(curr->target))
.get();
if (currModule == calleeModule) {
return;
}

Builder builder(*getModule());
Index secIndex = parent.funcToSecondaryIndex.at(curr->target);
auto* func = parent.secondaries.at(secIndex)->getFunction(curr->target);
Builder builder(*currModule);
auto* func = calleeModule->getFunction(curr->target);
auto tableSlot =
parent.tableManager.getSlot(curr->target, func->type.getHeapType());

replaceCurrent(
builder.makeCallIndirect(tableSlot.tableName,
tableSlot.makeExpr(parent.primary),
Expand Down Expand Up @@ -1151,9 +1150,9 @@ void ModuleSplitter::setupTablePatching() {
secondary.getGlobalOrNull(tableManager.activeBase.global);
if (!secondaryGlobal) {
secondaryGlobal = ModuleUtils::copyGlobal(primaryGlobal, secondary);
makeImportExport(
*primaryGlobal, *secondaryGlobal, "global", ExternalKind::Global);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by NFC fix: This is only necessary when we copied the global. There is no harm in calling makeImportExport again on it though.

}
makeImportExport(
*primaryGlobal, *secondaryGlobal, "global", ExternalKind::Global);

assert(tableManager.activeTableSegments.size() == 1 &&
"Unexpected number of segments with non-const base");
Expand Down
Loading