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

Side by Side Diff: src/compiler/js-inlining.cc

Issue 765983002: Clean up node iteration (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix windows build Created 6 years 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
« no previous file with comments | « src/compiler/instruction-selector.cc ('k') | src/compiler/node.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "src/ast.h" 5 #include "src/ast.h"
6 #include "src/ast-numbering.h" 6 #include "src/ast-numbering.h"
7 #include "src/compiler/access-builder.h" 7 #include "src/compiler/access-builder.h"
8 #include "src/compiler/ast-graph-builder.h" 8 #include "src/compiler/ast-graph-builder.h"
9 #include "src/compiler/common-operator.h" 9 #include "src/compiler/common-operator.h"
10 #include "src/compiler/graph-inl.h" 10 #include "src/compiler/graph-inl.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 int predecessors = final_merge->op()->ControlInputCount(); 120 int predecessors = final_merge->op()->ControlInputCount();
121 121
122 const Operator* op_phi = jsgraph->common()->Phi(kMachAnyTagged, predecessors); 122 const Operator* op_phi = jsgraph->common()->Phi(kMachAnyTagged, predecessors);
123 const Operator* op_ephi = jsgraph->common()->EffectPhi(predecessors); 123 const Operator* op_ephi = jsgraph->common()->EffectPhi(predecessors);
124 124
125 NodeVector values(jsgraph->zone()); 125 NodeVector values(jsgraph->zone());
126 NodeVector effects(jsgraph->zone()); 126 NodeVector effects(jsgraph->zone());
127 // Iterate over all control flow predecessors, 127 // Iterate over all control flow predecessors,
128 // which must be return statements. 128 // which must be return statements.
129 InputIter iter = final_merge->inputs().begin(); 129 for (Edge edge : final_merge->input_edges()) {
130 while (iter != final_merge->inputs().end()) { 130 Node* input = edge.to();
131 Node* input = *iter;
132 switch (input->opcode()) { 131 switch (input->opcode()) {
133 case IrOpcode::kReturn: 132 case IrOpcode::kReturn:
134 values.push_back(NodeProperties::GetValueInput(input, 0)); 133 values.push_back(NodeProperties::GetValueInput(input, 0));
135 effects.push_back(NodeProperties::GetEffectInput(input)); 134 effects.push_back(NodeProperties::GetEffectInput(input));
136 iter.UpdateToAndIncrement(NodeProperties::GetControlInput(input)); 135 edge.UpdateTo(NodeProperties::GetControlInput(input));
137 input->RemoveAllInputs(); 136 input->RemoveAllInputs();
138 break; 137 break;
139 default: 138 default:
140 UNREACHABLE(); 139 UNREACHABLE();
141 ++iter;
142 break; 140 break;
143 } 141 }
144 } 142 }
145 values.push_back(final_merge); 143 values.push_back(final_merge);
146 effects.push_back(final_merge); 144 effects.push_back(final_merge);
147 Node* phi = 145 Node* phi =
148 graph->NewNode(op_phi, static_cast<int>(values.size()), &values.front()); 146 graph->NewNode(op_phi, static_cast<int>(values.size()), &values.front());
149 Node* ephi = graph->NewNode(op_ephi, static_cast<int>(effects.size()), 147 Node* ephi = graph->NewNode(op_ephi, static_cast<int>(effects.size()),
150 &effects.front()); 148 &effects.front());
151 Node* new_return = 149 Node* new_return =
152 graph->NewNode(jsgraph->common()->Return(), phi, ephi, final_merge); 150 graph->NewNode(jsgraph->common()->Return(), phi, ephi, final_merge);
153 graph->end()->ReplaceInput(0, new_return); 151 graph->end()->ReplaceInput(0, new_return);
154 } 152 }
155 153
156 154
157 class CopyVisitor : public NullNodeVisitor { 155 class CopyVisitor : public NullNodeVisitor {
158 public: 156 public:
159 CopyVisitor(Graph* source_graph, Graph* target_graph, Zone* temp_zone) 157 CopyVisitor(Graph* source_graph, Graph* target_graph, Zone* temp_zone)
160 : copies_(source_graph->NodeCount(), NULL, temp_zone), 158 : copies_(source_graph->NodeCount(), NULL, temp_zone),
161 sentinels_(source_graph->NodeCount(), NULL, temp_zone), 159 sentinels_(source_graph->NodeCount(), NULL, temp_zone),
162 source_graph_(source_graph), 160 source_graph_(source_graph),
163 target_graph_(target_graph), 161 target_graph_(target_graph),
164 temp_zone_(temp_zone), 162 temp_zone_(temp_zone),
165 sentinel_op_(IrOpcode::kDead, Operator::kNoProperties, "sentinel", 0, 0, 163 sentinel_op_(IrOpcode::kDead, Operator::kNoProperties, "sentinel", 0, 0,
166 0, 0, 0, 0) {} 164 0, 0, 0, 0) {}
167 165
168 void Post(Node* original) { 166 void Post(Node* original) {
169 NodeVector inputs(temp_zone_); 167 NodeVector inputs(temp_zone_);
170 for (InputIter it = original->inputs().begin(); 168 for (Node* const node : original->inputs()) {
171 it != original->inputs().end(); ++it) { 169 inputs.push_back(GetCopy(node));
172 inputs.push_back(GetCopy(*it));
173 } 170 }
174 171
175 // Reuse the operator in the copy. This assumes that op lives in a zone 172 // Reuse the operator in the copy. This assumes that op lives in a zone
176 // that lives longer than graph()'s zone. 173 // that lives longer than graph()'s zone.
177 Node* copy = 174 Node* copy =
178 target_graph_->NewNode(original->op(), static_cast<int>(inputs.size()), 175 target_graph_->NewNode(original->op(), static_cast<int>(inputs.size()),
179 (inputs.empty() ? NULL : &inputs.front())); 176 (inputs.empty() ? NULL : &inputs.front()));
180 copies_[original->id()] = copy; 177 copies_[original->id()] = copy;
181 } 178 }
182 179
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 simplified.LoadField(AccessBuilder::ForJSFunctionContext()), 232 simplified.LoadField(AccessBuilder::ForJSFunctionContext()),
236 NodeProperties::GetValueInput(call, 0), 233 NodeProperties::GetValueInput(call, 0),
237 NodeProperties::GetEffectInput(call), control); 234 NodeProperties::GetEffectInput(call), control);
238 235
239 // Context is last argument. 236 // Context is last argument.
240 int inlinee_context_index = static_cast<int>(total_parameters()) - 1; 237 int inlinee_context_index = static_cast<int>(total_parameters()) - 1;
241 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not 238 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not
242 // context, effect, control. 239 // context, effect, control.
243 int inliner_inputs = call->op()->ValueInputCount(); 240 int inliner_inputs = call->op()->ValueInputCount();
244 // Iterate over all uses of the start node. 241 // Iterate over all uses of the start node.
245 UseIter iter = start_->uses().begin(); 242 for (Edge edge : start_->use_edges()) {
246 while (iter != start_->uses().end()) { 243 Node* use = edge.from();
247 Node* use = *iter;
248 switch (use->opcode()) { 244 switch (use->opcode()) {
249 case IrOpcode::kParameter: { 245 case IrOpcode::kParameter: {
250 int index = 1 + OpParameter<int>(use->op()); 246 int index = 1 + OpParameter<int>(use->op());
251 if (index < inliner_inputs && index < inlinee_context_index) { 247 if (index < inliner_inputs && index < inlinee_context_index) {
252 // There is an input from the call, and the index is a value 248 // There is an input from the call, and the index is a value
253 // projection but not the context, so rewire the input. 249 // projection but not the context, so rewire the input.
254 NodeProperties::ReplaceWithValue(*iter, call->InputAt(index)); 250 NodeProperties::ReplaceWithValue(use, call->InputAt(index));
255 } else if (index == inlinee_context_index) { 251 } else if (index == inlinee_context_index) {
256 // This is the context projection, rewire it to the context from the 252 // This is the context projection, rewire it to the context from the
257 // JSFunction object. 253 // JSFunction object.
258 NodeProperties::ReplaceWithValue(*iter, context); 254 NodeProperties::ReplaceWithValue(use, context);
259 } else if (index < inlinee_context_index) { 255 } else if (index < inlinee_context_index) {
260 // Call has fewer arguments than required, fill with undefined. 256 // Call has fewer arguments than required, fill with undefined.
261 NodeProperties::ReplaceWithValue(*iter, jsgraph->UndefinedConstant()); 257 NodeProperties::ReplaceWithValue(use, jsgraph->UndefinedConstant());
262 } else { 258 } else {
263 // We got too many arguments, discard for now. 259 // We got too many arguments, discard for now.
264 // TODO(sigurds): Fix to treat arguments array correctly. 260 // TODO(sigurds): Fix to treat arguments array correctly.
265 } 261 }
266 ++iter;
267 break; 262 break;
268 } 263 }
269 default: 264 default:
270 if (NodeProperties::IsEffectEdge(iter.edge())) { 265 if (NodeProperties::IsEffectEdge(edge)) {
271 iter.UpdateToAndIncrement(context); 266 edge.UpdateTo(context);
272 } else if (NodeProperties::IsControlEdge(iter.edge())) { 267 } else if (NodeProperties::IsControlEdge(edge)) {
273 iter.UpdateToAndIncrement(control); 268 edge.UpdateTo(control);
274 } else { 269 } else {
275 UNREACHABLE(); 270 UNREACHABLE();
276 } 271 }
277 break; 272 break;
278 } 273 }
279 } 274 }
280 275
281 NodeProperties::ReplaceWithValue(call, value_output(), effect_output()); 276 NodeProperties::ReplaceWithValue(call, value_output(), effect_output());
282 call->RemoveAllInputs(); 277 call->RemoveAllInputs();
283 DCHECK_EQ(0, call->UseCount()); 278 DCHECK_EQ(0, call->UseCount());
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 Node* context() const { return NodeProperties::GetContextInput(call_); } 443 Node* context() const { return NodeProperties::GetContextInput(call_); }
449 Node* control() const { return NodeProperties::GetControlInput(call_); } 444 Node* control() const { return NodeProperties::GetControlInput(call_); }
450 Node* effect() const { return NodeProperties::GetEffectInput(call_); } 445 Node* effect() const { return NodeProperties::GetEffectInput(call_); }
451 446
452 const Runtime::Function* function() const { 447 const Runtime::Function* function() const {
453 return Runtime::FunctionForId(CallRuntimeParametersOf(call_->op()).id()); 448 return Runtime::FunctionForId(CallRuntimeParametersOf(call_->op()).id());
454 } 449 }
455 450
456 NodeVector inputs(Zone* zone) const { 451 NodeVector inputs(Zone* zone) const {
457 NodeVector inputs(zone); 452 NodeVector inputs(zone);
458 for (InputIter it = call_->inputs().begin(); it != call_->inputs().end(); 453 for (Node* const node : call_->inputs()) {
459 ++it) { 454 inputs.push_back(node);
460 inputs.push_back(*it);
461 } 455 }
462 return inputs; 456 return inputs;
463 } 457 }
464 458
465 private: 459 private:
466 Node* call_; 460 Node* call_;
467 }; 461 };
468 462
469 463
470 void JSInliner::TryInlineRuntimeCall(Node* call_node) { 464 void JSInliner::TryInlineRuntimeCall(Node* call_node) {
(...skipping 15 matching lines...) Expand all
486 info_->shared_info()->DebugName()->ToCString().get()); 480 info_->shared_info()->DebugName()->ToCString().get());
487 } 481 }
488 NodeProperties::ReplaceWithValue(call_node, r.first, r.second); 482 NodeProperties::ReplaceWithValue(call_node, r.first, r.second);
489 call_node->RemoveAllInputs(); 483 call_node->RemoveAllInputs();
490 DCHECK_EQ(0, call_node->UseCount()); 484 DCHECK_EQ(0, call_node->UseCount());
491 } 485 }
492 } 486 }
493 } 487 }
494 } 488 }
495 } // namespace v8::internal::compiler 489 } // namespace v8::internal::compiler
OLDNEW
« no previous file with comments | « src/compiler/instruction-selector.cc ('k') | src/compiler/node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698