changeset 3107:9ef0777a61d5

Merge
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Thu, 30 Jun 2011 10:07:49 +0200
parents d9fa4309f89e (diff) c49c893c3d27 (current diff)
children 44b3508a12c8
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinter.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java src/share/tools/IdealGraphVisualizer/Text Editor/build/classes/at/ssw/visualizer/texteditor/Bundle.properties src/share/tools/IdealGraphVisualizer/Text Editor/build/classes/at/ssw/visualizer/texteditor/layer.xml src/share/tools/IdealGraphVisualizer/Text Editor/build/classes/at/ssw/visualizer/texteditor/preferences.xml src/share/tools/IdealGraphVisualizer/Text Editor/build/depcache/dependencies.txt src/share/tools/IdealGraphVisualizer/Text Editor/build/no-license.txt
diffstat 7 files changed, 127 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinter.java	Wed Jun 29 20:11:13 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinter.java	Thu Jun 30 10:07:49 2011 +0200
@@ -130,9 +130,9 @@
         }
         List<Loop> loops = null;
         try {
-            LoopUtil.computeLoops(graph);
+            loops = LoopUtil.computeLoops(graph);
         } catch (Throwable t) {
-
+            t.printStackTrace();
         }
 
         stream.println("  <nodes>");
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java	Wed Jun 29 20:11:13 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java	Thu Jun 30 10:07:49 2011 +0200
@@ -325,12 +325,12 @@
                     Merge merge = new Merge(graph);
                     assert p.predecessors().size() == 1 : "predecessors size: " + p.predecessors().size();
                     FixedNode next = p.next();
-                    p.setNext(null);
                     EndNode end = new EndNode(graph);
-                    p.replaceAndDelete(end);
+                    p.setNext(end);
                     merge.setNext(next);
                     merge.addEnd(end);
                     merge.setStateAfter(existingState);
+                    p.setStateAfter(existingState.duplicate(bci));
                     if (!(next instanceof LoopEnd)) {
                         target.firstInstruction = merge;
                     }
@@ -1203,7 +1203,14 @@
             } else {
                 EndNode end = new EndNode(graph);
                 ((Merge) result).addEnd(end);
-                result = end;
+                Placeholder p = new Placeholder(graph);
+                int bci = block.startBci;
+                if (block instanceof ExceptionBlock) {
+                    bci = ((ExceptionBlock) block).deoptBci;
+                }
+                p.setStateAfter(stateAfter.duplicate(bci));
+                p.setNext(end);
+                result = p;
             }
         }
         assert !(result instanceof LoopBegin || result instanceof Merge);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoopPhase.java	Wed Jun 29 20:11:13 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoopPhase.java	Thu Jun 30 10:07:49 2011 +0200
@@ -38,14 +38,14 @@
     protected void run(Graph graph) {
         List<Loop> loops = LoopUtil.computeLoops(graph);
 
+        for (Loop loop : loops) {
+            LoopUtil.peelLoop(loop);
+        }
+        loops = LoopUtil.computeLoops(graph); // TODO (gd) avoid recomputing loops
+
 //        for (Loop loop : loops) {
-//            LoopUtil.peelLoop(loop);
+//            doLoopCounters(loop);
 //        }
-//        loops = LoopUtil.computeLoops(graph); // TODO (gd) avoid recomputing loops
-
-        for (Loop loop : loops) {
-            doLoopCounters(loop);
-        }
     }
 
     private void doLoopCounters(Loop loop) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/Block.java	Wed Jun 29 20:11:13 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/Block.java	Thu Jun 30 10:07:49 2011 +0200
@@ -24,7 +24,6 @@
 
 import java.util.*;
 
