diff options
author | Alon Zakai <azakai@google.com> | 2022-11-11 10:16:32 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-11 10:16:32 -0800 |
commit | 3928189214e03430bbc9f2b51c6af3887b465160 (patch) | |
tree | 306cfddc749859a597ff1ca11bea52c24b836ebb /src/ir | |
parent | b7697808988037469d352b044bd6b2469f99da55 (diff) | |
download | binaryen-3928189214e03430bbc9f2b51c6af3887b465160.tar.gz binaryen-3928189214e03430bbc9f2b51c6af3887b465160.tar.bz2 binaryen-3928189214e03430bbc9f2b51c6af3887b465160.zip |
[Wasm GC] Add Monomorphize pass (#5238)
Monomorphization finds cases where we send more refined types to a function
than it declares. In such cases we can copy the function and refine the parameters:
// B is a subtype of A
foo(new B());
function foo(x : A) { ..}
=>
foo_B(new B()); // call redirected to refined copy
function foo(x : A) { ..} // unchanged
function foo_B(x : B) { ..} // refined copy
This increases code size so it may not be worth it in all cases. This initial PR is
hopefully enough to start experimenting with this on performance, and so it does
not enable the pass by default.
This adds two variations of monomorphization, one that always does it, and the
default which is "careful": it sees whether monomorphizing lets the refined function
actually be better than the original (say, by removing a cast). If there is no
improvement then we do not make any changes. This saves a significant amount
of code size - on j2wasm the careful version increases by 13% instead of 20% -
but it does run more slowly obviously.
Diffstat (limited to 'src/ir')
-rw-r--r-- | src/ir/type-updating.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/ir/type-updating.h b/src/ir/type-updating.h index f6df449ae..50ba9efca 100644 --- a/src/ir/type-updating.h +++ b/src/ir/type-updating.h @@ -409,12 +409,12 @@ Expression* fixLocalGet(LocalGet* get, Module& wasm); // Applies new types of parameters to a function. This does all the necessary // changes aside from altering the function type, which the caller is expected -// to do (the caller might simply change the type, but in other cases the caller -// might be rewriting the types and need to preserve their identity in terms of -// nominal typing, so we don't change the type here). The specific things this -// function does are to update the types of local.get/tee operations, -// refinalize, etc., basically all operations necessary to ensure validation -// with the new types. +// to do after we run (the caller might simply change the type, but in other +// cases the caller might be rewriting the types and need to preserve their +// identity in terms of nominal typing, so we don't change the type here). The +// specific things this function does are to update the types of local.get/tee +// operations, refinalize, etc., basically all operations necessary to ensure +// validation with the new types. // // While doing so, we can either update or not update the types of local.get and // local.tee operations. (We do not update them here if we'll be doing an update |