src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/RegisterAllocationConfig.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/RegisterAllocationConfig.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 org.graalvm.compiler.core.common.alloc;
  24 
  25 import static org.graalvm.compiler.core.common.GraalOptions.RegisterPressure;
  26 
  27 import java.util.HashMap;
  28 import java.util.Map;
  29 
  30 import jdk.vm.ci.code.Register;
  31 import jdk.vm.ci.code.RegisterArray;
  32 import jdk.vm.ci.code.RegisterConfig;
  33 import jdk.vm.ci.meta.PlatformKind;
  34 
  35 import org.graalvm.compiler.core.common.GraalOptions;
  36 
  37 /**
  38  * Configuration for register allocation. This is different to {@link RegisterConfig} as it only
  39  * returns registers specified by {@link GraalOptions#RegisterPressure}.
  40  */
  41 public class RegisterAllocationConfig {
  42 
  43     public static final class AllocatableRegisters {
  44         public final Register[] allocatableRegisters;
  45         public final int minRegisterNumber;
  46         public final int maxRegisterNumber;
  47 
  48         public AllocatableRegisters(RegisterArray allocatableRegisters, int minRegisterNumber, int maxRegisterNumber) {
  49             this.allocatableRegisters = allocatableRegisters.toArray();
  50             this.minRegisterNumber = minRegisterNumber;
  51             this.maxRegisterNumber = maxRegisterNumber;
  52             assert verify(allocatableRegisters, minRegisterNumber, maxRegisterNumber);
  53         }
  54 
  55         private static boolean verify(RegisterArray allocatableRegisters, int minRegisterNumber, int maxRegisterNumber) {
  56             int min = Integer.MAX_VALUE;


  65                 }
  66             }
  67             assert minRegisterNumber == min;
  68             assert maxRegisterNumber == max;
  69             return true;
  70         }
  71     }
  72 
  73     public static final String ALL_REGISTERS = "<all>";
  74 
  75     private static Register findRegister(String name, RegisterArray all) {
  76         for (Register reg : all) {
  77             if (reg.name.equals(name)) {
  78                 return reg;
  79             }
  80         }
  81         throw new IllegalArgumentException("register " + name + " is not allocatable");
  82     }
  83 
  84     protected RegisterArray initAllocatable(RegisterArray registers) {
  85         if (RegisterPressure.getValue() != null && !RegisterPressure.getValue().equals(ALL_REGISTERS)) {
  86             String[] names = RegisterPressure.getValue().split(",");
  87             Register[] regs = new Register[names.length];
  88             for (int i = 0; i < names.length; i++) {
  89                 regs[i] = findRegister(names[i], registers);
  90             }
  91             return new RegisterArray(regs);
  92         }
  93 
  94         return registers;
  95     }
  96 
  97     protected final RegisterConfig registerConfig;
  98     private final Map<PlatformKind.Key, AllocatableRegisters> categorized = new HashMap<>();

  99     private RegisterArray cachedRegisters;
 100 
 101     public RegisterAllocationConfig(RegisterConfig registerConfig) {




 102         assert registerConfig != null;
 103         this.registerConfig = registerConfig;

 104     }
 105 
 106     /**
 107      * Gets the set of registers that can be used by the register allocator for a value of a
 108      * particular kind.
 109      */
 110     public AllocatableRegisters getAllocatableRegisters(PlatformKind kind) {
 111         PlatformKind.Key key = kind.getKey();
 112         if (categorized.containsKey(key)) {
 113             AllocatableRegisters val = categorized.get(key);
 114             return val;
 115         }
 116         AllocatableRegisters ret = createAllocatableRegisters(registerConfig.filterAllocatableRegisters(kind, getAllocatableRegisters()));
 117         categorized.put(key, ret);
 118         return ret;
 119     }
 120 
 121     protected AllocatableRegisters createAllocatableRegisters(RegisterArray registers) {
 122         int min = Integer.MAX_VALUE;
 123         int max = Integer.MIN_VALUE;




   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 org.graalvm.compiler.core.common.alloc;
  24 
  25 import org.graalvm.compiler.core.common.GraalOptions;
  26 import org.graalvm.util.EconomicMap;
  27 import org.graalvm.util.Equivalence;

  28 
  29 import jdk.vm.ci.code.Register;
  30 import jdk.vm.ci.code.RegisterArray;
  31 import jdk.vm.ci.code.RegisterConfig;
  32 import jdk.vm.ci.meta.PlatformKind;
  33 


  34 /**
  35  * Configuration for register allocation. This is different to {@link RegisterConfig} as it only
  36  * returns registers specified by {@link GraalOptions#RegisterPressure}.
  37  */
  38 public class RegisterAllocationConfig {
  39 
  40     public static final class AllocatableRegisters {
  41         public final Register[] allocatableRegisters;
  42         public final int minRegisterNumber;
  43         public final int maxRegisterNumber;
  44 
  45         public AllocatableRegisters(RegisterArray allocatableRegisters, int minRegisterNumber, int maxRegisterNumber) {
  46             this.allocatableRegisters = allocatableRegisters.toArray();
  47             this.minRegisterNumber = minRegisterNumber;
  48             this.maxRegisterNumber = maxRegisterNumber;
  49             assert verify(allocatableRegisters, minRegisterNumber, maxRegisterNumber);
  50         }
  51 
  52         private static boolean verify(RegisterArray allocatableRegisters, int minRegisterNumber, int maxRegisterNumber) {
  53             int min = Integer.MAX_VALUE;


  62                 }
  63             }
  64             assert minRegisterNumber == min;
  65             assert maxRegisterNumber == max;
  66             return true;
  67         }
  68     }
  69 
  70     public static final String ALL_REGISTERS = "<all>";
  71 
  72     private static Register findRegister(String name, RegisterArray all) {
  73         for (Register reg : all) {
  74             if (reg.name.equals(name)) {
  75                 return reg;
  76             }
  77         }
  78         throw new IllegalArgumentException("register " + name + " is not allocatable");
  79     }
  80 
  81     protected RegisterArray initAllocatable(RegisterArray registers) {
  82         if (allocationRestrictedTo != null) {
  83             Register[] regs = new Register[allocationRestrictedTo.length];
  84             for (int i = 0; i < allocationRestrictedTo.length; i++) {
  85                 regs[i] = findRegister(allocationRestrictedTo[i], registers);

  86             }
  87             return new RegisterArray(regs);
  88         }
  89 
  90         return registers;
  91     }
  92 
  93     protected final RegisterConfig registerConfig;
  94     private final EconomicMap<PlatformKind.Key, AllocatableRegisters> categorized = EconomicMap.create(Equivalence.DEFAULT);
  95     private final String[] allocationRestrictedTo;
  96     private RegisterArray cachedRegisters;
  97 
  98     /**
  99      * @param allocationRestrictedTo if not {@code null}, register allocation will be restricted to
 100      *            registers whose names appear in this array
 101      */
 102     public RegisterAllocationConfig(RegisterConfig registerConfig, String[] allocationRestrictedTo) {
 103         assert registerConfig != null;
 104         this.registerConfig = registerConfig;
 105         this.allocationRestrictedTo = allocationRestrictedTo;
 106     }
 107 
 108     /**
 109      * Gets the set of registers that can be used by the register allocator for a value of a
 110      * particular kind.
 111      */
 112     public AllocatableRegisters getAllocatableRegisters(PlatformKind kind) {
 113         PlatformKind.Key key = kind.getKey();
 114         if (categorized.containsKey(key)) {
 115             AllocatableRegisters val = categorized.get(key);
 116             return val;
 117         }
 118         AllocatableRegisters ret = createAllocatableRegisters(registerConfig.filterAllocatableRegisters(kind, getAllocatableRegisters()));
 119         categorized.put(key, ret);
 120         return ret;
 121     }
 122 
 123     protected AllocatableRegisters createAllocatableRegisters(RegisterArray registers) {
 124         int min = Integer.MAX_VALUE;
 125         int max = Integer.MIN_VALUE;


src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/RegisterAllocationConfig.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File