OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "test/cctest/compiler/simplified-graph-builder.h" | 5 #include "test/cctest/compiler/simplified-graph-builder.h" |
6 | 6 |
| 7 #include "src/compiler/operator-properties.h" |
| 8 #include "src/compiler/operator-properties-inl.h" |
| 9 |
7 namespace v8 { | 10 namespace v8 { |
8 namespace internal { | 11 namespace internal { |
9 namespace compiler { | 12 namespace compiler { |
10 | 13 |
11 SimplifiedGraphBuilder::SimplifiedGraphBuilder( | 14 SimplifiedGraphBuilder::SimplifiedGraphBuilder( |
12 Graph* graph, CommonOperatorBuilder* common, | 15 Graph* graph, CommonOperatorBuilder* common, |
13 MachineOperatorBuilder* machine, SimplifiedOperatorBuilder* simplified) | 16 MachineOperatorBuilder* machine, SimplifiedOperatorBuilder* simplified) |
14 : StructuredGraphBuilder(graph, common), | 17 : GraphBuilder(graph), |
| 18 effect_(NULL), |
| 19 return_(NULL), |
| 20 common_(common), |
15 machine_(machine), | 21 machine_(machine), |
16 simplified_(simplified) {} | 22 simplified_(simplified) {} |
17 | 23 |
18 | 24 |
19 void SimplifiedGraphBuilder::Begin(int num_parameters) { | 25 void SimplifiedGraphBuilder::Begin(int num_parameters) { |
20 DCHECK(graph()->start() == NULL); | 26 DCHECK(graph()->start() == NULL); |
21 Node* start = graph()->NewNode(common()->Start(num_parameters)); | 27 Node* start = graph()->NewNode(common()->Start(num_parameters)); |
22 graph()->SetStart(start); | 28 graph()->SetStart(start); |
23 set_environment(new (zone()) Environment(this, start)); | 29 effect_ = start; |
24 } | 30 } |
25 | 31 |
26 | 32 |
27 void SimplifiedGraphBuilder::Return(Node* value) { | 33 void SimplifiedGraphBuilder::Return(Node* value) { |
28 Node* control = NewNode(common()->Return(), value); | 34 return_ = |
29 UpdateControlDependencyToLeaveFunction(control); | 35 graph()->NewNode(common()->Return(), value, effect_, graph()->start()); |
| 36 effect_ = NULL; |
30 } | 37 } |
31 | 38 |
32 | 39 |
33 void SimplifiedGraphBuilder::End() { | 40 void SimplifiedGraphBuilder::End() { |
34 environment()->UpdateControlDependency(exit_control()); | 41 Node* end = graph()->NewNode(common()->End(), return_); |
35 graph()->SetEnd(NewNode(common()->End())); | 42 graph()->SetEnd(end); |
36 } | 43 } |
37 | 44 |
38 | 45 |
39 SimplifiedGraphBuilder::Environment::Environment( | 46 Node* SimplifiedGraphBuilder::MakeNode(Operator* op, int value_input_count, |
40 SimplifiedGraphBuilder* builder, Node* control_dependency) | 47 Node** value_inputs) { |
41 : StructuredGraphBuilder::Environment(builder, control_dependency) {} | 48 DCHECK(op->InputCount() == value_input_count); |
42 | 49 |
| 50 DCHECK(!OperatorProperties::HasContextInput(op)); |
| 51 DCHECK(!OperatorProperties::HasFrameStateInput(op)); |
| 52 bool has_control = OperatorProperties::GetControlInputCount(op) == 1; |
| 53 bool has_effect = OperatorProperties::GetEffectInputCount(op) == 1; |
43 | 54 |
44 Node* SimplifiedGraphBuilder::Environment::Top() { | 55 DCHECK(OperatorProperties::GetControlInputCount(op) < 2); |
45 DCHECK(!values()->empty()); | 56 DCHECK(OperatorProperties::GetEffectInputCount(op) < 2); |
46 return values()->back(); | |
47 } | |
48 | 57 |
| 58 Node* result = NULL; |
| 59 if (!has_control && !has_effect) { |
| 60 result = graph()->NewNode(op, value_input_count, value_inputs); |
| 61 } else { |
| 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; |
| 68 if (has_effect) { |
| 69 *current_input++ = effect_; |
| 70 } |
| 71 if (has_control) { |
| 72 *current_input++ = graph()->start(); |
| 73 } |
| 74 result = graph()->NewNode(op, input_count_with_deps, buffer); |
| 75 if (has_effect) { |
| 76 effect_ = result; |
| 77 } |
| 78 if (OperatorProperties::HasControlOutput(result->op())) { |
| 79 // This graph builder does not support control flow. |
| 80 UNREACHABLE(); |
| 81 } |
| 82 } |
49 | 83 |
50 void SimplifiedGraphBuilder::Environment::Push(Node* node) { | 84 return result; |
51 values()->push_back(node); | |
52 } | |
53 | |
54 | |
55 Node* SimplifiedGraphBuilder::Environment::Pop() { | |
56 DCHECK(!values()->empty()); | |
57 Node* back = values()->back(); | |
58 values()->pop_back(); | |
59 return back; | |
60 } | |
61 | |
62 | |
63 void SimplifiedGraphBuilder::Environment::Poke(size_t depth, Node* node) { | |
64 DCHECK(depth < values()->size()); | |
65 size_t index = values()->size() - depth - 1; | |
66 values()->at(index) = node; | |
67 } | |
68 | |
69 | |
70 Node* SimplifiedGraphBuilder::Environment::Peek(size_t depth) { | |
71 DCHECK(depth < values()->size()); | |
72 size_t index = values()->size() - depth - 1; | |
73 return values()->at(index); | |
74 } | 85 } |
75 | 86 |
76 } // namespace compiler | 87 } // namespace compiler |
77 } // namespace internal | 88 } // namespace internal |
78 } // namespace v8 | 89 } // namespace v8 |
OLD | NEW |