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

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

Issue 640423005: Use phase-local zone in the graph builder. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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
« no previous file with comments | « src/compiler/graph-builder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "src/compiler/graph-builder.h" 5 #include "src/compiler/graph-builder.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/compiler/generic-graph.h" 8 #include "src/compiler/generic-graph.h"
9 #include "src/compiler/generic-node.h" 9 #include "src/compiler/generic-node.h"
10 #include "src/compiler/generic-node-inl.h" 10 #include "src/compiler/generic-node-inl.h"
11 #include "src/compiler/graph-visualizer.h" 11 #include "src/compiler/graph-visualizer.h"
12 #include "src/compiler/node-properties.h" 12 #include "src/compiler/node-properties.h"
13 #include "src/compiler/node-properties-inl.h" 13 #include "src/compiler/node-properties-inl.h"
14 #include "src/compiler/operator-properties.h" 14 #include "src/compiler/operator-properties.h"
15 #include "src/compiler/operator-properties-inl.h" 15 #include "src/compiler/operator-properties-inl.h"
16 16
17 namespace v8 { 17 namespace v8 {
18 namespace internal { 18 namespace internal {
19 namespace compiler { 19 namespace compiler {
20 20
21 21
22 StructuredGraphBuilder::StructuredGraphBuilder(Graph* graph, 22 StructuredGraphBuilder::StructuredGraphBuilder(Graph* graph,
23 CommonOperatorBuilder* common) 23 CommonOperatorBuilder* common)
24 : GraphBuilder(graph), 24 : GraphBuilder(graph),
25 common_(common), 25 common_(common),
26 environment_(NULL), 26 environment_(NULL),
27 local_zone_(isolate()),
27 current_context_(NULL), 28 current_context_(NULL),
28 exit_control_(NULL) {} 29 exit_control_(NULL) {}
29 30
30 31
31 Node* StructuredGraphBuilder::MakeNode(const Operator* op, 32 Node* StructuredGraphBuilder::MakeNode(const Operator* op,
32 int value_input_count, 33 int value_input_count,
33 Node** value_inputs) { 34 Node** value_inputs) {
34 DCHECK(op->InputCount() == value_input_count); 35 DCHECK(op->InputCount() == value_input_count);
35 36
36 bool has_context = OperatorProperties::HasContextInput(op); 37 bool has_context = OperatorProperties::HasContextInput(op);
37 bool has_framestate = OperatorProperties::HasFrameStateInput(op); 38 bool has_framestate = OperatorProperties::HasFrameStateInput(op);
38 bool has_control = OperatorProperties::GetControlInputCount(op) == 1; 39 bool has_control = OperatorProperties::GetControlInputCount(op) == 1;
39 bool has_effect = OperatorProperties::GetEffectInputCount(op) == 1; 40 bool has_effect = OperatorProperties::GetEffectInputCount(op) == 1;
40 41
41 DCHECK(OperatorProperties::GetControlInputCount(op) < 2); 42 DCHECK(OperatorProperties::GetControlInputCount(op) < 2);
42 DCHECK(OperatorProperties::GetEffectInputCount(op) < 2); 43 DCHECK(OperatorProperties::GetEffectInputCount(op) < 2);
43 44
44 Node* result = NULL; 45 Node* result = NULL;
45 if (!has_context && !has_framestate && !has_control && !has_effect) { 46 if (!has_context && !has_framestate && !has_control && !has_effect) {
46 result = graph()->NewNode(op, value_input_count, value_inputs); 47 result = graph()->NewNode(op, value_input_count, value_inputs);
47 } else { 48 } else {
48 int input_count_with_deps = value_input_count; 49 int input_count_with_deps = value_input_count;
49 if (has_context) ++input_count_with_deps; 50 if (has_context) ++input_count_with_deps;
50 if (has_framestate) ++input_count_with_deps; 51 if (has_framestate) ++input_count_with_deps;
51 if (has_control) ++input_count_with_deps; 52 if (has_control) ++input_count_with_deps;
52 if (has_effect) ++input_count_with_deps; 53 if (has_effect) ++input_count_with_deps;
53 Node** buffer = zone()->NewArray<Node*>(input_count_with_deps); 54 Node** buffer = local_zone()->NewArray<Node*>(input_count_with_deps);
54 memcpy(buffer, value_inputs, kPointerSize * value_input_count); 55 memcpy(buffer, value_inputs, kPointerSize * value_input_count);
55 Node** current_input = buffer + value_input_count; 56 Node** current_input = buffer + value_input_count;
56 if (has_context) { 57 if (has_context) {
57 *current_input++ = current_context(); 58 *current_input++ = current_context();
58 } 59 }
59 if (has_framestate) { 60 if (has_framestate) {
60 // The frame state will be inserted later. Here we misuse 61 // The frame state will be inserted later. Here we misuse
61 // the dead_control node as a sentinel to be later overwritten 62 // the dead_control node as a sentinel to be later overwritten
62 // with the real frame state. 63 // with the real frame state.
63 *current_input++ = dead_control(); 64 *current_input++ = dead_control();
(...skipping 24 matching lines...) Expand all
88 if (exit_control() != NULL) { 89 if (exit_control() != NULL) {
89 exit = MergeControl(exit_control(), exit); 90 exit = MergeControl(exit_control(), exit);
90 } 91 }
91 environment()->MarkAsUnreachable(); 92 environment()->MarkAsUnreachable();
92 set_exit_control(exit); 93 set_exit_control(exit);
93 } 94 }
94 95
95 96
96 StructuredGraphBuilder::Environment* StructuredGraphBuilder::CopyEnvironment( 97 StructuredGraphBuilder::Environment* StructuredGraphBuilder::CopyEnvironment(
97 Environment* env) { 98 Environment* env) {
98 return new (zone()) Environment(*env); 99 return new (local_zone()) Environment(*env);
99 } 100 }
100 101
101 102
102 StructuredGraphBuilder::Environment::Environment( 103 StructuredGraphBuilder::Environment::Environment(
103 StructuredGraphBuilder* builder, Node* control_dependency) 104 StructuredGraphBuilder* builder, Node* control_dependency)
104 : builder_(builder), 105 : builder_(builder),
105 control_dependency_(control_dependency), 106 control_dependency_(control_dependency),
106 effect_dependency_(control_dependency), 107 effect_dependency_(control_dependency),
107 values_(zone()) {} 108 values_(zone()) {}
108 109
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 Node* phi = builder_->NewPhi(1, values()->at(i), control); 157 Node* phi = builder_->NewPhi(1, values()->at(i), control);
157 values()->at(i) = phi; 158 values()->at(i) = phi;
158 } 159 }
159 Node* effect = builder_->NewEffectPhi(1, GetEffectDependency(), control); 160 Node* effect = builder_->NewEffectPhi(1, GetEffectDependency(), control);
160 UpdateEffectDependency(effect); 161 UpdateEffectDependency(effect);
161 } 162 }
162 163
163 164
164 Node* StructuredGraphBuilder::NewPhi(int count, Node* input, Node* control) { 165 Node* StructuredGraphBuilder::NewPhi(int count, Node* input, Node* control) {
165 const Operator* phi_op = common()->Phi(kMachAnyTagged, count); 166 const Operator* phi_op = common()->Phi(kMachAnyTagged, count);
166 Node** buffer = zone()->NewArray<Node*>(count + 1); 167 Node** buffer = local_zone()->NewArray<Node*>(count + 1);
167 MemsetPointer(buffer, input, count); 168 MemsetPointer(buffer, input, count);
168 buffer[count] = control; 169 buffer[count] = control;
169 return graph()->NewNode(phi_op, count + 1, buffer); 170 return graph()->NewNode(phi_op, count + 1, buffer);
170 } 171 }
171 172
172 173
173 // TODO(mstarzinger): Revisit this once we have proper effect states. 174 // TODO(mstarzinger): Revisit this once we have proper effect states.
174 Node* StructuredGraphBuilder::NewEffectPhi(int count, Node* input, 175 Node* StructuredGraphBuilder::NewEffectPhi(int count, Node* input,
175 Node* control) { 176 Node* control) {
176 const Operator* phi_op = common()->EffectPhi(count); 177 const Operator* phi_op = common()->EffectPhi(count);
177 Node** buffer = zone()->NewArray<Node*>(count + 1); 178 Node** buffer = local_zone()->NewArray<Node*>(count + 1);
178 MemsetPointer(buffer, input, count); 179 MemsetPointer(buffer, input, count);
179 buffer[count] = control; 180 buffer[count] = control;
180 return graph()->NewNode(phi_op, count + 1, buffer); 181 return graph()->NewNode(phi_op, count + 1, buffer);
181 } 182 }
182 183
183 184
184 Node* StructuredGraphBuilder::MergeControl(Node* control, Node* other) { 185 Node* StructuredGraphBuilder::MergeControl(Node* control, Node* other) {
185 int inputs = OperatorProperties::GetControlInputCount(control->op()) + 1; 186 int inputs = OperatorProperties::GetControlInputCount(control->op()) + 1;
186 if (control->opcode() == IrOpcode::kLoop) { 187 if (control->opcode() == IrOpcode::kLoop) {
187 // Control node for loop exists, add input. 188 // Control node for loop exists, add input.
188 const Operator* op = common()->Loop(inputs); 189 const Operator* op = common()->Loop(inputs);
189 control->AppendInput(zone(), other); 190 control->AppendInput(graph_zone(), other);
190 control->set_op(op); 191 control->set_op(op);
191 } else if (control->opcode() == IrOpcode::kMerge) { 192 } else if (control->opcode() == IrOpcode::kMerge) {
192 // Control node for merge exists, add input. 193 // Control node for merge exists, add input.
193 const Operator* op = common()->Merge(inputs); 194 const Operator* op = common()->Merge(inputs);
194 control->AppendInput(zone(), other); 195 control->AppendInput(graph_zone(), other);
195 control->set_op(op); 196 control->set_op(op);
196 } else { 197 } else {
197 // Control node is a singleton, introduce a merge. 198 // Control node is a singleton, introduce a merge.
198 const Operator* op = common()->Merge(inputs); 199 const Operator* op = common()->Merge(inputs);
199 control = graph()->NewNode(op, control, other); 200 control = graph()->NewNode(op, control, other);
200 } 201 }
201 return control; 202 return control;
202 } 203 }
203 204
204 205
205 Node* StructuredGraphBuilder::MergeEffect(Node* value, Node* other, 206 Node* StructuredGraphBuilder::MergeEffect(Node* value, Node* other,
206 Node* control) { 207 Node* control) {
207 int inputs = OperatorProperties::GetControlInputCount(control->op()); 208 int inputs = OperatorProperties::GetControlInputCount(control->op());
208 if (value->opcode() == IrOpcode::kEffectPhi && 209 if (value->opcode() == IrOpcode::kEffectPhi &&
209 NodeProperties::GetControlInput(value) == control) { 210 NodeProperties::GetControlInput(value) == control) {
210 // Phi already exists, add input. 211 // Phi already exists, add input.
211 value->set_op(common()->EffectPhi(inputs)); 212 value->set_op(common()->EffectPhi(inputs));
212 value->InsertInput(zone(), inputs - 1, other); 213 value->InsertInput(graph_zone(), inputs - 1, other);
213 } else if (value != other) { 214 } else if (value != other) {
214 // Phi does not exist yet, introduce one. 215 // Phi does not exist yet, introduce one.
215 value = NewEffectPhi(inputs, value, control); 216 value = NewEffectPhi(inputs, value, control);
216 value->ReplaceInput(inputs - 1, other); 217 value->ReplaceInput(inputs - 1, other);
217 } 218 }
218 return value; 219 return value;
219 } 220 }
220 221
221 222
222 Node* StructuredGraphBuilder::MergeValue(Node* value, Node* other, 223 Node* StructuredGraphBuilder::MergeValue(Node* value, Node* other,
223 Node* control) { 224 Node* control) {
224 int inputs = OperatorProperties::GetControlInputCount(control->op()); 225 int inputs = OperatorProperties::GetControlInputCount(control->op());
225 if (value->opcode() == IrOpcode::kPhi && 226 if (value->opcode() == IrOpcode::kPhi &&
226 NodeProperties::GetControlInput(value) == control) { 227 NodeProperties::GetControlInput(value) == control) {
227 // Phi already exists, add input. 228 // Phi already exists, add input.
228 value->set_op(common()->Phi(kMachAnyTagged, inputs)); 229 value->set_op(common()->Phi(kMachAnyTagged, inputs));
229 value->InsertInput(zone(), inputs - 1, other); 230 value->InsertInput(graph_zone(), inputs - 1, other);
230 } else if (value != other) { 231 } else if (value != other) {
231 // Phi does not exist yet, introduce one. 232 // Phi does not exist yet, introduce one.
232 value = NewPhi(inputs, value, control); 233 value = NewPhi(inputs, value, control);
233 value->ReplaceInput(inputs - 1, other); 234 value->ReplaceInput(inputs - 1, other);
234 } 235 }
235 return value; 236 return value;
236 } 237 }
237 238
238 239
239 Node* StructuredGraphBuilder::dead_control() { 240 Node* StructuredGraphBuilder::dead_control() {
240 if (!dead_control_.is_set()) { 241 if (!dead_control_.is_set()) {
241 Node* dead_node = graph()->NewNode(common_->Dead()); 242 Node* dead_node = graph()->NewNode(common_->Dead());
242 dead_control_.set(dead_node); 243 dead_control_.set(dead_node);
243 return dead_node; 244 return dead_node;
244 } 245 }
245 return dead_control_.get(); 246 return dead_control_.get();
246 } 247 }
247 } 248 }
248 } 249 }
249 } // namespace v8::internal::compiler 250 } // namespace v8::internal::compiler
OLDNEW
« no previous file with comments | « src/compiler/graph-builder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698