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

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

Issue 2809583002: Use off-heap data for type feedback in PolymorphicInstanceCallInstr (Closed)
Patch Set: Created 3 years, 8 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 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 LocationSummary* locs) { 1210 LocationSummary* locs) {
1211 ASSERT(Array::Handle(zone(), ic_data.arguments_descriptor()).Length() > 0); 1211 ASSERT(Array::Handle(zone(), ic_data.arguments_descriptor()).Length() > 0);
1212 __ LoadUniqueObject(RBX, ic_data); 1212 __ LoadUniqueObject(RBX, ic_data);
1213 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, 1213 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall,
1214 locs); 1214 locs);
1215 __ Drop(argument_count, RCX); 1215 __ Drop(argument_count, RCX);
1216 } 1216 }
1217 1217
1218 1218
1219 void FlowGraphCompiler::EmitMegamorphicInstanceCall( 1219 void FlowGraphCompiler::EmitMegamorphicInstanceCall(
1220 const ICData& ic_data, 1220 const String& name,
1221 const Array& arguments_descriptor,
1221 intptr_t argument_count, 1222 intptr_t argument_count,
1222 intptr_t deopt_id, 1223 intptr_t deopt_id,
1223 TokenPosition token_pos, 1224 TokenPosition token_pos,
1224 LocationSummary* locs, 1225 LocationSummary* locs,
1225 intptr_t try_index, 1226 intptr_t try_index,
1226 intptr_t slow_path_argument_count) { 1227 intptr_t slow_path_argument_count) {
1227 const String& name = String::Handle(zone(), ic_data.target_name());
1228 const Array& arguments_descriptor =
1229 Array::ZoneHandle(zone(), ic_data.arguments_descriptor());
1230 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); 1228 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0));
1231 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( 1229 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle(
1232 zone(), 1230 zone(),
1233 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); 1231 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor));
1234 __ Comment("MegamorphicCall"); 1232 __ Comment("MegamorphicCall");
1235 // Load receiver into RDI. 1233 // Load receiver into RDI.
1236 __ movq(RDI, Address(RSP, (argument_count - 1) * kWordSize)); 1234 __ movq(RDI, Address(RSP, (argument_count - 1) * kWordSize));
1237 __ LoadObject(RBX, cache); 1235 __ LoadObject(RBX, cache);
1238 __ call(Address(THR, Thread::megamorphic_call_checked_entry_offset())); 1236 __ call(Address(THR, Thread::megamorphic_call_checked_entry_offset()));
1239 1237
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 // TODO(zerny): clobber non-live temporary FPU registers. 1404 // TODO(zerny): clobber non-live temporary FPU registers.
1407 if (tmp.IsRegister() && 1405 if (tmp.IsRegister() &&
1408 !locs->live_registers()->ContainsRegister(tmp.reg())) { 1406 !locs->live_registers()->ContainsRegister(tmp.reg())) {
1409 __ movq(tmp.reg(), Immediate(0xf7)); 1407 __ movq(tmp.reg(), Immediate(0xf7));
1410 } 1408 }
1411 } 1409 }
1412 } 1410 }
1413 #endif 1411 #endif
1414 1412
1415 1413
1416 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data, 1414 void FlowGraphCompiler::EmitTestAndCall(const PolymorphicTargets& targets,
1415 const String& function_name,
1417 intptr_t argument_count, 1416 intptr_t argument_count,
1418 const Array& argument_names, 1417 const Array& argument_names,
1419 Label* failed, 1418 Label* failed,
1420 Label* match_found, 1419 Label* match_found,
1421 intptr_t deopt_id, 1420 intptr_t deopt_id,
1422 TokenPosition token_index, 1421 TokenPosition token_index,
1423 LocationSummary* locs, 1422 LocationSummary* locs,
1424 bool complete, 1423 bool complete,
1425 intptr_t total_ic_calls) { 1424 intptr_t total_ic_calls) {
1426 ASSERT(is_optimizing()); 1425 ASSERT(is_optimizing());
1427 1426
1428 __ Comment("EmitTestAndCall"); 1427 __ Comment("EmitTestAndCall");
1429 const Array& arguments_descriptor = Array::ZoneHandle( 1428 const Array& arguments_descriptor = Array::ZoneHandle(
1430 zone(), ArgumentsDescriptor::New(argument_count, argument_names)); 1429 zone(), ArgumentsDescriptor::New(argument_count, argument_names));
1431 // Load receiver into RAX. 1430 // Load receiver into RAX.
1432 __ movq(RAX, Address(RSP, (argument_count - 1) * kWordSize)); 1431 __ movq(RAX, Address(RSP, (argument_count - 1) * kWordSize));
1433 __ LoadObject(R10, arguments_descriptor); 1432 __ LoadObject(R10, arguments_descriptor);
1434 1433
1435 const bool kFirstCheckIsSmi = ic_data.GetReceiverClassIdAt(0) == kSmiCid; 1434 const int kNoCase = -1;
1436 const intptr_t num_checks = ic_data.NumberOfChecks(); 1435 int smi_case = kNoCase;
1436 int which_case_to_skip = kNoCase;
1437 1437
1438 ASSERT(!ic_data.IsNull() && (num_checks > 0)); 1438 const int length = targets.length();
1439 int non_smi_length = length;
1439 1440
1440 Label after_smi_test; 1441 // Find out if one of the classes in one of the cases is the Smi class. We
1441 if (kFirstCheckIsSmi) { 1442 // will be handling that specially.
1443 for (int i = 0; i < length; i++) {
1444 const intptr_t start = targets[i].cid_start;
1445 if (start > kSmiCid) continue;
1446 const intptr_t end = targets[i].cid_end;
1447 if (end >= kSmiCid) {
1448 smi_case = i;
1449 if (start == kSmiCid && end == kSmiCid) {
1450 // If this case has only the Smi class then we won't need to emit it at
1451 // all later.
1452 which_case_to_skip = i;
1453 non_smi_length--;
1454 }
1455 break;
1456 }
1457 }
1458
1459 if (smi_case != kNoCase) {
1460 Label after_smi_test;
1442 __ testq(RAX, Immediate(kSmiTagMask)); 1461 __ testq(RAX, Immediate(kSmiTagMask));
1443 // Jump if receiver is not Smi. 1462 // Jump if receiver is not Smi.
1444 if (num_checks == 1) { 1463 __ j(NOT_ZERO, non_smi_length == 0 ? failed : &after_smi_test);
1445 __ j(NOT_ZERO, failed);
1446 } else {
1447 __ j(NOT_ZERO, &after_smi_test);
1448 }
1449 // Do not use the code from the function, but let the code be patched so 1464 // Do not use the code from the function, but let the code be patched so
1450 // that we can record the outgoing edges to other code. 1465 // that we can record the outgoing edges to other code.
1451 const Function& function = 1466 const Function& function = *targets[smi_case].target;
1452 Function::ZoneHandle(zone(), ic_data.GetTargetAt(0));
1453 GenerateStaticDartCall(deopt_id, token_index, 1467 GenerateStaticDartCall(deopt_id, token_index,
1454 *StubCode::CallStaticFunction_entry(), 1468 *StubCode::CallStaticFunction_entry(),
1455 RawPcDescriptors::kOther, locs, function); 1469 RawPcDescriptors::kOther, locs, function);
1456 __ Drop(argument_count, RCX); 1470 __ Drop(argument_count, RCX);
1457 if (num_checks > 1) { 1471 if (non_smi_length > 0) {
1458 __ jmp(match_found); 1472 __ jmp(match_found);
1459 } 1473 }
1474 __ Bind(&after_smi_test);
1460 } else { 1475 } else {
1461 // Receiver is Smi, but Smi is not a valid class therefore fail. 1476 // Receiver is Smi, but Smi is not a valid class therefore fail.
1462 // (Smi class must be first in the list).
1463 if (!complete) { 1477 if (!complete) {
1464 __ testq(RAX, Immediate(kSmiTagMask)); 1478 __ testq(RAX, Immediate(kSmiTagMask));
1465 __ j(ZERO, failed); 1479 __ j(ZERO, failed);
1466 } 1480 }
1467 } 1481 }
1468 __ Bind(&after_smi_test);
1469 1482
1470 ASSERT(!ic_data.IsNull() && (num_checks > 0)); 1483 ASSERT(length > 0);
1471 GrowableArray<CidRangeTarget> sorted(num_checks);
1472 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true);
1473 1484
1474 const intptr_t sorted_len = sorted.length(); 1485 // If non_smi_length is 0 then only a Smi check was needed; the Smi check
1475 // If sorted_len is 0 then only a Smi check was needed; the Smi check above 1486 // above will fail if there was only one check and receiver is not Smi.
1476 // will fail if there was only one check and receiver is not Smi. 1487 if (non_smi_length == 0) return;
1477 if (sorted_len == 0) return;
1478 1488
1479 // Value is not Smi, 1489 // Value is not Smi,
1480 __ LoadClassId(RDI, RAX); 1490 __ LoadClassId(RDI, RAX);
1481 1491
1482 bool add_megamorphic_call = false; 1492 bool add_megamorphic_call = false;
1483 const int kMaxImmediateInInstruction = 127; 1493 const int kMaxImmediateInInstruction = 127;
1484 int bias = 1494 int bias =
1485 ComputeGoodBiasForCidComparison(sorted, kMaxImmediateInInstruction); 1495 ComputeGoodBiasForCidComparison(targets, kMaxImmediateInInstruction);
1486 if (bias != 0) __ addl(RDI, Immediate(-bias)); 1496 if (bias != 0) __ addl(RDI, Immediate(-bias));
1487 1497
1488 for (intptr_t i = 0; i < sorted_len; i++) { 1498 int last_check = which_case_to_skip == length - 1 ? length - 2 : length - 1;
1489 const bool is_last_check = (i == (sorted_len - 1)); 1499
1490 int cid_start = sorted[i].cid_start; 1500 for (intptr_t i = 0; i < length; i++) {
1491 int cid_end = sorted[i].cid_end; 1501 if (i == which_case_to_skip) continue;
1492 int count = sorted[i].count; 1502 const bool is_last_check = (i == last_check);
1493 if (!is_last_check && !complete && count < (total_ic_calls >> 5)) { 1503 const int cid_start = targets[i].cid_start;
1504 const int cid_end = targets[i].cid_end;
1505 const int count = targets[i].count;
1506 if (!is_last_check && !complete && count <= (total_ic_calls >> 5)) {
1494 // This case is hit too rarely to be worth writing class-id checks inline 1507 // This case is hit too rarely to be worth writing class-id checks inline
1495 // for. 1508 // for. Note that we can't do this for calls with only one target because
1509 // the type propagator may have made use of that and expects a deopt if
1510 // a new class is seen at this calls site. See HasSingleRecognizedCid.
1496 add_megamorphic_call = true; 1511 add_megamorphic_call = true;
1497 break; 1512 break;
1498 } 1513 }
1499 ASSERT(cid_start > kSmiCid || cid_end < kSmiCid);
1500 Label next_test; 1514 Label next_test;
1501 if (!complete || !is_last_check) { 1515 if (!complete || !is_last_check) {
1502 Label* next_label = is_last_check ? failed : &next_test; 1516 Label* const next_label = is_last_check ? failed : &next_test;
1503 bool near = is_last_check ? Assembler::kFarJump : Assembler::kNearJump; 1517 const bool near =
1518 is_last_check ? Assembler::kFarJump : Assembler::kNearJump;
1504 if (cid_start == cid_end) { 1519 if (cid_start == cid_end) {
1505 __ cmpl(RDI, Immediate(cid_start - bias)); 1520 __ cmpl(RDI, Immediate(cid_start - bias));
1506 __ j(NOT_EQUAL, next_label, near); 1521 __ j(NOT_EQUAL, next_label, near);
1507 } else { 1522 } else {
1508 __ addl(RDI, Immediate(bias - cid_start)); 1523 __ addl(RDI, Immediate(bias - cid_start));
1509 bias = cid_start; 1524 bias = cid_start;
1510 __ cmpl(RDI, Immediate(cid_end - cid_start)); 1525 __ cmpl(RDI, Immediate(cid_end - cid_start));
1511 __ j(ABOVE, next_label, near); // Unsigned higher. 1526 __ j(ABOVE, next_label, near); // Unsigned higher.
1512 } 1527 }
1513 } 1528 }
1514 // Do not use the code from the function, but let the code be patched so 1529 // Do not use the code from the function, but let the code be patched so
1515 // that we can record the outgoing edges to other code. 1530 // that we can record the outgoing edges to other code.
1516 const Function& function = *sorted[i].target; 1531 const Function& function = *targets[i].target;
1517 GenerateStaticDartCall(deopt_id, token_index, 1532 GenerateStaticDartCall(deopt_id, token_index,
1518 *StubCode::CallStaticFunction_entry(), 1533 *StubCode::CallStaticFunction_entry(),
1519 RawPcDescriptors::kOther, locs, function); 1534 RawPcDescriptors::kOther, locs, function);
1520 __ Drop(argument_count, RCX); 1535 __ Drop(argument_count, RCX);
1521 if (!is_last_check) { 1536 if (!is_last_check || add_megamorphic_call) {
1522 __ jmp(match_found); 1537 __ jmp(match_found);
1523 } 1538 }
1524 __ Bind(&next_test); 1539 __ Bind(&next_test);
1525 } 1540 }
1526 if (add_megamorphic_call) { 1541 if (add_megamorphic_call) {
1527 int try_index = CatchClauseNode::kInvalidTryIndex; 1542 const int try_index = CatchClauseNode::kInvalidTryIndex;
1528 EmitMegamorphicInstanceCall(ic_data, argument_count, deopt_id, token_index, 1543 EmitMegamorphicInstanceCall(function_name, arguments_descriptor,
1529 locs, try_index, argument_count); 1544 argument_count, deopt_id, token_index, locs,
1545 try_index);
1530 } 1546 }
1531 } 1547 }
1532 1548
1533 1549
1534 #undef __ 1550 #undef __
1535 #define __ compiler_->assembler()-> 1551 #define __ compiler_->assembler()->
1536 1552
1537 1553
1538 void ParallelMoveResolver::EmitMove(int index) { 1554 void ParallelMoveResolver::EmitMove(int index) {
1539 MoveOperands* move = moves_[index]; 1555 MoveOperands* move = moves_[index];
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 __ movups(reg, Address(RSP, 0)); 1777 __ movups(reg, Address(RSP, 0));
1762 __ AddImmediate(RSP, Immediate(kFpuRegisterSize)); 1778 __ AddImmediate(RSP, Immediate(kFpuRegisterSize));
1763 } 1779 }
1764 1780
1765 1781
1766 #undef __ 1782 #undef __
1767 1783
1768 } // namespace dart 1784 } // namespace dart
1769 1785
1770 #endif // defined TARGET_ARCH_X64 1786 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698