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

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: More feedback from Slava 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
« no previous file with comments | « runtime/vm/flow_graph_compiler_mips.cc ('k') | runtime/vm/flow_graph_inliner.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 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::EmitTestAndCallLoadReceiver(
1417 intptr_t argument_count, 1415 intptr_t argument_count,
1418 const Array& argument_names, 1416 const Array& arguments_descriptor) {
1419 Label* failed,
1420 Label* match_found,
1421 intptr_t deopt_id,
1422 TokenPosition token_index,
1423 LocationSummary* locs,
1424 bool complete,
1425 intptr_t total_ic_calls) {
1426 ASSERT(is_optimizing());
1427
1428 __ Comment("EmitTestAndCall"); 1417 __ Comment("EmitTestAndCall");
1429 const Array& arguments_descriptor = Array::ZoneHandle(
1430 zone(), ArgumentsDescriptor::New(argument_count, argument_names));
1431 // Load receiver into RAX. 1418 // Load receiver into RAX.
1432 __ movq(RAX, Address(RSP, (argument_count - 1) * kWordSize)); 1419 __ movq(RAX, Address(RSP, (argument_count - 1) * kWordSize));
1433 __ LoadObject(R10, arguments_descriptor); 1420 __ LoadObject(R10, arguments_descriptor);
1434
1435 const bool kFirstCheckIsSmi = ic_data.GetReceiverClassIdAt(0) == kSmiCid;
1436 const intptr_t num_checks = ic_data.NumberOfChecks();
1437
1438 ASSERT(!ic_data.IsNull() && (num_checks > 0));
1439
1440 Label after_smi_test;
1441 if (kFirstCheckIsSmi) {
1442 __ testq(RAX, Immediate(kSmiTagMask));
1443 // Jump if receiver is not Smi.
1444 if (num_checks == 1) {
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
1450 // that we can record the outgoing edges to other code.
1451 const Function& function =
1452 Function::ZoneHandle(zone(), ic_data.GetTargetAt(0));
1453 GenerateStaticDartCall(deopt_id, token_index,
1454 *StubCode::CallStaticFunction_entry(),
1455 RawPcDescriptors::kOther, locs, function);
1456 __ Drop(argument_count, RCX);
1457 if (num_checks > 1) {
1458 __ jmp(match_found);
1459 }
1460 } else {
1461 // Receiver is Smi, but Smi is not a valid class therefore fail.
1462 // (Smi class must be first in the list).
1463 if (!complete) {
1464 __ testq(RAX, Immediate(kSmiTagMask));
1465 __ j(ZERO, failed);
1466 }
1467 }
1468 __ Bind(&after_smi_test);
1469
1470 ASSERT(!ic_data.IsNull() && (num_checks > 0));
1471 GrowableArray<CidRangeTarget> sorted(num_checks);
1472 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true);
1473
1474 const intptr_t sorted_len = sorted.length();
1475 // If sorted_len is 0 then only a Smi check was needed; the Smi check above
1476 // will fail if there was only one check and receiver is not Smi.
1477 if (sorted_len == 0) return;
1478
1479 // Value is not Smi,
1480 __ LoadClassId(RDI, RAX);
1481
1482 bool add_megamorphic_call = false;
1483 const int kMaxImmediateInInstruction = 127;
1484 int bias =
1485 ComputeGoodBiasForCidComparison(sorted, kMaxImmediateInInstruction);
1486 if (bias != 0) __ addl(RDI, Immediate(-bias));
1487
1488 for (intptr_t i = 0; i < sorted_len; i++) {
1489 const bool is_last_check = (i == (sorted_len - 1));
1490 int cid_start = sorted[i].cid_start;
1491 int cid_end = sorted[i].cid_end;
1492 int count = sorted[i].count;
1493 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
1495 // for.
1496 add_megamorphic_call = true;
1497 break;
1498 }
1499 ASSERT(cid_start > kSmiCid || cid_end < kSmiCid);
1500 Label next_test;
1501 if (!complete || !is_last_check) {
1502 Label* next_label = is_last_check ? failed : &next_test;
1503 bool near = is_last_check ? Assembler::kFarJump : Assembler::kNearJump;
1504 if (cid_start == cid_end) {
1505 __ cmpl(RDI, Immediate(cid_start - bias));
1506 __ j(NOT_EQUAL, next_label, near);
1507 } else {
1508 __ addl(RDI, Immediate(bias - cid_start));
1509 bias = cid_start;
1510 __ cmpl(RDI, Immediate(cid_end - cid_start));
1511 __ j(ABOVE, next_label, near); // Unsigned higher.
1512 }
1513 }
1514 // 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.
1516 const Function& function = *sorted[i].target;
1517 GenerateStaticDartCall(deopt_id, token_index,
1518 *StubCode::CallStaticFunction_entry(),
1519 RawPcDescriptors::kOther, locs, function);
1520 __ Drop(argument_count, RCX);
1521 if (!is_last_check) {
1522 __ jmp(match_found);
1523 }
1524 __ Bind(&next_test);
1525 }
1526 if (add_megamorphic_call) {
1527 int try_index = CatchClauseNode::kInvalidTryIndex;
1528 EmitMegamorphicInstanceCall(ic_data, argument_count, deopt_id, token_index,
1529 locs, try_index, argument_count);
1530 }
1531 } 1421 }
1532 1422
1533 1423
1424 void FlowGraphCompiler::EmitTestAndCallSmiBranch(Label* label, bool if_smi) {
1425 __ testq(RAX, Immediate(kSmiTagMask));
1426 // Jump if receiver is (not) Smi.
1427 __ j(if_smi ? ZERO : NOT_ZERO, label);
1428 }
1429
1430
1431 void FlowGraphCompiler::EmitTestAndCallLoadCid() {
1432 __ LoadClassId(RDI, RAX);
1433 }
1434
1435
1436 int FlowGraphCompiler::EmitTestAndCallCheckCid(Label* next_label,
1437 const CidRangeTarget& target,
1438 int bias) {
1439 intptr_t cid_start = target.cid_start;
1440 intptr_t cid_end = target.cid_end;
1441 if (cid_start == cid_end) {
1442 __ cmpl(RDI, Immediate(cid_start - bias));
1443 __ j(NOT_EQUAL, next_label);
1444 } else {
1445 __ addl(RDI, Immediate(bias - cid_start));
1446 bias = cid_start;
1447 __ cmpl(RDI, Immediate(cid_end - cid_start));
1448 __ j(ABOVE, next_label); // Unsigned higher.
1449 }
1450 return bias;
1451 }
1452
1453
1534 #undef __ 1454 #undef __
1535 #define __ compiler_->assembler()-> 1455 #define __ compiler_->assembler()->
1536 1456
1537 1457
1538 void ParallelMoveResolver::EmitMove(int index) { 1458 void ParallelMoveResolver::EmitMove(int index) {
1539 MoveOperands* move = moves_[index]; 1459 MoveOperands* move = moves_[index];
1540 const Location source = move->src(); 1460 const Location source = move->src();
1541 const Location destination = move->dest(); 1461 const Location destination = move->dest();
1542 1462
1543 if (source.IsRegister()) { 1463 if (source.IsRegister()) {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 __ movups(reg, Address(RSP, 0)); 1681 __ movups(reg, Address(RSP, 0));
1762 __ AddImmediate(RSP, Immediate(kFpuRegisterSize)); 1682 __ AddImmediate(RSP, Immediate(kFpuRegisterSize));
1763 } 1683 }
1764 1684
1765 1685
1766 #undef __ 1686 #undef __
1767 1687
1768 } // namespace dart 1688 } // namespace dart
1769 1689
1770 #endif // defined TARGET_ARCH_X64 1690 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_compiler_mips.cc ('k') | runtime/vm/flow_graph_inliner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698