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

Side by Side Diff: runtime/vm/flow_graph_compiler_mips.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_ia32.cc ('k') | runtime/vm/flow_graph_compiler_x64.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_MIPS. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_MIPS.
6 #if defined(TARGET_ARCH_MIPS) 6 #if defined(TARGET_ARCH_MIPS)
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 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 __ Comment("InstanceCall"); 1218 __ Comment("InstanceCall");
1219 __ LoadUniqueObject(S5, ic_data); 1219 __ LoadUniqueObject(S5, ic_data);
1220 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, 1220 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall,
1221 locs); 1221 locs);
1222 __ Comment("InstanceCall return"); 1222 __ Comment("InstanceCall return");
1223 __ Drop(argument_count); 1223 __ Drop(argument_count);
1224 } 1224 }
1225 1225
1226 1226
1227 void FlowGraphCompiler::EmitMegamorphicInstanceCall( 1227 void FlowGraphCompiler::EmitMegamorphicInstanceCall(
1228 const ICData& ic_data, 1228 const String& name,
1229 const Array& arguments_descriptor,
1229 intptr_t argument_count, 1230 intptr_t argument_count,
1230 intptr_t deopt_id, 1231 intptr_t deopt_id,
1231 TokenPosition token_pos, 1232 TokenPosition token_pos,
1232 LocationSummary* locs, 1233 LocationSummary* locs,
1233 intptr_t try_index, 1234 intptr_t try_index,
1234 intptr_t slow_path_argument_count) { 1235 intptr_t slow_path_argument_count) {
1235 const String& name = String::Handle(zone(), ic_data.target_name());
1236 const Array& arguments_descriptor =
1237 Array::ZoneHandle(zone(), ic_data.arguments_descriptor());
1238 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); 1236 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0));
1239 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( 1237 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle(
1240 zone(), 1238 zone(),
1241 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); 1239 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor));
1242 1240
1243 __ Comment("MegamorphicCall"); 1241 __ Comment("MegamorphicCall");
1244 // Load receiver into T0, 1242 // Load receiver into T0,
1245 __ lw(T0, Address(SP, (argument_count - 1) * kWordSize)); 1243 __ lw(T0, Address(SP, (argument_count - 1) * kWordSize));
1246 __ LoadObject(S5, cache); 1244 __ LoadObject(S5, cache);
1247 __ lw(T9, Address(THR, Thread::megamorphic_call_checked_entry_offset())); 1245 __ lw(T9, Address(THR, Thread::megamorphic_call_checked_entry_offset()));
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 // TODO(zerny): clobber non-live temporary FPU registers. 1499 // TODO(zerny): clobber non-live temporary FPU registers.
1502 if (tmp.IsRegister() && 1500 if (tmp.IsRegister() &&
1503 !locs->live_registers()->ContainsRegister(tmp.reg())) { 1501 !locs->live_registers()->ContainsRegister(tmp.reg())) {
1504 __ LoadImmediate(tmp.reg(), 0xf7); 1502 __ LoadImmediate(tmp.reg(), 0xf7);
1505 } 1503 }
1506 } 1504 }
1507 } 1505 }
1508 #endif 1506 #endif
1509 1507
1510 1508
1511 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data, 1509 void FlowGraphCompiler::EmitTestAndCallLoadReceiver(
1512 intptr_t argument_count, 1510 intptr_t argument_count,
1513 const Array& argument_names, 1511 const Array& arguments_descriptor) {
1514 Label* failed,
1515 Label* match_found,
1516 intptr_t deopt_id,
1517 TokenPosition token_index,
1518 LocationSummary* locs,
1519 bool complete,
1520 intptr_t total_ic_calls) {
1521 ASSERT(is_optimizing());
1522 __ Comment("EmitTestAndCall"); 1512 __ Comment("EmitTestAndCall");
1523 const Array& arguments_descriptor = Array::ZoneHandle(
1524 zone(), ArgumentsDescriptor::New(argument_count, argument_names));
1525
1526 // Load receiver into T0. 1513 // Load receiver into T0.
1527 __ LoadFromOffset(T0, SP, (argument_count - 1) * kWordSize); 1514 __ LoadFromOffset(T0, SP, (argument_count - 1) * kWordSize);
1528 __ LoadObject(S4, arguments_descriptor); 1515 __ LoadObject(S4, arguments_descriptor);
1516 }
1529 1517
1530 const bool kFirstCheckIsSmi = ic_data.GetReceiverClassIdAt(0) == kSmiCid;
1531 const intptr_t num_checks = ic_data.NumberOfChecks();
1532 1518
1533 ASSERT(!ic_data.IsNull() && (num_checks > 0)); 1519 void FlowGraphCompiler::EmitTestAndCallSmiBranch(Label* label, bool if_smi) {
1534 1520 __ andi(CMPRES1, T0, Immediate(kSmiTagMask));
1535 Label after_smi_test; 1521 if (if_smi) {
1536 if (kFirstCheckIsSmi) { 1522 // Jump if receiver is Smi.
1537 __ andi(CMPRES1, T0, Immediate(kSmiTagMask)); 1523 __ beq(CMPRES1, ZR, label);
1524 } else {
1538 // Jump if receiver is not Smi. 1525 // Jump if receiver is not Smi.
1539 if (num_checks == 1) { 1526 __ bne(CMPRES1, ZR, label);
1540 __ bne(CMPRES1, ZR, failed);
1541 } else {
1542 __ bne(CMPRES1, ZR, &after_smi_test);
1543 }
1544 // Do not use the code from the function, but let the code be patched so
1545 // that we can record the outgoing edges to other code.
1546 const Function& function =
1547 Function::ZoneHandle(zone(), ic_data.GetTargetAt(0));
1548 GenerateStaticDartCall(deopt_id, token_index,
1549 *StubCode::CallStaticFunction_entry(),
1550 RawPcDescriptors::kOther, locs, function);
1551 __ Drop(argument_count);
1552 if (num_checks > 1) {
1553 __ b(match_found);
1554 }
1555 } else {
1556 // Receiver is Smi, but Smi is not a valid class therefore fail.
1557 // (Smi class must be first in the list).
1558 if (!complete) {
1559 __ andi(CMPRES1, T0, Immediate(kSmiTagMask));
1560 __ beq(CMPRES1, ZR, failed);
1561 }
1562 }
1563
1564 __ Bind(&after_smi_test);
1565
1566 ASSERT(!ic_data.IsNull() && (num_checks > 0));
1567 GrowableArray<CidRangeTarget> sorted(num_checks);
1568 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true);
1569
1570 const intptr_t sorted_len = sorted.length();
1571 // If sorted_len is 0 then only a Smi check was needed; the Smi check above
1572 // will fail if there was only one check and receiver is not Smi.
1573 if (sorted_len == 0) return;
1574
1575 // Value is not Smi,
1576 __ LoadClassId(T2, T0);
1577
1578 bool add_megamorphic_call = false;
1579 int bias = 0;
1580
1581 for (intptr_t i = 0; i < sorted_len; i++) {
1582 const bool is_last_check = (i == (sorted_len - 1));
1583 int cid_start = sorted[i].cid_start;
1584 int cid_end = sorted[i].cid_end;
1585 int count = sorted[i].count;
1586 if (!is_last_check && !complete && count < (total_ic_calls >> 5)) {
1587 // This case is hit too rarely to be worth writing class-id checks inline
1588 // for.
1589 add_megamorphic_call = true;
1590 break;
1591 }
1592 ASSERT(cid_start > kSmiCid || cid_end < kSmiCid);
1593 Label next_test;
1594 Condition no_match;
1595 if (!complete || !is_last_check) {
1596 Label* next_label = is_last_check ? failed : &next_test;
1597 if (cid_start == cid_end) {
1598 __ BranchNotEqual(T2, Immediate(cid_start - bias), next_label);
1599 } else {
1600 __ AddImmediate(T2, T2, bias - cid_start);
1601 bias = cid_start;
1602 // TODO(erikcorry): We should use sltiu instead of the temporary TMP if
1603 // the range is small enough.
1604 __ LoadImmediate(TMP, cid_end - cid_end);
1605 // Reverse comparison so we get 1 if biased cid > tmp ie cid is out of
1606 // range.
1607 __ sltu(TMP, TMP, T2);
1608 __ bne(TMP, ZR, next_label);
1609 }
1610 }
1611 // Do not use the code from the function, but let the code be patched so
1612 // that we can record the outgoing edges to other code.
1613 const Function& function = *sorted[i].target;
1614 GenerateStaticDartCall(deopt_id, token_index,
1615 *StubCode::CallStaticFunction_entry(),
1616 RawPcDescriptors::kOther, locs, function);
1617 __ Drop(argument_count);
1618 if (!is_last_check) {
1619 __ b(match_found);
1620 }
1621 __ Bind(&next_test);
1622 }
1623 if (add_megamorphic_call) {
1624 int try_index = CatchClauseNode::kInvalidTryIndex;
1625 EmitMegamorphicInstanceCall(ic_data, argument_count, deopt_id, token_index,
1626 locs, try_index, argument_count);
1627 } 1527 }
1628 } 1528 }
1629 1529
1630 1530
1531 void FlowGraphCompiler::EmitTestAndCallLoadCid() {
1532 __ LoadClassId(T2, T0);
1533 }
1534
1535
1536 int FlowGraphCompiler::EmitTestAndCallCheckCid(Label* next_label,
1537 const CidRangeTarget& target,
1538 int bias) {
1539 intptr_t cid_start = target.cid_start;
1540 intptr_t cid_end = target.cid_end;
1541 if (cid_start == cid_end) {
1542 __ BranchNotEqual(T2, Immediate(cid_start - bias), next_label);
1543 } else {
1544 __ AddImmediate(T2, T2, bias - cid_start);
1545 bias = cid_start;
1546 // TODO(erikcorry): We should use sltiu instead of the temporary TMP if
1547 // the range is small enough.
1548 __ LoadImmediate(TMP, cid_end - cid_end);
1549 // Reverse comparison so we get 1 if biased cid > tmp ie cid is out of
1550 // range.
1551 __ sltu(TMP, TMP, T2);
1552 __ bne(TMP, ZR, next_label);
1553 }
1554 return bias;
1555 }
1556
1557
1558 void FlowGraphCompiler::EmitTestAndCallGotoMatchFound(Label* match_found) {
1559 __ b(match_found);
1560 }
1561
1562
1631 #undef __ 1563 #undef __
1632 #define __ compiler_->assembler()-> 1564 #define __ compiler_->assembler()->
1633 1565
1634 1566
1635 void ParallelMoveResolver::EmitMove(int index) { 1567 void ParallelMoveResolver::EmitMove(int index) {
1636 MoveOperands* move = moves_[index]; 1568 MoveOperands* move = moves_[index];
1637 const Location source = move->src(); 1569 const Location source = move->src();
1638 const Location destination = move->dest(); 1570 const Location destination = move->dest();
1639 __ Comment("ParallelMoveResolver::EmitMove"); 1571 __ Comment("ParallelMoveResolver::EmitMove");
1640 1572
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 __ AddImmediate(SP, kDoubleSize); 1796 __ AddImmediate(SP, kDoubleSize);
1865 } 1797 }
1866 1798
1867 1799
1868 #undef __ 1800 #undef __
1869 1801
1870 1802
1871 } // namespace dart 1803 } // namespace dart
1872 1804
1873 #endif // defined TARGET_ARCH_MIPS 1805 #endif // defined TARGET_ARCH_MIPS
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_compiler_ia32.cc ('k') | runtime/vm/flow_graph_compiler_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698