diff options
Diffstat (limited to 'src/passes/RemoveUnusedModuleElements.cpp')
-rw-r--r-- | src/passes/RemoveUnusedModuleElements.cpp | 56 |
1 files changed, 14 insertions, 42 deletions
diff --git a/src/passes/RemoveUnusedModuleElements.cpp b/src/passes/RemoveUnusedModuleElements.cpp index 20ce284f7..cd69894f3 100644 --- a/src/passes/RemoveUnusedModuleElements.cpp +++ b/src/passes/RemoveUnusedModuleElements.cpp @@ -211,40 +211,18 @@ struct RemoveUnusedModuleElements : public Pass { // Compute reachability starting from the root set. ReachabilityAnalyzer analyzer(module, roots); // Remove unreachable elements. - { - auto& v = module->functions; - v.erase(std::remove_if(v.begin(), - v.end(), - [&](const std::unique_ptr<Function>& curr) { - return analyzer.reachable.count(ModuleElement( - ModuleElementKind::Function, - curr->name)) == 0; - }), - v.end()); - } - { - auto& v = module->globals; - v.erase(std::remove_if(v.begin(), - v.end(), - [&](const std::unique_ptr<Global>& curr) { - return analyzer.reachable.count( - ModuleElement(ModuleElementKind::Global, - curr->name)) == 0; - }), - v.end()); - } - { - auto& v = module->events; - v.erase(std::remove_if(v.begin(), - v.end(), - [&](const std::unique_ptr<Event>& curr) { - return analyzer.reachable.count( - ModuleElement(ModuleElementKind::Event, - curr->name)) == 0; - }), - v.end()); - } - module->updateMaps(); + module->removeFunctions([&](Function* curr) { + return analyzer.reachable.count( + ModuleElement(ModuleElementKind::Function, curr->name)) == 0; + }); + module->removeGlobals([&](Global* curr) { + return analyzer.reachable.count( + ModuleElement(ModuleElementKind::Global, curr->name)) == 0; + }); + module->removeEvents([&](Event* curr) { + return analyzer.reachable.count( + ModuleElement(ModuleElementKind::Event, curr->name)) == 0; + }); // Handle the memory and table if (!exportsMemory && !analyzer.usesMemory) { if (!importsMemory) { @@ -302,14 +280,8 @@ struct RemoveUnusedModuleElements : public Pass { call->fullType = canonicalize(call->fullType); } // remove no-longer used types - module->functionTypes.erase( - std::remove_if(module->functionTypes.begin(), - module->functionTypes.end(), - [&needed](std::unique_ptr<FunctionType>& type) { - return needed.count(type.get()) == 0; - }), - module->functionTypes.end()); - module->updateMaps(); + module->removeFunctionTypes( + [&](FunctionType* type) { return needed.count(type) == 0; }); } }; |