summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-01-06 15:47:19 -0600
committerGitHub <noreply@github.com>2023-01-06 13:47:19 -0800
commitf719c3527512377657f72f16ee4ac5581843614f (patch)
treeb082f8d5e80bb53a9d69e7c8197f6b7ada2939b6 /src/passes/Print.cpp
parent73a1cfcacd028ed7aefe304c2e140cda4068dcb0 (diff)
downloadbinaryen-f719c3527512377657f72f16ee4ac5581843614f.tar.gz
binaryen-f719c3527512377657f72f16ee4ac5581843614f.tar.bz2
binaryen-f719c3527512377657f72f16ee4ac5581843614f.zip
Consolidate br_on* operations (#5399)
The `br_on{_non}_{data,i31,func}` operations are deprecated and directly representable in terms of the new `br_on_cast` and `br_on_cast_fail` instructions, so remove their dedicated IR opcodes in favor of representing them as casts. `br_on_null` and `br_on_non_null` cannot be consolidated the same way because their behavior is not directly representable in terms of `br_on_cast` and `br_on_cast_fail`; when the cast to null bottom type succeeds, the null check instructions implicitly drop the null value whereas the cast instructions would propagate it. Add special logic to the binary writer and printer to continue emitting the deprecated instructions for now. This will allow us to update the test suite in a separate future PR with no additional functional changes. Some tests are updated because the validator no longer allows passing non-func data to `br_on_func`. Doing so has not made sense since we separated the three reference type hierarchies.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r--src/passes/Print.cpp68
1 files changed, 45 insertions, 23 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index c1064b7db..988b1d251 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2135,11 +2135,33 @@ struct PrintExpressionContents
switch (curr->op) {
case BrOnNull:
printMedium(o, "br_on_null ");
- break;
+ printName(curr->name, o);
+ return;
case BrOnNonNull:
printMedium(o, "br_on_non_null ");
- break;
+ printName(curr->name, o);
+ return;
case BrOnCast:
+ // TODO: These instructions are deprecated, so stop emitting them.
+ if (auto type = curr->castType.getHeapType();
+ type.isBasic() && curr->castType.isNonNullable()) {
+ switch (type.getBasic()) {
+ case HeapType::func:
+ printMedium(o, "br_on_func ");
+ printName(curr->name, o);
+ return;
+ case HeapType::data:
+ printMedium(o, "br_on_data ");
+ printName(curr->name, o);
+ return;
+ case HeapType::i31:
+ printMedium(o, "br_on_i31 ");
+ printName(curr->name, o);
+ return;
+ default:
+ break;
+ }
+ }
printMedium(o, "br_on_cast ");
printName(curr->name, o);
o << ' ';
@@ -2149,6 +2171,26 @@ struct PrintExpressionContents
printHeapType(o, curr->castType.getHeapType(), wasm);
return;
case BrOnCastFail:
+ // TODO: These instructions are deprecated, so stop emitting them.
+ if (auto type = curr->castType.getHeapType();
+ type.isBasic() && curr->castType.isNonNullable()) {
+ switch (type.getBasic()) {
+ case HeapType::func:
+ printMedium(o, "br_on_non_func ");
+ printName(curr->name, o);
+ return;
+ case HeapType::data:
+ printMedium(o, "br_on_non_data ");
+ printName(curr->name, o);
+ return;
+ case HeapType::i31:
+ printMedium(o, "br_on_non_i31 ");
+ printName(curr->name, o);
+ return;
+ default:
+ break;
+ }
+ }
printMedium(o, "br_on_cast_fail ");
printName(curr->name, o);
o << ' ';
@@ -2157,28 +2199,8 @@ struct PrintExpressionContents
}
printHeapType(o, curr->castType.getHeapType(), wasm);
return;
- case BrOnFunc:
- printMedium(o, "br_on_func ");
- break;
- case BrOnNonFunc:
- printMedium(o, "br_on_non_func ");
- break;
- case BrOnData:
- printMedium(o, "br_on_data ");
- break;
- case BrOnNonData:
- printMedium(o, "br_on_non_data ");
- break;
- case BrOnI31:
- printMedium(o, "br_on_i31 ");
- break;
- case BrOnNonI31:
- printMedium(o, "br_on_non_i31 ");
- break;
- default:
- WASM_UNREACHABLE("invalid ref.is_*");
}
- printName(curr->name, o);
+ WASM_UNREACHABLE("Unexpected br_on* op");
}
void visitStructNew(StructNew* curr) {
if (printUnreachableReplacement(curr)) {