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/compiler/code-assembler.h" | 5 #include "src/compiler/code-assembler.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 414 } |
415 | 415 |
416 Node* CodeAssembler::TailCallN(CallDescriptor* descriptor, Node* code_target, | 416 Node* CodeAssembler::TailCallN(CallDescriptor* descriptor, Node* code_target, |
417 Node** args) { | 417 Node** args) { |
418 return raw_assembler()->TailCallN(descriptor, code_target, args); | 418 return raw_assembler()->TailCallN(descriptor, code_target, args); |
419 } | 419 } |
420 | 420 |
421 template <class... TArgs> | 421 template <class... TArgs> |
422 Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context, | 422 Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context, |
423 TArgs... args) { | 423 TArgs... args) { |
424 CallPrologue(); | |
425 | |
426 int argc = static_cast<int>(sizeof...(args)); | 424 int argc = static_cast<int>(sizeof...(args)); |
427 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | 425 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
428 zone(), function, argc, Operator::kNoProperties, | 426 zone(), function, argc, Operator::kNoProperties, |
429 CallDescriptor::kNoFlags); | 427 CallDescriptor::kNoFlags); |
430 int return_count = static_cast<int>(desc->ReturnCount()); | 428 int return_count = static_cast<int>(desc->ReturnCount()); |
431 | 429 |
432 Node* centry = | 430 Node* centry = |
433 HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count)); | 431 HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count)); |
434 Node* ref = ExternalConstant(ExternalReference(function, isolate())); | 432 Node* ref = ExternalConstant(ExternalReference(function, isolate())); |
435 Node* arity = Int32Constant(argc); | 433 Node* arity = Int32Constant(argc); |
436 | 434 |
437 Node* nodes[] = {centry, args..., ref, arity, context}; | 435 Node* nodes[] = {centry, args..., ref, arity, context}; |
438 | 436 |
| 437 CallPrologue(); |
439 Node* return_value = raw_assembler()->CallN(desc, arraysize(nodes), nodes); | 438 Node* return_value = raw_assembler()->CallN(desc, arraysize(nodes), nodes); |
440 | |
441 CallEpilogue(); | 439 CallEpilogue(); |
442 return return_value; | 440 return return_value; |
443 } | 441 } |
444 | 442 |
445 // Instantiate CallRuntime() with up to 5 arguments. | 443 // Instantiate CallRuntime() with up to 5 arguments. |
446 #define INSTANTIATE(...) \ | 444 #define INSTANTIATE(...) \ |
447 template V8_EXPORT_PRIVATE Node* CodeAssembler::CallRuntime( \ | 445 template V8_EXPORT_PRIVATE Node* CodeAssembler::CallRuntime( \ |
448 Runtime::FunctionId, __VA_ARGS__); | 446 Runtime::FunctionId, __VA_ARGS__); |
449 REPEAT_1_TO_6(INSTANTIATE, Node*) | 447 REPEAT_1_TO_6(INSTANTIATE, Node*) |
450 #undef INSTANTIATE | 448 #undef INSTANTIATE |
451 | 449 |
452 template <class... TArgs> | 450 template <class... TArgs> |
453 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function, | 451 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function, |
454 Node* context, TArgs... args) { | 452 Node* context, TArgs... args) { |
455 CallPrologue(); | |
456 | |
457 int argc = static_cast<int>(sizeof...(args)); | 453 int argc = static_cast<int>(sizeof...(args)); |
458 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | 454 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
459 zone(), function, argc, Operator::kNoProperties, | 455 zone(), function, argc, Operator::kNoProperties, |
460 CallDescriptor::kSupportsTailCalls); | 456 CallDescriptor::kSupportsTailCalls); |
461 int return_count = static_cast<int>(desc->ReturnCount()); | 457 int return_count = static_cast<int>(desc->ReturnCount()); |
462 | 458 |
463 Node* centry = | 459 Node* centry = |
464 HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count)); | 460 HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count)); |
465 Node* ref = ExternalConstant(ExternalReference(function, isolate())); | 461 Node* ref = ExternalConstant(ExternalReference(function, isolate())); |
466 Node* arity = Int32Constant(argc); | 462 Node* arity = Int32Constant(argc); |
467 | 463 |
468 Node* nodes[] = {centry, args..., ref, arity, context}; | 464 Node* nodes[] = {centry, args..., ref, arity, context}; |
469 | 465 |
| 466 CallPrologue(); |
470 Node* return_value = | 467 Node* return_value = |
471 raw_assembler()->TailCallN(desc, arraysize(nodes), nodes); | 468 raw_assembler()->TailCallN(desc, arraysize(nodes), nodes); |
472 | |
473 CallEpilogue(); | 469 CallEpilogue(); |
474 return return_value; | 470 return return_value; |
475 } | 471 } |
476 | 472 |
477 // Instantiate TailCallRuntime() with up to 6 arguments. | 473 // Instantiate TailCallRuntime() with up to 6 arguments. |
478 #define INSTANTIATE(...) \ | 474 #define INSTANTIATE(...) \ |
479 template V8_EXPORT_PRIVATE Node* CodeAssembler::TailCallRuntime( \ | 475 template V8_EXPORT_PRIVATE Node* CodeAssembler::TailCallRuntime( \ |
480 Runtime::FunctionId, __VA_ARGS__); | 476 Runtime::FunctionId, __VA_ARGS__); |
481 REPEAT_1_TO_7(INSTANTIATE, Node*) | 477 REPEAT_1_TO_7(INSTANTIATE, Node*) |
482 #undef INSTANTIATE | 478 #undef INSTANTIATE |
483 | 479 |
484 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, | 480 template <class... TArgs> |
485 Node* arg1, size_t result_size) { | 481 Node* CodeAssembler::CallStubR(const CallInterfaceDescriptor& descriptor, |
486 Node* target = HeapConstant(callable.code()); | 482 size_t result_size, Node* target, Node* context, |
487 return CallStub(callable.descriptor(), target, context, arg1, result_size); | 483 TArgs... args) { |
| 484 Node* nodes[] = {target, args..., context}; |
| 485 return CallStubN(descriptor, result_size, arraysize(nodes), nodes); |
488 } | 486 } |
489 | 487 |
490 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, | 488 // Instantiate CallStubR() with up to 5 arguments. |
491 Node* arg1, Node* arg2, size_t result_size) { | 489 #define INSTANTIATE(...) \ |
492 Node* target = HeapConstant(callable.code()); | 490 template V8_EXPORT_PRIVATE Node* CodeAssembler::CallStubR( \ |
493 return CallStub(callable.descriptor(), target, context, arg1, arg2, | 491 const CallInterfaceDescriptor& descriptor, size_t, Node*, __VA_ARGS__); |
494 result_size); | 492 REPEAT_1_TO_6(INSTANTIATE, Node*) |
495 } | 493 #undef INSTANTIATE |
496 | 494 |
497 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, | 495 Node* CodeAssembler::CallStubN(const CallInterfaceDescriptor& descriptor, |
498 Node* arg1, Node* arg2, Node* arg3, | 496 size_t result_size, int input_count, |
499 size_t result_size) { | 497 Node* const* inputs) { |
500 Node* target = HeapConstant(callable.code()); | 498 // 2 is for target and context. |
501 return CallStub(callable.descriptor(), target, context, arg1, arg2, arg3, | 499 DCHECK_LE(2, input_count); |
502 result_size); | 500 int argc = input_count - 2; |
503 } | 501 DCHECK_LE(descriptor.GetParameterCount(), argc); |
504 | 502 // Extra arguments not mentioned in the descriptor are passed on the stack. |
505 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, | 503 int stack_parameter_count = argc - descriptor.GetRegisterParameterCount(); |
506 Node* arg1, Node* arg2, Node* arg3, Node* arg4, | 504 DCHECK_LE(descriptor.GetStackParameterCount(), stack_parameter_count); |
507 size_t result_size) { | 505 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
508 Node* target = HeapConstant(callable.code()); | 506 isolate(), zone(), descriptor, stack_parameter_count, |
509 return CallStub(callable.descriptor(), target, context, arg1, arg2, arg3, | |
510 arg4, result_size); | |
511 } | |
512 | |
513 Node* CodeAssembler::CallStubN(Callable const& callable, Node** args, | |
514 size_t result_size) { | |
515 Node* target = HeapConstant(callable.code()); | |
516 return CallStubN(callable.descriptor(), target, args, result_size); | |
517 } | |
518 | |
519 Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, | |
520 Node* target, Node* context, size_t result_size) { | |
521 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( | |
522 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), | |
523 CallDescriptor::kNoFlags, Operator::kNoProperties, | 507 CallDescriptor::kNoFlags, Operator::kNoProperties, |
524 MachineType::AnyTagged(), result_size); | 508 MachineType::AnyTagged(), result_size); |
525 | 509 |
526 Node** args = zone()->NewArray<Node*>(1); | 510 CallPrologue(); |
527 args[0] = context; | 511 Node* return_value = raw_assembler()->CallN(desc, input_count, inputs); |
528 | 512 CallEpilogue(); |
529 return CallN(call_descriptor, target, args); | 513 return return_value; |
530 } | 514 } |
531 | 515 |
532 Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, | |
533 Node* target, Node* context, Node* arg1, | |
534 size_t result_size) { | |
535 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( | |
536 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), | |
537 CallDescriptor::kNoFlags, Operator::kNoProperties, | |
538 MachineType::AnyTagged(), result_size); | |
539 | |
540 Node** args = zone()->NewArray<Node*>(2); | |
541 args[0] = arg1; | |
542 args[1] = context; | |
543 | |
544 return CallN(call_descriptor, target, args); | |
545 } | |
546 | |
547 Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, | |
548 Node* target, Node* context, Node* arg1, | |
549 Node* arg2, size_t result_size) { | |
550 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( | |
551 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), | |
552 CallDescriptor::kNoFlags, Operator::kNoProperties, | |
553 MachineType::AnyTagged(), result_size); | |
554 | |
555 Node** args = zone()->NewArray<Node*>(3); | |
556 args[0] = arg1; | |
557 args[1] = arg2; | |
558 args[2] = context; | |
559 | |
560 return CallN(call_descriptor, target, args); | |
561 } | |
562 | |
563 Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, | |
564 Node* target, Node* context, Node* arg1, | |
565 Node* arg2, Node* arg3, size_t result_size) { | |
566 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( | |
567 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), | |
568 CallDescriptor::kNoFlags, Operator::kNoProperties, | |
569 MachineType::AnyTagged(), result_size); | |
570 | |
571 Node** args = zone()->NewArray<Node*>(4); | |
572 args[0] = arg1; | |
573 args[1] = arg2; | |
574 args[2] = arg3; | |
575 args[3] = context; | |
576 | |
577 return CallN(call_descriptor, target, args); | |
578 } | |
579 | |
580 Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, | |
581 Node* target, Node* context, Node* arg1, | |
582 Node* arg2, Node* arg3, Node* arg4, | |
583 size_t result_size) { | |
584 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( | |
585 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), | |
586 CallDescriptor::kNoFlags, Operator::kNoProperties, | |
587 MachineType::AnyTagged(), result_size); | |
588 | |
589 Node** args = zone()->NewArray<Node*>(5); | |
590 args[0] = arg1; | |
591 args[1] = arg2; | |
592 args[2] = arg3; | |
593 args[3] = arg4; | |
594 args[4] = context; | |
595 | |
596 return CallN(call_descriptor, target, args); | |
597 } | |
598 | |
599 Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, | |
600 Node* target, Node* context, Node* arg1, | |
601 Node* arg2, Node* arg3, Node* arg4, Node* arg5, | |
602 size_t result_size) { | |
603 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( | |
604 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), | |
605 CallDescriptor::kNoFlags, Operator::kNoProperties, | |
606 MachineType::AnyTagged(), result_size); | |
607 | |
608 Node** args = zone()->NewArray<Node*>(6); | |
609 args[0] = arg1; | |
610 args[1] = arg2; | |
611 args[2] = arg3; | |
612 args[3] = arg4; | |
613 args[4] = arg5; | |
614 args[5] = context; | |
615 | |
616 return CallN(call_descriptor, target, args); | |
617 } | |
618 | 516 |
619 Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, | 517 Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, |
620 Node* target, Node* context, const Arg& arg1, | 518 Node* target, Node* context, const Arg& arg1, |
621 const Arg& arg2, size_t result_size) { | 519 const Arg& arg2, size_t result_size) { |
622 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( | 520 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( |
623 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), | 521 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), |
624 CallDescriptor::kNoFlags, Operator::kNoProperties, | 522 CallDescriptor::kNoFlags, Operator::kNoProperties, |
625 MachineType::AnyTagged(), result_size); | 523 MachineType::AnyTagged(), result_size); |
626 | 524 |
627 const int kArgsCount = 3; | 525 const int kArgsCount = 3; |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 } | 1084 } |
1187 } | 1085 } |
1188 } | 1086 } |
1189 | 1087 |
1190 bound_ = true; | 1088 bound_ = true; |
1191 } | 1089 } |
1192 | 1090 |
1193 } // namespace compiler | 1091 } // namespace compiler |
1194 } // namespace internal | 1092 } // namespace internal |
1195 } // namespace v8 | 1093 } // namespace v8 |
OLD | NEW |