1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "test/cctest/compiler/simplified-graph-builder.h"
7 #include "src/compiler/operator-properties.h"
13 SimplifiedGraphBuilder::SimplifiedGraphBuilder(
14 Isolate* isolate, Graph* graph, CommonOperatorBuilder* common,
15 MachineOperatorBuilder* machine, SimplifiedOperatorBuilder* simplified)
16 : GraphBuilder(isolate, graph),
21 simplified_(simplified) {}
24 void SimplifiedGraphBuilder::Begin(int num_parameters) {
25 DCHECK(graph()->start() == NULL);
26 Node* start = graph()->NewNode(common()->Start(num_parameters));
27 graph()->SetStart(start);
32 void SimplifiedGraphBuilder::Return(Node* value) {
34 graph()->NewNode(common()->Return(), value, effect_, graph()->start());
39 void SimplifiedGraphBuilder::End() {
40 Node* end = graph()->NewNode(common()->End(), return_);
45 Node* SimplifiedGraphBuilder::MakeNode(const Operator* op,
46 int value_input_count,
47 Node** value_inputs, bool incomplete) {
48 DCHECK(op->ValueInputCount() == value_input_count);
50 DCHECK(!OperatorProperties::HasContextInput(op));
51 DCHECK(!OperatorProperties::HasFrameStateInput(op));
52 bool has_control = op->ControlInputCount() == 1;
53 bool has_effect = op->EffectInputCount() == 1;
55 DCHECK(op->ControlInputCount() < 2);
56 DCHECK(op->EffectInputCount() < 2);
59 if (!has_control && !has_effect) {
60 result = graph()->NewNode(op, value_input_count, value_inputs, incomplete);
62 int input_count_with_deps = value_input_count;
63 if (has_control) ++input_count_with_deps;
64 if (has_effect) ++input_count_with_deps;
65 Node** buffer = zone()->NewArray<Node*>(input_count_with_deps);
66 memcpy(buffer, value_inputs, kPointerSize * value_input_count);
67 Node** current_input = buffer + value_input_count;
69 *current_input++ = effect_;
72 *current_input++ = graph()->start();
74 result = graph()->NewNode(op, input_count_with_deps, buffer, incomplete);
78 // This graph builder does not support control flow.
79 CHECK_EQ(0, op->ControlOutputCount());
85 } // namespace compiler
86 } // namespace internal