Mercurial > hg > graal-compiler
view graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/alloc/RegisterAllocationConfig.java @ 21556:48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 27 May 2015 00:36:16 +0200 |
parents | c6545476bc77 |
children | ce2113326bc8 |
line wrap: on
line source
/* * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.oracle.graal.compiler.common.alloc; import com.oracle.jvmci.code.RegisterConfig; import com.oracle.jvmci.code.Register; import com.oracle.jvmci.meta.PlatformKind; import static com.oracle.graal.compiler.common.GraalOptions.*; import java.util.*; import com.oracle.graal.compiler.common.*; /** * Configuration for register allocation. This is different to {@link RegisterConfig} as it only * returns registers specified by {@link GraalOptions#RegisterPressure}. */ public class RegisterAllocationConfig { public static final String ALL_REGISTERS = "<all>"; private static Register findRegister(String name, Register[] all) { for (Register reg : all) { if (reg.name.equals(name)) { return reg; } } throw new IllegalArgumentException("register " + name + " is not allocatable"); } private static Register[] initAllocatable(Register[] registers) { if (RegisterPressure.getValue() != null && !RegisterPressure.getValue().equals(ALL_REGISTERS)) { String[] names = RegisterPressure.getValue().split(","); Register[] regs = new Register[names.length]; for (int i = 0; i < names.length; i++) { regs[i] = findRegister(names[i], registers); } return regs; } return registers; } private final RegisterConfig registerConfig; private final Map<PlatformKind.Key, Register[]> categorized = new HashMap<>(); private Register[] cachedRegisters; public RegisterAllocationConfig(RegisterConfig registerConfig) { this.registerConfig = registerConfig; } /** * 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) { PlatformKind.Key key = kind.getKey(); if (categorized.containsKey(key)) { Register[] val = categorized.get(key); return val; } Register[] ret = registerConfig.filterAllocatableRegisters(kind, getAllocatableRegisters()); categorized.put(key, ret); return ret; } /** * Gets the set of registers that can be used by the register allocator. */ public Register[] getAllocatableRegisters() { if (cachedRegisters == null) { cachedRegisters = initAllocatable(registerConfig.getAllocatableRegisters()); } assert cachedRegisters != null; return cachedRegisters; } public RegisterConfig getRegisterConfig() { return registerConfig; } }