summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-10-16 12:40:04 -0700
committerGitHub <noreply@github.com>2017-10-16 12:40:04 -0700
commit73c04954fa52addb709d7de3f2364ec3082c408b (patch)
tree2adc4cc5d5909bd2d18763f327e7ef2d0359060d /src
parentfaaa20b4950351528fd00888040fdd2b14a5a084 (diff)
downloadbinaryen-73c04954fa52addb709d7de3f2364ec3082c408b.tar.gz
binaryen-73c04954fa52addb709d7de3f2364ec3082c408b.tar.bz2
binaryen-73c04954fa52addb709d7de3f2364ec3082c408b.zip
Use the type system to check if something is flowed out of (#1224)
now that the type system has a proper unreachable, we don't need obviouslyDoesNotFlowOut
Diffstat (limited to 'src')
-rw-r--r--src/ast_utils.h12
-rw-r--r--src/passes/RemoveUnusedBrs.cpp6
2 files changed, 3 insertions, 15 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h
index dfa233f26..6e5251860 100644
--- a/src/ast_utils.h
+++ b/src/ast_utils.h
@@ -55,18 +55,6 @@ struct ExpressionAnalyzer {
return !curr->condition && !curr->value;
}
- // Checks if an expression does not flow out in an obvious way.
- // We return true if it cannot flow out. If it can flow out, we
- // might still return true, as the analysis here is simple and fast.
- static bool obviouslyDoesNotFlowOut(Expression* curr) {
- if (auto* br = curr->dynCast<Break>()) {
- if (!br->condition) return true;
- } else if (auto* block = curr->dynCast<Block>()) {
- if (block->list.size() > 0 && obviouslyDoesNotFlowOut(block->list.back()) && !BranchUtils::BranchSeeker::hasReachable(block, block->name)) return true;
- }
- return false;
- }
-
using ExprComparer = std::function<bool(Expression*, Expression*)>;
static bool flexibleEqual(Expression* left, Expression* right, ExprComparer comparer);
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index 7903534b6..d2cdec7ad 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -250,7 +250,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
// let's try to move the code going to the top of the loop into the if-else
if (!iff->ifFalse) {
// we need the ifTrue to break, so it cannot reach the code we want to move
- if (ExpressionAnalyzer::obviouslyDoesNotFlowOut(iff->ifTrue)) {
+ if (iff->ifTrue->type == unreachable) {
iff->ifFalse = builder.stealSlice(block, i + 1, list.size());
iff->finalize();
block->finalize();
@@ -288,12 +288,12 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
return block;
};
- if (ExpressionAnalyzer::obviouslyDoesNotFlowOut(iff->ifTrue)) {
+ if (iff->ifTrue->type == unreachable) {
iff->ifFalse = blockifyMerge(iff->ifFalse, builder.stealSlice(block, i + 1, list.size()));
iff->finalize();
block->finalize();
return true;
- } else if (ExpressionAnalyzer::obviouslyDoesNotFlowOut(iff->ifFalse)) {
+ } else if (iff->ifFalse->type == unreachable) {
iff->ifTrue = blockifyMerge(iff->ifTrue, builder.stealSlice(block, i + 1, list.size()));
iff->finalize();
block->finalize();