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; 016import org.jikesrvm.classloader.RVMMethod; 017import org.jikesrvm.classloader.TypeReference; 018import org.jikesrvm.compilers.opt.ir.operand.Operand; 019import org.jikesrvm.compilers.opt.ir.operand.RegisterOperand; 020 021/** 022 * Pool of symbolic registers. 023 * Each IR contains has exactly one register pool object associated with it. 024 * 025 * @see Register 026 */ 027public abstract class GenericRegisterPool extends AbstractRegisterPool { 028 029 protected final GenericPhysicalRegisterSet physical; 030 031 public GenericPhysicalRegisterSet getPhysicalRegisterSet() { 032 return physical; 033 } 034 035 /** 036 * Initializes a new register pool for the method meth. 037 * 038 * @param meth the RVMMethod of the outermost method 039 */ 040 protected GenericRegisterPool(RVMMethod meth) { 041 if (VM.BuildForIA32) { 042 physical = new org.jikesrvm.compilers.opt.ir.ia32.PhysicalRegisterSet(); 043 } else { 044 if (VM.VerifyAssertions) VM._assert(VM.BuildForPowerPC); 045 physical = new org.jikesrvm.compilers.opt.ir.ppc.PhysicalRegisterSet(); 046 } 047 // currentNum is assigned an initial value to avoid overlap of 048 // physical and symbolic registers. 049 currentNum = physical.getNumberOfPhysicalRegisters(); 050 } 051 052 /** 053 * Return the number of symbolic registers (doesn't count physical ones) 054 * @return the number of symbolic registers allocated by the pool 055 */ 056 public int getNumberOfSymbolicRegisters() { 057 int start = physical.getNumberOfPhysicalRegisters(); 058 return currentNum - start; 059 } 060 061 /** 062 * @return the total number of register in the pool, including physical ones 063 */ 064 public int getTotalNumberOfRegisters() { 065 return currentNum; 066 } 067 068 /** 069 * Get the Framepointer (FP) 070 * 071 * @return the FP register 072 */ 073 public Register getFP() { 074 return physical.getFP(); 075 } 076 077 /** 078 * Get a temporary that represents the FP register 079 * 080 * @return the temp 081 */ 082 public RegisterOperand makeFPOp() { 083 return new RegisterOperand(getFP(), TypeReference.Address); 084 } 085 086 /** 087 * Get a temporary that represents the PR register 088 * 089 * @return the temp 090 */ 091 public RegisterOperand makeTROp() { 092 RegisterOperand trOp = new RegisterOperand(physical.getTR(), TypeReference.Thread); 093 trOp.setPreciseType(); 094 return trOp; 095 } 096 097 /** 098 * @return a temporary that represents the JTOC register (as an Address) 099 */ 100 public abstract Operand makeJTOCOp(); 101 102 /** 103 * @return a temporary that represents the JTOC register (as an Object) 104 */ 105 public abstract Operand makeTocOp(); 106}