changeset 2804:095162a84dcc

Introduced scheduling code.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Fri, 27 May 2011 18:44:13 +0200
parents 6a1e5d7e1f4e
children c3f64b66fc78
files graal/GraalCompiler/src/com/oracle/max/graal/schedule/Schedule.java graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java graal/GraalCompiler/src/com/sun/c1x/ir/Merge.java graal/GraalCompiler/src/com/sun/c1x/ir/Value.java
diffstat 4 files changed, 25 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/oracle/max/graal/schedule/Schedule.java	Fri May 27 18:14:36 2011 +0200
+++ b/graal/GraalCompiler/src/com/oracle/max/graal/schedule/Schedule.java	Fri May 27 18:44:13 2011 +0200
@@ -27,6 +27,7 @@
 import com.oracle.graal.graph.*;
 import com.sun.c1x.debug.*;
 import com.sun.c1x.ir.*;
+import com.sun.c1x.value.*;
 import com.sun.cri.ci.*;
 
 
@@ -153,16 +154,29 @@
                     predBlock.addSuccessor(block);
                 }
             }
-            if (n instanceof LoopBegin) {
-                LoopBegin loopBegin = (LoopBegin) n;
-                nodeToBlock.get(loopBegin.loopEnd()).addSuccessor(block);
-//                System.out.println("added LoopEnd to LoopBegin successor 2: " + loopBegin.loopEnd() + "->" + loopBegin);
+
+            if (n instanceof Merge) {
+                for (Node usage : n.usages()) {
+                    if (usage instanceof Phi) {
+                        nodeToBlock.set(usage, block);
+                    }
+                }
             }
         }
 
         computeDominators();
         assignLatestPossibleBlockToNodes();
         sortNodesWithinBlocks();
+
+        // Add successors of loop end nodes. Makes the graph cyclic.
+        for (Node n : blockBeginNodes) {
+            Block block = nodeToBlock.get(n);
+            if (n instanceof LoopBegin) {
+                LoopBegin loopBegin = (LoopBegin) n;
+                nodeToBlock.get(loopBegin.loopEnd()).addSuccessor(block);
+            }
+        }
+
         //print();
     }
 
@@ -213,6 +227,7 @@
 
     private void sortNodesWithinBlocks(Block b, NodeBitMap map) {
         List<Node> instructions = b.getInstructions();
+
         Collections.shuffle(instructions);
 
         List<Node> sortedInstructions = new ArrayList<Node>();
@@ -220,16 +235,18 @@
             addToSorting(b, i, sortedInstructions, map);
         }
         b.setInstructions(sortedInstructions);
+//        TTY.println("Block " + b);
+//        for (Node n : sortedInstructions) {
+//            TTY.println("Node: " + n);
+//        }
     }
 
     private void addToSorting(Block b, Node i, List<Node> sortedInstructions, NodeBitMap map) {
-        if (i == null || map.isMarked(i) || nodeToBlock.get(i) != b) {
+        if (i == null || map.isMarked(i) || nodeToBlock.get(i) != b || i instanceof Phi || i instanceof FrameState || i instanceof Local) {
             return;
         }
-        TTY.println("addToSorting " + i.id() + " " + i.getClass().getName());
 
         for (Node input : i.inputs()) {
-            if (input != null) TTY.println("visiting input " + input.id() + " " + input.getClass().getName());
             addToSorting(b, input, sortedInstructions, map);
         }
 
@@ -253,7 +270,6 @@
         while (!workList.isEmpty()) {
             Block b = workList.remove();
 
-            TTY.println("processing" + b);
             List<Block> predecessors = b.getPredecessors();
             if (predecessors.size() == 1) {
                 b.setDominator(predecessors.get(0));
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java	Fri May 27 18:14:36 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java	Fri May 27 18:44:13 2011 +0200
@@ -108,6 +108,7 @@
         Node sourceInstruction = source.getInstructions().get(source.getInstructions().size() - 1);
         Node targetInstruction = target.getInstructions().get(0);
         int sourceInstructionPredIndex = targetInstruction.predecessors().indexOf(sourceInstruction);
+        assert sourceInstructionPredIndex != -1 : "must find source instruction " + sourceInstruction + " in predecessor array of target instruction " + targetInstruction;
         int replacedIndex = targetInstruction.predecessorsIndex().get(sourceInstructionPredIndex);
         assert replacedIndex != -1 && sourceInstruction.successors().get(replacedIndex) != null;
         e.successors().setAndClear(1, sourceInstruction, replacedIndex);
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Merge.java	Fri May 27 18:14:36 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Merge.java	Fri May 27 18:44:13 2011 +0200
@@ -250,9 +250,4 @@
         }
         return sb.toString();
     }
-
-    @Override
-    public String shortName() {
-        return "Merge #" + id();
-    }
 }
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java	Fri May 27 18:14:36 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java	Fri May 27 18:44:13 2011 +0200
@@ -245,9 +245,6 @@
         }
         builder.append(getClass().getSimpleName());
         builder.append(" [").append(flagsToString()).append("]");
-        for (Node input : inputs()) {
-            TTY.println("input: " + input);
-        }
         return builder.toString();
     }