Skip to content

Commit ae613ab

Browse files
committed
Merge branch 'master' of github.com:jruby/jruby
2 parents 3402408 + 3b41c9c commit ae613ab

File tree

1 file changed

+23
-13
lines changed
  • core/src/main/java/org/jruby/ir/representations

1 file changed

+23
-13
lines changed

core/src/main/java/org/jruby/ir/representations/CFG.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -418,22 +418,32 @@ private void deleteOrphanedBlocks(DirectedGraph<BasicBlock> graph) {
418418
// System.out.println("\nGraph:\n" + toStringGraph());
419419
// System.out.println("\nInstructions:\n" + toStringInstrs());
420420

421-
// FIXME: Quick and dirty implementation
422-
while (true) {
423-
BasicBlock bbToRemove = null;
424-
for (BasicBlock b : graph.allData()) {
425-
if (b == entryBB) continue; // Skip entry bb!
426-
427-
// Every other bb should have at least one incoming edge
428-
if (graph.findVertexFor(b).getIncomingEdges().isEmpty()) {
429-
bbToRemove = b;
430-
break;
421+
Queue<BasicBlock> worklist = new LinkedList();
422+
Set<BasicBlock> living = new HashSet();
423+
worklist.add(entryBB);
424+
living.add(entryBB);
425+
426+
while (!worklist.isEmpty()) {
427+
BasicBlock current = worklist.remove();
428+
429+
for (BasicBlock bb: graph.findVertexFor(current).getOutgoingDestinationsData()) {
430+
if (!living.contains(bb)) {
431+
worklist.add(bb);
432+
living.add(bb);
431433
}
432434
}
433-
if (bbToRemove == null) break;
435+
}
436+
437+
// Seems like Java should have simpler way of doing this.
438+
// We canot just remove in this loop or we get concmodexc.
439+
Set<BasicBlock> dead = new HashSet();
440+
for (BasicBlock bb: graph.allData()) {
441+
if (!living.contains(bb)) dead.add(bb);
442+
}
434443

435-
removeBB(bbToRemove);
436-
removeNestedScopesFromBB(bbToRemove);
444+
for (BasicBlock bb: dead) {
445+
removeBB(bb);
446+
removeNestedScopesFromBB(bb);
437447
}
438448
}
439449

0 commit comments

Comments
 (0)