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" |
11 #include "src/compiler/instruction-selector.h" | 11 #include "src/compiler/instruction-selector.h" |
12 #include "src/compiler/linkage.h" | 12 #include "src/compiler/linkage.h" |
13 #include "src/compiler/node-matchers.h" | 13 #include "src/compiler/node-matchers.h" |
14 #include "src/compiler/pipeline.h" | 14 #include "src/compiler/pipeline.h" |
15 #include "src/compiler/raw-machine-assembler.h" | 15 #include "src/compiler/raw-machine-assembler.h" |
16 #include "src/compiler/schedule.h" | 16 #include "src/compiler/schedule.h" |
17 #include "src/frames.h" | 17 #include "src/frames.h" |
18 #include "src/interface-descriptors.h" | 18 #include "src/interface-descriptors.h" |
19 #include "src/interpreter/bytecodes.h" | 19 #include "src/interpreter/bytecodes.h" |
20 #include "src/machine-type.h" | 20 #include "src/machine-type.h" |
21 #include "src/macro-assembler.h" | 21 #include "src/macro-assembler.h" |
22 #include "src/utils.h" | 22 #include "src/utils.h" |
23 #include "src/zone/zone.h" | 23 #include "src/zone/zone.h" |
24 | 24 |
25 #define REPEAT_1_TO_2(V, T) V(T) V(T, T) | 25 #define REPEAT_1_TO_2(V, T) V(T) V(T, T) |
26 #define REPEAT_1_TO_3(V, T) REPEAT_1_TO_2(V, T) V(T, T, T) | 26 #define REPEAT_1_TO_3(V, T) REPEAT_1_TO_2(V, T) V(T, T, T) |
27 #define REPEAT_1_TO_4(V, T) REPEAT_1_TO_3(V, T) V(T, T, T, T) | 27 #define REPEAT_1_TO_4(V, T) REPEAT_1_TO_3(V, T) V(T, T, T, T) |
28 #define REPEAT_1_TO_5(V, T) REPEAT_1_TO_4(V, T) V(T, T, T, T, T) | 28 #define REPEAT_1_TO_5(V, T) REPEAT_1_TO_4(V, T) V(T, T, T, T, T) |
29 #define REPEAT_1_TO_6(V, T) REPEAT_1_TO_5(V, T) V(T, T, T, T, T, T) | 29 #define REPEAT_1_TO_6(V, T) REPEAT_1_TO_5(V, T) V(T, T, T, T, T, T) |
30 #define REPEAT_1_TO_7(V, T) REPEAT_1_TO_6(V, T) V(T, T, T, T, T, T) | 30 #define REPEAT_1_TO_7(V, T) REPEAT_1_TO_6(V, T) V(T, T, T, T, T, T, T) |
31 #define REPEAT_1_TO_8(V, T) REPEAT_1_TO_7(V, T) V(T, T, T, T, T, T, T) | 31 #define REPEAT_1_TO_8(V, T) REPEAT_1_TO_7(V, T) V(T, T, T, T, T, T, T, T) |
32 #define REPEAT_1_TO_9(V, T) REPEAT_1_TO_8(V, T) V(T, T, T, T, T, T, T, T) | 32 #define REPEAT_1_TO_9(V, T) REPEAT_1_TO_8(V, T) V(T, T, T, T, T, T, T, T, T) |
33 | 33 |
34 namespace v8 { | 34 namespace v8 { |
35 namespace internal { | 35 namespace internal { |
36 namespace compiler { | 36 namespace compiler { |
37 | 37 |
38 CodeAssemblerState::CodeAssemblerState( | 38 CodeAssemblerState::CodeAssemblerState( |
39 Isolate* isolate, Zone* zone, const CallInterfaceDescriptor& descriptor, | 39 Isolate* isolate, Zone* zone, const CallInterfaceDescriptor& descriptor, |
40 Code::Flags flags, const char* name, size_t result_size) | 40 Code::Flags flags, const char* name, size_t result_size) |
41 : CodeAssemblerState( | 41 : CodeAssemblerState( |
42 isolate, zone, | 42 isolate, zone, |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); | 424 CallPrologue(); |
425 Node* return_value = raw_assembler()->CallRuntime(function, context, args...); | 425 |
| 426 int argc = static_cast<int>(sizeof...(args)); |
| 427 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
| 428 zone(), function, argc, Operator::kNoProperties, |
| 429 CallDescriptor::kNoFlags); |
| 430 int return_count = static_cast<int>(desc->ReturnCount()); |
| 431 |
| 432 Node* centry = |
| 433 HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count)); |
| 434 Node* ref = ExternalConstant(ExternalReference(function, isolate())); |
| 435 Node* arity = Int32Constant(argc); |
| 436 Node* return_value = |
| 437 raw_assembler()->CallV(desc, centry, args..., ref, arity, context); |
| 438 |
426 CallEpilogue(); | 439 CallEpilogue(); |
427 return return_value; | 440 return return_value; |
428 } | 441 } |
429 | 442 |
430 // Instantiate CallRuntime() with up to 5 arguments. | 443 // Instantiate CallRuntime() with up to 5 arguments. |
431 #define INSTANTIATE(...) \ | 444 #define INSTANTIATE(...) \ |
432 template V8_EXPORT_PRIVATE Node* CodeAssembler::CallRuntime( \ | 445 template V8_EXPORT_PRIVATE Node* CodeAssembler::CallRuntime( \ |
433 Runtime::FunctionId, __VA_ARGS__); | 446 Runtime::FunctionId, __VA_ARGS__); |
434 REPEAT_1_TO_6(INSTANTIATE, Node*) | 447 REPEAT_1_TO_6(INSTANTIATE, Node*) |
435 #undef INSTANTIATE | 448 #undef INSTANTIATE |
436 | 449 |
437 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, | 450 template <class... TArgs> |
438 Node* context) { | 451 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function, |
439 return raw_assembler()->TailCallRuntime0(function_id, context); | 452 Node* context, TArgs... args) { |
| 453 CallPrologue(); |
| 454 |
| 455 int argc = static_cast<int>(sizeof...(args)); |
| 456 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
| 457 zone(), function, argc, Operator::kNoProperties, |
| 458 CallDescriptor::kSupportsTailCalls); |
| 459 int return_count = static_cast<int>(desc->ReturnCount()); |
| 460 |
| 461 Node* centry = |
| 462 HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count)); |
| 463 Node* ref = ExternalConstant(ExternalReference(function, isolate())); |
| 464 Node* arity = Int32Constant(argc); |
| 465 Node* return_value = |
| 466 raw_assembler()->TailCallV(desc, centry, args..., ref, arity, context); |
| 467 |
| 468 CallEpilogue(); |
| 469 return return_value; |
440 } | 470 } |
441 | 471 |
442 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, | 472 // Instantiate TailCallRuntime() with up to 6 arguments. |
443 Node* context, Node* arg1) { | 473 #define INSTANTIATE(...) \ |
444 return raw_assembler()->TailCallRuntime1(function_id, arg1, context); | 474 template V8_EXPORT_PRIVATE Node* CodeAssembler::TailCallRuntime( \ |
445 } | 475 Runtime::FunctionId, __VA_ARGS__); |
446 | 476 REPEAT_1_TO_7(INSTANTIATE, Node*) |
447 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, | 477 #undef INSTANTIATE |
448 Node* context, Node* arg1, Node* arg2) { | |
449 return raw_assembler()->TailCallRuntime2(function_id, arg1, arg2, context); | |
450 } | |
451 | |
452 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, | |
453 Node* context, Node* arg1, Node* arg2, | |
454 Node* arg3) { | |
455 return raw_assembler()->TailCallRuntime3(function_id, arg1, arg2, arg3, | |
456 context); | |
457 } | |
458 | |
459 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, | |
460 Node* context, Node* arg1, Node* arg2, | |
461 Node* arg3, Node* arg4) { | |
462 return raw_assembler()->TailCallRuntime4(function_id, arg1, arg2, arg3, arg4, | |
463 context); | |
464 } | |
465 | |
466 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, | |
467 Node* context, Node* arg1, Node* arg2, | |
468 Node* arg3, Node* arg4, Node* arg5) { | |
469 return raw_assembler()->TailCallRuntime5(function_id, arg1, arg2, arg3, arg4, | |
470 arg5, context); | |
471 } | |
472 | |
473 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, | |
474 Node* context, Node* arg1, Node* arg2, | |
475 Node* arg3, Node* arg4, Node* arg5, | |
476 Node* arg6) { | |
477 return raw_assembler()->TailCallRuntime6(function_id, arg1, arg2, arg3, arg4, | |
478 arg5, arg6, context); | |
479 } | |
480 | 478 |
481 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, | 479 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, |
482 Node* arg1, size_t result_size) { | 480 Node* arg1, size_t result_size) { |
483 Node* target = HeapConstant(callable.code()); | 481 Node* target = HeapConstant(callable.code()); |
484 return CallStub(callable.descriptor(), target, context, arg1, result_size); | 482 return CallStub(callable.descriptor(), target, context, arg1, result_size); |
485 } | 483 } |
486 | 484 |
487 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, | 485 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, |
488 Node* arg1, Node* arg2, size_t result_size) { | 486 Node* arg1, Node* arg2, size_t result_size) { |
489 Node* target = HeapConstant(callable.code()); | 487 Node* target = HeapConstant(callable.code()); |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 } | 1181 } |
1184 } | 1182 } |
1185 } | 1183 } |
1186 | 1184 |
1187 bound_ = true; | 1185 bound_ = true; |
1188 } | 1186 } |
1189 | 1187 |
1190 } // namespace compiler | 1188 } // namespace compiler |
1191 } // namespace internal | 1189 } // namespace internal |
1192 } // namespace v8 | 1190 } // namespace v8 |
OLD | NEW |