| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/flow_graph_optimizer.h" | 5 #include "vm/flow_graph_optimizer.h" |
| 6 | 6 |
| 7 #include "vm/flow_graph_builder.h" | 7 #include "vm/flow_graph_builder.h" |
| 8 #include "vm/il_printer.h" | 8 #include "vm/il_printer.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 | 10 |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 523 |
| 524 const intptr_t class_id = ReceiverClassId(comp); | 524 const intptr_t class_id = ReceiverClassId(comp); |
| 525 switch (class_id) { | 525 switch (class_id) { |
| 526 case kArray: | 526 case kArray: |
| 527 case kGrowableObjectArray: | 527 case kGrowableObjectArray: |
| 528 comp->set_receiver_type(static_cast<ObjectKind>(class_id)); | 528 comp->set_receiver_type(static_cast<ObjectKind>(class_id)); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 | 532 |
| 533 static void TryFuseComparisonWithBranch(ComparisonComp* comp) { |
| 534 Instruction* instr = comp->instr(); |
| 535 Instruction* next_instr = instr->StraightLineSuccessor(); |
| 536 if (next_instr != NULL && next_instr->IsBranch()) { |
| 537 BranchInstr* branch = next_instr->AsBranch(); |
| 538 UseVal* use = branch->value()->AsUse(); |
| 539 if (instr == use->definition()) { |
| 540 comp->MarkFusedWithBranch(branch); |
| 541 branch->MarkFusedWithComparison(); |
| 542 } |
| 543 } |
| 544 } |
| 545 |
| 546 |
| 533 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpComp* comp) { | 547 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpComp* comp) { |
| 534 if (!comp->HasICData()) return; | 548 if (!comp->HasICData()) return; |
| 535 | 549 |
| 536 const ICData& ic_data = *comp->ic_data(); | 550 const ICData& ic_data = *comp->ic_data(); |
| 537 if (ic_data.NumberOfChecks() == 0) return; | 551 if (ic_data.NumberOfChecks() == 0) return; |
| 538 // TODO(srdjan): Add multiple receiver type support. | 552 // TODO(srdjan): Add multiple receiver type support. |
| 539 if (ic_data.NumberOfChecks() != 1) return; | 553 if (ic_data.NumberOfChecks() != 1) return; |
| 540 ASSERT(HasOneTarget(ic_data)); | 554 ASSERT(HasOneTarget(ic_data)); |
| 541 | 555 |
| 542 if (HasTwoSmi(ic_data)) { | 556 if (HasTwoSmi(ic_data)) { |
| 543 comp->set_operands_class_id(kSmi); | 557 comp->set_operands_class_id(kSmi); |
| 544 } else if (HasTwoDouble(ic_data)) { | 558 } else if (HasTwoDouble(ic_data)) { |
| 545 comp->set_operands_class_id(kDouble); | 559 comp->set_operands_class_id(kDouble); |
| 560 } else { |
| 561 return; |
| 546 } | 562 } |
| 563 |
| 564 // For smi and double comparisons if the next instruction is a conditional |
| 565 // branch that uses the value of this comparison mark them as fused together |
| 566 // to avoid materializing a boolean value. |
| 567 // TODO(vegorov): recognize the pattern with BooleanNegate between comparsion |
| 568 // and a branch. |
| 569 TryFuseComparisonWithBranch(comp); |
| 547 } | 570 } |
| 548 | 571 |
| 549 | 572 |
| 573 void FlowGraphOptimizer::VisitStrictCompareComp(StrictCompareComp* comp) { |
| 574 // TODO(vegorov): recognize the pattern with BooleanNegate between comparsion |
| 575 // and a branch. |
| 576 TryFuseComparisonWithBranch(comp); |
| 577 } |
| 578 |
| 579 |
| 580 void FlowGraphOptimizer::VisitEqualityCompare(EqualityCompareComp* comp) { |
| 581 // TODO(vegorov): recognize the pattern with BooleanNegate between comparsion |
| 582 // and a branch. |
| 583 TryFuseComparisonWithBranch(comp); |
| 584 } |
| 585 |
| 586 |
| 550 void FlowGraphOptimizer::VisitDo(DoInstr* instr) { | 587 void FlowGraphOptimizer::VisitDo(DoInstr* instr) { |
| 551 instr->computation()->Accept(this); | 588 instr->computation()->Accept(this); |
| 552 } | 589 } |
| 553 | 590 |
| 554 | 591 |
| 555 void FlowGraphOptimizer::VisitBind(BindInstr* instr) { | 592 void FlowGraphOptimizer::VisitBind(BindInstr* instr) { |
| 556 instr->computation()->Accept(this); | 593 instr->computation()->Accept(this); |
| 557 } | 594 } |
| 558 | 595 |
| 559 | 596 |
| 560 } // namespace dart | 597 } // namespace dart |
| OLD | NEW |