| 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/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/flow_graph_builder.h" | 10 #include "vm/flow_graph_builder.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 ic_data.AddCheck(class_ids, function); | 171 ic_data.AddCheck(class_ids, function); |
| 172 } else { | 172 } else { |
| 173 ASSERT(class_ids.length() == 1); | 173 ASSERT(class_ids.length() == 1); |
| 174 ic_data.AddReceiverCheck(class_ids[0], function); | 174 ic_data.AddReceiverCheck(class_ids[0], function); |
| 175 } | 175 } |
| 176 call->set_ic_data(&ic_data); | 176 call->set_ic_data(&ic_data); |
| 177 return true; | 177 return true; |
| 178 } | 178 } |
| 179 | 179 |
| 180 | 180 |
| 181 static const ICData& SpecializeICData(const ICData& ic_data, intptr_t cid) { | 181 static const ICData& TrySpecializeICData(const ICData& ic_data, intptr_t cid) { |
| 182 ASSERT(ic_data.num_args_tested() == 1); | 182 ASSERT(ic_data.num_args_tested() == 1); |
| 183 | 183 |
| 184 if ((ic_data.NumberOfChecks() == 1) && | 184 if ((ic_data.NumberOfChecks() == 1) && |
| 185 (ic_data.GetReceiverClassIdAt(0) == cid)) { | 185 (ic_data.GetReceiverClassIdAt(0) == cid)) { |
| 186 return ic_data; // Nothing to do | 186 return ic_data; // Nothing to do |
| 187 } | 187 } |
| 188 | 188 |
| 189 const ICData& new_ic_data = ICData::ZoneHandle(ICData::New( | |
| 190 Function::Handle(ic_data.function()), | |
| 191 String::Handle(ic_data.target_name()), | |
| 192 Object::empty_array(), // Dummy argument descriptor. | |
| 193 ic_data.deopt_id(), | |
| 194 ic_data.num_args_tested())); | |
| 195 new_ic_data.set_deopt_reason(ic_data.deopt_reason()); | |
| 196 | |
| 197 const Function& function = | 189 const Function& function = |
| 198 Function::Handle(ic_data.GetTargetForReceiverClassId(cid)); | 190 Function::Handle(ic_data.GetTargetForReceiverClassId(cid)); |
| 191 // TODO(fschneider): Try looking up the function on the class if it is |
| 192 // not found in the ICData. |
| 199 if (!function.IsNull()) { | 193 if (!function.IsNull()) { |
| 194 const ICData& new_ic_data = ICData::ZoneHandle(ICData::New( |
| 195 Function::Handle(ic_data.function()), |
| 196 String::Handle(ic_data.target_name()), |
| 197 Object::empty_array(), // Dummy argument descriptor. |
| 198 ic_data.deopt_id(), |
| 199 ic_data.num_args_tested())); |
| 200 new_ic_data.set_deopt_reason(ic_data.deopt_reason()); |
| 200 new_ic_data.AddReceiverCheck(cid, function); | 201 new_ic_data.AddReceiverCheck(cid, function); |
| 202 return new_ic_data; |
| 201 } | 203 } |
| 202 | 204 |
| 203 return new_ic_data; | 205 return ic_data; |
| 204 } | 206 } |
| 205 | 207 |
| 206 | 208 |
| 207 void FlowGraphOptimizer::SpecializePolymorphicInstanceCall( | 209 void FlowGraphOptimizer::SpecializePolymorphicInstanceCall( |
| 208 PolymorphicInstanceCallInstr* call) { | 210 PolymorphicInstanceCallInstr* call) { |
| 209 if (!call->with_checks()) { | 211 if (!call->with_checks()) { |
| 210 return; // Already specialized. | 212 return; // Already specialized. |
| 211 } | 213 } |
| 212 | 214 |
| 213 const intptr_t receiver_cid = | 215 const intptr_t receiver_cid = |
| 214 call->PushArgumentAt(0)->value()->Type()->ToCid(); | 216 call->PushArgumentAt(0)->value()->Type()->ToCid(); |
| 215 if (receiver_cid == kDynamicCid) { | 217 if (receiver_cid == kDynamicCid) { |
| 216 return; // No information about receiver was infered. | 218 return; // No information about receiver was infered. |
| 217 } | 219 } |
| 218 | 220 |
| 219 const ICData& ic_data = SpecializeICData(call->ic_data(), receiver_cid); | 221 const ICData& ic_data = TrySpecializeICData(call->ic_data(), receiver_cid); |
| 222 if (ic_data.raw() == call->ic_data().raw()) { |
| 223 // No specialization. |
| 224 return; |
| 225 } |
| 220 | 226 |
| 221 const bool with_checks = false; | 227 const bool with_checks = false; |
| 222 PolymorphicInstanceCallInstr* specialized = | 228 PolymorphicInstanceCallInstr* specialized = |
| 223 new PolymorphicInstanceCallInstr(call->instance_call(), | 229 new PolymorphicInstanceCallInstr(call->instance_call(), |
| 224 ic_data, | 230 ic_data, |
| 225 with_checks); | 231 with_checks); |
| 226 call->ReplaceWith(specialized, current_iterator()); | 232 call->ReplaceWith(specialized, current_iterator()); |
| 227 } | 233 } |
| 228 | 234 |
| 229 | 235 |
| (...skipping 8085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8315 } | 8321 } |
| 8316 | 8322 |
| 8317 // Insert materializations at environment uses. | 8323 // Insert materializations at environment uses. |
| 8318 for (intptr_t i = 0; i < exits.length(); i++) { | 8324 for (intptr_t i = 0; i < exits.length(); i++) { |
| 8319 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); | 8325 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); |
| 8320 } | 8326 } |
| 8321 } | 8327 } |
| 8322 | 8328 |
| 8323 | 8329 |
| 8324 } // namespace dart | 8330 } // namespace dart |
| OLD | NEW |