Skip to content

Commit 11552ae

Browse files
authored
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
1 parent ab3811d commit 11552ae

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/passes/Inlining.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,19 @@ struct FunctionSplitter {
473473
// Returns a list of the names of the functions we split.
474474
std::vector<Name> finish() {
475475
std::vector<Name> ret;
476+
std::unordered_set<Name> inlineableNames;
476477
for (auto& kv : splits) {
477478
Name func = kv.first;
478479
auto& split = kv.second;
479480
auto* inlineable = split.inlineable;
480481
if (inlineable) {
481-
module->removeFunction(inlineable->name);
482+
inlineableNames.insert(inlineable->name);
482483
ret.push_back(func);
483484
}
484485
}
486+
module->removeFunctions([&](Function* func) {
487+
return inlineableNames.find(func->name) != inlineableNames.end();
488+
});
485489
return ret;
486490
}
487491

@@ -977,8 +981,9 @@ struct Inlining : public Pass {
977981
assert(inlinedUses[inlinedName] <= infos[inlinedName].refs);
978982
}
979983
}
980-
// anything we inlined into may now have non-unique label names, fix it up
981984
for (auto func : inlinedInto) {
985+
// Anything we inlined into may now have non-unique label names, fix it
986+
// up.
982987
wasm::UniqueNameMapper::uniquify(func->body);
983988
}
984989
if (optimize && inlinedInto.size() > 0) {

0 commit comments

Comments
 (0)