| 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_optimizer.h" | 5 #include "vm/flow_graph_optimizer.h" |
| 6 | 6 |
| 7 #include "vm/flow_graph_builder.h" | 7 #include "vm/flow_graph_builder.h" |
| 8 #include "vm/il_printer.h" | 8 #include "vm/il_printer.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 DECLARE_FLAG(bool, enable_type_checks); | 13 DECLARE_FLAG(bool, enable_type_checks); |
| 14 DECLARE_FLAG(bool, print_flow_graph); | 14 DECLARE_FLAG(bool, print_flow_graph); |
| 15 DECLARE_FLAG(bool, trace_optimization); | 15 DECLARE_FLAG(bool, trace_optimization); |
| 16 | 16 |
| 17 void FlowGraphOptimizer::ApplyICData() { | 17 void FlowGraphOptimizer::ApplyICData() { |
| 18 VisitBlocks(); | 18 VisitBlocks(); |
| 19 if (FLAG_print_flow_graph) { | 19 if (FLAG_print_flow_graph) { |
| 20 OS::Print("After Optimizations:\n"); | 20 OS::Print("After Optimizations:\n"); |
| 21 FlowGraphPrinter printer(Function::Handle(), block_order_); | 21 FlowGraphPrinter printer(Function::Handle(), block_order_); |
| 22 printer.PrintBlocks(); | 22 printer.PrintBlocks(); |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 | 26 |
| 27 void FlowGraphOptimizer::VisitBlocks() { | |
| 28 for (intptr_t i = 0; i < block_order_.length(); ++i) { | |
| 29 Instruction* instr = block_order_[i]->Accept(this); | |
| 30 // Optimize all successors until an exit, branch, or a block entry. | |
| 31 while ((instr != NULL) && !instr->IsBlockEntry()) { | |
| 32 instr = instr->Accept(this); | |
| 33 } | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 | |
| 38 static bool ICDataHasReceiverClassId(const ICData& ic_data, intptr_t class_id) { | 27 static bool ICDataHasReceiverClassId(const ICData& ic_data, intptr_t class_id) { |
| 39 ASSERT(ic_data.num_args_tested() > 0); | 28 ASSERT(ic_data.num_args_tested() > 0); |
| 40 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { | 29 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { |
| 41 const intptr_t test_class_id = ic_data.GetReceiverClassIdAt(i); | 30 const intptr_t test_class_id = ic_data.GetReceiverClassIdAt(i); |
| 42 if (test_class_id == class_id) { | 31 if (test_class_id == class_id) { |
| 43 return true; | 32 return true; |
| 44 } | 33 } |
| 45 } | 34 } |
| 46 return false; | 35 return false; |
| 47 } | 36 } |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 TryFuseComparisonWithBranch(instr, comp); | 603 TryFuseComparisonWithBranch(instr, comp); |
| 615 } | 604 } |
| 616 | 605 |
| 617 | 606 |
| 618 void FlowGraphOptimizer::VisitBind(BindInstr* instr) { | 607 void FlowGraphOptimizer::VisitBind(BindInstr* instr) { |
| 619 instr->computation()->Accept(this, instr); | 608 instr->computation()->Accept(this, instr); |
| 620 } | 609 } |
| 621 | 610 |
| 622 | 611 |
| 623 | 612 |
| 624 FlowGraphAnalyzer::FlowGraphAnalyzer( | |
| 625 const GrowableArray<BlockEntryInstr*>& blocks) | |
| 626 :blocks_(blocks), is_leaf_(false) {} | |
| 627 | |
| 628 | |
| 629 void FlowGraphAnalyzer::Analyze() { | 613 void FlowGraphAnalyzer::Analyze() { |
| 630 is_leaf_ = true; | 614 is_leaf_ = true; |
| 631 for (intptr_t i = 0; i < blocks_.length(); ++i) { | 615 for (intptr_t i = 0; i < blocks_.length(); ++i) { |
| 632 BlockEntryInstr* block_entry = blocks_[i]; | 616 BlockEntryInstr* entry = blocks_[i]; |
| 633 Instruction* instr = block_entry->next(); | 617 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { |
| 634 while ((instr != NULL) && !instr->IsBlockEntry()) { | 618 LocationSummary* locs = it.Current()->locs(); |
| 635 LocationSummary* locs = instr->locs(); | 619 if ((locs != NULL) && locs->is_call()) { |
| 636 if (locs != NULL) { | 620 is_leaf_ = false; |
| 637 if (locs->is_call()) { | 621 return; |
| 638 is_leaf_ = false; | |
| 639 return; | |
| 640 } | |
| 641 } | 622 } |
| 642 instr = instr->next(); | |
| 643 } | 623 } |
| 644 } | 624 } |
| 645 } | 625 } |
| 646 | 626 |
| 647 } // namespace dart | 627 } // namespace dart |
| OLD | NEW |