| 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 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 if (call->ArgumentCount() == 2) { | 1306 if (call->ArgumentCount() == 2) { |
| 1307 instantiator_type_args = flow_graph()->constant_null(); | 1307 instantiator_type_args = flow_graph()->constant_null(); |
| 1308 function_type_args = flow_graph()->constant_null(); | 1308 function_type_args = flow_graph()->constant_null(); |
| 1309 ASSERT(call->MatchesCoreName(Symbols::_simpleInstanceOf())); | 1309 ASSERT(call->MatchesCoreName(Symbols::_simpleInstanceOf())); |
| 1310 type = AbstractType::Cast(call->ArgumentAt(1)->AsConstant()->value()).raw(); | 1310 type = AbstractType::Cast(call->ArgumentAt(1)->AsConstant()->value()).raw(); |
| 1311 } else { | 1311 } else { |
| 1312 instantiator_type_args = call->ArgumentAt(1); | 1312 instantiator_type_args = call->ArgumentAt(1); |
| 1313 function_type_args = call->ArgumentAt(2); | 1313 function_type_args = call->ArgumentAt(2); |
| 1314 type = AbstractType::Cast(call->ArgumentAt(3)->AsConstant()->value()).raw(); | 1314 type = AbstractType::Cast(call->ArgumentAt(3)->AsConstant()->value()).raw(); |
| 1315 } | 1315 } |
| 1316 |
| 1317 if (TypeCheckAsClassEquality(type)) { |
| 1318 LoadClassIdInstr* left_cid = new (Z) LoadClassIdInstr(new (Z) Value(left)); |
| 1319 InsertBefore(call, left_cid, NULL, FlowGraph::kValue); |
| 1320 const intptr_t type_cid = Class::Handle(Z, type.type_class()).id(); |
| 1321 ConstantInstr* cid = |
| 1322 flow_graph()->GetConstant(Smi::Handle(Z, Smi::New(type_cid))); |
| 1323 |
| 1324 StrictCompareInstr* check_cid = new (Z) StrictCompareInstr( |
| 1325 call->token_pos(), Token::kEQ_STRICT, new (Z) Value(left_cid), |
| 1326 new (Z) Value(cid), /* number_check = */ false, Thread::kNoDeoptId); |
| 1327 ReplaceCall(call, check_cid); |
| 1328 return; |
| 1329 } |
| 1330 |
| 1316 const ICData& unary_checks = | 1331 const ICData& unary_checks = |
| 1317 ICData::ZoneHandle(Z, call->ic_data()->AsUnaryClassChecks()); | 1332 ICData::ZoneHandle(Z, call->ic_data()->AsUnaryClassChecks()); |
| 1318 const intptr_t number_of_checks = unary_checks.NumberOfChecks(); | 1333 const intptr_t number_of_checks = unary_checks.NumberOfChecks(); |
| 1319 if ((number_of_checks > 0) && | 1334 if ((number_of_checks > 0) && |
| 1320 (number_of_checks <= FLAG_max_polymorphic_checks)) { | 1335 (number_of_checks <= FLAG_max_polymorphic_checks)) { |
| 1321 ZoneGrowableArray<intptr_t>* results = | 1336 ZoneGrowableArray<intptr_t>* results = |
| 1322 new (Z) ZoneGrowableArray<intptr_t>(number_of_checks * 2); | 1337 new (Z) ZoneGrowableArray<intptr_t>(number_of_checks * 2); |
| 1323 Bool& as_bool = | 1338 Bool& as_bool = |
| 1324 Bool::ZoneHandle(Z, InstanceOfAsBool(unary_checks, type, results)); | 1339 Bool::ZoneHandle(Z, InstanceOfAsBool(unary_checks, type, results)); |
| 1325 if (as_bool.IsNull()) { | 1340 if (as_bool.IsNull()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1342 push->ReplaceUsesWith(push->value()->definition()); | 1357 push->ReplaceUsesWith(push->value()->definition()); |
| 1343 push->RemoveFromGraph(); | 1358 push->RemoveFromGraph(); |
| 1344 } | 1359 } |
| 1345 call->ReplaceUsesWith(bool_const); | 1360 call->ReplaceUsesWith(bool_const); |
| 1346 ASSERT(current_iterator()->Current() == call); | 1361 ASSERT(current_iterator()->Current() == call); |
| 1347 current_iterator()->RemoveCurrentFromGraph(); | 1362 current_iterator()->RemoveCurrentFromGraph(); |
| 1348 return; | 1363 return; |
| 1349 } | 1364 } |
| 1350 } | 1365 } |
| 1351 | 1366 |
| 1352 if (TypeCheckAsClassEquality(type)) { | |
| 1353 LoadClassIdInstr* left_cid = new (Z) LoadClassIdInstr(new (Z) Value(left)); | |
| 1354 InsertBefore(call, left_cid, NULL, FlowGraph::kValue); | |
| 1355 const intptr_t type_cid = Class::Handle(Z, type.type_class()).id(); | |
| 1356 ConstantInstr* cid = | |
| 1357 flow_graph()->GetConstant(Smi::Handle(Z, Smi::New(type_cid))); | |
| 1358 | |
| 1359 StrictCompareInstr* check_cid = new (Z) StrictCompareInstr( | |
| 1360 call->token_pos(), Token::kEQ_STRICT, new (Z) Value(left_cid), | |
| 1361 new (Z) Value(cid), /* number_check = */ false, Thread::kNoDeoptId); | |
| 1362 ReplaceCall(call, check_cid); | |
| 1363 return; | |
| 1364 } | |
| 1365 | |
| 1366 InstanceOfInstr* instance_of = new (Z) InstanceOfInstr( | 1367 InstanceOfInstr* instance_of = new (Z) InstanceOfInstr( |
| 1367 call->token_pos(), new (Z) Value(left), | 1368 call->token_pos(), new (Z) Value(left), |
| 1368 new (Z) Value(instantiator_type_args), new (Z) Value(function_type_args), | 1369 new (Z) Value(instantiator_type_args), new (Z) Value(function_type_args), |
| 1369 type, call->deopt_id()); | 1370 type, call->deopt_id()); |
| 1370 ReplaceCall(call, instance_of); | 1371 ReplaceCall(call, instance_of); |
| 1371 } | 1372 } |
| 1372 | 1373 |
| 1373 | 1374 |
| 1374 // TODO(srdjan): Apply optimizations as in ReplaceWithInstanceOf (TestCids). | 1375 // TODO(srdjan): Apply optimizations as in ReplaceWithInstanceOf (TestCids). |
| 1375 void JitOptimizer::ReplaceWithTypeCast(InstanceCallInstr* call) { | 1376 void JitOptimizer::ReplaceWithTypeCast(InstanceCallInstr* call) { |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 // Discard the environment from the original instruction because the store | 1772 // Discard the environment from the original instruction because the store |
| 1772 // can't deoptimize. | 1773 // can't deoptimize. |
| 1773 instr->RemoveEnvironment(); | 1774 instr->RemoveEnvironment(); |
| 1774 ReplaceCall(instr, store); | 1775 ReplaceCall(instr, store); |
| 1775 return true; | 1776 return true; |
| 1776 } | 1777 } |
| 1777 | 1778 |
| 1778 | 1779 |
| 1779 } // namespace dart | 1780 } // namespace dart |
| 1780 #endif // DART_PRECOMPILED_RUNTIME | 1781 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |