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