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/bit_vector.h" | 8 #include "vm/bit_vector.h" |
9 #include "vm/code_descriptors.h" | 9 #include "vm/code_descriptors.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
11 #include "vm/flags.h" | 11 #include "vm/flags.h" |
12 #include "vm/il_printer.h" | 12 #include "vm/il_printer.h" |
13 #include "vm/intermediate_language.h" | 13 #include "vm/intermediate_language.h" |
14 #include "vm/longjump.h" | 14 #include "vm/longjump.h" |
15 #include "vm/object_store.h" | 15 #include "vm/object_store.h" |
16 #include "vm/os.h" | 16 #include "vm/os.h" |
17 #include "vm/parser.h" | 17 #include "vm/parser.h" |
18 #include "vm/resolver.h" | 18 #include "vm/resolver.h" |
19 #include "vm/stub_code.h" | 19 #include "vm/stub_code.h" |
20 | 20 |
21 namespace dart { | 21 namespace dart { |
22 | 22 |
23 DEFINE_FLAG(bool, eliminate_type_checks, true, | 23 DEFINE_FLAG(bool, eliminate_type_checks, true, |
24 "Eliminate type checks when allowed by static type analysis"); | 24 "Eliminate type checks when allowed by static type analysis"); |
25 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree."); | 25 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree."); |
26 DEFINE_FLAG(bool, print_flow_graph, false, "Print the IR flow graph."); | 26 DEFINE_FLAG(bool, print_flow_graph, false, "Print the IR flow graph."); |
| 27 DEFINE_FLAG(bool, print_flow_graph_file, false, "Print the IR into a file."); |
27 DECLARE_FLAG(bool, enable_type_checks); | 28 DECLARE_FLAG(bool, enable_type_checks); |
28 | 29 |
29 | 30 |
30 FlowGraphBuilder::FlowGraphBuilder(const ParsedFunction& parsed_function) | 31 FlowGraphBuilder::FlowGraphBuilder(const ParsedFunction& parsed_function) |
31 : parsed_function_(parsed_function), | 32 : parsed_function_(parsed_function), |
32 preorder_block_entries_(), | 33 preorder_block_entries_(), |
33 postorder_block_entries_(), | 34 postorder_block_entries_(), |
34 context_level_(0), | 35 context_level_(0), |
35 last_used_try_index_(CatchClauseNode::kInvalidTryIndex), | 36 last_used_try_index_(CatchClauseNode::kInvalidTryIndex), |
36 try_index_(CatchClauseNode::kInvalidTryIndex), | 37 try_index_(CatchClauseNode::kInvalidTryIndex), |
(...skipping 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2294 variable_count); | 2295 variable_count); |
2295 // Number blocks in reverse postorder. | 2296 // Number blocks in reverse postorder. |
2296 intptr_t block_count = postorder_block_entries_.length(); | 2297 intptr_t block_count = postorder_block_entries_.length(); |
2297 for (intptr_t i = 0; i < block_count; ++i) { | 2298 for (intptr_t i = 0; i < block_count; ++i) { |
2298 postorder_block_entries_[i]->set_block_id(block_count - i - 1); | 2299 postorder_block_entries_[i]->set_block_id(block_count - i - 1); |
2299 } | 2300 } |
2300 if (for_optimized) { | 2301 if (for_optimized) { |
2301 GrowableArray<BitVector*> dominance_frontier; | 2302 GrowableArray<BitVector*> dominance_frontier; |
2302 ComputeDominators(&preorder_block_entries_, &parent, &dominance_frontier); | 2303 ComputeDominators(&preorder_block_entries_, &parent, &dominance_frontier); |
2303 } | 2304 } |
2304 if (FLAG_print_flow_graph) { | 2305 if (FLAG_print_flow_graph || FLAG_print_flow_graph_file) { |
2305 intptr_t length = postorder_block_entries_.length(); | 2306 intptr_t length = postorder_block_entries_.length(); |
2306 GrowableArray<BlockEntryInstr*> reverse_postorder(length); | 2307 GrowableArray<BlockEntryInstr*> reverse_postorder(length); |
2307 for (intptr_t i = length - 1; i >= 0; --i) { | 2308 for (intptr_t i = length - 1; i >= 0; --i) { |
2308 reverse_postorder.Add(postorder_block_entries_[i]); | 2309 reverse_postorder.Add(postorder_block_entries_[i]); |
2309 } | 2310 } |
2310 FlowGraphPrinter printer(function, reverse_postorder); | 2311 if (FLAG_print_flow_graph) { |
2311 printer.PrintBlocks(); | 2312 FlowGraphPrinter printer(function, reverse_postorder); |
| 2313 printer.PrintBlocks(); |
| 2314 } |
| 2315 if (FLAG_print_flow_graph_file) { |
| 2316 FlowGraphVisualizer printer(function, reverse_postorder); |
| 2317 printer.PrintFunction(); |
| 2318 } |
2312 } | 2319 } |
2313 } | 2320 } |
2314 | 2321 |
2315 | 2322 |
2316 // Compute immediate dominators and the dominance frontier for each basic | 2323 // Compute immediate dominators and the dominance frontier for each basic |
2317 // block. As a side effect of the algorithm, sets the immediate dominator | 2324 // block. As a side effect of the algorithm, sets the immediate dominator |
2318 // of each basic block. | 2325 // of each basic block. |
2319 // | 2326 // |
2320 // preorder: an input list of basic block entries in preorder. The | 2327 // preorder: an input list of basic block entries in preorder. The |
2321 // algorithm relies on the block ordering. | 2328 // algorithm relies on the block ordering. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2443 char* chars = reinterpret_cast<char*>( | 2450 char* chars = reinterpret_cast<char*>( |
2444 Isolate::Current()->current_zone()->Allocate(len)); | 2451 Isolate::Current()->current_zone()->Allocate(len)); |
2445 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2452 OS::SNPrint(chars, len, kFormat, function_name, reason); |
2446 const Error& error = Error::Handle( | 2453 const Error& error = Error::Handle( |
2447 LanguageError::New(String::Handle(String::New(chars)))); | 2454 LanguageError::New(String::Handle(String::New(chars)))); |
2448 Isolate::Current()->long_jump_base()->Jump(1, error); | 2455 Isolate::Current()->long_jump_base()->Jump(1, error); |
2449 } | 2456 } |
2450 | 2457 |
2451 | 2458 |
2452 } // namespace dart | 2459 } // namespace dart |
OLD | NEW |