-import com.oracle.max.graal.compiler.debug.*;
 import com.oracle.max.graal.compiler.ir.*;
 import com.oracle.max.graal.graph.*;
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/GraphUtil.java	Wed Jun 29 20:11:13 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/GraphUtil.java	Thu Jun 30 10:07:49 2011 +0200
@@ -35,13 +35,55 @@
 
     public static interface ColoringLambda<T> {
         T color(Iterable<T> incomming, Merge merge);
+        T danglingColor(Iterable<T> incomming, Merge merge);
     }
 
     /**
      * colors down, applying the lambda at merge points, starting at the pre-colored points.
      */
     public static <T> void colorCFGDown(NodeMap<T> colors, ColoringLambda<T> lambda) {
-        List<Node> startingPoints = new LinkedList<Node>();
+        Set<Merge> delayed = new HashSet<Merge>();
+        Set<Node> currentPoints = new HashSet<Node>();
+        Set<Node> otherPoints = new HashSet<Node>();
+        Set<Merge> otherMerges = new HashSet<Merge>();
+        for (Entry<Node, T> entry : colors.entries()) {
+            currentPoints.add(entry.getKey());
+        }
+        ArrayList<T> incomming = new ArrayList<T>(2);
+        while (!currentPoints.isEmpty()) {
+            for (Node node : currentPoints) {
+                otherMerges.addAll(colorCFGDownToMerge(node, colors.get(node), colors));
+            }
+            for (Merge merge : otherMerges) {
+                incomming.clear();
+                for (EndNode end : merge.cfgPredecessors()) {
+                    incomming.add(colors.get(end));
+                }
+                T color = lambda.color(incomming, merge);
+                if (color != null) {
+                    colors.set(merge, color);
+                    colors.set(merge.next(), color);
+                    otherPoints.add(merge.next());
+                    delayed.remove(merge);
+                } else {
+                    delayed.add(merge);
+                }
+            }
+            Set<Node> tmp = currentPoints;
+            currentPoints = otherPoints;
+            otherPoints = tmp;
+            otherPoints.clear();
+            otherMerges.clear();
+        }
+        for (Merge merge : delayed) {
+            T color = lambda.danglingColor(incomming, merge);
+            if (color != null) {
+                colors.set(merge, color);
+            }
+        }
+
+
+        /*List<Node> startingPoints = new LinkedList<Node>();
         for (Entry<Node, T> entry : colors.entries()) {
             startingPoints.add(entry.getKey());
         }
@@ -65,9 +107,10 @@
                 colors.set(merge, color);
                 work.addAll(colorCFGDownToMerge(merge.next(), color, colors));
             } else {
+                System.out.println("Can not color " + merge);
                 work.addAgain(merge);
             }
-        }
+        }*/
     }
 
     private static <T> Collection<Merge> colorCFGDownToMerge(Node from, T color, NodeMap<T> colors) {
@@ -155,12 +198,9 @@
                                     Value v = phi.valueAt(i);
                                     if (v == node) {
                                         T color = internalColoring.get(merge.phiPredecessorAt(i));
-                                        if (color == null) {
-                                            //System.out.println("Split : color from " + usage + " is null");
-                                            delay = true;
-                                            break;
+                                        if (color != null) {
+                                            colors.add(color);
                                         }
-                                        colors.add(color);
                                     }
                                 }
                             } else {
@@ -265,7 +305,7 @@
                 }
                 Map<String, Object> debug = new HashMap<String, Object>();
                 debug.put("split", debugColoring);
-                compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, "RuntimeException in split", coloring.graph(), true, false, debug));
+                compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, "RuntimeException in split", coloring.graph(), true, false, true, debug));
             }
         }
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/LoopUtil.java	Wed Jun 29 20:11:13 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/LoopUtil.java	Thu Jun 30 10:07:49 2011 +0200
@@ -147,9 +147,6 @@
                         if (merge instanceof LoopBegin) {
                             LoopBegin phiLoop = (LoopBegin) merge;
                             int backIndex = phiLoop.phiPredecessorIndex(phiLoop.loopEnd());
-                            if (backIndex >= phi.valueCount()) {
-                                System.out.println("Wierd phi : " + phi);
-                            }
                             if (phi.valueAt(backIndex) == n) {
                                 continue;
                             }
@@ -162,8 +159,25 @@
         NodeBitMap inOrBefore = loopBegin.graph().createNodeBitMap();
         for (Node n : workData2) {
             inOrBefore.mark(n);
-            for (Node input : n.dataInputs()) {
-                workData2.add(input);
+            if (n instanceof Phi) {
+                Phi phi = (Phi) n;
+                if (!phi.isDead()) {
+                    int backIndex = -1;
+                    Merge merge = phi.merge();
+                    if (merge instanceof LoopBegin) {
+                        LoopBegin phiLoop = (LoopBegin) merge;
+                        backIndex = phiLoop.phiPredecessorIndex(phiLoop.loopEnd());
+                    }
+                    for (int i = 0; i < phi.valueCount(); i++) {
+                        if (i != backIndex) {
+                            workData2.add(phi.valueAt(i));
+                        }
+                    }
+                }
+            } else {
+                for (Node input : n.dataInputs()) {
+                    workData2.add(input);
+                }
             }
             if (n instanceof Merge) { //add phis & counters
                 for (Node usage : n.dataUsages()) {
@@ -171,7 +185,7 @@
                 }
             }
         }
-        /*if (!recurse) {
+        if (!recurse) {
             recurse = true;
             GraalCompilation compilation = GraalCompilation.compilation();
             if (compilation.compiler.isObserved()) {
@@ -182,7 +196,7 @@
                 compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, "Compute loop nodes", loopBegin.graph(), true, false, debug));
             }
             recurse = false;
-        }*/
+        }
         inOrAfter.setIntersect(inOrBefore);
         loopNodes.setUnion(inOrAfter);
         return loopNodes;
@@ -260,13 +274,7 @@
         LoopBegin loopBegin = loop.loopBegin();
         Graph graph = loopBegin.graph();
         Node loopPred = loopBegin.singlePredecessor();
-        if (loopPred instanceof FixedNodeWithNext) {
-            ((FixedNodeWithNext) loopPred).setNext(peeling.begin);
-        } else if (loopPred instanceof StartNode) {
-            ((StartNode) loopPred).setStart(peeling.begin);
-        } else {
-            Util.shouldNotReachHere();
-        }
+        loopPred.successors().replace(loopBegin.forwardEdge(), peeling.begin);
         NodeBitMap loopNodes = loop.nodes();
         Node originalLast = from;
         if (originalLast == loopBegin.loopEnd()) {
@@ -346,7 +354,7 @@
                         phiMap = graph.createNodeMap();
                         newExitValues.set(originalValue, phiMap);
                     }
-                    phiMap.set(oEnd, (Value) originalValue);
+                    phiMap.set(original, (Value) originalValue);
                     phiMap.set(nEnd, (Value) newValue);
 
                     phiMap = newExitValues.get(newValue);
@@ -354,7 +362,7 @@
                         phiMap = graph.createNodeMap();
                         newExitValues.set(newValue, phiMap);
                     }
