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

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: m 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
« no previous file with comments | « runtime/vm/flow_graph_compiler_mips.cc ('k') | runtime/vm/intermediate_language_arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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, &after_smi_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 // Receiver is Smi, but Smi is not a valid class therefore fail.
1522 // (Smi class must be first in the list).
1523 __ j(ZERO, failed);
1524 }
1525 __ Bind(&after_smi_test);
1526
1527 ASSERT(!ic_data.IsNull() && (kNumChecks > 0));
1528 GrowableArray<CidTarget> sorted(kNumChecks);
1529 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true);
1530
1531 const intptr_t kSortedLen = sorted.length();
1532 // If kSortedLen is 0 then only a Smi check was needed; the Smi check above
1533 // will fail if there was only one check and receiver is not Smi.
1534 if (kSortedLen == 0) return;
1535
1536 // Value is not Smi,
1537 __ LoadClassId(RDI, RAX);
1538 for (intptr_t i = 0; i < kSortedLen; i++) {
1539 const bool kIsLastCheck = (i == (kSortedLen - 1));
1540 ASSERT(sorted[i].cid != kSmiCid);
1497 Label next_test; 1541 Label next_test;
1498 __ cmpl(class_id_reg, Immediate(sorted[i].cid)); 1542 __ cmpl(RDI, Immediate(sorted[i].cid));
1499 if (is_last_check) { 1543 if (kIsLastCheck) {
1500 __ j(NOT_EQUAL, deopt); 1544 __ j(NOT_EQUAL, failed);
1501 } else { 1545 } else {
1502 __ j(NOT_EQUAL, &next_test); 1546 __ j(NOT_EQUAL, &next_test);
1503 } 1547 }
1504 // Do not use the code from the function, but let the code be patched so 1548 // 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. 1549 // that we can record the outgoing edges to other code.
1506 GenerateDartCall(deopt_id, 1550 GenerateDartCall(deopt_id,
1507 token_index, 1551 token_index,
1508 &stub_code->CallStaticFunctionLabel(), 1552 &stub_code->CallStaticFunctionLabel(),
1509 RawPcDescriptors::kOther, 1553 RawPcDescriptors::kOther,
1510 locs); 1554 locs);
1511 const Function& function = *sorted[i].target; 1555 const Function& function = *sorted[i].target;
1512 AddStaticCallTarget(function); 1556 AddStaticCallTarget(function);
1513 __ Drop(argument_count, RCX); 1557 __ Drop(argument_count, RCX);
1514 if (!is_last_check) { 1558 if (!kIsLastCheck) {
1515 __ jmp(&match_found); 1559 __ jmp(match_found);
1516 } 1560 }
1517 __ Bind(&next_test); 1561 __ Bind(&next_test);
1518 } 1562 }
1519 __ Bind(&match_found);
1520 } 1563 }
1521 1564
1522 1565
1523 #undef __ 1566 #undef __
1524 #define __ compiler_->assembler()-> 1567 #define __ compiler_->assembler()->
1525 1568
1526 1569
1527 void ParallelMoveResolver::EmitMove(int index) { 1570 void ParallelMoveResolver::EmitMove(int index) {
1528 MoveOperands* move = moves_[index]; 1571 MoveOperands* move = moves_[index];
1529 const Location source = move->src(); 1572 const Location source = move->src();
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 __ movups(reg, Address(RSP, 0)); 1794 __ movups(reg, Address(RSP, 0));
1752 __ AddImmediate(RSP, Immediate(kFpuRegisterSize), PP); 1795 __ AddImmediate(RSP, Immediate(kFpuRegisterSize), PP);
1753 } 1796 }
1754 1797
1755 1798
1756 #undef __ 1799 #undef __
1757 1800
1758 } // namespace dart 1801 } // namespace dart
1759 1802
1760 #endif // defined TARGET_ARCH_X64 1803 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_compiler_mips.cc ('k') | runtime/vm/intermediate_language_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698