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