summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2016-09-15 15:49:03 -0700
committerGitHub <noreply@github.com>2016-09-15 15:49:03 -0700
commit22548bf789359be1f3c14aa41ffd4a23fda38542 (patch)
treee8a1d214c85309010229f4d70a9d553586ba47c6 /src
parente567fa8675831e79f855cea2181fa58beb107e42 (diff)
downloadbinaryen-22548bf789359be1f3c14aa41ffd4a23fda38542.tar.gz
binaryen-22548bf789359be1f3c14aa41ffd4a23fda38542.tar.bz2
binaryen-22548bf789359be1f3c14aa41ffd4a23fda38542.zip
Update s2wasm for 0xc changes (#698)
Several updates for s2wasm and its tests: Add explicit drops where they are emitted by LLVM already Convert loops (which are still modeled in the old way by LLVM) to wrap them in an explicit block (for the exit label). This also allows simplifying the loop creation (no need to post-process the implicit block which is the loop's body). After the engines update to 0xc we should update LLVM to model loops in the 0xc way, but for now it remains compatible with 0xb and 0xc. Fix the order of the calls to setTee() when creating tee_locals Add an explicit drop when creating the _start entry function wrapper if needed Update dot_s and llvm_autogenerated tests to remove store-results optimization (and few other minor updates) Fix the test auto-updater to fail if subprocesses fail There still seems to be a validation failure when building libc (I think it's from the stricter drop rules, but it may be in the source rather than the compiler), but this at least makes Binaryen's tests pa
Diffstat (limited to 'src')
-rw-r--r--src/s2wasm.h30
-rw-r--r--src/wasm-linker.cpp19
2 files changed, 25 insertions, 24 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 8c04f7891..5b7cd1fa4 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -745,7 +745,7 @@ class S2WasmBuilder {
};
auto setOutput = [&](Expression* curr, Name assign) {
if (assign.isNull() || assign.str[0] == 'd') { // drop
- addToBlock(curr);
+ addToBlock(builder.makeDrop(curr));
} else if (assign.str[0] == 'p') { // push
push(curr);
} else { // set to a local
@@ -1067,8 +1067,6 @@ class S2WasmBuilder {
return target->cast<Loop>()->name;
}
};
- // fixups
- std::vector<Block*> loopBlocks; // we need to clear their names
// main loop
while (1) {
skipWhitespace();
@@ -1097,21 +1095,27 @@ class S2WasmBuilder {
recordLabel();
} else s = strchr(s, '\n');
} else if (match("loop")) {
+ // Allocate an explicit block. This replaces the exit label that was previously on the loop.
+ // Do this for now to keep LLVM's output compatible with both 0xb and 0xc Binaryen.
+ // TODO: Update LLVM to model the 0xc loop behavior
+ auto* explicitBlock = allocator->alloc<Block>();
+ addToBlock(explicitBlock);
+ bstack.push_back(explicitBlock);
auto curr = allocator->alloc<Loop>();
addToBlock(curr);
curr->name = getNextLabel();
- auto block = allocator->alloc<Block>();
- block->name = getNextLabel();
- curr->body = block;
- loopBlocks.push_back(block);
- bstack.push_back(block);
+ explicitBlock->name = getNextLabel();
+ auto implicitBlock = allocator->alloc<Block>();
+ curr->body = implicitBlock;
bstack.push_back(curr);
} else if (match("end_loop")) {
auto* loop = bstack.back()->cast<Loop>();
bstack.pop_back();
- auto* implicitBlock = bstack.back()->cast<Block>();
+ auto* explicitBlock = bstack.back()->cast<Block>();
bstack.pop_back();
- implicitBlock->finalize();
+
+ explicitBlock->finalize();
+ loop->body->finalize();
loop->finalize();
} else if (match("br_table")) {
auto curr = allocator->alloc<Switch>();
@@ -1147,11 +1151,10 @@ class S2WasmBuilder {
Name assign = getAssign();
skipComma();
auto curr = allocator->alloc<SetLocal>();
- curr->setTee(true);
curr->index = func->getLocalIndex(getAssign());
skipComma();
curr->value = getInput();
- curr->type = curr->value->type;
+ curr->setTee(true);
setOutput(curr, assign);
} else if (match("return")) {
addToBlock(builder.makeReturn(*s == '$' ? getInput() : nullptr));
@@ -1198,9 +1201,6 @@ class S2WasmBuilder {
bstack.pop_back(); // remove the base block for the function body
assert(bstack.empty());
assert(estack.empty());
- for (auto block : loopBlocks) {
- block->name = Name();
- }
func->body->dynCast<Block>()->finalize();
wasm->addFunction(func);
}
diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp
index 527ff80ee..80374c1e4 100644
--- a/src/wasm-linker.cpp
+++ b/src/wasm-linker.cpp
@@ -193,23 +193,24 @@ void Linker::layout() {
out.wasm.addFunction(func);
exportFunction(start, true);
out.wasm.addStart(start);
- auto* block = out.wasm.allocator.alloc<Block>();
+ Builder builder(out.wasm);
+ auto* block = builder.makeBlock();
func->body = block;
{
// Create the call, matching its parameters.
// TODO allow calling with non-default values.
- auto* call = out.wasm.allocator.alloc<Call>();
- call->target = startFunction;
- size_t paramNum = 0;
+ std::vector<Expression*> args;
+ Index paramNum = 0;
for (WasmType type : target->params) {
Name name = Name::fromInt(paramNum++);
Builder::addVar(func, name, type);
- auto* param = out.wasm.allocator.alloc<GetLocal>();
- param->index = func->getLocalIndex(name);
- param->type = type;
- call->operands.push_back(param);
+ auto* param = builder.makeGetLocal(func->getLocalIndex(name), type);
+ args.push_back(param);
}
- block->list.push_back(call);
+ auto* call = builder.makeCall(startFunction, args, target->result);
+ Expression* e = call;
+ if (target->result != none) e = builder.makeDrop(call);
+ block->list.push_back(e);
block->finalize();
}
}