changeset 19842:a9fbe23a602b

Merge.
author Doug Simon <doug.simon@oracle.com>
date Sat, 14 Mar 2015 00:24:40 +0100
parents 834e5392ac05 (current diff) 80d48cc80222 (diff)
children e17f04731c61
files
diffstat 2 files changed, 85 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeStack.java	Sat Mar 14 00:24:40 2015 +0100
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.graph;
+
+public class NodeStack {
+
+    private static final int INITIAL_SIZE = 8;
+
+    protected Node[] values;
+    protected int tos;
+
+    public NodeStack() {
+        values = new Node[INITIAL_SIZE];
+    }
+
+    public void push(Node n) {
+        int newIndex = tos++;
+        int valuesLength = values.length;
+        if (newIndex >= valuesLength) {
+            Node[] newValues = new Node[valuesLength << 1];
+            System.arraycopy(values, 0, newValues, 0, valuesLength);
+            values = newValues;
+        }
+        values[newIndex] = n;
+    }
+
+    public Node pop() {
+        assert tos > 0 : "stack must be non-empty";
+        return values[--tos];
+    }
+
+    public Node peek() {
+        assert tos > 0 : "stack must be non-empty";
+        return values[tos - 1];
+    }
+
+    public boolean isEmpty() {
+        return tos == 0;
+    }
+}
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Sat Mar 14 00:23:48 2015 +0100
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Sat Mar 14 00:24:40 2015 +0100
@@ -278,7 +278,8 @@
 
     private static void sortNodesLatestWithinBlock(Block b, BlockMap<List<Node>> earliestBlockToNodesMap, BlockMap<List<Node>> latestBlockToNodesMap, NodeMap<Block> nodeMap,
                     BlockMap<ArrayList<FloatingReadNode>> watchListMap, NodeBitMap unprocessed) {
-        ArrayList<Node> result = new ArrayList<>();
+        List<Node> earliestSorting = earliestBlockToNodesMap.get(b);
+        ArrayList<Node> result = new ArrayList<>(earliestSorting.size());
         ArrayList<FloatingReadNode> watchList = null;
         if (watchListMap != null) {
             watchList = watchListMap.get(b);
@@ -296,7 +297,7 @@
             }
         }
         FixedNode endNode = b.getEndNode();
-        for (Node n : earliestBlockToNodesMap.get(b)) {
+        for (Node n : earliestSorting) {
             if (n != endNode) {
                 if (n instanceof FixedNode) {
                     assert nodeMap.get(n) == b;
@@ -448,7 +449,7 @@
 
     private static void scheduleEarliestIterative(ControlFlowGraph cfg, BlockMap<List<Node>> blockToNodes, NodeMap<Block> nodeToBlock, NodeBitMap visited, StructuredGraph graph) {
 
-        BlockMap<Boolean> floatingReads = new BlockMap<>(cfg);
+        BitSet floatingReads = new BitSet(cfg.getBlocks().size());
 
         // Add begin nodes as the first entry and set the block for phi nodes.
         for (Block b : cfg.getBlocks()) {
@@ -471,7 +472,7 @@
             }
         }
 
-        Stack<Node> stack = new Stack<>();
+        NodeStack stack = new NodeStack();
 
         // Start analysis with control flow ends.
         for (Block b : cfg.postOrder()) {
@@ -529,9 +530,11 @@
             }
         }
 
-        for (Block b : cfg.getBlocks()) {
-            if (floatingReads.get(b) == Boolean.TRUE) {
-                resortEarliestWithinBlock(b, blockToNodes, nodeToBlock, visited);
+        if (!floatingReads.isEmpty()) {
+            for (Block b : cfg.getBlocks()) {
+                if (floatingReads.get(b.getId())) {
+                    resortEarliestWithinBlock(b, blockToNodes, nodeToBlock, visited);
+                }
             }
         }
     }
@@ -556,7 +559,7 @@
             }
         }
 
-        ArrayList<Node> newList = new ArrayList<>();
+        ArrayList<Node> newList = new ArrayList<>(oldList.size());
         assert oldList.get(0) == beginNode;
         unprocessed.clear(beginNode);
         newList.add(beginNode);
@@ -602,7 +605,7 @@
         blockToNodes.get(b).add(endNode);
     }
 
-    private static void processStack(ControlFlowGraph cfg, BlockMap<List<Node>> blockToNodes, NodeMap<Block> nodeToBlock, NodeBitMap visited, BlockMap<Boolean> floatingReads, Stack<Node> stack) {
+    private static void processStack(ControlFlowGraph cfg, BlockMap<List<Node>> blockToNodes, NodeMap<Block> nodeToBlock, NodeBitMap visited, BitSet floatingReads, NodeStack stack) {
         Block startBlock = cfg.getStartBlock();
         while (!stack.isEmpty()) {
             Node current = stack.peek();
@@ -637,24 +640,21 @@
                 stack.pop();
 
                 if (nodeToBlock.get(current) == null) {
-                    Node predecessor = current.predecessor();
-                    Block curBlock;
-                    if (predecessor != null) {
-                        // Predecessor determines block.
-                        curBlock = nodeToBlock.get(predecessor);
-                    } else {
+                    Block curBlock = cfg.blockFor(current);
+                    if (curBlock == null) {
+                        assert current.predecessor() == null && !(current instanceof FixedNode) : "The assignment of blocks to fixed nodes is already done when constructing the cfg.";
                         Block earliest = startBlock;
                         for (Node input : current.inputs()) {
-                            if (current instanceof FrameState && input instanceof StateSplit && ((StateSplit) input).stateAfter() == current) {
-                                // ignore
+                            Block inputEarliest;
+                            if (input instanceof ControlSplitNode) {
+                                inputEarliest = nodeToBlock.get(((ControlSplitNode) input).getPrimarySuccessor());
                             } else {
-                                Block inputEarliest;
-                                if (input instanceof ControlSplitNode) {
-                                    inputEarliest = nodeToBlock.get(((ControlSplitNode) input).getPrimarySuccessor());
-                                } else {
-                                    inputEarliest = nodeToBlock.get(input);
-                                }
-                                assert inputEarliest != null : current + " / " + input;
+                                inputEarliest = nodeToBlock.get(input);
+                            }
+                            if (inputEarliest == null) {
+                                assert current instanceof FrameState && input instanceof StateSplit && ((StateSplit) input).stateAfter() == current;
+                            } else {
+                                assert inputEarliest != null;
                                 if (earliest.getDominatorDepth() < inputEarliest.getDominatorDepth()) {
                                     earliest = inputEarliest;
                                 }
@@ -668,7 +668,7 @@
                     if (current instanceof FloatingReadNode) {
                         FloatingReadNode floatingReadNode = (FloatingReadNode) current;
                         if (curBlock.canKill(floatingReadNode.getLocationIdentity())) {
-                            floatingReads.put(curBlock, Boolean.TRUE);
+                            floatingReads.set(curBlock.getId());
                         }
                     }
                 }