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_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 DEFINE_FLAG(bool, array_bounds_check_elimination, true, | 22 DEFINE_FLAG(bool, array_bounds_check_elimination, true, |
23 "Eliminate redundant bounds checks."); | 23 "Eliminate redundant bounds checks."); |
| 24 // TODO(srdjan): Enable/remove flag once it works. |
| 25 DEFINE_FLAG(bool, inline_getter_with_guarded_cid, false, |
| 26 "Inline implict getter using guarded cid"); |
24 DEFINE_FLAG(bool, load_cse, true, "Use redundant load elimination."); | 27 DEFINE_FLAG(bool, load_cse, true, "Use redundant load elimination."); |
25 DEFINE_FLAG(int, max_polymorphic_checks, 4, | 28 DEFINE_FLAG(int, max_polymorphic_checks, 4, |
26 "Maximum number of polymorphic check, otherwise it is megamorphic."); | 29 "Maximum number of polymorphic check, otherwise it is megamorphic."); |
27 DEFINE_FLAG(bool, remove_redundant_phis, true, "Remove redundant phis."); | 30 DEFINE_FLAG(bool, remove_redundant_phis, true, "Remove redundant phis."); |
28 DEFINE_FLAG(bool, trace_constant_propagation, false, | 31 DEFINE_FLAG(bool, trace_constant_propagation, false, |
29 "Print constant propagation and useless code elimination."); | 32 "Print constant propagation and useless code elimination."); |
30 DEFINE_FLAG(bool, trace_optimization, false, "Print optimization details."); | 33 DEFINE_FLAG(bool, trace_optimization, false, "Print optimization details."); |
31 DEFINE_FLAG(bool, trace_range_analysis, false, "Trace range analysis progress"); | 34 DEFINE_FLAG(bool, trace_range_analysis, false, "Trace range analysis progress"); |
32 DEFINE_FLAG(bool, truncating_left_shift, true, | 35 DEFINE_FLAG(bool, truncating_left_shift, true, |
33 "Optimize left shift to truncate if possible"); | 36 "Optimize left shift to truncate if possible"); |
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 | 1192 |
1190 if (InstanceCallNeedsClassCheck(call)) { | 1193 if (InstanceCallNeedsClassCheck(call)) { |
1191 AddReceiverCheck(call); | 1194 AddReceiverCheck(call); |
1192 } | 1195 } |
1193 LoadFieldInstr* load = new LoadFieldInstr( | 1196 LoadFieldInstr* load = new LoadFieldInstr( |
1194 new Value(call->ArgumentAt(0)), | 1197 new Value(call->ArgumentAt(0)), |
1195 field.Offset(), | 1198 field.Offset(), |
1196 AbstractType::ZoneHandle(field.type()), | 1199 AbstractType::ZoneHandle(field.type()), |
1197 field.is_final()); | 1200 field.is_final()); |
1198 if (field.guarded_cid() != kIllegalCid) { | 1201 if (field.guarded_cid() != kIllegalCid) { |
1199 Field* the_field = &Field::ZoneHandle(field.raw()); | |
1200 if (!field.is_nullable() || (field.guarded_cid() == kNullCid)) { | 1202 if (!field.is_nullable() || (field.guarded_cid() == kNullCid)) { |
1201 load->set_result_cid(field.guarded_cid()); | 1203 load->set_result_cid(field.guarded_cid()); |
1202 guarded_fields_->Add(the_field); | |
1203 } | 1204 } |
1204 load->set_field(the_field); | 1205 load->set_field(&Field::ZoneHandle(field.raw())); |
1205 } | 1206 } |
1206 load->set_field_name(String::Handle(field.name()).ToCString()); | 1207 load->set_field_name(String::Handle(field.name()).ToCString()); |
1207 | 1208 |
1208 // Discard the environment from the original instruction because the load | 1209 // Discard the environment from the original instruction because the load |
1209 // can't deoptimize. | 1210 // can't deoptimize. |
1210 call->RemoveEnvironment(); | 1211 call->RemoveEnvironment(); |
1211 ReplaceCall(call, load); | 1212 ReplaceCall(call, load); |
1212 | 1213 |
1213 if (load->result_cid() != kDynamicCid) { | 1214 if (FLAG_inline_getter_with_guarded_cid) { |
1214 // Reset value types if guarded_cid was used. | 1215 if (load->result_cid() != kDynamicCid) { |
1215 for (Value::Iterator it(load->input_use_list()); | 1216 // Reset value types if guarded_cid was used. |
1216 !it.Done(); | 1217 for (Value::Iterator it(load->input_use_list()); |
1217 it.Advance()) { | 1218 !it.Done(); |
1218 it.Current()->SetReachingType(NULL); | 1219 it.Advance()) { |
| 1220 it.Current()->SetReachingType(NULL); |
| 1221 } |
1219 } | 1222 } |
1220 } | 1223 } |
1221 } | 1224 } |
1222 | 1225 |
1223 | 1226 |
1224 void FlowGraphOptimizer::InlineArrayLengthGetter(InstanceCallInstr* call, | 1227 void FlowGraphOptimizer::InlineArrayLengthGetter(InstanceCallInstr* call, |
1225 intptr_t length_offset, | 1228 intptr_t length_offset, |
1226 bool is_immutable, | 1229 bool is_immutable, |
1227 MethodRecognizer::Kind kind) { | 1230 MethodRecognizer::Kind kind) { |
1228 AddReceiverCheck(call); | 1231 AddReceiverCheck(call); |
(...skipping 3500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4729 if (changed) { | 4732 if (changed) { |
4730 // We may have changed the block order and the dominator tree. | 4733 // We may have changed the block order and the dominator tree. |
4731 flow_graph->DiscoverBlocks(); | 4734 flow_graph->DiscoverBlocks(); |
4732 GrowableArray<BitVector*> dominance_frontier; | 4735 GrowableArray<BitVector*> dominance_frontier; |
4733 flow_graph->ComputeDominators(&dominance_frontier); | 4736 flow_graph->ComputeDominators(&dominance_frontier); |
4734 } | 4737 } |
4735 } | 4738 } |
4736 | 4739 |
4737 | 4740 |
4738 } // namespace dart | 4741 } // namespace dart |
OLD | NEW |