Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: runtime/vm/flow_graph_optimizer.cc

Issue 11824024: Constant propagator should revisit phis when it visits predecessor block. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | tests/language/constant_propagation_phis_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 predecessor. See VisitSuccessorPhis.
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 }
3670
3671 VisitSuccessorPhis(block);
3678 } 3672 }
3679 3673
3680 3674
3681 void ConstantPropagator::VisitTargetEntry(TargetEntryInstr* block) { 3675 void ConstantPropagator::VisitTargetEntry(TargetEntryInstr* block) {
3682 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { 3676 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) {
3683 it.Current()->Accept(this); 3677 it.Current()->Accept(this);
3684 } 3678 }
3679
3680 VisitSuccessorPhis(block);
3685 } 3681 }
3686 3682
3687 3683
3688 void ConstantPropagator::VisitParallelMove(ParallelMoveInstr* instr) { 3684 void ConstantPropagator::VisitParallelMove(ParallelMoveInstr* instr) {
3689 // Parallel moves have not yet been inserted in the graph. 3685 // Parallel moves have not yet been inserted in the graph.
3690 UNREACHABLE(); 3686 UNREACHABLE();
3691 } 3687 }
3692 3688
3693 3689
3690 void ConstantPropagator::VisitSuccessorPhis(BlockEntryInstr* block) {
3691 // Phi value depends on the reachability of a predecessor. We have
3692 // to revisit phis every time a predecessor becomes reachable.
3693 GotoInstr* goto_instr = block->last_instruction()->AsGoto();
3694 if (goto_instr != NULL) {
3695 for (PhiIterator it(goto_instr->successor()); !it.Done(); it.Advance()) {
3696 it.Current()->Accept(this);
3697 }
3698 }
3699 }
3700
3701
3694 // -------------------------------------------------------------------------- 3702 // --------------------------------------------------------------------------
3695 // Analysis of control instructions. Unconditional successors are 3703 // Analysis of control instructions. Unconditional successors are
3696 // reachable. Conditional successors are reachable depending on the 3704 // reachable. Conditional successors are reachable depending on the
3697 // constant value of the condition. 3705 // constant value of the condition.
3698 void ConstantPropagator::VisitReturn(ReturnInstr* instr) { 3706 void ConstantPropagator::VisitReturn(ReturnInstr* instr) {
3699 // Nothing to do. 3707 // Nothing to do.
3700 } 3708 }
3701 3709
3702 3710
3703 void ConstantPropagator::VisitThrow(ThrowInstr* instr) { 3711 void ConstantPropagator::VisitThrow(ThrowInstr* instr) {
3704 // Nothing to do. 3712 // Nothing to do.
3705 } 3713 }
3706 3714
3707 3715
3708 void ConstantPropagator::VisitReThrow(ReThrowInstr* instr) { 3716 void ConstantPropagator::VisitReThrow(ReThrowInstr* instr) {
3709 // Nothing to do. 3717 // Nothing to do.
3710 } 3718 }
3711 3719
3712 3720
3713 void ConstantPropagator::VisitGoto(GotoInstr* instr) { 3721 void ConstantPropagator::VisitGoto(GotoInstr* instr) {
3714 SetReachable(instr->successor()); 3722 SetReachable(instr->successor());
Kevin Millikin (Google) 2013/01/09 12:20:10 It seems simpler to move VisitSuccessorPhis here.
3715 } 3723 }
3716 3724
3717 3725
3718 void ConstantPropagator::VisitBranch(BranchInstr* instr) { 3726 void ConstantPropagator::VisitBranch(BranchInstr* instr) {
3719 instr->comparison()->Accept(this); 3727 instr->comparison()->Accept(this);
3720 3728
3721 // The successors may be reachable, but only if this instruction is. (We 3729 // 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 3730 // might be analyzing it because the constant value of one of its inputs
3723 // has changed.) 3731 // has changed.)
3724 if (reachable_->Contains(instr->GetBlock()->preorder_number())) { 3732 if (reachable_->Contains(instr->GetBlock()->preorder_number())) {
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
4420 4428
4421 if (FLAG_trace_constant_propagation) { 4429 if (FLAG_trace_constant_propagation) {
4422 OS::Print("\n==== After constant propagation ====\n"); 4430 OS::Print("\n==== After constant propagation ====\n");
4423 FlowGraphPrinter printer(*graph_); 4431 FlowGraphPrinter printer(*graph_);
4424 printer.PrintBlocks(); 4432 printer.PrintBlocks();
4425 } 4433 }
4426 } 4434 }
4427 4435
4428 4436
4429 } // namespace dart 4437 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | tests/language/constant_propagation_phis_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698