changeset 21507:4677c5d78ca6

RegisterAllocationConfig: add AllocatableRegisters.
author Josef Eisl <josef.eisl@jku.at>
date Wed, 27 May 2015 12:09:09 +0200
parents 5cbaf1e9ff2e
children dd612c515242
files graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/alloc/RegisterAllocationConfig.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanWalker.java
diffstat 2 files changed, 41 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/alloc/RegisterAllocationConfig.java	Thu May 28 10:59:34 2015 +0200
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/alloc/RegisterAllocationConfig.java	Wed May 27 12:09:09 2015 +0200
@@ -36,6 +36,36 @@
  */
 public class RegisterAllocationConfig {
 
+    public static final class AllocatableRegisters {
+        public final Register[] allocatableRegisters;
+        public final int minRegisterNumber;
+        public final int maxRegisterNumber;
+
+        public AllocatableRegisters(Register[] allocatableRegisters, int minRegisterNumber, int maxRegisterNumber) {
+            this.allocatableRegisters = allocatableRegisters;
+            this.minRegisterNumber = minRegisterNumber;
+            this.maxRegisterNumber = maxRegisterNumber;
+            assert verify(allocatableRegisters, minRegisterNumber, maxRegisterNumber);
+        }
+
+        private static boolean verify(Register[] allocatableRegisters, int minRegisterNumber, int maxRegisterNumber) {
+            int min = Integer.MAX_VALUE;
+            int max = Integer.MIN_VALUE;
+            for (Register reg : allocatableRegisters) {
+                int number = reg.number;
+                if (number < min) {
+                    min = number;
+                }
+                if (number > max) {
+                    max = number;
+                }
+            }
+            assert minRegisterNumber == min;
+            assert maxRegisterNumber == max;
+            return true;
+        }
+    }
+
     public static final String ALL_REGISTERS = "<all>";
 
     private static Register findRegister(String name, Register[] all) {
@@ -47,7 +77,7 @@
         throw new IllegalArgumentException("register " + name + " is not allocatable");
     }
 
-    private static Register[] initAllocatable(Register[] registers) {
+    protected Register[] initAllocatable(Register[] registers) {
         if (RegisterPressure.getValue() != null && !RegisterPressure.getValue().equals(ALL_REGISTERS)) {
             String[] names = RegisterPressure.getValue().split(",");
             Register[] regs = new Register[names.length];
@@ -60,11 +90,12 @@
         return registers;
     }
 
-    private final RegisterConfig registerConfig;
-    private final Map<PlatformKind.Key, Register[]> categorized = new HashMap<>();
+    protected final RegisterConfig registerConfig;
+    private final Map<PlatformKind.Key, AllocatableRegisters> categorized = new HashMap<>();
     private Register[] cachedRegisters;
 
     public RegisterAllocationConfig(RegisterConfig registerConfig) {
+        assert registerConfig != null;
         this.registerConfig = registerConfig;
     }
 
@@ -72,17 +103,19 @@
      * Gets the set of registers that can be used by the register allocator for a value of a
      * particular kind.
      */
-    public Register[] getAllocatableRegisters(PlatformKind kind) {
+    public AllocatableRegisters getAllocatableRegisters(PlatformKind kind) {
         PlatformKind.Key key = kind.getKey();
         if (categorized.containsKey(key)) {
-            Register[] val = categorized.get(key);
+            AllocatableRegisters val = categorized.get(key);
             return val;
         }
-
-        Register[] ret = registerConfig.filterAllocatableRegisters(kind, getAllocatableRegisters());
+        AllocatableRegisters ret = createAllocatableRegisters(registerConfig.filterAllocatableRegisters(kind, getAllocatableRegisters()));
         categorized.put(key, ret);
         return ret;
+    }
 
+    protected AllocatableRegisters createAllocatableRegisters(Register[] registers) {
+        return new AllocatableRegisters(registers, registers[0].number, registers[registers.length - 1].number);
     }
 
     /**
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanWalker.java	Thu May 28 10:59:34 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanWalker.java	Wed May 27 12:09:09 2015 +0200
@@ -858,7 +858,7 @@
     }
 
     void initVarsForAlloc(Interval interval) {
-        availableRegs = allocator.regAllocConfig.getAllocatableRegisters(interval.kind().getPlatformKind());
+        availableRegs = allocator.regAllocConfig.getAllocatableRegisters(interval.kind().getPlatformKind()).allocatableRegisters;
     }
 
     static boolean isMove(LIRInstruction op, Interval from, Interval to) {