diff options
author | Alon Zakai <azakai@google.com> | 2021-09-27 09:29:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-27 09:29:26 -0700 |
commit | 11552aef2a36cb90c0d7087644871777cc4a0ef7 (patch) | |
tree | c961f45ef5e5e4eb6c541d3cc7b84a0e283efe0a /src | |
parent | ab3811dafb27edd81f919d0096630014184b3836 (diff) | |
download | binaryen-11552aef2a36cb90c0d7087644871777cc4a0ef7.tar.gz binaryen-11552aef2a36cb90c0d7087644871777cc4a0ef7.tar.bz2 binaryen-11552aef2a36cb90c0d7087644871777cc4a0ef7.zip |
Inlining: Remove unneeded functions in linear time (#4190)
By mistake the recent partial inlining work introduced quadratic time into
the compiler: erasing a function from the list of functions takes linear time,
which is why we have removeFunctions that does a group at a time.
This isn't noticeable on small programs, but on j2cl output this makes the
inlining-optimizing step 2x faster.
See #4165
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Inlining.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp index a409bce8a..e1ae4c2a8 100644 --- a/src/passes/Inlining.cpp +++ b/src/passes/Inlining.cpp @@ -473,15 +473,19 @@ struct FunctionSplitter { // Returns a list of the names of the functions we split. std::vector<Name> finish() { std::vector<Name> ret; + std::unordered_set<Name> inlineableNames; for (auto& kv : splits) { Name func = kv.first; auto& split = kv.second; auto* inlineable = split.inlineable; if (inlineable) { - module->removeFunction(inlineable->name); + inlineableNames.insert(inlineable->name); ret.push_back(func); } } + module->removeFunctions([&](Function* func) { + return inlineableNames.find(func->name) != inlineableNames.end(); + }); return ret; } @@ -977,8 +981,9 @@ struct Inlining : public Pass { assert(inlinedUses[inlinedName] <= infos[inlinedName].refs); } } - // anything we inlined into may now have non-unique label names, fix it up for (auto func : inlinedInto) { + // Anything we inlined into may now have non-unique label names, fix it + // up. wasm::UniqueNameMapper::uniquify(func->body); } if (optimize && inlinedInto.size() > 0) { |