| 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" |
| (...skipping 2163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2174 | 2174 |
| 2175 | 2175 |
| 2176 void FlowGraphTypePropagator::VisitParameter(ParameterInstr* param) { | 2176 void FlowGraphTypePropagator::VisitParameter(ParameterInstr* param) { |
| 2177 // TODO(regis): Once we inline functions, the propagated type of the formal | 2177 // TODO(regis): Once we inline functions, the propagated type of the formal |
| 2178 // parameter will reflect the compile type of the passed-in argument. | 2178 // parameter will reflect the compile type of the passed-in argument. |
| 2179 // For now, we do not know anything about the argument type and therefore set | 2179 // For now, we do not know anything about the argument type and therefore set |
| 2180 // it to the DynamicType, unless the argument is a compiler generated value, | 2180 // it to the DynamicType, unless the argument is a compiler generated value, |
| 2181 // i.e. the receiver argument or the constructor phase argument. | 2181 // i.e. the receiver argument or the constructor phase argument. |
| 2182 AbstractType& param_type = AbstractType::Handle(Type::DynamicType()); | 2182 AbstractType& param_type = AbstractType::Handle(Type::DynamicType()); |
| 2183 param->SetPropagatedCid(kDynamicCid); | 2183 param->SetPropagatedCid(kDynamicCid); |
| 2184 if (param->index() < 2) { | 2184 bool param_type_is_known = false; |
| 2185 if (param->index() == 0) { |
| 2185 const Function& function = parsed_function().function(); | 2186 const Function& function = parsed_function().function(); |
| 2186 if (((param->index() == 0) && function.IsDynamicFunction()) || | 2187 if ((function.IsDynamicFunction() || function.IsConstructor())) { |
| 2187 ((param->index() == 1) && function.IsConstructor())) { | 2188 // Parameter is the receiver . |
| 2188 // Parameter is the receiver or the constructor phase. | 2189 param_type_is_known = true; |
| 2189 LocalScope* scope = parsed_function().node_sequence()->scope(); | 2190 } |
| 2190 param_type = scope->VariableAt(param->index())->type().raw(); | 2191 } else if ((param->index() == 1) && |
| 2191 if (FLAG_use_cha) { | 2192 parsed_function().function().IsConstructor()) { |
| 2192 const intptr_t cid = Class::Handle(param_type.type_class()).id(); | 2193 // Parameter is the constructor phase. |
| 2193 if (!CHA::HasSubclasses(cid)) { | 2194 param_type_is_known = true; |
| 2194 // Receiver's class has no subclasses. | 2195 } |
| 2195 param->SetPropagatedCid(cid); | 2196 if (param_type_is_known) { |
| 2196 } | 2197 LocalScope* scope = parsed_function().node_sequence()->scope(); |
| 2198 param_type = scope->VariableAt(param->index())->type().raw(); |
| 2199 if (FLAG_use_cha) { |
| 2200 const intptr_t cid = Class::Handle(param_type.type_class()).id(); |
| 2201 if (!CHA::HasSubclasses(cid)) { |
| 2202 // Receiver's class has no subclasses. |
| 2203 param->SetPropagatedCid(cid); |
| 2197 } | 2204 } |
| 2198 } | 2205 } |
| 2199 } | 2206 } |
| 2200 bool changed = param->SetPropagatedType(param_type); | 2207 bool changed = param->SetPropagatedType(param_type); |
| 2201 if (changed) { | 2208 if (changed) { |
| 2202 still_changing_ = true; | 2209 still_changing_ = true; |
| 2203 } | 2210 } |
| 2204 } | 2211 } |
| 2205 | 2212 |
| 2206 | 2213 |
| (...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3328 | 3335 |
| 3329 if (FLAG_trace_constant_propagation) { | 3336 if (FLAG_trace_constant_propagation) { |
| 3330 OS::Print("\n==== After constant propagation ====\n"); | 3337 OS::Print("\n==== After constant propagation ====\n"); |
| 3331 FlowGraphPrinter printer(*graph_); | 3338 FlowGraphPrinter printer(*graph_); |
| 3332 printer.PrintBlocks(); | 3339 printer.PrintBlocks(); |
| 3333 } | 3340 } |
| 3334 } | 3341 } |
| 3335 | 3342 |
| 3336 | 3343 |
| 3337 } // namespace dart | 3344 } // namespace dart |
| OLD | NEW |