| 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_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
| 6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 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 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 LocationSummary* locs) { | 1243 LocationSummary* locs) { |
| 1244 ASSERT(Array::Handle(zone(), ic_data.arguments_descriptor()).Length() > 0); | 1244 ASSERT(Array::Handle(zone(), ic_data.arguments_descriptor()).Length() > 0); |
| 1245 __ LoadUniqueObject(RBX, ic_data); | 1245 __ LoadUniqueObject(RBX, ic_data); |
| 1246 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, | 1246 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, |
| 1247 locs); | 1247 locs); |
| 1248 __ Drop(argument_count, RCX); | 1248 __ Drop(argument_count, RCX); |
| 1249 } | 1249 } |
| 1250 | 1250 |
| 1251 | 1251 |
| 1252 void FlowGraphCompiler::EmitMegamorphicInstanceCall( | 1252 void FlowGraphCompiler::EmitMegamorphicInstanceCall( |
| 1253 const String& name, | 1253 const ICData& ic_data, |
| 1254 const Array& arguments_descriptor, | |
| 1255 intptr_t argument_count, | 1254 intptr_t argument_count, |
| 1256 intptr_t deopt_id, | 1255 intptr_t deopt_id, |
| 1257 TokenPosition token_pos, | 1256 TokenPosition token_pos, |
| 1258 LocationSummary* locs, | 1257 LocationSummary* locs, |
| 1259 intptr_t try_index, | 1258 intptr_t try_index, |
| 1260 intptr_t slow_path_argument_count) { | 1259 intptr_t slow_path_argument_count) { |
| 1260 const String& name = String::Handle(zone(), ic_data.target_name()); |
| 1261 const Array& arguments_descriptor = |
| 1262 Array::ZoneHandle(zone(), ic_data.arguments_descriptor()); |
| 1261 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); | 1263 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); |
| 1262 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( | 1264 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( |
| 1263 zone(), | 1265 zone(), |
| 1264 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); | 1266 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); |
| 1265 __ Comment("MegamorphicCall"); | 1267 __ Comment("MegamorphicCall"); |
| 1266 // Load receiver into RDI. | 1268 // Load receiver into RDI. |
| 1267 __ movq(RDI, Address(RSP, (argument_count - 1) * kWordSize)); | 1269 __ movq(RDI, Address(RSP, (argument_count - 1) * kWordSize)); |
| 1268 __ LoadObject(RBX, cache); | 1270 __ LoadObject(RBX, cache); |
| 1269 __ call(Address(THR, Thread::megamorphic_call_checked_entry_offset())); | 1271 __ call(Address(THR, Thread::megamorphic_call_checked_entry_offset())); |
| 1270 | 1272 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 // TODO(zerny): clobber non-live temporary FPU registers. | 1439 // TODO(zerny): clobber non-live temporary FPU registers. |
| 1438 if (tmp.IsRegister() && | 1440 if (tmp.IsRegister() && |
| 1439 !locs->live_registers()->ContainsRegister(tmp.reg())) { | 1441 !locs->live_registers()->ContainsRegister(tmp.reg())) { |
| 1440 __ movq(tmp.reg(), Immediate(0xf7)); | 1442 __ movq(tmp.reg(), Immediate(0xf7)); |
| 1441 } | 1443 } |
| 1442 } | 1444 } |
| 1443 } | 1445 } |
| 1444 #endif | 1446 #endif |
| 1445 | 1447 |
| 1446 | 1448 |
| 1447 void FlowGraphCompiler::EmitTestAndCallLoadReceiver( | 1449 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data, |
| 1448 intptr_t argument_count, | 1450 intptr_t argument_count, |
| 1449 const Array& arguments_descriptor) { | 1451 const Array& argument_names, |
| 1452 Label* failed, |
| 1453 Label* match_found, |
| 1454 intptr_t deopt_id, |
| 1455 TokenPosition token_index, |
| 1456 LocationSummary* locs, |
| 1457 bool complete, |
| 1458 intptr_t total_ic_calls) { |
| 1459 ASSERT(is_optimizing()); |
| 1460 |
| 1450 __ Comment("EmitTestAndCall"); | 1461 __ Comment("EmitTestAndCall"); |
| 1462 const Array& arguments_descriptor = Array::ZoneHandle( |
| 1463 zone(), ArgumentsDescriptor::New(argument_count, argument_names)); |
| 1451 // Load receiver into RAX. | 1464 // Load receiver into RAX. |
| 1452 __ movq(RAX, Address(RSP, (argument_count - 1) * kWordSize)); | 1465 __ movq(RAX, Address(RSP, (argument_count - 1) * kWordSize)); |
| 1453 __ LoadObject(R10, arguments_descriptor); | 1466 __ LoadObject(R10, arguments_descriptor); |
| 1467 |
| 1468 const bool kFirstCheckIsSmi = ic_data.GetReceiverClassIdAt(0) == kSmiCid; |
| 1469 const intptr_t num_checks = ic_data.NumberOfChecks(); |
| 1470 |
| 1471 ASSERT(!ic_data.IsNull() && (num_checks > 0)); |
| 1472 |
| 1473 Label after_smi_test; |
| 1474 if (kFirstCheckIsSmi) { |
| 1475 __ testq(RAX, Immediate(kSmiTagMask)); |
| 1476 // Jump if receiver is not Smi. |
| 1477 if (num_checks == 1) { |
| 1478 __ j(NOT_ZERO, failed); |
| 1479 } else { |
| 1480 __ j(NOT_ZERO, &after_smi_test); |
| 1481 } |
| 1482 // Do not use the code from the function, but let the code be patched so |
| 1483 // that we can record the outgoing edges to other code. |
| 1484 const Function& function = |
| 1485 Function::ZoneHandle(zone(), ic_data.GetTargetAt(0)); |
| 1486 GenerateStaticDartCall(deopt_id, token_index, |
| 1487 *StubCode::CallStaticFunction_entry(), |
| 1488 RawPcDescriptors::kOther, locs, function); |
| 1489 __ Drop(argument_count, RCX); |
| 1490 if (num_checks > 1) { |
| 1491 __ jmp(match_found); |
| 1492 } |
| 1493 } else { |
| 1494 // Receiver is Smi, but Smi is not a valid class therefore fail. |
| 1495 // (Smi class must be first in the list). |
| 1496 if (!complete) { |
| 1497 __ testq(RAX, Immediate(kSmiTagMask)); |
| 1498 __ j(ZERO, failed); |
| 1499 } |
| 1500 } |
| 1501 __ Bind(&after_smi_test); |
| 1502 |
| 1503 ASSERT(!ic_data.IsNull() && (num_checks > 0)); |
| 1504 GrowableArray<CidRangeTarget> sorted(num_checks); |
| 1505 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true); |
| 1506 |
| 1507 const intptr_t sorted_len = sorted.length(); |
| 1508 // If sorted_len is 0 then only a Smi check was needed; the Smi check above |
| 1509 // will fail if there was only one check and receiver is not Smi. |
| 1510 if (sorted_len == 0) return; |
| 1511 |
| 1512 // Value is not Smi, |
| 1513 __ LoadClassId(RDI, RAX); |
| 1514 |
| 1515 bool add_megamorphic_call = false; |
| 1516 const int kMaxImmediateInInstruction = 127; |
| 1517 int bias = |
| 1518 ComputeGoodBiasForCidComparison(sorted, kMaxImmediateInInstruction); |
| 1519 if (bias != 0) __ addl(RDI, Immediate(-bias)); |
| 1520 |
| 1521 for (intptr_t i = 0; i < sorted_len; i++) { |
| 1522 const bool is_last_check = (i == (sorted_len - 1)); |
| 1523 int cid_start = sorted[i].cid_start; |
| 1524 int cid_end = sorted[i].cid_end; |
| 1525 int count = sorted[i].count; |
| 1526 if (!is_last_check && !complete && count < (total_ic_calls >> 5)) { |
| 1527 // This case is hit too rarely to be worth writing class-id checks inline |
| 1528 // for. |
| 1529 add_megamorphic_call = true; |
| 1530 break; |
| 1531 } |
| 1532 ASSERT(cid_start > kSmiCid || cid_end < kSmiCid); |
| 1533 Label next_test; |
| 1534 if (!complete || !is_last_check) { |
| 1535 Label* next_label = is_last_check ? failed : &next_test; |
| 1536 bool near = is_last_check ? Assembler::kFarJump : Assembler::kNearJump; |
| 1537 if (cid_start == cid_end) { |
| 1538 __ cmpl(RDI, Immediate(cid_start - bias)); |
| 1539 __ j(NOT_EQUAL, next_label, near); |
| 1540 } else { |
| 1541 __ addl(RDI, Immediate(bias - cid_start)); |
| 1542 bias = cid_start; |
| 1543 __ cmpl(RDI, Immediate(cid_end - cid_start)); |
| 1544 __ j(ABOVE, next_label, near); // Unsigned higher. |
| 1545 } |
| 1546 } |
| 1547 // Do not use the code from the function, but let the code be patched so |
| 1548 // that we can record the outgoing edges to other code. |
| 1549 const Function& function = *sorted[i].target; |
| 1550 GenerateStaticDartCall(deopt_id, token_index, |
| 1551 *StubCode::CallStaticFunction_entry(), |
| 1552 RawPcDescriptors::kOther, locs, function); |
| 1553 __ Drop(argument_count, RCX); |
| 1554 if (!is_last_check) { |
| 1555 __ jmp(match_found); |
| 1556 } |
| 1557 __ Bind(&next_test); |
| 1558 } |
| 1559 if (add_megamorphic_call) { |
| 1560 int try_index = CatchClauseNode::kInvalidTryIndex; |
| 1561 EmitMegamorphicInstanceCall(ic_data, argument_count, deopt_id, token_index, |
| 1562 locs, try_index, argument_count); |
| 1563 } |
| 1454 } | 1564 } |
| 1455 | 1565 |
| 1456 | 1566 |
| 1457 void FlowGraphCompiler::EmitTestAndCallSmiBranch(Label* label, bool if_smi) { | |
| 1458 __ testq(RAX, Immediate(kSmiTagMask)); | |
| 1459 // Jump if receiver is (not) Smi. | |
| 1460 __ j(if_smi ? ZERO : NOT_ZERO, label); | |
| 1461 } | |
| 1462 | |
| 1463 | |
| 1464 void FlowGraphCompiler::EmitTestAndCallLoadCid() { | |
| 1465 __ LoadClassId(RDI, RAX); | |
| 1466 } | |
| 1467 | |
| 1468 | |
| 1469 int FlowGraphCompiler::EmitTestAndCallCheckCid(Label* next_label, | |
| 1470 const CidRangeTarget& target, | |
| 1471 int bias) { | |
| 1472 intptr_t cid_start = target.cid_start; | |
| 1473 intptr_t cid_end = target.cid_end; | |
| 1474 if (cid_start == cid_end) { | |
| 1475 __ cmpl(RDI, Immediate(cid_start - bias)); | |
| 1476 __ j(NOT_EQUAL, next_label); | |
| 1477 } else { | |
| 1478 __ addl(RDI, Immediate(bias - cid_start)); | |
| 1479 bias = cid_start; | |
| 1480 __ cmpl(RDI, Immediate(cid_end - cid_start)); | |
| 1481 __ j(ABOVE, next_label); // Unsigned higher. | |
| 1482 } | |
| 1483 return bias; | |
| 1484 } | |
| 1485 | |
| 1486 | |
| 1487 #undef __ | 1567 #undef __ |
| 1488 #define __ compiler_->assembler()-> | 1568 #define __ compiler_->assembler()-> |
| 1489 | 1569 |
| 1490 | 1570 |
| 1491 void ParallelMoveResolver::EmitMove(int index) { | 1571 void ParallelMoveResolver::EmitMove(int index) { |
| 1492 MoveOperands* move = moves_[index]; | 1572 MoveOperands* move = moves_[index]; |
| 1493 const Location source = move->src(); | 1573 const Location source = move->src(); |
| 1494 const Location destination = move->dest(); | 1574 const Location destination = move->dest(); |
| 1495 | 1575 |
| 1496 if (source.IsRegister()) { | 1576 if (source.IsRegister()) { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 __ movups(reg, Address(RSP, 0)); | 1794 __ movups(reg, Address(RSP, 0)); |
| 1715 __ AddImmediate(RSP, Immediate(kFpuRegisterSize)); | 1795 __ AddImmediate(RSP, Immediate(kFpuRegisterSize)); |
| 1716 } | 1796 } |
| 1717 | 1797 |
| 1718 | 1798 |
| 1719 #undef __ | 1799 #undef __ |
| 1720 | 1800 |
| 1721 } // namespace dart | 1801 } // namespace dart |
| 1722 | 1802 |
| 1723 #endif // defined TARGET_ARCH_X64 | 1803 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |