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

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

Issue 10806047: Fix crash during parallel moves. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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_compiler.h ('k') | runtime/vm/flow_graph_compiler_ia32.cc » ('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/globals.h" // Needed here to get TARGET_ARCH_XXX. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_XXX.
6 6
7 #include "vm/flow_graph_compiler.h" 7 #include "vm/flow_graph_compiler.h"
8 8
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/debugger.h" 10 #include "vm/debugger.h"
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 ParallelMoveResolver::ParallelMoveResolver(FlowGraphCompiler* compiler) 692 ParallelMoveResolver::ParallelMoveResolver(FlowGraphCompiler* compiler)
693 : compiler_(compiler), moves_(32) {} 693 : compiler_(compiler), moves_(32) {}
694 694
695 695
696 void ParallelMoveResolver::EmitNativeCode(ParallelMoveInstr* parallel_move) { 696 void ParallelMoveResolver::EmitNativeCode(ParallelMoveInstr* parallel_move) {
697 ASSERT(moves_.is_empty()); 697 ASSERT(moves_.is_empty());
698 // Build up a worklist of moves. 698 // Build up a worklist of moves.
699 BuildInitialMoveList(parallel_move); 699 BuildInitialMoveList(parallel_move);
700 700
701 for (int i = 0; i < moves_.length(); ++i) { 701 for (int i = 0; i < moves_.length(); ++i) {
702 MoveOperands move = moves_[i]; 702 const MoveOperands& move = *moves_[i];
703 // Skip constants to perform them last. They don't block other moves 703 // Skip constants to perform them last. They don't block other moves
704 // and skipping such moves with register destinations keeps those 704 // and skipping such moves with register destinations keeps those
705 // registers free for the whole algorithm. 705 // registers free for the whole algorithm.
706 if (!move.IsEliminated() && !move.src().IsConstant()) PerformMove(i); 706 if (!move.IsEliminated() && !move.src().IsConstant()) PerformMove(i);
707 } 707 }
708 708
709 // Perform the moves with constant sources. 709 // Perform the moves with constant sources.
710 for (int i = 0; i < moves_.length(); ++i) { 710 for (int i = 0; i < moves_.length(); ++i) {
711 if (!moves_[i].IsEliminated()) { 711 const MoveOperands& move = *moves_[i];
712 ASSERT(moves_[i].src().IsConstant()); 712 if (!move.IsEliminated()) {
713 ASSERT(move.src().IsConstant());
713 EmitMove(i); 714 EmitMove(i);
714 } 715 }
715 } 716 }
716 717
717 moves_.Clear(); 718 moves_.Clear();
718 } 719 }
719 720
720 721
721 void ParallelMoveResolver::BuildInitialMoveList( 722 void ParallelMoveResolver::BuildInitialMoveList(
722 ParallelMoveInstr* parallel_move) { 723 ParallelMoveInstr* parallel_move) {
723 // Perform a linear sweep of the moves to add them to the initial list of 724 // Perform a linear sweep of the moves to add them to the initial list of
724 // moves to perform, ignoring any move that is redundant (the source is 725 // moves to perform, ignoring any move that is redundant (the source is
725 // the same as the destination, the destination is ignored and 726 // the same as the destination, the destination is ignored and
726 // unallocated, or the move was already eliminated). 727 // unallocated, or the move was already eliminated).
727 const GrowableArray<MoveOperands>& moves = parallel_move->moves(); 728 for (int i = 0; i < parallel_move->NumMoves(); i++) {
728 for (int i = 0; i < moves.length(); ++i) { 729 MoveOperands* move = parallel_move->MoveOperandsAt(i);
729 MoveOperands move = moves[i]; 730 if (!move->IsRedundant()) moves_.Add(move);
730 if (!move.IsRedundant()) moves_.Add(move);
731 } 731 }
732 } 732 }
733 733
734 734
735 void ParallelMoveResolver::PerformMove(int index) { 735 void ParallelMoveResolver::PerformMove(int index) {
736 // Each call to this function performs a move and deletes it from the move 736 // Each call to this function performs a move and deletes it from the move
737 // graph. We first recursively perform any move blocking this one. We 737 // graph. We first recursively perform any move blocking this one. We
738 // mark a move as "pending" on entry to PerformMove in order to detect 738 // mark a move as "pending" on entry to PerformMove in order to detect
739 // cycles in the move graph. We use operand swaps to resolve cycles, 739 // cycles in the move graph. We use operand swaps to resolve cycles,
740 // which means that a call to PerformMove could change any source operand 740 // which means that a call to PerformMove could change any source operand
741 // in the move graph. 741 // in the move graph.
742 742
743 ASSERT(!moves_[index].IsPending()); 743 ASSERT(!moves_[index]->IsPending());
744 ASSERT(!moves_[index].IsRedundant()); 744 ASSERT(!moves_[index]->IsRedundant());
745 745
746 // Clear this move's destination to indicate a pending move. The actual 746 // Clear this move's destination to indicate a pending move. The actual
747 // destination is saved in a stack-allocated local. Recursion may allow 747 // destination is saved in a stack-allocated local. Recursion may allow
748 // multiple moves to be pending. 748 // multiple moves to be pending.
749 ASSERT(!moves_[index].src().IsInvalid()); 749 ASSERT(!moves_[index]->src().IsInvalid());
750 Location destination = moves_[index].MarkPending(); 750 Location destination = moves_[index]->MarkPending();
751 751
752 // Perform a depth-first traversal of the move graph to resolve 752 // Perform a depth-first traversal of the move graph to resolve
753 // dependencies. Any unperformed, unpending move with a source the same 753 // dependencies. Any unperformed, unpending move with a source the same
754 // as this one's destination blocks this one so recursively perform all 754 // as this one's destination blocks this one so recursively perform all
755 // such moves. 755 // such moves.
756 for (int i = 0; i < moves_.length(); ++i) { 756 for (int i = 0; i < moves_.length(); ++i) {
757 MoveOperands other_move = moves_[i]; 757 const MoveOperands& other_move = *moves_[i];
758 if (other_move.Blocks(destination) && !other_move.IsPending()) { 758 if (other_move.Blocks(destination) && !other_move.IsPending()) {
759 // Though PerformMove can change any source operand in the move graph, 759 // Though PerformMove can change any source operand in the move graph,
760 // this call cannot create a blocking move via a swap (this loop does 760 // this call cannot create a blocking move via a swap (this loop does
761 // not miss any). Assume there is a non-blocking move with source A 761 // not miss any). Assume there is a non-blocking move with source A
762 // and this move is blocked on source B and there is a swap of A and 762 // and this move is blocked on source B and there is a swap of A and
763 // B. Then A and B must be involved in the same cycle (or they would 763 // B. Then A and B must be involved in the same cycle (or they would
764 // not be swapped). Since this move's destination is B and there is 764 // not be swapped). Since this move's destination is B and there is
765 // only a single incoming edge to an operand, this move must also be 765 // only a single incoming edge to an operand, this move must also be
766 // involved in the same cycle. In that case, the blocking move will 766 // involved in the same cycle. In that case, the blocking move will
767 // be created but will be "pending" when we return from PerformMove. 767 // be created but will be "pending" when we return from PerformMove.
768 PerformMove(i); 768 PerformMove(i);
769 } 769 }
770 } 770 }
771 771
772 // We are about to resolve this move and don't need it marked as 772 // We are about to resolve this move and don't need it marked as
773 // pending, so restore its destination. 773 // pending, so restore its destination.
774 moves_[index].ClearPending(destination); 774 moves_[index]->ClearPending(destination);
775 775
776 // This move's source may have changed due to swaps to resolve cycles and 776 // This move's source may have changed due to swaps to resolve cycles and
777 // so it may now be the last move in the cycle. If so remove it. 777 // so it may now be the last move in the cycle. If so remove it.
778 if (moves_[index].src().Equals(destination)) { 778 if (moves_[index]->src().Equals(destination)) {
779 moves_[index].Eliminate(); 779 moves_[index]->Eliminate();
780 return; 780 return;
781 } 781 }
782 782
783 // The move may be blocked on a (at most one) pending move, in which case 783 // The move may be blocked on a (at most one) pending move, in which case
784 // we have a cycle. Search for such a blocking move and perform a swap to 784 // we have a cycle. Search for such a blocking move and perform a swap to
785 // resolve it. 785 // resolve it.
786 for (int i = 0; i < moves_.length(); ++i) { 786 for (int i = 0; i < moves_.length(); ++i) {
787 MoveOperands other_move = moves_[i]; 787 const MoveOperands& other_move = *moves_[i];
788 if (other_move.Blocks(destination)) { 788 if (other_move.Blocks(destination)) {
789 ASSERT(other_move.IsPending()); 789 ASSERT(other_move.IsPending());
790 EmitSwap(index); 790 EmitSwap(index);
791 return; 791 return;
792 } 792 }
793 } 793 }
794 794
795 // This move is not blocked. 795 // This move is not blocked.
796 EmitMove(index); 796 EmitMove(index);
797 } 797 }
798 798
799 799
800 } // namespace dart 800 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_compiler.h ('k') | runtime/vm/flow_graph_compiler_ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698