| 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/compiler/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
| 6 #include "src/compiler/control-reducer.h" | 6 #include "src/compiler/control-reducer.h" |
| 7 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
| 8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
| 9 #include "src/compiler/node-marker.h" | 9 #include "src/compiler/node-marker.h" |
| 10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 ReplaceNode(use, (result == kTrue) ? dead() : control); | 502 ReplaceNode(use, (result == kTrue) ? dead() : control); |
| 503 control = NodeProperties::GetControlInput(node); // Could change! | 503 control = NodeProperties::GetControlInput(node); // Could change! |
| 504 } | 504 } |
| 505 } | 505 } |
| 506 return control; | 506 return control; |
| 507 } | 507 } |
| 508 | 508 |
| 509 // Remove inputs to {node} corresponding to the dead inputs to {merge} | 509 // Remove inputs to {node} corresponding to the dead inputs to {merge} |
| 510 // and compact the remaining inputs, updating the operator. | 510 // and compact the remaining inputs, updating the operator. |
| 511 void RemoveDeadInputs(Node* merge, Node* node) { | 511 void RemoveDeadInputs(Node* merge, Node* node) { |
| 512 int pos = 0; | 512 int live = 0; |
| 513 for (int i = 0; i < node->InputCount(); i++) { | 513 for (int i = 0; i < merge->InputCount(); i++) { |
| 514 // skip dead inputs. | 514 // skip dead inputs. |
| 515 if (i < merge->InputCount() && | 515 if (merge->InputAt(i)->opcode() == IrOpcode::kDead) continue; |
| 516 merge->InputAt(i)->opcode() == IrOpcode::kDead) | |
| 517 continue; | |
| 518 // compact live inputs. | 516 // compact live inputs. |
| 519 if (pos != i) node->ReplaceInput(pos, node->InputAt(i)); | 517 if (live != i) node->ReplaceInput(live, node->InputAt(i)); |
| 520 pos++; | 518 live++; |
| 521 } | 519 } |
| 522 node->TrimInputCount(pos); | 520 // compact remaining inputs. |
| 523 if (node->opcode() == IrOpcode::kPhi) { | 521 int total = live; |
| 524 node->set_op(common_->Phi(OpParameter<MachineType>(node->op()), pos - 1)); | 522 for (int i = merge->InputCount(); i < node->InputCount(); i++) { |
| 525 } else if (node->opcode() == IrOpcode::kEffectPhi) { | 523 if (total != i) node->ReplaceInput(total, node->InputAt(i)); |
| 526 node->set_op(common_->EffectPhi(pos - 1)); | 524 total++; |
| 527 } else if (node->opcode() == IrOpcode::kMerge) { | |
| 528 node->set_op(common_->Merge(pos)); | |
| 529 } else if (node->opcode() == IrOpcode::kLoop) { | |
| 530 node->set_op(common_->Loop(pos)); | |
| 531 } else { | |
| 532 UNREACHABLE(); | |
| 533 } | 525 } |
| 526 DCHECK_EQ(total, live + node->InputCount() - merge->InputCount()); |
| 527 DCHECK_NE(total, node->InputCount()); |
| 528 node->TrimInputCount(total); |
| 529 node->set_op(common_->ResizeMergeOrPhi(node->op(), live)); |
| 534 } | 530 } |
| 535 | 531 |
| 536 // Replace uses of {node} with {replacement} and revisit the uses. | 532 // Replace uses of {node} with {replacement} and revisit the uses. |
| 537 void ReplaceNode(Node* node, Node* replacement) { | 533 void ReplaceNode(Node* node, Node* replacement) { |
| 538 if (node == replacement) return; | 534 if (node == replacement) return; |
| 539 TRACE((" Replace: #%d:%s with #%d:%s\n", node->id(), | 535 TRACE((" Replace: #%d:%s with #%d:%s\n", node->id(), |
| 540 node->op()->mnemonic(), replacement->id(), | 536 node->op()->mnemonic(), replacement->id(), |
| 541 replacement->op()->mnemonic())); | 537 replacement->op()->mnemonic())); |
| 542 for (Node* const use : node->uses()) { | 538 for (Node* const use : node->uses()) { |
| 543 // Don't revisit this node if it refers to itself. | 539 // Don't revisit this node if it refers to itself. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 Node* ControlReducer::ReduceBranchForTesting(JSGraph* jsgraph, | 581 Node* ControlReducer::ReduceBranchForTesting(JSGraph* jsgraph, |
| 586 CommonOperatorBuilder* common, | 582 CommonOperatorBuilder* common, |
| 587 Node* node) { | 583 Node* node) { |
| 588 Zone zone(jsgraph->graph()->zone()->isolate()); | 584 Zone zone(jsgraph->graph()->zone()->isolate()); |
| 589 ControlReducerImpl impl(&zone, jsgraph, common); | 585 ControlReducerImpl impl(&zone, jsgraph, common); |
| 590 return impl.ReduceBranch(node); | 586 return impl.ReduceBranch(node); |
| 591 } | 587 } |
| 592 } | 588 } |
| 593 } | 589 } |
| 594 } // namespace v8::internal::compiler | 590 } // namespace v8::internal::compiler |
| OLD | NEW |