diff options
author | Alon Zakai <azakai@google.com> | 2023-10-18 09:26:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-18 09:26:11 -0700 |
commit | f2a556b1179fe4ee350728ad674bf723eb824768 (patch) | |
tree | 58bce1c29222b8a5ebd946f53e7fd4394def60e6 /src/passes/SimplifyGlobals.cpp | |
parent | f45207e02f3f703ef96b23957538a935856cf874 (diff) | |
download | binaryen-f2a556b1179fe4ee350728ad674bf723eb824768.tar.gz binaryen-f2a556b1179fe4ee350728ad674bf723eb824768.tar.bz2 binaryen-f2a556b1179fe4ee350728ad674bf723eb824768.zip |
SimplifyGlobals: Run on function code in missing places (#6020)
The pass was written before we had relevant code in module locations, but now
with GC we can have global.gets of more things.
The scanner did not run on global code in a way that is not a problem yet, but
will be for a later PR I'll open. It will be tested there. That is, right now there is no
optimization that is confused by the fact that we did not scan code at the module
level, but the next PR will do that.
The use modifier did not run on global code either, which was an actual missed
optimization opportunity: There are cases where we want to modify a global.get
to point to another one, and such a get might be in global code, not just in a
function. A test is added for that.
Diffstat (limited to 'src/passes/SimplifyGlobals.cpp')
-rw-r--r-- | src/passes/SimplifyGlobals.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/passes/SimplifyGlobals.cpp b/src/passes/SimplifyGlobals.cpp index e411adf55..02e685ca7 100644 --- a/src/passes/SimplifyGlobals.cpp +++ b/src/passes/SimplifyGlobals.cpp @@ -505,7 +505,11 @@ struct SimplifyGlobals : public Pass { map[ex->value].exported = true; } } - GlobalUseScanner(&map).run(getPassRunner(), module); + + GlobalUseScanner scanner(&map); + scanner.run(getPassRunner(), module); + scanner.runOnModuleCode(getPassRunner(), module); + // We now know which are immutable in practice. for (auto& global : module->globals) { auto& info = map[global->name]; @@ -601,8 +605,8 @@ struct SimplifyGlobals : public Pass { } void preferEarlierImports() { - // Optimize uses of immutable globals, prefer the earlier import when - // there is a copy. + // Optimize uses of immutable globals, prefer the earlier one when there is + // a copy. NameNameMap copiedParentMap; for (auto& global : module->globals) { auto child = global->name; @@ -626,7 +630,9 @@ struct SimplifyGlobals : public Pass { } } // Apply to the gets. - GlobalUseModifier(&copiedParentMap).run(getPassRunner(), module); + GlobalUseModifier modifier(&copiedParentMap); + modifier.run(getPassRunner(), module); + modifier.runOnModuleCode(getPassRunner(), module); } } |