diff options
author | Alon Zakai <azakai@google.com> | 2021-09-20 10:47:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-20 17:47:14 +0000 |
commit | 737c22d30798c491eea3b401b948b9327ac979de (patch) | |
tree | f75a72adbd81a85eca19b732378837670c828b23 /src/passes/Print.cpp | |
parent | b5e8c371001de20128453d5064ac0422d481020e (diff) | |
download | binaryen-737c22d30798c491eea3b401b948b9327ac979de.tar.gz binaryen-737c22d30798c491eea3b401b948b9327ac979de.tar.bz2 binaryen-737c22d30798c491eea3b401b948b9327ac979de.zip |
[Wasm GC] Add static variants of ref.test, ref.cast, and br_on_cast* (#4163)
These variants take a HeapType that is the type we intend to cast to,
and do not take an RTT.
These are intended to be more statically optimizable. For now though
this PR just implements the minimum to get them parsing and to get
through the optimizer without crashing.
Spec: https://docs.google.com/document/d/1afthjsL_B9UaMqCA5ekgVmOm75BVFu6duHNsN9-gnXw/edit#
See #4149
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r-- | src/passes/Print.cpp | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 00b09dea4..6198218d8 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -286,6 +286,12 @@ static std::ostream& printType(std::ostream& o, Type type, Module* wasm) { return o; } +static std::ostream& +printHeapType(std::ostream& o, HeapType type, Module* wasm) { + TypeNamePrinter(o, wasm).print(type); + return o; +} + static std::ostream& printPrefixedTypes(std::ostream& o, const char* prefix, Type type, @@ -1811,7 +1817,7 @@ struct PrintExpressionContents void visitMemoryGrow(MemoryGrow* curr) { printMedium(o, "memory.grow"); } void visitRefNull(RefNull* curr) { printMedium(o, "ref.null "); - TypeNamePrinter(o, wasm).print(curr->type.getHeapType()); + printHeapType(o, curr->type.getHeapType(), wasm); } void visitRefIs(RefIs* curr) { switch (curr->op) { @@ -1881,8 +1887,22 @@ struct PrintExpressionContents printMedium(o, "call_ref"); } } - void visitRefTest(RefTest* curr) { printMedium(o, "ref.test"); } - void visitRefCast(RefCast* curr) { printMedium(o, "ref.cast"); } + void visitRefTest(RefTest* curr) { + if (curr->rtt) { + printMedium(o, "ref.test"); + } else { + printMedium(o, "ref.test_static "); + printHeapType(o, curr->intendedType, wasm); + } + } + void visitRefCast(RefCast* curr) { + if (curr->rtt) { + printMedium(o, "ref.cast"); + } else { + printMedium(o, "ref.cast_static "); + printHeapType(o, curr->intendedType, wasm); + } + } void visitBrOn(BrOn* curr) { switch (curr->op) { case BrOnNull: @@ -1892,10 +1912,26 @@ struct PrintExpressionContents printMedium(o, "br_on_non_null "); break; case BrOnCast: - printMedium(o, "br_on_cast "); + if (curr->rtt) { + printMedium(o, "br_on_cast "); + } else { + printMedium(o, "br_on_cast_static "); + printName(curr->name, o); + o << ' '; + printHeapType(o, curr->intendedType, wasm); + return; + } break; case BrOnCastFail: - printMedium(o, "br_on_cast_fail "); + if (curr->rtt) { + printMedium(o, "br_on_cast_fail "); + } else { + printMedium(o, "br_on_cast_static_fail "); + printName(curr->name, o); + o << ' '; + printHeapType(o, curr->intendedType, wasm); + return; + } break; case BrOnFunc: printMedium(o, "br_on_func "); |