Mercurial > hg > graal-compiler
comparison graal/com.oracle.max.cri/src/com/sun/cri/ci/CiRegisterConfig.java @ 3733:e233f5660da4
Added Java files from Maxine project.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 19:59:18 +0100 |
parents | |
children | 319860ae697a |
comparison
equal
deleted
inserted
replaced
3732:3e2e8b8abdaf | 3733:e233f5660da4 |
---|---|
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.sun.cri.ci; | |
24 | |
25 import java.util.*; | |
26 | |
27 import com.sun.cri.ci.CiCallingConvention.Type; | |
28 import com.sun.cri.ci.CiRegister.RegisterFlag; | |
29 import com.sun.cri.ri.*; | |
30 | |
31 /** | |
32 * A default implementation of {@link RiRegisterConfig}. | |
33 */ | |
34 public class CiRegisterConfig implements RiRegisterConfig { | |
35 | |
36 /** | |
37 * The object describing the callee save area of this register configuration. | |
38 */ | |
39 public CiCalleeSaveLayout csl; | |
40 | |
41 /** | |
42 * The minimum register role identifier. | |
43 */ | |
44 public final int minRole; | |
45 | |
46 /** | |
47 * The map from register role IDs to registers. | |
48 */ | |
49 public final CiRegister[] registersRoleMap; | |
50 | |
51 /** | |
52 * The set of registers that can be used by the register allocator. | |
53 */ | |
54 public final CiRegister[] allocatable; | |
55 | |
56 /** | |
57 * The set of registers that can be used by the register allocator, | |
58 * {@linkplain CiRegister#categorize(CiRegister[]) categorized} by register | |
59 * {@linkplain RegisterFlag flags}. | |
60 */ | |
61 public final EnumMap<RegisterFlag, CiRegister[]> categorized; | |
62 | |
63 /** | |
64 * The ordered set of registers used to pass integral arguments. | |
65 */ | |
66 public final CiRegister[] cpuParameters; | |
67 | |
68 /** | |
69 * The ordered set of registers used to pass floating point arguments. | |
70 */ | |
71 public final CiRegister[] fpuParameters; | |
72 | |
73 /** | |
74 * The caller saved registers. | |
75 */ | |
76 public final CiRegister[] callerSave; | |
77 | |
78 /** | |
79 * The register to which {@link CiRegister#Frame} and {@link CiRegister#CallerFrame} are bound. | |
80 */ | |
81 public final CiRegister frame; | |
82 | |
83 /** | |
84 * Register for returning an integral value. | |
85 */ | |
86 public final CiRegister integralReturn; | |
87 | |
88 /** | |
89 * Register for returning a floating point value. | |
90 */ | |
91 public final CiRegister floatingPointReturn; | |
92 | |
93 /** | |
94 * The map from register {@linkplain CiRegister#number numbers} to register | |
95 * {@linkplain RiRegisterAttributes attributes} for this register configuration. | |
96 */ | |
97 public final RiRegisterAttributes[] attributesMap; | |
98 | |
99 /** | |
100 * The scratch register. | |
101 */ | |
102 public final CiRegister scratch; | |
103 | |
104 /** | |
105 * The frame offset of the first stack argument for each calling convention {@link CiCallingConvention.Type}. | |
106 */ | |
107 public final int[] stackArg0Offsets = new int[CiCallingConvention.Type.VALUES.length]; | |
108 | |
109 public CiRegisterConfig( | |
110 CiRegister frame, | |
111 CiRegister integralReturn, | |
112 CiRegister floatingPointReturn, | |
113 CiRegister scratch, | |
114 CiRegister[] allocatable, | |
115 CiRegister[] callerSave, | |
116 CiRegister[] parameters, | |
117 CiCalleeSaveLayout csl, | |
118 CiRegister[] allRegisters, | |
119 Map<Integer, CiRegister> roles) { | |
120 this.frame = frame; | |
121 this.csl = csl; | |
122 this.allocatable = allocatable; | |
123 this.callerSave = callerSave; | |
124 assert !Arrays.asList(allocatable).contains(scratch); | |
125 this.scratch = scratch; | |
126 EnumMap<RegisterFlag, CiRegister[]> categorizedParameters = CiRegister.categorize(parameters); | |
127 this.cpuParameters = categorizedParameters.get(RegisterFlag.CPU); | |
128 this.fpuParameters = categorizedParameters.get(RegisterFlag.FPU); | |
129 categorized = CiRegister.categorize(allocatable); | |
130 attributesMap = RiRegisterAttributes.createMap(this, allRegisters); | |
131 this.floatingPointReturn = floatingPointReturn; | |
132 this.integralReturn = integralReturn; | |
133 int minRoleId = Integer.MAX_VALUE; | |
134 int maxRoleId = Integer.MIN_VALUE; | |
135 for (Map.Entry<Integer, CiRegister> e : roles.entrySet()) { | |
136 int id = e.getKey(); | |
137 assert id >= 0; | |
138 if (minRoleId > id) { | |
139 minRoleId = id; | |
140 } | |
141 if (maxRoleId < id) { | |
142 maxRoleId = id; | |
143 } | |
144 } | |
145 registersRoleMap = new CiRegister[(maxRoleId - minRoleId) + 1]; | |
146 for (Map.Entry<Integer, CiRegister> e : roles.entrySet()) { | |
147 int id = e.getKey(); | |
148 registersRoleMap[id] = e.getValue(); | |
149 } | |
150 minRole = minRoleId; | |
151 } | |
152 | |
153 public CiRegisterConfig(CiRegisterConfig src, CiCalleeSaveLayout csl) { | |
154 this.frame = src.frame; | |
155 this.csl = csl; | |
156 this.allocatable = src.allocatable; | |
157 this.callerSave = src.callerSave; | |
158 this.scratch = src.scratch; | |
159 this.cpuParameters = src.cpuParameters; | |
160 this.fpuParameters = src.fpuParameters; | |
161 this.categorized = src.categorized; | |
162 this.attributesMap = src.attributesMap; | |
163 this.floatingPointReturn = src.floatingPointReturn; | |
164 this.integralReturn = src.integralReturn; | |
165 this.registersRoleMap = src.registersRoleMap; | |
166 this.minRole = src.minRole; | |
167 System.arraycopy(src.stackArg0Offsets, 0, stackArg0Offsets, 0, stackArg0Offsets.length); | |
168 } | |
169 | |
170 public CiRegister getReturnRegister(CiKind kind) { | |
171 if (kind.isDouble() || kind.isFloat()) { | |
172 return floatingPointReturn; | |
173 } | |
174 return integralReturn; | |
175 } | |
176 | |
177 public CiRegister getFrameRegister() { | |
178 return frame; | |
179 } | |
180 | |
181 public CiRegister getScratchRegister() { | |
182 return scratch; | |
183 } | |
184 | |
185 /** | |
186 * {@inheritDoc} | |
187 * | |
188 * This implementation assigns all available registers to parameters before assigning | |
189 * any stack slots to parameters. | |
190 */ | |
191 public CiCallingConvention getCallingConvention(Type type, CiKind[] parameters, CiTarget target, boolean stackOnly) { | |
192 CiValue[] locations = new CiValue[parameters.length]; | |
193 | |
194 int currentGeneral = 0; | |
195 int currentXMM = 0; | |
196 int firstStackIndex = (stackArg0Offsets[type.ordinal()]) / target.spillSlotSize; | |
197 int currentStackIndex = firstStackIndex; | |
198 | |
199 for (int i = 0; i < parameters.length; i++) { | |
200 final CiKind kind = parameters[i]; | |
201 | |
202 switch (kind) { | |
203 case Byte: | |
204 case Boolean: | |
205 case Short: | |
206 case Char: | |
207 case Int: | |
208 case Long: | |
209 case Object: | |
210 if (!stackOnly && currentGeneral < cpuParameters.length) { | |
211 CiRegister register = cpuParameters[currentGeneral++]; | |
212 locations[i] = register.asValue(kind); | |
213 } | |
214 break; | |
215 | |
216 case Float: | |
217 case Double: | |
218 if (!stackOnly && currentXMM < fpuParameters.length) { | |
219 CiRegister register = fpuParameters[currentXMM++]; | |
220 locations[i] = register.asValue(kind); | |
221 } | |
222 break; | |
223 | |
224 default: | |
225 throw new InternalError("Unexpected parameter kind: " + kind); | |
226 } | |
227 | |
228 if (locations[i] == null) { | |
229 locations[i] = CiStackSlot.get(kind.stackKind(), currentStackIndex, !type.out); | |
230 currentStackIndex += target.spillSlots(kind); | |
231 } | |
232 } | |
233 | |
234 return new CiCallingConvention(locations, (currentStackIndex - firstStackIndex) * target.spillSlotSize); | |
235 } | |
236 | |
237 public CiRegister[] getCallingConventionRegisters(Type type, RegisterFlag flag) { | |
238 if (flag == RegisterFlag.CPU) { | |
239 return cpuParameters; | |
240 } | |
241 assert flag == RegisterFlag.FPU; | |
242 return fpuParameters; | |
243 } | |
244 | |
245 public CiRegister[] getAllocatableRegisters() { | |
246 return allocatable; | |
247 } | |
248 | |
249 public EnumMap<RegisterFlag, CiRegister[]> getCategorizedAllocatableRegisters() { | |
250 return categorized; | |
251 } | |
252 | |
253 public CiRegister[] getCallerSaveRegisters() { | |
254 return callerSave; | |
255 } | |
256 | |
257 public CiCalleeSaveLayout getCalleeSaveLayout() { | |
258 return csl; | |
259 } | |
260 | |
261 public RiRegisterAttributes[] getAttributesMap() { | |
262 return attributesMap; | |
263 } | |
264 | |
265 public CiRegister getRegisterForRole(int id) { | |
266 return registersRoleMap[id - minRole]; | |
267 } | |
268 | |
269 @Override | |
270 public String toString() { | |
271 StringBuilder roleMap = new StringBuilder(); | |
272 for (int i = 0; i < registersRoleMap.length; ++i) { | |
273 CiRegister reg = registersRoleMap[i]; | |
274 if (reg != null) { | |
275 if (roleMap.length() != 0) { | |
276 roleMap.append(", "); | |
277 } | |
278 roleMap.append(i + minRole).append(" -> ").append(reg); | |
279 } | |
280 } | |
281 StringBuilder stackArg0OffsetsMap = new StringBuilder(); | |
282 for (Type t : Type.VALUES) { | |
283 if (stackArg0OffsetsMap.length() != 0) { | |
284 stackArg0OffsetsMap.append(", "); | |
285 } | |
286 stackArg0OffsetsMap.append(t).append(" -> ").append(stackArg0Offsets[t.ordinal()]); | |
287 } | |
288 String res = String.format( | |
289 "Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" + | |
290 "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n" + | |
291 "CalleeSave: " + getCalleeSaveLayout() + "%n" + | |
292 "CPU Params: " + Arrays.toString(cpuParameters) + "%n" + | |
293 "FPU Params: " + Arrays.toString(fpuParameters) + "%n" + | |
294 "VMRoles: " + roleMap + "%n" + | |
295 "stackArg0: " + stackArg0OffsetsMap + "%n" + | |
296 "Scratch: " + getScratchRegister() + "%n"); | |
297 return res; | |
298 } | |
299 } |