diff options
author | Heejin Ahn <aheejin@gmail.com> | 2020-01-03 16:56:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-03 16:56:13 -0800 |
commit | 2343e9fea395455954adde1b70f8bd2efcc48d4a (patch) | |
tree | 693a0603408e4e8e62eec1242a3aa5313a03ba10 /src | |
parent | 3fbec348f6de9c213d0091984305f9bb4906af47 (diff) | |
download | binaryen-2343e9fea395455954adde1b70f8bd2efcc48d4a.tar.gz binaryen-2343e9fea395455954adde1b70f8bd2efcc48d4a.tar.bz2 binaryen-2343e9fea395455954adde1b70f8bd2efcc48d4a.zip |
Generate push/pop in stack IR (#2566)
We have not been generating push and pop instructions in the stack IR.
Even though they are not written in binary, they have to be in the stack
IR to match the number of inputs and outputs of instructions.
Currently `BinaryenIRWriter` is used both for stack IR generation and
binary generation, so we should emit those instructions in
`BinaryenIRWriter`. `BinaryenIRToBinaryWriter`, which inherits
`BinaryenIRWriter`, does not do anything for push and pop instructions,
so they are still not emitted in binary.
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-stack.h | 6 | ||||
-rw-r--r-- | src/wasm-traversal.h | 6 | ||||
-rw-r--r-- | src/wasm/wasm-stack.cpp | 3 |
3 files changed, 8 insertions, 7 deletions
diff --git a/src/wasm-stack.h b/src/wasm-stack.h index 91c0c5383..5f0bf12af 100644 --- a/src/wasm-stack.h +++ b/src/wasm-stack.h @@ -779,14 +779,12 @@ void BinaryenIRWriter<SubType>::visitDrop(Drop* curr) { template<typename SubType> void BinaryenIRWriter<SubType>::visitPush(Push* curr) { - // Turns into nothing in the binary format: leave the child on the stack for - // others to use. visit(curr->value); + emit(curr); } template<typename SubType> void BinaryenIRWriter<SubType>::visitPop(Pop* curr) { - // Turns into nothing in the binary format: just get a value that is already - // on the stack. + emit(curr); } // Binaryen IR to binary writer diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index c9290cbab..eae4634b5 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -1185,7 +1185,8 @@ struct ControlFlowWalker : public PostWalker<SubType, VisitorType> { switch (curr->_id) { case Expression::Id::BlockId: case Expression::Id::IfId: - case Expression::Id::LoopId: { + case Expression::Id::LoopId: + case Expression::Id::TryId: { self->pushTask(SubType::doPostVisitControlFlow, currp); break; } @@ -1197,7 +1198,8 @@ struct ControlFlowWalker : public PostWalker<SubType, VisitorType> { switch (curr->_id) { case Expression::Id::BlockId: case Expression::Id::IfId: - case Expression::Id::LoopId: { + case Expression::Id::LoopId: + case Expression::Id::TryId: { self->pushTask(SubType::doPreVisitControlFlow, currp); break; } diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index 22d6a0036..a308ecb7a 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -1797,7 +1797,8 @@ StackInst* StackIRGenerator::makeStackInst(StackInst::Op op, ret->op = op; ret->origin = origin; auto stackType = origin->type; - if (origin->is<Block>() || origin->is<Loop>() || origin->is<If>()) { + if (origin->is<Block>() || origin->is<Loop>() || origin->is<If>() || + origin->is<Try>()) { if (stackType == unreachable) { // There are no unreachable blocks, loops, or ifs. we emit extra // unreachables to fix that up, so that they are valid as having none |