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 #include "src/compiler/raw-machine-assembler.h" | 5 #include "src/compiler/raw-machine-assembler.h" |
6 | 6 |
7 #include "src/code-factory.h" | |
8 #include "src/compiler/node-properties.h" | 7 #include "src/compiler/node-properties.h" |
9 #include "src/compiler/pipeline.h" | 8 #include "src/compiler/pipeline.h" |
10 #include "src/compiler/scheduler.h" | 9 #include "src/compiler/scheduler.h" |
| 10 #include "src/objects-inl.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 namespace compiler { | 14 namespace compiler { |
15 | 15 |
16 RawMachineAssembler::RawMachineAssembler( | 16 RawMachineAssembler::RawMachineAssembler( |
17 Isolate* isolate, Graph* graph, CallDescriptor* call_descriptor, | 17 Isolate* isolate, Graph* graph, CallDescriptor* call_descriptor, |
18 MachineRepresentation word, MachineOperatorBuilder::Flags flags, | 18 MachineRepresentation word, MachineOperatorBuilder::Flags flags, |
19 MachineOperatorBuilder::AlignmentRequirements alignment_requirements) | 19 MachineOperatorBuilder::AlignmentRequirements alignment_requirements) |
20 : isolate_(isolate), | 20 : isolate_(isolate), |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 int input_count = param_count + 1; | 176 int input_count = param_count + 1; |
177 Node** buffer = zone()->NewArray<Node*>(input_count); | 177 Node** buffer = zone()->NewArray<Node*>(input_count); |
178 int index = 0; | 178 int index = 0; |
179 buffer[index++] = function; | 179 buffer[index++] = function; |
180 for (int i = 0; i < param_count; i++) { | 180 for (int i = 0; i < param_count; i++) { |
181 buffer[index++] = args[i]; | 181 buffer[index++] = args[i]; |
182 } | 182 } |
183 return AddNode(common()->Call(desc), input_count, buffer); | 183 return AddNode(common()->Call(desc), input_count, buffer); |
184 } | 184 } |
185 | 185 |
| 186 Node* RawMachineAssembler::CallN(CallDescriptor* desc, int input_count, |
| 187 Node* const* nodes) { |
| 188 // +1 is for target. |
| 189 DCHECK_EQ(input_count, desc->ParameterCount() + 1); |
| 190 return AddNode(common()->Call(desc), input_count, nodes); |
| 191 } |
186 | 192 |
187 Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc, | 193 Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc, |
188 Node* function, Node** args, | 194 Node* function, Node** args, |
189 Node* frame_state) { | 195 Node* frame_state) { |
190 DCHECK(desc->NeedsFrameState()); | 196 DCHECK(desc->NeedsFrameState()); |
191 int param_count = static_cast<int>(desc->ParameterCount()); | 197 int param_count = static_cast<int>(desc->ParameterCount()); |
192 int input_count = param_count + 2; | 198 int input_count = param_count + 2; |
193 Node** buffer = zone()->NewArray<Node*>(input_count); | 199 Node** buffer = zone()->NewArray<Node*>(input_count); |
194 int index = 0; | 200 int index = 0; |
195 buffer[index++] = function; | 201 buffer[index++] = function; |
196 for (int i = 0; i < param_count; i++) { | 202 for (int i = 0; i < param_count; i++) { |
197 buffer[index++] = args[i]; | 203 buffer[index++] = args[i]; |
198 } | 204 } |
199 buffer[index++] = frame_state; | 205 buffer[index++] = frame_state; |
200 return AddNode(common()->Call(desc), input_count, buffer); | 206 return AddNode(common()->Call(desc), input_count, buffer); |
201 } | 207 } |
202 | 208 |
203 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function, | 209 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function, |
204 Node** args) { | 210 Node** args) { |
205 int param_count = static_cast<int>(desc->ParameterCount()); | 211 int param_count = static_cast<int>(desc->ParameterCount()); |
206 int input_count = param_count + 1; | 212 int input_count = param_count + 1; |
207 Node** buffer = zone()->NewArray<Node*>(input_count); | 213 Node** buffer = zone()->NewArray<Node*>(input_count); |
208 int index = 0; | 214 int index = 0; |
209 buffer[index++] = function; | 215 buffer[index++] = function; |
210 for (int i = 0; i < param_count; i++) { | 216 for (int i = 0; i < param_count; i++) { |
211 buffer[index++] = args[i]; | 217 buffer[index++] = args[i]; |
212 } | 218 } |
213 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer); | 219 return TailCallN(desc, input_count, buffer); |
| 220 } |
| 221 |
| 222 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, int input_count, |
| 223 Node* const* inputs) { |
| 224 // +1 is for target. |
| 225 DCHECK_EQ(input_count, desc->ParameterCount() + 1); |
| 226 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, inputs); |
214 schedule()->AddTailCall(CurrentBlock(), tail_call); | 227 schedule()->AddTailCall(CurrentBlock(), tail_call); |
215 current_block_ = nullptr; | 228 current_block_ = nullptr; |
216 return tail_call; | 229 return tail_call; |
217 } | |
218 | |
219 Node* RawMachineAssembler::TailCallRuntime0(Runtime::FunctionId function, | |
220 Node* context) { | |
221 const int kArity = 0; | |
222 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
223 zone(), function, kArity, Operator::kNoProperties, | |
224 CallDescriptor::kSupportsTailCalls); | |
225 int return_count = static_cast<int>(desc->ReturnCount()); | |
226 | |
227 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
228 Node* ref = AddNode( | |
229 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
230 Node* arity = Int32Constant(kArity); | |
231 | |
232 Node* nodes[] = {centry, ref, arity, context}; | |
233 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
234 | |
235 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
236 current_block_ = nullptr; | |
237 return tail_call; | |
238 } | |
239 | |
240 Node* RawMachineAssembler::TailCallRuntime1(Runtime::FunctionId function, | |
241 Node* arg1, Node* context) { | |
242 const int kArity = 1; | |
243 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
244 zone(), function, kArity, Operator::kNoProperties, | |
245 CallDescriptor::kSupportsTailCalls); | |
246 int return_count = static_cast<int>(desc->ReturnCount()); | |
247 | |
248 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
249 Node* ref = AddNode( | |
250 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
251 Node* arity = Int32Constant(kArity); | |
252 | |
253 Node* nodes[] = {centry, arg1, ref, arity, context}; | |
254 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
255 | |
256 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
257 current_block_ = nullptr; | |
258 return tail_call; | |
259 } | |
260 | |
261 | |
262 Node* RawMachineAssembler::TailCallRuntime2(Runtime::FunctionId function, | |
263 Node* arg1, Node* arg2, | |
264 Node* context) { | |
265 const int kArity = 2; | |
266 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
267 zone(), function, kArity, Operator::kNoProperties, | |
268 CallDescriptor::kSupportsTailCalls); | |
269 int return_count = static_cast<int>(desc->ReturnCount()); | |
270 | |
271 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
272 Node* ref = AddNode( | |
273 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
274 Node* arity = Int32Constant(kArity); | |
275 | |
276 Node* nodes[] = {centry, arg1, arg2, ref, arity, context}; | |
277 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
278 | |
279 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
280 current_block_ = nullptr; | |
281 return tail_call; | |
282 } | |
283 | |
284 Node* RawMachineAssembler::TailCallRuntime3(Runtime::FunctionId function, | |
285 Node* arg1, Node* arg2, Node* arg3, | |
286 Node* context) { | |
287 const int kArity = 3; | |
288 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
289 zone(), function, kArity, Operator::kNoProperties, | |
290 CallDescriptor::kSupportsTailCalls); | |
291 int return_count = static_cast<int>(desc->ReturnCount()); | |
292 | |
293 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
294 Node* ref = AddNode( | |
295 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
296 Node* arity = Int32Constant(kArity); | |
297 | |
298 Node* nodes[] = {centry, arg1, arg2, arg3, ref, arity, context}; | |
299 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
300 | |
301 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
302 current_block_ = nullptr; | |
303 return tail_call; | |
304 } | |
305 | |
306 Node* RawMachineAssembler::TailCallRuntime4(Runtime::FunctionId function, | |
307 Node* arg1, Node* arg2, Node* arg3, | |
308 Node* arg4, Node* context) { | |
309 const int kArity = 4; | |
310 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
311 zone(), function, kArity, Operator::kNoProperties, | |
312 CallDescriptor::kSupportsTailCalls); | |
313 int return_count = static_cast<int>(desc->ReturnCount()); | |
314 | |
315 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
316 Node* ref = AddNode( | |
317 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
318 Node* arity = Int32Constant(kArity); | |
319 | |
320 Node* nodes[] = {centry, arg1, arg2, arg3, arg4, ref, arity, context}; | |
321 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
322 | |
323 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
324 current_block_ = nullptr; | |
325 return tail_call; | |
326 } | |
327 | |
328 Node* RawMachineAssembler::TailCallRuntime5(Runtime::FunctionId function, | |
329 Node* arg1, Node* arg2, Node* arg3, | |
330 Node* arg4, Node* arg5, | |
331 Node* context) { | |
332 const int kArity = 5; | |
333 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
334 zone(), function, kArity, Operator::kNoProperties, | |
335 CallDescriptor::kSupportsTailCalls); | |
336 int return_count = static_cast<int>(desc->ReturnCount()); | |
337 | |
338 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
339 Node* ref = AddNode( | |
340 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
341 Node* arity = Int32Constant(kArity); | |
342 | |
343 Node* nodes[] = {centry, arg1, arg2, arg3, arg4, arg5, ref, arity, context}; | |
344 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
345 | |
346 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
347 current_block_ = nullptr; | |
348 return tail_call; | |
349 } | |
350 | |
351 Node* RawMachineAssembler::TailCallRuntime6(Runtime::FunctionId function, | |
352 Node* arg1, Node* arg2, Node* arg3, | |
353 Node* arg4, Node* arg5, Node* arg6, | |
354 Node* context) { | |
355 const int kArity = 6; | |
356 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
357 zone(), function, kArity, Operator::kNoProperties, | |
358 CallDescriptor::kSupportsTailCalls); | |
359 int return_count = static_cast<int>(desc->ReturnCount()); | |
360 | |
361 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
362 Node* ref = AddNode( | |
363 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
364 Node* arity = Int32Constant(kArity); | |
365 | |
366 Node* nodes[] = {centry, arg1, arg2, arg3, arg4, | |
367 arg5, arg6, ref, arity, context}; | |
368 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
369 | |
370 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
371 current_block_ = nullptr; | |
372 return tail_call; | |
373 } | 230 } |
374 | 231 |
375 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, | 232 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, |
376 Node* function) { | 233 Node* function) { |
377 MachineSignature::Builder builder(zone(), 1, 0); | 234 MachineSignature::Builder builder(zone(), 1, 0); |
378 builder.AddReturn(return_type); | 235 builder.AddReturn(return_type); |
379 const CallDescriptor* descriptor = | 236 const CallDescriptor* descriptor = |
380 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); | 237 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); |
381 | 238 |
382 return AddNode(common()->Call(descriptor), function); | 239 return AddNode(common()->Call(descriptor), function); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 // The raw machine assembler nodes do not have effect and control inputs, | 347 // The raw machine assembler nodes do not have effect and control inputs, |
491 // so we disable checking input counts here. | 348 // so we disable checking input counts here. |
492 return graph()->NewNodeUnchecked(op, input_count, inputs); | 349 return graph()->NewNodeUnchecked(op, input_count, inputs); |
493 } | 350 } |
494 | 351 |
495 RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); } | 352 RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); } |
496 | 353 |
497 } // namespace compiler | 354 } // namespace compiler |
498 } // namespace internal | 355 } // namespace internal |
499 } // namespace v8 | 356 } // namespace v8 |
OLD | NEW |