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 19 matching lines...) Expand all Loading... | |
30 namespace dart { | 30 namespace dart { |
31 | 31 |
32 DEFINE_FLAG(int, max_exhaustive_polymorphic_checks, 5, | 32 DEFINE_FLAG(int, max_exhaustive_polymorphic_checks, 5, |
33 "If a call receiver is known to be of at most this many classes, " | 33 "If a call receiver is known to be of at most this many classes, " |
34 "generate exhaustive class tests instead of a megamorphic call"); | 34 "generate exhaustive class tests instead of a megamorphic call"); |
35 | 35 |
36 // Quick access to the current isolate and zone. | 36 // Quick access to the current isolate and zone. |
37 #define I (isolate()) | 37 #define I (isolate()) |
38 #define Z (zone()) | 38 #define Z (zone()) |
39 | 39 |
40 #ifdef DART_PRECOMPILER | |
41 | |
40 static bool ShouldInlineSimd() { | 42 static bool ShouldInlineSimd() { |
41 return FlowGraphCompiler::SupportsUnboxedSimd128(); | 43 return FlowGraphCompiler::SupportsUnboxedSimd128(); |
42 } | 44 } |
43 | 45 |
44 | 46 |
45 static bool CanUnboxDouble() { | 47 static bool CanUnboxDouble() { |
46 return FlowGraphCompiler::SupportsUnboxedDoubles(); | 48 return FlowGraphCompiler::SupportsUnboxedDoubles(); |
47 } | 49 } |
48 | 50 |
49 | 51 |
(...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1514 } | 1516 } |
1515 } else { | 1517 } else { |
1516 type_args = call->ArgumentAt(1); | 1518 type_args = call->ArgumentAt(1); |
1517 type = AbstractType::Cast(call->ArgumentAt(2)->AsConstant()->value()).raw(); | 1519 type = AbstractType::Cast(call->ArgumentAt(2)->AsConstant()->value()).raw(); |
1518 negate = Bool::Cast(call->ArgumentAt(3)->OriginalDefinition() | 1520 negate = Bool::Cast(call->ArgumentAt(3)->OriginalDefinition() |
1519 ->AsConstant()->value()).value(); | 1521 ->AsConstant()->value()).value(); |
1520 } | 1522 } |
1521 | 1523 |
1522 if (TypeCheckAsClassEquality(type)) { | 1524 if (TypeCheckAsClassEquality(type)) { |
1523 LoadClassIdInstr* left_cid = new(Z) LoadClassIdInstr(new(Z) Value(left)); | 1525 LoadClassIdInstr* left_cid = new(Z) LoadClassIdInstr(new(Z) Value(left)); |
1524 InsertBefore(call, | 1526 InsertBefore(call, left_cid, NULL, FlowGraph::kValue); |
1525 left_cid, | |
1526 NULL, | |
1527 FlowGraph::kValue); | |
1528 const intptr_t type_cid = Class::Handle(Z, type.type_class()).id(); | 1527 const intptr_t type_cid = Class::Handle(Z, type.type_class()).id(); |
1529 ConstantInstr* cid = | 1528 ConstantInstr* cid = |
1530 flow_graph()->GetConstant(Smi::Handle(Z, Smi::New(type_cid))); | 1529 flow_graph()->GetConstant(Smi::Handle(Z, Smi::New(type_cid))); |
1531 | 1530 |
1532 StrictCompareInstr* check_cid = | 1531 StrictCompareInstr* check_cid = |
1533 new(Z) StrictCompareInstr( | 1532 new(Z) StrictCompareInstr( |
1534 call->token_pos(), | 1533 call->token_pos(), |
1535 negate ? Token::kNE_STRICT : Token::kEQ_STRICT, | 1534 negate ? Token::kNE_STRICT : Token::kEQ_STRICT, |
1536 new(Z) Value(left_cid), | 1535 new(Z) Value(left_cid), |
1537 new(Z) Value(cid), | 1536 new(Z) Value(cid), |
1538 false); // No number check. | 1537 false); // No number check. |
1539 ReplaceCall(call, check_cid); | 1538 ReplaceCall(call, check_cid); |
1540 return; | 1539 return; |
1541 } | 1540 } |
1542 | 1541 |
1542 TypeRangeCache* cache = thread()->type_range_cache(); | |
1543 intptr_t lower_limit, upper_limit; | |
1544 if (cache != NULL && | |
1545 cache->InstanceOfHasClassRange(type, &lower_limit, &upper_limit)) { | |
1546 // left.instanceof(type) => | |
1547 // _classRangeCheck(left.cid, lower_limit, upper_limit) | |
1548 | |
1549 LoadClassIdInstr* left_cid = new(Z) LoadClassIdInstr(new(Z) Value(left)); | |
1550 InsertBefore(call, left_cid, NULL, FlowGraph::kValue); | |
1551 ConstantInstr* lower_cid = | |
1552 flow_graph()->GetConstant(Smi::Handle(Z, Smi::New(lower_limit))); | |
1553 ConstantInstr* upper_cid = | |
1554 flow_graph()->GetConstant(Smi::Handle(Z, Smi::New(upper_limit))); | |
1555 | |
1556 ZoneGrowableArray<PushArgumentInstr*>* args = | |
1557 new(Z) ZoneGrowableArray<PushArgumentInstr*>(3); | |
1558 PushArgumentInstr* arg = new (Z) PushArgumentInstr(new (Z) Value(left_cid)); | |
1559 InsertBefore(call, arg, NULL, FlowGraph::kEffect); | |
1560 args->Add(arg); | |
1561 arg = new (Z) PushArgumentInstr(new (Z) Value(lower_cid)); | |
1562 InsertBefore(call, arg, NULL, FlowGraph::kEffect); | |
1563 args->Add(arg); | |
1564 arg = new (Z) PushArgumentInstr(new (Z) Value(upper_cid)); | |
1565 InsertBefore(call, arg, NULL, FlowGraph::kEffect); | |
1566 args->Add(arg); | |
1567 | |
1568 const Library& dart_internal = | |
1569 Library::Handle(Z, Library::InternalLibrary()); | |
1570 const String& target_name = | |
1571 String::Handle(Z, String::New(negate ? "_classRangeCheckNegative" | |
Florian Schneider
2016/09/08 21:21:05
Maybe add to symbols.h, and load from symbol table
rmacnak
2016/09/08 22:20:21
Done.
| |
1572 : "_classRangeCheck")); | |
Florian Schneider
2016/09/08 21:21:05
Same.
| |
1573 const Function& target = Function::ZoneHandle(Z, | |
1574 dart_internal.LookupFunctionAllowPrivate(target_name)); | |
1575 ASSERT(!target.IsNull()); | |
1576 ASSERT(target.IsRecognized() && target.always_inline()); | |
1577 | |
1578 StaticCallInstr* new_call = new (Z) StaticCallInstr( | |
1579 call->token_pos(), | |
1580 target, | |
1581 Object::null_array(), // argument_names | |
1582 args, | |
1583 call->deopt_id()); | |
1584 ReplaceCall(call, new_call); | |
1585 return; | |
1586 } | |
1587 | |
1543 const ICData& unary_checks = | 1588 const ICData& unary_checks = |
1544 ICData::ZoneHandle(Z, call->ic_data()->AsUnaryClassChecks()); | 1589 ICData::ZoneHandle(Z, call->ic_data()->AsUnaryClassChecks()); |
1545 if ((unary_checks.NumberOfChecks() > 0) && | 1590 if ((unary_checks.NumberOfChecks() > 0) && |
1546 (unary_checks.NumberOfChecks() <= FLAG_max_polymorphic_checks)) { | 1591 (unary_checks.NumberOfChecks() <= FLAG_max_polymorphic_checks)) { |
1547 ZoneGrowableArray<intptr_t>* results = | 1592 ZoneGrowableArray<intptr_t>* results = |
1548 new(Z) ZoneGrowableArray<intptr_t>(unary_checks.NumberOfChecks() * 2); | 1593 new(Z) ZoneGrowableArray<intptr_t>(unary_checks.NumberOfChecks() * 2); |
1549 InstanceOfAsBool(unary_checks, type, results); | 1594 InstanceOfAsBool(unary_checks, type, results); |
1550 if (results->length() == unary_checks.NumberOfChecks() * 2) { | 1595 if (results->length() == unary_checks.NumberOfChecks() * 2) { |
1551 const bool can_deopt = TryExpandTestCidsResult(results, type); | 1596 const bool can_deopt = TryExpandTestCidsResult(results, type); |
1552 if (can_deopt && !IsAllowedForInlining(call->deopt_id())) { | 1597 if (can_deopt && !IsAllowedForInlining(call->deopt_id())) { |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2131 new(Z) Value(check->index()->definition()), | 2176 new(Z) Value(check->index()->definition()), |
2132 check->deopt_id()); | 2177 check->deopt_id()); |
2133 flow_graph_->InsertBefore(check, new_check, | 2178 flow_graph_->InsertBefore(check, new_check, |
2134 check->env(), FlowGraph::kEffect); | 2179 check->env(), FlowGraph::kEffect); |
2135 current_iterator()->RemoveCurrentFromGraph(); | 2180 current_iterator()->RemoveCurrentFromGraph(); |
2136 } | 2181 } |
2137 } | 2182 } |
2138 } | 2183 } |
2139 } | 2184 } |
2140 | 2185 |
2186 #endif // DART_PRECOMPILER | |
2141 | 2187 |
2142 } // namespace dart | 2188 } // namespace dart |
OLD | NEW |