From 9d4acee666dfa46e81838d385a663b4c4730c852 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 2 Dec 2019 16:34:03 -0800 Subject: Refactor removing module elements (#2489) This creates utility functions for removing module elements: removing one element by name, and removing multiple elements using a predicate function. And makes other parts of code use it. I think this is a light-handed approach than calling `Module::updateMaps` after removing only a part of module elements. This also fixes a bug in the inlining pass: it didn't call `Module::updateMaps` after removing functions. After this patch callers don't need to additionally call it anyway. --- src/passes/DuplicateFunctionElimination.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/passes/DuplicateFunctionElimination.cpp') diff --git a/src/passes/DuplicateFunctionElimination.cpp b/src/passes/DuplicateFunctionElimination.cpp index 12da32806..8977e035f 100644 --- a/src/passes/DuplicateFunctionElimination.cpp +++ b/src/passes/DuplicateFunctionElimination.cpp @@ -89,14 +89,8 @@ struct DuplicateFunctionElimination : public Pass { // perform replacements if (replacements.size() > 0) { // remove the duplicates - auto& v = module->functions; - v.erase(std::remove_if(v.begin(), - v.end(), - [&](const std::unique_ptr& curr) { - return duplicates.count(curr->name) > 0; - }), - v.end()); - module->updateMaps(); + module->removeFunctions( + [&](Function* func) { return duplicates.count(func->name) > 0; }); OptUtils::replaceFunctions(runner, *module, replacements); } else { break; -- cgit v1.2.3