OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef V8_COMPILER_GRAPH_BUILDER_H_ | 5 #ifndef V8_COMPILER_GRAPH_BUILDER_H_ |
6 #define V8_COMPILER_GRAPH_BUILDER_H_ | 6 #define V8_COMPILER_GRAPH_BUILDER_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
11 #include "src/compiler/common-operator.h" | 11 #include "src/compiler/common-operator.h" |
12 #include "src/compiler/graph.h" | 12 #include "src/compiler/graph.h" |
13 #include "src/unique.h" | 13 #include "src/unique.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 namespace compiler { | 17 namespace compiler { |
18 | 18 |
19 class Node; | 19 class Node; |
20 | 20 |
21 // A common base class for anything that creates nodes in a graph. | 21 // A common base class for anything that creates nodes in a graph. |
22 class GraphBuilder { | 22 class GraphBuilder { |
23 public: | 23 public: |
24 explicit GraphBuilder(Graph* graph) : graph_(graph) {} | 24 explicit GraphBuilder(Graph* graph) : graph_(graph) {} |
25 virtual ~GraphBuilder() {} | 25 virtual ~GraphBuilder() {} |
26 | 26 |
27 Node* NewNode(const Operator* op) { | 27 Node* NewNode(const Operator* op, bool incomplete = false) { |
28 return MakeNode(op, 0, static_cast<Node**>(NULL)); | 28 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); |
29 } | 29 } |
30 | 30 |
31 Node* NewNode(const Operator* op, Node* n1) { return MakeNode(op, 1, &n1); } | 31 Node* NewNode(const Operator* op, Node* n1) { |
| 32 return MakeNode(op, 1, &n1, false); |
| 33 } |
32 | 34 |
33 Node* NewNode(const Operator* op, Node* n1, Node* n2) { | 35 Node* NewNode(const Operator* op, Node* n1, Node* n2) { |
34 Node* buffer[] = {n1, n2}; | 36 Node* buffer[] = {n1, n2}; |
35 return MakeNode(op, arraysize(buffer), buffer); | 37 return MakeNode(op, arraysize(buffer), buffer, false); |
36 } | 38 } |
37 | 39 |
38 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3) { | 40 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3) { |
39 Node* buffer[] = {n1, n2, n3}; | 41 Node* buffer[] = {n1, n2, n3}; |
40 return MakeNode(op, arraysize(buffer), buffer); | 42 return MakeNode(op, arraysize(buffer), buffer, false); |
41 } | 43 } |
42 | 44 |
43 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) { | 45 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) { |
44 Node* buffer[] = {n1, n2, n3, n4}; | 46 Node* buffer[] = {n1, n2, n3, n4}; |
45 return MakeNode(op, arraysize(buffer), buffer); | 47 return MakeNode(op, arraysize(buffer), buffer, false); |
46 } | 48 } |
47 | 49 |
48 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, | 50 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, |
49 Node* n5) { | 51 Node* n5) { |
50 Node* buffer[] = {n1, n2, n3, n4, n5}; | 52 Node* buffer[] = {n1, n2, n3, n4, n5}; |
51 return MakeNode(op, arraysize(buffer), buffer); | 53 return MakeNode(op, arraysize(buffer), buffer, false); |
52 } | 54 } |
53 | 55 |
54 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, | 56 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, |
55 Node* n5, Node* n6) { | 57 Node* n5, Node* n6) { |
56 Node* nodes[] = {n1, n2, n3, n4, n5, n6}; | 58 Node* nodes[] = {n1, n2, n3, n4, n5, n6}; |
57 return MakeNode(op, arraysize(nodes), nodes); | 59 return MakeNode(op, arraysize(nodes), nodes, false); |
58 } | 60 } |
59 | 61 |
60 Node* NewNode(const Operator* op, int value_input_count, | 62 Node* NewNode(const Operator* op, int value_input_count, Node** value_inputs, |
61 Node** value_inputs) { | 63 bool incomplete = false) { |
62 return MakeNode(op, value_input_count, value_inputs); | 64 return MakeNode(op, value_input_count, value_inputs, incomplete); |
63 } | 65 } |
64 | 66 |
65 Graph* graph() const { return graph_; } | 67 Graph* graph() const { return graph_; } |
66 | 68 |
67 protected: | 69 protected: |
68 // Base implementation used by all factory methods. | 70 // Base implementation used by all factory methods. |
69 virtual Node* MakeNode(const Operator* op, int value_input_count, | 71 virtual Node* MakeNode(const Operator* op, int value_input_count, |
70 Node** value_inputs) = 0; | 72 Node** value_inputs, bool incomplete) = 0; |
71 | 73 |
72 private: | 74 private: |
73 Graph* graph_; | 75 Graph* graph_; |
74 }; | 76 }; |
75 | 77 |
76 | 78 |
77 // The StructuredGraphBuilder produces a high-level IR graph. It is used as the | 79 // The StructuredGraphBuilder produces a high-level IR graph. It is used as the |
78 // base class for concrete implementations (e.g the AstGraphBuilder or the | 80 // base class for concrete implementations (e.g the AstGraphBuilder or the |
79 // StubGraphBuilder). | 81 // StubGraphBuilder). |
80 class StructuredGraphBuilder : public GraphBuilder { | 82 class StructuredGraphBuilder : public GraphBuilder { |
81 public: | 83 public: |
82 StructuredGraphBuilder(Graph* graph, CommonOperatorBuilder* common); | 84 StructuredGraphBuilder(Graph* graph, CommonOperatorBuilder* common); |
83 virtual ~StructuredGraphBuilder() {} | 85 virtual ~StructuredGraphBuilder() {} |
84 | 86 |
85 // Creates a new Phi node having {count} input values. | 87 // Creates a new Phi node having {count} input values. |
86 Node* NewPhi(int count, Node* input, Node* control); | 88 Node* NewPhi(int count, Node* input, Node* control); |
87 Node* NewEffectPhi(int count, Node* input, Node* control); | 89 Node* NewEffectPhi(int count, Node* input, Node* control); |
88 | 90 |
89 // Helpers for merging control, effect or value dependencies. | 91 // Helpers for merging control, effect or value dependencies. |
90 Node* MergeControl(Node* control, Node* other); | 92 Node* MergeControl(Node* control, Node* other); |
91 Node* MergeEffect(Node* value, Node* other, Node* control); | 93 Node* MergeEffect(Node* value, Node* other, Node* control); |
92 Node* MergeValue(Node* value, Node* other, Node* control); | 94 Node* MergeValue(Node* value, Node* other, Node* control); |
93 | 95 |
94 // Helpers to create new control nodes. | 96 // Helpers to create new control nodes. |
95 Node* NewIfTrue() { return NewNode(common()->IfTrue()); } | 97 Node* NewIfTrue() { return NewNode(common()->IfTrue()); } |
96 Node* NewIfFalse() { return NewNode(common()->IfFalse()); } | 98 Node* NewIfFalse() { return NewNode(common()->IfFalse()); } |
97 Node* NewMerge() { return NewNode(common()->Merge(1)); } | 99 Node* NewMerge() { return NewNode(common()->Merge(1), true); } |
98 Node* NewLoop() { return NewNode(common()->Loop(1)); } | 100 Node* NewLoop() { return NewNode(common()->Loop(1), true); } |
99 Node* NewBranch(Node* condition) { | 101 Node* NewBranch(Node* condition) { |
100 return NewNode(common()->Branch(), condition); | 102 return NewNode(common()->Branch(), condition); |
101 } | 103 } |
102 | 104 |
103 protected: | 105 protected: |
104 class Environment; | 106 class Environment; |
105 friend class Environment; | 107 friend class Environment; |
106 friend class ControlBuilder; | 108 friend class ControlBuilder; |
107 | 109 |
108 // The following method creates a new node having the specified operator and | 110 // The following method creates a new node having the specified operator and |
109 // ensures effect and control dependencies are wired up. The dependencies | 111 // ensures effect and control dependencies are wired up. The dependencies |
110 // tracked by the environment might be mutated. | 112 // tracked by the environment might be mutated. |
111 virtual Node* MakeNode(const Operator* op, int value_input_count, | 113 virtual Node* MakeNode(const Operator* op, int value_input_count, |
112 Node** value_inputs) FINAL; | 114 Node** value_inputs, bool incomplete) FINAL; |
113 | 115 |
114 Environment* environment() const { return environment_; } | 116 Environment* environment() const { return environment_; } |
115 void set_environment(Environment* env) { environment_ = env; } | 117 void set_environment(Environment* env) { environment_ = env; } |
116 | 118 |
117 Node* current_context() const { return current_context_; } | 119 Node* current_context() const { return current_context_; } |
118 void set_current_context(Node* context) { current_context_ = context; } | 120 void set_current_context(Node* context) { current_context_ = context; } |
119 | 121 |
120 Node* exit_control() const { return exit_control_; } | 122 Node* exit_control() const { return exit_control_; } |
121 void set_exit_control(Node* node) { exit_control_ = node; } | 123 void set_exit_control(Node* node) { exit_control_ = node; } |
122 | 124 |
(...skipping 17 matching lines...) Expand all Loading... |
140 // Helper to indicate a node exits the function body. | 142 // Helper to indicate a node exits the function body. |
141 void UpdateControlDependencyToLeaveFunction(Node* exit); | 143 void UpdateControlDependencyToLeaveFunction(Node* exit); |
142 | 144 |
143 private: | 145 private: |
144 CommonOperatorBuilder* common_; | 146 CommonOperatorBuilder* common_; |
145 Environment* environment_; | 147 Environment* environment_; |
146 | 148 |
147 // Zone local to the builder for data not leaking into the graph. | 149 // Zone local to the builder for data not leaking into the graph. |
148 Zone local_zone_; | 150 Zone local_zone_; |
149 | 151 |
| 152 // Temporary storage for building node input lists. |
| 153 int input_buffer_size_; |
| 154 Node** input_buffer_; |
| 155 |
150 // Node representing the control dependency for dead code. | 156 // Node representing the control dependency for dead code. |
151 SetOncePointer<Node> dead_control_; | 157 SetOncePointer<Node> dead_control_; |
152 | 158 |
153 // Node representing the current context within the function body. | 159 // Node representing the current context within the function body. |
154 Node* current_context_; | 160 Node* current_context_; |
155 | 161 |
156 // Merge of all control nodes that exit the function body. | 162 // Merge of all control nodes that exit the function body. |
157 Node* exit_control_; | 163 Node* exit_control_; |
158 | 164 |
| 165 // Growth increment for the temporary buffer used to construct input lists to |
| 166 // new nodes. |
| 167 static const int kInputBufferSizeIncrement = 64; |
| 168 |
| 169 Node** EnsureInputBufferSize(int size); |
| 170 |
159 DISALLOW_COPY_AND_ASSIGN(StructuredGraphBuilder); | 171 DISALLOW_COPY_AND_ASSIGN(StructuredGraphBuilder); |
160 }; | 172 }; |
161 | 173 |
162 | 174 |
163 // The abstract execution environment contains static knowledge about | 175 // The abstract execution environment contains static knowledge about |
164 // execution state at arbitrary control-flow points. It allows for | 176 // execution state at arbitrary control-flow points. It allows for |
165 // simulation of the control-flow at compile time. | 177 // simulation of the control-flow at compile time. |
166 class StructuredGraphBuilder::Environment : public ZoneObject { | 178 class StructuredGraphBuilder::Environment : public ZoneObject { |
167 public: | 179 public: |
168 Environment(StructuredGraphBuilder* builder, Node* control_dependency); | 180 Environment(StructuredGraphBuilder* builder, Node* control_dependency); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 StructuredGraphBuilder* builder_; | 235 StructuredGraphBuilder* builder_; |
224 Node* control_dependency_; | 236 Node* control_dependency_; |
225 Node* effect_dependency_; | 237 Node* effect_dependency_; |
226 NodeVector values_; | 238 NodeVector values_; |
227 }; | 239 }; |
228 } | 240 } |
229 } | 241 } |
230 } // namespace v8::internal::compiler | 242 } // namespace v8::internal::compiler |
231 | 243 |
232 #endif // V8_COMPILER_GRAPH_BUILDER_H__ | 244 #endif // V8_COMPILER_GRAPH_BUILDER_H__ |
OLD | NEW |