| 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 |
| 437 Node* nodes[] = {centry, args..., ref, arity, context}; |
| 438 |
| 439 Node* return_value = raw_assembler()->CallN(desc, arraysize(nodes), nodes); |
| 440 |
| 426 CallEpilogue(); | 441 CallEpilogue(); |
| 427 return return_value; | 442 return return_value; |
| 428 } | 443 } |
| 429 | 444 |
| 430 // Instantiate CallRuntime() with up to 5 arguments. | 445 // Instantiate CallRuntime() with up to 5 arguments. |
| 431 #define INSTANTIATE(...) \ | 446 #define INSTANTIATE(...) \ |
| 432 template V8_EXPORT_PRIVATE Node* CodeAssembler::CallRuntime( \ | 447 template V8_EXPORT_PRIVATE Node* CodeAssembler::CallRuntime( \ |
| 433 Runtime::FunctionId, __VA_ARGS__); | 448 Runtime::FunctionId, __VA_ARGS__); |
| 434 REPEAT_1_TO_6(INSTANTIATE, Node*) | 449 REPEAT_1_TO_6(INSTANTIATE, Node*) |
| 435 #undef INSTANTIATE | 450 #undef INSTANTIATE |
| 436 | 451 |
| 437 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, | 452 template <class... TArgs> |
| 438 Node* context) { | 453 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function, |
| 439 return raw_assembler()->TailCallRuntime0(function_id, context); | 454 Node* context, TArgs... args) { |
| 455 CallPrologue(); |
| 456 |
| 457 int argc = static_cast<int>(sizeof...(args)); |
| 458 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
| 459 zone(), function, argc, Operator::kNoProperties, |
| 460 CallDescriptor::kSupportsTailCalls); |
| 461 int return_count = static_cast<int>(desc->ReturnCount()); |
| 462 |
| 463 Node* centry = |
| 464 HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count)); |
| 465 Node* ref = ExternalConstant(ExternalReference(function, isolate())); |
| 466 Node* arity = Int32Constant(argc); |
| 467 |
| 468 Node* nodes[] = {centry, args..., ref, arity, context}; |
| 469 |
| 470 Node* return_value = |
| 471 raw_assembler()->TailCallN(desc, arraysize(nodes), nodes); |
| 472 |
| 473 CallEpilogue(); |
| 474 return return_value; |
| 440 } | 475 } |
| 441 | 476 |
| 442 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, | 477 // Instantiate TailCallRuntime() with up to 6 arguments. |
| 443 Node* context, Node* arg1) { | 478 #define INSTANTIATE(...) \ |
| 444 return raw_assembler()->TailCallRuntime1(function_id, arg1, context); | 479 template V8_EXPORT_PRIVATE Node* CodeAssembler::TailCallRuntime( \ |
| 445 } | 480 Runtime::FunctionId, __VA_ARGS__); |
| 446 | 481 REPEAT_1_TO_7(INSTANTIATE, Node*) |
| 447 Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, | 482 #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 | 483 |
| 481 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, | 484 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, |
| 482 Node* arg1, size_t result_size) { | 485 Node* arg1, size_t result_size) { |
| 483 Node* target = HeapConstant(callable.code()); | 486 Node* target = HeapConstant(callable.code()); |
| 484 return CallStub(callable.descriptor(), target, context, arg1, result_size); | 487 return CallStub(callable.descriptor(), target, context, arg1, result_size); |
| 485 } | 488 } |
| 486 | 489 |
| 487 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, | 490 Node* CodeAssembler::CallStub(Callable const& callable, Node* context, |
| 488 Node* arg1, Node* arg2, size_t result_size) { | 491 Node* arg1, Node* arg2, size_t result_size) { |
| 489 Node* target = HeapConstant(callable.code()); | 492 Node* target = HeapConstant(callable.code()); |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 } | 1186 } |
| 1184 } | 1187 } |
| 1185 } | 1188 } |
| 1186 | 1189 |
| 1187 bound_ = true; | 1190 bound_ = true; |
| 1188 } | 1191 } |
| 1189 | 1192 |
| 1190 } // namespace compiler | 1193 } // namespace compiler |
| 1191 } // namespace internal | 1194 } // namespace internal |
| 1192 } // namespace v8 | 1195 } // namespace v8 |
| OLD | NEW |