v8/test/cctest/compiler/simplified-graph-builder.cc
danno@chromium.org 16928e28d7 [turbofan] Reduce memory consumption of graph building
Allow reservation of additional input capacity when creating nodes to prevent switching to deque representation when adding well-known additional inputs.

Also ensure that only a single temporary buffer is used to create temporary input arrays before allocating nodes.

R=mstarzinger@chromium.org

Review URL: https://codereview.chromium.org/644083003

Cr-Commit-Position: refs/heads/master@{#24896}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24896 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-10-27 10:12:40 +00:00

91 lines
2.7 KiB
C++

// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "test/cctest/compiler/simplified-graph-builder.h"
#include "src/compiler/operator-properties.h"
#include "src/compiler/operator-properties-inl.h"
namespace v8 {
namespace internal {
namespace compiler {
SimplifiedGraphBuilder::SimplifiedGraphBuilder(
Graph* graph, CommonOperatorBuilder* common,
MachineOperatorBuilder* machine, SimplifiedOperatorBuilder* simplified)
: GraphBuilder(graph),
effect_(NULL),
return_(NULL),
common_(common),
machine_(machine),
simplified_(simplified) {}
void SimplifiedGraphBuilder::Begin(int num_parameters) {
DCHECK(graph()->start() == NULL);
Node* start = graph()->NewNode(common()->Start(num_parameters));
graph()->SetStart(start);
effect_ = start;
}
void SimplifiedGraphBuilder::Return(Node* value) {
return_ =
graph()->NewNode(common()->Return(), value, effect_, graph()->start());
effect_ = NULL;
}
void SimplifiedGraphBuilder::End() {
Node* end = graph()->NewNode(common()->End(), return_);
graph()->SetEnd(end);
}
Node* SimplifiedGraphBuilder::MakeNode(const Operator* op,
int value_input_count,
Node** value_inputs, bool incomplete) {
DCHECK(op->InputCount() == value_input_count);
DCHECK(!OperatorProperties::HasContextInput(op));
DCHECK(!OperatorProperties::HasFrameStateInput(op));
bool has_control = OperatorProperties::GetControlInputCount(op) == 1;
bool has_effect = OperatorProperties::GetEffectInputCount(op) == 1;
DCHECK(OperatorProperties::GetControlInputCount(op) < 2);
DCHECK(OperatorProperties::GetEffectInputCount(op) < 2);
Node* result = NULL;
if (!has_control && !has_effect) {
result = graph()->NewNode(op, value_input_count, value_inputs, incomplete);
} else {
int input_count_with_deps = value_input_count;
if (has_control) ++input_count_with_deps;
if (has_effect) ++input_count_with_deps;
Node** buffer = zone()->NewArray<Node*>(input_count_with_deps);
memcpy(buffer, value_inputs, kPointerSize * value_input_count);
Node** current_input = buffer + value_input_count;
if (has_effect) {
*current_input++ = effect_;
}
if (has_control) {
*current_input++ = graph()->start();
}
result = graph()->NewNode(op, input_count_with_deps, buffer, incomplete);
if (has_effect) {
effect_ = result;
}
if (OperatorProperties::HasControlOutput(result->op())) {
// This graph builder does not support control flow.
UNREACHABLE();
}
}
return result;
}
} // namespace compiler
} // namespace internal
} // namespace v8