Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: src/compiler/c-linkage.cc

Issue 1266603002: [turbofan] Factor C call descriptor building into compiler/c-linkage.cc. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/arm64/linkage-arm64.cc ('k') | src/compiler/ia32/linkage-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/assembler.h"
6 #include "src/macro-assembler.h"
7
8 #include "src/compiler/linkage.h"
9
10 #include "src/zone.h"
11
12 namespace v8 {
13 namespace internal {
14 namespace compiler {
15
16 namespace {
17 // Platform-specific configuration for C calling convention.
18 LinkageLocation regloc(Register reg) {
19 return LinkageLocation(Register::ToAllocationIndex(reg));
20 }
21
22
23 LinkageLocation stackloc(int i) {
24 DCHECK_LT(i, 0);
25 return LinkageLocation(i);
26 }
27
28
29 #if V8_TARGET_ARCH_IA32
30 // ===========================================================================
31 // == ia32 ===================================================================
32 // ===========================================================================
33 #define RETURN_REGISTER_0 eax
34 #define RETURN_REGISTER_1 edx
35 #define CALLEE_SAVE_REGISTERS esi.bit() | edi.bit() | ebx.bit()
36
37 #elif V8_TARGET_ARCH_X64
38 // ===========================================================================
39 // == x64 ====================================================================
40 // ===========================================================================
41 #define RETURN_REGISTER_0 rax
42 #define RETURN_REGISTER_1 rdx
43
44 #ifdef _WIN64
45 // == x64 windows ============================================================
46 #define STACK_SHADOW_WORDS 4
47 #define PARAM_REGISTERS rcx, rdx, r8, r9
48 #define CALLEE_SAVE_REGISTERS \
49 rbx.bit() | rdi.bit() | rsi.bit() | r12.bit() | r13.bit() | r14.bit() | \
50 r15.bit()
51 #define CALLEE_SAVE_FP_REGISTERS \
52 (1 << xmm6.code()) | (1 << xmm7.code()) | (1 << xmm8.code()) | \
53 (1 << xmm9.code()) | (1 << xmm10.code()) | (1 << xmm11.code()) | \
54 (1 << xmm12.code()) | (1 << xmm13.code()) | (1 << xmm14.code()) | \
55 (1 << xmm15.code())
56 #else
57 // == x64 other ==============================================================
58 #define PARAM_REGISTERS rdi, rsi, rdx, rcx, r8, r9
59 #define CALLEE_SAVE_REGISTERS \
60 rbx.bit() | r12.bit() | r13.bit() | r14.bit() | r15.bit()
61 #endif
62
63 #elif V8_TARGET_ARCH_X87
64 // ===========================================================================
65 // == x87 ====================================================================
66 // ===========================================================================
67 #define RETURN_REGISTER_0 eax
68 #define RETURN_REGISTER_1 edx
69 #define CALLEE_SAVE_REGISTERS esi.bit() | edi.bit() | ebx.bit()
70
71 #elif V8_TARGET_ARCH_ARM
72 // ===========================================================================
73 // == arm ====================================================================
74 // ===========================================================================
75 #define PARAM_REGISTERS r0, r1, r2, r3
76 #define RETURN_REGISTER_0 r0
77 #define RETURN_REGISTER_1 r1
78 #define CALLEE_SAVE_REGISTERS \
79 r4.bit() | r5.bit() | r6.bit() | r7.bit() | r8.bit() | r9.bit() | r10.bit()
80 #define CALLEE_SAVE_FP_REGISTERS \
81 (1 << d8.code()) | (1 << d9.code()) | (1 << d10.code()) | \
82 (1 << d11.code()) | (1 << d12.code()) | (1 << d13.code()) | \
83 (1 << d14.code()) | (1 << d15.code())
84
85
86 #elif V8_TARGET_ARCH_ARM64
87 // ===========================================================================
88 // == arm64 ====================================================================
89 // ===========================================================================
90 #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 \
94 (1 << x19.code()) | (1 << x20.code()) | (1 << x21.code()) | \
95 (1 << x22.code()) | (1 << x23.code()) | (1 << x24.code()) | \
96 (1 << x25.code()) | (1 << x26.code()) | (1 << x27.code()) | \
97 (1 << x28.code()) | (1 << x29.code()) | (1 << x30.code())
98
99
100 #define CALLEE_SAVE_FP_REGISTERS \
101 (1 << d8.code()) | (1 << d9.code()) | (1 << d10.code()) | \
102 (1 << d11.code()) | (1 << d12.code()) | (1 << d13.code()) | \
103 (1 << d14.code()) | (1 << d15.code())
104
105 #elif V8_TARGET_ARCH_MIPS
106 // ===========================================================================
107 // == mips ===================================================================
108 // ===========================================================================
109 #define PARAM_REGISTERS a0, a1, a2, a3
110 #define RETURN_REGISTER_0 v0
111 #define RETURN_REGISTER_1 v1
112 #define CALLEE_SAVE_REGISTERS \
113 s0.bit() | s1.bit() | s2.bit() | s3.bit() | s4.bit() | s5.bit() | s6.bit() | \
114 s7.bit()
115 #define CALLEE_SAVE_FP_REGISTERS \
116 f20.bit() | f22.bit() | f24.bit() | f26.bit() | f28.bit() | f30.bit()
117
118 #elif V8_TARGET_ARCH_MIPS64
119 // ===========================================================================
120 // == mips64 =================================================================
121 // ===========================================================================
122 #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 \
126 s0.bit() | s1.bit() | s2.bit() | s3.bit() | s4.bit() | s5.bit() | s6.bit() | \
127 s7.bit()
128 #define CALLEE_SAVE_FP_REGISTERS \
129 f20.bit() | f22.bit() | f24.bit() | f26.bit() | f28.bit() | f30.bit()
130
131 #elif V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64
132 // ===========================================================================
133 // == ppc & ppc64 ============================================================
134 // ===========================================================================
135 #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 \
139 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() | \
141 r26.bit() | r27.bit() | r28.bit() | r29.bit() | r30.bit() | fp.bit()
142
143 #else
144 // ===========================================================================
145 // == unknown ================================================================
146 // ===========================================================================
147 // Don't define anything. The below code will dynamically fail.
148 #endif
149 } // namespace
150
151
152 // General code uses the above configuration data.
153 CallDescriptor* Linkage::GetSimplifiedCDescriptor(
154 Zone* zone, const MachineSignature* msig) {
155 LocationSignature::Builder locations(zone, msig->return_count(),
156 msig->parameter_count());
157 #if 0 // TODO(titzer): instruction selector tests break here.
158 // Check the types of the signature.
159 // Currently no floating point parameters or returns are allowed because
160 // on x87 and ia32, the FP top of stack is involved.
161
162 for (size_t i = 0; i < msig->return_count(); i++) {
163 MachineType type = RepresentationOf(msig->GetReturn(i));
164 CHECK(type != kRepFloat32 && type != kRepFloat64);
165 }
166 for (size_t i = 0; i < msig->parameter_count(); i++) {
167 MachineType type = RepresentationOf(msig->GetParam(i));
168 CHECK(type != kRepFloat32 && type != kRepFloat64);
169 }
170 #endif
171
172 #ifdef RETURN_REGISTER_0
173 // Add return location(s).
174 CHECK(locations.return_count_ <= 2);
175
176 if (locations.return_count_ > 0) {
177 locations.AddReturn(regloc(RETURN_REGISTER_0));
178 }
179 if (locations.return_count_ > 1) {
180 locations.AddReturn(regloc(RETURN_REGISTER_1));
181 }
182 #else
183 // This method should not be called on unknown architectures.
184 V8_Fatal(__FILE__, __LINE__,
185 "requested C call descriptor on unsupported architecture");
186 return nullptr;
187 #endif
188
189 const int parameter_count = static_cast<int>(msig->parameter_count());
190
191 #ifdef PARAM_REGISTERS
192 static const Register kParamRegisters[] = {PARAM_REGISTERS};
193 static const int kParamRegisterCount =
194 static_cast<int>(arraysize(kParamRegisters));
195 #else
196 static const Register* kParamRegisters = nullptr;
197 static const int kParamRegisterCount = 0;
198 #endif
199
200 #ifdef STACK_SHADOW_WORDS
201 int stack_offset = STACK_SHADOW_WORDS;
202 #else
203 int stack_offset = 0;
204 #endif
205 // Add register and/or stack parameter(s).
206 for (int i = 0; i < parameter_count; i++) {
207 if (i < kParamRegisterCount) {
208 locations.AddParam(regloc(kParamRegisters[i]));
209 } else {
210 locations.AddParam(stackloc(-1 - stack_offset));
211 stack_offset++;
212 }
213 }
214
215 #ifdef CALLEE_SAVE_REGISTERS
216 const RegList kCalleeSaveRegisters = CALLEE_SAVE_REGISTERS;
217 #else
218 const RegList kCalleeSaveRegisters = 0;
219 #endif
220
221 #ifdef CALLEE_SAVE_FP_REGISTERS
222 const RegList kCalleeSaveFPRegisters = CALLEE_SAVE_FP_REGISTERS;
223 #else
224 const RegList kCalleeSaveFPRegisters = 0;
225 #endif
226
227 // The target for C calls is always an address (i.e. machine pointer).
228 MachineType target_type = kMachPtr;
229 LinkageLocation target_loc = LinkageLocation::AnyRegister();
230 return new (zone) CallDescriptor( // --
231 CallDescriptor::kCallAddress, // kind
232 target_type, // target MachineType
233 target_loc, // target location
234 msig, // machine_sig
235 locations.Build(), // location_sig
236 0, // js_parameter_count
237 Operator::kNoProperties, // properties
238 kCalleeSaveRegisters, // callee-saved registers
239 kCalleeSaveFPRegisters, // callee-saved fp regs
240 CallDescriptor::kNoFlags, // flags
241 "c-call");
242 }
243 }
244 }
245 }
OLDNEW
« no previous file with comments | « src/compiler/arm64/linkage-arm64.cc ('k') | src/compiler/ia32/linkage-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698