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
56 changes: 28 additions & 28 deletions src/ir/module-splitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,25 +638,6 @@ void ModuleSplitter::thunkExportedSecondaryFunctions() {
}
}

// Helper to walk expressions in segments but NOT in globals.
template<typename Walker>
static void walkSegments(Walker& walker, Module* module) {
walker.setModule(module);
for (auto& curr : module->elementSegments) {
if (curr->offset) {
walker.walk(curr->offset);
}
for (auto* item : curr->data) {
walker.walk(item);
}
}
for (auto& curr : module->dataSegments) {
if (curr->offset) {
walker.walk(curr->offset);
}
}
}

void ModuleSplitter::shareImportableItems() {

struct UsedNames {
Expand All @@ -666,6 +647,23 @@ void ModuleSplitter::shareImportableItems() {
std::unordered_set<Name> tags;
};

auto walkSegments = [](auto& walker, Module* module) {
walker.setModule(module);
for (auto& curr : module->elementSegments) {
if (curr->offset) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's add a TODO to walk the segment's init expression as well. (init segment support was added after this code was originally written, IIRC.)

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.

You mean #8405? It's in tables, not segments. I'll just do that as a follow-up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh right, tables. Sounds good 👍

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.

walker.walk(curr->offset);
}
for (auto* item : curr->data) {
walker.walk(item);
}
}
for (auto& curr : module->dataSegments) {
if (curr->offset) {
walker.walk(curr->offset);
}
}
};

struct NameCollector
: public PostWalker<NameCollector,
UnifiedExpressionVisitor<NameCollector>> {
Expand Down Expand Up @@ -776,6 +774,17 @@ void ModuleSplitter::shareImportableItems() {
}
}

// We need to assume the dispatch table and its base global are used in the
// primary module, because we will create segments there later.
if (&module == &primary) {
if (tableManager.dispatchTable) {
used.tables.insert(tableManager.dispatchTable->name);
}
if (tableManager.dispatchBase.global) {
used.globals.insert(tableManager.dispatchBase.global);
}
}

// Compute the transitive closure of globals referenced in other globals'
// initializers. Since globals can reference other globals, we must ensure
// that if a global is used in a module, all its dependencies are also
Expand Down Expand Up @@ -805,15 +814,6 @@ void ModuleSplitter::shareImportableItems() {
secondaryUsed.push_back(getUsedNames(*secondaryPtr));
}

// We need to assume the dispatch table and its base global are used in the
// primary module, because we will create segments there later.
if (tableManager.dispatchTable) {
primaryUsed.tables.insert(tableManager.dispatchTable->name);
}
if (tableManager.dispatchBase.global) {
primaryUsed.globals.insert(tableManager.dispatchBase.global);
}

// If custom-descirptors is enabled, global initializers can trap. Trapping
// globals should stay in the primary module to preserve the trapping behavior
// upon instantiation.
Expand Down
Loading