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 org.jikesrvm.ArchitectureSpecificOpt.PhysicalRegisterSet;
016    import org.jikesrvm.classloader.RVMMethod;
017    import org.jikesrvm.classloader.TypeReference;
018    import org.jikesrvm.compilers.opt.ir.operand.RegisterOperand;
019    
020    /**
021     * Pool of symbolic registers.
022     * Each IR contains has exactly one register pool object associated with it.
023     *
024     * @see Register
025     */
026    public class GenericRegisterPool extends AbstractRegisterPool {
027    
028      protected final PhysicalRegisterSet physical = new PhysicalRegisterSet();
029    
030      public PhysicalRegisterSet getPhysicalRegisterSet() {
031        return physical;
032      }
033    
034      /**
035       * Initializes a new register pool for the method meth.
036       *
037       * @param meth the RVMMethod of the outermost method
038       */
039      protected GenericRegisterPool(RVMMethod meth) {
040        // currentNum is assigned an initial value to avoid overlap of
041        // physical and symbolic registers.
042        currentNum = PhysicalRegisterSet.getSize();
043      }
044    
045      /**
046       * Return the number of symbolic registers (doesn't count physical ones)
047       * @return the number of symbolic registers allocated by the pool
048       */
049      public int getNumberOfSymbolicRegisters() {
050        int start = PhysicalRegisterSet.getSize();
051        return currentNum - start;
052      }
053    
054      /**
055       * Get the Framepointer (FP)
056       *
057       * @return the FP register
058       */
059      public Register getFP() {
060        return physical.getFP();
061      }
062    
063      /**
064       * Get a temporary that represents the FP register
065       *
066       * @return the temp
067       */
068      public RegisterOperand makeFPOp() {
069        return new RegisterOperand(getFP(), TypeReference.Address);
070      }
071    
072      /**
073       * Get a temporary that represents the PR register
074       *
075       * @return the temp
076       */
077      public RegisterOperand makeTROp() {
078        RegisterOperand trOp = new RegisterOperand(physical.getTR(), TypeReference.Thread);
079        trOp.setPreciseType();
080        return trOp;
081      }
082    
083    }