| 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.h" | 5 #include "vm/flow_graph.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/intermediate_language.h" | 9 #include "vm/intermediate_language.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 assigned_vars_(), | 22 assigned_vars_(), |
| 23 current_ssa_temp_index_(0), | 23 current_ssa_temp_index_(0), |
| 24 max_block_id_(max_block_id), | 24 max_block_id_(max_block_id), |
| 25 parsed_function_(builder.parsed_function()), | 25 parsed_function_(builder.parsed_function()), |
| 26 num_copied_params_(builder.num_copied_params()), | 26 num_copied_params_(builder.num_copied_params()), |
| 27 num_non_copied_params_(builder.num_non_copied_params()), | 27 num_non_copied_params_(builder.num_non_copied_params()), |
| 28 num_stack_locals_(builder.num_stack_locals()), | 28 num_stack_locals_(builder.num_stack_locals()), |
| 29 graph_entry_(graph_entry), | 29 graph_entry_(graph_entry), |
| 30 preorder_(), | 30 preorder_(), |
| 31 postorder_(), | 31 postorder_(), |
| 32 reverse_postorder_() { | 32 reverse_postorder_(), |
| 33 invalid_dominator_tree_(true) { |
| 33 DiscoverBlocks(); | 34 DiscoverBlocks(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 | 37 |
| 37 ConstantInstr* FlowGraph::AddConstantToInitialDefinitions( | 38 ConstantInstr* FlowGraph::AddConstantToInitialDefinitions( |
| 38 const Object& object) { | 39 const Object& object) { |
| 39 // Check if the constant is already in the pool. | 40 // Check if the constant is already in the pool. |
| 40 for (intptr_t i = 0; i < graph_entry_->initial_definitions()->length(); ++i) { | 41 for (intptr_t i = 0; i < graph_entry_->initial_definitions()->length(); ++i) { |
| 41 ConstantInstr* constant = | 42 ConstantInstr* constant = |
| 42 (*graph_entry_->initial_definitions())[i]->AsConstant(); | 43 (*graph_entry_->initial_definitions())[i]->AsConstant(); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 224 |
| 224 // Compute immediate dominators and the dominance frontier for each basic | 225 // Compute immediate dominators and the dominance frontier for each basic |
| 225 // block. As a side effect of the algorithm, sets the immediate dominator | 226 // block. As a side effect of the algorithm, sets the immediate dominator |
| 226 // of each basic block. | 227 // of each basic block. |
| 227 // | 228 // |
| 228 // dominance_frontier: an output parameter encoding the dominance frontier. | 229 // dominance_frontier: an output parameter encoding the dominance frontier. |
| 229 // The array maps the preorder block number of a block to the set of | 230 // The array maps the preorder block number of a block to the set of |
| 230 // (preorder block numbers of) blocks in the dominance frontier. | 231 // (preorder block numbers of) blocks in the dominance frontier. |
| 231 void FlowGraph::ComputeDominators( | 232 void FlowGraph::ComputeDominators( |
| 232 GrowableArray<BitVector*>* dominance_frontier) { | 233 GrowableArray<BitVector*>* dominance_frontier) { |
| 234 invalid_dominator_tree_ = false; |
| 233 // Use the SEMI-NCA algorithm to compute dominators. This is a two-pass | 235 // Use the SEMI-NCA algorithm to compute dominators. This is a two-pass |
| 234 // version of the Lengauer-Tarjan algorithm (LT is normally three passes) | 236 // version of the Lengauer-Tarjan algorithm (LT is normally three passes) |
| 235 // that eliminates a pass by using nearest-common ancestor (NCA) to | 237 // that eliminates a pass by using nearest-common ancestor (NCA) to |
| 236 // compute immediate dominators from semidominators. It also removes a | 238 // compute immediate dominators from semidominators. It also removes a |
| 237 // level of indirection in the link-eval forest data structure. | 239 // level of indirection in the link-eval forest data structure. |
| 238 // | 240 // |
| 239 // The algorithm is described in Georgiadis, Tarjan, and Werneck's | 241 // The algorithm is described in Georgiadis, Tarjan, and Werneck's |
| 240 // "Finding Dominators in Practice". | 242 // "Finding Dominators in Practice". |
| 241 // See http://www.cs.princeton.edu/~rwerneck/dominators/ . | 243 // See http://www.cs.princeton.edu/~rwerneck/dominators/ . |
| 242 | 244 |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 const char* function_name = parsed_function_.function().ToCString(); | 666 const char* function_name = parsed_function_.function().ToCString(); |
| 665 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 667 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
| 666 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 668 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 667 OS::SNPrint(chars, len, kFormat, function_name, reason); | 669 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 668 const Error& error = Error::Handle( | 670 const Error& error = Error::Handle( |
| 669 LanguageError::New(String::Handle(String::New(chars)))); | 671 LanguageError::New(String::Handle(String::New(chars)))); |
| 670 Isolate::Current()->long_jump_base()->Jump(1, error); | 672 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 671 } | 673 } |
| 672 | 674 |
| 673 | 675 |
| 676 void FlowGraph::RepairGraphAfterInlining() { |
| 677 DiscoverBlocks(); |
| 678 if (invalid_dominator_tree_) { |
| 679 GrowableArray<BitVector*> dominance_frontier; |
| 680 ComputeDominators(&dominance_frontier); |
| 681 } |
| 682 } |
| 683 |
| 684 |
| 674 intptr_t FlowGraph::InstructionCount() const { | 685 intptr_t FlowGraph::InstructionCount() const { |
| 675 intptr_t size = 0; | 686 intptr_t size = 0; |
| 676 // Iterate each block, skipping the graph entry. | 687 // Iterate each block, skipping the graph entry. |
| 677 for (intptr_t i = 1; i < preorder_.length(); ++i) { | 688 for (intptr_t i = 1; i < preorder_.length(); ++i) { |
| 678 for (ForwardInstructionIterator it(preorder_[i]); | 689 for (ForwardInstructionIterator it(preorder_[i]); |
| 679 !it.Done(); | 690 !it.Done(); |
| 680 it.Advance()) { | 691 it.Advance()) { |
| 681 ++size; | 692 ++size; |
| 682 } | 693 } |
| 683 } | 694 } |
| 684 return size; | 695 return size; |
| 685 } | 696 } |
| 686 | 697 |
| 687 } // namespace dart | 698 } // namespace dart |
| OLD | NEW |