コード例 #1
0
    private void scheduleEarliestIterative(
        BlockMap<List<Node>> blockToNodes,
        NodeMap<Block> nodeToBlock,
        NodeBitMap visited,
        StructuredGraph graph,
        boolean immutableGraph) {

      BitSet floatingReads = new BitSet(cfg.getBlocks().length);

      // Add begin nodes as the first entry and set the block for phi nodes.
      for (Block b : cfg.getBlocks()) {
        AbstractBeginNode beginNode = b.getBeginNode();
        ArrayList<Node> nodes = new ArrayList<>();
        nodeToBlock.set(beginNode, b);
        nodes.add(beginNode);
        blockToNodes.put(b, nodes);

        if (beginNode instanceof AbstractMergeNode) {
          AbstractMergeNode mergeNode = (AbstractMergeNode) beginNode;
          for (PhiNode phi : mergeNode.phis()) {
            nodeToBlock.set(phi, b);
          }
        } else if (beginNode instanceof LoopExitNode) {
          LoopExitNode loopExitNode = (LoopExitNode) beginNode;
          for (ProxyNode proxy : loopExitNode.proxies()) {
            nodeToBlock.set(proxy, b);
          }
        }
      }

      NodeStack stack = new NodeStack();

      // Start analysis with control flow ends.
      Block[] reversePostOrder = cfg.reversePostOrder();
      for (int j = reversePostOrder.length - 1; j >= 0; --j) {
        Block b = reversePostOrder[j];
        FixedNode endNode = b.getEndNode();
        if (isFixedEnd(endNode)) {
          stack.push(endNode);
          nodeToBlock.set(endNode, b);
        }
      }

      processStack(cfg, blockToNodes, nodeToBlock, visited, floatingReads, stack);

      // Visit back input edges of loop phis.
      boolean changed;
      boolean unmarkedPhi;
      do {
        changed = false;
        unmarkedPhi = false;
        for (LoopBeginNode loopBegin : graph.getNodes(LoopBeginNode.TYPE)) {
          for (PhiNode phi : loopBegin.phis()) {
            if (visited.isMarked(phi)) {
              for (int i = 0; i < loopBegin.getLoopEndCount(); ++i) {
                Node node = phi.valueAt(i + loopBegin.forwardEndCount());
                if (node != null && !visited.isMarked(node)) {
                  changed = true;
                  stack.push(node);
                  processStack(cfg, blockToNodes, nodeToBlock, visited, floatingReads, stack);
                }
              }
            } else {
              unmarkedPhi = true;
            }
          }
        }

        /*
         * the processing of one loop phi could have marked a previously checked loop phi,
         * therefore this needs to be iterative.
         */
      } while (unmarkedPhi && changed);

      // Check for dead nodes.
      if (!immutableGraph && visited.getCounter() < graph.getNodeCount()) {
        for (Node n : graph.getNodes()) {
          if (!visited.isMarked(n)) {
            n.clearInputs();
            n.markDeleted();
          }
        }
      }

      // Add end nodes as the last nodes in each block.
      for (Block b : cfg.getBlocks()) {
        FixedNode endNode = b.getEndNode();
        if (isFixedEnd(endNode)) {
          if (endNode != b.getBeginNode()) {
            addNode(blockToNodes, b, endNode);
          }
        }
      }

      if (!floatingReads.isEmpty()) {
        for (Block b : cfg.getBlocks()) {
          if (floatingReads.get(b.getId())) {
            resortEarliestWithinBlock(b, blockToNodes, nodeToBlock, visited);
          }
        }
      }

      assert MemoryScheduleVerification.check(cfg.getStartBlock(), blockToNodes);
    }
コード例 #2
0
    @SuppressFBWarnings(
        value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE",
        justification = "false positive found by findbugs")
    private BlockMap<ArrayList<FloatingReadNode>> calcLatestBlocks(
        SchedulingStrategy strategy,
        NodeMap<Block> currentNodeMap,
        BlockMap<List<Node>> earliestBlockToNodesMap,
        NodeBitMap visited,
        BlockMap<List<Node>> latestBlockToNodesMap,
        boolean immutableGraph) {
      BlockMap<ArrayList<FloatingReadNode>> watchListMap = new BlockMap<>(cfg);
      Block[] reversePostOrder = cfg.reversePostOrder();
      for (int j = reversePostOrder.length - 1; j >= 0; --j) {
        Block currentBlock = reversePostOrder[j];
        List<Node> blockToNodes = earliestBlockToNodesMap.get(currentBlock);
        LocationSet killed = null;
        int previousIndex = blockToNodes.size();
        for (int i = blockToNodes.size() - 1; i >= 0; --i) {
          Node currentNode = blockToNodes.get(i);
          assert currentNodeMap.get(currentNode) == currentBlock;
          assert !(currentNode instanceof PhiNode) && !(currentNode instanceof ProxyNode);
          assert visited.isMarked(currentNode);
          if (currentNode instanceof FixedNode) {
            // For these nodes, the earliest is at the same time the latest block.
          } else {
            Block latestBlock = null;

            LocationIdentity constrainingLocation = null;
            if (currentNode instanceof FloatingReadNode) {
              // We are scheduling a floating read node => check memory
              // anti-dependencies.
              FloatingReadNode floatingReadNode = (FloatingReadNode) currentNode;
              LocationIdentity location = floatingReadNode.getLocationIdentity();
              if (location.isMutable()) {
                // Location can be killed.
                constrainingLocation = location;
                if (currentBlock.canKill(location)) {
                  if (killed == null) {
                    killed = new LocationSet();
                  }
                  fillKillSet(killed, blockToNodes.subList(i + 1, previousIndex));
                  previousIndex = i;
                  if (killed.contains(location)) {
                    // Earliest block kills location => we need to stay within
                    // earliest block.
                    latestBlock = currentBlock;
                  }
                }
              }
            }

            if (latestBlock == null) {
              // We are not constraint within earliest block => calculate optimized
              // schedule.
              calcLatestBlock(
                  currentBlock,
                  strategy,
                  currentNode,
                  currentNodeMap,
                  constrainingLocation,
                  watchListMap,
                  latestBlockToNodesMap,
                  visited,
                  immutableGraph);
            } else {
              selectLatestBlock(
                  currentNode,
                  currentBlock,
                  latestBlock,
                  currentNodeMap,
                  watchListMap,
                  constrainingLocation,
                  latestBlockToNodesMap);
            }
          }
        }
      }
      return watchListMap;
    }