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/globals.h" // Needed here to get TARGET_ARCH_MIPS. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_MIPS. |
6 #if defined(TARGET_ARCH_MIPS) | 6 #if defined(TARGET_ARCH_MIPS) |
7 | 7 |
8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
9 | 9 |
10 #include "vm/ast_printer.h" | 10 #include "vm/ast_printer.h" |
(...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 __ Comment("InstanceCall"); | 1218 __ Comment("InstanceCall"); |
1219 __ LoadUniqueObject(S5, ic_data); | 1219 __ LoadUniqueObject(S5, ic_data); |
1220 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, | 1220 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, |
1221 locs); | 1221 locs); |
1222 __ Comment("InstanceCall return"); | 1222 __ Comment("InstanceCall return"); |
1223 __ Drop(argument_count); | 1223 __ Drop(argument_count); |
1224 } | 1224 } |
1225 | 1225 |
1226 | 1226 |
1227 void FlowGraphCompiler::EmitMegamorphicInstanceCall( | 1227 void FlowGraphCompiler::EmitMegamorphicInstanceCall( |
1228 const ICData& ic_data, | 1228 const String& name, |
| 1229 const Array& arguments_descriptor, |
1229 intptr_t argument_count, | 1230 intptr_t argument_count, |
1230 intptr_t deopt_id, | 1231 intptr_t deopt_id, |
1231 TokenPosition token_pos, | 1232 TokenPosition token_pos, |
1232 LocationSummary* locs, | 1233 LocationSummary* locs, |
1233 intptr_t try_index, | 1234 intptr_t try_index, |
1234 intptr_t slow_path_argument_count) { | 1235 intptr_t slow_path_argument_count) { |
1235 const String& name = String::Handle(zone(), ic_data.target_name()); | |
1236 const Array& arguments_descriptor = | |
1237 Array::ZoneHandle(zone(), ic_data.arguments_descriptor()); | |
1238 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); | 1236 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); |
1239 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( | 1237 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( |
1240 zone(), | 1238 zone(), |
1241 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); | 1239 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); |
1242 | 1240 |
1243 __ Comment("MegamorphicCall"); | 1241 __ Comment("MegamorphicCall"); |
1244 // Load receiver into T0, | 1242 // Load receiver into T0, |
1245 __ lw(T0, Address(SP, (argument_count - 1) * kWordSize)); | 1243 __ lw(T0, Address(SP, (argument_count - 1) * kWordSize)); |
1246 __ LoadObject(S5, cache); | 1244 __ LoadObject(S5, cache); |
1247 __ lw(T9, Address(THR, Thread::megamorphic_call_checked_entry_offset())); | 1245 __ lw(T9, Address(THR, Thread::megamorphic_call_checked_entry_offset())); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 // TODO(zerny): clobber non-live temporary FPU registers. | 1499 // TODO(zerny): clobber non-live temporary FPU registers. |
1502 if (tmp.IsRegister() && | 1500 if (tmp.IsRegister() && |
1503 !locs->live_registers()->ContainsRegister(tmp.reg())) { | 1501 !locs->live_registers()->ContainsRegister(tmp.reg())) { |
1504 __ LoadImmediate(tmp.reg(), 0xf7); | 1502 __ LoadImmediate(tmp.reg(), 0xf7); |
1505 } | 1503 } |
1506 } | 1504 } |
1507 } | 1505 } |
1508 #endif | 1506 #endif |
1509 | 1507 |
1510 | 1508 |
1511 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data, | 1509 void FlowGraphCompiler::EmitTestAndCall(const PolymorphicTargets& targets, |
| 1510 const String& function_name, |
1512 intptr_t argument_count, | 1511 intptr_t argument_count, |
1513 const Array& argument_names, | 1512 const Array& argument_names, |
1514 Label* failed, | 1513 Label* failed, |
1515 Label* match_found, | 1514 Label* match_found, |
1516 intptr_t deopt_id, | 1515 intptr_t deopt_id, |
1517 TokenPosition token_index, | 1516 TokenPosition token_index, |
1518 LocationSummary* locs, | 1517 LocationSummary* locs, |
1519 bool complete, | 1518 bool complete, |
1520 intptr_t total_ic_calls) { | 1519 intptr_t total_ic_calls) { |
1521 ASSERT(is_optimizing()); | 1520 ASSERT(is_optimizing()); |
| 1521 |
1522 __ Comment("EmitTestAndCall"); | 1522 __ Comment("EmitTestAndCall"); |
1523 const Array& arguments_descriptor = Array::ZoneHandle( | 1523 const Array& arguments_descriptor = Array::ZoneHandle( |
1524 zone(), ArgumentsDescriptor::New(argument_count, argument_names)); | 1524 zone(), ArgumentsDescriptor::New(argument_count, argument_names)); |
1525 | |
1526 // Load receiver into T0. | 1525 // Load receiver into T0. |
1527 __ LoadFromOffset(T0, SP, (argument_count - 1) * kWordSize); | 1526 __ LoadFromOffset(T0, SP, (argument_count - 1) * kWordSize); |
1528 __ LoadObject(S4, arguments_descriptor); | 1527 __ LoadObject(S4, arguments_descriptor); |
1529 | 1528 |
1530 const bool kFirstCheckIsSmi = ic_data.GetReceiverClassIdAt(0) == kSmiCid; | 1529 const int kNoCase = -1; |
1531 const intptr_t num_checks = ic_data.NumberOfChecks(); | 1530 int smi_case = kNoCase; |
| 1531 int which_case_to_skip = kNoCase; |
1532 | 1532 |
1533 ASSERT(!ic_data.IsNull() && (num_checks > 0)); | 1533 const int length = targets.length(); |
| 1534 int non_smi_length = length; |
1534 | 1535 |
1535 Label after_smi_test; | 1536 // Find out if one of the classes in one of the cases is the Smi class. We |
1536 if (kFirstCheckIsSmi) { | 1537 // will be handling that specially. |
| 1538 for (int i = 0; i < length; i++) { |
| 1539 const intptr_t start = targets[i].cid_start; |
| 1540 if (start > kSmiCid) continue; |
| 1541 const intptr_t end = targets[i].cid_end; |
| 1542 if (end >= kSmiCid) { |
| 1543 smi_case = i; |
| 1544 if (start == kSmiCid && end == kSmiCid) { |
| 1545 // If this case has only the Smi class then we won't need to emit it at |
| 1546 // all later. |
| 1547 which_case_to_skip = i; |
| 1548 non_smi_length--; |
| 1549 } |
| 1550 break; |
| 1551 } |
| 1552 } |
| 1553 |
| 1554 if (smi_case != kNoCase) { |
| 1555 Label after_smi_test; |
1537 __ andi(CMPRES1, T0, Immediate(kSmiTagMask)); | 1556 __ andi(CMPRES1, T0, Immediate(kSmiTagMask)); |
1538 // Jump if receiver is not Smi. | 1557 // Jump if receiver is not Smi. |
1539 if (num_checks == 1) { | 1558 __ bne(CMPRES1, ZR, non_smi_length == 0 ? failed : &after_smi_test); |
1540 __ bne(CMPRES1, ZR, failed); | |
1541 } else { | |
1542 __ bne(CMPRES1, ZR, &after_smi_test); | |
1543 } | |
1544 // Do not use the code from the function, but let the code be patched so | 1559 // Do not use the code from the function, but let the code be patched so |
1545 // that we can record the outgoing edges to other code. | 1560 // that we can record the outgoing edges to other code. |
1546 const Function& function = | 1561 const Function& function = *targets[smi_case].target; |
1547 Function::ZoneHandle(zone(), ic_data.GetTargetAt(0)); | |
1548 GenerateStaticDartCall(deopt_id, token_index, | 1562 GenerateStaticDartCall(deopt_id, token_index, |
1549 *StubCode::CallStaticFunction_entry(), | 1563 *StubCode::CallStaticFunction_entry(), |
1550 RawPcDescriptors::kOther, locs, function); | 1564 RawPcDescriptors::kOther, locs, function); |
1551 __ Drop(argument_count); | 1565 __ Drop(argument_count); |
1552 if (num_checks > 1) { | 1566 if (non_smi_length > 0) { |
1553 __ b(match_found); | 1567 __ b(match_found); |
| 1568 __ Bind(&after_smi_test); |
1554 } | 1569 } |
1555 } else { | 1570 } else { |
1556 // Receiver is Smi, but Smi is not a valid class therefore fail. | 1571 // Receiver is Smi, but Smi is not a valid class therefore fail. |
1557 // (Smi class must be first in the list). | |
1558 if (!complete) { | 1572 if (!complete) { |
1559 __ andi(CMPRES1, T0, Immediate(kSmiTagMask)); | 1573 __ andi(CMPRES1, T0, Immediate(kSmiTagMask)); |
1560 __ beq(CMPRES1, ZR, failed); | 1574 __ beq(CMPRES1, ZR, failed); |
1561 } | 1575 } |
1562 } | 1576 } |
1563 | 1577 |
1564 __ Bind(&after_smi_test); | 1578 ASSERT(length > 0); |
1565 | 1579 |
1566 ASSERT(!ic_data.IsNull() && (num_checks > 0)); | 1580 // If non_smi_length is 0 then only a Smi check was needed; the Smi check |
1567 GrowableArray<CidRangeTarget> sorted(num_checks); | 1581 // above will fail if there was only one check and receiver is not Smi. |
1568 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true); | 1582 if (non_smi_length == 0) return; |
1569 | |
1570 const intptr_t sorted_len = sorted.length(); | |
1571 // If sorted_len is 0 then only a Smi check was needed; the Smi check above | |
1572 // will fail if there was only one check and receiver is not Smi. | |
1573 if (sorted_len == 0) return; | |
1574 | 1583 |
1575 // Value is not Smi, | 1584 // Value is not Smi, |
1576 __ LoadClassId(T2, T0); | 1585 __ LoadClassId(T2, T0); |
1577 | 1586 |
1578 bool add_megamorphic_call = false; | 1587 bool add_megamorphic_call = false; |
1579 int bias = 0; | 1588 int bias = 0; |
1580 | 1589 |
1581 for (intptr_t i = 0; i < sorted_len; i++) { | 1590 int last_check = which_case_to_skip == length - 1 ? length - 2 : length - 1; |
1582 const bool is_last_check = (i == (sorted_len - 1)); | 1591 |
1583 int cid_start = sorted[i].cid_start; | 1592 for (intptr_t i = 0; i < length; i++) { |
1584 int cid_end = sorted[i].cid_end; | 1593 if (i == which_case_to_skip) continue; |
1585 int count = sorted[i].count; | 1594 const bool is_last_check = (i == last_check); |
| 1595 const int cid_start = targets[i].cid_start; |
| 1596 const int cid_end = targets[i].cid_end; |
| 1597 const int count = targets[i].count; |
1586 if (!is_last_check && !complete && count < (total_ic_calls >> 5)) { | 1598 if (!is_last_check && !complete && count < (total_ic_calls >> 5)) { |
1587 // This case is hit too rarely to be worth writing class-id checks inline | 1599 // This case is hit too rarely to be worth writing class-id checks inline |
1588 // for. | 1600 // for. Note that we can't do this for calls with only one target because |
| 1601 // the type propagator may have made use of that and expects a deopt if |
| 1602 // a new class is seen at this calls site. See HasSingleRecognizedCid. |
1589 add_megamorphic_call = true; | 1603 add_megamorphic_call = true; |
1590 break; | 1604 break; |
1591 } | 1605 } |
1592 ASSERT(cid_start > kSmiCid || cid_end < kSmiCid); | |
1593 Label next_test; | 1606 Label next_test; |
1594 Condition no_match; | 1607 Condition no_match; |
1595 if (!complete || !is_last_check) { | 1608 if (!complete || !is_last_check) { |
1596 Label* next_label = is_last_check ? failed : &next_test; | 1609 Label* next_label = is_last_check ? failed : &next_test; |
1597 if (cid_start == cid_end) { | 1610 if (cid_start == cid_end) { |
1598 __ BranchNotEqual(T2, Immediate(cid_start - bias), next_label); | 1611 __ BranchNotEqual(T2, Immediate(cid_start - bias), next_label); |
1599 } else { | 1612 } else { |
1600 __ AddImmediate(T2, T2, bias - cid_start); | 1613 __ AddImmediate(T2, T2, bias - cid_start); |
1601 bias = cid_start; | 1614 bias = cid_start; |
1602 // TODO(erikcorry): We should use sltiu instead of the temporary TMP if | 1615 // TODO(erikcorry): We should use sltiu instead of the temporary TMP if |
1603 // the range is small enough. | 1616 // the range is small enough. |
1604 __ LoadImmediate(TMP, cid_end - cid_end); | 1617 __ LoadImmediate(TMP, cid_end - cid_end); |
1605 // Reverse comparison so we get 1 if biased cid > tmp ie cid is out of | 1618 // Reverse comparison so we get 1 if biased cid > tmp ie cid is out of |
1606 // range. | 1619 // range. |
1607 __ sltu(TMP, TMP, T2); | 1620 __ sltu(TMP, TMP, T2); |
1608 __ bne(TMP, ZR, next_label); | 1621 __ bne(TMP, ZR, next_label); |
1609 } | 1622 } |
1610 } | 1623 } |
1611 // Do not use the code from the function, but let the code be patched so | 1624 // Do not use the code from the function, but let the code be patched so |
1612 // that we can record the outgoing edges to other code. | 1625 // that we can record the outgoing edges to other code. |
1613 const Function& function = *sorted[i].target; | 1626 const Function& function = *targets[i].target; |
1614 GenerateStaticDartCall(deopt_id, token_index, | 1627 GenerateStaticDartCall(deopt_id, token_index, |
1615 *StubCode::CallStaticFunction_entry(), | 1628 *StubCode::CallStaticFunction_entry(), |
1616 RawPcDescriptors::kOther, locs, function); | 1629 RawPcDescriptors::kOther, locs, function); |
1617 __ Drop(argument_count); | 1630 __ Drop(argument_count); |
1618 if (!is_last_check) { | 1631 if (!is_last_check || add_megamorphic_call) { |
1619 __ b(match_found); | 1632 __ b(match_found); |
1620 } | 1633 } |
1621 __ Bind(&next_test); | 1634 __ Bind(&next_test); |
1622 } | 1635 } |
1623 if (add_megamorphic_call) { | 1636 if (add_megamorphic_call) { |
1624 int try_index = CatchClauseNode::kInvalidTryIndex; | 1637 int try_index = CatchClauseNode::kInvalidTryIndex; |
1625 EmitMegamorphicInstanceCall(ic_data, argument_count, deopt_id, token_index, | 1638 EmitMegamorphicInstanceCall(function_name, arguments_descriptor, |
1626 locs, try_index, argument_count); | 1639 argument_count, deopt_id, token_index, locs, |
| 1640 try_index); |
1627 } | 1641 } |
1628 } | 1642 } |
1629 | 1643 |
1630 | 1644 |
1631 #undef __ | 1645 #undef __ |
1632 #define __ compiler_->assembler()-> | 1646 #define __ compiler_->assembler()-> |
1633 | 1647 |
1634 | 1648 |
1635 void ParallelMoveResolver::EmitMove(int index) { | 1649 void ParallelMoveResolver::EmitMove(int index) { |
1636 MoveOperands* move = moves_[index]; | 1650 MoveOperands* move = moves_[index]; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1864 __ AddImmediate(SP, kDoubleSize); | 1878 __ AddImmediate(SP, kDoubleSize); |
1865 } | 1879 } |
1866 | 1880 |
1867 | 1881 |
1868 #undef __ | 1882 #undef __ |
1869 | 1883 |
1870 | 1884 |
1871 } // namespace dart | 1885 } // namespace dart |
1872 | 1886 |
1873 #endif // defined TARGET_ARCH_MIPS | 1887 #endif // defined TARGET_ARCH_MIPS |
OLD | NEW |