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 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 } | 1328 } |
1329 | 1329 |
1330 return true; // May deoptimize since we have not identified all 'true' tests. | 1330 return true; // May deoptimize since we have not identified all 'true' tests. |
1331 } | 1331 } |
1332 | 1332 |
1333 | 1333 |
1334 // TODO(srdjan): Use ICData to check if always true or false. | 1334 // TODO(srdjan): Use ICData to check if always true or false. |
1335 void JitOptimizer::ReplaceWithInstanceOf(InstanceCallInstr* call) { | 1335 void JitOptimizer::ReplaceWithInstanceOf(InstanceCallInstr* call) { |
1336 ASSERT(Token::IsTypeTestOperator(call->token_kind())); | 1336 ASSERT(Token::IsTypeTestOperator(call->token_kind())); |
1337 Definition* left = call->ArgumentAt(0); | 1337 Definition* left = call->ArgumentAt(0); |
1338 Definition* type_args = NULL; | 1338 Definition* instantiator_type_args = NULL; |
| 1339 Definition* function_type_args = NULL; |
1339 AbstractType& type = AbstractType::ZoneHandle(Z); | 1340 AbstractType& type = AbstractType::ZoneHandle(Z); |
1340 if (call->ArgumentCount() == 2) { | 1341 if (call->ArgumentCount() == 2) { |
1341 type_args = flow_graph()->constant_null(); | 1342 instantiator_type_args = flow_graph()->constant_null(); |
| 1343 function_type_args = flow_graph()->constant_null(); |
1342 ASSERT(call->MatchesCoreName(Symbols::_simpleInstanceOf())); | 1344 ASSERT(call->MatchesCoreName(Symbols::_simpleInstanceOf())); |
1343 type = AbstractType::Cast(call->ArgumentAt(1)->AsConstant()->value()).raw(); | 1345 type = AbstractType::Cast(call->ArgumentAt(1)->AsConstant()->value()).raw(); |
1344 } else { | 1346 } else { |
1345 type_args = call->ArgumentAt(1); | 1347 instantiator_type_args = call->ArgumentAt(1); |
1346 type = AbstractType::Cast(call->ArgumentAt(2)->AsConstant()->value()).raw(); | 1348 function_type_args = call->ArgumentAt(2); |
| 1349 type = AbstractType::Cast(call->ArgumentAt(3)->AsConstant()->value()).raw(); |
1347 } | 1350 } |
1348 const ICData& unary_checks = | 1351 const ICData& unary_checks = |
1349 ICData::ZoneHandle(Z, call->ic_data()->AsUnaryClassChecks()); | 1352 ICData::ZoneHandle(Z, call->ic_data()->AsUnaryClassChecks()); |
1350 const intptr_t number_of_checks = unary_checks.NumberOfChecks(); | 1353 const intptr_t number_of_checks = unary_checks.NumberOfChecks(); |
1351 if ((number_of_checks > 0) && | 1354 if ((number_of_checks > 0) && |
1352 (number_of_checks <= FLAG_max_polymorphic_checks)) { | 1355 (number_of_checks <= FLAG_max_polymorphic_checks)) { |
1353 ZoneGrowableArray<intptr_t>* results = | 1356 ZoneGrowableArray<intptr_t>* results = |
1354 new (Z) ZoneGrowableArray<intptr_t>(number_of_checks * 2); | 1357 new (Z) ZoneGrowableArray<intptr_t>(number_of_checks * 2); |
1355 Bool& as_bool = | 1358 Bool& as_bool = |
1356 Bool::ZoneHandle(Z, InstanceOfAsBool(unary_checks, type, results)); | 1359 Bool::ZoneHandle(Z, InstanceOfAsBool(unary_checks, type, results)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1390 | 1393 |
1391 StrictCompareInstr* check_cid = | 1394 StrictCompareInstr* check_cid = |
1392 new (Z) StrictCompareInstr(call->token_pos(), Token::kEQ_STRICT, | 1395 new (Z) StrictCompareInstr(call->token_pos(), Token::kEQ_STRICT, |
1393 new (Z) Value(left_cid), new (Z) Value(cid), | 1396 new (Z) Value(left_cid), new (Z) Value(cid), |
1394 false); // No number check. | 1397 false); // No number check. |
1395 ReplaceCall(call, check_cid); | 1398 ReplaceCall(call, check_cid); |
1396 return; | 1399 return; |
1397 } | 1400 } |
1398 | 1401 |
1399 InstanceOfInstr* instance_of = new (Z) InstanceOfInstr( | 1402 InstanceOfInstr* instance_of = new (Z) InstanceOfInstr( |
1400 call->token_pos(), new (Z) Value(left), new (Z) Value(type_args), | 1403 call->token_pos(), new (Z) Value(left), |
1401 NULL, // TODO(regis): Pass function type args. | 1404 new (Z) Value(instantiator_type_args), new (Z) Value(function_type_args), |
1402 type, call->deopt_id()); | 1405 type, call->deopt_id()); |
1403 ReplaceCall(call, instance_of); | 1406 ReplaceCall(call, instance_of); |
1404 } | 1407 } |
1405 | 1408 |
1406 | 1409 |
1407 // TODO(srdjan): Apply optimizations as in ReplaceWithInstanceOf (TestCids). | 1410 // TODO(srdjan): Apply optimizations as in ReplaceWithInstanceOf (TestCids). |
1408 void JitOptimizer::ReplaceWithTypeCast(InstanceCallInstr* call) { | 1411 void JitOptimizer::ReplaceWithTypeCast(InstanceCallInstr* call) { |
1409 ASSERT(Token::IsTypeCastOperator(call->token_kind())); | 1412 ASSERT(Token::IsTypeCastOperator(call->token_kind())); |
1410 Definition* left = call->ArgumentAt(0); | 1413 Definition* left = call->ArgumentAt(0); |
1411 Definition* type_args = call->ArgumentAt(1); | 1414 Definition* instantiator_type_args = call->ArgumentAt(1); |
| 1415 Definition* function_type_args = call->ArgumentAt(2); |
1412 const AbstractType& type = | 1416 const AbstractType& type = |
1413 AbstractType::Cast(call->ArgumentAt(2)->AsConstant()->value()); | 1417 AbstractType::Cast(call->ArgumentAt(3)->AsConstant()->value()); |
1414 ASSERT(!type.IsMalformedOrMalbounded()); | 1418 ASSERT(!type.IsMalformedOrMalbounded()); |
1415 const ICData& unary_checks = | 1419 const ICData& unary_checks = |
1416 ICData::ZoneHandle(Z, call->ic_data()->AsUnaryClassChecks()); | 1420 ICData::ZoneHandle(Z, call->ic_data()->AsUnaryClassChecks()); |
1417 const intptr_t number_of_checks = unary_checks.NumberOfChecks(); | 1421 const intptr_t number_of_checks = unary_checks.NumberOfChecks(); |
1418 if ((number_of_checks > 0) && | 1422 if ((number_of_checks > 0) && |
1419 (number_of_checks <= FLAG_max_polymorphic_checks)) { | 1423 (number_of_checks <= FLAG_max_polymorphic_checks)) { |
1420 ZoneGrowableArray<intptr_t>* results = | 1424 ZoneGrowableArray<intptr_t>* results = |
1421 new (Z) ZoneGrowableArray<intptr_t>(number_of_checks * 2); | 1425 new (Z) ZoneGrowableArray<intptr_t>(number_of_checks * 2); |
1422 const Bool& as_bool = | 1426 const Bool& as_bool = |
1423 Bool::ZoneHandle(Z, InstanceOfAsBool(unary_checks, type, results)); | 1427 Bool::ZoneHandle(Z, InstanceOfAsBool(unary_checks, type, results)); |
1424 if (as_bool.raw() == Bool::True().raw()) { | 1428 if (as_bool.raw() == Bool::True().raw()) { |
1425 AddReceiverCheck(call); | 1429 AddReceiverCheck(call); |
1426 // Remove the original push arguments. | 1430 // Remove the original push arguments. |
1427 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) { | 1431 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) { |
1428 PushArgumentInstr* push = call->PushArgumentAt(i); | 1432 PushArgumentInstr* push = call->PushArgumentAt(i); |
1429 push->ReplaceUsesWith(push->value()->definition()); | 1433 push->ReplaceUsesWith(push->value()->definition()); |
1430 push->RemoveFromGraph(); | 1434 push->RemoveFromGraph(); |
1431 } | 1435 } |
1432 // Remove call, replace it with 'left'. | 1436 // Remove call, replace it with 'left'. |
1433 call->ReplaceUsesWith(left); | 1437 call->ReplaceUsesWith(left); |
1434 ASSERT(current_iterator()->Current() == call); | 1438 ASSERT(current_iterator()->Current() == call); |
1435 current_iterator()->RemoveCurrentFromGraph(); | 1439 current_iterator()->RemoveCurrentFromGraph(); |
1436 return; | 1440 return; |
1437 } | 1441 } |
1438 } | 1442 } |
1439 AssertAssignableInstr* assert_as = new (Z) AssertAssignableInstr( | 1443 AssertAssignableInstr* assert_as = new (Z) AssertAssignableInstr( |
1440 call->token_pos(), new (Z) Value(left), new (Z) Value(type_args), | 1444 call->token_pos(), new (Z) Value(left), |
1441 NULL, // TODO(regis): Pass function type arguments. | 1445 new (Z) Value(instantiator_type_args), new (Z) Value(function_type_args), |
1442 type, Symbols::InTypeCast(), call->deopt_id()); | 1446 type, Symbols::InTypeCast(), call->deopt_id()); |
1443 ReplaceCall(call, assert_as); | 1447 ReplaceCall(call, assert_as); |
1444 } | 1448 } |
1445 | 1449 |
1446 | 1450 |
1447 bool JitOptimizer::LookupMethodFor(int class_id, | 1451 bool JitOptimizer::LookupMethodFor(int class_id, |
1448 const ArgumentsDescriptor& args_desc, | 1452 const ArgumentsDescriptor& args_desc, |
1449 const String& name, | 1453 const String& name, |
1450 Function* fn_return) { | 1454 Function* fn_return) { |
1451 if (class_id < 0) return false; | 1455 if (class_id < 0) return false; |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1872 // Discard the environment from the original instruction because the store | 1876 // Discard the environment from the original instruction because the store |
1873 // can't deoptimize. | 1877 // can't deoptimize. |
1874 instr->RemoveEnvironment(); | 1878 instr->RemoveEnvironment(); |
1875 ReplaceCall(instr, store); | 1879 ReplaceCall(instr, store); |
1876 return true; | 1880 return true; |
1877 } | 1881 } |
1878 | 1882 |
1879 | 1883 |
1880 } // namespace dart | 1884 } // namespace dart |
1881 #endif // DART_PRECOMPILED_RUNTIME | 1885 #endif // DART_PRECOMPILED_RUNTIME |
OLD | NEW |