diff options
author | Heejin Ahn <aheejin@gmail.com> | 2019-12-02 16:34:03 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-02 16:34:03 -0800 |
commit | 9d4acee666dfa46e81838d385a663b4c4730c852 (patch) | |
tree | eaab2d8a8244e9259fa6af8545bc792be6f55c2c /src/passes/DuplicateFunctionElimination.cpp | |
parent | 86492f7b3d48c9ec5f27ca7d3abd90ec02972a40 (diff) | |
download | binaryen-9d4acee666dfa46e81838d385a663b4c4730c852.tar.gz binaryen-9d4acee666dfa46e81838d385a663b4c4730c852.tar.bz2 binaryen-9d4acee666dfa46e81838d385a663b4c4730c852.zip |
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.
Diffstat (limited to 'src/passes/DuplicateFunctionElimination.cpp')
-rw-r--r-- | src/passes/DuplicateFunctionElimination.cpp | 10 |
1 files changed, 2 insertions, 8 deletions
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<Function>& 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; |