-                    phiMap.set(oEnd, (Value) originalValue);
+                    phiMap.set(original, (Value) originalValue);
                     phiMap.set(nEnd, (Value) newValue);
                 }
             }
@@ -399,7 +407,7 @@
 
         // prepare inital colors
         for (Node exitPoint : exitPoints) {
-                colors.set(exitPoint, exitPoint);
+            colors.set(exitPoint, exitPoint);
         }
 
         /*System.out.println("newExitValues");
@@ -427,6 +435,19 @@
                 }
                 return color;
             }
+            @Override
+            public Node danglingColor(Iterable<Node> incomming, Merge merge) {
+                Node color = null;
+                for (Node c : incomming) {
+                    if (color == null) {
+                        color = c;
+                    } else if (color != c) {
+                        return merge;
+                    }
+                }
+                assert color != null;
+                return color;
+            }
         });
 
         final NodeBitMap inOrBefore = inOrBefore(loop);
@@ -447,6 +468,7 @@
             private Value getValueAt(Node point, NodeMap<Value> valueMap, CiKind kind) {
                 Value value = valueMap.get(point);
                 if (value != null) {
+                    //System.out.println("getValueAt(" + point + ", valueMap, kind) = " + value);
                     return value;
                 }
                 Merge merge = (Merge) point;
@@ -468,10 +490,12 @@
                     for (EndNode end : merge.cfgPredecessors()) {
                         phi.addInput(getValueAt(colors.get(end), valueMap, kind));
                     }
+                    //System.out.println("getValueAt(" + point + ", valueMap, kind) = " + phi);
                     return phi;
                 } else {
                     assert v != null;
                     valueMap.set(point, v);
+                    //System.out.println("getValueAt(" + point + ", valueMap, kind) = " + v);
                     return v;
                 }
             }
@@ -481,6 +505,7 @@
             }
             @Override
             public void fixNode(Node node, Node color) {
+                //System.out.println("fixNode(" + node + ", " + color + ")");
                 for (int i = 0; i < node.inputs().size(); i++) {
                     Node input = node.inputs().get(i);
                     if (input == null || newExitValues.isNew(input)) {
@@ -489,9 +514,7 @@
                     NodeMap<Value> valueMap = newExitValues.get(input);
                     if (valueMap != null) {
                         Value replacement = getValueAt(color, valueMap, ((Value) input).kind);
-                        //if (!(replacement instanceof Phi && replacement == node)) { // handle the Phi that were created when merging loop exits
-                            node.inputs().set(i, replacement);
-                        //}
+                        node.inputs().set(i, replacement);
                     }
                 }
             }
@@ -516,6 +539,12 @@
         LoopBegin loopBegin = loop.loopBegin();
         Graph graph = loopBegin.graph();
         NodeBitMap marked = computeLoopNodesFrom(loopBegin, from);
+        GraalCompilation compilation = GraalCompilation.compilation();
+        if (compilation.compiler.isObserved()) {
+            Map<String, Object> debug = new HashMap<String, Object>();
+            debug.put("marked", marked);
+            compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, "After computeLoopNodesFrom", loopBegin.graph(), true, false, debug));
+        }
         if (from == loopBegin.loopEnd()) {
             marked.clear(from);
         }
@@ -553,7 +582,7 @@
             }
         }
 
-        GraalCompilation compilation = GraalCompilation.compilation();
+        //GraalCompilation compilation = GraalCompilation.compilation();
         if (compilation.compiler.isObserved()) {
             Map<String, Object> debug = new HashMap<String, Object>();
             debug.put("marked", marked);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameState.java	Wed Jun 29 20:11:13 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameState.java	Thu Jun 30 10:07:49 2011 +0200
@@ -480,9 +480,17 @@
 
     @Override
     public String toString() {
-        /*StringBuilder sb = new StringBuilder();
+        return super.toString();
+    }
+
+    public String toDetailedString() {
+        StringBuilder sb = new StringBuilder();
         String nl = String.format("%n");
-        sb.append("[bci: ").append(bci).append("]").append(nl);
+        sb.append("[bci: ").append(bci).append("]");
+        if (rethrowException()) {
+            sb.append(" rethrows Exception");
+        }
+        sb.append(nl);
         for (int i = 0; i < localsSize(); ++i) {
             Value value = localAt(i);
             sb.append(String.format("  local[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value));
@@ -495,8 +503,7 @@
             Value value = lockAt(i);
             sb.append(String.format("  lock[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value));
         }
-        return sb.toString();*/
-        return super.toString();
+        return sb.toString();
     }
 
     @Override