Commit 6eeab124 authored by ishell's avatar ishell Committed by Commit bot

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

.. by using variadic templates in CodeAssembler.

BUG=

Review-Url: https://codereview.chromium.org/2577913003
Cr-Commit-Position: refs/heads/master@{#41749}
parent c5ea5125
...@@ -421,8 +421,6 @@ Node* CodeAssembler::TailCallN(CallDescriptor* descriptor, Node* code_target, ...@@ -421,8 +421,6 @@ Node* CodeAssembler::TailCallN(CallDescriptor* descriptor, Node* code_target,
template <class... TArgs> template <class... TArgs>
Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context, Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context,
TArgs... args) { TArgs... args) {
CallPrologue();
int argc = static_cast<int>(sizeof...(args)); int argc = static_cast<int>(sizeof...(args));
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
zone(), function, argc, Operator::kNoProperties, zone(), function, argc, Operator::kNoProperties,
...@@ -436,8 +434,8 @@ Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context, ...@@ -436,8 +434,8 @@ Node* CodeAssembler::CallRuntime(Runtime::FunctionId function, Node* context,
Node* nodes[] = {centry, args..., ref, arity, context}; Node* nodes[] = {centry, args..., ref, arity, context};
CallPrologue();
Node* return_value = raw_assembler()->CallN(desc, arraysize(nodes), nodes); Node* return_value = raw_assembler()->CallN(desc, arraysize(nodes), nodes);
CallEpilogue(); CallEpilogue();
return return_value; return return_value;
} }
...@@ -452,8 +450,6 @@ REPEAT_1_TO_6(INSTANTIATE, Node*) ...@@ -452,8 +450,6 @@ REPEAT_1_TO_6(INSTANTIATE, Node*)
template <class... TArgs> template <class... TArgs>
Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function, Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function,
Node* context, TArgs... args) { Node* context, TArgs... args) {
CallPrologue();
int argc = static_cast<int>(sizeof...(args)); int argc = static_cast<int>(sizeof...(args));
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
zone(), function, argc, Operator::kNoProperties, zone(), function, argc, Operator::kNoProperties,
...@@ -467,9 +463,9 @@ Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function, ...@@ -467,9 +463,9 @@ Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function,
Node* nodes[] = {centry, args..., ref, arity, context}; Node* nodes[] = {centry, args..., ref, arity, context};
CallPrologue();
Node* return_value = Node* return_value =
raw_assembler()->TailCallN(desc, arraysize(nodes), nodes); raw_assembler()->TailCallN(desc, arraysize(nodes), nodes);
CallEpilogue(); CallEpilogue();
return return_value; return return_value;
} }
...@@ -481,140 +477,42 @@ Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function, ...@@ -481,140 +477,42 @@ Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function,
REPEAT_1_TO_7(INSTANTIATE, Node*) REPEAT_1_TO_7(INSTANTIATE, Node*)
#undef INSTANTIATE #undef INSTANTIATE
Node* CodeAssembler::CallStub(Callable const& callable, Node* context, template <class... TArgs>
Node* arg1, size_t result_size) { Node* CodeAssembler::CallStubR(const CallInterfaceDescriptor& descriptor,
Node* target = HeapConstant(callable.code()); size_t result_size, Node* target, Node* context,
return CallStub(callable.descriptor(), target, context, arg1, result_size); TArgs... args) {
} Node* nodes[] = {target, args..., context};
return CallStubN(descriptor, result_size, arraysize(nodes), nodes);
Node* CodeAssembler::CallStub(Callable const& callable, Node* context,
Node* arg1, Node* arg2, size_t result_size) {
Node* target = HeapConstant(callable.code());
return CallStub(callable.descriptor(), target, context, arg1, arg2,
result_size);
}
Node* CodeAssembler::CallStub(Callable const& callable, Node* context,
Node* arg1, Node* arg2, Node* arg3,
size_t result_size) {
Node* target = HeapConstant(callable.code());
return CallStub(callable.descriptor(), target, context, arg1, arg2, arg3,
result_size);
}
Node* CodeAssembler::CallStub(Callable const& callable, Node* context,
Node* arg1, Node* arg2, Node* arg3, Node* arg4,
size_t result_size) {
Node* target = HeapConstant(callable.code());
return CallStub(callable.descriptor(), target, context, arg1, arg2, arg3,
arg4, result_size);
}
Node* CodeAssembler::CallStubN(Callable const& callable, Node** args,
size_t result_size) {
Node* target = HeapConstant(callable.code());
return CallStubN(callable.descriptor(), target, args, result_size);
}
Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor,
Node* target, Node* context, size_t result_size) {
CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
isolate(), zone(), descriptor, descriptor.GetStackParameterCount(),
CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size);
Node** args = zone()->NewArray<Node*>(1);
args[0] = context;
return CallN(call_descriptor, target, args);
}
Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor,
Node* target, Node* context, Node* arg1,
size_t result_size) {
CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
isolate(), zone(), descriptor, descriptor.GetStackParameterCount(),
CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size);
Node** args = zone()->NewArray<Node*>(2);
args[0] = arg1;
args[1] = context;
return CallN(call_descriptor, target, args);
}
Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor,
Node* target, Node* context, Node* arg1,
Node* arg2, size_t result_size) {
CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
isolate(), zone(), descriptor, descriptor.GetStackParameterCount(),
CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size);
Node** args = zone()->NewArray<Node*>(3);
args[0] = arg1;
args[1] = arg2;
args[2] = context;
return CallN(call_descriptor, target, args);
} }
Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, // Instantiate CallStubR() with up to 5 arguments.
Node* target, Node* context, Node* arg1, #define INSTANTIATE(...) \
Node* arg2, Node* arg3, size_t result_size) { template V8_EXPORT_PRIVATE Node* CodeAssembler::CallStubR( \
CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( const CallInterfaceDescriptor& descriptor, size_t, Node*, __VA_ARGS__);
isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), REPEAT_1_TO_6(INSTANTIATE, Node*)
CallDescriptor::kNoFlags, Operator::kNoProperties, #undef INSTANTIATE
MachineType::AnyTagged(), result_size);
Node** args = zone()->NewArray<Node*>(4);
args[0] = arg1;
args[1] = arg2;
args[2] = arg3;
args[3] = context;
return CallN(call_descriptor, target, args);
}
Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, Node* CodeAssembler::CallStubN(const CallInterfaceDescriptor& descriptor,
Node* target, Node* context, Node* arg1, size_t result_size, int input_count,
Node* arg2, Node* arg3, Node* arg4, Node* const* inputs) {
size_t result_size) { // 2 is for target and context.
CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( DCHECK_LE(2, input_count);
isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), int argc = input_count - 2;
DCHECK_LE(descriptor.GetParameterCount(), argc);
// Extra arguments not mentioned in the descriptor are passed on the stack.
int stack_parameter_count = argc - descriptor.GetRegisterParameterCount();
DCHECK_LE(descriptor.GetStackParameterCount(), stack_parameter_count);
CallDescriptor* desc = Linkage::GetStubCallDescriptor(
isolate(), zone(), descriptor, stack_parameter_count,
CallDescriptor::kNoFlags, Operator::kNoProperties, CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size); MachineType::AnyTagged(), result_size);
Node** args = zone()->NewArray<Node*>(5); CallPrologue();
args[0] = arg1; Node* return_value = raw_assembler()->CallN(desc, input_count, inputs);
args[1] = arg2; CallEpilogue();
args[2] = arg3; return return_value;
args[3] = arg4;
args[4] = context;
return CallN(call_descriptor, target, args);
} }
Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor,
Node* target, Node* context, Node* arg1,
Node* arg2, Node* arg3, Node* arg4, Node* arg5,
size_t result_size) {
CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
isolate(), zone(), descriptor, descriptor.GetStackParameterCount(),
CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size);
Node** args = zone()->NewArray<Node*>(6);
args[0] = arg1;
args[1] = arg2;
args[2] = arg3;
args[3] = arg4;
args[4] = arg5;
args[5] = context;
return CallN(call_descriptor, target, args);
}
Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor, Node* CodeAssembler::CallStub(const CallInterfaceDescriptor& descriptor,
Node* target, Node* context, const Arg& arg1, Node* target, Node* context, const Arg& arg1,
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
// Do not include anything from src/compiler here! // Do not include anything from src/compiler here!
#include "src/allocation.h" #include "src/allocation.h"
#include "src/builtins/builtins.h" #include "src/builtins/builtins.h"
#include "src/code-factory.h"
#include "src/globals.h" #include "src/globals.h"
#include "src/heap/heap.h" #include "src/heap/heap.h"
#include "src/machine-type.h" #include "src/machine-type.h"
...@@ -316,32 +317,24 @@ class V8_EXPORT_PRIVATE CodeAssembler { ...@@ -316,32 +317,24 @@ class V8_EXPORT_PRIVATE CodeAssembler {
Node* const value; Node* const value;
}; };
Node* CallStub(Callable const& callable, Node* context, Node* arg1, template <class... TArgs>
size_t result_size = 1); Node* CallStub(Callable const& callable, Node* context, TArgs... args) {
Node* CallStub(Callable const& callable, Node* context, Node* arg1, Node* target = HeapConstant(callable.code());
Node* arg2, size_t result_size = 1); return CallStub(callable.descriptor(), target, context, args...);
Node* CallStub(Callable const& callable, Node* context, Node* arg1, }
Node* arg2, Node* arg3, size_t result_size = 1);
Node* CallStub(Callable const& callable, Node* context, Node* arg1,
Node* arg2, Node* arg3, Node* arg4, size_t result_size = 1);
Node* CallStubN(Callable const& callable, Node** args,
size_t result_size = 1);
template <class... TArgs>
Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target, Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target,
Node* context, size_t result_size = 1); Node* context, TArgs... args) {
Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target, return CallStubR(descriptor, 1, target, context, args...);
Node* context, Node* arg1, size_t result_size = 1); }
Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target,
Node* context, Node* arg1, Node* arg2, size_t result_size = 1); template <class... TArgs>
Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target, Node* CallStubR(const CallInterfaceDescriptor& descriptor, size_t result_size,
Node* context, Node* arg1, Node* arg2, Node* arg3, Node* target, Node* context, TArgs... args);
size_t result_size = 1);
Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target, Node* CallStubN(const CallInterfaceDescriptor& descriptor, size_t result_size,
Node* context, Node* arg1, Node* arg2, Node* arg3, Node* arg4, int input_count, Node* const* inputs);
size_t result_size = 1);
Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target,
Node* context, Node* arg1, Node* arg2, Node* arg3, Node* arg4,
Node* arg5, size_t result_size = 1);
Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target, Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target,
Node* context, const Arg& arg1, const Arg& arg2, Node* context, const Arg& arg1, const Arg& arg2,
......
...@@ -192,23 +192,13 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::Call( ...@@ -192,23 +192,13 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::Call(
Node* context = assembler_->Parameter(kContextParameter); Node* context = assembler_->Parameter(kContextParameter);
Node* target = assembler_->HeapConstant(stub.GetCode()); Node* target = assembler_->HeapConstant(stub.GetCode());
int param_count = descriptor.GetParameterCount(); Node* call = assembler_->CallStub(
Node** args = zone()->NewArray<Node*>(param_count + 1 + kJSParameterCount); descriptor, target, context,
// Stub/register parameters: assembler_->UndefinedConstant(), // callee (there's no JSFunction)
args[0] = assembler_->UndefinedConstant(); // callee (there's no JSFunction) assembler_->UndefinedConstant(), // call_data (undefined)
args[1] = assembler_->UndefinedConstant(); // call_data (undefined) assembler_->Parameter(0), // receiver (same as holder in this case)
args[2] = assembler_->Parameter(0); // receiver (same as holder in this case) assembler_->ExternalConstant(callback), // API callback function
args[3] = assembler_->ExternalConstant(callback); // API callback function FromId(arg)); // JS argument, on stack
// JS arguments, on stack:
args[4] = FromId(arg);
// Context.
args[5] = context;
Node* call =
assembler_->CallStubN(descriptor, kJSParameterCount, target, args);
return FromRaw(call); return FromRaw(call);
} }
......
...@@ -847,8 +847,8 @@ Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, ...@@ -847,8 +847,8 @@ Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context,
Load(MachineType::Pointer(), function, Load(MachineType::Pointer(), function,
IntPtrConstant(offsetof(Runtime::Function, entry))); IntPtrConstant(offsetof(Runtime::Function, entry)));
return CallStub(callable.descriptor(), code_target, context, arg_count, return CallStubR(callable.descriptor(), result_size, code_target, context,
first_arg, function_entry, result_size); arg_count, first_arg, function_entry);
} }
void InterpreterAssembler::UpdateInterruptBudget(Node* weight) { void InterpreterAssembler::UpdateInterruptBudget(Node* weight) {
......
...@@ -222,14 +222,16 @@ Node* IntrinsicsHelper::IsSmi(Node* input, Node* arg_count, Node* context) { ...@@ -222,14 +222,16 @@ Node* IntrinsicsHelper::IsSmi(Node* input, Node* arg_count, Node* context) {
Node* IntrinsicsHelper::IntrinsicAsStubCall(Node* args_reg, Node* context, Node* IntrinsicsHelper::IntrinsicAsStubCall(Node* args_reg, Node* context,
Callable const& callable) { Callable const& callable) {
int param_count = callable.descriptor().GetParameterCount(); int param_count = callable.descriptor().GetParameterCount();
Node** args = zone()->NewArray<Node*>(param_count + 1); // 1 for context int input_count = param_count + 2; // +2 for target and context
Node** args = zone()->NewArray<Node*>(input_count);
int index = 0;
args[index++] = __ HeapConstant(callable.code());
for (int i = 0; i < param_count; i++) { for (int i = 0; i < param_count; i++) {
args[i] = __ LoadRegister(args_reg); args[index++] = __ LoadRegister(args_reg);
args_reg = __ NextRegister(args_reg); args_reg = __ NextRegister(args_reg);
} }
args[param_count] = context; args[index++] = context;
return __ CallStubN(callable.descriptor(), 1, input_count, args);
return __ CallStubN(callable, args);
} }
Node* IntrinsicsHelper::HasProperty(Node* input, Node* arg_count, Node* IntrinsicsHelper::HasProperty(Node* input, Node* arg_count,
......
...@@ -1357,9 +1357,9 @@ void Interpreter::DoAddSmi(InterpreterAssembler* assembler) { ...@@ -1357,9 +1357,9 @@ void Interpreter::DoAddSmi(InterpreterAssembler* assembler) {
AddWithFeedbackStub stub(__ isolate()); AddWithFeedbackStub stub(__ isolate());
Callable callable = Callable callable =
Callable(stub.GetCode(), AddWithFeedbackStub::Descriptor(__ isolate())); Callable(stub.GetCode(), AddWithFeedbackStub::Descriptor(__ isolate()));
Node* args[] = {left, right, __ TruncateWordToWord32(slot_index), var_result.Bind(__ CallStub(callable, context, left, right,
type_feedback_vector, context}; __ TruncateWordToWord32(slot_index),
var_result.Bind(__ CallStubN(callable, args, 1)); type_feedback_vector));
__ Goto(&end); __ Goto(&end);
} }
__ Bind(&end); __ Bind(&end);
...@@ -1411,9 +1411,9 @@ void Interpreter::DoSubSmi(InterpreterAssembler* assembler) { ...@@ -1411,9 +1411,9 @@ void Interpreter::DoSubSmi(InterpreterAssembler* assembler) {
SubtractWithFeedbackStub stub(__ isolate()); SubtractWithFeedbackStub stub(__ isolate());
Callable callable = Callable( Callable callable = Callable(
stub.GetCode(), SubtractWithFeedbackStub::Descriptor(__ isolate())); stub.GetCode(), SubtractWithFeedbackStub::Descriptor(__ isolate()));
Node* args[] = {left, right, __ TruncateWordToWord32(slot_index), var_result.Bind(__ CallStub(callable, context, left, right,
type_feedback_vector, context}; __ TruncateWordToWord32(slot_index),
var_result.Bind(__ CallStubN(callable, args, 1)); type_feedback_vector));
__ Goto(&end); __ Goto(&end);
} }
__ Bind(&end); __ Bind(&end);
......
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