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