diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-05-10 20:49:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-10 20:49:16 -0700 |
commit | 77802a63e5814bcde5ac9af3f4694507d8bae9e9 (patch) | |
tree | 839be4a2210611c008527b54ad741db52aa0d456 /src/passes/RemoveUnusedBrs.cpp | |
parent | 6efa4a97b2c643bf35756bb6e989b90d6b3e44bc (diff) | |
parent | b3c97a9d6e9c0858c7a021c6437a4f38ceb7a156 (diff) | |
download | binaryen-77802a63e5814bcde5ac9af3f4694507d8bae9e9.tar.gz binaryen-77802a63e5814bcde5ac9af3f4694507d8bae9e9.tar.bz2 binaryen-77802a63e5814bcde5ac9af3f4694507d8bae9e9.zip |
Merge pull request #1007 from WebAssembly/brs
Misc minor remove-unused-brs improvements
Diffstat (limited to 'src/passes/RemoveUnusedBrs.cpp')
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index 434b8a4bd..785b1c92e 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -122,6 +122,8 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { } else if (curr->is<Nop>()) { // ignore (could be result of a previous cycle) self->valueCanFlow = false; + } else if (curr->is<Loop>()) { + // do nothing - it's ok for values to flow out } else { // anything else stops the flow flows.clear(); @@ -323,10 +325,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { // map of all value-less breaks going to a block (and not a loop) std::map<Block*, std::vector<Break*>> breaksToBlock; - // number of definitions of each name - when a name is defined more than once, it is not trivially safe to do this - std::map<Name, Index> numDefs; - - // the names to update, when we can (just one def) + // the names to update std::map<Break*, Name> newNames; void visitBreak(Break* curr) { @@ -338,8 +337,6 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { } // TODO: Switch? void visitBlock(Block* curr) { - if (curr->name.is()) numDefs[curr->name]++; - auto& list = curr->list; if (list.size() == 1 && curr->name.is()) { // if this block has just one child, a sub-block, then jumps to the former are jumps to us, really @@ -372,17 +369,12 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { } } } - void visitLoop(Loop* curr) { - if (curr->name.is()) numDefs[curr->name]++; - } void finish() { for (auto& iter : newNames) { auto* br = iter.first; auto name = iter.second; - if (numDefs[name] == 1) { - br->name = name; - } + br->name = name; } } }; |