diff graal/GraalCompiler/src/com/sun/c1x/ir/NewMultiArray.java @ 2600:f1bc67c2d453

new node layout: TypeCheck, RegisterFinalizer, Invoke, NewArray, NullCheck
author Lukas Stadler <lukas.stadler@jku.at>
date Thu, 05 May 2011 16:32:20 +0200
parents 16b9a8b5ad39
children 91d3952f7eb7
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/NewMultiArray.java	Thu May 05 16:07:00 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/NewMultiArray.java	Thu May 05 16:32:20 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.value.*;
 import com.sun.cri.ci.*;
@@ -30,12 +31,44 @@
 /**
  * The {@code NewMultiArray} instruction represents an allocation of a multi-dimensional object
  * array.
- *
- * @author Ben L. Titzer
  */
 public final class NewMultiArray extends NewArray {
+
+    private final int dimensionCount;
+
+    private static final int SUCCESSOR_COUNT = 0;
+
+    @Override
+    protected int inputCount() {
+        return super.inputCount() + dimensionCount;
+    }
+
+    @Override
+    protected int successorCount() {
+        return super.successorCount() + SUCCESSOR_COUNT;
+    }
+
+    /**
+     * The list of instructions which produce input for this instruction.
+     */
+    public Value dimension(int index) {
+        assert index >= 0 && index < dimensionCount;
+        return (Value) inputs().get(super.inputCount() + index);
+    }
+
+    public Value setDimension(int index, Value n) {
+        assert index >= 0 && index < dimensionCount;
+        return (Value) inputs().set(super.inputCount() + index, n);
+    }
+
+    /**
+     * The rank of the array allocated by this instruction, i.e. how many array dimensions.
+     */
+    public int dimensionCount() {
+        return dimensionCount;
+    }
+
     public final RiType elementKind;
-    final Value[] dimensions;
     public final int cpi;
     public final RiConstantPool constantPool;
 
@@ -46,35 +79,17 @@
      * @param stateBefore the state before this instruction
      * @param cpi the constant pool index for resolution
      * @param riConstantPool the constant pool for resolution
+     * @param graph
      */
-    public NewMultiArray(RiType elementKind, Value[] dimensions, FrameState stateBefore, int cpi, RiConstantPool riConstantPool) {
-        super(null, stateBefore);
+    public NewMultiArray(RiType elementKind, Value[] dimensions, FrameState stateBefore, int cpi, RiConstantPool riConstantPool, Graph graph) {
+        super(null, stateBefore, dimensions.length, SUCCESSOR_COUNT, graph);
         this.constantPool = riConstantPool;
         this.elementKind = elementKind;
-        this.dimensions = dimensions;
         this.cpi = cpi;
-    }
-
-    /**
-     * Gets the list of instructions which produce input for this instruction.
-     * @return the list of instructions which produce input
-     */
-    public Value[] dimensions() {
-        return dimensions;
-    }
 
-    /**
-     * Gets the rank of the array allocated by this instruction, i.e. how many array dimensions.
-     * @return the rank of the array allocated
-     */
-    public int rank() {
-        return dimensions.length;
-    }
-
-    @Override
-    public void inputValuesDo(ValueClosure closure) {
+        this.dimensionCount = dimensions.length;
         for (int i = 0; i < dimensions.length; i++) {
-            dimensions[i] = closure.apply(dimensions[i]);
+            setDimension(i, dimensions[i]);
         }
     }
 
@@ -94,12 +109,11 @@
     @Override
     public void print(LogStream out) {
         out.print("new multi array [");
-        final Value[] dimensions = dimensions();
-        for (int i = 0; i < dimensions.length; i++) {
+        for (int i = 0; i < dimensionCount; i++) {
           if (i > 0) {
               out.print(", ");
           }
-          out.print(dimensions[i]);
+          out.print(dimension(i));
         }
         out.print("] ").print(CiUtil.toJavaName(elementKind));
     }