Skip to content
Merged
Show file tree
Hide file tree
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: 28 additions & 21 deletions src/ir/module-splitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,27 +762,6 @@ ModuleSplitter::PrimarySecondaryUsedNames ModuleSplitter::computeUsedNames() {
}
}
}

// 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 @@ -842,6 +821,34 @@ ModuleSplitter::PrimarySecondaryUsedNames ModuleSplitter::computeUsedNames() {
}
}

// 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);
}

return std::make_pair(primaryUsed, secondaryUsed);
}

Expand Down
14 changes: 14 additions & 0 deletions test/lit/wasm-split/trapping-module-items.wast
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
)
)

;; PRIMARY: (global $null-desc nullref
;; PRIMARY-TNH-NOT: (global $null-desc nullref
(global $null-desc (ref null none)
(ref.null none)
)

;; PRIMARY: (global $trapping-global-init-global-get (ref $struct)
;; PRIMARY-TNH-NOT: (global $trapping-global-init-global-get (ref $struct)
(global $trapping-global-init-global-get (ref $struct)
(struct.new_desc $struct
(global.get $null-desc)
)
)

;; PRIMARY: (table $trapping-table 1 1 (ref $struct)
;; PRIMARY-TNH-NOT: (table $trapping-table 1 1 (ref $struct)
(table $trapping-table 1 1 (ref $struct)
Expand Down
Loading