/**
  * Remove unreachable code
  *
  * @param ir the IR to optimize
  */
 private void removeUnreachableCode(IR ir) {
   boolean removedCode = false;
   BasicBlock entry = ir.cfg.entry();
   ir.cfg.clearDFS();
   entry.sortDFS();
   for (BasicBlock node = entry; node != null; ) {
     // save it now before removeFromCFGAndCodeOrder nulls it out!!!
     BasicBlock nextNode = (BasicBlock) node.getNext();
     if (!node.dfsVisited()) {
       for (BasicBlockEnumeration e = node.getOut(); e.hasMoreElements(); ) {
         BasicBlock target = e.next();
         if (target != node && !target.isExit() && target.dfsVisited()) {
           SSA.purgeBlockFromPHIs(node, target);
         }
       }
       ir.cfg.removeFromCFGAndCodeOrder(node);
       removedCode = true;
     }
     node = nextNode;
   }
   if (removedCode) {
     ir.cfg.compactNodeNumbering();
     ir.HIRInfo.dominatorTree = null;
     ir.HIRInfo.dominatorsAreComputed = false;
   }
 }