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

Side by Side Diff: runtime/vm/flow_graph_compiler_ia32.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_IA32. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32.
6 #if defined(TARGET_ARCH_IA32) 6 #if defined(TARGET_ARCH_IA32)
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 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 LocationSummary* locs) { 1176 LocationSummary* locs) {
1177 ASSERT(Array::Handle(ic_data.arguments_descriptor()).Length() > 0); 1177 ASSERT(Array::Handle(ic_data.arguments_descriptor()).Length() > 0);
1178 __ LoadObject(ECX, ic_data); 1178 __ LoadObject(ECX, ic_data);
1179 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, 1179 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall,
1180 locs); 1180 locs);
1181 __ Drop(argument_count); 1181 __ Drop(argument_count);
1182 } 1182 }
1183 1183
1184 1184
1185 void FlowGraphCompiler::EmitMegamorphicInstanceCall( 1185 void FlowGraphCompiler::EmitMegamorphicInstanceCall(
1186 const ICData& ic_data, 1186 const String& name,
1187 const Array& arguments_descriptor,
1187 intptr_t argument_count, 1188 intptr_t argument_count,
1188 intptr_t deopt_id, 1189 intptr_t deopt_id,
1189 TokenPosition token_pos, 1190 TokenPosition token_pos,
1190 LocationSummary* locs, 1191 LocationSummary* locs,
1191 intptr_t try_index, 1192 intptr_t try_index,
1192 intptr_t slow_path_argument_count) { 1193 intptr_t slow_path_argument_count) {
1193 const String& name = String::Handle(zone(), ic_data.target_name());
1194 const Array& arguments_descriptor =
1195 Array::ZoneHandle(zone(), ic_data.arguments_descriptor());
1196 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); 1194 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0));
1197 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( 1195 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle(
1198 zone(), 1196 zone(),
1199 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); 1197 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor));
1200 1198
1201 __ Comment("MegamorphicCall"); 1199 __ Comment("MegamorphicCall");
1202 // Load receiver into EBX. 1200 // Load receiver into EBX.
1203 __ movl(EBX, Address(ESP, (argument_count - 1) * kWordSize)); 1201 __ movl(EBX, Address(ESP, (argument_count - 1) * kWordSize));
1204 __ LoadObject(ECX, cache); 1202 __ LoadObject(ECX, cache);
1205 __ call(Address(THR, Thread::megamorphic_call_checked_entry_offset())); 1203 __ call(Address(THR, Thread::megamorphic_call_checked_entry_offset()));
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 // TODO(zerny): clobber non-live temporary FPU registers. 1383 // TODO(zerny): clobber non-live temporary FPU registers.
1386 if (tmp.IsRegister() && 1384 if (tmp.IsRegister() &&
1387 !locs->live_registers()->ContainsRegister(tmp.reg())) { 1385 !locs->live_registers()->ContainsRegister(tmp.reg())) {
1388 __ movl(tmp.reg(), Immediate(0xf7)); 1386 __ movl(tmp.reg(), Immediate(0xf7));
1389 } 1387 }
1390 } 1388 }
1391 } 1389 }
1392 #endif 1390 #endif
1393 1391
1394 1392
1395 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data, 1393 void FlowGraphCompiler::EmitTestAndCall(const PolymorphicTargets& targets,
1394 const String& function_name,
1396 intptr_t argument_count, 1395 intptr_t argument_count,
1397 const Array& argument_names, 1396 const Array& argument_names,
1398 Label* failed, 1397 Label* failed,
1399 Label* match_found, 1398 Label* match_found,
1400 intptr_t deopt_id, 1399 intptr_t deopt_id,
1401 TokenPosition token_index, 1400 TokenPosition token_index,
1402 LocationSummary* locs, 1401 LocationSummary* locs,
1403 bool complete, 1402 bool complete,
1404 intptr_t total_ic_calls) { 1403 intptr_t total_ic_calls) {
1405 ASSERT(is_optimizing()); 1404 ASSERT(is_optimizing());
1406 ASSERT(!complete); 1405 ASSERT(!complete);
1407 __ Comment("EmitTestAndCall"); 1406 __ Comment("EmitTestAndCall");
1408 const Array& arguments_descriptor = Array::ZoneHandle( 1407 const Array& arguments_descriptor = Array::ZoneHandle(
1409 zone(), ArgumentsDescriptor::New(argument_count, argument_names)); 1408 zone(), ArgumentsDescriptor::New(argument_count, argument_names));
1410 // Load receiver into EAX. 1409 // Load receiver into EAX.
1411 __ movl(EAX, Address(ESP, (argument_count - 1) * kWordSize)); 1410 __ movl(EAX, Address(ESP, (argument_count - 1) * kWordSize));
1412 __ LoadObject(EDX, arguments_descriptor); 1411 __ LoadObject(EDX, arguments_descriptor);
1413 1412
1414 const bool kFirstCheckIsSmi = ic_data.GetReceiverClassIdAt(0) == kSmiCid; 1413 const int kNoCase = -1;
1415 const intptr_t num_checks = ic_data.NumberOfChecks(); 1414 int smi_case = kNoCase;
1415 int which_case_to_skip = kNoCase;
1416 1416
1417 ASSERT(!ic_data.IsNull() && (num_checks > 0)); 1417 const int length = targets.length();
1418 int non_smi_length = length;
1418 1419
1419 Label after_smi_test; 1420 // Find out if one of the classes in one of the cases is the Smi class. We
1421 // will be handling that specially.
1422 for (int i = 0; i < length; i++) {
1423 const intptr_t start = targets[i].cid_start;
1424 if (start > kSmiCid) continue;
1425 const intptr_t end = targets[i].cid_end;
1426 if (end >= kSmiCid) {
1427 smi_case = i;
1428 if (start == kSmiCid && end == kSmiCid) {
1429 // If this case has only the Smi class then we won't need to emit it at
1430 // all later.
1431 which_case_to_skip = i;
1432 non_smi_length--;
1433 }
1434 break;
1435 }
1436 }
1437
1420 __ testl(EAX, Immediate(kSmiTagMask)); 1438 __ testl(EAX, Immediate(kSmiTagMask));
1421 if (kFirstCheckIsSmi) { 1439
1440 if (smi_case != kNoCase) {
1441 Label after_smi_test;
1422 // Jump if receiver is not Smi. 1442 // Jump if receiver is not Smi.
1423 if (num_checks == 1) { 1443 __ j(NOT_ZERO, non_smi_length == 0 ? failed : &after_smi_test);
1424 __ j(NOT_ZERO, failed);
1425 } else {
1426 __ j(NOT_ZERO, &after_smi_test);
1427 }
1428 // Do not use the code from the function, but let the code be patched so 1444 // Do not use the code from the function, but let the code be patched so
1429 // that we can record the outgoing edges to other code. 1445 // that we can record the outgoing edges to other code.
1446 const Function& function = *targets[smi_case].target;
1430 GenerateDartCall(deopt_id, token_index, 1447 GenerateDartCall(deopt_id, token_index,
1431 *StubCode::CallStaticFunction_entry(), 1448 *StubCode::CallStaticFunction_entry(),
1432 RawPcDescriptors::kOther, locs); 1449 RawPcDescriptors::kOther, locs);
1433 const Function& function =
1434 Function::ZoneHandle(zone(), ic_data.GetTargetAt(0));
1435 AddStaticCallTarget(function); 1450 AddStaticCallTarget(function);
1451
1436 __ Drop(argument_count); 1452 __ Drop(argument_count);
1437 if (num_checks > 1) { 1453 if (non_smi_length > 0) {
1438 __ jmp(match_found); 1454 __ jmp(match_found);
1439 } 1455 }
1456 __ Bind(&after_smi_test);
1440 } else { 1457 } else {
1441 // Receiver is Smi, but Smi is not a valid class therefore fail. 1458 // Receiver is Smi, but Smi is not a valid class therefore fail.
1442 // (Smi class must be first in the list).
1443 __ j(ZERO, failed); 1459 __ j(ZERO, failed);
1444 } 1460 }
1445 __ Bind(&after_smi_test);
1446 1461
1447 ASSERT(!ic_data.IsNull() && (num_checks > 0)); 1462 ASSERT(length > 0);
1448 GrowableArray<CidRangeTarget> sorted(num_checks);
1449 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true);
1450 1463
1451 const intptr_t sorted_len = sorted.length(); 1464 // If non_smi_length is 0 then only a Smi check was needed; the Smi check
1452 // If sorted_len is 0 then only a Smi check was needed; the Smi check above 1465 // above will fail if there was only one check and receiver is not Smi.
1453 // will fail if there was only one check and receiver is not Smi. 1466 if (non_smi_length == 0) return;
1454 if (sorted_len == 0) return;
1455 1467
1456 // Value is not Smi, 1468 // Value is not Smi,
1457 __ LoadClassId(EDI, EAX); 1469 __ LoadClassId(EDI, EAX);
1458 1470
1459 bool add_megamorphic_call = false; 1471 bool add_megamorphic_call = false;
1460 const int kMaxImmediateInInstruction = 127; 1472 const int kMaxImmediateInInstruction = 127;
1461 int bias = 1473 int bias =
1462 ComputeGoodBiasForCidComparison(sorted, kMaxImmediateInInstruction); 1474 ComputeGoodBiasForCidComparison(targets, kMaxImmediateInInstruction);
1463 if (bias != 0) __ addl(EDI, Immediate(-bias)); 1475 if (bias != 0) __ addl(EDI, Immediate(-bias));
1464 1476
1465 for (intptr_t i = 0; i < sorted_len; i++) { 1477 int last_check = which_case_to_skip == length - 1 ? length - 2 : length - 1;
1466 const bool is_last_check = (i == (sorted_len - 1)); 1478
1467 int cid_start = sorted[i].cid_start; 1479 for (intptr_t i = 0; i < length; i++) {
1468 int cid_end = sorted[i].cid_end; 1480 if (i == which_case_to_skip) continue;
1469 int count = sorted[i].count; 1481 const bool is_last_check = (i == last_check);
1470 if (!is_last_check && !complete && count < (total_ic_calls >> 5)) { 1482 int cid_start = targets[i].cid_start;
1483 int cid_end = targets[i].cid_end;
1484 int count = targets[i].count;
1485 if (!is_last_check && !complete && count <= (total_ic_calls >> 5)) {
1471 // This case is hit too rarely to be worth writing class-id checks inline 1486 // This case is hit too rarely to be worth writing class-id checks inline
1472 // for. 1487 // for. Note that we can't do this for calls with only one target because
1488 // the type propagator may have made use of that and expects a deopt if
1489 // a new class is seen at this calls site. See HasSingleRecognizedCid.
1473 add_megamorphic_call = true; 1490 add_megamorphic_call = true;
1474 break; 1491 break;
1475 } 1492 }
1476 ASSERT(cid_start > kSmiCid || cid_end < kSmiCid);
1477 Label next_test; 1493 Label next_test;
1478 if (!complete || !is_last_check) { 1494 Label* next_label = is_last_check ? failed : &next_test;
1479 Label* next_label = is_last_check ? failed : &next_test; 1495 if (cid_start == cid_end) {
1480 if (cid_start == cid_end) { 1496 __ cmpl(EDI, Immediate(cid_start - bias));
1481 __ cmpl(EDI, Immediate(cid_start - bias)); 1497 __ j(NOT_EQUAL, next_label);
1482 __ j(NOT_EQUAL, next_label); 1498 } else {
1483 } else { 1499 __ addl(EDI, Immediate(bias - cid_start));
1484 __ addl(EDI, Immediate(bias - cid_start)); 1500 bias = cid_start;
1485 bias = cid_start; 1501 __ cmpl(EDI, Immediate(cid_end - cid_start));
1486 __ cmpl(EDI, Immediate(cid_end - cid_start)); 1502 __ j(ABOVE, next_label); // Unsigned higher.
1487 __ j(ABOVE, next_label); // Unsigned higher.
1488 }
1489 } 1503 }
1490 // Do not use the code from the function, but let the code be patched so 1504 // Do not use the code from the function, but let the code be patched so
1491 // that we can record the outgoing edges to other code. 1505 // that we can record the outgoing edges to other code.
1492 const Function& function = *sorted[i].target; 1506 const Function& function = *targets[i].target;
1493 GenerateDartCall(deopt_id, token_index, 1507 GenerateDartCall(deopt_id, token_index,
1494 *StubCode::CallStaticFunction_entry(), 1508 *StubCode::CallStaticFunction_entry(),
1495 RawPcDescriptors::kOther, locs); 1509 RawPcDescriptors::kOther, locs);
1496 AddStaticCallTarget(function); 1510 AddStaticCallTarget(function);
1497 __ Drop(argument_count); 1511 __ Drop(argument_count);
1498 if (!is_last_check) { 1512 if (!is_last_check || add_megamorphic_call) {
1499 __ jmp(match_found); 1513 __ jmp(match_found);
1500 } 1514 }
1501 __ Bind(&next_test); 1515 __ Bind(&next_test);
1502 } 1516 }
1503 if (add_megamorphic_call) { 1517 if (add_megamorphic_call) {
1504 int try_index = CatchClauseNode::kInvalidTryIndex; 1518 const int try_index = CatchClauseNode::kInvalidTryIndex;
1505 EmitMegamorphicInstanceCall(ic_data, argument_count, deopt_id, token_index, 1519 EmitMegamorphicInstanceCall(function_name, arguments_descriptor,
1506 locs, try_index, argument_count); 1520 argument_count, deopt_id, token_index, locs,
1521 try_index);
1507 } 1522 }
1508 } 1523 }
1509 1524
1510 1525
1511 #undef __ 1526 #undef __
1512 #define __ compiler_->assembler()-> 1527 #define __ compiler_->assembler()->
1513 1528
1514 1529
1515 void ParallelMoveResolver::EmitMove(int index) { 1530 void ParallelMoveResolver::EmitMove(int index) {
1516 MoveOperands* move = moves_[index]; 1531 MoveOperands* move = moves_[index];
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 __ movups(reg, Address(ESP, 0)); 1782 __ movups(reg, Address(ESP, 0));
1768 __ addl(ESP, Immediate(kFpuRegisterSize)); 1783 __ addl(ESP, Immediate(kFpuRegisterSize));
1769 } 1784 }
1770 1785
1771 1786
1772 #undef __ 1787 #undef __
1773 1788
1774 } // namespace dart 1789 } // namespace dart
1775 1790
1776 #endif // defined TARGET_ARCH_IA32 1791 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698