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
49 changes: 21 additions & 28 deletions src/ir/module-splitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,27 @@ void ModuleSplitter::shareImportableItems() {
break;
}
}

// 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
// marked as used.
UniqueNonrepeatingDeferredQueue<Name> worklist;
for (auto global : used.globals) {
worklist.push(global);
}
while (!worklist.empty()) {
Name name = worklist.pop();
// At this point all globals are still in the primary module, so this
// exists
auto* global = primary.getGlobal(name);
if (!global->imported() && global->init) {
for (auto* get : FindAll<GlobalGet>(global->init).list) {
worklist.push(get->name);
used.globals.insert(get->name);
}
}
}
return used;
};

Expand Down Expand Up @@ -804,34 +825,6 @@ void ModuleSplitter::shareImportableItems() {
}
}

// 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 marked
// as used.
auto computeTransitiveGlobals = [&](UsedNames& used) {
UniqueNonrepeatingDeferredQueue<Name> worklist;
for (auto global : used.globals) {
worklist.push(global);
}
while (!worklist.empty()) {
Name name = worklist.pop();
// At this point all globals are still in the primary module, so this
// exists
auto* global = primary.getGlobal(name);
if (!global->imported() && global->init) {
for (auto* get : FindAll<GlobalGet>(global->init).list) {
worklist.push(get->name);
used.globals.insert(get->name);
}
}
}
};

computeTransitiveGlobals(primaryUsed);
for (auto& used : secondaryUsed) {
computeTransitiveGlobals(used);
}

// Given a name and module item kind, returns the list of secondary modules
// using that name
auto getUsingSecondaries = [&](const Name& name, auto UsedNames::* field) {
Expand Down
Loading