Chromium Code Reviews| 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/flow_graph_builder.h" | 7 #include "vm/flow_graph_builder.h" |
| 8 #include "vm/hash_map.h" | 8 #include "vm/hash_map.h" |
| 9 #include "vm/il_printer.h" | 9 #include "vm/il_printer.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| 11 #include "vm/parser.h" | 11 #include "vm/parser.h" |
| 12 #include "vm/scopes.h" | 12 #include "vm/scopes.h" |
| 13 #include "vm/symbols.h" | 13 #include "vm/symbols.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 DECLARE_FLAG(bool, eliminate_type_checks); | 17 DECLARE_FLAG(bool, eliminate_type_checks); |
| 18 DECLARE_FLAG(bool, enable_type_checks); | 18 DECLARE_FLAG(bool, enable_type_checks); |
| 19 DEFINE_FLAG(bool, trace_optimization, false, "Print optimization details."); | 19 DEFINE_FLAG(bool, trace_optimization, false, "Print optimization details."); |
| 20 DECLARE_FLAG(bool, trace_type_check_elimination); | 20 DECLARE_FLAG(bool, trace_type_check_elimination); |
| 21 DEFINE_FLAG(bool, use_cha, true, "Use class hierarchy analysis."); | |
| 21 | 22 |
| 22 void FlowGraphOptimizer::ApplyICData() { | 23 void FlowGraphOptimizer::ApplyICData() { |
| 23 VisitBlocks(); | 24 VisitBlocks(); |
| 24 } | 25 } |
| 25 | 26 |
| 26 | 27 |
| 27 void FlowGraphOptimizer::OptimizeComputations() { | 28 void FlowGraphOptimizer::OptimizeComputations() { |
| 28 for (intptr_t i = 0; i < block_order_.length(); ++i) { | 29 for (intptr_t i = 0; i < block_order_.length(); ++i) { |
| 29 BlockEntryInstr* entry = block_order_[i]; | 30 BlockEntryInstr* entry = block_order_[i]; |
| 30 entry->Accept(this); | 31 entry->Accept(this); |
| (...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 } | 862 } |
| 862 | 863 |
| 863 | 864 |
| 864 void FlowGraphTypePropagator::VisitParameter(ParameterInstr* param) { | 865 void FlowGraphTypePropagator::VisitParameter(ParameterInstr* param) { |
| 865 // TODO(regis): Once we inline functions, the propagated type of the formal | 866 // TODO(regis): Once we inline functions, the propagated type of the formal |
| 866 // parameter will reflect the compile type of the passed-in argument. | 867 // parameter will reflect the compile type of the passed-in argument. |
| 867 // For now, we do not know anything about the argument type and therefore set | 868 // For now, we do not know anything about the argument type and therefore set |
| 868 // it to the DynamicType, unless the argument is a compiler generated value, | 869 // it to the DynamicType, unless the argument is a compiler generated value, |
| 869 // i.e. the receiver argument or the constructor phase argument. | 870 // i.e. the receiver argument or the constructor phase argument. |
| 870 AbstractType& param_type = AbstractType::Handle(Type::DynamicType()); | 871 AbstractType& param_type = AbstractType::Handle(Type::DynamicType()); |
| 872 param->SetPropagatedCid(kDynamicCid); | |
| 871 if (param->index() < 2) { | 873 if (param->index() < 2) { |
| 872 const Function& function = parsed_function().function(); | 874 const Function& function = parsed_function().function(); |
| 873 if (((param->index() == 0) && function.IsDynamicFunction()) || | 875 if (((param->index() == 0) && function.IsDynamicFunction()) || |
| 874 ((param->index() == 1) && function.IsConstructor())) { | 876 ((param->index() == 1) && function.IsConstructor())) { |
| 875 // Parameter is the receiver or the constructor phase. | 877 // Parameter is the receiver or the constructor phase. |
| 876 LocalScope* scope = parsed_function().node_sequence()->scope(); | 878 LocalScope* scope = parsed_function().node_sequence()->scope(); |
| 877 param_type = scope->VariableAt(param->index())->type().raw(); | 879 param_type = scope->VariableAt(param->index())->type().raw(); |
| 880 if (FLAG_use_cha) { | |
| 881 intptr_t cid = Class::Handle(param_type.type_class()).id(); | |
|
regis
2012/08/21 20:52:21
const
srdjan
2012/08/21 22:08:15
Done.
| |
| 882 if (!Isolate::Current()->class_table()->HasSubclasses(cid)) { | |
| 883 // Receiver's class has no subclasses. | |
| 884 param->SetPropagatedCid(cid); | |
| 885 } | |
| 886 } | |
| 878 } | 887 } |
| 879 } | 888 } |
| 880 bool changed = param->SetPropagatedType(param_type); | 889 bool changed = param->SetPropagatedType(param_type); |
| 881 if (changed) { | 890 if (changed) { |
| 882 still_changing_ = true; | 891 still_changing_ = true; |
| 883 } | 892 } |
| 884 param->SetPropagatedCid(kDynamicCid); | |
| 885 } | 893 } |
| 886 | 894 |
| 887 | 895 |
| 888 void FlowGraphTypePropagator::PropagateTypes() { | 896 void FlowGraphTypePropagator::PropagateTypes() { |
| 889 // TODO(regis): Is there a way to make this more efficient, e.g. by visiting | 897 // TODO(regis): Is there a way to make this more efficient, e.g. by visiting |
| 890 // only blocks depending on blocks that have changed and not the whole graph. | 898 // only blocks depending on blocks that have changed and not the whole graph. |
| 891 do { | 899 do { |
| 892 still_changing_ = false; | 900 still_changing_ = false; |
| 893 VisitBlocks(); | 901 VisitBlocks(); |
| 894 } while (still_changing_); | 902 } while (still_changing_); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 930 OS::Print("Replacing v%d with v%d\n", | 938 OS::Print("Replacing v%d with v%d\n", |
| 931 instr->ssa_temp_index(), | 939 instr->ssa_temp_index(), |
| 932 result->ssa_temp_index()); | 940 result->ssa_temp_index()); |
| 933 } | 941 } |
| 934 } | 942 } |
| 935 } | 943 } |
| 936 } | 944 } |
| 937 | 945 |
| 938 | 946 |
| 939 } // namespace dart | 947 } // namespace dart |
| OLD | NEW |