| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 for (intptr_t i = 0; i < graph_entry_->initial_definitions()->length(); ++i) { | 42 for (intptr_t i = 0; i < graph_entry_->initial_definitions()->length(); ++i) { |
| 43 ConstantInstr* constant = | 43 ConstantInstr* constant = |
| 44 (*graph_entry_->initial_definitions())[i]->AsConstant(); | 44 (*graph_entry_->initial_definitions())[i]->AsConstant(); |
| 45 if ((constant != NULL) && (constant->value().raw() == object.raw())) { | 45 if ((constant != NULL) && (constant->value().raw() == object.raw())) { |
| 46 return constant; | 46 return constant; |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 // Otherwise, allocate and add it to the pool. | 49 // Otherwise, allocate and add it to the pool. |
| 50 ConstantInstr* constant = new ConstantInstr(object); | 50 ConstantInstr* constant = new ConstantInstr(object); |
| 51 constant->set_ssa_temp_index(alloc_ssa_temp_index()); | 51 constant->set_ssa_temp_index(alloc_ssa_temp_index()); |
| 52 graph_entry_->initial_definitions()->Add(constant); | 52 AddToInitialDefinitions(constant); |
| 53 return constant; | 53 return constant; |
| 54 } | 54 } |
| 55 | 55 |
| 56 void FlowGraph::AddToInitialDefinitions(Definition* defn) { |
| 57 // TODO(zerny): Set previous to the graph entry so it is accessible by |
| 58 // GetBlock. Remove this once there is a direct pointer to the block. |
| 59 defn->set_previous(graph_entry_); |
| 60 graph_entry_->initial_definitions()->Add(defn); |
| 61 } |
| 62 |
| 56 | 63 |
| 57 void FlowGraph::DiscoverBlocks() { | 64 void FlowGraph::DiscoverBlocks() { |
| 58 // Initialize state. | 65 // Initialize state. |
| 59 preorder_.Clear(); | 66 preorder_.Clear(); |
| 60 postorder_.Clear(); | 67 postorder_.Clear(); |
| 61 reverse_postorder_.Clear(); | 68 reverse_postorder_.Clear(); |
| 62 parent_.Clear(); | 69 parent_.Clear(); |
| 63 assigned_vars_.Clear(); | 70 assigned_vars_.Clear(); |
| 64 // Perform a depth-first traversal of the graph to build preorder and | 71 // Perform a depth-first traversal of the graph to build preorder and |
| 65 // postorder block orders. | 72 // postorder block orders. |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 GrowableArray<Definition*>* inlining_parameters) { | 502 GrowableArray<Definition*>* inlining_parameters) { |
| 496 // TODO(fschneider): Support catch-entry. | 503 // TODO(fschneider): Support catch-entry. |
| 497 if (graph_entry_->SuccessorCount() > 1) { | 504 if (graph_entry_->SuccessorCount() > 1) { |
| 498 Bailout("Catch-entry support in SSA."); | 505 Bailout("Catch-entry support in SSA."); |
| 499 } | 506 } |
| 500 | 507 |
| 501 // Initial renaming environment. | 508 // Initial renaming environment. |
| 502 GrowableArray<Definition*> env(variable_count()); | 509 GrowableArray<Definition*> env(variable_count()); |
| 503 | 510 |
| 504 // Add global constants to the initial definitions. | 511 // Add global constants to the initial definitions. |
| 505 ConstantInstr* constant_null = new ConstantInstr(Object::ZoneHandle()); | 512 ConstantInstr* constant_null = |
| 506 constant_null->set_ssa_temp_index(alloc_ssa_temp_index()); | 513 AddConstantToInitialDefinitions(Object::ZoneHandle()); |
| 507 graph_entry_->initial_definitions()->Add(constant_null); | |
| 508 | 514 |
| 509 // Add parameters to the initial definitions and renaming environment. | 515 // Add parameters to the initial definitions and renaming environment. |
| 510 if (inlining_parameters != NULL) { | 516 if (inlining_parameters != NULL) { |
| 511 // Use known parameters. | 517 // Use known parameters. |
| 512 ASSERT(parameter_count() == inlining_parameters->length()); | 518 ASSERT(parameter_count() == inlining_parameters->length()); |
| 513 for (intptr_t i = 0; i < parameter_count(); ++i) { | 519 for (intptr_t i = 0; i < parameter_count(); ++i) { |
| 514 Definition* defn = (*inlining_parameters)[i]; | 520 Definition* defn = (*inlining_parameters)[i]; |
| 515 defn->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. | 521 defn->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. |
| 516 graph_entry_->initial_definitions()->Add(defn); | 522 AddToInitialDefinitions(defn); |
| 517 env.Add(defn); | 523 env.Add(defn); |
| 518 } | 524 } |
| 519 } else { | 525 } else { |
| 520 // Create new parameters. | 526 // Create new parameters. |
| 521 for (intptr_t i = 0; i < parameter_count(); ++i) { | 527 for (intptr_t i = 0; i < parameter_count(); ++i) { |
| 522 ParameterInstr* param = new ParameterInstr(i, graph_entry_); | 528 ParameterInstr* param = new ParameterInstr(i, graph_entry_); |
| 523 param->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. | 529 param->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. |
| 524 graph_entry_->initial_definitions()->Add(param); | 530 AddToInitialDefinitions(param); |
| 525 env.Add(param); | 531 env.Add(param); |
| 526 } | 532 } |
| 527 } | 533 } |
| 528 | 534 |
| 529 // Initialize all locals with #null in the renaming environment. | 535 // Initialize all locals with #null in the renaming environment. |
| 530 for (intptr_t i = parameter_count(); i < variable_count(); ++i) { | 536 for (intptr_t i = parameter_count(); i < variable_count(); ++i) { |
| 531 env.Add(constant_null); | 537 env.Add(constant_null); |
| 532 } | 538 } |
| 533 | 539 |
| 534 BlockEntryInstr* normal_entry = graph_entry_->SuccessorAt(0); | 540 BlockEntryInstr* normal_entry = graph_entry_->SuccessorAt(0); |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 !it.Done(); | 1008 !it.Done(); |
| 1003 it.Advance()) { | 1009 it.Advance()) { |
| 1004 ++size; | 1010 ++size; |
| 1005 } | 1011 } |
| 1006 } | 1012 } |
| 1007 return size; | 1013 return size; |
| 1008 } | 1014 } |
| 1009 | 1015 |
| 1010 | 1016 |
| 1011 } // namespace dart | 1017 } // namespace dart |
| OLD | NEW |