changeset 2960:49a8b14e9d24

Tentative change that adds successor tags.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Tue, 14 Jun 2011 16:41:27 +0200
parents 84a7b7069ffb
children 0966a5a904ad
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Instruction.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Value.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SplitCriticalEdgesPhase.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeArray.java
diffstat 8 files changed, 69 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Tue Jun 14 15:10:46 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Tue Jun 14 16:41:27 2011 +0200
@@ -1407,6 +1407,50 @@
         // Moves all stack values into their phi position
         LIRBlock bb = currentBlock;
         if (bb.numberOfSux() == 1) {
+
+            Node lastNode = bb.lastInstruction();
+            if (lastNode instanceof Instruction || lastNode == lastNode.graph().start()) {
+                Node nextInstr = lastNode.successors().get(Instruction.SUCCESSOR_NEXT);
+                int nextSuccIndex = lastNode.successorTags()[Instruction.SUCCESSOR_NEXT];
+
+                if (lastNode instanceof LoopEnd) {
+                    LoopEnd loopEnd = (LoopEnd) lastNode;
+                    nextInstr = loopEnd.loopBegin();
+                    nextSuccIndex = loopEnd.loopBegin().predecessors().size() + 1;
+                }
+                if (nextInstr instanceof Merge) {
+                    Merge merge = (Merge) nextInstr;
+                    assert nextSuccIndex > 0 : "nextSuccIndex=" + nextSuccIndex + ", lastNode=" + lastNode + ", nextInstr=" + nextInstr + "; preds=" + nextInstr.predecessors() + "; predIndex=" + nextInstr.predecessorsIndex();
+
+                    PhiResolver resolver = new PhiResolver(this);
+                    for (Node n : merge.usages()) {
+                        if (n instanceof Phi) {
+                            Phi phi = (Phi) n;
+                            if (!phi.isDead()) {
+                                Value curVal = phi.valueAt(nextSuccIndex - 1);
+                                if (curVal != null && curVal != phi) {
+                                    if (curVal instanceof Phi) {
+                                        operandForPhi((Phi) curVal);
+                                    }
+                                    CiValue operand = curVal.operand();
+                                    if (operand.isIllegal()) {
+                                        assert curVal instanceof Constant || curVal instanceof Local : "these can be produced lazily" + curVal + "/" + phi;
+                                        operand = operandForInstruction(curVal);
+                                    }
+                                    resolver.move(operand, operandForPhi(phi));
+                                }
+                            }
+                        }
+                    }
+                    resolver.dispose();
+                }
+                return;
+            }
+
+            assert false : "lastNode=" + lastNode + " instr=" + bb.getInstructions();
+
+
+
             LIRBlock sux = bb.suxAt(0);
             assert sux.numberOfPreds() > 0 : "invalid CFG";
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java	Tue Jun 14 15:10:46 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java	Tue Jun 14 16:41:27 2011 +0200
@@ -69,6 +69,8 @@
      */
     public void build() {
         new GraphBuilderPhase(compilation, compilation.method, false, false).apply(compilation.graph);
+
+
         printGraph("After GraphBuilding", compilation.graph);
         //new DuplicationPhase().apply(compilation.graph);
         new DeadCodeEliminationPhase().apply(compilation.graph);
@@ -79,6 +81,17 @@
             printGraph("After Ininling", compilation.graph);
         }
 
+        // Set successor tags
+        for (Node n : compilation.graph.getNodes()) {
+            if (n instanceof Merge) {
+                for (int i=0; i<n.predecessors().size(); ++i) {
+                    int predIndex = n.predecessorsIndex().get(i);
+                    Node pred = n.predecessors().get(i);
+                    pred.successorTags()[predIndex] = (i + 1);
+                }
+            }
+        }
+
         if (GraalOptions.Time) {
             GraalTimers.COMPUTE_LINEAR_SCAN_ORDER.start();
         }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Instruction.java	Tue Jun 14 15:10:46 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Instruction.java	Tue Jun 14 16:41:27 2011 +0200
@@ -22,8 +22,6 @@
  */
 package com.oracle.max.graal.compiler.ir;
 
-import java.util.*;
-
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.value.*;
 import com.oracle.max.graal.graph.*;
@@ -88,16 +86,6 @@
         GraalMetrics.HIRInstructions++;
     }
 
