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 */ 013package org.jikesrvm.compilers.opt.ir; 014 015import org.jikesrvm.VM; 016 017/** 018 * A class to hold each element in the GCIRMap 019 */ 020public class RegSpillListElement { 021 022 /** 023 * this should be a symbolic register 024 */ 025 private final Register symbolicReg; 026 027 /** 028 * This could be either a spill or a real reg number. Spills are stored 029 * as they are. For register numbers, we store the negative value. 030 */ 031 private int value; 032 033 /** 034 * Constructor 035 * @param symbolicReg the symbolic register holding the reference 036 */ 037 public RegSpillListElement(Register symbolicReg) { 038 this.symbolicReg = symbolicReg; 039 } 040 041 /** 042 * Sets the spill component associated with this object 043 * @param value the spill value 044 */ 045 public final void setSpill(int value) { 046 if (VM.VerifyAssertions) VM._assert(value > 0); 047 this.value = value; 048 } 049 050 /** 051 * Sets the real (i.e., physical) register component associated with 052 * this object 053 * @param reg the real (physical) register 054 */ 055 public final void setRealReg(Register reg) { 056 // we store registers as non-positive numbers to distinguish them from 057 // spills 058 this.value = -reg.number; 059 } 060 061 /** 062 * Is this a spill? 063 * @return whether this is a spill 064 */ 065 public final boolean isSpill() { 066 return (value > 0); 067 } 068 069 /** 070 * returns the symbolic register associated with this object 071 * @return the symbolic register associated with this object 072 */ 073 public final Register getSymbolicReg() { 074 return symbolicReg; 075 } 076 077 /** 078 * returns the real (physical) register associated with this object 079 * @return the real (physical) register associated with this object 080 */ 081 public final int getRealRegNumber() { 082 if (VM.VerifyAssertions) { 083 VM._assert(!isSpill(), "RegSpillListElement asked for a Real Reg, when it had a spill"); 084 } 085 086 // real regs are stored as non-positive values 087 return -value; 088 } 089 090 /** 091 * returns the spill value associated with this object 092 * @return the spill value associated with this object 093 */ 094 public final int getSpill() { 095 if (VM.VerifyAssertions) { 096 VM._assert(isSpill(), "RegSpillListElement asked for a spill, when it had a real register"); 097 } 098 099 return value; 100 } 101 102 /** 103 * return a string version of this object 104 * @return string version of this object 105 */ 106 @Override 107 public String toString() { 108 StringBuilder buf = new StringBuilder(); 109 buf.append("(").append(symbolicReg).append(", "); 110 if (isSpill()) { 111 buf.append("Sp: ").append(getSpill()); 112 } else { 113 buf.append("Reg: ").append(getRealRegNumber()); 114 } 115 buf.append(") "); 116 return buf.toString(); 117 } 118} 119 120 121