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.compilers.opt.util.BitSetMapping;
017    import org.jikesrvm.compilers.opt.util.ReverseEnumerator;
018    
019    /**
020     * This class represents a set of Registers corresponding to the
021     * physical register set. This class holds the architecture-independent
022     * functionality
023     *
024     * <P> Implementation Note: Each register has an integer field
025     * Register.number.  This class must number the physical registers so
026     * that get(n) returns an Register r with r.number = n!
027     */
028    public abstract class GenericPhysicalRegisterSet implements BitSetMapping {
029    
030      /**
031       * Return the total number of physical registers.
032       */
033      public abstract int getNumberOfPhysicalRegisters();
034    
035      /**
036       * @return the FP register
037       */
038      public abstract Register getFP();
039    
040      /**
041       * @return the thread register
042       */
043      public abstract Register getTR();
044    
045      /**
046       * @return the nth physical GPR
047       */
048      public abstract Register getGPR(int n);
049    
050      /**
051       * @return the first GPR return
052       */
053      public abstract Register getFirstReturnGPR();
054    
055      /**
056       * @return the nth physical FPR
057       */
058      public abstract Register getFPR(int n);
059    
060      /**
061       * @return the nth physical register in the pool.
062       */
063      public abstract Register get(int n);
064    
065      /**
066       * Enumerate all the physical registers in this set.
067       */
068      public abstract Enumeration<Register> enumerateAll();
069    
070      /**
071       * Enumerate all the GPRs in this set.
072       */
073      public abstract Enumeration<Register> enumerateGPRs();
074    
075      /**
076       * Enumerate all the volatile GPRs in this set.
077       */
078      public abstract Enumeration<Register> enumerateVolatileGPRs();
079    
080      /**
081       * Enumerate all the nonvolatile GPRs in this set.
082       */
083      public abstract Enumeration<Register> enumerateNonvolatileGPRs();
084    
085      /**
086       * Enumerate all the volatile FPRs in this set.
087       */
088      public abstract Enumeration<Register> enumerateVolatileFPRs();
089    
090      /**
091       * Enumerate all the nonvolatile FPRs in this set.
092       */
093      public abstract Enumeration<Register> enumerateNonvolatileFPRs();
094    
095      /**
096       * Enumerate all the volatile physical registers
097       */
098      public abstract Enumeration<Register> enumerateVolatiles();
099    
100      /**
101       * Enumerate all the nonvolatile GPRs in this set, backwards
102       */
103      public Enumeration<Register> enumerateNonvolatileGPRsBackwards() {
104        return new ReverseEnumerator<Register>(enumerateNonvolatileGPRs());
105      }
106    
107      /**
108       * Enumerate all the nonvolatile FPRs in this set, backwards.
109       */
110      public Enumeration<Register> enumerateNonvolatileFPRsBackwards() {
111        return new ReverseEnumerator<Register>(enumerateNonvolatileFPRs());
112      }
113    
114      @Override
115      public final Object getMappedObject(int n) {
116        return get(n);
117      }
118    
119      @Override
120      public final int getMappedIndex(Object o) {
121        Register r = (Register) o;
122        return r.number;
123      }
124    
125      @Override
126      public final int getMappingSize() {
127        return getNumberOfPhysicalRegisters();
128      }
129    }