-
-    /**
-     * Gets the list of predecessors of this block.
-     * @return the predecessor list
-     */
-    @SuppressWarnings({ "unchecked", "rawtypes" })
-    public List<Instruction> blockPredecessors() {
-        return (List) Collections.unmodifiableList(predecessors());
-    }
-
     /**
      * Get the number of predecessors.
      * @return the number of predecessors
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Value.java	Tue Jun 14 15:10:46 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Value.java	Tue Jun 14 16:41:27 2011 +0200
@@ -134,19 +134,6 @@
         return null; // default: unknown declared type
     }
 
-    /**
-     * Apply the specified closure to all the input values of this instruction.
-     * @param closure the closure to apply
-     */
-    public void inputValuesDo(ValueClosure closure) {
-        for (int i = 0; i < inputs().size(); i++) {
-            inputs().set(i, closure.apply((Value) inputs().get(i)));
-        }
-        for (int i = 0; i < successors().size(); i++) {
-            successors().set(i, closure.apply((Value) successors().get(i)));
-        }
-    }
-
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java	Tue Jun 14 15:10:46 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java	Tue Jun 14 16:41:27 2011 +0200
@@ -193,8 +193,8 @@
         for (Node n : graph.getNodes()) {
             if (n instanceof Placeholder) {
                 Placeholder p = (Placeholder) n;
-                assert p.blockPredecessors().size() == 1;
-                Node pred = p.blockPredecessors().get(0);
+                assert p.predecessors().size() == 1;
+                Node pred = p.predecessors().get(0);
                 int predIndex = p.predecessorsIndex().get(0);
                 pred.successors().setAndClear(predIndex, p, 0);
                 p.delete();
@@ -1123,8 +1123,6 @@
 
         if (block.firstInstruction == null) {
             if (block.isLoopHeader) {
-//                block.firstInstruction = new Merge(block.startBci, graph);
-
                 LoopBegin loopBegin = new LoopBegin(graph);
                 LoopEnd loopEnd = new LoopEnd(graph);
                 loopEnd.setLoopBegin(loopBegin);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SplitCriticalEdgesPhase.java	Tue Jun 14 15:10:46 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SplitCriticalEdgesPhase.java	Tue Jun 14 16:41:27 2011 +0200
@@ -43,6 +43,7 @@
                         Anchor a = new Anchor(graph);
                         a.successors().setAndClear(Instruction.SUCCESSOR_NEXT, n, j);
                         n.successors().set(j, a);
+                        n.successorTags()[j] = 1;
                     }
                 }
             }
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java	Tue Jun 14 15:10:46 2011 +0200
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java	Tue Jun 14 16:41:27 2011 +0200
@@ -40,6 +40,7 @@
     final ArrayList<Node> usages;
     final ArrayList<Node> predecessors;
     final ArrayList<Integer> predecessorsIndex;
+    final int[] successorTags;
 
     public Node(int inputCount, int successorCount, Graph graph) {
         assert graph != null : "cannot create a node for a null graph";
@@ -47,6 +48,7 @@
         this.id = graph.register(this);
         this.inputs = new NodeArray(this, inputCount);
         this.successors = new NodeArray(this, successorCount);
+        this.successorTags = new int[successorCount];
         this.predecessors = new ArrayList<Node>();
         this.usages = new ArrayList<Node>();
         this.predecessorsIndex = new ArrayList<Integer>();
@@ -71,6 +73,10 @@
     public NodeArray successors() {
         return successors;
     }
+    
+    public int[] successorTags() {
+        return successorTags;
+    }
 
     public int id() {
         return id;
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeArray.java	Tue Jun 14 15:10:46 2011 +0200
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeArray.java	Tue Jun 14 16:41:27 2011 +0200
@@ -26,6 +26,8 @@
 import java.util.Arrays;
 import java.util.Iterator;
 
+import org.omg.PortableInterceptor.SUCCESSFUL;
+
 public class NodeArray extends AbstractList<Node> {
 
     private final Node node;
@@ -149,6 +151,7 @@
         assert !self().isDeleted() : "trying to setAndClear successor of deleted node: " + self().shortName();
         assert self().successors == this;
         Node value = clearedNode.successors.get(clearedIndex);
+        self().successorTags[index] = clearedNode.successorTags[clearedIndex];
         assert value != Node.Null;
         clearedNode.successors.nodes[clearedIndex] = Node.Null;
         set(index, Node.Null);