Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.hotspot.aarch64/src/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java @ 23392:b3a816d3b844
Backed out changeset: a920338dd4d4
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 12 May 2016 11:06:49 +0200 |
parents | a920338dd4d4 |
children | 1d4ce2d19e52 |
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 | |
198 public Register getRegisterForRole(int index) { | |
199 throw new UnsupportedOperationException(); | |
200 } | |
201 | |
202 @Override | |
22783
d63506bb5237
Make CallingConvention.Type extensible; remove unused stackOnly parameter
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22759
diff
changeset
|
203 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
|
204 HotSpotCallingConventionType hotspotType = (HotSpotCallingConventionType) type; |
22783
d63506bb5237
Make CallingConvention.Type extensible; remove unused stackOnly parameter
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22759
diff
changeset
|
205 if (type == HotSpotCallingConventionType.NativeCall) { |
22784
0ab4d816a7f0
Always check the type of CallingConvention.Type
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22783
diff
changeset
|
206 return callingConvention(nativeGeneralParameterRegisters, returnType, parameterTypes, hotspotType, target); |
22759 | 207 } |
208 // On x64, parameter locations are the same whether viewed | |
209 // 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
|
210 return callingConvention(javaGeneralParameterRegisters, returnType, parameterTypes, hotspotType, target); |
22759 | 211 } |
212 | |
22784
0ab4d816a7f0
Always check the type of CallingConvention.Type
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22783
diff
changeset
|
213 @Override |
22759 | 214 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
|
215 HotSpotCallingConventionType hotspotType = (HotSpotCallingConventionType) type; |
22759 | 216 switch (kind) { |
217 case Boolean: | |
218 case Byte: | |
219 case Short: | |
220 case Char: | |
221 case Int: | |
222 case Long: | |
223 case Object: | |
22784
0ab4d816a7f0
Always check the type of CallingConvention.Type
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22783
diff
changeset
|
224 return hotspotType == HotSpotCallingConventionType.NativeCall ? nativeGeneralParameterRegisters : javaGeneralParameterRegisters; |
22759 | 225 case Float: |
226 case Double: | |
227 return simdParameterRegisters; | |
228 default: | |
23392
b3a816d3b844
Backed out changeset: a920338dd4d4
Doug Simon <doug.simon@oracle.com>
parents:
23387
diff
changeset
|
229 throw JVMCIError.shouldNotReachHere(); |
22759 | 230 } |
231 } | |
232 | |
22783
d63506bb5237
Make CallingConvention.Type extensible; remove unused stackOnly parameter
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22759
diff
changeset
|
233 private CallingConvention callingConvention(Register[] generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, HotSpotCallingConventionType type, TargetDescription target) { |
22759 | 234 AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; |
235 | |
236 int currentGeneral = 0; | |
237 int currentSIMD = 0; | |
238 int currentStackOffset = 0; | |
239 | |
240 for (int i = 0; i < parameterTypes.length; i++) { | |
241 final JavaKind kind = parameterTypes[i].getJavaKind().getStackKind(); | |
242 | |
243 switch (kind) { | |
244 case Byte: | |
245 case Boolean: | |
246 case Short: | |
247 case Char: | |
248 case Int: | |
249 case Long: | |
250 case Object: | |
22783
d63506bb5237
Make CallingConvention.Type extensible; remove unused stackOnly parameter
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22759
diff
changeset
|
251 if (currentGeneral < generalParameterRegisters.length) { |
22759 | 252 Register register = generalParameterRegisters[currentGeneral++]; |
253 locations[i] = register.asValue(target.getLIRKind(kind)); | |
254 } | |
255 break; | |
256 case Float: | |
257 case Double: | |
22783
d63506bb5237
Make CallingConvention.Type extensible; remove unused stackOnly parameter
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22759
diff
changeset
|
258 if (currentSIMD < simdParameterRegisters.length) { |
22759 | 259 Register register = simdParameterRegisters[currentSIMD++]; |
260 locations[i] = register.asValue(target.getLIRKind(kind)); | |
261 } | |
262 break; | |
263 default: | |
23392
b3a816d3b844
Backed out changeset: a920338dd4d4
Doug Simon <doug.simon@oracle.com>
parents:
23387
diff
changeset
|
264 throw JVMCIError.shouldNotReachHere(); |
22759 | 265 } |
266 | |
267 if (locations[i] == null) { | |
268 LIRKind lirKind = target.getLIRKind(kind); | |
269 locations[i] = StackSlot.get(lirKind, currentStackOffset, !type.out); | |
270 currentStackOffset += Math.max(lirKind.getPlatformKind().getSizeInBytes(), target.wordSize); | |
271 } | |
272 } | |
273 | |
274 JavaKind returnKind = returnType == null ? JavaKind.Void : returnType.getJavaKind(); | |
275 AllocatableValue returnLocation = returnKind == JavaKind.Void ? Value.ILLEGAL : getReturnRegister(returnKind).asValue(target.getLIRKind(returnKind.getStackKind())); | |
276 return new CallingConvention(currentStackOffset, returnLocation, locations); | |
277 } | |
278 | |
279 @Override | |
280 public Register getReturnRegister(JavaKind kind) { | |
281 switch (kind) { | |
282 case Boolean: | |
283 case Byte: | |
284 case Char: | |
285 case Short: | |
286 case Int: | |
287 case Long: | |
288 case Object: | |
289 return r0; | |
290 case Float: | |
291 case Double: | |
292 return v0; | |
293 case Void: | |
294 case Illegal: | |
295 return null; | |
296 default: | |
297 throw new UnsupportedOperationException("no return register for type " + kind); | |
298 } | |
299 } | |
300 | |
301 @Override | |
302 public Register getFrameRegister() { | |
303 return sp; | |
304 } | |
305 | |
306 @Override | |
307 public String toString() { | |
308 return String.format("Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" + "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n"); | |
309 } | |
310 } |