File tree Expand file tree Collapse file tree 1 file changed +23
-13
lines changed
core/src/main/java/org/jruby/ir/representations Expand file tree Collapse file tree 1 file changed +23
-13
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments