Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: runtime/vm/flow_graph_compiler_x64.cc

Issue 1184093004: Faster checks in polymorphic instance calls if Smi-s are involved (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 if (tmp.IsRegister() && 1464 if (tmp.IsRegister() &&
1465 !locs->live_registers()->ContainsRegister(tmp.reg())) { 1465 !locs->live_registers()->ContainsRegister(tmp.reg())) {
1466 __ movq(tmp.reg(), Immediate(0xf7)); 1466 __ movq(tmp.reg(), Immediate(0xf7));
1467 } 1467 }
1468 } 1468 }
1469 } 1469 }
1470 #endif 1470 #endif
1471 1471
1472 1472
1473 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data, 1473 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data,
1474 Register class_id_reg,
1475 intptr_t argument_count, 1474 intptr_t argument_count,
1476 const Array& argument_names, 1475 const Array& argument_names,
1477 Label* deopt, 1476 Label* failed,
1477 Label* match_found,
1478 intptr_t deopt_id, 1478 intptr_t deopt_id,
1479 intptr_t token_index, 1479 intptr_t token_index,
1480 LocationSummary* locs) { 1480 LocationSummary* locs) {
1481 ASSERT(is_optimizing()); 1481 ASSERT(is_optimizing());
1482 ASSERT(!ic_data.IsNull() && (ic_data.NumberOfUsedChecks() > 0)); 1482
1483 Label match_found; 1483 __ Comment("EmitTestAndCall");
1484 const intptr_t len = ic_data.NumberOfChecks();
1485 GrowableArray<CidTarget> sorted(len);
1486 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ false);
1487 ASSERT(class_id_reg != R10);
1488 ASSERT(len > 0); // Why bother otherwise.
1489 const Array& arguments_descriptor = 1484 const Array& arguments_descriptor =
1490 Array::ZoneHandle(ArgumentsDescriptor::New(argument_count, 1485 Array::ZoneHandle(ArgumentsDescriptor::New(argument_count,
1491 argument_names)); 1486 argument_names));
1492 StubCode* stub_code = isolate()->stub_code(); 1487 StubCode* stub_code = isolate()->stub_code();
1488 // Load receiver into RAX.
1489 __ movq(RAX,
1490 Address(RSP, (argument_count - 1) * kWordSize));
1491 __ LoadObject(R10, arguments_descriptor, PP);
1493 1492
1494 __ LoadObject(R10, arguments_descriptor, PP); 1493 const bool kFirstCheckIsSmi = ic_data.GetReceiverClassIdAt(0) == kSmiCid;
1495 for (intptr_t i = 0; i < len; i++) { 1494 const intptr_t kNumChecks = ic_data.NumberOfChecks();
1496 const bool is_last_check = (i == (len - 1)); 1495
1496 ASSERT(!ic_data.IsNull() && (kNumChecks > 0));
1497
1498 Label next_test;
zra 2015/06/15 20:17:23 after_smi_test
1499 __ testq(RAX, Immediate(kSmiTagMask));
1500 if (kFirstCheckIsSmi) {
1501 // Jump if receiver is not Smi.
1502 if (kNumChecks == 1) {
1503 __ j(NOT_ZERO, failed);
1504 } else {
1505 __ j(NOT_ZERO, &next_test);
1506 }
1507 // Do not use the code from the function, but let the code be patched so
1508 // that we can record the outgoing edges to other code.
1509 GenerateDartCall(deopt_id,
1510 token_index,
1511 &stub_code->CallStaticFunctionLabel(),
1512 RawPcDescriptors::kOther,
1513 locs);
1514 const Function& function = Function::Handle(ic_data.GetTargetAt(0));
1515 AddStaticCallTarget(function);
1516 __ Drop(argument_count, RCX);
1517 if (kNumChecks > 1) {
1518 __ jmp(match_found);
1519 }
1520 } else {
1521 // It is Smi, butSmi is not handled here.
1522 __ j(ZERO, failed);
1523 }
1524 __ Bind(&next_test);
1525
1526 ASSERT(!ic_data.IsNull() && (kNumChecks > 0));
1527 GrowableArray<CidTarget> sorted(kNumChecks);
1528 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true);
1529
1530 const intptr_t kSortedLen = sorted.length();
1531 if (kSortedLen == 0) return;
1532
1533 // Value is not Smi,
1534 __ LoadClassId(RDI, RAX);
1535 for (intptr_t i = 0; i < kSortedLen; i++) {
1536 const bool kIsLastCheck = (i == (kSortedLen - 1));
1497 Label next_test; 1537 Label next_test;
1498 __ cmpl(class_id_reg, Immediate(sorted[i].cid)); 1538 __ cmpl(RDI, Immediate(sorted[i].cid));
1499 if (is_last_check) { 1539 if (kIsLastCheck) {
1500 __ j(NOT_EQUAL, deopt); 1540 __ j(NOT_EQUAL, failed);
1501 } else { 1541 } else {
1502 __ j(NOT_EQUAL, &next_test); 1542 __ j(NOT_EQUAL, &next_test);
1503 } 1543 }
1504 // Do not use the code from the function, but let the code be patched so 1544 // Do not use the code from the function, but let the code be patched so
1505 // that we can record the outgoing edges to other code. 1545 // that we can record the outgoing edges to other code.
1506 GenerateDartCall(deopt_id, 1546 GenerateDartCall(deopt_id,
1507 token_index, 1547 token_index,
1508 &stub_code->CallStaticFunctionLabel(), 1548 &stub_code->CallStaticFunctionLabel(),
1509 RawPcDescriptors::kOther, 1549 RawPcDescriptors::kOther,
1510 locs); 1550 locs);
1511 const Function& function = *sorted[i].target; 1551 const Function& function = *sorted[i].target;
1512 AddStaticCallTarget(function); 1552 AddStaticCallTarget(function);
1513 __ Drop(argument_count, RCX); 1553 __ Drop(argument_count, RCX);
1514 if (!is_last_check) { 1554 if (!kIsLastCheck) {
1515 __ jmp(&match_found); 1555 __ jmp(match_found);
1516 } 1556 }
1517 __ Bind(&next_test); 1557 __ Bind(&next_test);
1518 } 1558 }
1519 __ Bind(&match_found);
1520 } 1559 }
1521 1560
1522 1561
1523 #undef __ 1562 #undef __
1524 #define __ compiler_->assembler()-> 1563 #define __ compiler_->assembler()->
1525 1564
1526 1565
1527 void ParallelMoveResolver::EmitMove(int index) { 1566 void ParallelMoveResolver::EmitMove(int index) {
1528 MoveOperands* move = moves_[index]; 1567 MoveOperands* move = moves_[index];
1529 const Location source = move->src(); 1568 const Location source = move->src();
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 __ movups(reg, Address(RSP, 0)); 1790 __ movups(reg, Address(RSP, 0));
1752 __ AddImmediate(RSP, Immediate(kFpuRegisterSize), PP); 1791 __ AddImmediate(RSP, Immediate(kFpuRegisterSize), PP);
1753 } 1792 }
1754 1793
1755 1794
1756 #undef __ 1795 #undef __
1757 1796
1758 } // namespace dart 1797 } // namespace dart
1759 1798
1760 #endif // defined TARGET_ARCH_X64 1799 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698