示例#1
0
 private static Block calcBlockForUsage(
     Node node, Node usage, Block startBlock, NodeMap<Block> currentNodeMap) {
   assert !(node instanceof PhiNode);
   Block currentBlock = startBlock;
   if (usage instanceof PhiNode) {
     // An input to a PhiNode is used at the end of the predecessor block that
     // corresponds to the PhiNode input. One PhiNode can use an input multiple times.
     PhiNode phi = (PhiNode) usage;
     AbstractMergeNode merge = phi.merge();
     Block mergeBlock = currentNodeMap.get(merge);
     for (int i = 0; i < phi.valueCount(); ++i) {
       if (phi.valueAt(i) == node) {
         Block otherBlock = mergeBlock.getPredecessors()[i];
         currentBlock = AbstractControlFlowGraph.commonDominatorTyped(currentBlock, otherBlock);
       }
     }
   } else if (usage instanceof AbstractBeginNode) {
     AbstractBeginNode abstractBeginNode = (AbstractBeginNode) usage;
     if (abstractBeginNode instanceof StartNode) {
       currentBlock =
           AbstractControlFlowGraph.commonDominatorTyped(
               currentBlock, currentNodeMap.get(abstractBeginNode));
     } else {
       Block otherBlock = currentNodeMap.get(abstractBeginNode).getDominator();
       currentBlock = AbstractControlFlowGraph.commonDominatorTyped(currentBlock, otherBlock);
     }
   } else {
     // All other types of usages: Put the input into the same block as the usage.
     Block otherBlock = currentNodeMap.get(usage);
     currentBlock = AbstractControlFlowGraph.commonDominatorTyped(currentBlock, otherBlock);
   }
   return currentBlock;
 }