diff options
author | Alon Zakai <azakai@google.com> | 2022-09-16 08:22:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-16 08:22:11 -0700 |
commit | 989489020e635d35870b22894a5d129c8c55d640 (patch) | |
tree | 5d40a3e087e6ea84b9f0aa4dc5b9d25424ba381c /test/wasm2js/reinterpret_scratch.2asm.js | |
parent | fe898e3216bbd13c36c3bc02186ab9f4a629c8d3 (diff) | |
download | binaryen-989489020e635d35870b22894a5d129c8c55d640.tar.gz binaryen-989489020e635d35870b22894a5d129c8c55d640.tar.bz2 binaryen-989489020e635d35870b22894a5d129c8c55d640.zip |
Allow optimizing with global function effects (#5040)
This adds a map of function name => the effects of that function to the
PassOptions structure. That lets us compute those effects once and then
use them in multiple passes afterwards. For example, that lets us optimize
away a call to a function that has no effects:
(drop (call $nothing))
[..]
(func $nothing
;; .. lots of stuff but no effects, only a returned value ..
)
Vacuum will remove that dropped call if we tell it that the called function has
no effects. Note that a nice result of adding this to the PassOptions struct
is that all passes will use the extra info automatically.
This is not enabled by default as the benefits seem rather minor, though it
does help in a small but noticeable way on J2Wasm code, where we use
call.without.effects and have situations like this:
(func $foo
(call $bar)
)
(func $bar
(call.without.effects ..)
)
The call to bar looks like it has effects, normally, but with global effect info
we know it actually doesn't.
To use this, one would do
--generate-global-effects [.. some passes that use the effects ..] --discard-global-effects
Discarding is not necessary, but if there is a pass later that adds effects, then not
discarding could lead to bugs, since we'd think there are fewer effects than there are.
(However, normal optimization passes never add effects, only remove them.)
It's also possible to call this multiple times:
--generate-global-effects -O3 --generate-global-effects -O3
That computes affects after the first -O3, and may find fewer effects than earlier.
This doesn't compute the full transitive closure of the effects across functions. That is,
when computing a function's effects, we don't look into its own calls. The simple case
so far is enough to handle the call.without.effects example from before (though it
may take multiple optimization cycles).
Diffstat (limited to 'test/wasm2js/reinterpret_scratch.2asm.js')
0 files changed, 0 insertions, 0 deletions