changeset 2864:32c3d7b51716

Merge
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Tue, 07 Jun 2011 17:05:13 +0200
parents 4f64bd98f9dc 45422967cbcf
children 7a4e6e11877f
files graal/GraalCompiler/src/com/sun/c1x/ir/Materialize.java
diffstat 8 files changed, 236 insertions(+), 167 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Tue Jun 07 17:04:55 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Tue Jun 07 17:05:13 2011 +0200
@@ -577,7 +577,7 @@
     private void genCompareOp(CiKind kind, int opcode, CiKind resultKind) {
         Value y = frameState.pop(kind);
         Value x = frameState.pop(kind);
-        Value value = append(new Materialize(opcode, resultKind, x, y, graph));
+        Value value = append(new NormalizeCompare(opcode, resultKind, x, y, graph));
         if (!resultKind.isVoid()) {
             frameState.ipush(value);
         }
@@ -602,7 +602,7 @@
 
     private void ifNode(Value x, Condition cond, Value y) {
         assert !x.isDeleted() && !y.isDeleted();
-        If ifNode = new If(x, cond, y, graph);
+        If ifNode = new If(new Compare(x, cond, y, graph), graph);
         append(ifNode);
         Instruction tsucc = createTargetAt(stream().readBranchDest(), frameState);
         ifNode.setBlockSuccessor(0, tsucc);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Compare.java	Tue Jun 07 17:05:13 2011 +0200
@@ -0,0 +1,141 @@
+
+/*
+ * Copyright (c) 2011, 2011, 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.sun.c1x.ir;
+
+import com.oracle.graal.graph.*;
+import com.sun.c1x.debug.*;
+import com.sun.c1x.util.*;
+import com.sun.cri.ci.*;
+
+public final class Compare extends Value {
+
+    private static final int INPUT_COUNT = 2;
+    private static final int INPUT_X = 0;
+    private static final int INPUT_Y = 1;
+
+    private static final int SUCCESSOR_COUNT = 0;
+
+    @Override
+    protected int inputCount() {
+        return super.inputCount() + INPUT_COUNT;
+    }
+
+    @Override
+    protected int successorCount() {
+        return super.successorCount() + SUCCESSOR_COUNT;
+    }
+
+    /**
+     * The instruction that produces the first input to this comparison.
+     */
+     public Value x() {
+        return (Value) inputs().get(super.inputCount() + INPUT_X);
+    }
+
+    public Value setX(Value n) {
+        return (Value) inputs().set(super.inputCount() + INPUT_X, n);
+    }
+
+    /**
+     * The instruction that produces the second input to this comparison.
+     */
+    public Value y() {
+        return (Value) inputs().get(super.inputCount() + INPUT_Y);
+    }
+
+    public Value setY(Value n) {
+        return (Value) inputs().set(super.inputCount() + INPUT_Y, n);
+    }
+
+    Condition condition;
+    boolean unorderedIsTrue;
+
+    /**
+     * Constructs a new If instruction.
+     * @param x the instruction producing the first input to the instruction
+     * @param condition the condition (comparison operation)
+     * @param y the instruction that produces the second input to this instruction
+     * @param graph
+     */
+    public Compare(Value x, Condition condition, Value y, Graph graph) {
+        super(CiKind.Illegal, INPUT_COUNT, SUCCESSOR_COUNT, graph);
+        assert (x == null && y == null) || Util.archKindsEqual(x, y);
+        this.condition = condition;
+        setX(x);
+        setY(y);
+    }
+
+    /**
+     * Gets the condition (comparison operation) for this instruction.
+     * @return the condition
+     */
+    public Condition condition() {
+        return condition;
+    }
+
+    /**
+     * Checks whether unordered inputs mean true or false.
+     * @return {@code true} if unordered inputs produce true
+     */
+    public boolean unorderedIsTrue() {
+        return unorderedIsTrue;
+    }
+
+    /**
+     * Swaps the operands to this if and reverses the condition (e.g. > goes to <=).
+     * @see Condition#mirror()
+     */
+    public void swapOperands() {
+        condition = condition.mirror();
+        Value t = x();
+        setX(y());
+        setY(t);
+    }
+
+    @Override
+    public void accept(ValueVisitor v) {
+    }
+
+    @Override
+    public void print(LogStream out) {
+        out.print("comp ").
+        print(x()).
+        print(' ').
+        print(condition().operator).
+        print(' ').
+        print(y());
+    }
+
+    @Override
+    public String shortName() {
+        return "Comp " + condition.operator;
+    }
+
+    @Override
+    public Node copy(Graph into) {
+        Compare x = new Compare(null, condition, null, into);
+        x.unorderedIsTrue = unorderedIsTrue;
+        return x;
+    }
+}
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/If.java	Tue Jun 07 17:04:55 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/If.java	Tue Jun 07 17:05:13 2011 +0200
@@ -33,9 +33,8 @@
  */
 public final class If extends BlockEnd {
 
-    private static final int INPUT_COUNT = 2;
-    private static final int INPUT_X = 0;
-    private static final int INPUT_Y = 1;
+    private static final int INPUT_COUNT = 1;
+    private static final int INPUT_COMPARE = 0;
 
     private static final int SUCCESSOR_COUNT = 0;
 
@@ -52,57 +51,17 @@
     /**
      * The instruction that produces the first input to this comparison.
      */
-     public Value x() {
-        return (Value) inputs().get(super.inputCount() + INPUT_X);
+     public Compare compare() {
+        return (Compare) inputs().get(super.inputCount() + INPUT_COMPARE);
     }
 
-    public Value setX(Value n) {
-        return (Value) inputs().set(super.inputCount() + INPUT_X, n);
+    public Value setCompare(Compare n) {
+        return (Value) inputs().set(super.inputCount() + INPUT_COMPARE, n);
     }
 
-    /**
-     * The instruction that produces the second input to this comparison.
-     */
-    public Value y() {
-        return (Value) inputs().get(super.inputCount() + INPUT_Y);
-    }
-
-    public Value setY(Value n) {
-        return (Value) inputs().set(super.inputCount() + INPUT_Y, n);
-    }
-
-    Condition condition;
-    boolean unorderedIsTrue;
-
-    /**
-     * Constructs a new If instruction.
-     * @param x the instruction producing the first input to the instruction
-     * @param condition the condition (comparison operation)
-     * @param y the instruction that produces the second input to this instruction
-     * @param graph
-     */
-    public If(Value x, Condition condition, Value y, Graph graph) {
+    public If(Compare compare, Graph graph) {
         super(CiKind.Illegal, 2, INPUT_COUNT, SUCCESSOR_COUNT, graph);
-        assert (x == null && y == null) || Util.archKindsEqual(x, y);
-        this.condition = condition;
-        setX(x);
-        setY(y);
-    }
-
-    /**
-     * Gets the condition (comparison operation) for this instruction.
-     * @return the condition
-     */
-    public Condition condition() {
-        return condition;
-    }
-
-    /**
-     * Checks whether unordered inputs mean true or false.
-     * @return {@code true} if unordered inputs produce true
-     */
-    public boolean unorderedIsTrue() {
-        return unorderedIsTrue;
+        setCompare(compare);
     }
 
     /**
@@ -130,38 +89,6 @@
         return blockSuccessor(istrue ? 0 : 1);
     }
 
-    /**
-     * Gets the successor of this instruction for the unordered case.
-     * @return the successor for unordered inputs
-     */
-    public Instruction unorderedSuccessor() {
-        return successor(unorderedIsTrue());
-    }
-
-    /**
-     * Swaps the operands to this if and reverses the condition (e.g. > goes to <=).
-     * @see Condition#mirror()
-     */
-    public void swapOperands() {
-        condition = condition.mirror();
-        Value t = x();
-        setX(y());
-        setY(t);
-    }
-
-    /**
-     * Swaps the successor blocks to this if and negates the condition (e.g. == goes to !=)
-     * @see Condition#negate()
-     */
-    public void swapSuccessors() {
-        unorderedIsTrue = !unorderedIsTrue;
-        condition = condition.negate();
-        Instruction t = blockSuccessor(0);
-        Instruction f = blockSuccessor(1);
-        setBlockSuccessor(0, f);
-        setBlockSuccessor(1, t);
-    }
-
     @Override
     public void accept(ValueVisitor v) {
         v.visitIf(this);
@@ -170,11 +97,11 @@
     @Override
     public void print(LogStream out) {
         out.print("if ").
-        print(x()).
+        print(compare().x()).
         print(' ').
-        print(condition().operator).
+        print(compare().condition().operator).
         print(' ').
-        print(y()).
+        print(compare().y()).
         print(" then ").
         print(blockSuccessors().get(0)).
         print(" else ").
@@ -183,13 +110,11 @@
 
     @Override
     public String shortName() {
-        return "If " + condition.operator;
+        return "If " + compare().condition.operator;
     }
 
     @Override
     public Node copy(Graph into) {
-        If x = new If(null, condition, null, into);
-        x.unorderedIsTrue = unorderedIsTrue;
-        return x;
+        return new If(compare(), into);
     }
 }
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Materialize.java	Tue Jun 07 17:04:55 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2009, 2011, 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.sun.c1x.ir;
-
-import com.oracle.graal.graph.*;
-import com.sun.c1x.debug.*;
-import com.sun.cri.bytecode.*;
-import com.sun.cri.ci.*;
-
-/**
- * The {@code CompareOp} instruction represents comparisons such as equals, not equal, etc.
- */
-public final class Materialize extends Binary {
-
-    private static final int INPUT_COUNT = 0;
-    private static final int SUCCESSOR_COUNT = 0;
-
-    /**
-     * Creates a new compare operation.
-     * @param opcode the bytecode opcode
-     * @param kind the result kind
-     * @param x the first input
-     * @param y the second input
-     */
-    public Materialize(int opcode, CiKind kind, Value x, Value y, Graph graph) {
-        super(kind, opcode, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph);
-    }
-
-    @Override
-    public void accept(ValueVisitor v) {
-        v.visitMaterialize(this);
-    }
-
-    @Override
-    public void print(LogStream out) {
-        out.print(x()).
-            print(' ').
-            print(Bytecodes.operator(opcode)).
-            print(' ').
-            print(y());
-    }
-
-    @Override
-    public Node copy(Graph into) {
-        Materialize x = new Materialize(opcode, kind, null, null, into);
-        return x;
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/NormalizeCompare.java	Tue Jun 07 17:05:13 2011 +0200
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2009, 2011, 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.sun.c1x.ir;
+
+import com.oracle.graal.graph.*;
+import com.sun.c1x.debug.*;
+import com.sun.cri.bytecode.*;
+import com.sun.cri.ci.*;
+
+/**
+ * Returns -1, 0, or 1 if either x > y, x == y, or x < y.
+ */
+public final class NormalizeCompare extends Binary {
+
+    private static final int INPUT_COUNT = 0;
+    private static final int SUCCESSOR_COUNT = 0;
+
+    /**
+     * Creates a new compare operation.
+     * @param opcode the bytecode opcode
+     * @param kind the result kind
+     * @param x the first input
+     * @param y the second input
+     */
+    public NormalizeCompare(int opcode, CiKind kind, Value x, Value y, Graph graph) {
+        super(kind, opcode, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph);
+    }
+
+    @Override
+    public void accept(ValueVisitor v) {
+        v.visitMaterialize(this);
+    }
+
+    @Override
+    public void print(LogStream out) {
+        out.print(x()).
+            print(' ').
+            print(Bytecodes.operator(opcode)).
+            print(' ').
+            print(y());
+    }
+
+    @Override
+    public Node copy(Graph into) {
+        return new NormalizeCompare(opcode, kind, null, null, into);
+    }
+}
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/ValueVisitor.java	Tue Jun 07 17:04:55 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/ValueVisitor.java	Tue Jun 07 17:05:13 2011 +0200
@@ -35,7 +35,7 @@
     public abstract void visitArrayLength(ArrayLength i);
     public abstract void visitMerge(Merge i);
     public abstract void visitCheckCast(CheckCast i);
-    public abstract void visitMaterialize(Materialize i);
+    public abstract void visitMaterialize(NormalizeCompare i);
     public abstract void visitConstant(Constant i);
     public abstract void visitConvert(Convert i);
     public abstract void visitExceptionObject(ExceptionObject i);
--- a/graal/GraalCompiler/src/com/sun/c1x/target/amd64/AMD64LIRGenerator.java	Tue Jun 07 17:04:55 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/target/amd64/AMD64LIRGenerator.java	Tue Jun 07 17:05:13 2011 +0200
@@ -417,7 +417,7 @@
     }
 
     @Override
-    public void visitMaterialize(Materialize x) {
+    public void visitMaterialize(NormalizeCompare x) {
         LIRItem left = new LIRItem(x.x(), this);
         LIRItem right = new LIRItem(x.y(), this);
         if (!x.kind.isVoid() && x.x().kind.isLong()) {
@@ -472,12 +472,12 @@
 
     @Override
     public void visitIf(If x) {
-        CiKind kind = x.x().kind;
+        CiKind kind = x.compare().x().kind;
 
-        Condition cond = x.condition();
+        Condition cond = x.compare().condition();
 
-        LIRItem xitem = new LIRItem(x.x(), this);
-        LIRItem yitem = new LIRItem(x.y(), this);
+        LIRItem xitem = new LIRItem(x.compare().x(), this);
+        LIRItem yitem = new LIRItem(x.compare().y(), this);
         LIRItem xin = xitem;
         LIRItem yin = yitem;
 
@@ -504,8 +504,12 @@
         CiValue left = xin.result();
         CiValue right = yin.result();
         lir.cmp(cond, left, right);
-        if (x.x().kind.isFloat() || x.x().kind.isDouble()) {
-            lir.branch(cond, right.kind, getLIRBlock(x.trueSuccessor()), getLIRBlock(x.unorderedSuccessor()));
+        if (x.compare().x().kind.isFloat() || x.compare().x().kind.isDouble()) {
+            Instruction unorderedSucc = x.falseSuccessor();
+            if (x.compare().unorderedIsTrue()) {
+                unorderedSucc = x.trueSuccessor();
+            }
+            lir.branch(cond, right.kind, getLIRBlock(x.trueSuccessor()), getLIRBlock(unorderedSucc));
         } else {
             lir.branch(cond, right.kind, getLIRBlock(x.trueSuccessor()));
         }
--- a/graal/GraalGraph/src/com/oracle/graal/graph/NodeArray.java	Tue Jun 07 17:04:55 2011 +0200
+++ b/graal/GraalGraph/src/com/oracle/graal/graph/NodeArray.java	Tue Jun 07 17:05:13 2011 +0200
@@ -47,7 +47,7 @@
 
     @Override
     public Node set(int index, Node node) {
-        assert node == Node.Null || node.graph == self().graph : "node is from different graph";
+        assert node == Node.Null || node.graph == self().graph : "node is from different graph: (this=" + this + ") and (node=" + node + ")";
         assert node == Node.Null || node.id() != Node.DeletedID : "inserted node must not be deleted";
         Node old = nodes[index];