| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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_ARM64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64. |
| 6 #if defined(TARGET_ARCH_ARM64) | 6 #if defined(TARGET_ARCH_ARM64) |
| 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 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 LocationSummary* locs) { | 1195 LocationSummary* locs) { |
| 1196 ASSERT(Array::Handle(zone(), ic_data.arguments_descriptor()).Length() > 0); | 1196 ASSERT(Array::Handle(zone(), ic_data.arguments_descriptor()).Length() > 0); |
| 1197 __ LoadUniqueObject(R5, ic_data); | 1197 __ LoadUniqueObject(R5, ic_data); |
| 1198 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, | 1198 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, |
| 1199 locs); | 1199 locs); |
| 1200 __ Drop(argument_count); | 1200 __ Drop(argument_count); |
| 1201 } | 1201 } |
| 1202 | 1202 |
| 1203 | 1203 |
| 1204 void FlowGraphCompiler::EmitMegamorphicInstanceCall( | 1204 void FlowGraphCompiler::EmitMegamorphicInstanceCall( |
| 1205 const ICData& ic_data, | 1205 const String& name, |
| 1206 const Array& arguments_descriptor, |
| 1206 intptr_t argument_count, | 1207 intptr_t argument_count, |
| 1207 intptr_t deopt_id, | 1208 intptr_t deopt_id, |
| 1208 TokenPosition token_pos, | 1209 TokenPosition token_pos, |
| 1209 LocationSummary* locs, | 1210 LocationSummary* locs, |
| 1210 intptr_t try_index, | 1211 intptr_t try_index, |
| 1211 intptr_t slow_path_argument_count) { | 1212 intptr_t slow_path_argument_count) { |
| 1212 const String& name = String::Handle(zone(), ic_data.target_name()); | |
| 1213 const Array& arguments_descriptor = | |
| 1214 Array::ZoneHandle(zone(), ic_data.arguments_descriptor()); | |
| 1215 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); | 1213 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); |
| 1216 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( | 1214 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( |
| 1217 zone(), | 1215 zone(), |
| 1218 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); | 1216 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); |
| 1219 | 1217 |
| 1220 __ Comment("MegamorphicCall"); | 1218 __ Comment("MegamorphicCall"); |
| 1221 // Load receiver into R0. | 1219 // Load receiver into R0. |
| 1222 __ LoadFromOffset(R0, SP, (argument_count - 1) * kWordSize); | 1220 __ LoadFromOffset(R0, SP, (argument_count - 1) * kWordSize); |
| 1223 | 1221 |
| 1224 __ LoadObject(R5, cache); | 1222 __ LoadObject(R5, cache); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 // TODO(zerny): clobber non-live temporary FPU registers. | 1435 // TODO(zerny): clobber non-live temporary FPU registers. |
| 1438 if (tmp.IsRegister() && | 1436 if (tmp.IsRegister() && |
| 1439 !locs->live_registers()->ContainsRegister(tmp.reg())) { | 1437 !locs->live_registers()->ContainsRegister(tmp.reg())) { |
| 1440 __ movz(tmp.reg(), Immediate(0xf7), 0); | 1438 __ movz(tmp.reg(), Immediate(0xf7), 0); |
| 1441 } | 1439 } |
| 1442 } | 1440 } |
| 1443 } | 1441 } |
| 1444 #endif | 1442 #endif |
| 1445 | 1443 |
| 1446 | 1444 |
| 1447 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data, | 1445 void FlowGraphCompiler::EmitTestAndCallLoadReceiver( |
| 1448 intptr_t argument_count, | 1446 intptr_t argument_count, |
| 1449 const Array& argument_names, | 1447 const Array& arguments_descriptor) { |
| 1450 Label* failed, | |
| 1451 Label* match_found, | |
| 1452 intptr_t deopt_id, | |
| 1453 TokenPosition token_index, | |
| 1454 LocationSummary* locs, | |
| 1455 bool complete, | |
| 1456 intptr_t total_ic_calls) { | |
| 1457 ASSERT(is_optimizing()); | |
| 1458 __ Comment("EmitTestAndCall"); | 1448 __ Comment("EmitTestAndCall"); |
| 1459 const Array& arguments_descriptor = Array::ZoneHandle( | |
| 1460 zone(), ArgumentsDescriptor::New(argument_count, argument_names)); | |
| 1461 | |
| 1462 // Load receiver into R0. | 1449 // Load receiver into R0. |
| 1463 __ LoadFromOffset(R0, SP, (argument_count - 1) * kWordSize); | 1450 __ LoadFromOffset(R0, SP, (argument_count - 1) * kWordSize); |
| 1464 __ LoadObject(R4, arguments_descriptor); | 1451 __ LoadObject(R4, arguments_descriptor); |
| 1465 | |
| 1466 const bool kFirstCheckIsSmi = ic_data.GetReceiverClassIdAt(0) == kSmiCid; | |
| 1467 const intptr_t num_checks = ic_data.NumberOfChecks(); | |
| 1468 | |
| 1469 ASSERT(!ic_data.IsNull() && (num_checks > 0)); | |
| 1470 | |
| 1471 Label after_smi_test; | |
| 1472 if (kFirstCheckIsSmi) { | |
| 1473 __ tsti(R0, Immediate(kSmiTagMask)); | |
| 1474 // Jump if receiver is not Smi. | |
| 1475 if (num_checks == 1) { | |
| 1476 __ b(failed, NE); | |
| 1477 } else { | |
| 1478 __ b(&after_smi_test, NE); | |
| 1479 } | |
| 1480 // Do not use the code from the function, but let the code be patched so | |
| 1481 // that we can record the outgoing edges to other code. | |
| 1482 const Function& function = | |
| 1483 Function::ZoneHandle(zone(), ic_data.GetTargetAt(0)); | |
| 1484 GenerateStaticDartCall(deopt_id, token_index, | |
| 1485 *StubCode::CallStaticFunction_entry(), | |
| 1486 RawPcDescriptors::kOther, locs, function); | |
| 1487 __ Drop(argument_count); | |
| 1488 if (num_checks > 1) { | |
| 1489 __ b(match_found); | |
| 1490 } | |
| 1491 } else { | |
| 1492 // Receiver is Smi, but Smi is not a valid class therefore fail. | |
| 1493 // (Smi class must be first in the list). | |
| 1494 if (!complete) { | |
| 1495 __ tsti(R0, Immediate(kSmiTagMask)); | |
| 1496 __ b(failed, EQ); | |
| 1497 } | |
| 1498 } | |
| 1499 __ Bind(&after_smi_test); | |
| 1500 | |
| 1501 ASSERT(!ic_data.IsNull() && (num_checks > 0)); | |
| 1502 GrowableArray<CidRangeTarget> sorted(num_checks); | |
| 1503 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true); | |
| 1504 | |
| 1505 const intptr_t sorted_len = sorted.length(); | |
| 1506 // If sorted_len is 0 then only a Smi check was needed; the Smi check above | |
| 1507 // will fail if there was only one check and receiver is not Smi. | |
| 1508 if (sorted_len == 0) return; | |
| 1509 | |
| 1510 // Value is not Smi, | |
| 1511 __ LoadClassId(R2, R0); | |
| 1512 | |
| 1513 bool add_megamorphic_call = false; | |
| 1514 const int kMaxImmediateInInstruction = 256; | |
| 1515 int bias = | |
| 1516 ComputeGoodBiasForCidComparison(sorted, kMaxImmediateInInstruction); | |
| 1517 if (bias != 0) __ AddImmediate(R2, R2, -bias); | |
| 1518 | |
| 1519 for (intptr_t i = 0; i < sorted_len; i++) { | |
| 1520 const bool is_last_check = (i == (sorted_len - 1)); | |
| 1521 int cid_start = sorted[i].cid_start; | |
| 1522 int cid_end = sorted[i].cid_end; | |
| 1523 int count = sorted[i].count; | |
| 1524 if (!is_last_check && !complete && count < (total_ic_calls >> 5)) { | |
| 1525 // This case is hit too rarely to be worth writing class-id checks inline | |
| 1526 // for. | |
| 1527 add_megamorphic_call = true; | |
| 1528 break; | |
| 1529 } | |
| 1530 ASSERT(cid_start > kSmiCid || cid_end < kSmiCid); | |
| 1531 Label next_test; | |
| 1532 if (!complete || !is_last_check) { | |
| 1533 Label* next_label = is_last_check ? failed : &next_test; | |
| 1534 if (cid_start == cid_end) { | |
| 1535 __ CompareImmediate(R2, cid_start - bias); | |
| 1536 __ b(next_label, NE); | |
| 1537 } else { | |
| 1538 __ AddImmediate(R2, R2, bias - cid_start); | |
| 1539 bias = cid_start; | |
| 1540 __ CompareImmediate(R2, cid_end - cid_start); | |
| 1541 __ b(next_label, HI); // Unsigned higher. | |
| 1542 } | |
| 1543 } | |
| 1544 // 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. | |
| 1546 const Function& function = *sorted[i].target; | |
| 1547 GenerateStaticDartCall(deopt_id, token_index, | |
| 1548 *StubCode::CallStaticFunction_entry(), | |
| 1549 RawPcDescriptors::kOther, locs, function); | |
| 1550 __ Drop(argument_count); | |
| 1551 if (!is_last_check) { | |
| 1552 __ b(match_found); | |
| 1553 } | |
| 1554 __ Bind(&next_test); | |
| 1555 } | |
| 1556 if (add_megamorphic_call) { | |
| 1557 int try_index = CatchClauseNode::kInvalidTryIndex; | |
| 1558 EmitMegamorphicInstanceCall(ic_data, argument_count, deopt_id, token_index, | |
| 1559 locs, try_index, argument_count); | |
| 1560 } | |
| 1561 } | 1452 } |
| 1562 | 1453 |
| 1563 | 1454 |
| 1455 void FlowGraphCompiler::EmitTestAndCallSmiBranch(Label* label, bool if_smi) { |
| 1456 __ tsti(R0, Immediate(kSmiTagMask)); |
| 1457 // Jump if receiver is not Smi. |
| 1458 __ b(label, if_smi ? EQ : NE); |
| 1459 } |
| 1460 |
| 1461 |
| 1462 void FlowGraphCompiler::EmitTestAndCallLoadCid() { |
| 1463 __ LoadClassId(R2, R0); |
| 1464 } |
| 1465 |
| 1466 |
| 1467 int FlowGraphCompiler::EmitTestAndCallCheckCid(Label* next_label, |
| 1468 const CidRangeTarget& target, |
| 1469 int bias) { |
| 1470 intptr_t cid_start = target.cid_start; |
| 1471 intptr_t cid_end = target.cid_end; |
| 1472 if (cid_start == cid_end) { |
| 1473 __ CompareImmediate(R2, cid_start - bias); |
| 1474 __ b(next_label, NE); |
| 1475 } else { |
| 1476 __ AddImmediate(R2, R2, bias - cid_start); |
| 1477 bias = cid_start; |
| 1478 __ CompareImmediate(R2, cid_end - cid_start); |
| 1479 __ b(next_label, HI); // Unsigned higher. |
| 1480 } |
| 1481 return bias; |
| 1482 } |
| 1483 |
| 1484 |
| 1564 #undef __ | 1485 #undef __ |
| 1565 #define __ compiler_->assembler()-> | 1486 #define __ compiler_->assembler()-> |
| 1566 | 1487 |
| 1567 | 1488 |
| 1568 void ParallelMoveResolver::EmitMove(int index) { | 1489 void ParallelMoveResolver::EmitMove(int index) { |
| 1569 MoveOperands* move = moves_[index]; | 1490 MoveOperands* move = moves_[index]; |
| 1570 const Location source = move->src(); | 1491 const Location source = move->src(); |
| 1571 const Location destination = move->dest(); | 1492 const Location destination = move->dest(); |
| 1572 | 1493 |
| 1573 if (source.IsRegister()) { | 1494 if (source.IsRegister()) { |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1833 void ParallelMoveResolver::RestoreFpuScratch(FpuRegister reg) { | 1754 void ParallelMoveResolver::RestoreFpuScratch(FpuRegister reg) { |
| 1834 __ PopDouble(reg); | 1755 __ PopDouble(reg); |
| 1835 } | 1756 } |
| 1836 | 1757 |
| 1837 | 1758 |
| 1838 #undef __ | 1759 #undef __ |
| 1839 | 1760 |
| 1840 } // namespace dart | 1761 } // namespace dart |
| 1841 | 1762 |
| 1842 #endif // defined TARGET_ARCH_ARM64 | 1763 #endif // defined TARGET_ARCH_ARM64 |
| OLD | NEW |