| 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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/ast_printer.h" | 8 #include "vm/ast_printer.h" |
| 9 #include "vm/bit_vector.h" | 9 #include "vm/bit_vector.h" |
| 10 #include "vm/code_descriptors.h" | 10 #include "vm/code_descriptors.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 ASSERT(callee_graph->max_virtual_register_number() > | 75 ASSERT(callee_graph->max_virtual_register_number() > |
| 76 caller_graph_->max_virtual_register_number()); | 76 caller_graph_->max_virtual_register_number()); |
| 77 | 77 |
| 78 // Adjust the caller's maximum block id and current SSA temp index. | 78 // Adjust the caller's maximum block id and current SSA temp index. |
| 79 caller_graph_->set_max_block_id(callee_graph->max_block_id()); | 79 caller_graph_->set_max_block_id(callee_graph->max_block_id()); |
| 80 caller_graph_->set_current_ssa_temp_index( | 80 caller_graph_->set_current_ssa_temp_index( |
| 81 callee_graph->max_virtual_register_number()); | 81 callee_graph->max_virtual_register_number()); |
| 82 | 82 |
| 83 // Attach the outer environment on each instruction in the callee graph. | 83 // Attach the outer environment on each instruction in the callee graph. |
| 84 ASSERT(call_->env() != NULL); | 84 ASSERT(call_->env() != NULL); |
| 85 // Scale the edge weights by the call count for the inlined function. |
| 86 double scale_factor = static_cast<double>(call_->CallCount()) |
| 87 / static_cast<double>(caller_graph_->graph_entry()->entry_count()); |
| 85 for (BlockIterator block_it = callee_graph->postorder_iterator(); | 88 for (BlockIterator block_it = callee_graph->postorder_iterator(); |
| 86 !block_it.Done(); | 89 !block_it.Done(); |
| 87 block_it.Advance()) { | 90 block_it.Advance()) { |
| 88 for (ForwardInstructionIterator it(block_it.Current()); | 91 BlockEntryInstr* block = block_it.Current(); |
| 89 !it.Done(); | 92 if (block->IsTargetEntry()) { |
| 90 it.Advance()) { | 93 block->AsTargetEntry()->adjust_edge_weight(scale_factor); |
| 91 Instruction* instr = it.Current(); | 94 } |
| 95 Instruction* instr = block; |
| 96 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { |
| 97 instr = it.Current(); |
| 92 // TODO(zerny): Avoid creating unnecessary environments. Note that some | 98 // TODO(zerny): Avoid creating unnecessary environments. Note that some |
| 93 // optimizations need deoptimization info for non-deoptable instructions, | 99 // optimizations need deoptimization info for non-deoptable instructions, |
| 94 // eg, LICM on GOTOs. | 100 // eg, LICM on GOTOs. |
| 95 if (instr->env() != NULL) call_->env()->DeepCopyToOuter(instr); | 101 if (instr->env() != NULL) call_->env()->DeepCopyToOuter(instr); |
| 96 } | 102 } |
| 103 if (instr->IsGoto()) { |
| 104 instr->AsGoto()->adjust_edge_weight(scale_factor); |
| 105 } |
| 97 } | 106 } |
| 98 } | 107 } |
| 99 | 108 |
| 100 | 109 |
| 101 void InlineExitCollector::AddExit(ReturnInstr* exit) { | 110 void InlineExitCollector::AddExit(ReturnInstr* exit) { |
| 102 Data data = { NULL, exit }; | 111 Data data = { NULL, exit }; |
| 103 exits_.Add(data); | 112 exits_.Add(data); |
| 104 } | 113 } |
| 105 | 114 |
| 106 | 115 |
| (...skipping 3614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3721 } | 3730 } |
| 3722 | 3731 |
| 3723 FlowGraph* graph = new FlowGraph(*this, graph_entry_, last_used_block_id_); | 3732 FlowGraph* graph = new FlowGraph(*this, graph_entry_, last_used_block_id_); |
| 3724 return graph; | 3733 return graph; |
| 3725 } | 3734 } |
| 3726 | 3735 |
| 3727 | 3736 |
| 3728 void FlowGraphBuilder::PruneUnreachable() { | 3737 void FlowGraphBuilder::PruneUnreachable() { |
| 3729 ASSERT(osr_id_ != Isolate::kNoDeoptId); | 3738 ASSERT(osr_id_ != Isolate::kNoDeoptId); |
| 3730 BitVector* block_marks = new BitVector(last_used_block_id_ + 1); | 3739 BitVector* block_marks = new BitVector(last_used_block_id_ + 1); |
| 3731 bool found = graph_entry_->PruneUnreachable(this, graph_entry_, osr_id_, | 3740 bool found = graph_entry_->PruneUnreachable(this, graph_entry_, NULL, osr_id_, |
| 3732 block_marks); | 3741 block_marks); |
| 3733 ASSERT(found); | 3742 ASSERT(found); |
| 3734 } | 3743 } |
| 3735 | 3744 |
| 3736 | 3745 |
| 3737 void FlowGraphBuilder::Bailout(const char* reason) { | 3746 void FlowGraphBuilder::Bailout(const char* reason) { |
| 3738 const char* kFormat = "FlowGraphBuilder Bailout: %s %s"; | 3747 const char* kFormat = "FlowGraphBuilder Bailout: %s %s"; |
| 3739 const char* function_name = parsed_function_->function().ToCString(); | 3748 const char* function_name = parsed_function_->function().ToCString(); |
| 3740 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 3749 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
| 3741 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 3750 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 3742 OS::SNPrint(chars, len, kFormat, function_name, reason); | 3751 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 3743 const Error& error = Error::Handle( | 3752 const Error& error = Error::Handle( |
| 3744 LanguageError::New(String::Handle(String::New(chars)))); | 3753 LanguageError::New(String::Handle(String::New(chars)))); |
| 3745 Isolate::Current()->long_jump_base()->Jump(1, error); | 3754 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 3746 } | 3755 } |
| 3747 | 3756 |
| 3748 | 3757 |
| 3749 } // namespace dart | 3758 } // namespace dart |
| OLD | NEW |