changeset 2587:51ebe5f0516f

changed NegateOp, more Op2 changes (generic inputValuesDo impl)
author Lukas Stadler <lukas.stadler@jku.at>
date Thu, 05 May 2011 15:01:34 +0200
parents 421da5f53b5e
children dac9bcc6bd4a fec99fc30af1
files graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java graal/GraalCompiler/src/com/sun/c1x/ir/ArithmeticOp.java graal/GraalCompiler/src/com/sun/c1x/ir/CompareOp.java graal/GraalCompiler/src/com/sun/c1x/ir/IfOp.java graal/GraalCompiler/src/com/sun/c1x/ir/LogicOp.java graal/GraalCompiler/src/com/sun/c1x/ir/NegateOp.java graal/GraalCompiler/src/com/sun/c1x/ir/Op2.java graal/GraalCompiler/src/com/sun/c1x/ir/ShiftOp.java graal/GraalCompiler/src/com/sun/c1x/ir/Value.java
diffstat 9 files changed, 55 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Thu May 05 14:37:17 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Thu May 05 15:01:34 2011 +0200
@@ -560,7 +560,7 @@
     }
 
     void genNegateOp(CiKind kind) {
-        push(kind, append(new NegateOp(pop(kind))));
+        push(kind, append(new NegateOp(pop(kind), graph)));
     }
 
     void genShiftOp(CiKind kind, int opcode) {
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/ArithmeticOp.java	Thu May 05 14:37:17 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/ArithmeticOp.java	Thu May 05 15:01:34 2011 +0200
@@ -33,6 +33,9 @@
  */
 public final class ArithmeticOp extends Op2 {
 
+    private static final int INPUT_COUNT = 0;
+    private static final int SUCCESSOR_COUNT = 0;
+
     private final FrameState stateBefore;
     private final boolean isStrictFP;
 
@@ -46,7 +49,7 @@
      * @param stateBefore the state for instructions that may trap
      */
     public ArithmeticOp(int opcode, CiKind kind, Value x, Value y, boolean isStrictFP, FrameState stateBefore, Graph graph) {
-        super(kind, opcode, x, y, graph);
+        super(kind, opcode, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph);
         this.isStrictFP = isStrictFP;
         this.stateBefore = stateBefore;
     }
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/CompareOp.java	Thu May 05 14:37:17 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/CompareOp.java	Thu May 05 15:01:34 2011 +0200
@@ -32,6 +32,9 @@
  */
 public final class CompareOp extends Op2 {
 
+    private static final int INPUT_COUNT = 0;
+    private static final int SUCCESSOR_COUNT = 0;
+
     /**
      * Creates a new compare operation.
      * @param opcode the bytecode opcode
@@ -40,7 +43,7 @@
      * @param y the second input
      */
     public CompareOp(int opcode, CiKind kind, Value x, Value y, Graph graph) {
-        super(kind, opcode, x, y, graph);
+        super(kind, opcode, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph);
     }
 
     @Override
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/IfOp.java	Thu May 05 14:37:17 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/IfOp.java	Thu May 05 15:01:34 2011 +0200
@@ -88,7 +88,7 @@
      */
     public IfOp(Value x, Condition cond, Value y, Value trueValue, Value falseValue, Graph graph) {
         // TODO: return the appropriate bytecode IF_ICMPEQ, etc
-        super(trueValue.kind.meet(falseValue.kind), Bytecodes.ILLEGAL, x, y, graph);
+        super(trueValue.kind.meet(falseValue.kind), Bytecodes.ILLEGAL, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph);
         this.cond = cond;
         setTrueValue(trueValue);
         setFalseValue(falseValue);
@@ -111,13 +111,6 @@
     }
 
     @Override
-    public void inputValuesDo(ValueClosure closure) {
-        super.inputValuesDo(closure);
-        setTrueValue(closure.apply(trueValue()));
-        setFalseValue(closure.apply(falseValue()));
-    }
-
-    @Override
     public void accept(ValueVisitor v) {
         v.visitIfOp(this);
     }
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/LogicOp.java	Thu May 05 14:37:17 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/LogicOp.java	Thu May 05 15:01:34 2011 +0200
@@ -33,6 +33,9 @@
  */
 public final class LogicOp extends Op2 {
 
+    private static final int INPUT_COUNT = 0;
+    private static final int SUCCESSOR_COUNT = 0;
+
     /**
      * Constructs a new logic operation instruction.
      * @param opcode the opcode of the logic operation
@@ -40,7 +43,7 @@
      * @param y the second input into this instruction
      */
     public LogicOp(int opcode, Value x, Value y, Graph graph) {
-        super(x.kind, opcode, x, y, graph);
+        super(x.kind, opcode, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph);
     }
 
     @Override
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/NegateOp.java	Thu May 05 14:37:17 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/NegateOp.java	Thu May 05 15:01:34 2011 +0200
@@ -22,6 +22,7 @@
  */
 package com.sun.c1x.ir;
 
+import com.oracle.graal.graph.*;
 import com.sun.c1x.debug.*;
 import com.sun.c1x.util.*;
 import com.sun.cri.bytecode.*;
@@ -33,28 +34,40 @@
  */
 public final class NegateOp extends Instruction {
 
-    Value x;
+    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 producing input to this instruction.
+     */
+     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);
+    }
 
     /**
      * Creates new NegateOp instance.
      * @param x the instruction producing the value that is input to this instruction
      */
-    public NegateOp(Value x) {
-        super(x.kind);
-        this.x = x;
-    }
-
-    /**
-     * Gets the instruction producing input to this instruction.
-     * @return the instruction that produces this instruction's input
-     */
-    public Value x() {
-        return x;
-    }
-
-    @Override
-    public void inputValuesDo(ValueClosure closure) {
-        x = closure.apply(x);
+    public NegateOp(Value x, Graph graph) {
+        super(x.kind, INPUT_COUNT, SUCCESSOR_COUNT, graph);
+        setX(x);
     }
 
     @Override
@@ -64,14 +77,14 @@
 
     @Override
     public int valueNumber() {
-        return Util.hash1(Bytecodes.INEG, x);
+        return Util.hash1(Bytecodes.INEG, x());
     }
 
     @Override
     public boolean valueEqual(Instruction i) {
         if (i instanceof NegateOp) {
             NegateOp o = (NegateOp) i;
-            return x == o.x;
+            return x() == o.x();
         }
         return false;
     }
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Op2.java	Thu May 05 14:37:17 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Op2.java	Thu May 05 15:01:34 2011 +0200
@@ -84,8 +84,8 @@
      * @param x the first input instruction
      * @param y the second input instruction
      */
-    public Op2(CiKind kind, int opcode, Value x, Value y, Graph graph) {
-        super(kind, INPUT_COUNT, SUCCESSOR_COUNT, graph);
+    public Op2(CiKind kind, int opcode, Value x, Value y, int inputCount, int successorCount, Graph graph) {
+        super(kind, inputCount + INPUT_COUNT, successorCount + SUCCESSOR_COUNT, graph);
         this.opcode = opcode;
         setX(x);
         setY(y);
@@ -101,16 +101,6 @@
         setY(t);
     }
 
-    /**
-     * Iterates over the inputs to this instruction.
-     * @param closure the closure to apply to each input value
-     */
-    @Override
-    public void inputValuesDo(ValueClosure closure) {
-        setX(closure.apply(x()));
-        setY(closure.apply(y()));
-    }
-
     @Override
     public int valueNumber() {
         return Util.hash2(opcode, x(), y());
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/ShiftOp.java	Thu May 05 14:37:17 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/ShiftOp.java	Thu May 05 15:01:34 2011 +0200
@@ -33,6 +33,9 @@
  */
 public final class ShiftOp extends Op2 {
 
+    private static final int INPUT_COUNT = 0;
+    private static final int SUCCESSOR_COUNT = 0;
+
     /**
      * Creates a new shift operation.
      * @param opcode the opcode of the shift
@@ -40,7 +43,7 @@
      * @param y the second input value
      */
     public ShiftOp(int opcode, Value x, Value y, Graph graph) {
-        super(x.kind, opcode, x, y, graph);
+        super(x.kind, opcode, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph);
     }
 
     @Override
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java	Thu May 05 14:37:17 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java	Thu May 05 15:01:34 2011 +0200
@@ -271,7 +271,9 @@
      * @param closure the closure to apply
      */
     public void inputValuesDo(ValueClosure closure) {
-        // default: do nothing.
+        for (int i = 0; i < inputs().size(); i++) {
+            inputs().set(i, closure.apply((Value) inputs().get(i)));
+        }
     }
 
     @Override