diff options
author | Alon Zakai <azakai@google.com> | 2020-11-13 11:54:58 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-13 11:54:58 -0800 |
commit | 6af57f53c0ab80891d97f4fed0d41951db0cc7fd (patch) | |
tree | 18a2cccedaee5db19b6c3884c89f1ec3d49560ac /src/wasm/wasm-binary.cpp | |
parent | 4989d79fb15dfc01d35be4b595d4246f91a55405 (diff) | |
download | binaryen-6af57f53c0ab80891d97f4fed0d41951db0cc7fd.tar.gz binaryen-6af57f53c0ab80891d97f4fed0d41951db0cc7fd.tar.bz2 binaryen-6af57f53c0ab80891d97f4fed0d41951db0cc7fd.zip |
Quick followup to #3349 - avoid unnecessary allocations (#3354)
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 813810016..1a5c8a0f4 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -3160,72 +3160,90 @@ void WasmBinaryBuilder::readMemoryAccess(Address& alignment, Address& offset) { bool WasmBinaryBuilder::maybeVisitLoad(Expression*& out, uint8_t code, bool isAtomic) { - auto* curr = allocator.alloc<Load>(); - // The signed field does not matter in some cases (where the size of the load - // is equal to the size of the type, in which case we do not extend), but give - // it a default value nonetheless, to make hashing and other code simpler, so - // that they do not need to consider whether the sign matters or not. - curr->signed_ = false; + Load* curr; + auto allocate = [&]() { + curr = allocator.alloc<Load>(); + // The signed field does not matter in some cases (where the size of the + // load is equal to the size of the type, in which case we do not extend), + // but give it a default value nonetheless, to make hashing and other code + // simpler, so that they do not need to consider whether the sign matters or + // not. + curr->signed_ = false; + }; if (!isAtomic) { switch (code) { case BinaryConsts::I32LoadMem8S: + allocate(); curr->bytes = 1; curr->type = Type::i32; curr->signed_ = true; break; case BinaryConsts::I32LoadMem8U: + allocate(); curr->bytes = 1; curr->type = Type::i32; break; case BinaryConsts::I32LoadMem16S: + allocate(); curr->bytes = 2; curr->type = Type::i32; curr->signed_ = true; break; case BinaryConsts::I32LoadMem16U: + allocate(); curr->bytes = 2; curr->type = Type::i32; break; case BinaryConsts::I32LoadMem: + allocate(); curr->bytes = 4; curr->type = Type::i32; break; case BinaryConsts::I64LoadMem8S: + allocate(); curr->bytes = 1; curr->type = Type::i64; curr->signed_ = true; break; case BinaryConsts::I64LoadMem8U: + allocate(); curr->bytes = 1; curr->type = Type::i64; break; case BinaryConsts::I64LoadMem16S: + allocate(); curr->bytes = 2; curr->type = Type::i64; curr->signed_ = true; break; case BinaryConsts::I64LoadMem16U: + allocate(); curr->bytes = 2; curr->type = Type::i64; break; case BinaryConsts::I64LoadMem32S: + allocate(); curr->bytes = 4; curr->type = Type::i64; curr->signed_ = true; break; case BinaryConsts::I64LoadMem32U: + allocate(); curr->bytes = 4; curr->type = Type::i64; break; case BinaryConsts::I64LoadMem: + allocate(); curr->bytes = 8; curr->type = Type::i64; break; case BinaryConsts::F32LoadMem: + allocate(); curr->bytes = 4; curr->type = Type::f32; break; case BinaryConsts::F64LoadMem: + allocate(); curr->bytes = 8; curr->type = Type::f64; break; @@ -3236,30 +3254,37 @@ bool WasmBinaryBuilder::maybeVisitLoad(Expression*& out, } else { switch (code) { case BinaryConsts::I32AtomicLoad8U: + allocate(); curr->bytes = 1; curr->type = Type::i32; break; case BinaryConsts::I32AtomicLoad16U: + allocate(); curr->bytes = 2; curr->type = Type::i32; break; case BinaryConsts::I32AtomicLoad: + allocate(); curr->bytes = 4; curr->type = Type::i32; break; case BinaryConsts::I64AtomicLoad8U: + allocate(); curr->bytes = 1; curr->type = Type::i64; break; case BinaryConsts::I64AtomicLoad16U: + allocate(); curr->bytes = 2; curr->type = Type::i64; break; case BinaryConsts::I64AtomicLoad32U: + allocate(); curr->bytes = 4; curr->type = Type::i64; break; case BinaryConsts::I64AtomicLoad: + allocate(); curr->bytes = 8; curr->type = Type::i64; break; |