Commit 4bd0cbdd authored by ishell's avatar ishell Committed by Commit bot

[turbofan] Combine family of TailCallRuntime() methods into single implementation.

.. by using variadic templates in CodeAssembler.

BUG=

Review-Url: https://codereview.chromium.org/2577013003
Cr-Commit-Position: refs/heads/master@{#41746}
parent e3ad4f13
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
#define REPEAT_1_TO_4(V, T) REPEAT_1_TO_3(V, T) V(T, T, T, T) #define REPEAT_1_TO_4(V, T) REPEAT_1_TO_3(V, T) V(T, T, T, T)
#define REPEAT_1_TO_5(V, T) REPEAT_1_TO_4(V, T) V(T, T, T, T, T) #define REPEAT_1_TO_5(V, T) REPEAT_1_TO_4(V, T) V(T, T, T, T, T)
#define REPEAT_1_TO_6(V, T) REPEAT_1_TO_5(V, T) V(T, T, T, T, T, T) #define REPEAT_1_TO_6(V, T) REPEAT_1_TO_5(V, T) V(T, T, T, T, T, T)
#define REPEAT_1_TO_7(V, T) REPEAT_1_TO_6(V, T) V(T, T, T, T, T, T) #define REPEAT_1_TO_7(V, T) REPEAT_1_TO_6(V, T) V(T, T, T, T, T, T, T)
#define REPEAT_1_TO_8(V, T) REPEAT_1_TO_7(V, T) V(T, T, T, T, T, T, T) #define REPEAT_1_TO_8(V, T) REPEAT_1_TO_7(V, T) V(T, T, T, T, T, T, T, T)
#define REPEAT_1_TO_9(V, T) REPEAT_1_TO_8(V, T) V(T, T, T, T, T, T, T, T) #define REPEAT_1_TO_9(V, T) REPEAT_1_TO_8(V, T) V(T, T, T, T, T, T, T, T, T)
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -422,7 +422,22 @@ template <class... TArgs> ...@@ -422,7 +422,22 @@ template <class... TArgs>
Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context, Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context,
TArgs... args) { TArgs... args) {
CallPrologue(); CallPrologue();
Node* return_value = raw_assembler()->CallRuntime(function, context, args...);
int argc = static_cast<int>(sizeof...(args));
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
zone(), function, argc, Operator::kNoProperties,
CallDescriptor::kNoFlags);
int return_count = static_cast<int>(desc->ReturnCount());
Node* centry =
HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count));
Node* ref = ExternalConstant(ExternalReference(function, isolate()));
Node* arity = Int32Constant(argc);
Node* nodes[] = {centry, args..., ref, arity, context};
Node* return_value = raw_assembler()->CallN(desc, arraysize(nodes), nodes);
CallEpilogue(); CallEpilogue();
return return_value; return return_value;
} }
...@@ -434,49 +449,37 @@ Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context, ...@@ -434,49 +449,37 @@ Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context,
REPEAT_1_TO_6(INSTANTIATE, Node*) REPEAT_1_TO_6(INSTANTIATE, Node*)
#undef INSTANTIATE #undef INSTANTIATE
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, template <class... TArgs>
Node* context) { Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function,
return raw_assembler()->TailCallRuntime0(function_id, context); Node* context, TArgs... args) {
} CallPrologue();
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, int argc = static_cast<int>(sizeof...(args));
Node* context, Node* arg1) { CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
return raw_assembler()->TailCallRuntime1(function_id, arg1, context); zone(), function, argc, Operator::kNoProperties,
} CallDescriptor::kSupportsTailCalls);
int return_count = static_cast<int>(desc->ReturnCount());
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, Node* centry =
Node* context, Node* arg1, Node* arg2) { HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count));
return raw_assembler()->TailCallRuntime2(function_id, arg1, arg2, context); Node* ref = ExternalConstant(ExternalReference(function, isolate()));
} Node* arity = Int32Constant(argc);
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, Node* nodes[] = {centry, args..., ref, arity, context};
Node* context, Node* arg1, Node* arg2,
Node* arg3) {
return raw_assembler()->TailCallRuntime3(function_id, arg1, arg2, arg3,
context);
}
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, Node* return_value =
Node* context, Node* arg1, Node* arg2, raw_assembler()->TailCallN(desc, arraysize(nodes), nodes);
Node* arg3, Node* arg4) {
return raw_assembler()->TailCallRuntime4(function_id, arg1, arg2, arg3, arg4,
context);
}
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, CallEpilogue();
Node* context, Node* arg1, Node* arg2, return return_value;
Node* arg3, Node* arg4, Node* arg5) {
return raw_assembler()->TailCallRuntime5(function_id, arg1, arg2, arg3, arg4,
arg5, context);
} }
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id, // Instantiate TailCallRuntime() with up to 6 arguments.
Node* context, Node* arg1, Node* arg2, #define INSTANTIATE(...) \
Node* arg3, Node* arg4, Node* arg5, template V8_EXPORT_PRIVATE Node* CodeAssembler::TailCallRuntime( \
Node* arg6) { Runtime::FunctionId, __VA_ARGS__);
return raw_assembler()->TailCallRuntime6(function_id, arg1, arg2, arg3, arg4, REPEAT_1_TO_7(INSTANTIATE, Node*)
arg5, arg6, context); #undef INSTANTIATE
}
Node* CodeAssembler::CallStub(Callable const& callable, Node* context, Node* CodeAssembler::CallStub(Callable const& callable, Node* context,
Node* arg1, size_t result_size) { Node* arg1, size_t result_size) {
......
...@@ -303,21 +303,9 @@ class V8_EXPORT_PRIVATE CodeAssembler { ...@@ -303,21 +303,9 @@ class V8_EXPORT_PRIVATE CodeAssembler {
template <class... TArgs> template <class... TArgs>
Node* CallRuntime(Runtime::FunctionId function, Node* context, TArgs... args); Node* CallRuntime(Runtime::FunctionId function, Node* context, TArgs... args);
Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context); template <class... TArgs>
Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, Node* TailCallRuntime(Runtime::FunctionId function, Node* context,
Node* arg1); TArgs... args);
Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
Node* arg1, Node* arg2);
Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
Node* arg1, Node* arg2, Node* arg3);
Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
Node* arg1, Node* arg2, Node* arg3, Node* arg4);
Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
Node* arg1, Node* arg2, Node* arg3, Node* arg4,
Node* arg5);
Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
Node* arg1, Node* arg2, Node* arg3, Node* arg4,
Node* arg5, Node* arg6);
// A pair of a zero-based argument index and a value. // A pair of a zero-based argument index and a value.
// It helps writing arguments order independent code. // It helps writing arguments order independent code.
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
#include "src/compiler/raw-machine-assembler.h" #include "src/compiler/raw-machine-assembler.h"
#include "src/code-factory.h"
#include "src/compiler/node-properties.h" #include "src/compiler/node-properties.h"
#include "src/compiler/pipeline.h" #include "src/compiler/pipeline.h"
#include "src/compiler/scheduler.h" #include "src/compiler/scheduler.h"
#include "src/objects-inl.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -183,6 +183,12 @@ Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function, ...@@ -183,6 +183,12 @@ Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function,
return AddNode(common()->Call(desc), input_count, buffer); return AddNode(common()->Call(desc), input_count, buffer);
} }
Node* RawMachineAssembler::CallN(CallDescriptor* desc, int input_count,
Node* const* nodes) {
// +1 is for target.
DCHECK_EQ(input_count, desc->ParameterCount() + 1);
return AddNode(common()->Call(desc), input_count, nodes);
}
Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc, Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc,
Node* function, Node** args, Node* function, Node** args,
...@@ -210,163 +216,14 @@ Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function, ...@@ -210,163 +216,14 @@ Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function,
for (int i = 0; i < param_count; i++) { for (int i = 0; i < param_count; i++) {
buffer[index++] = args[i]; buffer[index++] = args[i];
} }
Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer); return TailCallN(desc, input_count, buffer);
schedule()->AddTailCall(CurrentBlock(), tail_call);
current_block_ = nullptr;
return tail_call;
}
Node* RawMachineAssembler::TailCallRuntime0(Runtime::FunctionId function,
Node* context) {
const int kArity = 0;
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
zone(), function, kArity, Operator::kNoProperties,
CallDescriptor::kSupportsTailCalls);
int return_count = static_cast<int>(desc->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(kArity);
Node* nodes[] = {centry, ref, arity, context};
Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
schedule()->AddTailCall(CurrentBlock(), tail_call);
current_block_ = nullptr;
return tail_call;
}
Node* RawMachineAssembler::TailCallRuntime1(Runtime::FunctionId function,
Node* arg1, Node* context) {
const int kArity = 1;
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
zone(), function, kArity, Operator::kNoProperties,
CallDescriptor::kSupportsTailCalls);
int return_count = static_cast<int>(desc->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(kArity);
Node* nodes[] = {centry, arg1, ref, arity, context};
Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
schedule()->AddTailCall(CurrentBlock(), tail_call);
current_block_ = nullptr;
return tail_call;
}
Node* RawMachineAssembler::TailCallRuntime2(Runtime::FunctionId function,
Node* arg1, Node* arg2,
Node* context) {
const int kArity = 2;
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
zone(), function, kArity, Operator::kNoProperties,
CallDescriptor::kSupportsTailCalls);
int return_count = static_cast<int>(desc->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(kArity);
Node* nodes[] = {centry, arg1, arg2, ref, arity, context};
Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
schedule()->AddTailCall(CurrentBlock(), tail_call);
current_block_ = nullptr;
return tail_call;
}
Node* RawMachineAssembler::TailCallRuntime3(Runtime::FunctionId function,
Node* arg1, Node* arg2, Node* arg3,
Node* context) {
const int kArity = 3;
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
zone(), function, kArity, Operator::kNoProperties,
CallDescriptor::kSupportsTailCalls);
int return_count = static_cast<int>(desc->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(kArity);
Node* nodes[] = {centry, arg1, arg2, arg3, ref, arity, context};
Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
schedule()->AddTailCall(CurrentBlock(), tail_call);
current_block_ = nullptr;
return tail_call;
}
Node* RawMachineAssembler::TailCallRuntime4(Runtime::FunctionId function,
Node* arg1, Node* arg2, Node* arg3,
Node* arg4, Node* context) {
const int kArity = 4;
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
zone(), function, kArity, Operator::kNoProperties,
CallDescriptor::kSupportsTailCalls);
int return_count = static_cast<int>(desc->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(kArity);
Node* nodes[] = {centry, arg1, arg2, arg3, arg4, ref, arity, context};
Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
schedule()->AddTailCall(CurrentBlock(), tail_call);
current_block_ = nullptr;
return tail_call;
}
Node* RawMachineAssembler::TailCallRuntime5(Runtime::FunctionId function,
Node* arg1, Node* arg2, Node* arg3,
Node* arg4, Node* arg5,
Node* context) {
const int kArity = 5;
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
zone(), function, kArity, Operator::kNoProperties,
CallDescriptor::kSupportsTailCalls);
int return_count = static_cast<int>(desc->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(kArity);
Node* nodes[] = {centry, arg1, arg2, arg3, arg4, arg5, ref, arity, context};
Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
schedule()->AddTailCall(CurrentBlock(), tail_call);
current_block_ = nullptr;
return tail_call;
} }
Node* RawMachineAssembler::TailCallRuntime6(Runtime::FunctionId function, Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, int input_count,
Node* arg1, Node* arg2, Node* arg3, Node* const* inputs) {
Node* arg4, Node* arg5, Node* arg6, // +1 is for target.
Node* context) { DCHECK_EQ(input_count, desc->ParameterCount() + 1);
const int kArity = 6; Node* tail_call = MakeNode(common()->TailCall(desc), input_count, inputs);
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
zone(), function, kArity, Operator::kNoProperties,
CallDescriptor::kSupportsTailCalls);
int return_count = static_cast<int>(desc->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(kArity);
Node* nodes[] = {centry, arg1, arg2, arg3, arg4,
arg5, arg6, ref, arity, context};
Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
schedule()->AddTailCall(CurrentBlock(), tail_call); schedule()->AddTailCall(CurrentBlock(), tail_call);
current_block_ = nullptr; current_block_ = nullptr;
return tail_call; return tail_call;
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_ #define V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_
#include "src/assembler.h" #include "src/assembler.h"
#include "src/code-factory.h"
#include "src/compiler/common-operator.h" #include "src/compiler/common-operator.h"
#include "src/compiler/graph.h" #include "src/compiler/graph.h"
#include "src/compiler/linkage.h" #include "src/compiler/linkage.h"
...@@ -707,25 +706,13 @@ class V8_EXPORT_PRIVATE RawMachineAssembler { ...@@ -707,25 +706,13 @@ class V8_EXPORT_PRIVATE RawMachineAssembler {
Node* CallNWithFrameState(CallDescriptor* desc, Node* function, Node** args, Node* CallNWithFrameState(CallDescriptor* desc, Node* function, Node** args,
Node* frame_state); Node* frame_state);
// Call to a runtime function with given arguments. // Call a given call descriptor and the given arguments.
template <class... TArgs> // The call target is passed as part of the {inputs} array.
Node* CallRuntime(Runtime::FunctionId function, Node* context, Node* CallN(CallDescriptor* desc, int input_count, Node* const* inputs);
TArgs... args) {
int argc = static_cast<int>(sizeof...(args));
CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
zone(), function, argc, Operator::kNoProperties,
CallDescriptor::kNoFlags);
int return_count = static_cast<int>(descriptor->ReturnCount());
Node* centry =
HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count));
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(argc);
return AddNode(common()->Call(descriptor), centry, args..., ref, arity, // Tail call a given call descriptor and the given arguments.
context); // The call target is passed as part of the {inputs} array.
} Node* TailCallN(CallDescriptor* desc, int input_count, Node* const* inputs);
// Call to a C function with zero arguments. // Call to a C function with zero arguments.
Node* CallCFunction0(MachineType return_type, Node* function); Node* CallCFunction0(MachineType return_type, Node* function);
...@@ -747,27 +734,6 @@ class V8_EXPORT_PRIVATE RawMachineAssembler { ...@@ -747,27 +734,6 @@ class V8_EXPORT_PRIVATE RawMachineAssembler {
// Tail call the given call descriptor and the given arguments. // Tail call the given call descriptor and the given arguments.
Node* TailCallN(CallDescriptor* call_descriptor, Node* function, Node** args); Node* TailCallN(CallDescriptor* call_descriptor, Node* function, Node** args);
// Tail call to a runtime function with zero arguments.
Node* TailCallRuntime0(Runtime::FunctionId function, Node* context);
// Tail call to a runtime function with one argument.
Node* TailCallRuntime1(Runtime::FunctionId function, Node* arg0,
Node* context);
// Tail call to a runtime function with two arguments.
Node* TailCallRuntime2(Runtime::FunctionId function, Node* arg1, Node* arg2,
Node* context);
// Tail call to a runtime function with three arguments.
Node* TailCallRuntime3(Runtime::FunctionId function, Node* arg1, Node* arg2,
Node* arg3, Node* context);
// Tail call to a runtime function with four arguments.
Node* TailCallRuntime4(Runtime::FunctionId function, Node* arg1, Node* arg2,
Node* arg3, Node* arg4, Node* context);
// Tail call to a runtime function with five arguments.
Node* TailCallRuntime5(Runtime::FunctionId function, Node* arg1, Node* arg2,
Node* arg3, Node* arg4, Node* arg5, Node* context);
// Tail call to a runtime function with six arguments.
Node* TailCallRuntime6(Runtime::FunctionId function, Node* arg1, Node* arg2,
Node* arg3, Node* arg4, Node* arg5, Node* arg6,
Node* context);
// =========================================================================== // ===========================================================================
// The following utility methods deal with control flow, hence might switch // The following utility methods deal with control flow, hence might switch
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment