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 @@
#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_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_8(V, T) REPEAT_1_TO_7(V, T) V(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_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, 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 internal {
......@@ -422,7 +422,22 @@ template <class... TArgs>
Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context,
TArgs... args) {
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();
return return_value;
}
......@@ -434,49 +449,37 @@ Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context,
REPEAT_1_TO_6(INSTANTIATE, Node*)
#undef INSTANTIATE
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id,
Node* context) {
return raw_assembler()->TailCallRuntime0(function_id, context);
}
template <class... TArgs>
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function,
Node* context, TArgs... args) {
CallPrologue();
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id,
Node* context, Node* arg1) {
return raw_assembler()->TailCallRuntime1(function_id, arg1, context);
}
int argc = static_cast<int>(sizeof...(args));
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
zone(), function, argc, Operator::kNoProperties,
CallDescriptor::kSupportsTailCalls);
int return_count = static_cast<int>(desc->ReturnCount());
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id,
Node* context, Node* arg1, Node* arg2) {
return raw_assembler()->TailCallRuntime2(function_id, arg1, arg2, context);
}
Node* centry =
HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count));
Node* ref = ExternalConstant(ExternalReference(function, isolate()));
Node* arity = Int32Constant(argc);
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id,
Node* context, Node* arg1, Node* arg2,
Node* arg3) {
return raw_assembler()->TailCallRuntime3(function_id, arg1, arg2, arg3,
context);
}
Node* nodes[] = {centry, args..., ref, arity, context};
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id,
Node* context, Node* arg1, Node* arg2,
Node* arg3, Node* arg4) {
return raw_assembler()->TailCallRuntime4(function_id, arg1, arg2, arg3, arg4,
context);
}
Node* return_value =
raw_assembler()->TailCallN(desc, arraysize(nodes), nodes);
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id,
Node* context, Node* arg1, Node* arg2,
Node* arg3, Node* arg4, Node* arg5) {
return raw_assembler()->TailCallRuntime5(function_id, arg1, arg2, arg3, arg4,
arg5, context);
CallEpilogue();
return return_value;
}
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id,
Node* context, Node* arg1, Node* arg2,
Node* arg3, Node* arg4, Node* arg5,
Node* arg6) {
return raw_assembler()->TailCallRuntime6(function_id, arg1, arg2, arg3, arg4,
arg5, arg6, context);
}
// Instantiate TailCallRuntime() with up to 6 arguments.
#define INSTANTIATE(...) \
template V8_EXPORT_PRIVATE Node* CodeAssembler::TailCallRuntime( \
Runtime::FunctionId, __VA_ARGS__);
REPEAT_1_TO_7(INSTANTIATE, Node*)
#undef INSTANTIATE
Node* CodeAssembler::CallStub(Callable const& callable, Node* context,
Node* arg1, size_t result_size) {
......
......@@ -303,21 +303,9 @@ class V8_EXPORT_PRIVATE CodeAssembler {
template <class... TArgs>
Node* CallRuntime(Runtime::FunctionId function, Node* context, TArgs... args);
Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context);
Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
Node* arg1);
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);
template <class... TArgs>
Node* TailCallRuntime(Runtime::FunctionId function, Node* context,
TArgs... args);
// A pair of a zero-based argument index and a value.
// It helps writing arguments order independent code.
......
......@@ -4,10 +4,10 @@
#include "src/compiler/raw-machine-assembler.h"
#include "src/code-factory.h"
#include "src/compiler/node-properties.h"
#include "src/compiler/pipeline.h"
#include "src/compiler/scheduler.h"
#include "src/objects-inl.h"
namespace v8 {
namespace internal {
......@@ -183,6 +183,12 @@ Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function,
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* function, Node** args,
......@@ -210,163 +216,14 @@ Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function,
for (int i = 0; i < param_count; i++) {
buffer[index++] = args[i];
}
Node* tail_call = MakeNode(common()->TailCall(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;
return TailCallN(desc, input_count, buffer);
}
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* arg1, Node* arg2, Node* arg3,
Node* arg4, Node* arg5, Node* arg6,
Node* context) {
const int kArity = 6;
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);
Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, int input_count,
Node* const* inputs) {
// +1 is for target.
DCHECK_EQ(input_count, desc->ParameterCount() + 1);
Node* tail_call = MakeNode(common()->TailCall(desc), input_count, inputs);
schedule()->AddTailCall(CurrentBlock(), tail_call);
current_block_ = nullptr;
return tail_call;
......
......@@ -6,7 +6,6 @@
#define V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_
#include "src/assembler.h"
#include "src/code-factory.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/linkage.h"
......@@ -707,25 +706,13 @@ class V8_EXPORT_PRIVATE RawMachineAssembler {
Node* CallNWithFrameState(CallDescriptor* desc, Node* function, Node** args,
Node* frame_state);
// Call to a runtime function with given arguments.
template <class... TArgs>
Node* CallRuntime(Runtime::FunctionId function, Node* context,
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);
// Call a given call descriptor and the given arguments.
// The call target is passed as part of the {inputs} array.
Node* CallN(CallDescriptor* desc, int input_count, Node* const* inputs);
return AddNode(common()->Call(descriptor), centry, args..., ref, arity,
context);
}
// Tail call a given call descriptor and the given arguments.
// 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.
Node* CallCFunction0(MachineType return_type, Node* function);
......@@ -747,27 +734,6 @@ class V8_EXPORT_PRIVATE RawMachineAssembler {
// Tail call the given call descriptor and the given arguments.
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
......
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