1/*
2 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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 */
23package jdk.vm.ci.code;
24
25import jdk.vm.ci.code.CallingConvention.Type;
26import jdk.vm.ci.meta.JavaKind;
27import jdk.vm.ci.meta.JavaType;
28import jdk.vm.ci.meta.PlatformKind;
29import jdk.vm.ci.meta.ValueKind;
30
31/**
32 * A register configuration binds roles and {@linkplain RegisterAttributes attributes} to physical
33 * registers.
34 */
35public interface RegisterConfig {
36
37    /**
38     * Gets the register to be used for returning a value of a given kind.
39     */
40    Register getReturnRegister(JavaKind kind);
41
42    /**
43     * Gets the maximum allowed size of the frame.
44     */
45    default int getMaximumFrameSize() {
46        return Integer.MAX_VALUE;
47    }
48
49    /**
50     * Gets the register used as the frame pointer. Spill slots and outgoing stack-based arguments
51     * are addressed relative to this register.
52     */
53    Register getFrameRegister();
54
55    /**
56     * Gets the calling convention describing how arguments are passed.
57     *
58     * @param type the type of calling convention being requested
59     * @param returnType the return type (can be null for methods returning {@code void})
60     * @param parameterTypes the types of the arguments of the call
61     * @param valueKindFactory the factory to create custom {@link ValueKind ValueKinds}
62     */
63    CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, ValueKindFactory<?> valueKindFactory);
64
65    /**
66     * Gets the ordered set of registers that are can be used to pass parameters according to a
67     * given calling convention.
68     *
69     * @param type the type of calling convention
70     * @param kind specifies what kind of registers is being requested
71     * @return the ordered set of registers that may be used to pass parameters in a call conforming
72     *         to {@code type}
73     */
74    RegisterArray getCallingConventionRegisters(Type type, JavaKind kind);
75
76    /**
77     * Gets the set of all registers that might be used by the register allocator.
78     *
79     * To get the set of registers the register allocator is allowed to use see
80     * {@link RegisterAllocationConfig#getAllocatableRegisters()}
81     */
82    @SuppressWarnings("javadoc")
83    RegisterArray getAllocatableRegisters();
84
85    /**
86     * Filters a set of registers and returns only those that can be used by the register allocator
87     * for a value of a particular kind.
88     */
89    RegisterArray filterAllocatableRegisters(PlatformKind kind, RegisterArray registers);
90
91    /**
92     * Gets the registers whose values must be preserved by a method across any call it makes.
93     */
94    RegisterArray getCallerSaveRegisters();
95
96    /**
97     * Gets the registers whose values must be preserved by the callee.
98     */
99    RegisterArray getCalleeSaveRegisters();
100
101    /**
102     * Gets a map from register {@linkplain Register#number numbers} to register
103     * {@linkplain RegisterAttributes attributes} for this register configuration.
104     *
105     * @return an array where an element at index i holds the attributes of the register whose
106     *         number is i
107     */
108    RegisterAttributes[] getAttributesMap();
109
110    /**
111     * Determines if all {@link #getAllocatableRegisters() allocatable} registers are
112     * {@link #getCallerSaveRegisters() caller saved}.
113     */
114    boolean areAllAllocatableRegistersCallerSaved();
115}
116