< prev index next >

src/jdk.vm.ci/share/classes/jdk.vm.ci.code/src/jdk/vm/ci/code/Register.java

Print this page




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package jdk.vm.ci.code;
  24 
  25 import jdk.vm.ci.meta.ValueKind;
  26 
  27 /**
  28  * Represents a target machine register.
  29  */
  30 public final class Register implements Comparable<Register> {
  31 
  32     public static final RegisterCategory SPECIAL = new RegisterCategory("SPECIAL");
  33 
  34     /**
  35      * Invalid register.
  36      */
  37     public static final Register None = new Register(-1, -1, "noreg", SPECIAL);
  38 
  39     /**
  40      * Frame pointer of the current method. All spill slots and outgoing stack-based arguments are
  41      * addressed relative to this register.
  42      */
  43     public static final Register Frame = new Register(-2, -2, "framereg", SPECIAL);
  44 
  45     public static final Register CallerFrame = new Register(-3, -3, "callerframereg", SPECIAL);
  46 
  47     /**
  48      * The identifier for this register that is unique across all the registers in a
  49      * {@link Architecture}. A valid register has {@code number > 0}.
  50      */
  51     public final int number;
  52 
  53     /**
  54      * The mnemonic of this register.
  55      */
  56     public final String name;
  57 
  58     /**
  59      * The actual encoding in a target machine instruction for this register, which may or may not
  60      * be the same as {@link #number}.
  61      */
  62     public final int encoding;
  63 
  64     /**
  65      * The assembler calls this method to get the register's encoding.
  66      */
  67     public int encoding() {
  68         return encoding;
  69     }


 148     }
 149 
 150     /**
 151      * Gets this register as a {@linkplain RegisterValue value} with no particular kind.
 152      *
 153      * @return a {@link RegisterValue} with {@link ValueKind#Illegal} kind.
 154      */
 155     public RegisterValue asValue() {
 156         return asValue(ValueKind.Illegal);
 157     }
 158 
 159     /**
 160      * Determines if this is a valid register.
 161      *
 162      * @return {@code true} iff this register is valid
 163      */
 164     public boolean isValid() {
 165         return number >= 0;
 166     }
 167 
 168     /**
 169      * Gets the maximum register {@linkplain #number number} in a given set of registers.
 170      *
 171      * @param registers the set of registers to process
 172      * @return the maximum register number for any register in {@code registers}
 173      */
 174     public static int maxRegisterNumber(Register[] registers) {
 175         int max = Integer.MIN_VALUE;
 176         for (Register r : registers) {
 177             if (r.number > max) {
 178                 max = r.number;
 179             }
 180         }
 181         return max;
 182     }
 183 
 184     /**
 185      * Gets the maximum register {@linkplain #encoding encoding} in a given set of registers.
 186      *
 187      * @param registers the set of registers to process
 188      * @return the maximum register encoding for any register in {@code registers}
 189      */
 190     public static int maxRegisterEncoding(Register[] registers) {
 191         int max = Integer.MIN_VALUE;
 192         for (Register r : registers) {
 193             if (r.encoding > max) {
 194                 max = r.encoding;
 195             }
 196         }
 197         return max;
 198     }
 199 
 200     @Override
 201     public String toString() {
 202         return name;
 203     }
 204 
 205     @Override
 206     public int compareTo(Register o) {
 207         if (number < o.number) {
 208             return -1;
 209         }
 210         if (number > o.number) {
 211             return 1;
 212         }
 213         return 0;
 214     }
 215 
 216     @Override
 217     public int hashCode() {
 218         return 17 + name.hashCode();
 219     }


  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package jdk.vm.ci.code;
  24 
  25 import jdk.vm.ci.meta.ValueKind;
  26 
  27 /**
  28  * Represents a target machine register.
  29  */
  30 public final class Register implements Comparable<Register> {
  31 
  32     public static final RegisterCategory SPECIAL = new RegisterCategory("SPECIAL");
  33 
  34     /**
  35      * Invalid register.
  36      */
  37     public static final Register None = new Register(-1, -1, "noreg", SPECIAL);
  38 
  39     /**








  40      * The identifier for this register that is unique across all the registers in a
  41      * {@link Architecture}. A valid register has {@code number >= 0}.
  42      */
  43     public final int number;
  44 
  45     /**
  46      * The mnemonic of this register.
  47      */
  48     public final String name;
  49 
  50     /**
  51      * The actual encoding in a target machine instruction for this register, which may or may not
  52      * be the same as {@link #number}.
  53      */
  54     public final int encoding;
  55 
  56     /**
  57      * The assembler calls this method to get the register's encoding.
  58      */
  59     public int encoding() {
  60         return encoding;
  61     }


 140     }
 141 
 142     /**
 143      * Gets this register as a {@linkplain RegisterValue value} with no particular kind.
 144      *
 145      * @return a {@link RegisterValue} with {@link ValueKind#Illegal} kind.
 146      */
 147     public RegisterValue asValue() {
 148         return asValue(ValueKind.Illegal);
 149     }
 150 
 151     /**
 152      * Determines if this is a valid register.
 153      *
 154      * @return {@code true} iff this register is valid
 155      */
 156     public boolean isValid() {
 157         return number >= 0;
 158     }
 159 
































 160     @Override
 161     public String toString() {
 162         return name;
 163     }
 164 
 165     @Override
 166     public int compareTo(Register o) {
 167         if (number < o.number) {
 168             return -1;
 169         }
 170         if (number > o.number) {
 171             return 1;
 172         }
 173         return 0;
 174     }
 175 
 176     @Override
 177     public int hashCode() {
 178         return 17 + name.hashCode();
 179     }
< prev index next >