Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java @ 16277:2bcba15fa725
Introduce LIRInstructionClass.Position.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Wed, 25 Jun 2014 15:04:00 +0200 |
parents | dcaf26339f7c |
children | 7a1dee389497 |
comparison
equal
deleted
inserted
replaced
16276:5cdcb94a7cf7 | 16277:2bcba15fa725 |
---|---|
239 } | 239 } |
240 str.append("]"); | 240 str.append("]"); |
241 return str.toString(); | 241 return str.toString(); |
242 } | 242 } |
243 | 243 |
244 /** | |
245 * Describes an operand slot for a {@link LIRInstructionClass}. | |
246 * | |
247 * @see LIRInstructionClass#get(LIRInstruction, Position) | |
248 */ | |
249 public static final class Position { | |
250 | |
251 private final OperandMode mode; | |
252 private final int index; | |
253 private final int subIndex; | |
254 | |
255 public Position(OperandMode mode, int index, int subIndex) { | |
256 this.mode = mode; | |
257 this.index = index; | |
258 this.subIndex = subIndex; | |
259 } | |
260 | |
261 public Value get(LIRInstruction inst) { | |
262 return inst.getLIRInstructionClass().get(inst, this); | |
263 } | |
264 | |
265 public EnumSet<OperandFlag> getFlags(LIRInstruction inst) { | |
266 return inst.getLIRInstructionClass().getFlags(this); | |
267 } | |
268 | |
269 public void set(LIRInstruction inst, Value value) { | |
270 inst.getLIRInstructionClass().set(inst, this, value); | |
271 } | |
272 | |
273 public int getSubIndex() { | |
274 return subIndex; | |
275 } | |
276 | |
277 public int getIndex() { | |
278 return index; | |
279 } | |
280 | |
281 public OperandMode getMode() { | |
282 return mode; | |
283 } | |
284 | |
285 @Override | |
286 public String toString() { | |
287 return mode.toString() + index + "/" + subIndex; | |
288 } | |
289 | |
290 @Override | |
291 public int hashCode() { | |
292 final int prime = 31; | |
293 int result = 1; | |
294 result = prime * result + index; | |
295 result = prime * result + ((mode == null) ? 0 : mode.hashCode()); | |
296 result = prime * result + subIndex; | |
297 return result; | |
298 } | |
299 | |
300 @Override | |
301 public boolean equals(Object obj) { | |
302 if (this == obj) { | |
303 return true; | |
304 } | |
305 if (obj == null) { | |
306 return false; | |
307 } | |
308 if (getClass() != obj.getClass()) { | |
309 return false; | |
310 } | |
311 Position other = (Position) obj; | |
312 if (index != other.index) { | |
313 return false; | |
314 } | |
315 if (mode != other.mode) { | |
316 return false; | |
317 } | |
318 if (subIndex != other.subIndex) { | |
319 return false; | |
320 } | |
321 return true; | |
322 } | |
323 } | |
324 | |
325 protected Value get(LIRInstruction obj, Position pos) { | |
326 long[] offsets; | |
327 int directCount; | |
328 switch (pos.getMode()) { | |
329 case USE: | |
330 directCount = directUseCount; | |
331 offsets = useOffsets; | |
332 break; | |
333 case ALIVE: | |
334 directCount = directAliveCount; | |
335 offsets = aliveOffsets; | |
336 break; | |
337 case TEMP: | |
338 directCount = directTempCount; | |
339 offsets = tempOffsets; | |
340 break; | |
341 case DEF: | |
342 directCount = directDefCount; | |
343 offsets = defOffsets; | |
344 break; | |
345 default: | |
346 throw GraalInternalError.shouldNotReachHere("unkown OperandMode: " + pos.getMode()); | |
347 } | |
348 if (pos.index < directCount) { | |
349 return getValue(obj, offsets[pos.getIndex()]); | |
350 } | |
351 return getValueArray(obj, offsets[pos.getIndex()])[pos.getSubIndex()]; | |
352 } | |
353 | |
354 protected void set(LIRInstruction obj, Position pos, Value value) { | |
355 long[] offsets; | |
356 int directCount; | |
357 switch (pos.getMode()) { | |
358 case USE: | |
359 directCount = directUseCount; | |
360 offsets = useOffsets; | |
361 break; | |
362 case ALIVE: | |
363 directCount = directAliveCount; | |
364 offsets = aliveOffsets; | |
365 break; | |
366 case TEMP: | |
367 directCount = directTempCount; | |
368 offsets = tempOffsets; | |
369 break; | |
370 case DEF: | |
371 directCount = directDefCount; | |
372 offsets = defOffsets; | |
373 break; | |
374 default: | |
375 throw GraalInternalError.shouldNotReachHere("unkown OperandMode: " + pos.getMode()); | |
376 } | |
377 if (pos.index < directCount) { | |
378 setValue(obj, offsets[pos.getIndex()], value); | |
379 } | |
380 getValueArray(obj, offsets[pos.getIndex()])[pos.getSubIndex()] = value; | |
381 } | |
382 | |
383 public EnumSet<OperandFlag> getFlags(Position pos) { | |
384 switch (pos.getMode()) { | |
385 case USE: | |
386 return useFlags[pos.getIndex()]; | |
387 case ALIVE: | |
388 return aliveFlags[pos.getIndex()]; | |
389 case TEMP: | |
390 return tempFlags[pos.getIndex()]; | |
391 case DEF: | |
392 return defFlags[pos.getIndex()]; | |
393 default: | |
394 throw GraalInternalError.shouldNotReachHere("unkown OperandMode: " + pos.getMode()); | |
395 } | |
396 } | |
397 | |
244 public final String getOpcode(LIRInstruction obj) { | 398 public final String getOpcode(LIRInstruction obj) { |
245 if (opcodeConstant != null) { | 399 if (opcodeConstant != null) { |
246 return opcodeConstant; | 400 return opcodeConstant; |
247 } | 401 } |
248 assert opcodeOffset != -1; | 402 assert opcodeOffset != -1; |