summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-stack.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-09-20 10:47:14 -0700
committerGitHub <noreply@github.com>2021-09-20 17:47:14 +0000
commit737c22d30798c491eea3b401b948b9327ac979de (patch)
treef75a72adbd81a85eca19b732378837670c828b23 /src/wasm/wasm-stack.cpp
parentb5e8c371001de20128453d5064ac0422d481020e (diff)
downloadbinaryen-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/wasm/wasm-stack.cpp')
-rw-r--r--src/wasm/wasm-stack.cpp33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index e5460cf6f..b6424cdde 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -1942,11 +1942,23 @@ void BinaryInstWriter::visitCallRef(CallRef* curr) {
}
void BinaryInstWriter::visitRefTest(RefTest* curr) {
- o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::RefTest);
+ o << int8_t(BinaryConsts::GCPrefix);
+ if (curr->rtt) {
+ o << U32LEB(BinaryConsts::RefTest);
+ } else {
+ o << U32LEB(BinaryConsts::RefTestStatic);
+ parent.writeIndexedHeapType(curr->intendedType);
+ }
}
void BinaryInstWriter::visitRefCast(RefCast* curr) {
- o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::RefCast);
+ o << int8_t(BinaryConsts::GCPrefix);
+ if (curr->rtt) {
+ o << U32LEB(BinaryConsts::RefCast);
+ } else {
+ o << U32LEB(BinaryConsts::RefCastStatic);
+ parent.writeIndexedHeapType(curr->intendedType);
+ }
}
void BinaryInstWriter::visitBrOn(BrOn* curr) {
@@ -1958,10 +1970,20 @@ void BinaryInstWriter::visitBrOn(BrOn* curr) {
o << int8_t(BinaryConsts::BrOnNonNull);
break;
case BrOnCast:
- o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::BrOnCast);
+ o << int8_t(BinaryConsts::GCPrefix);
+ if (curr->rtt) {
+ o << U32LEB(BinaryConsts::BrOnCast);
+ } else {
+ o << U32LEB(BinaryConsts::BrOnCastStatic);
+ }
break;
case BrOnCastFail:
- o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::BrOnCastFail);
+ o << int8_t(BinaryConsts::GCPrefix);
+ if (curr->rtt) {
+ o << U32LEB(BinaryConsts::BrOnCastFail);
+ } else {
+ o << U32LEB(BinaryConsts::BrOnCastStaticFail);
+ }
break;
case BrOnFunc:
o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::BrOnFunc);
@@ -1985,6 +2007,9 @@ void BinaryInstWriter::visitBrOn(BrOn* curr) {
WASM_UNREACHABLE("invalid br_on_*");
}
o << U32LEB(getBreakIndex(curr->name));
+ if ((curr->op == BrOnCast || curr->op == BrOnCastFail) && !curr->rtt) {
+ parent.writeIndexedHeapType(curr->intendedType);
+ }
}
void BinaryInstWriter::visitRttCanon(RttCanon* curr) {