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

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: Addressed comments. 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 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 // Detect that a block has been visited as part of the current 856 // Detect that a block has been visited as part of the current
857 // DiscoverBlocks (we can call DiscoverBlocks multiple times). The block 857 // DiscoverBlocks (we can call DiscoverBlocks multiple times). The block
858 // will be 'marked' by (1) having a preorder number in the range of the 858 // will be 'marked' by (1) having a preorder number in the range of the
859 // preorder array and (2) being in the preorder array at that index. 859 // preorder array and (2) being in the preorder array at that index.
860 intptr_t i = block->preorder_number(); 860 intptr_t i = block->preorder_number();
861 return (i >= 0) && (i < preorder->length()) && ((*preorder)[i] == block); 861 return (i >= 0) && (i < preorder->length()) && ((*preorder)[i] == block);
862 } 862 }
863 863
864 864
865 // Base class implementation used for JoinEntry and TargetEntry. 865 // Base class implementation used for JoinEntry and TargetEntry.
866 void BlockEntryInstr::DiscoverBlocks( 866 bool BlockEntryInstr::DiscoverBlock(
867 BlockEntryInstr* predecessor, 867 BlockEntryInstr* predecessor,
868 GrowableArray<BlockEntryInstr*>* preorder, 868 GrowableArray<BlockEntryInstr*>* preorder,
869 GrowableArray<BlockEntryInstr*>* postorder, 869 GrowableArray<intptr_t>* parent) {
870 GrowableArray<intptr_t>* parent,
871 intptr_t variable_count,
872 intptr_t fixed_parameter_count) {
873 // If this block has a predecessor (i.e., is not the graph entry) we can 870 // If this block has a predecessor (i.e., is not the graph entry) we can
874 // assume the preorder array is non-empty. 871 // assume the preorder array is non-empty.
875 ASSERT((predecessor == NULL) || !preorder->is_empty()); 872 ASSERT((predecessor == NULL) || !preorder->is_empty());
876 // Blocks with a single predecessor cannot have been reached before. 873 // Blocks with a single predecessor cannot have been reached before.
877 ASSERT(IsJoinEntry() || !IsMarked(this, preorder)); 874 ASSERT(IsJoinEntry() || !IsMarked(this, preorder));
878 875
879 // 1. If the block has already been reached, add current_block as a 876 // 1. If the block has already been reached, add current_block as a
880 // basic-block predecessor and we are done. 877 // basic-block predecessor and we are done.
881 if (IsMarked(this, preorder)) { 878 if (IsMarked(this, preorder)) {
882 ASSERT(predecessor != NULL); 879 ASSERT(predecessor != NULL);
883 AddPredecessor(predecessor); 880 AddPredecessor(predecessor);
884 return; 881 return false;
885 } 882 }
886 883
887 // 2. Otherwise, clear the predecessors which might have been computed on 884 // 2. Otherwise, clear the predecessors which might have been computed on
888 // some earlier call to DiscoverBlocks and record this predecessor. 885 // some earlier call to DiscoverBlocks and record this predecessor.
889 ClearPredecessors(); 886 ClearPredecessors();
890 if (predecessor != NULL) AddPredecessor(predecessor); 887 if (predecessor != NULL) AddPredecessor(predecessor);
891 888
892 // 3. The predecessor is the spanning-tree parent. The graph entry has no 889 // 3. The predecessor is the spanning-tree parent. The graph entry has no
893 // parent, indicated by -1. 890 // parent, indicated by -1.
894 intptr_t parent_number = 891 intptr_t parent_number =
(...skipping 11 matching lines...) Expand all
906 // 5. Iterate straight-line successors to record assigned variables and 903 // 5. Iterate straight-line successors to record assigned variables and
907 // find the last instruction in the block. The graph entry block consists 904 // find the last instruction in the block. The graph entry block consists
908 // of only the entry instruction, so that is the last instruction in the 905 // of only the entry instruction, so that is the last instruction in the
909 // block. 906 // block.
910 Instruction* last = this; 907 Instruction* last = this;
911 for (ForwardInstructionIterator it(this); !it.Done(); it.Advance()) { 908 for (ForwardInstructionIterator it(this); !it.Done(); it.Advance()) {
912 last = it.Current(); 909 last = it.Current();
913 } 910 }
914 set_last_instruction(last); 911 set_last_instruction(last);
915 912
916 // Visit the block's successors in reverse so that they appear forwards 913 return true;
917 // the reverse postorder block ordering.
918 for (intptr_t i = last->SuccessorCount() - 1; i >= 0; --i) {
919 last->SuccessorAt(i)->DiscoverBlocks(this,
920 preorder,
921 postorder,
922 parent,
923 variable_count,
924 fixed_parameter_count);
925 }
926
927 // 6. Assign postorder number and add the block entry to the list.
928 set_postorder_number(postorder->length());
929 postorder->Add(this);
930 } 914 }
931 915
932 916
933 bool BlockEntryInstr::PruneUnreachable(FlowGraphBuilder* builder, 917 bool BlockEntryInstr::PruneUnreachable(FlowGraphBuilder* builder,
934 GraphEntryInstr* graph_entry, 918 GraphEntryInstr* graph_entry,
935 Instruction* parent, 919 Instruction* parent,
936 intptr_t osr_id, 920 intptr_t osr_id,
937 BitVector* block_marks) { 921 BitVector* block_marks) {
938 // Search for the instruction with the OSR id. Use a depth first search 922 // Search for the instruction with the OSR id. Use a depth first search
939 // because basic blocks have not been discovered yet. Prune unreachable 923 // because basic blocks have not been discovered yet. Prune unreachable
(...skipping 2432 matching lines...) Expand 10 before | Expand all | Expand 10 after
3372 case Token::kTRUNCDIV: return 0; 3356 case Token::kTRUNCDIV: return 0;
3373 case Token::kMOD: return 1; 3357 case Token::kMOD: return 1;
3374 default: UNIMPLEMENTED(); return -1; 3358 default: UNIMPLEMENTED(); return -1;
3375 } 3359 }
3376 } 3360 }
3377 3361
3378 3362
3379 #undef __ 3363 #undef __
3380 3364
3381 } // namespace dart 3365 } // 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