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 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 callee_receiver->IsParameter() && | 1167 callee_receiver->IsParameter() && |
1171 (callee_receiver->AsParameter()->index() == 0)) { | 1168 (callee_receiver->AsParameter()->index() == 0)) { |
1172 const String& field_name = | 1169 const String& field_name = |
1173 String::Handle(Field::NameFromGetter(call->function_name())); | 1170 String::Handle(Field::NameFromGetter(call->function_name())); |
1174 return CHA::HasOverride(Class::Handle(function.Owner()), field_name); | 1171 return CHA::HasOverride(Class::Handle(function.Owner()), field_name); |
1175 } | 1172 } |
1176 return true; | 1173 return true; |
1177 } | 1174 } |
1178 | 1175 |
1179 | 1176 |
| 1177 void FlowGraphOptimizer::AddToGuardedFields(Field* field) { |
| 1178 if ((field->guarded_cid() == kDynamicCid) || |
| 1179 (field->guarded_cid() == kIllegalCid)) { |
| 1180 return; |
| 1181 } |
| 1182 for (intptr_t j = 0; j < guarded_fields_->length(); j++) { |
| 1183 if ((*guarded_fields_)[j]->raw() == field->raw()) { |
| 1184 return; |
| 1185 } |
| 1186 } |
| 1187 guarded_fields_->Add(field); |
| 1188 } |
| 1189 |
| 1190 |
1180 void FlowGraphOptimizer::InlineImplicitInstanceGetter(InstanceCallInstr* call) { | 1191 void FlowGraphOptimizer::InlineImplicitInstanceGetter(InstanceCallInstr* call) { |
1181 ASSERT(call->HasICData()); | 1192 ASSERT(call->HasICData()); |
1182 const ICData& ic_data = *call->ic_data(); | 1193 const ICData& ic_data = *call->ic_data(); |
1183 Function& target = Function::Handle(); | 1194 Function& target = Function::Handle(); |
1184 GrowableArray<intptr_t> class_ids; | 1195 GrowableArray<intptr_t> class_ids; |
1185 ic_data.GetCheckAt(0, &class_ids, &target); | 1196 ic_data.GetCheckAt(0, &class_ids, &target); |
1186 ASSERT(class_ids.length() == 1); | 1197 ASSERT(class_ids.length() == 1); |
1187 // Inline implicit instance getter. | 1198 // Inline implicit instance getter. |
1188 const String& field_name = | 1199 const String& field_name = |
1189 String::Handle(Field::NameFromGetter(call->function_name())); | 1200 String::Handle(Field::NameFromGetter(call->function_name())); |
1190 const Field& field = Field::Handle(GetField(class_ids[0], field_name)); | 1201 const Field& field = Field::Handle(GetField(class_ids[0], field_name)); |
1191 ASSERT(!field.IsNull()); | 1202 ASSERT(!field.IsNull()); |
1192 | 1203 |
1193 if (InstanceCallNeedsClassCheck(call)) { | 1204 if (InstanceCallNeedsClassCheck(call)) { |
1194 AddReceiverCheck(call); | 1205 AddReceiverCheck(call); |
1195 } | 1206 } |
1196 LoadFieldInstr* load = new LoadFieldInstr( | 1207 LoadFieldInstr* load = new LoadFieldInstr( |
1197 new Value(call->ArgumentAt(0)), | 1208 new Value(call->ArgumentAt(0)), |
1198 field.Offset(), | 1209 field.Offset(), |
1199 AbstractType::ZoneHandle(field.type()), | 1210 AbstractType::ZoneHandle(field.type()), |
1200 field.is_final()); | 1211 field.is_final()); |
1201 if (field.guarded_cid() != kIllegalCid) { | 1212 if (field.guarded_cid() != kIllegalCid) { |
1202 if (!field.is_nullable() || (field.guarded_cid() == kNullCid)) { | 1213 if (!field.is_nullable() || (field.guarded_cid() == kNullCid)) { |
1203 load->set_result_cid(field.guarded_cid()); | 1214 load->set_result_cid(field.guarded_cid()); |
1204 } | 1215 } |
1205 load->set_field(&Field::ZoneHandle(field.raw())); | 1216 Field* the_field = &Field::ZoneHandle(field.raw()); |
| 1217 load->set_field(the_field); |
| 1218 AddToGuardedFields(the_field); |
1206 } | 1219 } |
1207 load->set_field_name(String::Handle(field.name()).ToCString()); | 1220 load->set_field_name(String::Handle(field.name()).ToCString()); |
1208 | 1221 |
1209 // Discard the environment from the original instruction because the load | 1222 // Discard the environment from the original instruction because the load |
1210 // can't deoptimize. | 1223 // can't deoptimize. |
1211 call->RemoveEnvironment(); | 1224 call->RemoveEnvironment(); |
1212 ReplaceCall(call, load); | 1225 ReplaceCall(call, load); |
1213 | 1226 |
1214 if (FLAG_inline_getter_with_guarded_cid) { | 1227 if (load->result_cid() != kDynamicCid) { |
1215 if (load->result_cid() != kDynamicCid) { | 1228 // Reset value types if guarded_cid was used. |
1216 // Reset value types if guarded_cid was used. | 1229 for (Value::Iterator it(load->input_use_list()); |
1217 for (Value::Iterator it(load->input_use_list()); | 1230 !it.Done(); |
1218 !it.Done(); | 1231 it.Advance()) { |
1219 it.Advance()) { | 1232 it.Current()->SetReachingType(NULL); |
1220 it.Current()->SetReachingType(NULL); | |
1221 } | |
1222 } | 1233 } |
1223 } | 1234 } |
1224 } | 1235 } |
1225 | 1236 |
1226 | 1237 |
1227 void FlowGraphOptimizer::InlineArrayLengthGetter(InstanceCallInstr* call, | 1238 void FlowGraphOptimizer::InlineArrayLengthGetter(InstanceCallInstr* call, |
1228 intptr_t length_offset, | 1239 intptr_t length_offset, |
1229 bool is_immutable, | 1240 bool is_immutable, |
1230 MethodRecognizer::Kind kind) { | 1241 MethodRecognizer::Kind kind) { |
1231 AddReceiverCheck(call); | 1242 AddReceiverCheck(call); |
(...skipping 3500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4732 if (changed) { | 4743 if (changed) { |
4733 // We may have changed the block order and the dominator tree. | 4744 // We may have changed the block order and the dominator tree. |
4734 flow_graph->DiscoverBlocks(); | 4745 flow_graph->DiscoverBlocks(); |
4735 GrowableArray<BitVector*> dominance_frontier; | 4746 GrowableArray<BitVector*> dominance_frontier; |
4736 flow_graph->ComputeDominators(&dominance_frontier); | 4747 flow_graph->ComputeDominators(&dominance_frontier); |
4737 } | 4748 } |
4738 } | 4749 } |
4739 | 4750 |
4740 | 4751 |
4741 } // namespace dart | 4752 } // namespace dart |
OLD | NEW |