Mercurial > hg > truffle
comparison graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiRegisterAttributes.java @ 4199:aaac4894175c
Renamed cri packages from sun to oracle.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 03 Jan 2012 16:29:28 +0100 |
parents | graal/com.oracle.max.cri/src/com/sun/cri/ri/RiRegisterAttributes.java@e233f5660da4 |
children |
comparison
equal
deleted
inserted
replaced
4198:8c9c0e1eaab1 | 4199:aaac4894175c |
---|---|
1 /* | |
2 * Copyright (c) 2010, 2011, 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 */ | |
23 package com.oracle.max.cri.ri; | |
24 | |
25 import java.util.*; | |
26 | |
27 import com.oracle.max.cri.ci.*; | |
28 | |
29 /** | |
30 * A collection of register attributes. The specific attribute values for a register may be | |
31 * local to a compilation context. For example, a {@link RiRegisterConfig} in use during | |
32 * a compilation will determine which registers are callee saved. | |
33 */ | |
34 public class RiRegisterAttributes { | |
35 | |
36 /** | |
37 * Denotes a register whose value preservation (if required) across a call is the responsibility of the caller. | |
38 */ | |
39 public final boolean isCallerSave; | |
40 | |
41 /** | |
42 * Denotes a register whose value preservation (if required) across a call is the responsibility of the callee. | |
43 */ | |
44 public final boolean isCalleeSave; | |
45 | |
46 /** | |
47 * Denotes a register that is available for use by a register allocator. | |
48 */ | |
49 public final boolean isAllocatable; | |
50 | |
51 /** | |
52 * Denotes a register guaranteed to be non-zero if read in compiled Java code. | |
53 * For example, a register dedicated to holding the current thread. | |
54 */ | |
55 public boolean isNonZero; | |
56 | |
57 public RiRegisterAttributes(boolean isCallerSave, boolean isCalleeSave, boolean isAllocatable) { | |
58 this.isCallerSave = isCallerSave; | |
59 this.isCalleeSave = isCalleeSave; | |
60 this.isAllocatable = isAllocatable; | |
61 } | |
62 | |
63 public static final RiRegisterAttributes NONE = new RiRegisterAttributes(false, false, false); | |
64 | |
65 /** | |
66 * Creates a map from register {@linkplain CiRegister#number numbers} to register | |
67 * {@linkplain RiRegisterAttributes attributes} for a given register configuration and set of | |
68 * registers. | |
69 * | |
70 * @param registerConfig a register configuration | |
71 * @param registers a set of registers | |
72 * @return an array whose length is the max register number in {@code registers} plus 1. An element at index i holds | |
73 * the attributes of the register whose number is i. | |
74 */ | |
75 public static RiRegisterAttributes[] createMap(RiRegisterConfig registerConfig, CiRegister[] registers) { | |
76 RiRegisterAttributes[] map = new RiRegisterAttributes[registers.length]; | |
77 for (CiRegister reg : registers) { | |
78 if (reg != null) { | |
79 CiCalleeSaveLayout csl = registerConfig.getCalleeSaveLayout(); | |
80 RiRegisterAttributes attr = new RiRegisterAttributes( | |
81 Arrays.asList(registerConfig.getCallerSaveRegisters()).contains(reg), | |
82 csl == null ? false : Arrays.asList(csl.registers).contains(reg), | |
83 Arrays.asList(registerConfig.getAllocatableRegisters()).contains(reg)); | |
84 if (map.length <= reg.number) { | |
85 map = Arrays.copyOf(map, reg.number + 1); | |
86 } | |
87 map[reg.number] = attr; | |
88 } | |
89 } | |
90 for (int i = 0; i < map.length; i++) { | |
91 if (map[i] == null) { | |
92 map[i] = NONE; | |
93 } | |
94 } | |
95 return map; | |
96 } | |
97 } |