comparison graal/Runtime/src/com/sun/hotspot/c1x/HotSpotRegisterConfig.java @ 2297:099e697d8934

Renaming c1x4hotspotsrc => graal and HotSpotVM => Runtime
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 22 Apr 2011 15:08:53 +0200
parents
children
comparison
equal deleted inserted replaced
2296:34354e2e40a3 2297:099e697d8934
1 /*
2 * Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved.
3 *
4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 * that is described in this document. In particular, and without limitation, these intellectual property
6 * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 * more additional patents or pending patent applications in the U.S. and in other countries.
8 *
9 * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 * supplements.
12 *
13 * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 * U.S. and other countries.
17 *
18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 * Company, Ltd.
20 */
21 package com.sun.hotspot.c1x;
22
23 import static com.sun.c1x.target.amd64.AMD64.*;
24
25 import java.util.*;
26
27 import com.sun.c1x.target.amd64.*;
28 import com.sun.c1x.util.*;
29 import com.sun.cri.ci.*;
30 import com.sun.cri.ci.CiCallingConvention.Type;
31 import com.sun.cri.ci.CiRegister.RegisterFlag;
32 import com.sun.cri.ri.*;
33
34 /**
35 * @author Thomas Wuerthinger
36 *
37 */
38 public class HotSpotRegisterConfig implements RiRegisterConfig {
39
40 // be careful - the contents of this array are duplicated in c1x_CodeInstaller.cpp
41 private final CiRegister[] allocatable = {
42 rax, rbx, rcx, rdx, rsi, rdi, r8, r9, /* r10, */r11, r12, r13, r14, /*r15*/
43 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,
44 xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15
45 };
46
47 private final EnumMap<RegisterFlag, CiRegister[]> categorized = CiRegister.categorize(allocatable);
48
49 private final RiRegisterAttributes[] attributesMap;
50
51 @Override
52 public CiRegister[] getAllocatableRegisters() {
53 return allocatable;
54 }
55
56 @Override
57 public EnumMap<RegisterFlag, CiRegister[]> getCategorizedAllocatableRegisters() {
58 return categorized;
59 }
60
61 @Override
62 public RiRegisterAttributes[] getAttributesMap() {
63 return attributesMap;
64 }
65
66 private final CiRegister[] generalParameterRegisters;
67 private final CiRegister[] xmmParameterRegisters = {xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7};
68 private final CiRegister[] allParameterRegisters;
69
70 private final CiRegister[] rsaRegs = {
71 rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi,
72 r8, r9, r10, r11, r12, r13, r14, r15,
73 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,
74 xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15
75 };
76
77 private final CiCalleeSaveArea registerSaveArea;
78
79
80 public HotSpotRegisterConfig(HotSpotVMConfig config, boolean globalStubConfig) {
81 if (config.windowsOs) {
82 generalParameterRegisters = new CiRegister[] {rdx, r8, r9, rdi, rsi, rcx};
83 } else {
84 generalParameterRegisters = new CiRegister[] {rsi, rdx, rcx, r8, r9, rdi};
85 }
86
87 if (globalStubConfig) {
88 registerSaveArea = new CiCalleeSaveArea(-1, 8, rsaRegs);
89 } else {
90 registerSaveArea = CiCalleeSaveArea.EMPTY;
91 }
92
93 attributesMap = RiRegisterAttributes.createMap(this, AMD64.allRegisters);
94 allParameterRegisters = Arrays.copyOf(generalParameterRegisters, generalParameterRegisters.length + xmmParameterRegisters.length);
95 System.arraycopy(xmmParameterRegisters, 0, allParameterRegisters, generalParameterRegisters.length, xmmParameterRegisters.length);
96 }
97
98 @Override
99 public CiRegister[] getCallerSaveRegisters() {
100 return getAllocatableRegisters();
101 }
102
103 @Override
104 public CiRegister getRegisterForRole(int index) {
105 throw new UnsupportedOperationException();
106 }
107
108 @Override
109 public CiCallingConvention getCallingConvention(Type type, CiKind[] parameters, CiTarget target) {
110 if (type == Type.NativeCall) {
111 throw new UnsupportedOperationException();
112 }
113 return callingConvention(parameters, type, target);
114 }
115
116 public CiRegister[] getCallingConventionRegisters(Type type, RegisterFlag flag) {
117 return allParameterRegisters;
118 }
119
120 private CiCallingConvention callingConvention(CiKind[] types, Type type, CiTarget target) {
121 CiValue[] locations = new CiValue[types.length];
122
123 int currentGeneral = 0;
124 int currentXMM = 0;
125 int currentStackIndex = 0;
126
127 for (int i = 0; i < types.length; i++) {
128 final CiKind kind = types[i];
129
130 switch (kind) {
131 case Byte:
132 case Boolean:
133 case Short:
134 case Char:
135 case Int:
136 case Long:
137 case Word:
138 case Object:
139 if (currentGeneral < generalParameterRegisters.length) {
140 CiRegister register = generalParameterRegisters[currentGeneral++];
141 locations[i] = register.asValue(kind);
142 }
143 break;
144 case Float:
145 case Double:
146 if (currentXMM < xmmParameterRegisters.length) {
147 CiRegister register = xmmParameterRegisters[currentXMM++];
148 locations[i] = register.asValue(kind);
149 }
150 break;
151 default:
152 throw Util.shouldNotReachHere();
153 }
154
155 if (locations[i] == null) {
156 // we need to adjust for the frame pointer stored on the stack, which shifts incoming arguments by one slot
157 locations[i] = CiStackSlot.get(kind.stackKind(), currentStackIndex + (type.out ? 0 : 1), !type.out);
158 currentStackIndex += target.spillSlots(kind);
159 }
160 }
161
162 return new CiCallingConvention(locations, currentStackIndex * target.spillSlotSize);
163 }
164
165 @Override
166 public CiRegister getReturnRegister(CiKind kind) {
167 switch (kind) {
168 case Boolean:
169 case Byte:
170 case Char:
171 case Short:
172 case Int:
173 case Long:
174 case Object:
175 case Word:
176 return rax;
177 case Float:
178 case Double:
179 return xmm0;
180 case Void:
181 case Illegal:
182 return null;
183 default:
184 throw new UnsupportedOperationException("no return register for type " + kind);
185 }
186 }
187
188 @Override
189 public CiRegister getScratchRegister() {
190 return r10;
191 }
192
193 @Override
194 public CiRegister getFrameRegister() {
195 return rsp;
196 }
197
198 public CiCalleeSaveArea getCalleeSaveArea() {
199 return registerSaveArea;
200 }
201
202 @Override
203 public String toString() {
204 String res = String.format(
205 "Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" +
206 "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n" +
207 "CalleeSave: " + getCalleeSaveArea() + "%n" +
208 "Scratch: " + getScratchRegister() + "%n");
209 return res;
210 }
211 }