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

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

Issue 617933003: Iterative graph traversal in FlowGraph::DiscoverBlocks() (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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
« runtime/vm/flow_graph.cc ('K') | « runtime/vm/intermediate_language.h ('k') | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/cpu.h" 8 #include "vm/cpu.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flow_graph_allocator.h" 10 #include "vm/flow_graph_allocator.h"
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 // preorder array and (2) being in the preorder array at that index. 831 // preorder array and (2) being in the preorder array at that index.
832 intptr_t i = block->preorder_number(); 832 intptr_t i = block->preorder_number();
833 return (i >= 0) && (i < preorder->length()) && ((*preorder)[i] == block); 833 return (i >= 0) && (i < preorder->length()) && ((*preorder)[i] == block);
834 } 834 }
835 835
836 836
837 // Base class implementation used for JoinEntry and TargetEntry. 837 // Base class implementation used for JoinEntry and TargetEntry.
838 void BlockEntryInstr::DiscoverBlocks( 838 void BlockEntryInstr::DiscoverBlocks(
839 BlockEntryInstr* predecessor, 839 BlockEntryInstr* predecessor,
840 GrowableArray<BlockEntryInstr*>* preorder, 840 GrowableArray<BlockEntryInstr*>* preorder,
841 GrowableArray<BlockEntryInstr*>* postorder,
842 GrowableArray<intptr_t>* parent, 841 GrowableArray<intptr_t>* parent,
843 intptr_t variable_count, 842 GrowableArray<BlockEntryEdge>* block_stack) {
844 intptr_t fixed_parameter_count) {
845 // If this block has a predecessor (i.e., is not the graph entry) we can 843 // If this block has a predecessor (i.e., is not the graph entry) we can
846 // assume the preorder array is non-empty. 844 // assume the preorder array is non-empty.
847 ASSERT((predecessor == NULL) || !preorder->is_empty()); 845 ASSERT((predecessor == NULL) || !preorder->is_empty());
848 // Blocks with a single predecessor cannot have been reached before. 846 // Blocks with a single predecessor cannot have been reached before.
849 ASSERT(IsJoinEntry() || !IsMarked(this, preorder)); 847 ASSERT(IsJoinEntry() || !IsMarked(this, preorder));
850 848
851 // 1. If the block has already been reached, add current_block as a 849 // 1. If the block has already been reached, add current_block as a
852 // basic-block predecessor and we are done. 850 // basic-block predecessor and we are done.
853 if (IsMarked(this, preorder)) { 851 if (IsMarked(this, preorder)) {
854 ASSERT(predecessor != NULL); 852 ASSERT(predecessor != NULL);
(...skipping 23 matching lines...) Expand all
878 // 5. Iterate straight-line successors to record assigned variables and 876 // 5. Iterate straight-line successors to record assigned variables and
879 // find the last instruction in the block. The graph entry block consists 877 // find the last instruction in the block. The graph entry block consists
880 // of only the entry instruction, so that is the last instruction in the 878 // of only the entry instruction, so that is the last instruction in the
881 // block. 879 // block.
882 Instruction* last = this; 880 Instruction* last = this;
883 for (ForwardInstructionIterator it(this); !it.Done(); it.Advance()) { 881 for (ForwardInstructionIterator it(this); !it.Done(); it.Advance()) {
884 last = it.Current(); 882 last = it.Current();
885 } 883 }
886 set_last_instruction(last); 884 set_last_instruction(last);
887 885
888 // Visit the block's successors in reverse so that they appear forwards 886 // Push the block's successors in reverse so that they are visited from left
889 // the reverse postorder block ordering. 887 // to right.
890 for (intptr_t i = last->SuccessorCount() - 1; i >= 0; --i) { 888 for (intptr_t i = last->SuccessorCount() - 1; i >= 0; --i) {
891 last->SuccessorAt(i)->DiscoverBlocks(this, 889 block_stack->Add(BlockEntryEdge(this, last->SuccessorAt(i)));
892 preorder,
893 postorder,
894 parent,
895 variable_count,
896 fixed_parameter_count);
897 } 890 }
898
899 // 6. Assign postorder number and add the block entry to the list.
900 set_postorder_number(postorder->length());
901 postorder->Add(this);
902 } 891 }
903 892
904 893
905 bool BlockEntryInstr::PruneUnreachable(FlowGraphBuilder* builder, 894 bool BlockEntryInstr::PruneUnreachable(FlowGraphBuilder* builder,
906 GraphEntryInstr* graph_entry, 895 GraphEntryInstr* graph_entry,
907 Instruction* parent, 896 Instruction* parent,
908 intptr_t osr_id, 897 intptr_t osr_id,
909 BitVector* block_marks) { 898 BitVector* block_marks) {
910 // Search for the instruction with the OSR id. Use a depth first search 899 // Search for the instruction with the OSR id. Use a depth first search
911 // because basic blocks have not been discovered yet. Prune unreachable 900 // because basic blocks have not been discovered yet. Prune unreachable
(...skipping 2408 matching lines...) Expand 10 before | Expand all | Expand 10 after
3320 case Token::kTRUNCDIV: return 0; 3309 case Token::kTRUNCDIV: return 0;
3321 case Token::kMOD: return 1; 3310 case Token::kMOD: return 1;
3322 default: UNIMPLEMENTED(); return -1; 3311 default: UNIMPLEMENTED(); return -1;
3323 } 3312 }
3324 } 3313 }
3325 3314
3326 3315
3327 #undef __ 3316 #undef __
3328 3317
3329 } // namespace dart 3318 } // namespace dart
OLDNEW
« runtime/vm/flow_graph.cc ('K') | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698