Esempio n. 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;
 }
Esempio n. 2
0
  public static void checkRedundantPhi(PhiNode phiNode) {
    if (phiNode.isDeleted() || phiNode.valueCount() == 1) {
      return;
    }

    ValueNode singleValue = phiNode.singleValue();
    if (singleValue != null) {
      Collection<PhiNode> phiUsages = phiNode.usages().filter(PhiNode.class).snapshot();
      Collection<ProxyNode> proxyUsages = phiNode.usages().filter(ProxyNode.class).snapshot();
      phiNode.graph().replaceFloating(phiNode, singleValue);
      for (PhiNode phi : phiUsages) {
        checkRedundantPhi(phi);
      }
      for (ProxyNode proxy : proxyUsages) {
        checkRedundantProxy(proxy);
      }
    }
  }