| 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 #ifndef DART_PRECOMPILED_RUNTIME | 4 #ifndef DART_PRECOMPILED_RUNTIME |
| 5 #include "vm/jit_optimizer.h" | 5 #include "vm/jit_optimizer.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/branch_optimizer.h" | 8 #include "vm/branch_optimizer.h" |
| 9 #include "vm/cha.h" | 9 #include "vm/cha.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 call->set_ic_data(&ic_data); | 185 call->set_ic_data(&ic_data); |
| 186 return true; | 186 return true; |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 return false; | 191 return false; |
| 192 } | 192 } |
| 193 | 193 |
| 194 | 194 |
| 195 const ICData& JitOptimizer::TrySpecializeICData(const ICData& ic_data, | |
| 196 intptr_t cid) { | |
| 197 ASSERT(ic_data.NumArgsTested() == 1); | |
| 198 | |
| 199 if ((ic_data.NumberOfUsedChecks() == 1) && ic_data.HasReceiverClassId(cid)) { | |
| 200 return ic_data; // Nothing to do | |
| 201 } | |
| 202 | |
| 203 const Function& function = | |
| 204 Function::Handle(Z, ic_data.GetTargetForReceiverClassId(cid)); | |
| 205 // TODO(fschneider): Try looking up the function on the class if it is | |
| 206 // not found in the ICData. | |
| 207 if (!function.IsNull()) { | |
| 208 const ICData& new_ic_data = ICData::ZoneHandle( | |
| 209 Z, ICData::New(Function::Handle(Z, ic_data.Owner()), | |
| 210 String::Handle(Z, ic_data.target_name()), | |
| 211 Object::empty_array(), // Dummy argument descriptor. | |
| 212 ic_data.deopt_id(), ic_data.NumArgsTested(), false)); | |
| 213 new_ic_data.SetDeoptReasons(ic_data.DeoptReasons()); | |
| 214 new_ic_data.AddReceiverCheck(cid, function); | |
| 215 return new_ic_data; | |
| 216 } | |
| 217 | |
| 218 return ic_data; | |
| 219 } | |
| 220 | |
| 221 | |
| 222 void JitOptimizer::SpecializePolymorphicInstanceCall( | 195 void JitOptimizer::SpecializePolymorphicInstanceCall( |
| 223 PolymorphicInstanceCallInstr* call) { | 196 PolymorphicInstanceCallInstr* call) { |
| 224 if (!FLAG_polymorphic_with_deopt) { | 197 if (!FLAG_polymorphic_with_deopt) { |
| 225 // Specialization adds receiver checks which can lead to deoptimization. | 198 // Specialization adds receiver checks which can lead to deoptimization. |
| 226 return; | 199 return; |
| 227 } | 200 } |
| 228 if (!call->with_checks()) { | 201 if (!call->with_checks()) { |
| 229 return; // Already specialized. | 202 return; // Already specialized. |
| 230 } | 203 } |
| 231 | 204 |
| 232 const intptr_t receiver_cid = | 205 const intptr_t receiver_cid = |
| 233 call->PushArgumentAt(0)->value()->Type()->ToCid(); | 206 call->PushArgumentAt(0)->value()->Type()->ToCid(); |
| 234 if (receiver_cid == kDynamicCid) { | 207 if (receiver_cid == kDynamicCid) { |
| 235 return; // No information about receiver was infered. | 208 return; // No information about receiver was infered. |
| 236 } | 209 } |
| 237 | 210 |
| 238 const ICData& ic_data = TrySpecializeICData(call->ic_data(), receiver_cid); | 211 const ICData& ic_data = FlowGraphCompiler::TrySpecializeICDataByReceiverCid( |
| 212 call->ic_data(), receiver_cid); |
| 239 if (ic_data.raw() == call->ic_data().raw()) { | 213 if (ic_data.raw() == call->ic_data().raw()) { |
| 240 // No specialization. | 214 // No specialization. |
| 241 return; | 215 return; |
| 242 } | 216 } |
| 243 | 217 |
| 244 const bool with_checks = false; | 218 const bool with_checks = false; |
| 245 const bool complete = false; | 219 const bool complete = false; |
| 246 PolymorphicInstanceCallInstr* specialized = | 220 PolymorphicInstanceCallInstr* specialized = |
| 247 new (Z) PolymorphicInstanceCallInstr(call->instance_call(), ic_data, | 221 new (Z) PolymorphicInstanceCallInstr(call->instance_call(), ic_data, |
| 248 with_checks, complete); | 222 with_checks, complete); |
| (...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1859 // Discard the environment from the original instruction because the store | 1833 // Discard the environment from the original instruction because the store |
| 1860 // can't deoptimize. | 1834 // can't deoptimize. |
| 1861 instr->RemoveEnvironment(); | 1835 instr->RemoveEnvironment(); |
| 1862 ReplaceCall(instr, store); | 1836 ReplaceCall(instr, store); |
| 1863 return true; | 1837 return true; |
| 1864 } | 1838 } |
| 1865 | 1839 |
| 1866 | 1840 |
| 1867 } // namespace dart | 1841 } // namespace dart |
| 1868 #endif // DART_PRECOMPILED_RUNTIME | 1842 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |