OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef V8_COMPILER_LINKAGE_IMPL_H_ | 5 #ifndef V8_COMPILER_LINKAGE_IMPL_H_ |
6 #define V8_COMPILER_LINKAGE_IMPL_H_ | 6 #define V8_COMPILER_LINKAGE_IMPL_H_ |
7 | 7 |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 10 matching lines...) Expand all Loading... |
21 DCHECK(locations->return_count_ <= 2); | 21 DCHECK(locations->return_count_ <= 2); |
22 if (locations->return_count_ > 0) { | 22 if (locations->return_count_ > 0) { |
23 locations->AddReturn(regloc(LinkageTraits::ReturnValueReg())); | 23 locations->AddReturn(regloc(LinkageTraits::ReturnValueReg())); |
24 } | 24 } |
25 if (locations->return_count_ > 1) { | 25 if (locations->return_count_ > 1) { |
26 locations->AddReturn(regloc(LinkageTraits::ReturnValue2Reg())); | 26 locations->AddReturn(regloc(LinkageTraits::ReturnValue2Reg())); |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
30 // TODO(turbofan): cache call descriptors for JSFunction calls. | 30 // TODO(turbofan): cache call descriptors for JSFunction calls. |
31 static CallDescriptor* GetJSCallDescriptor(Zone* zone, int js_parameter_count, | 31 static CallDescriptor* GetJSCallDescriptor(Zone* zone, |
32 CallDescriptor::Flags flags) { | 32 int js_parameter_count) { |
33 const size_t return_count = 1; | 33 const size_t return_count = 1; |
34 const size_t context_count = 1; | 34 const size_t context_count = 1; |
35 const size_t parameter_count = js_parameter_count + context_count; | 35 const size_t parameter_count = js_parameter_count + context_count; |
36 | 36 |
37 LocationSignature::Builder locations(zone, return_count, parameter_count); | 37 LocationSignature::Builder locations(zone, return_count, parameter_count); |
38 MachineSignature::Builder types(zone, return_count, parameter_count); | 38 MachineSignature::Builder types(zone, return_count, parameter_count); |
39 | 39 |
40 // Add returns. | 40 // Add returns. |
41 AddReturnLocations(&locations); | 41 AddReturnLocations(&locations); |
42 for (size_t i = 0; i < return_count; i++) { | 42 for (size_t i = 0; i < return_count; i++) { |
43 types.AddReturn(kMachAnyTagged); | 43 types.AddReturn(kMachAnyTagged); |
44 } | 44 } |
45 | 45 |
46 // All parameters to JS calls go on the stack. | 46 // All parameters to JS calls go on the stack. |
47 for (int i = 0; i < js_parameter_count; i++) { | 47 for (int i = 0; i < js_parameter_count; i++) { |
48 int spill_slot_index = i - js_parameter_count; | 48 int spill_slot_index = i - js_parameter_count; |
49 locations.AddParam(stackloc(spill_slot_index)); | 49 locations.AddParam(stackloc(spill_slot_index)); |
50 types.AddParam(kMachAnyTagged); | 50 types.AddParam(kMachAnyTagged); |
51 } | 51 } |
52 // Add context. | 52 // Add context. |
53 locations.AddParam(regloc(LinkageTraits::ContextReg())); | 53 locations.AddParam(regloc(LinkageTraits::ContextReg())); |
54 types.AddParam(kMachAnyTagged); | 54 types.AddParam(kMachAnyTagged); |
55 | 55 |
56 // The target for JS function calls is the JSFunction object. | 56 // The target for JS function calls is the JSFunction object. |
57 MachineType target_type = kMachAnyTagged; | 57 MachineType target_type = kMachAnyTagged; |
58 LinkageLocation target_loc = regloc(LinkageTraits::JSCallFunctionReg()); | 58 LinkageLocation target_loc = regloc(LinkageTraits::JSCallFunctionReg()); |
59 return new (zone) CallDescriptor( // -- | 59 return new (zone) CallDescriptor(CallDescriptor::kCallJSFunction, // kind |
60 CallDescriptor::kCallJSFunction, // kind | 60 target_type, // target MachineType |
61 target_type, // target MachineType | 61 target_loc, // target location |
62 target_loc, // target location | 62 types.Build(), // machine_sig |
63 types.Build(), // machine_sig | 63 locations.Build(), // location_sig |
64 locations.Build(), // location_sig | 64 js_parameter_count, // js_parameter_count |
65 js_parameter_count, // js_parameter_count | 65 Operator::kNoProperties, // properties |
66 Operator::kNoProperties, // properties | 66 kNoCalleeSaved, // callee-saved |
67 kNoCalleeSaved, // callee-saved | 67 CallDescriptor::kNeedsFrameState, // flags |
68 flags, // flags | 68 "js-call"); |
69 "js-call"); | |
70 } | 69 } |
71 | 70 |
72 | 71 |
73 // TODO(turbofan): cache call descriptors for runtime calls. | 72 // TODO(turbofan): cache call descriptors for runtime calls. |
74 static CallDescriptor* GetRuntimeCallDescriptor( | 73 static CallDescriptor* GetRuntimeCallDescriptor( |
75 Zone* zone, Runtime::FunctionId function_id, int js_parameter_count, | 74 Zone* zone, Runtime::FunctionId function_id, int js_parameter_count, |
76 Operator::Properties properties) { | 75 Operator::Properties properties) { |
77 const size_t function_count = 1; | 76 const size_t function_count = 1; |
78 const size_t num_args_count = 1; | 77 const size_t num_args_count = 1; |
79 const size_t context_count = 1; | 78 const size_t context_count = 1; |
(...skipping 30 matching lines...) Expand all Loading... |
110 locations.AddParam(regloc(LinkageTraits::ContextReg())); | 109 locations.AddParam(regloc(LinkageTraits::ContextReg())); |
111 types.AddParam(kMachAnyTagged); | 110 types.AddParam(kMachAnyTagged); |
112 | 111 |
113 CallDescriptor::Flags flags = Linkage::NeedsFrameState(function_id) | 112 CallDescriptor::Flags flags = Linkage::NeedsFrameState(function_id) |
114 ? CallDescriptor::kNeedsFrameState | 113 ? CallDescriptor::kNeedsFrameState |
115 : CallDescriptor::kNoFlags; | 114 : CallDescriptor::kNoFlags; |
116 | 115 |
117 // The target for runtime calls is a code object. | 116 // The target for runtime calls is a code object. |
118 MachineType target_type = kMachAnyTagged; | 117 MachineType target_type = kMachAnyTagged; |
119 LinkageLocation target_loc = LinkageLocation::AnyRegister(); | 118 LinkageLocation target_loc = LinkageLocation::AnyRegister(); |
120 return new (zone) CallDescriptor( // -- | 119 return new (zone) CallDescriptor(CallDescriptor::kCallCodeObject, // kind |
121 CallDescriptor::kCallCodeObject, // kind | 120 target_type, // target MachineType |
122 target_type, // target MachineType | 121 target_loc, // target location |
123 target_loc, // target location | 122 types.Build(), // machine_sig |
124 types.Build(), // machine_sig | 123 locations.Build(), // location_sig |
125 locations.Build(), // location_sig | 124 js_parameter_count, // js_parameter_count |
126 js_parameter_count, // js_parameter_count | 125 properties, // properties |
127 properties, // properties | 126 kNoCalleeSaved, // callee-saved |
128 kNoCalleeSaved, // callee-saved | 127 flags, // flags |
129 flags, // flags | 128 function->name); // debug name |
130 function->name); // debug name | |
131 } | 129 } |
132 | 130 |
133 | 131 |
134 // TODO(turbofan): cache call descriptors for code stub calls. | 132 // TODO(turbofan): cache call descriptors for code stub calls. |
135 static CallDescriptor* GetStubCallDescriptor( | 133 static CallDescriptor* GetStubCallDescriptor( |
136 Zone* zone, const CallInterfaceDescriptor& descriptor, | 134 Zone* zone, const CallInterfaceDescriptor& descriptor, |
137 int stack_parameter_count, CallDescriptor::Flags flags) { | 135 int stack_parameter_count, CallDescriptor::Flags flags) { |
138 const int register_parameter_count = | 136 const int register_parameter_count = |
139 descriptor.GetEnvironmentParameterCount(); | 137 descriptor.GetEnvironmentParameterCount(); |
140 const int js_parameter_count = | 138 const int js_parameter_count = |
(...skipping 23 matching lines...) Expand all Loading... |
164 } | 162 } |
165 types.AddParam(kMachAnyTagged); | 163 types.AddParam(kMachAnyTagged); |
166 } | 164 } |
167 // Add context. | 165 // Add context. |
168 locations.AddParam(regloc(LinkageTraits::ContextReg())); | 166 locations.AddParam(regloc(LinkageTraits::ContextReg())); |
169 types.AddParam(kMachAnyTagged); | 167 types.AddParam(kMachAnyTagged); |
170 | 168 |
171 // The target for stub calls is a code object. | 169 // The target for stub calls is a code object. |
172 MachineType target_type = kMachAnyTagged; | 170 MachineType target_type = kMachAnyTagged; |
173 LinkageLocation target_loc = LinkageLocation::AnyRegister(); | 171 LinkageLocation target_loc = LinkageLocation::AnyRegister(); |
174 return new (zone) CallDescriptor( // -- | 172 return new (zone) CallDescriptor(CallDescriptor::kCallCodeObject, // kind |
175 CallDescriptor::kCallCodeObject, // kind | 173 target_type, // target MachineType |
176 target_type, // target MachineType | 174 target_loc, // target location |
177 target_loc, // target location | 175 types.Build(), // machine_sig |
178 types.Build(), // machine_sig | 176 locations.Build(), // location_sig |
179 locations.Build(), // location_sig | 177 js_parameter_count, // js_parameter_count |
180 js_parameter_count, // js_parameter_count | 178 Operator::kNoProperties, // properties |
181 Operator::kNoProperties, // properties | 179 kNoCalleeSaved, // callee-saved registers |
182 kNoCalleeSaved, // callee-saved registers | 180 flags, // flags |
183 flags, // flags | 181 descriptor.DebugName(zone->isolate())); |
184 descriptor.DebugName(zone->isolate())); | |
185 } | 182 } |
186 | 183 |
187 static CallDescriptor* GetSimplifiedCDescriptor(Zone* zone, | 184 static CallDescriptor* GetSimplifiedCDescriptor(Zone* zone, |
188 MachineSignature* msig) { | 185 MachineSignature* msig) { |
189 LocationSignature::Builder locations(zone, msig->return_count(), | 186 LocationSignature::Builder locations(zone, msig->return_count(), |
190 msig->parameter_count()); | 187 msig->parameter_count()); |
191 // Add return location(s). | 188 // Add return location(s). |
192 AddReturnLocations(&locations); | 189 AddReturnLocations(&locations); |
193 | 190 |
194 // Add register and/or stack parameter(s). | 191 // Add register and/or stack parameter(s). |
195 const int parameter_count = static_cast<int>(msig->parameter_count()); | 192 const int parameter_count = static_cast<int>(msig->parameter_count()); |
196 for (int i = 0; i < parameter_count; i++) { | 193 for (int i = 0; i < parameter_count; i++) { |
197 if (i < LinkageTraits::CRegisterParametersLength()) { | 194 if (i < LinkageTraits::CRegisterParametersLength()) { |
198 locations.AddParam(regloc(LinkageTraits::CRegisterParameter(i))); | 195 locations.AddParam(regloc(LinkageTraits::CRegisterParameter(i))); |
199 } else { | 196 } else { |
200 locations.AddParam(stackloc(-1 - i)); | 197 locations.AddParam(stackloc(-1 - i)); |
201 } | 198 } |
202 } | 199 } |
203 | 200 |
204 // The target for C calls is always an address (i.e. machine pointer). | 201 // The target for C calls is always an address (i.e. machine pointer). |
205 MachineType target_type = kMachPtr; | 202 MachineType target_type = kMachPtr; |
206 LinkageLocation target_loc = LinkageLocation::AnyRegister(); | 203 LinkageLocation target_loc = LinkageLocation::AnyRegister(); |
207 return new (zone) CallDescriptor( // -- | 204 return new (zone) CallDescriptor(CallDescriptor::kCallAddress, // kind |
208 CallDescriptor::kCallAddress, // kind | 205 target_type, // target MachineType |
209 target_type, // target MachineType | 206 target_loc, // target location |
210 target_loc, // target location | 207 msig, // machine_sig |
211 msig, // machine_sig | 208 locations.Build(), // location_sig |
212 locations.Build(), // location_sig | 209 0, // js_parameter_count |
213 0, // js_parameter_count | 210 Operator::kNoProperties, // properties |
214 Operator::kNoProperties, // properties | 211 LinkageTraits::CCalleeSaveRegisters(), |
215 LinkageTraits::CCalleeSaveRegisters(), CallDescriptor::kNoFlags, | 212 CallDescriptor::kNoFlags, "c-call"); |
216 "c-call"); | |
217 } | 213 } |
218 | 214 |
219 static LinkageLocation regloc(Register reg) { | 215 static LinkageLocation regloc(Register reg) { |
220 return LinkageLocation(Register::ToAllocationIndex(reg)); | 216 return LinkageLocation(Register::ToAllocationIndex(reg)); |
221 } | 217 } |
222 | 218 |
223 static LinkageLocation stackloc(int i) { | 219 static LinkageLocation stackloc(int i) { |
224 DCHECK_LT(i, 0); | 220 DCHECK_LT(i, 0); |
225 return LinkageLocation(i); | 221 return LinkageLocation(i); |
226 } | 222 } |
227 }; | 223 }; |
228 } // namespace compiler | 224 } // namespace compiler |
229 } // namespace internal | 225 } // namespace internal |
230 } // namespace v8 | 226 } // namespace v8 |
231 | 227 |
232 #endif // V8_COMPILER_LINKAGE_IMPL_H_ | 228 #endif // V8_COMPILER_LINKAGE_IMPL_H_ |
OLD | NEW |