@@ -122,6 +122,8 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
122
122
} else if (curr->is <Nop>()) {
123
123
// ignore (could be result of a previous cycle)
124
124
self->valueCanFlow = false ;
125
+ } else if (curr->is <Loop>()) {
126
+ // do nothing - it's ok for values to flow out
125
127
} else {
126
128
// anything else stops the flow
127
129
flows.clear ();
@@ -323,10 +325,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
323
325
// map of all value-less breaks going to a block (and not a loop)
324
326
std::map<Block*, std::vector<Break*>> breaksToBlock;
325
327
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
330
329
std::map<Break*, Name> newNames;
331
330
332
331
void visitBreak (Break* curr) {
@@ -338,8 +337,6 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
338
337
}
339
338
// TODO: Switch?
340
339
void visitBlock (Block* curr) {
341
- if (curr->name .is ()) numDefs[curr->name ]++;
342
-
343
340
auto & list = curr->list ;
344
341
if (list.size () == 1 && curr->name .is ()) {
345
342
// 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>> {
372
369
}
373
370
}
374
371
}
375
- void visitLoop (Loop* curr) {
376
- if (curr->name .is ()) numDefs[curr->name ]++;
377
- }
378
372
379
373
void finish () {
380
374
for (auto & iter : newNames) {
381
375
auto * br = iter.first ;
382
376
auto name = iter.second ;
383
- if (numDefs[name] == 1 ) {
384
- br->name = name;
385
- }
377
+ br->name = name;
386
378
}
387
379
}
388
380
};
0 commit comments