comparison graal/GraalCompiler/src/com/sun/c1x/ir/Value.java @ 2821:015be60afcf3

removed flags from Value class
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 30 May 2011 17:05:06 +0200
parents c3f64b66fc78
children bd17ac598c6e
comparison
equal deleted inserted replaced
2820:2b8ef0a06391 2821:015be60afcf3
31 * This class represents a value within the HIR graph, including local variables, phis, and 31 * This class represents a value within the HIR graph, including local variables, phis, and
32 * all other instructions. 32 * all other instructions.
33 */ 33 */
34 public abstract class Value extends Node { 34 public abstract class Value extends Node {
35 35
36 public enum Flag {
37 NonNull, // this value is non-null
38
39 PhiDead, // phi is illegal because local is dead
40 PhiCannotSimplify, // phi cannot be simplified
41 PhiVisited; // phi has been visited during simplification
42
43 public final int mask = 1 << ordinal();
44 }
45
46 /** 36 /**
47 * The kind of this value. This is {@link CiKind#Void} for instructions that produce no value. 37 * The kind of this value. This is {@link CiKind#Void} for instructions that produce no value.
48 * This kind is guaranteed to be a {@linkplain CiKind#stackKind() stack kind}. 38 * This kind is guaranteed to be a {@linkplain CiKind#stackKind() stack kind}.
49 */ 39 */
50 public final CiKind kind; 40 public final CiKind kind;
51 41
52 /** 42 private boolean isNonNull;
53 * A mask of {@linkplain Flag flags} denoting extra properties of this value.
54 */
55 private int flags;
56 43
57 protected CiValue operand = CiValue.IllegalValue; 44 protected CiValue operand = CiValue.IllegalValue;
58 45
59 /** 46 /**
60 * Creates a new value with the specified kind. 47 * Creates a new value with the specified kind.
81 protected Object clone() throws CloneNotSupportedException { 68 protected Object clone() throws CloneNotSupportedException {
82 throw new CloneNotSupportedException(); 69 throw new CloneNotSupportedException();
83 } 70 }
84 71
85 /** 72 /**
86 * Check whether this instruction has the specified flag set.
87 * @param flag the flag to test
88 * @return {@code true} if this instruction has the flag
89 */
90 public final boolean checkFlag(Flag flag) {
91 return (flags & flag.mask) != 0;
92 }
93
94 /**
95 * Set a flag on this instruction.
96 * @param flag the flag to set
97 */
98 public final void setFlag(Flag flag) {
99 flags |= flag.mask;
100 }
101
102 /**
103 * Clear a flag on this instruction.
104 * @param flag the flag to set
105 */
106 public final void clearFlag(Flag flag) {
107 flags &= ~flag.mask;
108 }
109
110 /**
111 * Set or clear a flag on this instruction.
112 * @param flag the flag to set
113 * @param val if {@code true}, set the flag, otherwise clear it
114 */
115 public final void setFlag(Flag flag, boolean val) {
116 if (val) {
117 setFlag(flag);
118 } else {
119 clearFlag(flag);
120 }
121 }
122
123 /**
124 * Initialize a flag on this instruction. Assumes the flag is not initially set,
125 * e.g. in the constructor of an instruction.
126 * @param flag the flag to set
127 * @param val if {@code true}, set the flag, otherwise do nothing
128 */
129 public final void initFlag(Flag flag, boolean val) {
130 if (val) {
131 setFlag(flag);
132 }
133 }
134
135 /**
136 * Checks whether this instruction produces a value which is guaranteed to be non-null. 73 * Checks whether this instruction produces a value which is guaranteed to be non-null.
137 * @return {@code true} if this instruction's value is not null 74 * @return {@code true} if this instruction's value is not null
138 */ 75 */
139 public final boolean isNonNull() { 76 public boolean isNonNull() {
140 return checkFlag(Flag.NonNull); 77 return isNonNull;
78 }
79
80 public void setNonNull(boolean isNonNull) {
81 this.isNonNull = isNonNull;
141 } 82 }
142 83
143 /** 84 /**
144 * Checks whether this value is a constant (i.e. it is of type {@link Constant}. 85 * Checks whether this value is a constant (i.e. it is of type {@link Constant}.
145 * @return {@code true} if this value is a constant 86 * @return {@code true} if this value is a constant
152 * Checks whether this value represents the null constant. 93 * Checks whether this value represents the null constant.
153 * @return {@code true} if this value represents the null constant 94 * @return {@code true} if this value represents the null constant
154 */ 95 */
155 public final boolean isNullConstant() { 96 public final boolean isNullConstant() {
156 return this instanceof Constant && ((Constant) this).value.isNull(); 97 return this instanceof Constant && ((Constant) this).value.isNull();
157 }
158
159 /**
160 * Checks whether this instruction "is illegal"--i.e. it represents a dead
161 * phi or an instruction which does not produce a value.
162 * @return {@code true} if this instruction is illegal as an input value to another instruction
163 */
164 public final boolean isIllegal() {
165 return checkFlag(Flag.PhiDead);
166 } 98 }
167 99
168 /** 100 /**
169 * Convert this value to a constant if it is a constant, otherwise return null. 101 * Convert this value to a constant if it is a constant, otherwise return null.
170 * @return the {@link CiConstant} represented by this value if it is a constant; {@code null} 102 * @return the {@link CiConstant} represented by this value if it is a constant; {@code null}
246 return builder.toString(); 178 return builder.toString();
247 } 179 }
248 180
249 public String flagsToString() { 181 public String flagsToString() {
250 StringBuilder sb = new StringBuilder(); 182 StringBuilder sb = new StringBuilder();
251 for (Flag f : Flag.values()) { 183 if (isNonNull()) {
252 if (checkFlag(f)) { 184 sb.append("NonNull");
253 if (sb.length() != 0) {
254 sb.append(' ');
255 }
256 sb.append(f.name());
257 }
258 } 185 }
259 return sb.toString(); 186 return sb.toString();
260 }
261
262 public final boolean isDeadPhi() {
263 return checkFlag(Flag.PhiDead);
264 } 187 }
265 188
266 /** 189 /**
267 * Compute the value number of this Instruction. Local and global value numbering 190 * Compute the value number of this Instruction. Local and global value numbering
268 * optimizations use a hash map, and the value number provides a hash code. 191 * optimizations use a hash map, and the value number provides a hash code.