Commit 52702e55 authored by ishell's avatar ishell Committed by Commit bot

[turbofan] Avoid allocation of temporary array of Nodes when generating calls.

BUG=

Review-Url: https://codereview.chromium.org/2586903002
Cr-Commit-Position: refs/heads/master@{#41798}
parent 039e29f7
......@@ -170,40 +170,21 @@ void RawMachineAssembler::Comment(const char* msg) {
AddNode(machine()->Comment(msg));
}
Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function,
Node** args) {
int param_count = static_cast<int>(desc->ParameterCount());
int input_count = param_count + 1;
Node** buffer = zone()->NewArray<Node*>(input_count);
int index = 0;
buffer[index++] = function;
for (int i = 0; i < param_count; i++) {
buffer[index++] = args[i];
}
return AddNode(common()->Call(desc), input_count, buffer);
}
Node* RawMachineAssembler::CallN(CallDescriptor* desc, int input_count,
Node* const* nodes) {
Node* const* inputs) {
DCHECK(!desc->NeedsFrameState());
// +1 is for target.
DCHECK_EQ(input_count, desc->ParameterCount() + 1);
return AddNode(common()->Call(desc), input_count, nodes);
return AddNode(common()->Call(desc), input_count, inputs);
}
Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc,
Node* function, Node** args,
Node* frame_state) {
int input_count,
Node* const* inputs) {
DCHECK(desc->NeedsFrameState());
int param_count = static_cast<int>(desc->ParameterCount());
int input_count = param_count + 2;
Node** buffer = zone()->NewArray<Node*>(input_count);
int index = 0;
buffer[index++] = function;
for (int i = 0; i < param_count; i++) {
buffer[index++] = args[i];
}
buffer[index++] = frame_state;
return AddNode(common()->Call(desc), input_count, buffer);
// +2 is for target and frame state.
DCHECK_EQ(input_count, desc->ParameterCount() + 2);
return AddNode(common()->Call(desc), input_count, inputs);
}
Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, int input_count,
......
......@@ -700,16 +700,15 @@ class V8_EXPORT_PRIVATE RawMachineAssembler {
return HeapConstant(isolate()->factory()->InternalizeUtf8String(string));
}
// Call a given call descriptor and the given arguments.
Node* CallN(CallDescriptor* desc, Node* function, Node** args);
// Call a given call descriptor and the given arguments and frame-state.
Node* CallNWithFrameState(CallDescriptor* desc, Node* function, Node** args,
Node* frame_state);
// 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);
// Call a given call descriptor and the given arguments and frame-state.
// The call target and frame state are passed as part of the {inputs} array.
Node* CallNWithFrameState(CallDescriptor* desc, int input_count,
Node* const* inputs);
// 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);
......
......@@ -458,12 +458,14 @@ class Computer {
CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig);
RawMachineAssembler raw(isolate, &graph, cdesc);
Node* target = raw.HeapConstant(inner);
Node** args = zone.NewArray<Node*>(num_params);
Node** inputs = zone.NewArray<Node*>(num_params + 1);
int input_count = 0;
inputs[input_count++] = target;
for (int i = 0; i < num_params; i++) {
args[i] = io.MakeConstant(raw, io.input[i]);
inputs[input_count++] = io.MakeConstant(raw, io.input[i]);
}
Node* call = raw.CallN(desc, target, args);
Node* call = raw.CallN(desc, input_count, inputs);
Node* store = io.StoreOutput(raw, call);
USE(store);
raw.Return(raw.Int32Constant(seed));
......@@ -491,12 +493,14 @@ class Computer {
RawMachineAssembler raw(isolate, &graph, cdesc);
Node* base = raw.PointerConstant(io.input);
Node* target = raw.HeapConstant(inner);
Node** args = zone.NewArray<Node*>(kMaxParamCount);
Node** inputs = zone.NewArray<Node*>(kMaxParamCount + 1);
int input_count = 0;
inputs[input_count++] = target;
for (int i = 0; i < num_params; i++) {
args[i] = io.LoadInput(raw, base, i);
inputs[input_count++] = io.LoadInput(raw, base, i);
}
Node* call = raw.CallN(desc, target, args);
Node* call = raw.CallN(desc, input_count, inputs);
Node* store = io.StoreOutput(raw, call);
USE(store);
raw.Return(raw.Int32Constant(seed));
......@@ -588,13 +592,15 @@ static void CopyTwentyInt32(CallDescriptor* desc) {
RawMachineAssembler raw(isolate, &graph, cdesc);
Node* base = raw.PointerConstant(input);
Node* target = raw.HeapConstant(inner);
Node** args = zone.NewArray<Node*>(kNumParams);
Node** inputs = zone.NewArray<Node*>(kNumParams + 1);
int input_count = 0;
inputs[input_count++] = target;
for (int i = 0; i < kNumParams; i++) {
Node* offset = raw.Int32Constant(i * sizeof(int32_t));
args[i] = raw.Load(MachineType::Int32(), base, offset);
inputs[input_count++] = raw.Load(MachineType::Int32(), base, offset);
}
Node* call = raw.CallN(desc, target, args);
Node* call = raw.CallN(desc, input_count, inputs);
raw.Return(call);
wrapper =
CompileGraph("CopyTwentyInt32-wrapper", cdesc, &graph, raw.Export());
......@@ -970,12 +976,14 @@ static void Build_Select_With_Call(CallDescriptor* desc,
{
// Build a call to the function that does the select.
Node* target = raw.HeapConstant(inner);
Node** args = raw.zone()->NewArray<Node*>(num_params);
Node** inputs = raw.zone()->NewArray<Node*>(num_params + 1);
int input_count = 0;
inputs[input_count++] = target;
for (int i = 0; i < num_params; i++) {
args[i] = raw.Parameter(i);
inputs[input_count++] = raw.Parameter(i);
}
Node* call = raw.CallN(desc, target, args);
Node* call = raw.CallN(desc, input_count, inputs);
raw.Return(call);
}
}
......@@ -1075,7 +1083,9 @@ void MixedParamTest(int start) {
CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig);
RawMachineAssembler raw(isolate, &graph, cdesc);
Node* target = raw.HeapConstant(select);
Node** args = zone.NewArray<Node*>(num_params);
Node** inputs = zone.NewArray<Node*>(num_params + 1);
int input_count = 0;
inputs[input_count++] = target;
int64_t constant = 0x0102030405060708;
for (int i = 0; i < num_params; i++) {
MachineType param_type = sig->GetParam(i);
......@@ -1102,11 +1112,11 @@ void MixedParamTest(int start) {
}
CHECK_NOT_NULL(konst);
args[i] = konst;
inputs[input_count++] = konst;
constant += 0x1010101010101010;
}
Node* call = raw.CallN(desc, target, args);
Node* call = raw.CallN(desc, input_count, inputs);
Node* store =
raw.StoreToPointer(output, sig->GetReturn().representation(), call);
USE(store);
......@@ -1178,14 +1188,16 @@ void TestStackSlot(MachineType slot_type, T expected) {
BufferedRawMachineAssemblerTester<T> f(slot_type);
Node* target = f.HeapConstant(inner);
Node* stack_slot = f.StackSlot(slot_type.representation());
Node* args[12];
Node* nodes[14];
int input_count = 0;
nodes[input_count++] = target;
for (int i = 0; i < 10; i++) {
args[i] = f.Int32Constant(i);
nodes[input_count++] = f.Int32Constant(i);
}
args[10] = f.Parameter(0);
args[11] = stack_slot;
nodes[input_count++] = f.Parameter(0);
nodes[input_count++] = stack_slot;
f.CallN(desc, target, args);
f.CallN(desc, input_count, nodes);
f.Return(f.Load(slot_type, stack_slot, f.IntPtrConstant(0)));
CHECK_EQ(expected, f.Call(expected));
......
......@@ -376,9 +376,9 @@ TARGET_TEST_F(InstructionSelectorTest, CallJSFunctionWithDeopt) {
m.UndefinedConstant());
// Build the call.
Node* args[] = {receiver, m.UndefinedConstant(), m.Int32Constant(1), context};
Node* call =
m.CallNWithFrameState(descriptor, function_node, args, state_node);
Node* nodes[] = {function_node, receiver, m.UndefinedConstant(),
m.Int32Constant(1), context, state_node};
Node* call = m.CallNWithFrameState(descriptor, arraysize(nodes), nodes);
m.Return(call);
Stream s = m.Build(kAllExceptNopInstructions);
......@@ -433,9 +433,9 @@ TARGET_TEST_F(InstructionSelectorTest, CallStubWithDeopt) {
m.UndefinedConstant());
// Build the call.
Node* args[] = {function_node, receiver, context};
Node* stub_code = m.HeapConstant(callable.code());
Node* call = m.CallNWithFrameState(descriptor, stub_code, args, state_node);
Node* nodes[] = {stub_code, function_node, receiver, context, state_node};
Node* call = m.CallNWithFrameState(descriptor, arraysize(nodes), nodes);
m.Return(call);
Stream s = m.Build(kAllExceptNopInstructions);
......@@ -537,9 +537,9 @@ TARGET_TEST_F(InstructionSelectorTest, CallStubWithDeoptRecursiveFrameState) {
frame_state_parent);
// Build the call.
Node* args[] = {function_node, receiver, context2};
Node* stub_code = m.HeapConstant(callable.code());
Node* call = m.CallNWithFrameState(descriptor, stub_code, args, state_node);
Node* nodes[] = {stub_code, function_node, receiver, context2, state_node};
Node* call = m.CallNWithFrameState(descriptor, arraysize(nodes), nodes);
m.Return(call);
Stream s = m.Build(kAllExceptNopInstructions);
......
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