From a42f2247e0f4ddd7c4560a9d466f65ee88753bd7 Mon Sep 17 00:00:00 2001 From: "Alon Zakai (kripken)" Date: Wed, 10 May 2017 14:40:42 -0700 Subject: allow values to flow out of loops in RemoveUnneededBrs, and simplify some unnecessary complexity in that pass as well --- src/passes/RemoveUnusedBrs.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'src') 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> { } else if (curr->is()) { // ignore (could be result of a previous cycle) self->valueCanFlow = false; + } else if (curr->is()) { + // 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> { // map of all value-less breaks going to a block (and not a loop) std::map> 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 numDefs; - - // the names to update, when we can (just one def) + // the names to update std::map newNames; void visitBreak(Break* curr) { @@ -338,8 +337,6 @@ struct RemoveUnusedBrs : public WalkerPass> { } // 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> { } } } - 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; } } }; -- cgit v1.2.3