Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: src/compiler/graph-builder.h

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef V8_COMPILER_GRAPH_BUILDER_H_
6 #define V8_COMPILER_GRAPH_BUILDER_H_
7
8 #include "src/v8.h"
9
10 #include "src/allocation.h"
11 #include "src/compiler/common-operator.h"
12 #include "src/compiler/graph.h"
13 #include "src/unique.h"
14
15 namespace v8 {
16 namespace internal {
17 namespace compiler {
18
19 class Node;
20
21 // A common base class for anything that creates nodes in a graph.
22 class GraphBuilder {
23 public:
24 explicit GraphBuilder(Graph* graph) : graph_(graph) {}
25 virtual ~GraphBuilder() {}
26
27 Node* NewNode(Operator* op) {
28 return MakeNode(op, 0, static_cast<Node**>(NULL));
29 }
30
31 Node* NewNode(Operator* op, Node* n1) { return MakeNode(op, 1, &n1); }
32
33 Node* NewNode(Operator* op, Node* n1, Node* n2) {
34 Node* buffer[] = { n1, n2 };
35 return MakeNode(op, ARRAY_SIZE(buffer), buffer);
36 }
37
38 Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3) {
39 Node* buffer[] = { n1, n2, n3 };
40 return MakeNode(op, ARRAY_SIZE(buffer), buffer);
41 }
42
43 Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) {
44 Node* buffer[] = { n1, n2, n3, n4 };
45 return MakeNode(op, ARRAY_SIZE(buffer), buffer);
46 }
47
48 Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
49 Node* n5) {
50 Node* buffer[] = { n1, n2, n3, n4, n5 };
51 return MakeNode(op, ARRAY_SIZE(buffer), buffer);
52 }
53
54 Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, Node* n5,
55 Node* n6) {
56 Node* nodes[] = {n1, n2, n3, n4, n5, n6};
57 return MakeNode(op, ARRAY_SIZE(nodes), nodes);
58 }
59
60 Node* NewNode(Operator* op, int value_input_count, Node** value_inputs) {
61 return MakeNode(op, value_input_count, value_inputs);
62 }
63
64 Graph* graph() const { return graph_; }
65
66 protected:
67 // Base implementation used by all factory methods.
68 virtual Node* MakeNode(Operator* op, int value_input_count,
69 Node** value_inputs) = 0;
70
71 private:
72 Graph* graph_;
73 };
74
75
76 // The StructuredGraphBuilder produces a high-level IR graph. It is used as the
77 // base class for concrete implementations (e.g the AstGraphBuilder or the
78 // StubGraphBuilder).
79 class StructuredGraphBuilder : public GraphBuilder {
80 public:
81 StructuredGraphBuilder(Graph* graph, CommonOperatorBuilder* common);
82 virtual ~StructuredGraphBuilder() {}
83
84 // Creates a new Phi node having {count} input values.
85 Node* NewPhi(int count, Node* input, Node* control);
86 Node* NewEffectPhi(int count, Node* input, Node* control);
87
88 // Helpers for merging control, effect or value dependencies.
89 Node* MergeControl(Node* control, Node* other);
90 Node* MergeEffect(Node* value, Node* other, Node* control);
91 Node* MergeValue(Node* value, Node* other, Node* control);
92
93 // Helpers to create new control nodes.
94 Node* NewIfTrue() { return NewNode(common()->IfTrue()); }
95 Node* NewIfFalse() { return NewNode(common()->IfFalse()); }
96 Node* NewMerge() { return NewNode(common()->Merge(1)); }
97 Node* NewLoop() { return NewNode(common()->Loop(1)); }
98 Node* NewBranch(Node* condition) {
99 return NewNode(common()->Branch(), condition);
100 }
101
102 protected:
103 class Environment;
104 friend class ControlBuilder;
105
106 // The following method creates a new node having the specified operator and
107 // ensures effect and control dependencies are wired up. The dependencies
108 // tracked by the environment might be mutated.
109 virtual Node* MakeNode(Operator* op, int value_input_count,
110 Node** value_inputs);
111
112 Environment* environment_internal() const { return environment_; }
113 void set_environment(Environment* env) { environment_ = env; }
114
115 Node* current_context() const { return current_context_; }
116 void set_current_context(Node* context) { current_context_ = context; }
117
118 Node* exit_control() const { return exit_control_; }
119 void set_exit_control(Node* node) { exit_control_ = node; }
120
121 Node* dead_control();
122
123 // TODO(mstarzinger): Use phase-local zone instead!
124 Zone* zone() const { return graph()->zone(); }
125 Isolate* isolate() const { return zone()->isolate(); }
126 CommonOperatorBuilder* common() const { return common_; }
127
128 // Helper to wrap a Handle<T> into a Unique<T>.
129 template<class T> PrintableUnique<T> MakeUnique(Handle<T> object) {
130 return PrintableUnique<T>::CreateUninitialized(zone(), object);
131 }
132
133 // Support for control flow builders. The concrete type of the environment
134 // depends on the graph builder, but environments themselves are not virtual.
135 virtual Environment* CopyEnvironment(Environment* env);
136
137 // Helper when creating node that depends on control.
138 Node* GetControlDependency();
139
140 // Helper when creating node that updates control.
141 void UpdateControlDependency(Node* new_control);
142
143 // Helper to indicate a node exits the function body.
144 void UpdateControlDependencyToLeaveFunction(Node* exit);
145
146 private:
147 CommonOperatorBuilder* common_;
148 Environment* environment_;
149
150 // Node representing the control dependency for dead code.
151 SetOncePointer<Node> dead_control_;
152
153 // Node representing the current context within the function body.
154 Node* current_context_;
155
156 // Merge of all control nodes that exit the function body.
157 Node* exit_control_;
158
159 DISALLOW_COPY_AND_ASSIGN(StructuredGraphBuilder);
160 };
161
162
163 // The abstract execution environment contains static knowledge about
164 // execution state at arbitrary control-flow points. It allows for
165 // simulation of the control-flow at compile time.
166 class StructuredGraphBuilder::Environment : public ZoneObject {
167 public:
168 Environment(StructuredGraphBuilder* builder, Node* control_dependency);
169 Environment(const Environment& copy);
170
171 // Control dependency tracked by this environment.
172 Node* GetControlDependency() { return control_dependency_; }
173 void UpdateControlDependency(Node* dependency) {
174 control_dependency_ = dependency;
175 }
176
177 // Effect dependency tracked by this environment.
178 Node* GetEffectDependency() { return effect_dependency_; }
179 void UpdateEffectDependency(Node* dependency) {
180 effect_dependency_ = dependency;
181 }
182
183 // Mark this environment as being unreachable.
184 void MarkAsUnreachable() {
185 UpdateControlDependency(builder()->dead_control());
186 }
187 bool IsMarkedAsUnreachable() {
188 return GetControlDependency()->opcode() == IrOpcode::kDead;
189 }
190
191 // Merge another environment into this one.
192 void Merge(Environment* other);
193
194 // Copies this environment at a control-flow split point.
195 Environment* CopyForConditional() {
196 return builder()->CopyEnvironment(this);
197 }
198
199 // Copies this environment to a potentially unreachable control-flow point.
200 Environment* CopyAsUnreachable() {
201 Environment* env = builder()->CopyEnvironment(this);
202 env->MarkAsUnreachable();
203 return env;
204 }
205
206 // Copies this environment at a loop header control-flow point.
207 Environment* CopyForLoop() {
208 PrepareForLoop();
209 return builder()->CopyEnvironment(this);
210 }
211
212 protected:
213 // TODO(mstarzinger): Use phase-local zone instead!
214 Zone* zone() const { return graph()->zone(); }
215 Graph* graph() const { return builder_->graph(); }
216 StructuredGraphBuilder* builder() const { return builder_; }
217 CommonOperatorBuilder* common() { return builder_->common(); }
218 NodeVector* values() { return &values_; }
219
220 // Prepare environment to be used as loop header.
221 void PrepareForLoop();
222
223 private:
224 StructuredGraphBuilder* builder_;
225 Node* control_dependency_;
226 Node* effect_dependency_;
227 NodeVector values_;
228 };
229
230
231 } } } // namespace v8::internal::compiler
232
233 #endif // V8_COMPILER_GRAPH_BUILDER_H__
OLDNEW
« no previous file with comments | « src/compiler/graph.cc ('k') | src/compiler/graph-builder.cc » ('j') | src/lithium-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698