001 /* 002 * This file is part of the Jikes RVM project (http://jikesrvm.org). 003 * 004 * This file is licensed to You under the Eclipse Public License (EPL); 005 * You may not use this file except in compliance with the License. You 006 * may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/eclipse-1.0.php 009 * 010 * See the COPYRIGHT.txt file distributed with this work for information 011 * regarding copyright ownership. 012 */ 013 package org.jikesrvm.compilers.opt.ir.operand; 014 015 import org.jikesrvm.compilers.opt.ir.Instruction; 016 import org.jikesrvm.compilers.opt.ssa.HeapVariable; 017 018 /** 019 * Represents a heap variable for instructions in Heap Array SSA form. 020 * 021 * @see Operand 022 * @see HeapVariable 023 */ 024 public final class HeapOperand<T> extends Operand { 025 026 /** 027 * The heap variable corresponding to this operand. 028 */ 029 public final HeapVariable<T> value; 030 031 /** 032 * Return the heap variable corresponding to this operand. 033 * @return the heap variable corresponding to this operand. 034 */ 035 public HeapVariable<T> getHeapVariable() { 036 return value; 037 } 038 039 /** 040 * Return the number of the heap variable corresponding to this 041 * operand. 042 * @return the number of the heap variable corresponding to this 043 * operand. 044 */ 045 public int getNumber() { 046 return value.getNumber(); 047 } 048 049 /** 050 * Return the type corresponding to the heap variable associated with 051 * this operand. 052 * @return the type corresponding to the heap variable associated with 053 * this operand. 054 */ 055 public T getHeapType() { 056 return value.getHeapType(); 057 } 058 059 /** 060 * Construct an operand corresponding to a heap variable. 061 * @param heap the heap variable corresponding to this operand. 062 */ 063 public HeapOperand(HeapVariable<T> heap) { 064 value = heap; 065 } 066 067 /** 068 * Construct a new heap operand associated with the same heap variable as 069 * this operand 070 * 071 * @return a new heap operand associated with the same heap variable as 072 * this operand 073 */ 074 @Override 075 public HeapOperand<T> copy() { 076 return new HeapOperand<T>(value); 077 } 078 079 /** 080 * Does this operand correspond to the same heap variable as another 081 * heap operand? 082 * 083 * @param op the second operand to compare with 084 * @return {@code true} or {@code false} 085 */ 086 @Override 087 public boolean similar(Operand op) { 088 if (!(op instanceof HeapOperand<?>)) { 089 return false; 090 } 091 HeapOperand<?> h = (HeapOperand<?>) op; 092 return (h.value == value); 093 } 094 095 /** 096 * Return a string representation of this operand. 097 * @return a string representation of this operand. 098 */ 099 @Override 100 public String toString() { 101 return value.toString(); 102 } 103 104 /** 105 * Associate this operand with a given instruction. 106 * @param s the associated instruction 107 */ 108 public void setInstruction(Instruction s) { 109 this.instruction = s; 110 } 111 112 /** 113 * Return the instruction associated with this operand. 114 * @return the instruction associated with this operand. 115 */ 116 public Instruction getInstruction() { 117 return instruction; 118 } 119 }