Skip to content

Commit

Permalink
Only update functions in optimizeAfterInlining() (#5624)
Browse files Browse the repository at this point in the history
This saves the work of freeing and allocating for all the other maps. This is a
code path that is used by several passes so it showed up in profiling for
#5561
  • Loading branch information
kripken authored Apr 5, 2023
1 parent 9ee557a commit 30097e5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/passes/opt-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ inline void optimizeAfterInlining(const std::unordered_set<Function*>& funcs,
// save the full list of functions on the side
std::vector<std::unique_ptr<Function>> all;
all.swap(module->functions);
module->updateMaps();
module->updateFunctionsMap();
for (auto& func : funcs) {
module->addFunction(func);
}
Expand All @@ -53,7 +53,7 @@ inline void optimizeAfterInlining(const std::unordered_set<Function*>& funcs,
func.release();
}
all.swap(module->functions);
module->updateMaps();
module->updateFunctionsMap();
}

struct FunctionRefReplacer
Expand Down
1 change: 1 addition & 0 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,7 @@ class Module {
void removeGlobals(std::function<bool(Global*)> pred);
void removeTags(std::function<bool(Tag*)> pred);

void updateFunctionsMap();
void updateDataSegmentsMap();
void updateMaps();

Expand Down
12 changes: 8 additions & 4 deletions src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,13 @@ void Module::removeTags(std::function<bool(Tag*)> pred) {
removeModuleElements(tags, tagsMap, pred);
}

void Module::updateFunctionsMap() {
functionsMap.clear();
for (auto& curr : functions) {
functionsMap[curr->name] = curr.get();
}
}

void Module::updateDataSegmentsMap() {
dataSegmentsMap.clear();
for (auto& curr : dataSegments) {
Expand All @@ -1576,10 +1583,7 @@ void Module::updateDataSegmentsMap() {
}

void Module::updateMaps() {
functionsMap.clear();
for (auto& curr : functions) {
functionsMap[curr->name] = curr.get();
}
updateFunctionsMap();
exportsMap.clear();
for (auto& curr : exports) {
exportsMap[curr->name] = curr.get();
Expand Down

0 comments on commit 30097e5

Please sign in to comment.