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

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

Issue 644083003: [turbofan] Reduce memory consumption of graph building (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add missing arraysize 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
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 local_zone_(isolate()),
28 input_buffer_size_(0),
29 input_buffer_(NULL),
28 current_context_(NULL), 30 current_context_(NULL),
29 exit_control_(NULL) {} 31 exit_control_(NULL) {
32 EnsureInputBufferSize(kInputBufferSizeIncrement);
33 }
34
35
36 Node** StructuredGraphBuilder::EnsureInputBufferSize(int size) {
37 if (size > input_buffer_size_) {
38 size += kInputBufferSizeIncrement;
39 input_buffer_ = local_zone()->NewArray<Node*>(size);
40 }
41 return input_buffer_;
42 }
30 43
31 44
32 Node* StructuredGraphBuilder::MakeNode(const Operator* op, 45 Node* StructuredGraphBuilder::MakeNode(const Operator* op,
33 int value_input_count, 46 int value_input_count,
34 Node** value_inputs) { 47 Node** value_inputs, bool incomplete) {
35 DCHECK(op->InputCount() == value_input_count); 48 DCHECK(op->InputCount() == value_input_count);
36 49
37 bool has_context = OperatorProperties::HasContextInput(op); 50 bool has_context = OperatorProperties::HasContextInput(op);
38 bool has_framestate = OperatorProperties::HasFrameStateInput(op); 51 bool has_framestate = OperatorProperties::HasFrameStateInput(op);
39 bool has_control = OperatorProperties::GetControlInputCount(op) == 1; 52 bool has_control = OperatorProperties::GetControlInputCount(op) == 1;
40 bool has_effect = OperatorProperties::GetEffectInputCount(op) == 1; 53 bool has_effect = OperatorProperties::GetEffectInputCount(op) == 1;
41 54
42 DCHECK(OperatorProperties::GetControlInputCount(op) < 2); 55 DCHECK(OperatorProperties::GetControlInputCount(op) < 2);
43 DCHECK(OperatorProperties::GetEffectInputCount(op) < 2); 56 DCHECK(OperatorProperties::GetEffectInputCount(op) < 2);
44 57
45 Node* result = NULL; 58 Node* result = NULL;
46 if (!has_context && !has_framestate && !has_control && !has_effect) { 59 if (!has_context && !has_framestate && !has_control && !has_effect) {
47 result = graph()->NewNode(op, value_input_count, value_inputs); 60 result = graph()->NewNode(op, value_input_count, value_inputs, incomplete);
48 } else { 61 } else {
49 int input_count_with_deps = value_input_count; 62 int input_count_with_deps = value_input_count;
50 if (has_context) ++input_count_with_deps; 63 if (has_context) ++input_count_with_deps;
51 if (has_framestate) ++input_count_with_deps; 64 if (has_framestate) ++input_count_with_deps;
52 if (has_control) ++input_count_with_deps; 65 if (has_control) ++input_count_with_deps;
53 if (has_effect) ++input_count_with_deps; 66 if (has_effect) ++input_count_with_deps;
54 Node** buffer = local_zone()->NewArray<Node*>(input_count_with_deps); 67 Node** buffer = EnsureInputBufferSize(input_count_with_deps);
55 memcpy(buffer, value_inputs, kPointerSize * value_input_count); 68 memcpy(buffer, value_inputs, kPointerSize * value_input_count);
56 Node** current_input = buffer + value_input_count; 69 Node** current_input = buffer + value_input_count;
57 if (has_context) { 70 if (has_context) {
58 *current_input++ = current_context(); 71 *current_input++ = current_context();
59 } 72 }
60 if (has_framestate) { 73 if (has_framestate) {
61 // The frame state will be inserted later. Here we misuse 74 // The frame state will be inserted later. Here we misuse
62 // the dead_control node as a sentinel to be later overwritten 75 // the dead_control node as a sentinel to be later overwritten
63 // with the real frame state. 76 // with the real frame state.
64 *current_input++ = dead_control(); 77 *current_input++ = dead_control();
65 } 78 }
66 if (has_effect) { 79 if (has_effect) {
67 *current_input++ = environment_->GetEffectDependency(); 80 *current_input++ = environment_->GetEffectDependency();
68 } 81 }
69 if (has_control) { 82 if (has_control) {
70 *current_input++ = environment_->GetControlDependency(); 83 *current_input++ = environment_->GetControlDependency();
71 } 84 }
72 result = graph()->NewNode(op, input_count_with_deps, buffer); 85 result = graph()->NewNode(op, input_count_with_deps, buffer, incomplete);
73 if (has_effect) { 86 if (has_effect) {
74 environment_->UpdateEffectDependency(result); 87 environment_->UpdateEffectDependency(result);
75 } 88 }
76 if (OperatorProperties::HasControlOutput(result->op()) && 89 if (OperatorProperties::HasControlOutput(result->op()) &&
77 !environment()->IsMarkedAsUnreachable()) { 90 !environment()->IsMarkedAsUnreachable()) {
78 environment_->UpdateControlDependency(result); 91 environment_->UpdateControlDependency(result);
79 } 92 }
80 } 93 }
81 94
82 return result; 95 return result;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 void StructuredGraphBuilder::Environment::Merge(Environment* other) { 131 void StructuredGraphBuilder::Environment::Merge(Environment* other) {
119 DCHECK(values_.size() == other->values_.size()); 132 DCHECK(values_.size() == other->values_.size());
120 133
121 // Nothing to do if the other environment is dead. 134 // Nothing to do if the other environment is dead.
122 if (other->IsMarkedAsUnreachable()) return; 135 if (other->IsMarkedAsUnreachable()) return;
123 136
124 // Resurrect a dead environment by copying the contents of the other one and 137 // Resurrect a dead environment by copying the contents of the other one and
125 // placing a singleton merge as the new control dependency. 138 // placing a singleton merge as the new control dependency.
126 if (this->IsMarkedAsUnreachable()) { 139 if (this->IsMarkedAsUnreachable()) {
127 Node* other_control = other->control_dependency_; 140 Node* other_control = other->control_dependency_;
128 control_dependency_ = graph()->NewNode(common()->Merge(1), other_control); 141 Node* inputs[] = {other_control};
142 control_dependency_ =
143 graph()->NewNode(common()->Merge(1), arraysize(inputs), inputs, true);
Michael Starzinger 2014/10/27 09:34:19 suggestion: Having the "incomplete" parameter (wit
129 effect_dependency_ = other->effect_dependency_; 144 effect_dependency_ = other->effect_dependency_;
130 values_ = other->values_; 145 values_ = other->values_;
131 return; 146 return;
132 } 147 }
133 148
134 // Create a merge of the control dependencies of both environments and update 149 // Create a merge of the control dependencies of both environments and update
135 // the current environment's control dependency accordingly. 150 // the current environment's control dependency accordingly.
136 Node* control = builder_->MergeControl(this->GetControlDependency(), 151 Node* control = builder_->MergeControl(this->GetControlDependency(),
137 other->GetControlDependency()); 152 other->GetControlDependency());
138 UpdateControlDependency(control); 153 UpdateControlDependency(control);
(...skipping 18 matching lines...) Expand all
157 Node* phi = builder_->NewPhi(1, values()->at(i), control); 172 Node* phi = builder_->NewPhi(1, values()->at(i), control);
158 values()->at(i) = phi; 173 values()->at(i) = phi;
159 } 174 }
160 Node* effect = builder_->NewEffectPhi(1, GetEffectDependency(), control); 175 Node* effect = builder_->NewEffectPhi(1, GetEffectDependency(), control);
161 UpdateEffectDependency(effect); 176 UpdateEffectDependency(effect);
162 } 177 }
163 178
164 179
165 Node* StructuredGraphBuilder::NewPhi(int count, Node* input, Node* control) { 180 Node* StructuredGraphBuilder::NewPhi(int count, Node* input, Node* control) {
166 const Operator* phi_op = common()->Phi(kMachAnyTagged, count); 181 const Operator* phi_op = common()->Phi(kMachAnyTagged, count);
167 Node** buffer = local_zone()->NewArray<Node*>(count + 1); 182 Node** buffer = EnsureInputBufferSize(count + 1);
168 MemsetPointer(buffer, input, count); 183 MemsetPointer(buffer, input, count);
169 buffer[count] = control; 184 buffer[count] = control;
170 return graph()->NewNode(phi_op, count + 1, buffer, true); 185 return graph()->NewNode(phi_op, count + 1, buffer, true);
171 } 186 }
172 187
173 188
174 // TODO(mstarzinger): Revisit this once we have proper effect states. 189 // TODO(mstarzinger): Revisit this once we have proper effect states.
175 Node* StructuredGraphBuilder::NewEffectPhi(int count, Node* input, 190 Node* StructuredGraphBuilder::NewEffectPhi(int count, Node* input,
176 Node* control) { 191 Node* control) {
177 const Operator* phi_op = common()->EffectPhi(count); 192 const Operator* phi_op = common()->EffectPhi(count);
178 Node** buffer = local_zone()->NewArray<Node*>(count + 1); 193 Node** buffer = EnsureInputBufferSize(count + 1);
179 MemsetPointer(buffer, input, count); 194 MemsetPointer(buffer, input, count);
180 buffer[count] = control; 195 buffer[count] = control;
181 return graph()->NewNode(phi_op, count + 1, buffer, true); 196 return graph()->NewNode(phi_op, count + 1, buffer, true);
182 } 197 }
183 198
184 199
185 Node* StructuredGraphBuilder::MergeControl(Node* control, Node* other) { 200 Node* StructuredGraphBuilder::MergeControl(Node* control, Node* other) {
186 int inputs = OperatorProperties::GetControlInputCount(control->op()) + 1; 201 int inputs = OperatorProperties::GetControlInputCount(control->op()) + 1;
187 if (control->opcode() == IrOpcode::kLoop) { 202 if (control->opcode() == IrOpcode::kLoop) {
188 // Control node for loop exists, add input. 203 // Control node for loop exists, add input.
189 const Operator* op = common()->Loop(inputs); 204 const Operator* op = common()->Loop(inputs);
190 control->AppendInput(graph_zone(), other); 205 control->AppendInput(graph_zone(), other);
191 control->set_op(op); 206 control->set_op(op);
192 } else if (control->opcode() == IrOpcode::kMerge) { 207 } else if (control->opcode() == IrOpcode::kMerge) {
193 // Control node for merge exists, add input. 208 // Control node for merge exists, add input.
194 const Operator* op = common()->Merge(inputs); 209 const Operator* op = common()->Merge(inputs);
195 control->AppendInput(graph_zone(), other); 210 control->AppendInput(graph_zone(), other);
196 control->set_op(op); 211 control->set_op(op);
197 } else { 212 } else {
198 // Control node is a singleton, introduce a merge. 213 // Control node is a singleton, introduce a merge.
199 const Operator* op = common()->Merge(inputs); 214 const Operator* op = common()->Merge(inputs);
200 control = graph()->NewNode(op, control, other); 215 Node* inputs[] = {control, other};
216 control = graph()->NewNode(op, arraysize(inputs), inputs, true);
Michael Starzinger 2014/10/27 09:34:19 suggestion: Having the "incomplete" parameter (wit
201 } 217 }
202 return control; 218 return control;
203 } 219 }
204 220
205 221
206 Node* StructuredGraphBuilder::MergeEffect(Node* value, Node* other, 222 Node* StructuredGraphBuilder::MergeEffect(Node* value, Node* other,
207 Node* control) { 223 Node* control) {
208 int inputs = OperatorProperties::GetControlInputCount(control->op()); 224 int inputs = OperatorProperties::GetControlInputCount(control->op());
209 if (value->opcode() == IrOpcode::kEffectPhi && 225 if (value->opcode() == IrOpcode::kEffectPhi &&
210 NodeProperties::GetControlInput(value) == control) { 226 NodeProperties::GetControlInput(value) == control) {
(...skipping 30 matching lines...) Expand all
241 if (!dead_control_.is_set()) { 257 if (!dead_control_.is_set()) {
242 Node* dead_node = graph()->NewNode(common_->Dead()); 258 Node* dead_node = graph()->NewNode(common_->Dead());
243 dead_control_.set(dead_node); 259 dead_control_.set(dead_node);
244 return dead_node; 260 return dead_node;
245 } 261 }
246 return dead_control_.get(); 262 return dead_control_.get();
247 } 263 }
248 } 264 }
249 } 265 }
250 } // namespace v8::internal::compiler 266 } // namespace v8::internal::compiler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698