diff options
author | Alon Zakai <azakai@google.com> | 2021-08-05 11:03:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-05 11:03:34 -0700 |
commit | 243ac8942e1e0136b8d91242642d9bc825a9cfd9 (patch) | |
tree | 15a354159162a566251383913cee329be0c1d1f5 /src/wasm-type.h | |
parent | 4ba4d31eafb723a28503faffae1702940b6926ca (diff) | |
download | binaryen-243ac8942e1e0136b8d91242642d9bc825a9cfd9.tar.gz binaryen-243ac8942e1e0136b8d91242642d9bc825a9cfd9.tar.bz2 binaryen-243ac8942e1e0136b8d91242642d9bc825a9cfd9.zip |
[Wasm GC] Constant Field Propagation (#4052)
A field in a struct is constant if we can see that in the entire program we
only ever write the same constant value to it. For example, imagine a
vtable type that we construct with the same funcrefs each time, then (if
we have no struct.sets, or if we did, and they had the same value), we
could replace a get with that constant value, since it cannot be anything
else:
(struct.new $T (i32.const 10) (rtt))
..no other conflicting values..
(struct.get $T 0) => (i32.const 10)
If the value is a function reference, then this may allow other passes
to turn what was a call_ref into a direct call and perhaps also get
inlined, effectively a form of devirtualization.
This only works in nominal typing, as we need to know the supertype
of each type. (It could work in theory in structural, but we'd need to do
hard work to find all the possible supertypes, and it would also
become far less effective.)
This deletes a trivial test for running -O on GC content. We have
many more tests for GC at this point, so that test is not needed, and
this PR also optimizes the code into something trivial and
uninteresting anyhow.
Diffstat (limited to 'src/wasm-type.h')
-rw-r--r-- | src/wasm-type.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/wasm-type.h b/src/wasm-type.h index ff1019e55..43a93b4aa 100644 --- a/src/wasm-type.h +++ b/src/wasm-type.h @@ -41,6 +41,8 @@ enum class TypeSystem { // created. The default system is equirecursive. void setTypeSystem(TypeSystem system); +TypeSystem getTypeSystem(); + // The types defined in this file. All of them are small and typically passed by // value except for `Tuple` and `Struct`, which may own an unbounded amount of // data. |