summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-09-16 17:55:58 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-09-16 18:28:28 -0700
commit0a9df805f688d5eab8be380ab7c9dde115d88852 (patch)
tree23f956226f783d2a72abfce8cf186909c7256367 /src
parentf0546a0c8322a4e2f1777c8a749207a70cdca681 (diff)
downloadbinaryen-0a9df805f688d5eab8be380ab7c9dde115d88852.tar.gz
binaryen-0a9df805f688d5eab8be380ab7c9dde115d88852.tar.bz2
binaryen-0a9df805f688d5eab8be380ab7c9dde115d88852.zip
br_if returns its value
Diffstat (limited to 'src')
-rw-r--r--src/passes/RemoveUnusedBrs.cpp7
-rw-r--r--src/wasm-builder.h6
-rw-r--r--src/wasm-interpreter.h7
-rw-r--r--src/wasm.h6
4 files changed, 18 insertions, 8 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index fa8ab2f6c..15482de25 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -146,11 +146,10 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs, Visitor<R
// if without an else. try to reduce if (condition) br => br_if (condition)
Break* br = curr->ifTrue->dynCast<Break>();
if (br && !br->condition) { // TODO: if there is a condition, join them
- // if the br has a value, then if => br_if means we always execute the value, and also the order is value,condition vs condition,value
if (canTurnIfIntoBrIf(curr->condition, br->value)) {
br->condition = curr->condition;
br->finalize();
- replaceCurrent(br);
+ replaceCurrent(Builder(*getModule()).dropIfConcretelyTyped(br));
anotherCycle = true;
}
}
@@ -407,18 +406,18 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs, Visitor<R
auto* ifTrueBreak = iff->ifTrue->dynCast<Break>();
if (ifTrueBreak && !ifTrueBreak->condition && canTurnIfIntoBrIf(iff->condition, ifTrueBreak->value)) {
// we are an if-else where the ifTrue is a break without a condition, so we can do this
- list[i] = ifTrueBreak;
ifTrueBreak->condition = iff->condition;
ifTrueBreak->finalize();
+ list[i] = Builder(*getModule()).dropIfConcretelyTyped(ifTrueBreak);
ExpressionManipulator::spliceIntoBlock(curr, i + 1, iff->ifFalse);
continue;
}
// otherwise, perhaps we can flip the if
auto* ifFalseBreak = iff->ifFalse->dynCast<Break>();
if (ifFalseBreak && !ifFalseBreak->condition && canTurnIfIntoBrIf(iff->condition, ifFalseBreak->value)) {
- list[i] = ifFalseBreak;
ifFalseBreak->condition = Builder(*getModule()).makeUnary(EqZInt32, iff->condition);
ifFalseBreak->finalize();
+ list[i] = Builder(*getModule()).dropIfConcretelyTyped(ifFalseBreak);
ExpressionManipulator::spliceIntoBlock(curr, i + 1, iff->ifTrue);
continue;
}
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index f9b2e73f6..546d72391 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -339,6 +339,12 @@ public:
input->finalize();
return ret;
}
+
+ // Drop an expression if it has a concrete type
+ Expression* dropIfConcretelyTyped(Expression* curr) {
+ if (!isConcreteWasmType(curr->type)) return curr;
+ return makeDrop(curr);
+ }
};
} // namespace wasm
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 292d6a521..5d4e7d7b4 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -155,18 +155,19 @@ public:
Flow visitBreak(Break *curr) {
NOTE_ENTER("Break");
bool condition = true;
- Flow flow(curr->name);
+ Flow flow;
if (curr->value) {
flow = visit(curr->value);
if (flow.breaking()) return flow;
- flow.breakTo = curr->name;
}
if (curr->condition) {
Flow conditionFlow = visit(curr->condition);
if (conditionFlow.breaking()) return conditionFlow;
condition = conditionFlow.value.getInteger() != 0;
+ if (!condition) return flow;
}
- return condition ? flow : Flow();
+ flow.breakTo = curr->name;
+ return flow;
}
Flow visitSwitch(Switch *curr) {
NOTE_ENTER("Switch");
diff --git a/src/wasm.h b/src/wasm.h
index 4d5cf4d70..1bce0bac9 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -1027,7 +1027,11 @@ public:
void finalize() {
if (condition) {
- type = none;
+ if (value) {
+ type = value->type;
+ } else {
+ type = none;
+ }
} else {
type = unreachable;
}