annotate graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotRegisterConfig.java @ 16321:fac4af29aeb8

[SPARC] Fixing lots of float and double issues.
author Stefan Anzinger <stefan.anzinger@gmail.com>
date Thu, 05 Jun 2014 11:28:16 +0200
parents 109d6c7c40b5
children 5f01f7c48d40
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
1 /*
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
4 *
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
7 * published by the Free Software Foundation.
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
8 *
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
13 * accompanied this code).
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
14 *
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
18 *
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
21 * questions.
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
22 */
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
23 package com.oracle.graal.hotspot.sparc;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
24
15259
d90e5c22ba55 Move GraalOptions to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15193
diff changeset
25 import static com.oracle.graal.compiler.common.GraalOptions.*;
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
26 import static com.oracle.graal.sparc.SPARC.*;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
27
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
28 import java.util.*;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
29
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
30 import com.oracle.graal.api.code.*;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
31 import com.oracle.graal.api.code.CallingConvention.Type;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
32 import com.oracle.graal.api.meta.*;
15193
96bb07a5d667 Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents: 15011
diff changeset
33 import com.oracle.graal.compiler.common.*;
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
34 import com.oracle.graal.hotspot.*;
11233
5a9d68c3a7d7 SPARC: a lot of fixes and more
twisti
parents: 10871
diff changeset
35 import com.oracle.graal.lir.*;
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14614
diff changeset
36 import com.oracle.graal.sparc.*;
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
37
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
38 public class SPARCHotSpotRegisterConfig implements RegisterConfig {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
39
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
40 private final Architecture architecture;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
41
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
42 private final Register[] allocatable;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
43
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
44 private final HashMap<PlatformKind, Register[]> categorized = new HashMap<>();
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
45
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
46 private final RegisterAttributes[] attributesMap;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
47
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
48 @Override
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
49 public Register[] getAllocatableRegisters() {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
50 return allocatable.clone();
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
51 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
52
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
53 public Register[] getAllocatableRegisters(PlatformKind kind) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
54 if (categorized.containsKey(kind)) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
55 return categorized.get(kind);
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
56 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
57
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
58 ArrayList<Register> list = new ArrayList<>();
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
59 for (Register reg : getAllocatableRegisters()) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
60 if (architecture.canStoreValue(reg.getRegisterCategory(), kind)) {
16321
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
61 // Special treatment for double precision
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
62 if (kind == Kind.Double) {
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
63 // Only even register numbers are valid double precision regs
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
64 if (reg.number % 2 == 0) {
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
65 list.add(reg);
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
66 }
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
67 } else {
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
68 list.add(reg);
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
69 }
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
70 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
71 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
72
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
73 Register[] ret = list.toArray(new Register[0]);
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
74 categorized.put(kind, ret);
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
75 return ret;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
76 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
77
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
78 @Override
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
79 public RegisterAttributes[] getAttributesMap() {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
80 return attributesMap.clone();
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
81 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
82
10792
7a8d6ba83a04 SPARC: fixes and more stuff works
twisti
parents: 10686
diff changeset
83 private final Register[] cpuCallerParameterRegisters = {o0, o1, o2, o3, o4, o5};
7a8d6ba83a04 SPARC: fixes and more stuff works
twisti
parents: 10686
diff changeset
84 private final Register[] cpuCalleeParameterRegisters = {i0, i1, i2, i3, i4, i5};
7a8d6ba83a04 SPARC: fixes and more stuff works
twisti
parents: 10686
diff changeset
85
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
86 private final Register[] fpuParameterRegisters = {f0, f1, f2, f3, f4, f5, f6, f7};
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
87
10686
73122b5edf6a SPARC: Can compile simple methods and do static calls.
twisti
parents: 10459
diff changeset
88 private final Register[] callerSaveRegisters = {g1, g3, g4, g5, o0, o1, o2, o3, o4, o5, o7};
11233
5a9d68c3a7d7 SPARC: a lot of fixes and more
twisti
parents: 10871
diff changeset
89
5a9d68c3a7d7 SPARC: a lot of fixes and more
twisti
parents: 10871
diff changeset
90 /**
5a9d68c3a7d7 SPARC: a lot of fixes and more
twisti
parents: 10871
diff changeset
91 * Registers saved by the callee. This lists all L and I registers which are saved in the
5a9d68c3a7d7 SPARC: a lot of fixes and more
twisti
parents: 10871
diff changeset
92 * register window. {@link FrameMap} uses this array to calculate the spill area size.
5a9d68c3a7d7 SPARC: a lot of fixes and more
twisti
parents: 10871
diff changeset
93 */
5a9d68c3a7d7 SPARC: a lot of fixes and more
twisti
parents: 10871
diff changeset
94 private final Register[] calleeSaveRegisters = {l0, l1, l2, l3, l4, l5, l6, l7, i0, i1, i2, i3, i4, i5, i6, i7};
10686
73122b5edf6a SPARC: Can compile simple methods and do static calls.
twisti
parents: 10459
diff changeset
95
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
96 private final CalleeSaveLayout csl;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
97
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
98 private static Register findRegister(String name, Register[] all) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
99 for (Register reg : all) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
100 if (reg.name.equals(name)) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
101 return reg;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
102 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
103 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
104 throw new IllegalArgumentException("register " + name + " is not allocatable");
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
105 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
106
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
107 private static Register[] initAllocatable(boolean reserveForHeapBase) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
108 Register[] registers = null;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
109 if (reserveForHeapBase) {
15345
109d6c7c40b5 implement SPARC uncommon trap stub
twisti
parents: 15259
diff changeset
110 // @formatter:off
109d6c7c40b5 implement SPARC uncommon trap stub
twisti
parents: 15259
diff changeset
111 registers = new Register[]{
10854
e1fcdda22831 SPARC: can compile some stubs now but they don't work yet
twisti
parents: 10792
diff changeset
112 // TODO this is not complete
e1fcdda22831 SPARC: can compile some stubs now but they don't work yet
twisti
parents: 10792
diff changeset
113 o0, o1, o2, o3, o4, o5, /*o6,*/ o7,
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
114 l0, l1, l2, l3, l4, l5, l6, l7,
11233
5a9d68c3a7d7 SPARC: a lot of fixes and more
twisti
parents: 10871
diff changeset
115 i0, i1, i2, i3, i4, i5, /*i6,*/ /*i7,*/
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
116 f0, f1, f2, f3, f4, f5, f6, f7
15345
109d6c7c40b5 implement SPARC uncommon trap stub
twisti
parents: 15259
diff changeset
117 };
109d6c7c40b5 implement SPARC uncommon trap stub
twisti
parents: 15259
diff changeset
118 // @formatter:on
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
119 } else {
15345
109d6c7c40b5 implement SPARC uncommon trap stub
twisti
parents: 15259
diff changeset
120 // @formatter:off
109d6c7c40b5 implement SPARC uncommon trap stub
twisti
parents: 15259
diff changeset
121 registers = new Register[]{
10854
e1fcdda22831 SPARC: can compile some stubs now but they don't work yet
twisti
parents: 10792
diff changeset
122 // TODO this is not complete
e1fcdda22831 SPARC: can compile some stubs now but they don't work yet
twisti
parents: 10792
diff changeset
123 o0, o1, o2, o3, o4, o5, /*o6,*/ o7,
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
124 l0, l1, l2, l3, l4, l5, l6, l7,
11233
5a9d68c3a7d7 SPARC: a lot of fixes and more
twisti
parents: 10871
diff changeset
125 i0, i1, i2, i3, i4, i5, /*i6,*/ /*i7,*/
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
126 f0, f1, f2, f3, f4, f5, f6, f7
15345
109d6c7c40b5 implement SPARC uncommon trap stub
twisti
parents: 15259
diff changeset
127 };
109d6c7c40b5 implement SPARC uncommon trap stub
twisti
parents: 15259
diff changeset
128 // @formatter:on
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
129 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
130
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
131 if (RegisterPressure.getValue() != null) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
132 String[] names = RegisterPressure.getValue().split(",");
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
133 Register[] regs = new Register[names.length];
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
134 for (int i = 0; i < names.length; i++) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
135 regs[i] = findRegister(names[i], registers);
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
136 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
137 return regs;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
138 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
139
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
140 return registers;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
141 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
142
14559
883fbd3e06e0 Make size of PlatformKind overridable by VM specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 14003
diff changeset
143 public SPARCHotSpotRegisterConfig(TargetDescription target, HotSpotVMConfig config) {
15011
c8e575742f36 allow compilation with custom RegisterConfig
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
144 this(target, initAllocatable(config.useCompressedOops));
c8e575742f36 allow compilation with custom RegisterConfig
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
145 }
c8e575742f36 allow compilation with custom RegisterConfig
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
146
c8e575742f36 allow compilation with custom RegisterConfig
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
147 public SPARCHotSpotRegisterConfig(TargetDescription target, Register[] allocatable) {
14559
883fbd3e06e0 Make size of PlatformKind overridable by VM specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 14003
diff changeset
148 this.architecture = target.arch;
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
149
14559
883fbd3e06e0 Make size of PlatformKind overridable by VM specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 14003
diff changeset
150 csl = new CalleeSaveLayout(target, -1, -1, target.arch.getWordSize(), calleeSaveRegisters);
15011
c8e575742f36 allow compilation with custom RegisterConfig
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
151 this.allocatable = allocatable.clone();
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
152 attributesMap = RegisterAttributes.createMap(this, SPARC.allRegisters);
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
153 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
154
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
155 @Override
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
156 public Register[] getCallerSaveRegisters() {
10686
73122b5edf6a SPARC: Can compile simple methods and do static calls.
twisti
parents: 10459
diff changeset
157 return callerSaveRegisters;
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
158 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
159
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
160 @Override
14614
abf7cf57df5e added RegisterConfig.areAllAllocatableRegistersCallerSaved()
Doug Simon <doug.simon@oracle.com>
parents: 14559
diff changeset
161 public boolean areAllAllocatableRegistersCallerSaved() {
abf7cf57df5e added RegisterConfig.areAllAllocatableRegistersCallerSaved()
Doug Simon <doug.simon@oracle.com>
parents: 14559
diff changeset
162 return false;
abf7cf57df5e added RegisterConfig.areAllAllocatableRegistersCallerSaved()
Doug Simon <doug.simon@oracle.com>
parents: 14559
diff changeset
163 }
abf7cf57df5e added RegisterConfig.areAllAllocatableRegistersCallerSaved()
Doug Simon <doug.simon@oracle.com>
parents: 14559
diff changeset
164
abf7cf57df5e added RegisterConfig.areAllAllocatableRegistersCallerSaved()
Doug Simon <doug.simon@oracle.com>
parents: 14559
diff changeset
165 @Override
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
166 public Register getRegisterForRole(int index) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
167 throw new UnsupportedOperationException();
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
168 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
169
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
170 @Override
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
171 public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target, boolean stackOnly) {
10792
7a8d6ba83a04 SPARC: fixes and more stuff works
twisti
parents: 10686
diff changeset
172 if (type == Type.JavaCall || type == Type.NativeCall) {
7a8d6ba83a04 SPARC: fixes and more stuff works
twisti
parents: 10686
diff changeset
173 return callingConvention(cpuCallerParameterRegisters, returnType, parameterTypes, type, target, stackOnly);
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
174 }
10792
7a8d6ba83a04 SPARC: fixes and more stuff works
twisti
parents: 10686
diff changeset
175 if (type == Type.JavaCallee) {
7a8d6ba83a04 SPARC: fixes and more stuff works
twisti
parents: 10686
diff changeset
176 return callingConvention(cpuCalleeParameterRegisters, returnType, parameterTypes, type, target, stackOnly);
7a8d6ba83a04 SPARC: fixes and more stuff works
twisti
parents: 10686
diff changeset
177 }
7a8d6ba83a04 SPARC: fixes and more stuff works
twisti
parents: 10686
diff changeset
178 throw GraalInternalError.shouldNotReachHere();
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
179 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
180
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
181 public Register[] getCallingConventionRegisters(Type type, Kind kind) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
182 if (architecture.canStoreValue(FPU, kind)) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
183 return fpuParameterRegisters;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
184 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
185 assert architecture.canStoreValue(CPU, kind);
10792
7a8d6ba83a04 SPARC: fixes and more stuff works
twisti
parents: 10686
diff changeset
186 return type == Type.JavaCallee ? cpuCalleeParameterRegisters : cpuCallerParameterRegisters;
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
187 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
188
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
189 private CallingConvention callingConvention(Register[] generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, Type type, TargetDescription target, boolean stackOnly) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
190 AllocatableValue[] locations = new AllocatableValue[parameterTypes.length];
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
191
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
192 int currentGeneral = 0;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
193 int currentFloating = 0;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
194 int currentStackOffset = 0;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
195
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
196 for (int i = 0; i < parameterTypes.length; i++) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
197 final Kind kind = parameterTypes[i].getKind();
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
198
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
199 switch (kind) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
200 case Byte:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
201 case Boolean:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
202 case Short:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
203 case Char:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
204 case Int:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
205 case Long:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
206 case Object:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
207 if (!stackOnly && currentGeneral < generalParameterRegisters.length) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
208 Register register = generalParameterRegisters[currentGeneral++];
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
209 locations[i] = register.asValue(kind);
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
210 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
211 break;
16321
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
212 case Double:
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
213 if (!stackOnly && currentFloating < fpuParameterRegisters.length) {
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
214 if (currentFloating % 2 != 0) {
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
215 // Make register number even to be a double reg
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
216 currentFloating++;
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
217 }
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
218 Register register = fpuParameterRegisters[currentFloating];
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
219 currentFloating += 2; // Only every second is a double register
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
220 locations[i] = register.asValue(kind);
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
221 }
fac4af29aeb8 [SPARC] Fixing lots of float and double issues.
Stefan Anzinger <stefan.anzinger@gmail.com>
parents: 15345
diff changeset
222 break;
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
223 case Float:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
224 if (!stackOnly && currentFloating < fpuParameterRegisters.length) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
225 Register register = fpuParameterRegisters[currentFloating++];
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
226 locations[i] = register.asValue(kind);
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
227 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
228 break;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
229 default:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
230 throw GraalInternalError.shouldNotReachHere();
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
231 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
232
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
233 if (locations[i] == null) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
234 locations[i] = StackSlot.get(kind.getStackKind(), currentStackOffset, !type.out);
14559
883fbd3e06e0 Make size of PlatformKind overridable by VM specific code.
Roland Schatz <roland.schatz@oracle.com>
parents: 14003
diff changeset
235 currentStackOffset += Math.max(target.getSizeInBytes(kind), target.wordSize);
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
236 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
237 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
238
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
239 Kind returnKind = returnType == null ? Kind.Void : returnType.getKind();
14003
0c38906450a0 Make conversion from Stamp to PlatformKind extensible by backend.
Roland Schatz <roland.schatz@oracle.com>
parents: 11233
diff changeset
240 AllocatableValue returnLocation = returnKind == Kind.Void ? Value.ILLEGAL : getReturnRegister(returnKind, type).asValue(returnKind.getStackKind());
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
241 return new CallingConvention(currentStackOffset, returnLocation, locations);
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
242 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
243
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
244 @Override
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
245 public Register getReturnRegister(Kind kind) {
10871
c3b09d69dfde SPARC: fixes and more implementation; can now allocate objects
twisti
parents: 10854
diff changeset
246 return getReturnRegister(kind, Type.JavaCallee);
c3b09d69dfde SPARC: fixes and more implementation; can now allocate objects
twisti
parents: 10854
diff changeset
247 }
c3b09d69dfde SPARC: fixes and more implementation; can now allocate objects
twisti
parents: 10854
diff changeset
248
c3b09d69dfde SPARC: fixes and more implementation; can now allocate objects
twisti
parents: 10854
diff changeset
249 private static Register getReturnRegister(Kind kind, Type type) {
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
250 switch (kind) {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
251 case Boolean:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
252 case Byte:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
253 case Char:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
254 case Short:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
255 case Int:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
256 case Long:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
257 case Object:
10871
c3b09d69dfde SPARC: fixes and more implementation; can now allocate objects
twisti
parents: 10854
diff changeset
258 return type == Type.JavaCallee ? i0 : o0;
10459
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
259 case Float:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
260 case Double:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
261 return f0;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
262 case Void:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
263 case Illegal:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
264 return null;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
265 default:
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
266 throw new UnsupportedOperationException("no return register for type " + kind);
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
267 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
268 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
269
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
270 @Override
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
271 public Register getFrameRegister() {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
272 return sp;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
273 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
274
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
275 public CalleeSaveLayout getCalleeSaveLayout() {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
276 return csl;
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
277 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
278
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
279 @Override
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
280 public String toString() {
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
281 return String.format("Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" + "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n");
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
282 }
f78079947084 some basic SPARC arithmetic works
twisti
parents:
diff changeset
283 }