Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.hotspot.aarch64/src/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java @ 22784:0ab4d816a7f0
Always check the type of CallingConvention.Type
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Fri, 22 Jan 2016 14:05:49 -0800 |
parents | d63506bb5237 |
children | 7d014b014ce7 |
rev | line source |
---|---|
22759 | 1 /* |
2 * Copyright (c) 2015, 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 jdk.vm.ci.hotspot.aarch64; | |
24 | |
25 import static jdk.vm.ci.aarch64.AArch64.lr; | |
26 import static jdk.vm.ci.aarch64.AArch64.r0; | |
27 import static jdk.vm.ci.aarch64.AArch64.r1; | |
28 import static jdk.vm.ci.aarch64.AArch64.r12; | |
29 import static jdk.vm.ci.aarch64.AArch64.r2; | |
30 import static jdk.vm.ci.aarch64.AArch64.r27; | |
31 import static jdk.vm.ci.aarch64.AArch64.r28; | |
32 import static jdk.vm.ci.aarch64.AArch64.r29; | |
33 import static jdk.vm.ci.aarch64.AArch64.r3; | |
34 import static jdk.vm.ci.aarch64.AArch64.r4; | |
35 import static jdk.vm.ci.aarch64.AArch64.r5; | |
36 import static jdk.vm.ci.aarch64.AArch64.r6; | |
37 import static jdk.vm.ci.aarch64.AArch64.r7; | |
38 import static jdk.vm.ci.aarch64.AArch64.r9; | |
39 import static jdk.vm.ci.aarch64.AArch64.sp; | |
40 import static jdk.vm.ci.aarch64.AArch64.v0; | |
41 import static jdk.vm.ci.aarch64.AArch64.v1; | |
42 import static jdk.vm.ci.aarch64.AArch64.v2; | |
43 import static jdk.vm.ci.aarch64.AArch64.v3; | |
44 import static jdk.vm.ci.aarch64.AArch64.v4; | |
45 import static jdk.vm.ci.aarch64.AArch64.v5; | |
46 import static jdk.vm.ci.aarch64.AArch64.v6; | |
47 import static jdk.vm.ci.aarch64.AArch64.v7; | |
48 | |
49 import java.util.ArrayList; | |
50 import java.util.Arrays; | |
51 import java.util.Collections; | |
52 import java.util.HashSet; | |
53 import java.util.Set; | |
54 | |
55 import jdk.vm.ci.aarch64.AArch64; | |
56 import jdk.vm.ci.code.Architecture; | |
57 import jdk.vm.ci.code.CallingConvention; | |
58 import jdk.vm.ci.code.CallingConvention.Type; | |
59 import jdk.vm.ci.code.Register; | |
60 import jdk.vm.ci.code.RegisterAttributes; | |
61 import jdk.vm.ci.code.RegisterConfig; | |
62 import jdk.vm.ci.code.StackSlot; | |
63 import jdk.vm.ci.code.TargetDescription; | |
64 import jdk.vm.ci.common.JVMCIError; | |
22783
d63506bb5237
Make CallingConvention.Type extensible; remove unused stackOnly parameter
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22759
diff
changeset
|
65 import jdk.vm.ci.hotspot.HotSpotCallingConventionType; |
22759 | 66 import jdk.vm.ci.hotspot.HotSpotVMConfig; |
67 import jdk.vm.ci.meta.AllocatableValue; | |
68 import jdk.vm.ci.meta.JavaKind; | |
69 import jdk.vm.ci.meta.JavaType; | |
70 import jdk.vm.ci.meta.LIRKind; | |
71 import jdk.vm.ci.meta.PlatformKind; | |
72 import jdk.vm.ci.meta.Value; | |
73 | |
74 public class AArch64HotSpotRegisterConfig implements RegisterConfig { | |
75 | |
76 private final Architecture architecture; | |
77 | |
78 private final Register[] allocatable; | |
79 | |
80 private final int maxFrameSize; | |
81 | |
82 /** | |
83 * The caller saved registers always include all parameter registers. | |
84 */ | |
85 private final Register[] callerSaved; | |
86 | |
87 private final boolean allAllocatableAreCallerSaved; | |
88 | |
89 private final RegisterAttributes[] attributesMap; | |
90 | |
91 public int getMaximumFrameSize() { | |
92 return maxFrameSize; | |
93 } | |
94 | |
95 @Override | |
96 public Register[] getAllocatableRegisters() { | |
97 return allocatable.clone(); | |
98 } | |
99 | |
22784
0ab4d816a7f0
Always check the type of CallingConvention.Type
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22783
diff
changeset
|
100 @Override |
22759 | 101 public Register[] filterAllocatableRegisters(PlatformKind kind, Register[] registers) { |
102 ArrayList<Register> list = new ArrayList<>(); | |
103 for (Register reg : registers) { | |
104 if (architecture.canStoreValue(reg.getRegisterCategory(), kind)) { | |
105 list.add(reg); | |
106 } | |
107 } | |
108 | |
109 Register[] ret = list.toArray(new Register[list.size()]); | |
110 return ret; | |
111 } | |
112 | |
113 @Override | |
114 public RegisterAttributes[] getAttributesMap() { | |
115 return attributesMap.clone(); | |
116 } | |
117 | |
118 private final Register[] javaGeneralParameterRegisters = {r1, r2, r3, r4, r5, r6, r7, r0}; | |
119 private final Register[] nativeGeneralParameterRegisters = {r0, r1, r2, r3, r4, r5, r6, r7}; | |
120 private final Register[] simdParameterRegisters = {v0, v1, v2, v3, v4, v5, v6, v7}; | |
121 | |
122 public static final Register inlineCacheRegister = r9; | |
123 | |
124 /** | |
125 * Vtable stubs expect the metaspace Method in r12. | |
126 */ | |
127 public static final Register metaspaceMethodRegister = r12; | |
128 | |
129 public static final Register heapBaseRegister = r27; | |
130 public static final Register threadRegister = r28; | |
131 public static final Register fp = r29; | |
132 | |
133 private static Register[] initAllocatable(Architecture arch, boolean reserveForHeapBase) { | |
134 Register[] allRegisters = arch.getAvailableValueRegisters(); | |
135 Register[] registers = new Register[allRegisters.length - (reserveForHeapBase ? 5 : 4)]; | |
136 | |
137 int idx = 0; | |
138 for (Register reg : allRegisters) { | |
139 if (reg.equals(threadRegister) || reg.equals(fp) || reg.equals(lr) || reg.equals(sp)) { | |
140 // skip thread register, frame pointer, link register and stack pointer | |
141 continue; | |
142 } | |
143 if (reserveForHeapBase && reg.equals(heapBaseRegister)) { | |
144 // skip heap base register | |
145 continue; | |
146 } | |
147 | |
148 registers[idx++] = reg; | |
149 } | |
150 | |
151 assert idx == registers.length; | |
152 return registers; | |
153 } | |
154 | |
155 public AArch64HotSpotRegisterConfig(Architecture architecture, HotSpotVMConfig config) { | |
156 this(architecture, config, initAllocatable(architecture, config.useCompressedOops)); | |
157 assert callerSaved.length >= allocatable.length; | |
158 } | |
159 | |
160 public AArch64HotSpotRegisterConfig(Architecture architecture, HotSpotVMConfig config, Register[] allocatable) { | |
161 this.architecture = architecture; | |
162 this.maxFrameSize = config.maxFrameSize; | |
163 | |
164 this.allocatable = allocatable.clone(); | |
165 Set<Register> callerSaveSet = new HashSet<>(); | |
166 Collections.addAll(callerSaveSet, allocatable); | |
167 Collections.addAll(callerSaveSet, simdParameterRegisters); | |
168 Collections.addAll(callerSaveSet, javaGeneralParameterRegisters); | |
169 Collections.addAll(callerSaveSet, nativeGeneralParameterRegisters); | |
170 callerSaved = callerSaveSet.toArray(new Register[callerSaveSet.size()]); | |
171 | |
172 allAllocatableAreCallerSaved = true; | |
173 attributesMap = RegisterAttributes.createMap(this, AArch64.allRegisters); | |
174 } | |
175 | |
176 @Override | |
177 public Register[] getCallerSaveRegisters() { | |
178 return callerSaved; | |
179 } | |
180 | |
181 public Register[] getCalleeSaveRegisters() { | |
182 return null; | |
183 } | |
184 | |
185 @Override | |
186 public boolean areAllAllocatableRegistersCallerSaved() { | |
187 return allAllocatableAreCallerSaved; | |
188 } | |
189 | |
190 @Override | |
191 public Register getRegisterForRole(int index) { | |
192 throw new UnsupportedOperationException(); | |
193 } | |
194 | |
195 @Override | |
22783
d63506bb5237
Make CallingConvention.Type extensible; remove unused stackOnly parameter
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22759
diff
changeset
|
196 public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target) { |
22784
0ab4d816a7f0
Always check the type of CallingConvention.Type
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22783
diff
changeset
|
197 HotSpotCallingConventionType hotspotType = (HotSpotCallingConventionType) type; |
22783
d63506bb5237
Make CallingConvention.Type extensible; remove unused stackOnly parameter
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22759
diff
changeset
|
198 if (type == HotSpotCallingConventionType.NativeCall) { |
22784
0ab4d816a7f0
Always check the type of CallingConvention.Type
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22783
diff
changeset
|
199 return callingConvention(nativeGeneralParameterRegisters, returnType, parameterTypes, hotspotType, target); |
22759 | 200 } |
201 // On x64, parameter locations are the same whether viewed | |
202 // from the caller or callee perspective | |
22784
0ab4d816a7f0
Always check the type of CallingConvention.Type
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22783
diff
changeset
|
203 return callingConvention(javaGeneralParameterRegisters, returnType, parameterTypes, hotspotType, target); |
22759 | 204 } |
205 | |
22784
0ab4d816a7f0
Always check the type of CallingConvention.Type
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22783
diff
changeset
|
206 @Override |
22759 | 207 public Register[] getCallingConventionRegisters(Type type, JavaKind kind) { |
22784
0ab4d816a7f0
Always check the type of CallingConvention.Type
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22783
diff
changeset
|
208 HotSpotCallingConventionType hotspotType = (HotSpotCallingConventionType) type; |
22759 | 209 switch (kind) { |
210 case Boolean: | |
211 case Byte: | |
212 case Short: | |
213 case Char: | |
214 case Int: | |
215 case Long: | |
216 case Object: | |
22784
0ab4d816a7f0
Always check the type of CallingConvention.Type
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22783
diff
changeset
|
217 return hotspotType == HotSpotCallingConventionType.NativeCall ? nativeGeneralParameterRegisters : javaGeneralParameterRegisters; |
22759 | 218 case Float: |
219 case Double: | |
220 return simdParameterRegisters; | |
221 default: | |
222 throw JVMCIError.shouldNotReachHere(); | |
223 } | |
224 } | |
225 | |
22783
d63506bb5237
Make CallingConvention.Type extensible; remove unused stackOnly parameter
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22759
diff
changeset
|
226 private CallingConvention callingConvention(Register[] generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, HotSpotCallingConventionType type, TargetDescription target) { |
22759 | 227 AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; |
228 | |
229 int currentGeneral = 0; | |
230 int currentSIMD = 0; | |
231 int currentStackOffset = 0; | |
232 | |
233 for (int i = 0; i < parameterTypes.length; i++) { | |
234 final JavaKind kind = parameterTypes[i].getJavaKind().getStackKind(); | |
235 | |
236 switch (kind) { | |
237 case Byte: | |
238 case Boolean: | |
239 case Short: | |
240 case Char: | |
241 case Int: | |
242 case Long: | |
243 case Object: | |
22783
d63506bb5237
Make CallingConvention.Type extensible; remove unused stackOnly parameter
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22759
diff
changeset
|
244 if (currentGeneral < generalParameterRegisters.length) { |
22759 | 245 Register register = generalParameterRegisters[currentGeneral++]; |
246 locations[i] = register.asValue(target.getLIRKind(kind)); | |
247 } | |
248 break; | |
249 case Float: | |
250 case Double: | |
22783
d63506bb5237
Make CallingConvention.Type extensible; remove unused stackOnly parameter
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22759
diff
changeset
|
251 if (currentSIMD < simdParameterRegisters.length) { |
22759 | 252 Register register = simdParameterRegisters[currentSIMD++]; |
253 locations[i] = register.asValue(target.getLIRKind(kind)); | |
254 } | |
255 break; | |
256 default: | |
257 throw JVMCIError.shouldNotReachHere(); | |
258 } | |
259 | |
260 if (locations[i] == null) { | |
261 LIRKind lirKind = target.getLIRKind(kind); | |
262 locations[i] = StackSlot.get(lirKind, currentStackOffset, !type.out); | |
263 currentStackOffset += Math.max(lirKind.getPlatformKind().getSizeInBytes(), target.wordSize); | |
264 } | |
265 } | |
266 | |
267 JavaKind returnKind = returnType == null ? JavaKind.Void : returnType.getJavaKind(); | |
268 AllocatableValue returnLocation = returnKind == JavaKind.Void ? Value.ILLEGAL : getReturnRegister(returnKind).asValue(target.getLIRKind(returnKind.getStackKind())); | |
269 return new CallingConvention(currentStackOffset, returnLocation, locations); | |
270 } | |
271 | |
272 @Override | |
273 public Register getReturnRegister(JavaKind kind) { | |
274 switch (kind) { | |
275 case Boolean: | |
276 case Byte: | |
277 case Char: | |
278 case Short: | |
279 case Int: | |
280 case Long: | |
281 case Object: | |
282 return r0; | |
283 case Float: | |
284 case Double: | |
285 return v0; | |
286 case Void: | |
287 case Illegal: | |
288 return null; | |
289 default: | |
290 throw new UnsupportedOperationException("no return register for type " + kind); | |
291 } | |
292 } | |
293 | |
294 @Override | |
295 public Register getFrameRegister() { | |
296 return sp; | |
297 } | |
298 | |
299 @Override | |
300 public String toString() { | |
301 return String.format("Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" + "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n"); | |
302 } | |
303 } |