Chromium Code Reviews| 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 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1175 values, | 1175 values, |
| 1176 element_type); | 1176 element_type); |
| 1177 ReturnComputation(create); | 1177 ReturnComputation(create); |
| 1178 } | 1178 } |
| 1179 | 1179 |
| 1180 | 1180 |
| 1181 void EffectGraphVisitor::VisitClosureNode(ClosureNode* node) { | 1181 void EffectGraphVisitor::VisitClosureNode(ClosureNode* node) { |
| 1182 const Function& function = node->function(); | 1182 const Function& function = node->function(); |
| 1183 | 1183 |
| 1184 if (function.IsNonImplicitClosureFunction()) { | 1184 if (function.IsNonImplicitClosureFunction()) { |
| 1185 const ContextScope& context_scope = ContextScope::ZoneHandle( | 1185 // The context scope may have already been set by the new non-optimizing |
|
regis
2012/05/08 16:07:32
I would drop "new".
srdjan
2012/05/08 16:16:03
Done in next CL.
| |
| 1186 node->scope()->PreserveOuterScope(owner()->context_level())); | 1186 // compiler. If it was not, set it here. |
| 1187 ASSERT(!function.HasCode()); | 1187 if (function.context_scope() == ContextScope::null()) { |
| 1188 ASSERT(function.context_scope() == ContextScope::null()); | 1188 const ContextScope& context_scope = ContextScope::ZoneHandle( |
| 1189 function.set_context_scope(context_scope); | 1189 node->scope()->PreserveOuterScope(owner()->context_level())); |
| 1190 ASSERT(!function.HasCode()); | |
| 1191 ASSERT(function.context_scope() == ContextScope::null()); | |
| 1192 function.set_context_scope(context_scope); | |
| 1193 } | |
| 1190 } else if (function.IsImplicitInstanceClosureFunction()) { | 1194 } else if (function.IsImplicitInstanceClosureFunction()) { |
| 1191 ValueGraphVisitor for_receiver(owner(), temp_index()); | 1195 ValueGraphVisitor for_receiver(owner(), temp_index()); |
| 1192 node->receiver()->Visit(&for_receiver); | 1196 node->receiver()->Visit(&for_receiver); |
| 1193 Append(for_receiver); | 1197 Append(for_receiver); |
| 1194 } | 1198 } |
| 1195 ASSERT(function.context_scope() != ContextScope::null()); | 1199 ASSERT(function.context_scope() != ContextScope::null()); |
| 1196 | 1200 |
| 1197 // The function type of a closure may have type arguments. In that case, pass | 1201 // The function type of a closure may have type arguments. In that case, pass |
| 1198 // the type arguments of the instantiator. | 1202 // the type arguments of the instantiator. |
| 1199 const Class& cls = Class::Handle(function.signature_class()); | 1203 const Class& cls = Class::Handle(function.signature_class()); |
| (...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2440 | 2444 |
| 2441 void FlowGraphPrinter::VisitBranch(BranchInstr* instr) { | 2445 void FlowGraphPrinter::VisitBranch(BranchInstr* instr) { |
| 2442 OS::Print(" if "); | 2446 OS::Print(" if "); |
| 2443 instr->value()->Accept(this); | 2447 instr->value()->Accept(this); |
| 2444 OS::Print(" goto(%d, %d)", | 2448 OS::Print(" goto(%d, %d)", |
| 2445 reverse_index(instr->true_successor()->postorder_number()), | 2449 reverse_index(instr->true_successor()->postorder_number()), |
| 2446 reverse_index(instr->false_successor()->postorder_number())); | 2450 reverse_index(instr->false_successor()->postorder_number())); |
| 2447 } | 2451 } |
| 2448 | 2452 |
| 2449 | 2453 |
| 2450 void FlowGraphBuilder::BuildGraph() { | 2454 void FlowGraphBuilder::BuildGraph(bool for_optimized) { |
| 2451 if (FLAG_print_ast) { | 2455 if (FLAG_print_ast) { |
| 2452 // Print the function ast before IL generation. | 2456 // Print the function ast before IL generation. |
| 2453 AstPrinter::PrintFunctionNodes(parsed_function()); | 2457 AstPrinter::PrintFunctionNodes(parsed_function()); |
| 2454 } | 2458 } |
| 2455 TimerScope timer(FLAG_compiler_stats, &CompilerStats::graphbuilder_timer); | 2459 TimerScope timer(FLAG_compiler_stats, &CompilerStats::graphbuilder_timer); |
| 2456 // Compilation can be nested, preserve the computation-id. | 2460 // Compilation can be nested, preserve the computation-id. |
| 2457 Isolate* isolate = Isolate::Current(); | 2461 Isolate* isolate = Isolate::Current(); |
| 2458 const intptr_t prev_cid = isolate->computation_id(); | 2462 const intptr_t prev_cid = isolate->computation_id(); |
| 2459 isolate->set_computation_id(0); | 2463 isolate->set_computation_id(0); |
| 2460 const Function& function = parsed_function().function(); | 2464 const Function& function = parsed_function().function(); |
| 2461 EffectGraphVisitor for_effect(this, 0); | 2465 EffectGraphVisitor for_effect(this, 0); |
| 2462 for_effect.AddInstruction(new TargetEntryInstr()); | 2466 for_effect.AddInstruction(new TargetEntryInstr()); |
| 2463 parsed_function().node_sequence()->Visit(&for_effect); | 2467 parsed_function().node_sequence()->Visit(&for_effect); |
| 2464 // Check that the graph is properly terminated. | 2468 // Check that the graph is properly terminated. |
| 2465 ASSERT(!for_effect.is_open()); | 2469 ASSERT(!for_effect.is_open()); |
| 2466 GrowableArray<intptr_t> parent; | 2470 GrowableArray<intptr_t> parent; |
| 2467 for (intptr_t i = 0; i < catch_entries_.length(); i++) { | 2471 for (intptr_t i = 0; i < catch_entries_.length(); i++) { |
| 2468 Instruction* entry = catch_entries_[i]; | 2472 Instruction* entry = catch_entries_[i]; |
| 2469 entry->DiscoverBlocks(NULL, // Entry block predecessor. | 2473 entry->DiscoverBlocks(NULL, // Entry block predecessor. |
| 2470 &preorder_block_entries_, | 2474 &preorder_block_entries_, |
| 2471 &postorder_block_entries_, | 2475 &postorder_block_entries_, |
| 2472 &parent); | 2476 &parent); |
| 2473 ComputeDominators(&preorder_block_entries_, &parent); | 2477 if (for_optimized) { |
| 2478 ComputeDominators(&preorder_block_entries_, &parent); | |
| 2479 } | |
| 2474 } | 2480 } |
| 2475 if (for_effect.entry() != NULL) { | 2481 if (for_effect.entry() != NULL) { |
| 2476 // Perform a depth-first traversal of the graph to build preorder and | 2482 // Perform a depth-first traversal of the graph to build preorder and |
| 2477 // postorder block orders. | 2483 // postorder block orders. |
| 2478 for_effect.entry()->DiscoverBlocks(NULL, // Entry block predecessor. | 2484 for_effect.entry()->DiscoverBlocks(NULL, // Entry block predecessor. |
| 2479 &preorder_block_entries_, | 2485 &preorder_block_entries_, |
| 2480 &postorder_block_entries_, | 2486 &postorder_block_entries_, |
| 2481 &parent); | 2487 &parent); |
| 2482 ComputeDominators(&preorder_block_entries_, &parent); | 2488 if (for_optimized) { |
| 2489 ComputeDominators(&preorder_block_entries_, &parent); | |
| 2490 } | |
| 2483 } | 2491 } |
| 2484 isolate->set_computation_id(prev_cid); | 2492 isolate->set_computation_id(prev_cid); |
| 2485 if (FLAG_print_flow_graph) { | 2493 if (FLAG_print_flow_graph) { |
| 2486 intptr_t length = postorder_block_entries_.length(); | 2494 intptr_t length = postorder_block_entries_.length(); |
| 2487 GrowableArray<BlockEntryInstr*> reverse_postorder(length); | 2495 GrowableArray<BlockEntryInstr*> reverse_postorder(length); |
| 2488 for (intptr_t i = length - 1; i >= 0; --i) { | 2496 for (intptr_t i = length - 1; i >= 0; --i) { |
| 2489 reverse_postorder.Add(postorder_block_entries_[i]); | 2497 reverse_postorder.Add(postorder_block_entries_[i]); |
| 2490 } | 2498 } |
| 2491 FlowGraphPrinter printer(function, reverse_postorder); | 2499 FlowGraphPrinter printer(function, reverse_postorder); |
| 2492 printer.VisitBlocks(); | 2500 printer.VisitBlocks(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2588 char* chars = reinterpret_cast<char*>( | 2596 char* chars = reinterpret_cast<char*>( |
| 2589 Isolate::Current()->current_zone()->Allocate(len)); | 2597 Isolate::Current()->current_zone()->Allocate(len)); |
| 2590 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2598 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2591 const Error& error = Error::Handle( | 2599 const Error& error = Error::Handle( |
| 2592 LanguageError::New(String::Handle(String::New(chars)))); | 2600 LanguageError::New(String::Handle(String::New(chars)))); |
| 2593 Isolate::Current()->long_jump_base()->Jump(1, error); | 2601 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2594 } | 2602 } |
| 2595 | 2603 |
| 2596 | 2604 |
| 2597 } // namespace dart | 2605 } // namespace dart |
| OLD | NEW |