| 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/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/cha.h" | 8 #include "vm/cha.h" |
| 9 #include "vm/flow_graph_builder.h" | 9 #include "vm/flow_graph_builder.h" |
| 10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
| 11 #include "vm/hash_map.h" | 11 #include "vm/hash_map.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/object_store.h" | 14 #include "vm/object_store.h" |
| 15 #include "vm/parser.h" | 15 #include "vm/parser.h" |
| 16 #include "vm/resolver.h" | 16 #include "vm/resolver.h" |
| 17 #include "vm/scopes.h" | 17 #include "vm/scopes.h" |
| 18 #include "vm/symbols.h" | 18 #include "vm/symbols.h" |
| 19 | 19 |
| 20 namespace dart { | 20 namespace dart { |
| 21 | 21 |
| 22 DECLARE_FLAG(bool, eliminate_type_checks); | 22 DECLARE_FLAG(bool, eliminate_type_checks); |
| 23 DECLARE_FLAG(bool, enable_type_checks); | 23 DECLARE_FLAG(bool, enable_type_checks); |
| 24 DEFINE_FLAG(bool, trace_optimization, false, "Print optimization details."); | 24 DEFINE_FLAG(bool, trace_optimization, false, "Print optimization details."); |
| 25 DECLARE_FLAG(bool, trace_type_check_elimination); | 25 DECLARE_FLAG(bool, trace_type_check_elimination); |
| 26 DEFINE_FLAG(bool, use_cha, true, "Use class hierarchy analysis."); | 26 DEFINE_FLAG(bool, use_cha, true, "Use class hierarchy analysis."); |
| 27 DEFINE_FLAG(bool, load_cse, true, "Use redundant load elimination."); | 27 DEFINE_FLAG(bool, load_cse, true, "Use redundant load elimination."); |
| 28 DEFINE_FLAG(bool, trace_range_analysis, false, "Trace range analysis progress"); | 28 DEFINE_FLAG(bool, trace_range_analysis, false, "Trace range analysis progress"); |
| 29 DEFINE_FLAG(bool, trace_constant_propagation, false, | 29 DEFINE_FLAG(bool, trace_constant_propagation, false, |
| 30 "Print constant propagation and useless code elimination."); | 30 "Print constant propagation and useless code elimination."); |
| 31 DEFINE_FLAG(bool, array_bounds_check_elimination, true, | 31 DEFINE_FLAG(bool, array_bounds_check_elimination, true, |
| 32 "Eliminate redundant bounds checks."); | 32 "Eliminate redundant bounds checks."); |
| 33 DEFINE_FLAG(int, max_polymorphic_checks, 4, |
| 34 "Maximum number of polymorphic check, otherwise it is megamorphic."); |
| 33 | 35 |
| 34 | 36 |
| 35 void FlowGraphOptimizer::ApplyICData() { | 37 void FlowGraphOptimizer::ApplyICData() { |
| 36 VisitBlocks(); | 38 VisitBlocks(); |
| 37 } | 39 } |
| 38 | 40 |
| 39 | 41 |
| 40 // Attempts to convert an instance call (IC call) using propagated class-ids, | 42 // Attempts to convert an instance call (IC call) using propagated class-ids, |
| 41 // e.g., receiver class id. | 43 // e.g., receiver class id. |
| 42 void FlowGraphOptimizer::ApplyClassIds() { | 44 void FlowGraphOptimizer::ApplyClassIds() { |
| (...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 const ICData& unary_checks = | 1152 const ICData& unary_checks = |
| 1151 ICData::ZoneHandle(instr->ic_data()->AsUnaryClassChecks()); | 1153 ICData::ZoneHandle(instr->ic_data()->AsUnaryClassChecks()); |
| 1152 if (!InstanceCallNeedsClassCheck(instr)) { | 1154 if (!InstanceCallNeedsClassCheck(instr)) { |
| 1153 const bool call_with_checks = false; | 1155 const bool call_with_checks = false; |
| 1154 PolymorphicInstanceCallInstr* call = | 1156 PolymorphicInstanceCallInstr* call = |
| 1155 new PolymorphicInstanceCallInstr(instr, unary_checks, | 1157 new PolymorphicInstanceCallInstr(instr, unary_checks, |
| 1156 call_with_checks); | 1158 call_with_checks); |
| 1157 instr->ReplaceWith(call, current_iterator()); | 1159 instr->ReplaceWith(call, current_iterator()); |
| 1158 return; | 1160 return; |
| 1159 } | 1161 } |
| 1160 const intptr_t kMaxChecks = 4; | 1162 if (instr->ic_data()->NumberOfChecks() <= FLAG_max_polymorphic_checks) { |
| 1161 if (instr->ic_data()->NumberOfChecks() <= kMaxChecks) { | |
| 1162 bool call_with_checks; | 1163 bool call_with_checks; |
| 1163 if (unary_checks.HasOneTarget()) { | 1164 if (unary_checks.HasOneTarget()) { |
| 1164 // Type propagation has not run yet, we cannot eliminate the check. | 1165 // Type propagation has not run yet, we cannot eliminate the check. |
| 1165 AddCheckClass(instr, instr->ArgumentAt(0)->value()->Copy()); | 1166 AddCheckClass(instr, instr->ArgumentAt(0)->value()->Copy()); |
| 1166 // Call can still deoptimize, do not detach environment from instr. | 1167 // Call can still deoptimize, do not detach environment from instr. |
| 1167 call_with_checks = false; | 1168 call_with_checks = false; |
| 1168 } else { | 1169 } else { |
| 1169 call_with_checks = true; | 1170 call_with_checks = true; |
| 1170 } | 1171 } |
| 1171 PolymorphicInstanceCallInstr* call = | 1172 PolymorphicInstanceCallInstr* call = |
| (...skipping 2470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3642 | 3643 |
| 3643 if (FLAG_trace_constant_propagation) { | 3644 if (FLAG_trace_constant_propagation) { |
| 3644 OS::Print("\n==== After constant propagation ====\n"); | 3645 OS::Print("\n==== After constant propagation ====\n"); |
| 3645 FlowGraphPrinter printer(*graph_); | 3646 FlowGraphPrinter printer(*graph_); |
| 3646 printer.PrintBlocks(); | 3647 printer.PrintBlocks(); |
| 3647 } | 3648 } |
| 3648 } | 3649 } |
| 3649 | 3650 |
| 3650 | 3651 |
| 3651 } // namespace dart | 3652 } // namespace dart |
| OLD | NEW |