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

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: 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_arm64.cc ('k') | runtime/vm/flow_graph_compiler_mips.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_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 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 if (is_optimizing()) { 1091 if (is_optimizing()) {
1092 AddDeoptIndexAtCall(deopt_id_after); 1092 AddDeoptIndexAtCall(deopt_id_after);
1093 } else { 1093 } else {
1094 // Add deoptimization continuation point after the call and before the 1094 // Add deoptimization continuation point after the call and before the
1095 // arguments are removed. 1095 // arguments are removed.
1096 AddCurrentDescriptor(RawPcDescriptors::kDeopt, deopt_id_after, token_pos); 1096 AddCurrentDescriptor(RawPcDescriptors::kDeopt, deopt_id_after, token_pos);
1097 } 1097 }
1098 } 1098 }
1099 1099
1100 1100
1101 void FlowGraphCompiler::GenerateStaticDartCall(intptr_t deopt_id,
1102 TokenPosition token_pos,
1103 const StubEntry& stub_entry,
1104 RawPcDescriptors::Kind kind,
1105 LocationSummary* locs,
1106 const Function& target) {
1107 GenerateDartCall(deopt_id, token_pos, stub_entry, kind, locs);
1108 AddStaticCallTarget(target);
1109 }
1110
1111
1101 void FlowGraphCompiler::GenerateRuntimeCall(TokenPosition token_pos, 1112 void FlowGraphCompiler::GenerateRuntimeCall(TokenPosition token_pos,
1102 intptr_t deopt_id, 1113 intptr_t deopt_id,
1103 const RuntimeEntry& entry, 1114 const RuntimeEntry& entry,
1104 intptr_t argument_count, 1115 intptr_t argument_count,
1105 LocationSummary* locs) { 1116 LocationSummary* locs) {
1106 __ CallRuntime(entry, argument_count); 1117 __ CallRuntime(entry, argument_count);
1107 EmitCallsiteMetaData(token_pos, deopt_id, RawPcDescriptors::kOther, locs); 1118 EmitCallsiteMetaData(token_pos, deopt_id, RawPcDescriptors::kOther, locs);
1108 if (deopt_id != Thread::kNoDeoptId) { 1119 if (deopt_id != Thread::kNoDeoptId) {
1109 // Marks either the continuation point in unoptimized code or the 1120 // Marks either the continuation point in unoptimized code or the
1110 // deoptimization point in optimized code, after call. 1121 // deoptimization point in optimized code, after call.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 LocationSummary* locs) { 1187 LocationSummary* locs) {
1177 ASSERT(Array::Handle(ic_data.arguments_descriptor()).Length() > 0); 1188 ASSERT(Array::Handle(ic_data.arguments_descriptor()).Length() > 0);
1178 __ LoadObject(ECX, ic_data); 1189 __ LoadObject(ECX, ic_data);
1179 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, 1190 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall,
1180 locs); 1191 locs);
1181 __ Drop(argument_count); 1192 __ Drop(argument_count);
1182 } 1193 }
1183 1194
1184 1195
1185 void FlowGraphCompiler::EmitMegamorphicInstanceCall( 1196 void FlowGraphCompiler::EmitMegamorphicInstanceCall(
1186 const ICData& ic_data, 1197 const String& name,
1198 const Array& arguments_descriptor,
1187 intptr_t argument_count, 1199 intptr_t argument_count,
1188 intptr_t deopt_id, 1200 intptr_t deopt_id,
1189 TokenPosition token_pos, 1201 TokenPosition token_pos,
1190 LocationSummary* locs, 1202 LocationSummary* locs,
1191 intptr_t try_index, 1203 intptr_t try_index,
1192 intptr_t slow_path_argument_count) { 1204 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)); 1205 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0));
1197 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( 1206 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle(
1198 zone(), 1207 zone(),
1199 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); 1208 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor));
1200 1209
1201 __ Comment("MegamorphicCall"); 1210 __ Comment("MegamorphicCall");
1202 // Load receiver into EBX. 1211 // Load receiver into EBX.
1203 __ movl(EBX, Address(ESP, (argument_count - 1) * kWordSize)); 1212 __ movl(EBX, Address(ESP, (argument_count - 1) * kWordSize));
1204 __ LoadObject(ECX, cache); 1213 __ LoadObject(ECX, cache);
1205 __ call(Address(THR, Thread::megamorphic_call_checked_entry_offset())); 1214 __ 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. 1394 // TODO(zerny): clobber non-live temporary FPU registers.
1386 if (tmp.IsRegister() && 1395 if (tmp.IsRegister() &&
1387 !locs->live_registers()->ContainsRegister(tmp.reg())) { 1396 !locs->live_registers()->ContainsRegister(tmp.reg())) {
1388 __ movl(tmp.reg(), Immediate(0xf7)); 1397 __ movl(tmp.reg(), Immediate(0xf7));
1389 } 1398 }
1390 } 1399 }
1391 } 1400 }
1392 #endif 1401 #endif
1393 1402
1394 1403
1395 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data, 1404 void FlowGraphCompiler::EmitTestAndCallLoadReceiver(
1396 intptr_t argument_count, 1405 intptr_t argument_count,
1397 const Array& argument_names, 1406 const Array& arguments_descriptor) {
1398 Label* failed,
1399 Label* match_found,
1400 intptr_t deopt_id,
1401 TokenPosition token_index,
1402 LocationSummary* locs,
1403 bool complete,
1404 intptr_t total_ic_calls) {
1405 ASSERT(is_optimizing());
1406 ASSERT(!complete);
1407 __ Comment("EmitTestAndCall"); 1407 __ Comment("EmitTestAndCall");
1408 const Array& arguments_descriptor = Array::ZoneHandle(
1409 zone(), ArgumentsDescriptor::New(argument_count, argument_names));
1410 // Load receiver into EAX. 1408 // Load receiver into EAX.
1411 __ movl(EAX, Address(ESP, (argument_count - 1) * kWordSize)); 1409 __ movl(EAX, Address(ESP, (argument_count - 1) * kWordSize));
1412 __ LoadObject(EDX, arguments_descriptor); 1410 __ LoadObject(EDX, arguments_descriptor);
1413
1414 const bool kFirstCheckIsSmi = ic_data.GetReceiverClassIdAt(0) == kSmiCid;
1415 const intptr_t num_checks = ic_data.NumberOfChecks();
1416
1417 ASSERT(!ic_data.IsNull() && (num_checks > 0));
1418
1419 Label after_smi_test;
1420 __ testl(EAX, Immediate(kSmiTagMask));
1421 if (kFirstCheckIsSmi) {
1422 // Jump if receiver is not Smi.
1423 if (num_checks == 1) {
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
1429 // that we can record the outgoing edges to other code.
1430 GenerateDartCall(deopt_id, token_index,
1431 *StubCode::CallStaticFunction_entry(),
1432 RawPcDescriptors::kOther, locs);
1433 const Function& function =
1434 Function::ZoneHandle(zone(), ic_data.GetTargetAt(0));
1435 AddStaticCallTarget(function);
1436 __ Drop(argument_count);
1437 if (num_checks > 1) {
1438 __ jmp(match_found);
1439 }
1440 } else {
1441 // 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);
1444 }
1445 __ Bind(&after_smi_test);
1446
1447 ASSERT(!ic_data.IsNull() && (num_checks > 0));
1448 GrowableArray<CidRangeTarget> sorted(num_checks);
1449 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true);
1450
1451 const intptr_t sorted_len = sorted.length();
1452 // If sorted_len is 0 then only a Smi check was needed; the Smi check above
1453 // will fail if there was only one check and receiver is not Smi.
1454 if (sorted_len == 0) return;
1455
1456 // Value is not Smi,
1457 __ LoadClassId(EDI, EAX);
1458
1459 bool add_megamorphic_call = false;
1460 const int kMaxImmediateInInstruction = 127;
1461 int bias =
1462 ComputeGoodBiasForCidComparison(sorted, kMaxImmediateInInstruction);
1463 if (bias != 0) __ addl(EDI, Immediate(-bias));
1464
1465 for (intptr_t i = 0; i < sorted_len; i++) {
1466 const bool is_last_check = (i == (sorted_len - 1));
1467 int cid_start = sorted[i].cid_start;
1468 int cid_end = sorted[i].cid_end;
1469 int count = sorted[i].count;
1470 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
1472 // for.
1473 add_megamorphic_call = true;
1474 break;
1475 }
1476 ASSERT(cid_start > kSmiCid || cid_end < kSmiCid);
1477 Label next_test;
1478 if (!complete || !is_last_check) {
1479 Label* next_label = is_last_check ? failed : &next_test;
1480 if (cid_start == cid_end) {
1481 __ cmpl(EDI, Immediate(cid_start - bias));
1482 __ j(NOT_EQUAL, next_label);
1483 } else {
1484 __ addl(EDI, Immediate(bias - cid_start));
1485 bias = cid_start;
1486 __ cmpl(EDI, Immediate(cid_end - cid_start));
1487 __ j(ABOVE, next_label); // Unsigned higher.
1488 }
1489 }
1490 // 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.
1492 const Function& function = *sorted[i].target;
1493 GenerateDartCall(deopt_id, token_index,
1494 *StubCode::CallStaticFunction_entry(),
1495 RawPcDescriptors::kOther, locs);
1496 AddStaticCallTarget(function);
1497 __ Drop(argument_count);
1498 if (!is_last_check) {
1499 __ jmp(match_found);
1500 }
1501 __ Bind(&next_test);
1502 }
1503 if (add_megamorphic_call) {
1504 int try_index = CatchClauseNode::kInvalidTryIndex;
1505 EmitMegamorphicInstanceCall(ic_data, argument_count, deopt_id, token_index,
1506 locs, try_index, argument_count);
1507 }
1508 } 1411 }
1509 1412
1510 1413
1414 void FlowGraphCompiler::EmitTestAndCallSmiBranch(Label* label, bool if_smi) {
1415 __ testl(EAX, Immediate(kSmiTagMask));
1416 // Jump if receiver is (not) Smi.
1417 __ j(if_smi ? ZERO : NOT_ZERO, label);
1418 }
1419
1420
1421 void FlowGraphCompiler::EmitTestAndCallLoadCid() {
1422 __ LoadClassId(EDI, EAX);
1423 }
1424
1425
1426 int FlowGraphCompiler::EmitTestAndCallCheckCid(Label* next_label,
1427 const CidRangeTarget& target,
1428 int bias) {
1429 intptr_t cid_start = target.cid_start;
1430 intptr_t cid_end = target.cid_end;
1431 if (cid_start == cid_end) {
1432 __ cmpl(EDI, Immediate(cid_start - bias));
1433 __ j(NOT_EQUAL, next_label);
1434 } else {
1435 __ addl(EDI, Immediate(bias - cid_start));
1436 bias = cid_start;
1437 __ cmpl(EDI, Immediate(cid_end - cid_start));
1438 __ j(ABOVE, next_label); // Unsigned higher.
1439 }
1440 return bias;
1441 }
1442
1443
1511 #undef __ 1444 #undef __
1512 #define __ compiler_->assembler()-> 1445 #define __ compiler_->assembler()->
1513 1446
1514 1447
1515 void ParallelMoveResolver::EmitMove(int index) { 1448 void ParallelMoveResolver::EmitMove(int index) {
1516 MoveOperands* move = moves_[index]; 1449 MoveOperands* move = moves_[index];
1517 const Location source = move->src(); 1450 const Location source = move->src();
1518 const Location destination = move->dest(); 1451 const Location destination = move->dest();
1519 1452
1520 if (source.IsRegister()) { 1453 if (source.IsRegister()) {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 __ movups(reg, Address(ESP, 0)); 1700 __ movups(reg, Address(ESP, 0));
1768 __ addl(ESP, Immediate(kFpuRegisterSize)); 1701 __ addl(ESP, Immediate(kFpuRegisterSize));
1769 } 1702 }
1770 1703
1771 1704
1772 #undef __ 1705 #undef __
1773 1706
1774 } // namespace dart 1707 } // namespace dart
1775 1708
1776 #endif // defined TARGET_ARCH_IA32 1709 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_compiler_arm64.cc ('k') | runtime/vm/flow_graph_compiler_mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698