changeset 19660:e17923568367

Handle case in new earliest schedule when end node and begin node are identical.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 02 Mar 2015 19:09:46 +0100
parents 84776a6314d7
children c96f8337292e
files graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java
diffstat 1 files changed, 34 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Mon Mar 02 17:07:51 2015 +0100
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Mon Mar 02 19:09:46 2015 +0100
@@ -348,8 +348,8 @@
         // Add begin nodes as the first entry and set the block for phi nodes.
         for (Block b : cfg.getBlocks()) {
             AbstractBeginNode beginNode = b.getBeginNode();
+            ArrayList<ValueNode> nodes = new ArrayList<>();
             nodeToBlock.set(beginNode, b);
-            ArrayList<ValueNode> nodes = new ArrayList<>();
             nodes.add(beginNode);
             blockToNodes.put(b, nodes);
 
@@ -399,12 +399,20 @@
 
         // Add end nodes as the last nodes in each block.
         for (Block b : cfg.getBlocks()) {
-            blockToNodes.get(b).add(b.getEndNode());
+            FixedNode endNode = b.getEndNode();
+            if (endNode != b.getBeginNode()) {
+                addNode(blockToNodes, b, endNode);
+            }
         }
 
         this.blockToNodesMap = blockToNodes;
     }
 
+    private static void addNode(BlockMap<List<ValueNode>> blockToNodes, Block b, ValueNode endNode) {
+        assert !blockToNodes.get(b).contains(endNode) : endNode;
+        blockToNodes.get(b).add(endNode);
+    }
+
     private void processStack(BlockMap<List<ValueNode>> blockToNodes, NodeMap<Block> nodeToBlock, NodeBitMap visited, Stack<Node> stack) {
         Block startBlock = cfg.getStartBlock();
         while (!stack.isEmpty()) {
@@ -439,36 +447,35 @@
 
                 if (nodeToBlock.get(current) == null) {
                     Node predecessor = current.predecessor();
-                    if (nodeToBlock.get(current) == null) {
-                        Block curBlock;
-                        if (predecessor != null) {
-                            // Predecessor determines block.
-                            curBlock = nodeToBlock.get(predecessor);
-                        } else {
-                            Block earliest = startBlock;
-                            for (Node input : current.inputs()) {
-                                if (current instanceof FrameState && input instanceof StateSplit && ((StateSplit) input).stateAfter() == current) {
-                                    // ignore
+                    Block curBlock;
+                    if (predecessor != null) {
+                        // Predecessor determines block.
+                        curBlock = nodeToBlock.get(predecessor);
+                    } else {
+                        Block earliest = startBlock;
+                        for (Node input : current.inputs()) {
+                            if (current instanceof FrameState && input instanceof StateSplit && ((StateSplit) input).stateAfter() == current) {
+                                // ignore
+                            } else {
+                                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;
-                                    if (earliest.getDominatorDepth() < inputEarliest.getDominatorDepth()) {
-                                        earliest = inputEarliest;
-                                    }
+                                    inputEarliest = nodeToBlock.get(input);
+                                }
+                                assert inputEarliest != null : current + " / " + input;
+                                if (earliest.getDominatorDepth() < inputEarliest.getDominatorDepth()) {
+                                    earliest = inputEarliest;
                                 }
                             }
-                            curBlock = earliest;
                         }
-                        if (current instanceof ValueNode) {
-                            blockToNodes.get(curBlock).add((ValueNode) current);
-                        }
-                        nodeToBlock.set(current, curBlock);
+                        curBlock = earliest;
                     }
+                    assert curBlock != null;
+                    if (current instanceof ValueNode) {
+                        addNode(blockToNodes, curBlock, (ValueNode) current);
+                    }
+                    nodeToBlock.set(current, curBlock);
                 }
             }
         }