| 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/aot_optimizer.h" | 5 #include "vm/aot_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 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 return false; | 1441 return false; |
| 1442 } | 1442 } |
| 1443 return true; // May deoptimize since we have not identified all 'true' tests. | 1443 return true; // May deoptimize since we have not identified all 'true' tests. |
| 1444 } | 1444 } |
| 1445 | 1445 |
| 1446 | 1446 |
| 1447 // TODO(srdjan): Use ICData to check if always true or false. | 1447 // TODO(srdjan): Use ICData to check if always true or false. |
| 1448 void AotOptimizer::ReplaceWithInstanceOf(InstanceCallInstr* call) { | 1448 void AotOptimizer::ReplaceWithInstanceOf(InstanceCallInstr* call) { |
| 1449 ASSERT(Token::IsTypeTestOperator(call->token_kind())); | 1449 ASSERT(Token::IsTypeTestOperator(call->token_kind())); |
| 1450 Definition* left = call->ArgumentAt(0); | 1450 Definition* left = call->ArgumentAt(0); |
| 1451 Definition* type_args = NULL; | 1451 Definition* instantiator_type_args = NULL; |
| 1452 Definition* function_type_args = NULL; |
| 1452 AbstractType& type = AbstractType::ZoneHandle(Z); | 1453 AbstractType& type = AbstractType::ZoneHandle(Z); |
| 1453 if (call->ArgumentCount() == 2) { | 1454 if (call->ArgumentCount() == 2) { |
| 1454 type_args = flow_graph()->constant_null(); | 1455 instantiator_type_args = flow_graph()->constant_null(); |
| 1456 function_type_args = flow_graph()->constant_null(); |
| 1455 ASSERT(call->MatchesCoreName(Symbols::_simpleInstanceOf())); | 1457 ASSERT(call->MatchesCoreName(Symbols::_simpleInstanceOf())); |
| 1456 type = AbstractType::Cast(call->ArgumentAt(1)->AsConstant()->value()).raw(); | 1458 type = AbstractType::Cast(call->ArgumentAt(1)->AsConstant()->value()).raw(); |
| 1457 } else { | 1459 } else { |
| 1458 type_args = call->ArgumentAt(1); | 1460 instantiator_type_args = call->ArgumentAt(1); |
| 1459 type = AbstractType::Cast(call->ArgumentAt(2)->AsConstant()->value()).raw(); | 1461 function_type_args = call->ArgumentAt(2); |
| 1462 type = AbstractType::Cast(call->ArgumentAt(3)->AsConstant()->value()).raw(); |
| 1460 } | 1463 } |
| 1461 | 1464 |
| 1462 if (TypeCheckAsClassEquality(type)) { | 1465 if (TypeCheckAsClassEquality(type)) { |
| 1463 LoadClassIdInstr* left_cid = new (Z) LoadClassIdInstr(new (Z) Value(left)); | 1466 LoadClassIdInstr* left_cid = new (Z) LoadClassIdInstr(new (Z) Value(left)); |
| 1464 InsertBefore(call, left_cid, NULL, FlowGraph::kValue); | 1467 InsertBefore(call, left_cid, NULL, FlowGraph::kValue); |
| 1465 const intptr_t type_cid = Class::Handle(Z, type.type_class()).id(); | 1468 const intptr_t type_cid = Class::Handle(Z, type.type_class()).id(); |
| 1466 ConstantInstr* cid = | 1469 ConstantInstr* cid = |
| 1467 flow_graph()->GetConstant(Smi::Handle(Z, Smi::New(type_cid))); | 1470 flow_graph()->GetConstant(Smi::Handle(Z, Smi::New(type_cid))); |
| 1468 | 1471 |
| 1469 StrictCompareInstr* check_cid = | 1472 StrictCompareInstr* check_cid = |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 TestCidsInstr* test_cids = new (Z) TestCidsInstr( | 1546 TestCidsInstr* test_cids = new (Z) TestCidsInstr( |
| 1544 call->token_pos(), Token::kIS, new (Z) Value(left), *results, | 1547 call->token_pos(), Token::kIS, new (Z) Value(left), *results, |
| 1545 can_deopt ? call->deopt_id() : Thread::kNoDeoptId); | 1548 can_deopt ? call->deopt_id() : Thread::kNoDeoptId); |
| 1546 // Remove type. | 1549 // Remove type. |
| 1547 ReplaceCall(call, test_cids); | 1550 ReplaceCall(call, test_cids); |
| 1548 return; | 1551 return; |
| 1549 } | 1552 } |
| 1550 } | 1553 } |
| 1551 | 1554 |
| 1552 InstanceOfInstr* instance_of = new (Z) InstanceOfInstr( | 1555 InstanceOfInstr* instance_of = new (Z) InstanceOfInstr( |
| 1553 call->token_pos(), new (Z) Value(left), new (Z) Value(type_args), | 1556 call->token_pos(), new (Z) Value(left), |
| 1554 NULL, // TODO(regis): Pass function type args. | 1557 new (Z) Value(instantiator_type_args), new (Z) Value(function_type_args), |
| 1555 type, call->deopt_id()); | 1558 type, call->deopt_id()); |
| 1556 ReplaceCall(call, instance_of); | 1559 ReplaceCall(call, instance_of); |
| 1557 } | 1560 } |
| 1558 | 1561 |
| 1559 | 1562 |
| 1560 // TODO(srdjan): Apply optimizations as in ReplaceWithInstanceOf (TestCids). | 1563 // TODO(srdjan): Apply optimizations as in ReplaceWithInstanceOf (TestCids). |
| 1561 void AotOptimizer::ReplaceWithTypeCast(InstanceCallInstr* call) { | 1564 void AotOptimizer::ReplaceWithTypeCast(InstanceCallInstr* call) { |
| 1562 ASSERT(Token::IsTypeCastOperator(call->token_kind())); | 1565 ASSERT(Token::IsTypeCastOperator(call->token_kind())); |
| 1563 Definition* left = call->ArgumentAt(0); | 1566 Definition* left = call->ArgumentAt(0); |
| 1564 Definition* type_args = call->ArgumentAt(1); | 1567 Definition* instantiator_type_args = call->ArgumentAt(1); |
| 1568 Definition* function_type_args = call->ArgumentAt(2); |
| 1565 const AbstractType& type = | 1569 const AbstractType& type = |
| 1566 AbstractType::Cast(call->ArgumentAt(2)->AsConstant()->value()); | 1570 AbstractType::Cast(call->ArgumentAt(3)->AsConstant()->value()); |
| 1567 ASSERT(!type.IsMalformedOrMalbounded()); | 1571 ASSERT(!type.IsMalformedOrMalbounded()); |
| 1568 const ICData& unary_checks = | 1572 const ICData& unary_checks = |
| 1569 ICData::ZoneHandle(Z, call->ic_data()->AsUnaryClassChecks()); | 1573 ICData::ZoneHandle(Z, call->ic_data()->AsUnaryClassChecks()); |
| 1570 const intptr_t number_of_checks = unary_checks.NumberOfChecks(); | 1574 const intptr_t number_of_checks = unary_checks.NumberOfChecks(); |
| 1571 if (number_of_checks > 0 && number_of_checks <= FLAG_max_polymorphic_checks) { | 1575 if (number_of_checks > 0 && number_of_checks <= FLAG_max_polymorphic_checks) { |
| 1572 ZoneGrowableArray<intptr_t>* results = | 1576 ZoneGrowableArray<intptr_t>* results = |
| 1573 new (Z) ZoneGrowableArray<intptr_t>(number_of_checks * 2); | 1577 new (Z) ZoneGrowableArray<intptr_t>(number_of_checks * 2); |
| 1574 const Bool& as_bool = | 1578 const Bool& as_bool = |
| 1575 Bool::ZoneHandle(Z, InstanceOfAsBool(unary_checks, type, results)); | 1579 Bool::ZoneHandle(Z, InstanceOfAsBool(unary_checks, type, results)); |
| 1576 if (as_bool.raw() == Bool::True().raw()) { | 1580 if (as_bool.raw() == Bool::True().raw()) { |
| 1577 // Guard against repeated speculative inlining. | 1581 // Guard against repeated speculative inlining. |
| 1578 if (!IsAllowedForInlining(call->deopt_id())) { | 1582 if (!IsAllowedForInlining(call->deopt_id())) { |
| 1579 return; | 1583 return; |
| 1580 } | 1584 } |
| 1581 AddReceiverCheck(call); | 1585 AddReceiverCheck(call); |
| 1582 // Remove the original push arguments. | 1586 // Remove the original push arguments. |
| 1583 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) { | 1587 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) { |
| 1584 PushArgumentInstr* push = call->PushArgumentAt(i); | 1588 PushArgumentInstr* push = call->PushArgumentAt(i); |
| 1585 push->ReplaceUsesWith(push->value()->definition()); | 1589 push->ReplaceUsesWith(push->value()->definition()); |
| 1586 push->RemoveFromGraph(); | 1590 push->RemoveFromGraph(); |
| 1587 } | 1591 } |
| 1588 // Remove call, replace it with 'left'. | 1592 // Remove call, replace it with 'left'. |
| 1589 call->ReplaceUsesWith(left); | 1593 call->ReplaceUsesWith(left); |
| 1590 ASSERT(current_iterator()->Current() == call); | 1594 ASSERT(current_iterator()->Current() == call); |
| 1591 current_iterator()->RemoveCurrentFromGraph(); | 1595 current_iterator()->RemoveCurrentFromGraph(); |
| 1592 return; | 1596 return; |
| 1593 } | 1597 } |
| 1594 } | 1598 } |
| 1595 AssertAssignableInstr* assert_as = new (Z) AssertAssignableInstr( | 1599 AssertAssignableInstr* assert_as = new (Z) AssertAssignableInstr( |
| 1596 call->token_pos(), new (Z) Value(left), new (Z) Value(type_args), | 1600 call->token_pos(), new (Z) Value(left), |
| 1597 NULL, // TODO(regis): Pass function type arguments. | 1601 new (Z) Value(instantiator_type_args), new (Z) Value(function_type_args), |
| 1598 type, Symbols::InTypeCast(), call->deopt_id()); | 1602 type, Symbols::InTypeCast(), call->deopt_id()); |
| 1599 ReplaceCall(call, assert_as); | 1603 ReplaceCall(call, assert_as); |
| 1600 } | 1604 } |
| 1601 | 1605 |
| 1602 | 1606 |
| 1603 bool AotOptimizer::IsAllowedForInlining(intptr_t call_deopt_id) { | 1607 bool AotOptimizer::IsAllowedForInlining(intptr_t call_deopt_id) { |
| 1604 if (!use_speculative_inlining_) return false; | 1608 if (!use_speculative_inlining_) return false; |
| 1605 for (intptr_t i = 0; i < inlining_black_list_->length(); ++i) { | 1609 for (intptr_t i = 0; i < inlining_black_list_->length(); ++i) { |
| 1606 if ((*inlining_black_list_)[i] == call_deopt_id) return false; | 1610 if ((*inlining_black_list_)[i] == call_deopt_id) return false; |
| 1607 } | 1611 } |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2132 FlowGraph::kEffect); | 2136 FlowGraph::kEffect); |
| 2133 current_iterator()->RemoveCurrentFromGraph(); | 2137 current_iterator()->RemoveCurrentFromGraph(); |
| 2134 } | 2138 } |
| 2135 } | 2139 } |
| 2136 } | 2140 } |
| 2137 } | 2141 } |
| 2138 | 2142 |
| 2139 #endif // DART_PRECOMPILER | 2143 #endif // DART_PRECOMPILER |
| 2140 | 2144 |
| 2141 } // namespace dart | 2145 } // namespace dart |
| OLD | NEW |