< prev index next >

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

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  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 java.util.ArrayList;
  26 import java.util.List;
  27 
  28 import jdk.vm.ci.meta.AllocatableValue;
  29 import jdk.vm.ci.meta.JavaConstant;
  30 import jdk.vm.ci.meta.JavaValue;
  31 import jdk.vm.ci.meta.PlatformKind;
  32 import jdk.vm.ci.meta.Value;
  33 
  34 /**
  35  * Utility class for working with the {@link Value} class and its subclasses.
  36  */
  37 public final class ValueUtil {
  38 
  39     public static boolean isIllegal(Value value) {
  40         assert value != null;
  41         return Value.ILLEGAL.equals(value);
  42     }
  43 
  44     public static boolean isIllegalJavaValue(JavaValue value) {
  45         assert value != null;
  46         return Value.ILLEGAL.equals(value);
  47     }


  94         assert value != null;
  95         return value instanceof RegisterValue;
  96     }
  97 
  98     public static Register asRegister(Value value) {
  99         return asRegisterValue(value).getRegister();
 100     }
 101 
 102     public static RegisterValue asRegisterValue(Value value) {
 103         assert value != null;
 104         return (RegisterValue) value;
 105     }
 106 
 107     public static Register asRegister(Value value, PlatformKind kind) {
 108         if (value.getPlatformKind() != kind) {
 109             throw new InternalError("needed: " + kind + " got: " + value.getPlatformKind());
 110         } else {
 111             return asRegister(value);
 112         }
 113     }
 114 
 115     public static boolean sameRegister(Value v1, Value v2) {
 116         return isRegister(v1) && isRegister(v2) && asRegister(v1).equals(asRegister(v2));
 117     }
 118 
 119     public static boolean sameRegister(Value v1, Value v2, Value v3) {
 120         return sameRegister(v1, v2) && sameRegister(v1, v3);
 121     }
 122 
 123     /**
 124      * Checks if all the provided values are different physical registers. The parameters can be
 125      * either {@link Register registers}, {@link Value values} or arrays of them. All values that
 126      * are not {@link RegisterValue registers} are ignored.
 127      */
 128     public static boolean differentRegisters(Object... values) {
 129         List<Register> registers = collectRegisters(values, new ArrayList<Register>());
 130         for (int i = 1; i < registers.size(); i++) {
 131             Register r1 = registers.get(i);
 132             for (int j = 0; j < i; j++) {
 133                 Register r2 = registers.get(j);
 134                 if (r1.equals(r2)) {
 135                     return false;
 136                 }
 137             }
 138         }
 139         return true;
 140     }
 141 
 142     private static List<Register> collectRegisters(Object[] values, List<Register> registers) {
 143         for (Object o : values) {
 144             if (o instanceof Register) {
 145                 registers.add((Register) o);
 146             } else if (o instanceof Value) {
 147                 if (isRegister((Value) o)) {
 148                     registers.add(asRegister((Value) o));
 149                 }
 150             } else if (o instanceof Object[]) {
 151                 collectRegisters((Object[]) o, registers);
 152             } else {
 153                 throw new IllegalArgumentException("Not a Register or Value: " + o);
 154             }
 155         }
 156         return registers;
 157     }
 158 
 159     /**
 160      * Subtract sets of registers (x - y).
 161      *
 162      * @param x a set of register to subtract from.
 163      * @param y a set of registers to subtract.
 164      * @return resulting set of registers (x - y).
 165      */
 166     public static Value[] subtractRegisters(Value[] x, Value[] y) {
 167         ArrayList<Value> result = new ArrayList<>(x.length);
 168         for (Value i : x) {
 169             boolean append = true;
 170             for (Value j : y) {
 171                 if (ValueUtil.sameRegister(i, j)) {
 172                     append = false;
 173                     break;
 174                 }
 175             }
 176             if (append) {
 177                 result.add(i);
 178             }
 179         }
 180         Value[] resultArray = new Value[result.size()];
 181         return result.toArray(resultArray);
 182     }
 183 }


   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  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.AllocatableValue;
  26 import jdk.vm.ci.meta.JavaConstant;
  27 import jdk.vm.ci.meta.JavaValue;
  28 import jdk.vm.ci.meta.PlatformKind;
  29 import jdk.vm.ci.meta.Value;
  30 
  31 /**
  32  * Utility class for working with the {@link Value} class and its subclasses.
  33  */
  34 public final class ValueUtil {
  35 
  36     public static boolean isIllegal(Value value) {
  37         assert value != null;
  38         return Value.ILLEGAL.equals(value);
  39     }
  40 
  41     public static boolean isIllegalJavaValue(JavaValue value) {
  42         assert value != null;
  43         return Value.ILLEGAL.equals(value);
  44     }


  91         assert value != null;
  92         return value instanceof RegisterValue;
  93     }
  94 
  95     public static Register asRegister(Value value) {
  96         return asRegisterValue(value).getRegister();
  97     }
  98 
  99     public static RegisterValue asRegisterValue(Value value) {
 100         assert value != null;
 101         return (RegisterValue) value;
 102     }
 103 
 104     public static Register asRegister(Value value, PlatformKind kind) {
 105         if (value.getPlatformKind() != kind) {
 106             throw new InternalError("needed: " + kind + " got: " + value.getPlatformKind());
 107         } else {
 108             return asRegister(value);
 109         }
 110     }





































































 111 }
< prev index next >