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/lit/help/wasm-opt.test | |
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/lit/help/wasm-opt.test')
-rw-r--r-- | test/lit/help/wasm-opt.test | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/test/lit/help/wasm-opt.test b/test/lit/help/wasm-opt.test index 6bc5bf770..64119ecd2 100644 --- a/test/lit/help/wasm-opt.test +++ b/test/lit/help/wasm-opt.test @@ -129,6 +129,8 @@ ;; CHECK-NEXT: --directize turns indirect calls into direct ;; CHECK-NEXT: ones ;; CHECK-NEXT: +;; CHECK-NEXT: --discard-global-effects discards global effect info +;; CHECK-NEXT: ;; CHECK-NEXT: --duplicate-function-elimination removes duplicate functions ;; CHECK-NEXT: ;; CHECK-NEXT: --duplicate-import-elimination removes duplicate imports @@ -157,6 +159,9 @@ ;; CHECK-NEXT: --generate-dyncalls generate dynCall fuctions used ;; CHECK-NEXT: by emscripten ABI ;; CHECK-NEXT: +;; CHECK-NEXT: --generate-global-effects generate global effect info +;; CHECK-NEXT: (helps later passes) +;; CHECK-NEXT: ;; CHECK-NEXT: --generate-i64-dyncalls generate dynCall functions used ;; CHECK-NEXT: by emscripten ABI, but only for ;; CHECK-NEXT: functions with i64 in their |