Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotRegisterConfig.java @ 10854:e1fcdda22831
SPARC: can compile some stubs now but they don't work yet
author | twisti |
---|---|
date | Mon, 22 Jul 2013 22:26:49 -0700 |
parents | 7a8d6ba83a04 |
children | c3b09d69dfde |
rev | line source |
---|---|
10459 | 1 /* |
2 * Copyright (c) 2013, 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.graal.hotspot.sparc; | |
24 | |
25 import static com.oracle.graal.sparc.SPARC.*; | |
26 import static com.oracle.graal.phases.GraalOptions.*; | |
27 | |
28 import java.util.*; | |
29 | |
30 import com.oracle.graal.sparc.*; | |
31 import com.oracle.graal.api.code.*; | |
32 import com.oracle.graal.api.code.CallingConvention.Type; | |
33 import com.oracle.graal.api.meta.*; | |
34 import com.oracle.graal.graph.*; | |
35 import com.oracle.graal.hotspot.*; | |
36 | |
37 public class SPARCHotSpotRegisterConfig implements RegisterConfig { | |
38 | |
39 private final Architecture architecture; | |
40 | |
41 private final Register[] allocatable; | |
42 | |
43 private final HashMap<PlatformKind, Register[]> categorized = new HashMap<>(); | |
44 | |
45 private final RegisterAttributes[] attributesMap; | |
46 | |
47 @Override | |
48 public Register[] getAllocatableRegisters() { | |
49 return allocatable.clone(); | |
50 } | |
51 | |
52 public Register[] getAllocatableRegisters(PlatformKind kind) { | |
53 if (categorized.containsKey(kind)) { | |
54 return categorized.get(kind); | |
55 } | |
56 | |
57 ArrayList<Register> list = new ArrayList<>(); | |
58 for (Register reg : getAllocatableRegisters()) { | |
59 if (architecture.canStoreValue(reg.getRegisterCategory(), kind)) { | |
60 list.add(reg); | |
61 } | |
62 } | |
63 | |
64 Register[] ret = list.toArray(new Register[0]); | |
65 categorized.put(kind, ret); | |
66 return ret; | |
67 } | |
68 | |
69 @Override | |
70 public RegisterAttributes[] getAttributesMap() { | |
71 return attributesMap.clone(); | |
72 } | |
73 | |
10792 | 74 private final Register[] cpuCallerParameterRegisters = {o0, o1, o2, o3, o4, o5}; |
75 private final Register[] cpuCalleeParameterRegisters = {i0, i1, i2, i3, i4, i5}; | |
76 | |
10459 | 77 private final Register[] fpuParameterRegisters = {f0, f1, f2, f3, f4, f5, f6, f7}; |
78 | |
10686
73122b5edf6a
SPARC: Can compile simple methods and do static calls.
twisti
parents:
10459
diff
changeset
|
79 private final Register[] callerSaveRegisters = {g1, g3, g4, g5, o0, o1, o2, o3, o4, o5, o7}; |
73122b5edf6a
SPARC: Can compile simple methods and do static calls.
twisti
parents:
10459
diff
changeset
|
80 private final Register[] calleeSaveRegisters = {l0, l1, l2, l3, l4, l5, l6, l7, i0, i1, i2, i3, i4, i5, i6, i7}; |
73122b5edf6a
SPARC: Can compile simple methods and do static calls.
twisti
parents:
10459
diff
changeset
|
81 |
10459 | 82 private final CalleeSaveLayout csl; |
83 | |
84 private static Register findRegister(String name, Register[] all) { | |
85 for (Register reg : all) { | |
86 if (reg.name.equals(name)) { | |
87 return reg; | |
88 } | |
89 } | |
90 throw new IllegalArgumentException("register " + name + " is not allocatable"); | |
91 } | |
92 | |
93 private static Register[] initAllocatable(boolean reserveForHeapBase) { | |
94 Register[] registers = null; | |
95 // @formatter:off | |
96 if (reserveForHeapBase) { | |
97 registers = new Register[] { | |
10854
e1fcdda22831
SPARC: can compile some stubs now but they don't work yet
twisti
parents:
10792
diff
changeset
|
98 // TODO this is not complete |
e1fcdda22831
SPARC: can compile some stubs now but they don't work yet
twisti
parents:
10792
diff
changeset
|
99 o0, o1, o2, o3, o4, o5, /*o6,*/ o7, |
10459 | 100 l0, l1, l2, l3, l4, l5, l6, l7, |
101 i0, i1, i2, i3, i4, i5, /*i6,*/ i7, | |
102 f0, f1, f2, f3, f4, f5, f6, f7 | |
103 }; | |
104 } else { | |
105 registers = new Register[] { | |
10854
e1fcdda22831
SPARC: can compile some stubs now but they don't work yet
twisti
parents:
10792
diff
changeset
|
106 // TODO this is not complete |
e1fcdda22831
SPARC: can compile some stubs now but they don't work yet
twisti
parents:
10792
diff
changeset
|
107 o0, o1, o2, o3, o4, o5, /*o6,*/ o7, |
10459 | 108 l0, l1, l2, l3, l4, l5, l6, l7, |
109 i0, i1, i2, i3, i4, i5, /*i6,*/ i7, | |
110 f0, f1, f2, f3, f4, f5, f6, f7 | |
111 }; | |
112 } | |
113 // @formatter:on | |
114 | |
115 if (RegisterPressure.getValue() != null) { | |
116 String[] names = RegisterPressure.getValue().split(","); | |
117 Register[] regs = new Register[names.length]; | |
118 for (int i = 0; i < names.length; i++) { | |
119 regs[i] = findRegister(names[i], registers); | |
120 } | |
121 return regs; | |
122 } | |
123 | |
124 return registers; | |
125 } | |
126 | |
127 public SPARCHotSpotRegisterConfig(Architecture architecture, HotSpotVMConfig config) { | |
128 this.architecture = architecture; | |
129 | |
10686
73122b5edf6a
SPARC: Can compile simple methods and do static calls.
twisti
parents:
10459
diff
changeset
|
130 csl = new CalleeSaveLayout(architecture, -1, -1, architecture.getWordSize(), calleeSaveRegisters); |
10459 | 131 allocatable = initAllocatable(config.useCompressedOops); |
132 attributesMap = RegisterAttributes.createMap(this, SPARC.allRegisters); | |
133 } | |
134 | |
135 @Override | |
136 public Register[] getCallerSaveRegisters() { | |
10686
73122b5edf6a
SPARC: Can compile simple methods and do static calls.
twisti
parents:
10459
diff
changeset
|
137 return callerSaveRegisters; |
10459 | 138 } |
139 | |
140 @Override | |
141 public Register getRegisterForRole(int index) { | |
142 throw new UnsupportedOperationException(); | |
143 } | |
144 | |
145 @Override | |
146 public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target, boolean stackOnly) { | |
10792 | 147 if (type == Type.JavaCall || type == Type.NativeCall) { |
148 return callingConvention(cpuCallerParameterRegisters, returnType, parameterTypes, type, target, stackOnly); | |
10459 | 149 } |
10792 | 150 if (type == Type.JavaCallee) { |
151 return callingConvention(cpuCalleeParameterRegisters, returnType, parameterTypes, type, target, stackOnly); | |
152 } | |
153 throw GraalInternalError.shouldNotReachHere(); | |
10459 | 154 } |
155 | |
156 public Register[] getCallingConventionRegisters(Type type, Kind kind) { | |
157 if (architecture.canStoreValue(FPU, kind)) { | |
158 return fpuParameterRegisters; | |
159 } | |
160 assert architecture.canStoreValue(CPU, kind); | |
10792 | 161 return type == Type.JavaCallee ? cpuCalleeParameterRegisters : cpuCallerParameterRegisters; |
10459 | 162 } |
163 | |
164 private CallingConvention callingConvention(Register[] generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, Type type, TargetDescription target, boolean stackOnly) { | |
165 AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; | |
166 | |
167 int currentGeneral = 0; | |
168 int currentFloating = 0; | |
169 int currentStackOffset = 0; | |
170 | |
171 for (int i = 0; i < parameterTypes.length; i++) { | |
172 final Kind kind = parameterTypes[i].getKind(); | |
173 | |
174 switch (kind) { | |
175 case Byte: | |
176 case Boolean: | |
177 case Short: | |
178 case Char: | |
179 case Int: | |
180 case Long: | |
181 case Object: | |
182 if (!stackOnly && currentGeneral < generalParameterRegisters.length) { | |
183 Register register = generalParameterRegisters[currentGeneral++]; | |
184 locations[i] = register.asValue(kind); | |
185 } | |
186 break; | |
187 case Float: | |
188 case Double: | |
189 if (!stackOnly && currentFloating < fpuParameterRegisters.length) { | |
190 Register register = fpuParameterRegisters[currentFloating++]; | |
191 locations[i] = register.asValue(kind); | |
192 } | |
193 break; | |
194 default: | |
195 throw GraalInternalError.shouldNotReachHere(); | |
196 } | |
197 | |
198 if (locations[i] == null) { | |
199 locations[i] = StackSlot.get(kind.getStackKind(), currentStackOffset, !type.out); | |
200 currentStackOffset += Math.max(target.arch.getSizeInBytes(kind), target.wordSize); | |
201 } | |
202 } | |
203 | |
204 Kind returnKind = returnType == null ? Kind.Void : returnType.getKind(); | |
205 AllocatableValue returnLocation = returnKind == Kind.Void ? Value.ILLEGAL : getReturnRegister(returnKind).asValue(returnKind); | |
206 return new CallingConvention(currentStackOffset, returnLocation, locations); | |
207 } | |
208 | |
209 @Override | |
210 public Register getReturnRegister(Kind kind) { | |
211 switch (kind) { | |
212 case Boolean: | |
213 case Byte: | |
214 case Char: | |
215 case Short: | |
216 case Int: | |
217 case Long: | |
218 case Object: | |
219 return i0; | |
220 case Float: | |
221 case Double: | |
222 return f0; | |
223 case Void: | |
224 case Illegal: | |
225 return null; | |
226 default: | |
227 throw new UnsupportedOperationException("no return register for type " + kind); | |
228 } | |
229 } | |
230 | |
231 @Override | |
232 public Register getFrameRegister() { | |
233 return sp; | |
234 } | |
235 | |
236 public CalleeSaveLayout getCalleeSaveLayout() { | |
237 return csl; | |
238 } | |
239 | |
240 @Override | |
241 public String toString() { | |
242 return String.format("Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" + "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n"); | |
243 } | |
244 } |