001/*
002 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package jdk.internal.jvmci.code;
024
025import jdk.internal.jvmci.code.CallingConvention.*;
026import jdk.internal.jvmci.meta.*;
027
028/**
029 * A register configuration binds roles and {@linkplain RegisterAttributes attributes} to physical
030 * registers.
031 */
032public interface RegisterConfig {
033
034    /**
035     * Gets the register to be used for returning a value of a given kind.
036     */
037    Register getReturnRegister(Kind kind);
038
039    /**
040     * Gets the maximum allowed size of the frame.
041     */
042    default int getMaximumFrameSize() {
043        return Integer.MAX_VALUE;
044    }
045
046    /**
047     * Gets the register to which {@link Register#Frame} and {@link Register#CallerFrame} are bound.
048     */
049    Register getFrameRegister();
050
051    /**
052     * Gets the calling convention describing how arguments are passed.
053     *
054     * @param type the type of calling convention being requested
055     * @param returnType the return type (can be null for methods returning {@code void})
056     * @param parameterTypes the types of the arguments of the call
057     * @param target the target platform
058     * @param stackOnly ignore registers
059     */
060    CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target, boolean stackOnly);
061
062    /**
063     * Gets the ordered set of registers that are can be used to pass parameters according to a
064     * given calling convention.
065     *
066     * @param type the type of calling convention
067     * @param kind specifies what kind of registers is being requested
068     * @return the ordered set of registers that may be used to pass parameters in a call conforming
069     *         to {@code type}
070     */
071    Register[] getCallingConventionRegisters(Type type, Kind kind);
072
073    /**
074     * Gets the set of all registers that might be used by the register allocator.
075     *
076     * To get the set of registers the register allocator is allowed to use see
077     * {@link RegisterAllocationConfig#getAllocatableRegisters()}
078     */
079    @SuppressWarnings("javadoc")
080    Register[] getAllocatableRegisters();
081
082    /**
083     * Filters a set of registers and returns only those that can be used by the register allocator
084     * for a value of a particular kind.
085     */
086    Register[] filterAllocatableRegisters(PlatformKind kind, Register[] registers);
087
088    /**
089     * Gets the registers whose values must be preserved by a method across any call it makes.
090     */
091    Register[] getCallerSaveRegisters();
092
093    /**
094     * Gets the layout of the callee save area of this register configuration.
095     *
096     * @return {@code null} if there is no callee save area
097     */
098    CalleeSaveLayout getCalleeSaveLayout();
099
100    /**
101     * Gets a map from register {@linkplain Register#number numbers} to register
102     * {@linkplain RegisterAttributes attributes} for this register configuration.
103     *
104     * @return an array where an element at index i holds the attributes of the register whose
105     *         number is i
106     */
107    RegisterAttributes[] getAttributesMap();
108
109    /**
110     * Gets the register corresponding to a runtime-defined role.
111     *
112     * @param id the identifier of a runtime-defined register role
113     * @return the register playing the role specified by {@code id}
114     */
115    Register getRegisterForRole(int id);
116
117    /**
118     * Determines if all {@link #getAllocatableRegisters() allocatable} registers are
119     * {@link #getCallerSaveRegisters() caller saved}.
120     */
121    boolean areAllAllocatableRegistersCallerSaved();
122}