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