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; 014 015 import java.util.Enumeration; 016 import org.jikesrvm.ArchitectureSpecificOpt.PhysicalRegisterSet; 017 import org.jikesrvm.compilers.opt.ir.operand.Operand; 018 import org.jikesrvm.compilers.opt.ir.operand.RegisterOperand; 019 020 /** 021 * This abstract class provides a set of useful architecture-independent 022 * methods for manipulating physical registers for an IR. 023 */ 024 public abstract class GenericPhysicalRegisterTools extends IRTools { 025 026 /** 027 * Return the governing IR. 028 */ 029 public abstract IR getIR(); 030 031 /** 032 * Create an address register operand for a given physical GPR. 033 * To be used in passthrough expressions like 034 * <pre> 035 * ... Load.create(INT_LOAD, I(2), A(1), IC(4)) ... 036 * </pre> 037 * 038 * @param regnum the given GPR register number 039 * @return integer register operand 040 */ 041 protected final RegisterOperand A(int regnum) { 042 PhysicalRegisterSet phys = getIR().regpool.getPhysicalRegisterSet(); 043 return A(phys.getGPR(regnum)); 044 } 045 046 /** 047 * Create an integer register operand for a given physical GPR. 048 * To be used in passthrough expressions like 049 * <pre> 050 * ... Load.create(INT_LOAD, I(2), A(1), IC(4)) ... 051 * </pre> 052 * 053 * @param regnum the given GPR register number 054 * @return integer register operand 055 */ 056 protected final RegisterOperand I(int regnum) { 057 PhysicalRegisterSet phys = getIR().regpool.getPhysicalRegisterSet(); 058 return I(phys.getGPR(regnum)); 059 } 060 061 /** 062 * Create a float register operand for a given physical FPR. 063 * To be used in passthrough expressions like 064 * <pre> 065 * ... Load.create(FLOAT_LOAD, F(2), A(1), IC(4)) ... 066 * </pre> 067 * 068 * @param regnum the given DOUBLE register number 069 * @return float register operand 070 */ 071 final RegisterOperand F(int regnum) { 072 PhysicalRegisterSet phys = getIR().regpool.getPhysicalRegisterSet(); 073 return F(phys.getFPR(regnum)); 074 } 075 076 /** 077 * Create a double register operand for a given physical FPR. 078 * To be used in passthrough expressions like 079 * <pre> 080 * ... Load.create(DOUBLE_LOAD, D(2), A(1), IC(4)) ... 081 * </pre> 082 * 083 * @param regnum the given double register number 084 * @return double register operand 085 */ 086 final RegisterOperand D(int regnum) { 087 PhysicalRegisterSet phys = getIR().regpool.getPhysicalRegisterSet(); 088 return D(phys.getFPR(regnum)); 089 } 090 091 /** 092 * Create a long register operand for a given GPR number. 093 * To be used in passthrough expressions like 094 * <pre> 095 * ... Load.create(LONG_LOAD, L(2), A(1), IC(4)) ... 096 * </pre> 097 * 098 * @param regnum the given GPR register number 099 * @return long register operand 100 */ 101 final RegisterOperand L(int regnum) { 102 PhysicalRegisterSet phys = getIR().regpool.getPhysicalRegisterSet(); 103 return L(phys.getGPR(regnum)); 104 } 105 106 /** 107 * Does instruction s have an operand that contains a physical register? 108 */ 109 static boolean hasPhysicalOperand(Instruction s) { 110 for (Enumeration<Operand> e = s.getOperands(); e.hasMoreElements();) { 111 Operand op = e.nextElement(); 112 if (op == null) continue; 113 if (op.isRegister()) { 114 if (op.asRegister().getRegister().isPhysical()) { 115 return true; 116 } 117 } 118 } 119 return false; 120 } 121 }