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
39 changes: 16 additions & 23 deletions src/passes/RemoveUnusedModuleElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,26 @@ struct ReachabilityAnalyzer : public PostWalker<ReachabilityAnalyzer> {
}
}

void visitCall(Call* curr) {
if (reachable.count(
ModuleElement(ModuleElementKind::Function, curr->target)) == 0) {
queue.emplace_back(ModuleElementKind::Function, curr->target);
void maybeAdd(ModuleElement element) {
if (reachable.count(element) == 0) {
queue.emplace_back(element);
}
}

void visitCall(Call* curr) {
maybeAdd(ModuleElement(ModuleElementKind::Function, curr->target));
}
void visitCallIndirect(CallIndirect* curr) {
assert(!module->tables.empty() && "call-indirect to undefined table.");

if (reachable.count(ModuleElement(ModuleElementKind::Table, curr->table)) ==
0) {
queue.emplace_back(ModuleElementKind::Table, curr->table);
}
maybeAdd(ModuleElement(ModuleElementKind::Table, curr->table));
}

void visitGlobalGet(GlobalGet* curr) {
if (reachable.count(ModuleElement(ModuleElementKind::Global, curr->name)) ==
0) {
queue.emplace_back(ModuleElementKind::Global, curr->name);
}
maybeAdd(ModuleElement(ModuleElementKind::Global, curr->name));
}
void visitGlobalSet(GlobalSet* curr) {
if (reachable.count(ModuleElement(ModuleElementKind::Global, curr->name)) ==
0) {
queue.emplace_back(ModuleElementKind::Global, curr->name);
}
maybeAdd(ModuleElement(ModuleElementKind::Global, curr->name));
}

void visitLoad(Load* curr) { usesMemory = true; }
Expand All @@ -127,15 +121,14 @@ struct ReachabilityAnalyzer : public PostWalker<ReachabilityAnalyzer> {
void visitMemorySize(MemorySize* curr) { usesMemory = true; }
void visitMemoryGrow(MemoryGrow* curr) { usesMemory = true; }
void visitRefFunc(RefFunc* curr) {
if (reachable.count(
ModuleElement(ModuleElementKind::Function, curr->func)) == 0) {
queue.emplace_back(ModuleElementKind::Function, curr->func);
}
maybeAdd(ModuleElement(ModuleElementKind::Function, curr->func));
}
void visitThrow(Throw* curr) {
if (reachable.count(ModuleElement(ModuleElementKind::Event, curr->event)) ==
0) {
queue.emplace_back(ModuleElementKind::Event, curr->event);
maybeAdd(ModuleElement(ModuleElementKind::Event, curr->event));
}
void visitTry(Try* curr) {
for (auto event : curr->catchEvents) {
maybeAdd(ModuleElement(ModuleElementKind::Event, event));
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion test/passes/remove-unused-module-elements_all-features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,12 @@
)
)
(module
(type $none_=>_none (func))
(type $i32_=>_none (func (param i32)))
(type $none_=>_none (func))
(type $i64_=>_none (func (param i64)))
(event $e-export (attr 0) (param i64))
(event $e-throw (attr 0) (param i32))
(event $e-catch (attr 0) (param i32))
(export "e-export" (event $e-export))
(start $start)
(func $start
Expand Down