/**
  * 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;
   }
 }
Пример #2
0
 /**
  * Returns an enumeration of the "prev" nodes (either in or out) for the passed block depending on
  * which way we are viewing the graph
  *
  * @param block the basic block of interest
  */
 private BasicBlockEnumeration getPrevNodes(BasicBlock block) {
   BasicBlockEnumeration bbEnum;
   if (forward) {
     bbEnum = block.getIn();
   } else {
     bbEnum = block.getOut();
   }
   return bbEnum;
 }