Skip to content

Commit a42f224

Browse files
committed
allow values to flow out of loops in RemoveUnneededBrs, and simplify some unnecessary complexity in that pass as well
1 parent 6efa4a9 commit a42f224

10 files changed

+1117
-1150
lines changed

src/passes/RemoveUnusedBrs.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
122122
} else if (curr->is<Nop>()) {
123123
// ignore (could be result of a previous cycle)
124124
self->valueCanFlow = false;
125+
} else if (curr->is<Loop>()) {
126+
// do nothing - it's ok for values to flow out
125127
} else {
126128
// anything else stops the flow
127129
flows.clear();
@@ -323,10 +325,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
323325
// map of all value-less breaks going to a block (and not a loop)
324326
std::map<Block*, std::vector<Break*>> breaksToBlock;
325327

326-
// number of definitions of each name - when a name is defined more than once, it is not trivially safe to do this
327-
std::map<Name, Index> numDefs;
328-
329-
// the names to update, when we can (just one def)
328+
// the names to update
330329
std::map<Break*, Name> newNames;
331330

332331
void visitBreak(Break* curr) {
@@ -338,8 +337,6 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
338337
}
339338
// TODO: Switch?
340339
void visitBlock(Block* curr) {
341-
if (curr->name.is()) numDefs[curr->name]++;
342-
343340
auto& list = curr->list;
344341
if (list.size() == 1 && curr->name.is()) {
345342
// 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>> {
372369
}
373370
}
374371
}
375-
void visitLoop(Loop* curr) {
376-
if (curr->name.is()) numDefs[curr->name]++;
377-
}
378372

379373
void finish() {
380374
for (auto& iter : newNames) {
381375
auto* br = iter.first;
382376
auto name = iter.second;
383-
if (numDefs[name] == 1) {
384-
br->name = name;
385-
}
377+
br->name = name;
386378
}
387379
}
388380
};

0 commit comments

Comments
 (0)