summaryrefslogtreecommitdiff
path: root/src/wasm-builder.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-05-10 15:07:35 -0700
committerGitHub <noreply@github.com>2021-05-10 15:07:35 -0700
commit08e0a3cdc5303f6906bb807de3ad9ed9e2cbdb51 (patch)
tree69791163aa63c401d1ba2c2882a198a181b012d1 /src/wasm-builder.h
parent5499ef491a264b02d24180f5dad824feec52074a (diff)
downloadbinaryen-08e0a3cdc5303f6906bb807de3ad9ed9e2cbdb51.tar.gz
binaryen-08e0a3cdc5303f6906bb807de3ad9ed9e2cbdb51.tar.bz2
binaryen-08e0a3cdc5303f6906bb807de3ad9ed9e2cbdb51.zip
Implement all Builder::replaceWithIdenticalType() cases as best we can (#3872)
The method had TODOs which it halted on. But we should not halt the entire program, as this is a best-effort attempt to replace a node with something simpler of the same type (we call it when we know the value is not actually used).
Diffstat (limited to 'src/wasm-builder.h')
-rw-r--r--src/wasm-builder.h10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index bb739af89..fabaac22a 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -1040,9 +1040,8 @@ public:
iff->condition = makeUnary(EqZInt32, iff->condition);
}
- // returns a replacement with the precise same type, and with
- // minimal contents. as a replacement, this may reuse the
- // input node
+ // Returns a replacement with the precise same type, and with minimal contents
+ // as best we can. As a replacement, this may reuse the input node.
template<typename T> Expression* replaceWithIdenticalType(T* curr) {
if (curr->type.isTuple()) {
return makeConstantExpression(Literal::makeZeros(curr->type));
@@ -1050,13 +1049,12 @@ public:
if (curr->type.isNullable()) {
return ExpressionManipulator::refNull(curr, curr->type);
}
- if (curr->type.isFunction()) {
+ if (curr->type.isFunction() || !curr->type.isBasic()) {
// We can't do any better, keep the original.
return curr;
}
Literal value;
// TODO: reuse node conditionally when possible for literals
- TODO_SINGLE_COMPOUND(curr->type);
switch (curr->type.getBasic()) {
case Type::i32:
value = Literal(int32_t(0));
@@ -1085,7 +1083,7 @@ public:
case Type::i31ref:
return makeI31New(makeConst(0));
case Type::dataref:
- WASM_UNREACHABLE("TODO: dataref");
+ return curr;
case Type::none:
return ExpressionManipulator::nop(curr);
case Type::unreachable: