Commit c131dd95 authored by ishell's avatar ishell Committed by Commit bot

[turbofan] Combine family of CallRuntime() methods into single imeplementation.

.. by using variadic templates in CodeAssembler and RawMachineAssembler.

BUG=

Review-Url: https://codereview.chromium.org/2580823002
Cr-Commit-Position: refs/heads/master@{#41733}
parent 5993a116
......@@ -21,6 +21,12 @@ Callable make_callable(Stub& stub) {
} // namespace
// static
Handle<Code> CodeFactory::RuntimeCEntry(Isolate* isolate, int result_size) {
CEntryStub stub(isolate, result_size);
return stub.GetCode();
}
// static
Callable CodeFactory::LoadIC(Isolate* isolate) {
LoadICTrampolineStub stub(isolate);
......
......@@ -30,6 +30,12 @@ class Callable final BASE_EMBEDDED {
class V8_EXPORT_PRIVATE CodeFactory final {
public:
// CEntryStub has var-args semantics (all the arguments are passed on the
// stack and the arguments count is passed via register) which currently
// can't be expressed in CallInterfaceDescriptor. Therefore only the code
// is exported here.
static Handle<Code> RuntimeCEntry(Isolate* isolate, int result_size = 1);
// Initial states for ICs.
static Callable LoadIC(Isolate* isolate);
static Callable LoadICInOptimizedCode(Isolate* isolate);
......
......@@ -22,6 +22,15 @@
#include "src/utils.h"
#include "src/zone/zone.h"
#define REPEAT_1_TO_2(V, T) V(T) V(T, T)
#define REPEAT_1_TO_3(V, T) REPEAT_1_TO_2(V, T) V(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_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)
namespace v8 {
namespace internal {
namespace compiler {
......@@ -409,60 +418,21 @@ Node* CodeAssembler::TailCallN(CallDescriptor* descriptor, Node* code_target,
return raw_assembler()->TailCallN(descriptor, code_target, args);
}
Node* CodeAssembler::CallRuntime(Runtime::FunctionId function_id,
Node* context) {
template <class... TArgs>
Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context,
TArgs... args) {
CallPrologue();
Node* return_value = raw_assembler()->CallRuntime0(function_id, context);
Node* return_value = raw_assembler()->CallRuntime(function, context, args...);
CallEpilogue();
return return_value;
}
Node* CodeAssembler::CallRuntime(Runtime::FunctionId function_id, Node* context,
Node* arg1) {
CallPrologue();
Node* return_value =
raw_assembler()->CallRuntime1(function_id, arg1, context);
CallEpilogue();
return return_value;
}
Node* CodeAssembler::CallRuntime(Runtime::FunctionId function_id, Node* context,
Node* arg1, Node* arg2) {
CallPrologue();
Node* return_value =
raw_assembler()->CallRuntime2(function_id, arg1, arg2, context);
CallEpilogue();
return return_value;
}
Node* CodeAssembler::CallRuntime(Runtime::FunctionId function_id, Node* context,
Node* arg1, Node* arg2, Node* arg3) {
CallPrologue();
Node* return_value =
raw_assembler()->CallRuntime3(function_id, arg1, arg2, arg3, context);
CallEpilogue();
return return_value;
}
Node* CodeAssembler::CallRuntime(Runtime::FunctionId function_id, Node* context,
Node* arg1, Node* arg2, Node* arg3,
Node* arg4) {
CallPrologue();
Node* return_value = raw_assembler()->CallRuntime4(function_id, arg1, arg2,
arg3, arg4, context);
CallEpilogue();
return return_value;
}
Node* CodeAssembler::CallRuntime(Runtime::FunctionId function_id, Node* context,
Node* arg1, Node* arg2, Node* arg3, Node* arg4,
Node* arg5) {
CallPrologue();
Node* return_value = raw_assembler()->CallRuntime5(function_id, arg1, arg2,
arg3, arg4, arg5, context);
CallEpilogue();
return return_value;
}
// Instantiate CallRuntime() with up to 5 arguments.
#define INSTANTIATE(...) \
template V8_EXPORT_PRIVATE Node* CodeAssembler::CallRuntime( \
Runtime::FunctionId, __VA_ARGS__);
REPEAT_1_TO_6(INSTANTIATE, Node*)
#undef INSTANTIATE
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function_id,
Node* context) {
......
......@@ -300,16 +300,8 @@ class V8_EXPORT_PRIVATE CodeAssembler {
Node* Projection(int index, Node* value);
// Calls
Node* CallRuntime(Runtime::FunctionId function_id, Node* context);
Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1);
Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1,
Node* arg2);
Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1,
Node* arg2, Node* arg3);
Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1,
Node* arg2, Node* arg3, Node* arg4);
Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1,
Node* arg2, Node* arg3, Node* arg4, Node* arg5);
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,
......
......@@ -200,98 +200,6 @@ Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc,
return AddNode(common()->Call(desc), input_count, buffer);
}
Node* RawMachineAssembler::CallRuntime0(Runtime::FunctionId function,
Node* context) {
CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
zone(), function, 0, Operator::kNoProperties, CallDescriptor::kNoFlags);
int return_count = static_cast<int>(descriptor->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(0);
return AddNode(common()->Call(descriptor), centry, ref, arity, context);
}
Node* RawMachineAssembler::CallRuntime1(Runtime::FunctionId function,
Node* arg1, Node* context) {
CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
zone(), function, 1, Operator::kNoProperties, CallDescriptor::kNoFlags);
int return_count = static_cast<int>(descriptor->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(1);
return AddNode(common()->Call(descriptor), centry, arg1, ref, arity, context);
}
Node* RawMachineAssembler::CallRuntime2(Runtime::FunctionId function,
Node* arg1, Node* arg2, Node* context) {
CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
zone(), function, 2, Operator::kNoProperties, CallDescriptor::kNoFlags);
int return_count = static_cast<int>(descriptor->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(2);
return AddNode(common()->Call(descriptor), centry, arg1, arg2, ref, arity,
context);
}
Node* RawMachineAssembler::CallRuntime3(Runtime::FunctionId function,
Node* arg1, Node* arg2, Node* arg3,
Node* context) {
CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
zone(), function, 3, Operator::kNoProperties, CallDescriptor::kNoFlags);
int return_count = static_cast<int>(descriptor->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(3);
return AddNode(common()->Call(descriptor), centry, arg1, arg2, arg3, ref,
arity, context);
}
Node* RawMachineAssembler::CallRuntime4(Runtime::FunctionId function,
Node* arg1, Node* arg2, Node* arg3,
Node* arg4, Node* context) {
CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
zone(), function, 4, Operator::kNoProperties, CallDescriptor::kNoFlags);
int return_count = static_cast<int>(descriptor->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(4);
return AddNode(common()->Call(descriptor), centry, arg1, arg2, arg3, arg4,
ref, arity, context);
}
Node* RawMachineAssembler::CallRuntime5(Runtime::FunctionId function,
Node* arg1, Node* arg2, Node* arg3,
Node* arg4, Node* arg5, Node* context) {
CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
zone(), function, 5, Operator::kNoProperties, CallDescriptor::kNoFlags);
int return_count = static_cast<int>(descriptor->ReturnCount());
Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(5);
return AddNode(common()->Call(descriptor), centry, arg1, arg2, arg3, arg4,
arg5, ref, arity, context);
}
Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function,
Node** args) {
int param_count = static_cast<int>(desc->ParameterCount());
......
......@@ -6,6 +6,7 @@
#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"
......@@ -705,22 +706,27 @@ class V8_EXPORT_PRIVATE RawMachineAssembler {
// Call a given call descriptor and the given arguments and frame-state.
Node* CallNWithFrameState(CallDescriptor* desc, Node* function, Node** args,
Node* frame_state);
// Call to a runtime function with zero arguments.
Node* CallRuntime0(Runtime::FunctionId function, Node* context);
// Call to a runtime function with one arguments.
Node* CallRuntime1(Runtime::FunctionId function, Node* arg0, Node* context);
// Call to a runtime function with two arguments.
Node* CallRuntime2(Runtime::FunctionId function, Node* arg1, Node* arg2,
Node* context);
// Call to a runtime function with three arguments.
Node* CallRuntime3(Runtime::FunctionId function, Node* arg1, Node* arg2,
Node* arg3, Node* context);
// Call to a runtime function with four arguments.
Node* CallRuntime4(Runtime::FunctionId function, Node* arg1, Node* arg2,
Node* arg3, Node* arg4, Node* context);
// Call to a runtime function with five arguments.
Node* CallRuntime5(Runtime::FunctionId function, Node* arg1, Node* arg2,
Node* arg3, Node* arg4, Node* arg5, Node* context);
// 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);
return AddNode(common()->Call(descriptor), centry, args..., ref, arity,
context);
}
// Call to a C function with zero arguments.
Node* CallCFunction0(MachineType return_type, Node* function);
// Call to a C function with one parameter.
......
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