OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/loop-variable-optimizer.h" | 5 #include "src/compiler/loop-variable-optimizer.h" |
6 | 6 |
7 #include "src/compiler/common-operator.h" | 7 #include "src/compiler/common-operator.h" |
8 #include "src/compiler/graph.h" | 8 #include "src/compiler/graph.h" |
9 #include "src/compiler/node-marker.h" | 9 #include "src/compiler/node-marker.h" |
10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 for (auto bound : induction_var->upper_bounds()) { | 362 for (auto bound : induction_var->upper_bounds()) { |
363 induction_var->phi()->InsertInput( | 363 induction_var->phi()->InsertInput( |
364 graph()->zone(), induction_var->phi()->InputCount() - 1, bound.bound); | 364 graph()->zone(), induction_var->phi()->InputCount() - 1, bound.bound); |
365 } | 365 } |
366 NodeProperties::ChangeOp( | 366 NodeProperties::ChangeOp( |
367 induction_var->phi(), | 367 induction_var->phi(), |
368 common()->InductionVariablePhi(induction_var->phi()->InputCount() - 1)); | 368 common()->InductionVariablePhi(induction_var->phi()->InputCount() - 1)); |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 void LoopVariableOptimizer::ChangeFromInductionVariablePhis() { | 372 void LoopVariableOptimizer::ChangeToPhisAndInsertSigmas() { |
373 for (auto entry : induction_vars_) { | 373 for (auto entry : induction_vars_) { |
374 InductionVariable* induction_var = entry.second; | 374 InductionVariable* induction_var = entry.second; |
375 if (induction_var->phi()->opcode() == IrOpcode::kInductionVariablePhi) { | 375 if (induction_var->phi()->opcode() == IrOpcode::kInductionVariablePhi) { |
| 376 // Turn the induction variable phi back to normal phi. |
376 int value_count = 2; | 377 int value_count = 2; |
377 Node* control = NodeProperties::GetControlInput(induction_var->phi()); | 378 Node* control = NodeProperties::GetControlInput(induction_var->phi()); |
378 DCHECK_EQ(value_count, control->op()->ControlInputCount()); | 379 DCHECK_EQ(value_count, control->op()->ControlInputCount()); |
379 induction_var->phi()->TrimInputCount(value_count + 1); | 380 induction_var->phi()->TrimInputCount(value_count + 1); |
380 induction_var->phi()->ReplaceInput(value_count, control); | 381 induction_var->phi()->ReplaceInput(value_count, control); |
381 NodeProperties::ChangeOp( | 382 NodeProperties::ChangeOp( |
382 induction_var->phi(), | 383 induction_var->phi(), |
383 common()->Phi(MachineRepresentation::kTagged, value_count)); | 384 common()->Phi(MachineRepresentation::kTagged, value_count)); |
| 385 |
| 386 // If the backedge is not a subtype of the phi's type, we insert a sigma |
| 387 // to get the typing right. |
| 388 Node* backedge_value = induction_var->phi()->InputAt(1); |
| 389 Type* backedge_type = NodeProperties::GetType(backedge_value); |
| 390 Type* phi_type = NodeProperties::GetType(induction_var->phi()); |
| 391 if (!backedge_type->Is(phi_type)) { |
| 392 Node* backedge_control = |
| 393 NodeProperties::GetControlInput(induction_var->phi())->InputAt(1); |
| 394 Node* rename = graph()->NewNode(common()->Sigma(phi_type), |
| 395 backedge_value, backedge_control); |
| 396 induction_var->phi()->ReplaceInput(1, rename); |
| 397 } |
384 } | 398 } |
385 } | 399 } |
386 } | 400 } |
387 | 401 |
388 } // namespace compiler | 402 } // namespace compiler |
389 } // namespace internal | 403 } // namespace internal |
390 } // namespace v8 | 404 } // namespace v8 |
OLD | NEW |