summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-01 15:31:00 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-01 15:31:00 -0800
commit44e83f2fb039a38b0764a172aa7c64ec3290d8c5 (patch)
tree888f217d7df089525bf368849f22cf6a7505f1f2
parentb25e59d51d828f6a818141a715e9008f05e7063f (diff)
downloadbinaryen-44e83f2fb039a38b0764a172aa7c64ec3290d8c5.tar.gz
binaryen-44e83f2fb039a38b0764a172aa7c64ec3290d8c5.tar.bz2
binaryen-44e83f2fb039a38b0764a172aa7c64ec3290d8c5.zip
remove condition from break
-rw-r--r--src/asm2wasm.h32
-rw-r--r--src/wasm-interpreter.h5
-rw-r--r--src/wasm.h4
-rw-r--r--test/emcc_O2_hello_world.wast36
-rw-r--r--test/emcc_hello_world.wast28
5 files changed, 66 insertions, 39 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 356077460..3a8d3d579 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -836,7 +836,6 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
needTopmost = true;
auto ret = allocator.alloc<Break>();
ret->name = TOPMOST;
- ret->condition = nullptr;
ret->value = !!ast[1] ? process(ast[1]) : nullptr;
return ret;
} else if (what == BLOCK) {
@@ -845,14 +844,12 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
auto ret = allocator.alloc<Break>();
assert(breakStack.size() > 0);
ret->name = !!ast[1] ? getBreakLabelName(ast[1]->getIString()) : breakStack.back();
- ret->condition = nullptr;
ret->value = nullptr;
return ret;
} else if (what == CONTINUE) {
auto ret = allocator.alloc<Break>();
assert(continueStack.size() > 0);
ret->name = !!ast[1] ? getContinueLabelName(ast[1]->getIString()) : continueStack.back();
- ret->condition = nullptr;
ret->value = nullptr;
return ret;
} else if (what == WHILE) {
@@ -874,12 +871,15 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
if (forever) {
ret->body = process(ast[2]);
} else {
- Break *continueWhile = allocator.alloc<Break>();
- continueWhile->name = in;
- continueWhile->condition = process(ast[1]);
- continueWhile->value = nullptr;
+ Break *breakOut = allocator.alloc<Break>();
+ breakOut->name = in;
+ breakOut->value = nullptr;
+ If *condition = allocator.alloc<If>();
+ condition->condition = process(ast[1]);
+ condition->ifTrue = breakOut;
+ condition->ifFalse = nullptr;
auto body = allocator.alloc<Block>();
- body->list.push_back(continueWhile);
+ body->list.push_back(condition);
body->list.push_back(process(ast[2]));
ret->body = body;
}
@@ -923,16 +923,19 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
ret->body = process(ast[2]);
continueStack.pop_back();
breakStack.pop_back();
- Break *continueIf = allocator.alloc<Break>();
- continueIf->name = in;
- continueIf->condition = process(ast[1]);
- continueIf->value = nullptr;
+ Break *continueIn = allocator.alloc<Break>();
+ continueIn->name = in;
+ continueIn->value = nullptr;
+ If *condition = allocator.alloc<If>();
+ condition->condition = process(ast[1]);
+ condition->ifTrue = continueIn;
+ condition->ifFalse = nullptr;
if (Block *block = ret->body->dyn_cast<Block>()) {
- block->list.push_back(continueIf);
+ block->list.push_back(condition);
} else {
auto newBody = allocator.alloc<Block>();
newBody->list.push_back(ret->body);
- newBody->list.push_back(continueIf);
+ newBody->list.push_back(condition);
ret->body = newBody;
}
return ret;
@@ -1054,7 +1057,6 @@ void Asm2WasmBuilder::optimize() {
// look in the child's children to see if there are more uses of this name
BreakSeeker breakSeeker(curr->name);
- breakSeeker.walk(child->condition);
breakSeeker.walk(child->value);
if (breakSeeker.found == 0) return child->value;
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 7356c6b64..a18289c5b 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -123,11 +123,6 @@ public:
}
Flow visitBreak(Break *curr) override {
NOTE_VISIT("Break");
- if (curr->condition) {
- Flow flow = visit(curr->condition);
- if (flow.breaking()) return flow;
- if (!flow.value.geti32()) return Flow();
- }
if (curr->value) {
Flow flow = visit(curr->value);
if (!flow.breaking()) {
diff --git a/src/wasm.h b/src/wasm.h
index 3deae22ef..222eb7cfa 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -387,12 +387,11 @@ public:
Break() : Expression(BreakId) {}
Name name;
- Expression *condition, *value;
+ Expression *value;
std::ostream& doPrint(std::ostream &o, unsigned indent) {
printOpening(o, "break ") << name;
incIndent(o, indent);
- if (condition) printFullLine(o, indent, condition);
if (value) printFullLine(o, indent, value);
return decIndent(o, indent);
}
@@ -1039,7 +1038,6 @@ struct WasmWalker : public WasmVisitor<Expression*> {
}
void visitLabel(Label *curr) override {}
void visitBreak(Break *curr) override {
- curr->condition = parent.walk(curr->condition);
curr->value = parent.walk(curr->value);
}
void visitSwitch(Switch *curr) override {
diff --git a/test/emcc_O2_hello_world.wast b/test/emcc_O2_hello_world.wast
index 1b3ff0336..777bcc9d0 100644
--- a/test/emcc_O2_hello_world.wast
+++ b/test/emcc_O2_hello_world.wast
@@ -4654,11 +4654,13 @@
)
)
)
- (break $do-in$29
+ (if
(i32.ne
(get_local $i63)
(i32.const 0)
)
+ (break $do-in$29
+ )
)
)
)
@@ -6677,7 +6679,7 @@
(get_local $i63)
(i32.const 7)
)
- (break $do-in$47
+ (if
(i32.lt_u
(i32.shr_u
(i32.add
@@ -6691,6 +6693,8 @@
(i32.const 0)
)
)
+ (break $do-in$47
+ )
)
)
)
@@ -7379,11 +7383,13 @@
(i32.const 1)
)
)
- (break $do-in$51
+ (if
(i32.ne
(get_local $i5)
(i32.const 32)
)
+ (break $do-in$51
+ )
)
)
)
@@ -11450,11 +11456,13 @@
(block
(loop $while-out$0 $while-in$1
(block
- (break $while-in$1
+ (if
(i32.and
(get_local $i1)
(i32.const 3)
)
+ (break $while-in$1
+ )
)
(block
(if
@@ -11495,11 +11503,13 @@
)
(loop $while-out$2 $while-in$3
(block
- (break $while-in$3
+ (if
(i32.ge_s
(get_local $i3)
(i32.const 4)
)
+ (break $while-in$3
+ )
)
(block
(i32.store align=4
@@ -11533,11 +11543,13 @@
)
(loop $while-out$4 $while-in$5
(block
- (break $while-in$5
+ (if
(i32.gt_s
(get_local $i3)
(i32.const 0)
)
+ (break $while-in$5
+ )
)
(block
(i32.store8 align=1
@@ -11649,11 +11661,13 @@
)
(loop $while-out$0 $while-in$1
(block
- (break $while-in$1
+ (if
(i32.lt_s
(get_local $i1)
(get_local $i5)
)
+ (break $while-in$1
+ )
)
(block
(i32.store8 align=1
@@ -11673,11 +11687,13 @@
)
(loop $while-out$2 $while-in$3
(block
- (break $while-in$3
+ (if
(i32.lt_s
(get_local $i1)
(get_local $i7)
)
+ (break $while-in$3
+ )
)
(block
(i32.store align=4
@@ -11697,11 +11713,13 @@
)
(loop $while-out$4 $while-in$5
(block
- (break $while-in$5
+ (if
(i32.lt_s
(get_local $i1)
(get_local $i4)
)
+ (break $while-in$5
+ )
)
(block
(i32.store8 align=1
diff --git a/test/emcc_hello_world.wast b/test/emcc_hello_world.wast
index 21394f768..7941533c6 100644
--- a/test/emcc_hello_world.wast
+++ b/test/emcc_hello_world.wast
@@ -2300,11 +2300,13 @@
(i32.const 4)
)
)
- (break $do-in$1
+ (if
(i32.lt_s
(get_local $dest)
(get_local $stop)
)
+ (break $do-in$1
+ )
)
)
)
@@ -24869,11 +24871,13 @@
)
(loop $while-out$0 $while-in$1
(block
- (break $while-in$1
+ (if
(i32.lt_s
(get_local $ptr)
(get_local $unaligned)
)
+ (break $while-in$1
+ )
)
(block
(i32.store8 align=1
@@ -24893,11 +24897,13 @@
)
(loop $while-out$2 $while-in$3
(block
- (break $while-in$3
+ (if
(i32.lt_s
(get_local $ptr)
(get_local $stop4)
)
+ (break $while-in$3
+ )
)
(block
(i32.store align=4
@@ -24917,11 +24923,13 @@
)
(loop $while-out$4 $while-in$5
(block
- (break $while-in$5
+ (if
(i32.lt_s
(get_local $ptr)
(get_local $stop)
)
+ (break $while-in$5
+ )
)
(block
(i32.store8 align=1
@@ -25100,11 +25108,13 @@
(block
(loop $while-out$0 $while-in$1
(block
- (break $while-in$1
+ (if
(i32.and
(get_local $dest)
(i32.const 3)
)
+ (break $while-in$1
+ )
)
(block
(if
@@ -25145,11 +25155,13 @@
)
(loop $while-out$2 $while-in$3
(block
- (break $while-in$3
+ (if
(i32.ge_s
(get_local $num)
(i32.const 4)
)
+ (break $while-in$3
+ )
)
(block
(i32.store align=4
@@ -25183,11 +25195,13 @@
)
(loop $while-out$4 $while-in$5
(block
- (break $while-in$5
+ (if
(i32.gt_s
(get_local $num)
(i32.const 0)
)
+ (break $while-in$5
+ )
)
(block
(i32.store8 align=1