| 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/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/cha.h" | 8 #include "vm/cha.h" |
| 9 #include "vm/flow_graph_builder.h" | 9 #include "vm/flow_graph_builder.h" |
| 10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
| (...skipping 3645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3656 for (intptr_t i = 0; i < defs.length(); ++i) { | 3656 for (intptr_t i = 0; i < defs.length(); ++i) { |
| 3657 defs[i]->Accept(this); | 3657 defs[i]->Accept(this); |
| 3658 } | 3658 } |
| 3659 ASSERT(ForwardInstructionIterator(block).Done()); | 3659 ASSERT(ForwardInstructionIterator(block).Done()); |
| 3660 | 3660 |
| 3661 SetReachable(block->normal_entry()); | 3661 SetReachable(block->normal_entry()); |
| 3662 } | 3662 } |
| 3663 | 3663 |
| 3664 | 3664 |
| 3665 void ConstantPropagator::VisitJoinEntry(JoinEntryInstr* block) { | 3665 void ConstantPropagator::VisitJoinEntry(JoinEntryInstr* block) { |
| 3666 ZoneGrowableArray<PhiInstr*>* phis = block->phis(); | 3666 // Phis are visited when visiting Goto at a predecessor. See VisitGoto. |
| 3667 if (phis != NULL) { | |
| 3668 for (intptr_t phi_idx = 0; phi_idx < phis->length(); ++phi_idx) { | |
| 3669 PhiInstr* phi = (*phis)[phi_idx]; | |
| 3670 if (phi == NULL) continue; | |
| 3671 phi->Accept(this); | |
| 3672 } | |
| 3673 } | |
| 3674 | |
| 3675 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { | 3667 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { |
| 3676 it.Current()->Accept(this); | 3668 it.Current()->Accept(this); |
| 3677 } | 3669 } |
| 3678 } | 3670 } |
| 3679 | 3671 |
| 3680 | 3672 |
| 3681 void ConstantPropagator::VisitTargetEntry(TargetEntryInstr* block) { | 3673 void ConstantPropagator::VisitTargetEntry(TargetEntryInstr* block) { |
| 3682 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { | 3674 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { |
| 3683 it.Current()->Accept(this); | 3675 it.Current()->Accept(this); |
| 3684 } | 3676 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3705 } | 3697 } |
| 3706 | 3698 |
| 3707 | 3699 |
| 3708 void ConstantPropagator::VisitReThrow(ReThrowInstr* instr) { | 3700 void ConstantPropagator::VisitReThrow(ReThrowInstr* instr) { |
| 3709 // Nothing to do. | 3701 // Nothing to do. |
| 3710 } | 3702 } |
| 3711 | 3703 |
| 3712 | 3704 |
| 3713 void ConstantPropagator::VisitGoto(GotoInstr* instr) { | 3705 void ConstantPropagator::VisitGoto(GotoInstr* instr) { |
| 3714 SetReachable(instr->successor()); | 3706 SetReachable(instr->successor()); |
| 3707 |
| 3708 // Phi value depends on the reachability of a predecessor. We have |
| 3709 // to revisit phis every time a predecessor becomes reachable. |
| 3710 for (PhiIterator it(instr->successor()); !it.Done(); it.Advance()) { |
| 3711 it.Current()->Accept(this); |
| 3712 } |
| 3715 } | 3713 } |
| 3716 | 3714 |
| 3717 | 3715 |
| 3718 void ConstantPropagator::VisitBranch(BranchInstr* instr) { | 3716 void ConstantPropagator::VisitBranch(BranchInstr* instr) { |
| 3719 instr->comparison()->Accept(this); | 3717 instr->comparison()->Accept(this); |
| 3720 | 3718 |
| 3721 // The successors may be reachable, but only if this instruction is. (We | 3719 // The successors may be reachable, but only if this instruction is. (We |
| 3722 // might be analyzing it because the constant value of one of its inputs | 3720 // might be analyzing it because the constant value of one of its inputs |
| 3723 // has changed.) | 3721 // has changed.) |
| 3724 if (reachable_->Contains(instr->GetBlock()->preorder_number())) { | 3722 if (reachable_->Contains(instr->GetBlock()->preorder_number())) { |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4420 | 4418 |
| 4421 if (FLAG_trace_constant_propagation) { | 4419 if (FLAG_trace_constant_propagation) { |
| 4422 OS::Print("\n==== After constant propagation ====\n"); | 4420 OS::Print("\n==== After constant propagation ====\n"); |
| 4423 FlowGraphPrinter printer(*graph_); | 4421 FlowGraphPrinter printer(*graph_); |
| 4424 printer.PrintBlocks(); | 4422 printer.PrintBlocks(); |
| 4425 } | 4423 } |
| 4426 } | 4424 } |
| 4427 | 4425 |
| 4428 | 4426 |
| 4429 } // namespace dart | 4427 } // namespace dart |
| OLD | NEW |