comparison graal/com.oracle.max.graal.compiler/src/com/sun/c1x/lir/LIROperand.java @ 2872:0341b6424579

Project renaming.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 08 Jun 2011 08:42:25 +0200
parents graal/GraalCompiler/src/com/sun/c1x/lir/LIROperand.java@16b9a8b5ad39
children
comparison
equal deleted inserted replaced
2871:d704eb526603 2872:0341b6424579
1 /*
2 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.sun.c1x.lir;
24
25 import com.sun.cri.ci.*;
26
27 /**
28 * An instruction operand. If the register allocator can modify this operand (e.g. to replace a
29 * variable with a register), then it will have a corresponding entry in the {@link LIRInstruction#allocatorOperands}
30 * list of an instruction.
31 *
32 * @author Doug Simon
33 */
34 public class LIROperand {
35
36 /**
37 * The value of the operand.
38 */
39 CiValue value;
40
41 LIROperand(CiValue value) {
42 this.value = value;
43 }
44
45 /**
46 * Gets the value of this operand. This may still be a {@linkplain CiVariable}
47 * if the register allocator has not yet assigned a register or stack address to the operand.
48 *
49 * @param inst the instruction containing this operand
50 */
51 public CiValue value(LIRInstruction inst) {
52 return value;
53 }
54
55 @Override
56 public String toString() {
57 return value.toString();
58 }
59
60 static class LIRVariableOperand extends LIROperand {
61 /**
62 * Index into an instruction's {@linkplain LIRInstruction#allocatorOperands allocator operands}.
63 */
64 final int index;
65
66 LIRVariableOperand(int index) {
67 super(null);
68 this.index = index;
69 }
70
71 @Override
72 public CiValue value(LIRInstruction inst) {
73 if (value == null) {
74 CiValue value = inst.allocatorOperands.get(index);
75 if (value.isVariable()) {
76 return value;
77 }
78 this.value = value;
79 }
80 return value;
81 }
82
83 @Override
84 public String toString() {
85 if (value == null) {
86 return "operands[" + index + "]";
87 }
88 return value.toString();
89 }
90 }
91
92 /**
93 * An address operand with at least one {@linkplain CiVariable variable} constituent.
94 */
95 static class LIRAddressOperand extends LIROperand {
96 int base;
97 int index;
98
99 LIRAddressOperand(int base, int index, CiAddress address) {
100 super(address);
101 assert base != -1 || index != -1 : "address should have at least one variable part";
102 this.base = base;
103 this.index = index;
104 }
105
106 @Override
107 public CiValue value(LIRInstruction inst) {
108 if (base != -1 || index != -1) {
109 CiAddress address = (CiAddress) value;
110 CiValue baseOperand = base == -1 ? address.base : inst.allocatorOperands.get(base);
111 CiValue indexOperand = index == -1 ? address.index : inst.allocatorOperands.get(index);
112 if (address.index.isLegal()) {
113 assert indexOperand.isVariableOrRegister();
114 if (baseOperand.isVariable() || indexOperand.isVariable()) {
115 return address;
116 }
117 } else {
118 if (baseOperand.isVariable()) {
119 return address;
120 }
121 }
122 value = new CiAddress(address.kind, baseOperand, indexOperand, address.scale, address.displacement);
123 base = -1;
124 index = -1;
125 }
126 return value;
127 }
128
129 @Override
130 public String toString() {
131 return value.toString();
132 }
133 }
134 }