OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/assembler.h" | 5 #include "src/assembler.h" |
6 #include "src/macro-assembler.h" | 6 #include "src/macro-assembler.h" |
7 | 7 |
8 #include "src/compiler/linkage.h" | 8 #include "src/compiler/linkage.h" |
9 | 9 |
10 #include "src/zone.h" | 10 #include "src/zone.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 namespace compiler { | 14 namespace compiler { |
15 | 15 |
16 namespace { | 16 namespace { |
17 // Platform-specific configuration for C calling convention. | |
18 LinkageLocation regloc(Register reg) { | 17 LinkageLocation regloc(Register reg) { |
19 return LinkageLocation::ForRegister(Register::ToAllocationIndex(reg)); | 18 return LinkageLocation::ForRegister(Register::ToAllocationIndex(reg)); |
20 } | 19 } |
21 | 20 |
22 | 21 |
23 LinkageLocation stackloc(int i) { | 22 // Platform-specific configuration for C calling convention. |
24 DCHECK_LT(i, 0); | |
25 return LinkageLocation::ForCallerFrameSlot(i); | |
26 } | |
27 | |
28 | |
29 #if V8_TARGET_ARCH_IA32 | 23 #if V8_TARGET_ARCH_IA32 |
30 // =========================================================================== | 24 // =========================================================================== |
31 // == ia32 =================================================================== | 25 // == ia32 =================================================================== |
32 // =========================================================================== | 26 // =========================================================================== |
33 #define RETURN_REGISTER_0 eax | |
34 #define RETURN_REGISTER_1 edx | |
35 #define CALLEE_SAVE_REGISTERS esi.bit() | edi.bit() | ebx.bit() | 27 #define CALLEE_SAVE_REGISTERS esi.bit() | edi.bit() | ebx.bit() |
36 | 28 |
37 #elif V8_TARGET_ARCH_X64 | 29 #elif V8_TARGET_ARCH_X64 |
38 // =========================================================================== | 30 // =========================================================================== |
39 // == x64 ==================================================================== | 31 // == x64 ==================================================================== |
40 // =========================================================================== | 32 // =========================================================================== |
41 #define RETURN_REGISTER_0 rax | |
42 #define RETURN_REGISTER_1 rdx | |
43 | 33 |
44 #ifdef _WIN64 | 34 #ifdef _WIN64 |
45 // == x64 windows ============================================================ | 35 // == x64 windows ============================================================ |
46 #define STACK_SHADOW_WORDS 4 | 36 #define STACK_SHADOW_WORDS 4 |
47 #define PARAM_REGISTERS rcx, rdx, r8, r9 | 37 #define PARAM_REGISTERS rcx, rdx, r8, r9 |
48 #define CALLEE_SAVE_REGISTERS \ | 38 #define CALLEE_SAVE_REGISTERS \ |
49 rbx.bit() | rdi.bit() | rsi.bit() | r12.bit() | r13.bit() | r14.bit() | \ | 39 rbx.bit() | rdi.bit() | rsi.bit() | r12.bit() | r13.bit() | r14.bit() | \ |
50 r15.bit() | 40 r15.bit() |
51 #define CALLEE_SAVE_FP_REGISTERS \ | 41 #define CALLEE_SAVE_FP_REGISTERS \ |
52 (1 << xmm6.code()) | (1 << xmm7.code()) | (1 << xmm8.code()) | \ | 42 (1 << xmm6.code()) | (1 << xmm7.code()) | (1 << xmm8.code()) | \ |
53 (1 << xmm9.code()) | (1 << xmm10.code()) | (1 << xmm11.code()) | \ | 43 (1 << xmm9.code()) | (1 << xmm10.code()) | (1 << xmm11.code()) | \ |
54 (1 << xmm12.code()) | (1 << xmm13.code()) | (1 << xmm14.code()) | \ | 44 (1 << xmm12.code()) | (1 << xmm13.code()) | (1 << xmm14.code()) | \ |
55 (1 << xmm15.code()) | 45 (1 << xmm15.code()) |
56 #else | 46 #else |
57 // == x64 other ============================================================== | 47 // == x64 other ============================================================== |
58 #define PARAM_REGISTERS rdi, rsi, rdx, rcx, r8, r9 | 48 #define PARAM_REGISTERS rdi, rsi, rdx, rcx, r8, r9 |
59 #define CALLEE_SAVE_REGISTERS \ | 49 #define CALLEE_SAVE_REGISTERS \ |
60 rbx.bit() | r12.bit() | r13.bit() | r14.bit() | r15.bit() | 50 rbx.bit() | r12.bit() | r13.bit() | r14.bit() | r15.bit() |
61 #endif | 51 #endif |
62 | 52 |
63 #elif V8_TARGET_ARCH_X87 | 53 #elif V8_TARGET_ARCH_X87 |
64 // =========================================================================== | 54 // =========================================================================== |
65 // == x87 ==================================================================== | 55 // == x87 ==================================================================== |
66 // =========================================================================== | 56 // =========================================================================== |
67 #define RETURN_REGISTER_0 eax | |
68 #define RETURN_REGISTER_1 edx | |
69 #define CALLEE_SAVE_REGISTERS esi.bit() | edi.bit() | ebx.bit() | 57 #define CALLEE_SAVE_REGISTERS esi.bit() | edi.bit() | ebx.bit() |
70 | 58 |
71 #elif V8_TARGET_ARCH_ARM | 59 #elif V8_TARGET_ARCH_ARM |
72 // =========================================================================== | 60 // =========================================================================== |
73 // == arm ==================================================================== | 61 // == arm ==================================================================== |
74 // =========================================================================== | 62 // =========================================================================== |
75 #define PARAM_REGISTERS r0, r1, r2, r3 | 63 #define PARAM_REGISTERS r0, r1, r2, r3 |
76 #define RETURN_REGISTER_0 r0 | |
77 #define RETURN_REGISTER_1 r1 | |
78 #define CALLEE_SAVE_REGISTERS \ | 64 #define CALLEE_SAVE_REGISTERS \ |
79 r4.bit() | r5.bit() | r6.bit() | r7.bit() | r8.bit() | r9.bit() | r10.bit() | 65 r4.bit() | r5.bit() | r6.bit() | r7.bit() | r8.bit() | r9.bit() | r10.bit() |
80 #define CALLEE_SAVE_FP_REGISTERS \ | 66 #define CALLEE_SAVE_FP_REGISTERS \ |
81 (1 << d8.code()) | (1 << d9.code()) | (1 << d10.code()) | \ | 67 (1 << d8.code()) | (1 << d9.code()) | (1 << d10.code()) | \ |
82 (1 << d11.code()) | (1 << d12.code()) | (1 << d13.code()) | \ | 68 (1 << d11.code()) | (1 << d12.code()) | (1 << d13.code()) | \ |
83 (1 << d14.code()) | (1 << d15.code()) | 69 (1 << d14.code()) | (1 << d15.code()) |
84 | 70 |
85 | 71 |
86 #elif V8_TARGET_ARCH_ARM64 | 72 #elif V8_TARGET_ARCH_ARM64 |
87 // =========================================================================== | 73 // =========================================================================== |
88 // == arm64 ==================================================================== | 74 // == arm64 ==================================================================== |
89 // =========================================================================== | 75 // =========================================================================== |
90 #define PARAM_REGISTERS x0, x1, x2, x3, x4, x5, x6, x7 | 76 #define PARAM_REGISTERS x0, x1, x2, x3, x4, x5, x6, x7 |
91 #define RETURN_REGISTER_0 x0 | |
92 #define RETURN_REGISTER_1 x1 | |
93 #define CALLEE_SAVE_REGISTERS \ | 77 #define CALLEE_SAVE_REGISTERS \ |
94 (1 << x19.code()) | (1 << x20.code()) | (1 << x21.code()) | \ | 78 (1 << x19.code()) | (1 << x20.code()) | (1 << x21.code()) | \ |
95 (1 << x22.code()) | (1 << x23.code()) | (1 << x24.code()) | \ | 79 (1 << x22.code()) | (1 << x23.code()) | (1 << x24.code()) | \ |
96 (1 << x25.code()) | (1 << x26.code()) | (1 << x27.code()) | \ | 80 (1 << x25.code()) | (1 << x26.code()) | (1 << x27.code()) | \ |
97 (1 << x28.code()) | (1 << x29.code()) | (1 << x30.code()) | 81 (1 << x28.code()) | (1 << x29.code()) | (1 << x30.code()) |
98 | 82 |
99 | 83 |
100 #define CALLEE_SAVE_FP_REGISTERS \ | 84 #define CALLEE_SAVE_FP_REGISTERS \ |
101 (1 << d8.code()) | (1 << d9.code()) | (1 << d10.code()) | \ | 85 (1 << d8.code()) | (1 << d9.code()) | (1 << d10.code()) | \ |
102 (1 << d11.code()) | (1 << d12.code()) | (1 << d13.code()) | \ | 86 (1 << d11.code()) | (1 << d12.code()) | (1 << d13.code()) | \ |
103 (1 << d14.code()) | (1 << d15.code()) | 87 (1 << d14.code()) | (1 << d15.code()) |
104 | 88 |
105 #elif V8_TARGET_ARCH_MIPS | 89 #elif V8_TARGET_ARCH_MIPS |
106 // =========================================================================== | 90 // =========================================================================== |
107 // == mips =================================================================== | 91 // == mips =================================================================== |
108 // =========================================================================== | 92 // =========================================================================== |
109 #define PARAM_REGISTERS a0, a1, a2, a3 | 93 #define PARAM_REGISTERS a0, a1, a2, a3 |
110 #define RETURN_REGISTER_0 v0 | |
111 #define RETURN_REGISTER_1 v1 | |
112 #define CALLEE_SAVE_REGISTERS \ | 94 #define CALLEE_SAVE_REGISTERS \ |
113 s0.bit() | s1.bit() | s2.bit() | s3.bit() | s4.bit() | s5.bit() | s6.bit() | \ | 95 s0.bit() | s1.bit() | s2.bit() | s3.bit() | s4.bit() | s5.bit() | s6.bit() | \ |
114 s7.bit() | 96 s7.bit() |
115 #define CALLEE_SAVE_FP_REGISTERS \ | 97 #define CALLEE_SAVE_FP_REGISTERS \ |
116 f20.bit() | f22.bit() | f24.bit() | f26.bit() | f28.bit() | f30.bit() | 98 f20.bit() | f22.bit() | f24.bit() | f26.bit() | f28.bit() | f30.bit() |
117 | 99 |
118 #elif V8_TARGET_ARCH_MIPS64 | 100 #elif V8_TARGET_ARCH_MIPS64 |
119 // =========================================================================== | 101 // =========================================================================== |
120 // == mips64 ================================================================= | 102 // == mips64 ================================================================= |
121 // =========================================================================== | 103 // =========================================================================== |
122 #define PARAM_REGISTERS a0, a1, a2, a3, a4, a5, a6, a7 | 104 #define PARAM_REGISTERS a0, a1, a2, a3, a4, a5, a6, a7 |
123 #define RETURN_REGISTER_0 v0 | |
124 #define RETURN_REGISTER_1 v1 | |
125 #define CALLEE_SAVE_REGISTERS \ | 105 #define CALLEE_SAVE_REGISTERS \ |
126 s0.bit() | s1.bit() | s2.bit() | s3.bit() | s4.bit() | s5.bit() | s6.bit() | \ | 106 s0.bit() | s1.bit() | s2.bit() | s3.bit() | s4.bit() | s5.bit() | s6.bit() | \ |
127 s7.bit() | 107 s7.bit() |
128 #define CALLEE_SAVE_FP_REGISTERS \ | 108 #define CALLEE_SAVE_FP_REGISTERS \ |
129 f20.bit() | f22.bit() | f24.bit() | f26.bit() | f28.bit() | f30.bit() | 109 f20.bit() | f22.bit() | f24.bit() | f26.bit() | f28.bit() | f30.bit() |
130 | 110 |
131 #elif V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64 | 111 #elif V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64 |
132 // =========================================================================== | 112 // =========================================================================== |
133 // == ppc & ppc64 ============================================================ | 113 // == ppc & ppc64 ============================================================ |
134 // =========================================================================== | 114 // =========================================================================== |
135 #define PARAM_REGISTERS r3, r4, r5, r6, r7, r8, r9, r10 | 115 #define PARAM_REGISTERS r3, r4, r5, r6, r7, r8, r9, r10 |
136 #define RETURN_REGISTER_0 r3 | |
137 #define RETURN_REGISTER_1 r4 | |
138 #define CALLEE_SAVE_REGISTERS \ | 116 #define CALLEE_SAVE_REGISTERS \ |
139 r14.bit() | r15.bit() | r16.bit() | r17.bit() | r18.bit() | r19.bit() | \ | 117 r14.bit() | r15.bit() | r16.bit() | r17.bit() | r18.bit() | r19.bit() | \ |
140 r20.bit() | r21.bit() | r22.bit() | r23.bit() | r24.bit() | r25.bit() | \ | 118 r20.bit() | r21.bit() | r22.bit() | r23.bit() | r24.bit() | r25.bit() | \ |
141 r26.bit() | r27.bit() | r28.bit() | r29.bit() | r30.bit() | 119 r26.bit() | r27.bit() | r28.bit() | r29.bit() | r30.bit() |
142 #define CALLEE_SAVE_FP_REGISTERS \ | 120 #define CALLEE_SAVE_FP_REGISTERS \ |
143 d14.bit() | d15.bit() | d16.bit() | d17.bit() | d18.bit() | d19.bit() | \ | 121 d14.bit() | d15.bit() | d16.bit() | d17.bit() | d18.bit() | d19.bit() | \ |
144 d20.bit() | d21.bit() | d22.bit() | d23.bit() | d24.bit() | d25.bit() | \ | 122 d20.bit() | d21.bit() | d22.bit() | d23.bit() | d24.bit() | d25.bit() | \ |
145 d26.bit() | d27.bit() | d28.bit() | d29.bit() | d30.bit() | d31.bit() | 123 d26.bit() | d27.bit() | d28.bit() | d29.bit() | d30.bit() | d31.bit() |
146 | 124 |
147 #else | 125 #else |
148 // =========================================================================== | 126 // =========================================================================== |
149 // == unknown ================================================================ | 127 // == unknown ================================================================ |
150 // =========================================================================== | 128 // =========================================================================== |
151 // Don't define anything. The below code will dynamically fail. | 129 #define UNSUPPORTED_C_LINKAGE 1 |
152 #endif | 130 #endif |
153 } // namespace | 131 } // namespace |
154 | 132 |
155 | 133 |
156 // General code uses the above configuration data. | 134 // General code uses the above configuration data. |
157 CallDescriptor* Linkage::GetSimplifiedCDescriptor( | 135 CallDescriptor* Linkage::GetSimplifiedCDescriptor( |
158 Zone* zone, const MachineSignature* msig) { | 136 Zone* zone, const MachineSignature* msig) { |
159 LocationSignature::Builder locations(zone, msig->return_count(), | 137 LocationSignature::Builder locations(zone, msig->return_count(), |
160 msig->parameter_count()); | 138 msig->parameter_count()); |
161 #if 0 // TODO(titzer): instruction selector tests break here. | 139 #if 0 // TODO(titzer): instruction selector tests break here. |
162 // Check the types of the signature. | 140 // Check the types of the signature. |
163 // Currently no floating point parameters or returns are allowed because | 141 // Currently no floating point parameters or returns are allowed because |
164 // on x87 and ia32, the FP top of stack is involved. | 142 // on x87 and ia32, the FP top of stack is involved. |
165 | 143 |
166 for (size_t i = 0; i < msig->return_count(); i++) { | 144 for (size_t i = 0; i < msig->return_count(); i++) { |
167 MachineType type = RepresentationOf(msig->GetReturn(i)); | 145 MachineType type = RepresentationOf(msig->GetReturn(i)); |
168 CHECK(type != kRepFloat32 && type != kRepFloat64); | 146 CHECK(type != kRepFloat32 && type != kRepFloat64); |
169 } | 147 } |
170 for (size_t i = 0; i < msig->parameter_count(); i++) { | 148 for (size_t i = 0; i < msig->parameter_count(); i++) { |
171 MachineType type = RepresentationOf(msig->GetParam(i)); | 149 MachineType type = RepresentationOf(msig->GetParam(i)); |
172 CHECK(type != kRepFloat32 && type != kRepFloat64); | 150 CHECK(type != kRepFloat32 && type != kRepFloat64); |
173 } | 151 } |
174 #endif | 152 #endif |
175 | 153 |
176 #ifdef RETURN_REGISTER_0 | 154 #ifdef UNSUPPORTED_C_LINKAGE |
177 // Add return location(s). | |
178 CHECK(locations.return_count_ <= 2); | |
179 | |
180 if (locations.return_count_ > 0) { | |
181 locations.AddReturn(regloc(RETURN_REGISTER_0)); | |
182 } | |
183 if (locations.return_count_ > 1) { | |
184 locations.AddReturn(regloc(RETURN_REGISTER_1)); | |
185 } | |
186 #else | |
187 // This method should not be called on unknown architectures. | 155 // This method should not be called on unknown architectures. |
188 V8_Fatal(__FILE__, __LINE__, | 156 V8_Fatal(__FILE__, __LINE__, |
189 "requested C call descriptor on unsupported architecture"); | 157 "requested C call descriptor on unsupported architecture"); |
190 return nullptr; | 158 return nullptr; |
191 #endif | 159 #endif |
192 | 160 |
| 161 // Add return location(s). |
| 162 CHECK(locations.return_count_ <= 2); |
| 163 |
| 164 if (locations.return_count_ > 0) { |
| 165 locations.AddReturn(regloc(kReturnRegister0)); |
| 166 } |
| 167 if (locations.return_count_ > 1) { |
| 168 locations.AddReturn(regloc(kReturnRegister1)); |
| 169 } |
| 170 |
193 const int parameter_count = static_cast<int>(msig->parameter_count()); | 171 const int parameter_count = static_cast<int>(msig->parameter_count()); |
194 | 172 |
195 #ifdef PARAM_REGISTERS | 173 #ifdef PARAM_REGISTERS |
196 static const Register kParamRegisters[] = {PARAM_REGISTERS}; | 174 static const Register kParamRegisters[] = {PARAM_REGISTERS}; |
197 static const int kParamRegisterCount = | 175 static const int kParamRegisterCount = |
198 static_cast<int>(arraysize(kParamRegisters)); | 176 static_cast<int>(arraysize(kParamRegisters)); |
199 #else | 177 #else |
200 static const Register* kParamRegisters = nullptr; | 178 static const Register* kParamRegisters = nullptr; |
201 static const int kParamRegisterCount = 0; | 179 static const int kParamRegisterCount = 0; |
202 #endif | 180 #endif |
203 | 181 |
204 #ifdef STACK_SHADOW_WORDS | 182 #ifdef STACK_SHADOW_WORDS |
205 int stack_offset = STACK_SHADOW_WORDS; | 183 int stack_offset = STACK_SHADOW_WORDS; |
206 #else | 184 #else |
207 int stack_offset = 0; | 185 int stack_offset = 0; |
208 #endif | 186 #endif |
209 // Add register and/or stack parameter(s). | 187 // Add register and/or stack parameter(s). |
210 for (int i = 0; i < parameter_count; i++) { | 188 for (int i = 0; i < parameter_count; i++) { |
211 if (i < kParamRegisterCount) { | 189 if (i < kParamRegisterCount) { |
212 locations.AddParam(regloc(kParamRegisters[i])); | 190 locations.AddParam(regloc(kParamRegisters[i])); |
213 } else { | 191 } else { |
214 locations.AddParam(stackloc(-1 - stack_offset)); | 192 locations.AddParam( |
| 193 LinkageLocation::ForCallerFrameSlot(-1 - stack_offset)); |
215 stack_offset++; | 194 stack_offset++; |
216 } | 195 } |
217 } | 196 } |
218 | 197 |
219 #ifdef CALLEE_SAVE_REGISTERS | 198 #ifdef CALLEE_SAVE_REGISTERS |
220 const RegList kCalleeSaveRegisters = CALLEE_SAVE_REGISTERS; | 199 const RegList kCalleeSaveRegisters = CALLEE_SAVE_REGISTERS; |
221 #else | 200 #else |
222 const RegList kCalleeSaveRegisters = 0; | 201 const RegList kCalleeSaveRegisters = 0; |
223 #endif | 202 #endif |
224 | 203 |
(...skipping 15 matching lines...) Expand all Loading... |
240 0, // stack_parameter_count | 219 0, // stack_parameter_count |
241 Operator::kNoProperties, // properties | 220 Operator::kNoProperties, // properties |
242 kCalleeSaveRegisters, // callee-saved registers | 221 kCalleeSaveRegisters, // callee-saved registers |
243 kCalleeSaveFPRegisters, // callee-saved fp regs | 222 kCalleeSaveFPRegisters, // callee-saved fp regs |
244 CallDescriptor::kNoFlags, // flags | 223 CallDescriptor::kNoFlags, // flags |
245 "c-call"); | 224 "c-call"); |
246 } | 225 } |
247 } | 226 } |
248 } | 227 } |
249 } | 228 } |
OLD | NEW |