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