comparison graal/GraalCompiler/src/com/sun/c1x/ir/Op2.java @ 2585:3e0e65161345

new node layout: Op2
author Lukas Stadler <lukas.stadler@jku.at>
date Thu, 05 May 2011 14:12:19 +0200
parents 16b9a8b5ad39
children 421da5f53b5e
comparison
equal deleted inserted replaced
2584:06b2eac2f5d3 2585:3e0e65161345
31 * 31 *
32 * @author Ben L. Titzer 32 * @author Ben L. Titzer
33 */ 33 */
34 public abstract class Op2 extends Instruction { 34 public abstract class Op2 extends Instruction {
35 35
36 private static final int INPUT_COUNT = 2;
37 private static final int INPUT_X = 0;
38 private static final int INPUT_Y = 1;
39
40 private static final int SUCCESSOR_COUNT = 0;
41
42 @Override
43 protected int inputCount() {
44 return super.inputCount() + INPUT_COUNT;
45 }
46
47 @Override
48 protected int successorCount() {
49 return super.successorCount() + SUCCESSOR_COUNT;
50 }
51
52 /**
53 * The first input to this instruction
54 */
55 public Value x() {
56 return (Value) inputs().get(super.inputCount() + INPUT_X);
57 }
58
59 public Value setX(Value n) {
60 return (Value) inputs().set(super.inputCount() + INPUT_X, n);
61 }
62
63 /**
64 * The second input to this instruction
65 */
66 public Value y() {
67 return (Value) inputs().get(super.inputCount() + INPUT_Y);
68 }
69
70 public Value setY(Value n) {
71 return (Value) inputs().set(super.inputCount() + INPUT_Y, n);
72 }
73
36 /** 74 /**
37 * The opcode of this instruction. 75 * The opcode of this instruction.
38 */ 76 */
39 public final int opcode; 77 public final int opcode;
40
41 Value x;
42 Value y;
43 78
44 /** 79 /**
45 * Creates a new Op2 instance. 80 * Creates a new Op2 instance.
46 * @param kind the result type of this instruction 81 * @param kind the result type of this instruction
47 * @param opcode the bytecode opcode 82 * @param opcode the bytecode opcode
48 * @param x the first input instruction 83 * @param x the first input instruction
49 * @param y the second input instruction 84 * @param y the second input instruction
50 */ 85 */
51 public Op2(CiKind kind, int opcode, Value x, Value y) { 86 public Op2(CiKind kind, int opcode, Value x, Value y) {
52 super(kind); 87 super(kind, INPUT_COUNT, SUCCESSOR_COUNT, null);
53 this.opcode = opcode; 88 this.opcode = opcode;
54 this.x = x; 89 setX(x);
55 this.y = y; 90 setY(y);
56 }
57
58 /**
59 * Gets the first input to this instruction.
60 * @return the first input to this instruction
61 */
62 public final Value x() {
63 return x;
64 }
65
66 /**
67 * Gets the second input to this instruction.
68 * @return the second input to this instruction
69 */
70 public final Value y() {
71 return y;
72 } 91 }
73 92
74 /** 93 /**
75 * Swaps the operands of this instruction. This is only legal for commutative operations. 94 * Swaps the operands of this instruction. This is only legal for commutative operations.
76 */ 95 */
77 public void swapOperands() { 96 public void swapOperands() {
78 assert Bytecodes.isCommutative(opcode); 97 assert Bytecodes.isCommutative(opcode);
79 Value t = x; 98 Value t = x();
80 x = y; 99 setX(y());
81 y = t; 100 setY(t);
82 } 101 }
83 102
84 /** 103 /**
85 * Iterates over the inputs to this instruction. 104 * Iterates over the inputs to this instruction.
86 * @param closure the closure to apply to each input value 105 * @param closure the closure to apply to each input value
87 */ 106 */
88 @Override 107 @Override
89 public void inputValuesDo(ValueClosure closure) { 108 public void inputValuesDo(ValueClosure closure) {
90 x = closure.apply(x); 109 setX(closure.apply(x()));
91 y = closure.apply(y); 110 setY(closure.apply(y()));
92 } 111 }
93 112
94 @Override 113 @Override
95 public int valueNumber() { 114 public int valueNumber() {
96 return Util.hash2(opcode, x, y); 115 return Util.hash2(opcode, x(), y());
97 } 116 }
98 117
99 @Override 118 @Override
100 public boolean valueEqual(Instruction i) { 119 public boolean valueEqual(Instruction i) {
101 if (i instanceof Op2) { 120 if (i instanceof Op2) {
102 Op2 o = (Op2) i; 121 Op2 o = (Op2) i;
103 return opcode == o.opcode && x == o.x && y == o.y; 122 return opcode == o.opcode && x() == o.x() && y() == o.y();
104 } 123 }
105 return false; 124 return false;
106 } 125 }
107 } 126 }