comparison 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
comparison
equal deleted inserted replaced
2596:1c36b17f7ee0 2600:f1bc67c2d453
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 */ 22 */
23 package com.sun.c1x.ir; 23 package com.sun.c1x.ir;
24 24
25 import com.oracle.graal.graph.*;
25 import com.sun.c1x.debug.*; 26 import com.sun.c1x.debug.*;
26 import com.sun.c1x.value.*; 27 import com.sun.c1x.value.*;
27 import com.sun.cri.ci.*; 28 import com.sun.cri.ci.*;
28 import com.sun.cri.ri.*; 29 import com.sun.cri.ri.*;
29 30
30 /** 31 /**
31 * The {@code NewMultiArray} instruction represents an allocation of a multi-dimensional object 32 * The {@code NewMultiArray} instruction represents an allocation of a multi-dimensional object
32 * array. 33 * array.
33 *
34 * @author Ben L. Titzer
35 */ 34 */
36 public final class NewMultiArray extends NewArray { 35 public final class NewMultiArray extends NewArray {
36
37 private final int dimensionCount;
38
39 private static final int SUCCESSOR_COUNT = 0;
40
41 @Override
42 protected int inputCount() {
43 return super.inputCount() + dimensionCount;
44 }
45
46 @Override
47 protected int successorCount() {
48 return super.successorCount() + SUCCESSOR_COUNT;
49 }
50
51 /**
52 * The list of instructions which produce input for this instruction.
53 */
54 public Value dimension(int index) {
55 assert index >= 0 && index < dimensionCount;
56 return (Value) inputs().get(super.inputCount() + index);
57 }
58
59 public Value setDimension(int index, Value n) {
60 assert index >= 0 && index < dimensionCount;
61 return (Value) inputs().set(super.inputCount() + index, n);
62 }
63
64 /**
65 * The rank of the array allocated by this instruction, i.e. how many array dimensions.
66 */
67 public int dimensionCount() {
68 return dimensionCount;
69 }
70
37 public final RiType elementKind; 71 public final RiType elementKind;
38 final Value[] dimensions;
39 public final int cpi; 72 public final int cpi;
40 public final RiConstantPool constantPool; 73 public final RiConstantPool constantPool;
41 74
42 /** 75 /**
43 * Constructs a new NewMultiArray instruction. 76 * Constructs a new NewMultiArray instruction.
44 * @param elementKind the element type of the array 77 * @param elementKind the element type of the array
45 * @param dimensions the instructions which produce the dimensions for this array 78 * @param dimensions the instructions which produce the dimensions for this array
46 * @param stateBefore the state before this instruction 79 * @param stateBefore the state before this instruction
47 * @param cpi the constant pool index for resolution 80 * @param cpi the constant pool index for resolution
48 * @param riConstantPool the constant pool for resolution 81 * @param riConstantPool the constant pool for resolution
82 * @param graph
49 */ 83 */
50 public NewMultiArray(RiType elementKind, Value[] dimensions, FrameState stateBefore, int cpi, RiConstantPool riConstantPool) { 84 public NewMultiArray(RiType elementKind, Value[] dimensions, FrameState stateBefore, int cpi, RiConstantPool riConstantPool, Graph graph) {
51 super(null, stateBefore); 85 super(null, stateBefore, dimensions.length, SUCCESSOR_COUNT, graph);
52 this.constantPool = riConstantPool; 86 this.constantPool = riConstantPool;
53 this.elementKind = elementKind; 87 this.elementKind = elementKind;
54 this.dimensions = dimensions;
55 this.cpi = cpi; 88 this.cpi = cpi;
56 }
57 89
58 /** 90 this.dimensionCount = dimensions.length;
59 * Gets the list of instructions which produce input for this instruction.
60 * @return the list of instructions which produce input
61 */
62 public Value[] dimensions() {
63 return dimensions;
64 }
65
66 /**
67 * Gets the rank of the array allocated by this instruction, i.e. how many array dimensions.
68 * @return the rank of the array allocated
69 */
70 public int rank() {
71 return dimensions.length;
72 }
73
74 @Override
75 public void inputValuesDo(ValueClosure closure) {
76 for (int i = 0; i < dimensions.length; i++) { 91 for (int i = 0; i < dimensions.length; i++) {
77 dimensions[i] = closure.apply(dimensions[i]); 92 setDimension(i, dimensions[i]);
78 } 93 }
79 } 94 }
80 95
81 @Override 96 @Override
82 public void accept(ValueVisitor v) { 97 public void accept(ValueVisitor v) {
92 } 107 }
93 108
94 @Override 109 @Override
95 public void print(LogStream out) { 110 public void print(LogStream out) {
96 out.print("new multi array ["); 111 out.print("new multi array [");
97 final Value[] dimensions = dimensions(); 112 for (int i = 0; i < dimensionCount; i++) {
98 for (int i = 0; i < dimensions.length; i++) {
99 if (i > 0) { 113 if (i > 0) {
100 out.print(", "); 114 out.print(", ");
101 } 115 }
102 out.print(dimensions[i]); 116 out.print(dimension(i));
103 } 117 }
104 out.print("] ").print(CiUtil.toJavaName(elementKind)); 118 out.print("] ").print(CiUtil.toJavaName(elementKind));
105 } 119 }
106 } 120 }