| 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_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "vm/ast_printer.h" | 7 #include "vm/ast_printer.h" |
| 8 #include "vm/code_descriptors.h" | 8 #include "vm/code_descriptors.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree."); | 24 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree."); |
| 25 | 25 |
| 26 | 26 |
| 27 FlowGraphBuilder::FlowGraphBuilder(const ParsedFunction& parsed_function) | 27 FlowGraphBuilder::FlowGraphBuilder(const ParsedFunction& parsed_function) |
| 28 : parsed_function_(parsed_function), | 28 : parsed_function_(parsed_function), |
| 29 preorder_block_entries_(), | 29 preorder_block_entries_(), |
| 30 postorder_block_entries_(), | 30 postorder_block_entries_(), |
| 31 context_level_(0), | 31 context_level_(0), |
| 32 last_used_try_index_(CatchClauseNode::kInvalidTryIndex), | 32 last_used_try_index_(CatchClauseNode::kInvalidTryIndex), |
| 33 try_index_(CatchClauseNode::kInvalidTryIndex), | 33 try_index_(CatchClauseNode::kInvalidTryIndex), |
| 34 catch_entries_() {} | 34 graph_entry_(NULL) {} |
| 35 | 35 |
| 36 | 36 |
| 37 void FlowGraphBuilder::AddCatchEntry(intptr_t try_index, Instruction* entry) { | 37 void FlowGraphBuilder::AddCatchEntry(TargetEntryInstr* entry) { |
| 38 catch_entries_.Add(entry); | 38 graph_entry_->AddCatchEntry(entry); |
| 39 } | 39 } |
| 40 | 40 |
| 41 | 41 |
| 42 void EffectGraphVisitor::Append(const EffectGraphVisitor& other_fragment) { | 42 void EffectGraphVisitor::Append(const EffectGraphVisitor& other_fragment) { |
| 43 ASSERT(is_open()); | 43 ASSERT(is_open()); |
| 44 if (other_fragment.is_empty()) return; | 44 if (other_fragment.is_empty()) return; |
| 45 if (is_empty()) { | 45 if (is_empty()) { |
| 46 entry_ = other_fragment.entry(); | 46 entry_ = other_fragment.entry(); |
| 47 exit_ = other_fragment.exit(); | 47 exit_ = other_fragment.exit(); |
| 48 } else { | 48 } else { |
| (...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2006 // We are done generating code for the try block. | 2006 // We are done generating code for the try block. |
| 2007 owner()->set_try_index(old_try_index); | 2007 owner()->set_try_index(old_try_index); |
| 2008 | 2008 |
| 2009 CatchClauseNode* catch_block = node->catch_block(); | 2009 CatchClauseNode* catch_block = node->catch_block(); |
| 2010 if (catch_block != NULL) { | 2010 if (catch_block != NULL) { |
| 2011 // Set the corresponding try index for this catch block so | 2011 // Set the corresponding try index for this catch block so |
| 2012 // that we can set the appropriate handler pc when we generate | 2012 // that we can set the appropriate handler pc when we generate |
| 2013 // code for this catch block. | 2013 // code for this catch block. |
| 2014 catch_block->set_try_index(try_index); | 2014 catch_block->set_try_index(try_index); |
| 2015 EffectGraphVisitor for_catch_block(owner(), temp_index()); | 2015 EffectGraphVisitor for_catch_block(owner(), temp_index()); |
| 2016 for_catch_block.AddInstruction(new TargetEntryInstr(try_index)); | 2016 TargetEntryInstr* catch_entry = new TargetEntryInstr(try_index); |
| 2017 for_catch_block.AddInstruction(catch_entry); |
| 2017 catch_block->Visit(&for_catch_block); | 2018 catch_block->Visit(&for_catch_block); |
| 2018 owner()->AddCatchEntry(try_index, for_catch_block.entry()); | 2019 owner()->AddCatchEntry(catch_entry); |
| 2019 ASSERT(!for_catch_block.is_open()); | 2020 ASSERT(!for_catch_block.is_open()); |
| 2020 if ((node->end_catch_label() != NULL) && | 2021 if ((node->end_catch_label() != NULL) && |
| 2021 (node->end_catch_label()->join_for_continue() != NULL)) { | 2022 (node->end_catch_label()->join_for_continue() != NULL)) { |
| 2022 if (is_open()) { | 2023 if (is_open()) { |
| 2023 AddInstruction(node->end_catch_label()->join_for_continue()); | 2024 AddInstruction(node->end_catch_label()->join_for_continue()); |
| 2024 } else { | 2025 } else { |
| 2025 exit_ = node->end_catch_label()->join_for_continue(); | 2026 exit_ = node->end_catch_label()->join_for_continue(); |
| 2026 } | 2027 } |
| 2027 } | 2028 } |
| 2028 } | 2029 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2094 void FlowGraphBuilder::BuildGraph(bool for_optimized) { | 2095 void FlowGraphBuilder::BuildGraph(bool for_optimized) { |
| 2095 if (FLAG_print_ast) { | 2096 if (FLAG_print_ast) { |
| 2096 // Print the function ast before IL generation. | 2097 // Print the function ast before IL generation. |
| 2097 AstPrinter::PrintFunctionNodes(parsed_function()); | 2098 AstPrinter::PrintFunctionNodes(parsed_function()); |
| 2098 } | 2099 } |
| 2099 // Compilation can be nested, preserve the computation-id. | 2100 // Compilation can be nested, preserve the computation-id. |
| 2100 Isolate* isolate = Isolate::Current(); | 2101 Isolate* isolate = Isolate::Current(); |
| 2101 const intptr_t prev_cid = isolate->computation_id(); | 2102 const intptr_t prev_cid = isolate->computation_id(); |
| 2102 isolate->set_computation_id(0); | 2103 isolate->set_computation_id(0); |
| 2103 const Function& function = parsed_function().function(); | 2104 const Function& function = parsed_function().function(); |
| 2105 TargetEntryInstr* normal_entry = new TargetEntryInstr(); |
| 2106 graph_entry_ = new GraphEntryInstr(normal_entry); |
| 2104 EffectGraphVisitor for_effect(this, 0); | 2107 EffectGraphVisitor for_effect(this, 0); |
| 2105 for_effect.AddInstruction(new TargetEntryInstr()); | 2108 for_effect.AddInstruction(normal_entry); |
| 2106 parsed_function().node_sequence()->Visit(&for_effect); | 2109 parsed_function().node_sequence()->Visit(&for_effect); |
| 2107 // Check that the graph is properly terminated. | 2110 // Check that the graph is properly terminated. |
| 2108 ASSERT(!for_effect.is_open()); | 2111 ASSERT(!for_effect.is_open()); |
| 2109 GrowableArray<intptr_t> parent; | 2112 GrowableArray<intptr_t> parent; |
| 2110 for (intptr_t i = 0; i < catch_entries_.length(); i++) { | 2113 // Perform a depth-first traversal of the graph to build preorder and |
| 2111 Instruction* entry = catch_entries_[i]; | 2114 // postorder block orders. |
| 2112 entry->DiscoverBlocks(NULL, // Entry block predecessor. | 2115 graph_entry_->DiscoverBlocks(NULL, // Entry block predecessor. |
| 2113 &preorder_block_entries_, | 2116 &preorder_block_entries_, |
| 2114 &postorder_block_entries_, | 2117 &postorder_block_entries_, |
| 2115 &parent); | 2118 &parent); |
| 2116 if (for_optimized) { | 2119 if (for_optimized) { |
| 2117 ComputeDominators(&preorder_block_entries_, &parent); | 2120 ComputeDominators(&preorder_block_entries_, &parent); |
| 2118 } | |
| 2119 } | |
| 2120 if (for_effect.entry() != NULL) { | |
| 2121 // Perform a depth-first traversal of the graph to build preorder and | |
| 2122 // postorder block orders. | |
| 2123 for_effect.entry()->DiscoverBlocks(NULL, // Entry block predecessor. | |
| 2124 &preorder_block_entries_, | |
| 2125 &postorder_block_entries_, | |
| 2126 &parent); | |
| 2127 if (for_optimized) { | |
| 2128 ComputeDominators(&preorder_block_entries_, &parent); | |
| 2129 } | |
| 2130 } | 2121 } |
| 2131 isolate->set_computation_id(prev_cid); | 2122 isolate->set_computation_id(prev_cid); |
| 2132 if (FLAG_print_flow_graph) { | 2123 if (FLAG_print_flow_graph) { |
| 2133 intptr_t length = postorder_block_entries_.length(); | 2124 intptr_t length = postorder_block_entries_.length(); |
| 2134 GrowableArray<BlockEntryInstr*> reverse_postorder(length); | 2125 GrowableArray<BlockEntryInstr*> reverse_postorder(length); |
| 2135 for (intptr_t i = length - 1; i >= 0; --i) { | 2126 for (intptr_t i = length - 1; i >= 0; --i) { |
| 2136 reverse_postorder.Add(postorder_block_entries_[i]); | 2127 reverse_postorder.Add(postorder_block_entries_[i]); |
| 2137 } | 2128 } |
| 2138 FlowGraphPrinter printer(function, reverse_postorder); | 2129 FlowGraphPrinter printer(function, reverse_postorder); |
| 2139 printer.VisitBlocks(); | 2130 printer.VisitBlocks(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2235 char* chars = reinterpret_cast<char*>( | 2226 char* chars = reinterpret_cast<char*>( |
| 2236 Isolate::Current()->current_zone()->Allocate(len)); | 2227 Isolate::Current()->current_zone()->Allocate(len)); |
| 2237 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2228 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2238 const Error& error = Error::Handle( | 2229 const Error& error = Error::Handle( |
| 2239 LanguageError::New(String::Handle(String::New(chars)))); | 2230 LanguageError::New(String::Handle(String::New(chars)))); |
| 2240 Isolate::Current()->long_jump_base()->Jump(1, error); | 2231 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2241 } | 2232 } |
| 2242 | 2233 |
| 2243 | 2234 |
| 2244 } // namespace dart | 2235 } // namespace dart |
| OLD | NEW |