diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2020-03-10 18:52:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-10 18:52:50 -0700 |
commit | 0abc9ce8e9676c95f7ff572529eebf3018179dad (patch) | |
tree | cfe650786faef0e072ed426d70590a29095031ca /src/wasm/literal.cpp | |
parent | 8f16059d3c29e285d4effed7f0c1f84c1f2f4d9d (diff) | |
download | binaryen-0abc9ce8e9676c95f7ff572529eebf3018179dad.tar.gz binaryen-0abc9ce8e9676c95f7ff572529eebf3018179dad.tar.bz2 binaryen-0abc9ce8e9676c95f7ff572529eebf3018179dad.zip |
Update Precompute to handle tuples (#2687)
This involves replacing `Literal::makeZero` with `Literal::makeZeroes`
and `Literal::makeSingleZero` and updating `isConstantExpression` to
handle constant tuples as well. Also makes `Literals` its own struct
and adds convenience methods on it.
Diffstat (limited to 'src/wasm/literal.cpp')
-rw-r--r-- | src/wasm/literal.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 1cf867cdd..aa2acdcc1 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -66,6 +66,24 @@ Literal::Literal(const LaneArray<2>& lanes) : type(Type::v128) { extractBytes<uint64_t, 2>(v128, lanes); } +Literals Literal::makeZero(Type type) { + assert(type.isConcrete()); + Literals zeroes; + for (auto t : type.expand()) { + zeroes.push_back(makeSingleZero(t)); + } + return zeroes; +} + +Literal Literal::makeSingleZero(Type type) { + assert(type.isSingle()); + if (type.isRef()) { + return makeNullref(); + } else { + return makeFromInt32(0, type); + } +} + std::array<uint8_t, 16> Literal::getv128() const { assert(type == Type::v128); std::array<uint8_t, 16> ret; @@ -1483,7 +1501,7 @@ template<int Lanes, LaneArray<Lanes> (Literal::*IntoLanes)() const> static Literal any_true(const Literal& val) { LaneArray<Lanes> lanes = (val.*IntoLanes)(); for (size_t i = 0; i < Lanes; ++i) { - if (lanes[i] != Literal::makeZero(lanes[i].type)) { + if (lanes[i] != Literal::makeSingleZero(lanes[i].type)) { return Literal(int32_t(1)); } } @@ -1494,7 +1512,7 @@ template<int Lanes, LaneArray<Lanes> (Literal::*IntoLanes)() const> static Literal all_true(const Literal& val) { LaneArray<Lanes> lanes = (val.*IntoLanes)(); for (size_t i = 0; i < Lanes; ++i) { - if (lanes[i] == Literal::makeZero(lanes[i].type)) { + if (lanes[i] == Literal::makeSingleZero(lanes[i].type)) { return Literal(int32_t(0)); } } |