Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_inliner.h" | 5 #include "vm/flow_graph_inliner.h" |
| 6 | 6 |
| 7 #include "vm/aot_optimizer.h" | 7 #include "vm/aot_optimizer.h" |
| 8 #include "vm/block_scheduler.h" | 8 #include "vm/block_scheduler.h" |
| 9 #include "vm/branch_optimizer.h" | 9 #include "vm/branch_optimizer.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1207 | 1207 |
| 1208 void InlineInstanceCalls() { | 1208 void InlineInstanceCalls() { |
| 1209 const GrowableArray<CallSites::InstanceCallInfo>& call_info = | 1209 const GrowableArray<CallSites::InstanceCallInfo>& call_info = |
| 1210 inlining_call_sites_->instance_calls(); | 1210 inlining_call_sites_->instance_calls(); |
| 1211 TRACE_INLINING(THR_Print(" Polymorphic Instance Calls (%" Pd ")\n", | 1211 TRACE_INLINING(THR_Print(" Polymorphic Instance Calls (%" Pd ")\n", |
| 1212 call_info.length())); | 1212 call_info.length())); |
| 1213 for (intptr_t call_idx = 0; call_idx < call_info.length(); ++call_idx) { | 1213 for (intptr_t call_idx = 0; call_idx < call_info.length(); ++call_idx) { |
| 1214 PolymorphicInstanceCallInstr* call = call_info[call_idx].call; | 1214 PolymorphicInstanceCallInstr* call = call_info[call_idx].call; |
| 1215 if (call->with_checks()) { | 1215 if (call->with_checks()) { |
| 1216 // PolymorphicInliner introduces deoptimization paths. | 1216 // PolymorphicInliner introduces deoptimization paths. |
| 1217 if (!FLAG_polymorphic_with_deopt) { | 1217 if (!call->complete() && !FLAG_polymorphic_with_deopt) { |
| 1218 TRACE_INLINING(THR_Print( | 1218 TRACE_INLINING(THR_Print( |
| 1219 " => %s\n Bailout: call with checks\n", | 1219 " => %s\n Bailout: call with checks\n", |
| 1220 call->instance_call()->function_name().ToCString())); | 1220 call->instance_call()->function_name().ToCString())); |
| 1221 continue; | 1221 continue; |
| 1222 } | 1222 } |
| 1223 const Function& cl = call_info[call_idx].caller(); | 1223 const Function& cl = call_info[call_idx].caller(); |
| 1224 intptr_t caller_inlining_id = | 1224 intptr_t caller_inlining_id = |
| 1225 call_info[call_idx].caller_graph->inlining_id(); | 1225 call_info[call_idx].caller_graph->inlining_id(); |
| 1226 PolymorphicInliner inliner(this, call, cl, caller_inlining_id); | 1226 PolymorphicInliner inliner(this, call, cl, caller_inlining_id); |
| 1227 inliner.Inline(); | 1227 inliner.Inline(); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1624 // at least one branch on the class id. | 1624 // at least one branch on the class id. |
| 1625 LoadClassIdInstr* load_cid = | 1625 LoadClassIdInstr* load_cid = |
| 1626 new(Z) LoadClassIdInstr(new(Z) Value(receiver)); | 1626 new(Z) LoadClassIdInstr(new(Z) Value(receiver)); |
| 1627 load_cid->set_ssa_temp_index(owner_->caller_graph()->alloc_ssa_temp_index()); | 1627 load_cid->set_ssa_temp_index(owner_->caller_graph()->alloc_ssa_temp_index()); |
| 1628 cursor = AppendInstruction(cursor, load_cid); | 1628 cursor = AppendInstruction(cursor, load_cid); |
| 1629 for (intptr_t i = 0; i < inlined_variants_.length(); ++i) { | 1629 for (intptr_t i = 0; i < inlined_variants_.length(); ++i) { |
| 1630 // 1. Guard the body with a class id check. | 1630 // 1. Guard the body with a class id check. |
| 1631 if ((i == (inlined_variants_.length() - 1)) && | 1631 if ((i == (inlined_variants_.length() - 1)) && |
| 1632 non_inlined_variants_.is_empty()) { | 1632 non_inlined_variants_.is_empty()) { |
| 1633 // If it is the last variant use a check class id instruction which can | 1633 // If it is the last variant use a check class id instruction which can |
| 1634 // deoptimize, followed unconditionally by the body. | 1634 // deoptimize, followed unconditionally by the body. Omit the check if |
| 1635 RedefinitionInstr* cid_redefinition = | 1635 // we know that we have covered all possible classes. |
| 1636 new RedefinitionInstr(new(Z) Value(load_cid)); | 1636 if (!call_->complete()) { |
| 1637 cid_redefinition->set_ssa_temp_index( | 1637 RedefinitionInstr* cid_redefinition = |
| 1638 owner_->caller_graph()->alloc_ssa_temp_index()); | 1638 new RedefinitionInstr(new(Z) Value(load_cid)); |
| 1639 cursor = AppendInstruction(cursor, cid_redefinition); | 1639 cid_redefinition->set_ssa_temp_index( |
| 1640 CheckClassIdInstr* check_class_id = new(Z) CheckClassIdInstr( | 1640 owner_->caller_graph()->alloc_ssa_temp_index()); |
| 1641 new(Z) Value(cid_redefinition), | 1641 cursor = AppendInstruction(cursor, cid_redefinition); |
| 1642 inlined_variants_[i].cid, | 1642 CheckClassIdInstr* check_class_id = new(Z) CheckClassIdInstr( |
| 1643 call_->deopt_id()); | 1643 new(Z) Value(cid_redefinition), |
| 1644 check_class_id->InheritDeoptTarget(zone(), call_); | 1644 inlined_variants_[i].cid, |
| 1645 cursor = AppendInstruction(cursor, check_class_id); | 1645 call_->deopt_id()); |
| 1646 check_class_id->InheritDeoptTarget(zone(), call_); | |
| 1647 cursor = AppendInstruction(cursor, check_class_id); | |
| 1648 } | |
| 1646 | 1649 |
| 1647 // The next instruction is the first instruction of the inlined body. | 1650 // The next instruction is the first instruction of the inlined body. |
| 1648 // Handle the two possible cases (unshared and shared subsequent | 1651 // Handle the two possible cases (unshared and shared subsequent |
| 1649 // predecessors) separately. | 1652 // predecessors) separately. |
| 1650 BlockEntryInstr* callee_entry = inlined_entries_[i]; | 1653 BlockEntryInstr* callee_entry = inlined_entries_[i]; |
| 1651 if (callee_entry->IsGraphEntry()) { | 1654 if (callee_entry->IsGraphEntry()) { |
| 1652 // Unshared. Graft the normal entry on after the check class | 1655 // Unshared. Graft the normal entry on after the check class |
| 1653 // instruction. | 1656 // instruction. |
| 1654 TargetEntryInstr* target = | 1657 TargetEntryInstr* target = |
| 1655 callee_entry->AsGraphEntry()->normal_entry(); | 1658 callee_entry->AsGraphEntry()->normal_entry(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1768 old_checks.deopt_id(), | 1771 old_checks.deopt_id(), |
| 1769 1)); // Number of args tested. | 1772 1)); // Number of args tested. |
| 1770 for (intptr_t i = 0; i < non_inlined_variants_.length(); ++i) { | 1773 for (intptr_t i = 0; i < non_inlined_variants_.length(); ++i) { |
| 1771 new_checks.AddReceiverCheck(non_inlined_variants_[i].cid, | 1774 new_checks.AddReceiverCheck(non_inlined_variants_[i].cid, |
| 1772 *non_inlined_variants_[i].target, | 1775 *non_inlined_variants_[i].target, |
| 1773 non_inlined_variants_[i].count); | 1776 non_inlined_variants_[i].count); |
| 1774 } | 1777 } |
| 1775 PolymorphicInstanceCallInstr* fallback_call = | 1778 PolymorphicInstanceCallInstr* fallback_call = |
| 1776 new PolymorphicInstanceCallInstr(call_->instance_call(), | 1779 new PolymorphicInstanceCallInstr(call_->instance_call(), |
| 1777 new_checks, | 1780 new_checks, |
| 1778 true); // With checks. | 1781 true, // With checks. |
| 1782 call_->complete()); // Complete. | |
|
Florian Schneider
2016/04/08 22:39:38
This call could avoid the slow path code if you ch
| |
| 1779 fallback_call->set_ssa_temp_index( | 1783 fallback_call->set_ssa_temp_index( |
| 1780 owner_->caller_graph()->alloc_ssa_temp_index()); | 1784 owner_->caller_graph()->alloc_ssa_temp_index()); |
| 1781 fallback_call->InheritDeoptTarget(zone(), call_); | 1785 fallback_call->InheritDeoptTarget(zone(), call_); |
| 1782 ReturnInstr* fallback_return = | 1786 ReturnInstr* fallback_return = |
| 1783 new ReturnInstr(call_->instance_call()->token_pos(), | 1787 new ReturnInstr(call_->instance_call()->token_pos(), |
| 1784 new Value(fallback_call)); | 1788 new Value(fallback_call)); |
| 1785 fallback_return->InheritDeoptTargetAfter( | 1789 fallback_return->InheritDeoptTargetAfter( |
| 1786 owner_->caller_graph(), | 1790 owner_->caller_graph(), |
| 1787 call_, | 1791 call_, |
| 1788 fallback_call); | 1792 fallback_call); |
| (...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2863 | 2867 |
| 2864 bool FlowGraphInliner::TryInlineRecognizedMethod(FlowGraph* flow_graph, | 2868 bool FlowGraphInliner::TryInlineRecognizedMethod(FlowGraph* flow_graph, |
| 2865 intptr_t receiver_cid, | 2869 intptr_t receiver_cid, |
| 2866 const Function& target, | 2870 const Function& target, |
| 2867 Instruction* call, | 2871 Instruction* call, |
| 2868 Definition* receiver, | 2872 Definition* receiver, |
| 2869 TokenPosition token_pos, | 2873 TokenPosition token_pos, |
| 2870 const ICData& ic_data, | 2874 const ICData& ic_data, |
| 2871 TargetEntryInstr** entry, | 2875 TargetEntryInstr** entry, |
| 2872 Definition** last) { | 2876 Definition** last) { |
| 2877 if (FLAG_precompiled_mode) { | |
| 2878 // The graphs generated below include deopts. | |
| 2879 return false; | |
| 2880 } | |
| 2881 | |
| 2873 ICData& value_check = ICData::ZoneHandle(Z); | 2882 ICData& value_check = ICData::ZoneHandle(Z); |
| 2874 MethodRecognizer::Kind kind = MethodRecognizer::RecognizeKind(target); | 2883 MethodRecognizer::Kind kind = MethodRecognizer::RecognizeKind(target); |
| 2875 switch (kind) { | 2884 switch (kind) { |
| 2876 // Recognized [] operators. | 2885 // Recognized [] operators. |
| 2877 case MethodRecognizer::kImmutableArrayGetIndexed: | 2886 case MethodRecognizer::kImmutableArrayGetIndexed: |
| 2878 case MethodRecognizer::kObjectArrayGetIndexed: | 2887 case MethodRecognizer::kObjectArrayGetIndexed: |
| 2879 case MethodRecognizer::kGrowableArrayGetIndexed: | 2888 case MethodRecognizer::kGrowableArrayGetIndexed: |
| 2880 case MethodRecognizer::kInt8ArrayGetIndexed: | 2889 case MethodRecognizer::kInt8ArrayGetIndexed: |
| 2881 case MethodRecognizer::kUint8ArrayGetIndexed: | 2890 case MethodRecognizer::kUint8ArrayGetIndexed: |
| 2882 case MethodRecognizer::kUint8ClampedArrayGetIndexed: | 2891 case MethodRecognizer::kUint8ClampedArrayGetIndexed: |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3097 return InlineDoubleOp(flow_graph, Token::kMUL, call, entry, last); | 3106 return InlineDoubleOp(flow_graph, Token::kMUL, call, entry, last); |
| 3098 case MethodRecognizer::kDoubleDiv: | 3107 case MethodRecognizer::kDoubleDiv: |
| 3099 return InlineDoubleOp(flow_graph, Token::kDIV, call, entry, last); | 3108 return InlineDoubleOp(flow_graph, Token::kDIV, call, entry, last); |
| 3100 default: | 3109 default: |
| 3101 return false; | 3110 return false; |
| 3102 } | 3111 } |
| 3103 } | 3112 } |
| 3104 | 3113 |
| 3105 | 3114 |
| 3106 } // namespace dart | 3115 } // namespace dart |
| OLD | NEW |