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

Unified Diff: runtime/vm/flow_graph_compiler_arm64.cc

Issue 1184093004: Faster checks in polymorphic instance calls if Smi-s are involved (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: m Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/flow_graph_compiler_arm.cc ('k') | runtime/vm/flow_graph_compiler_ia32.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/flow_graph_compiler_arm64.cc
diff --git a/runtime/vm/flow_graph_compiler_arm64.cc b/runtime/vm/flow_graph_compiler_arm64.cc
index 913cd2abd0000b764c0e411696b3f2f949124fe5..e2b8308c2fedb29bbbcd1ce5a9d6cee3f4e3b65f 100644
--- a/runtime/vm/flow_graph_compiler_arm64.cc
+++ b/runtime/vm/flow_graph_compiler_arm64.cc
@@ -1476,33 +1476,77 @@ void FlowGraphCompiler::ClobberDeadTempRegisters(LocationSummary* locs) {
void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data,
- Register class_id_reg,
intptr_t argument_count,
const Array& argument_names,
- Label* deopt,
+ Label* failed,
+ Label* match_found,
intptr_t deopt_id,
intptr_t token_index,
LocationSummary* locs) {
ASSERT(is_optimizing());
- ASSERT(!ic_data.IsNull() && (ic_data.NumberOfUsedChecks() > 0));
- Label match_found;
- const intptr_t len = ic_data.NumberOfChecks();
- GrowableArray<CidTarget> sorted(len);
- SortICDataByCount(ic_data, &sorted, /* drop_smi = */ false);
- ASSERT(class_id_reg != R4);
- ASSERT(len > 0); // Why bother otherwise.
+
+ __ Comment("EmitTestAndCall");
const Array& arguments_descriptor =
Array::ZoneHandle(ArgumentsDescriptor::New(argument_count,
argument_names));
StubCode* stub_code = isolate()->stub_code();
+ // Load receiver into R0.
+ __ LoadFromOffset(R0, SP, (argument_count - 1) * kWordSize, PP);
__ LoadObject(R4, arguments_descriptor, PP);
- for (intptr_t i = 0; i < len; i++) {
- const bool is_last_check = (i == (len - 1));
+
+ const bool kFirstCheckIsSmi = ic_data.GetReceiverClassIdAt(0) == kSmiCid;
+ const intptr_t kNumChecks = ic_data.NumberOfChecks();
+
+ ASSERT(!ic_data.IsNull() && (kNumChecks > 0));
+
+ Label after_smi_test;
+ __ tsti(R0, Immediate(kSmiTagMask));
+ if (kFirstCheckIsSmi) {
+ // Jump if receiver is not Smi.
+ if (kNumChecks == 1) {
+ __ b(failed, NE);
+ } else {
+ __ b(&after_smi_test, NE);
+ }
+ // Do not use the code from the function, but let the code be patched so
+ // that we can record the outgoing edges to other code.
+ GenerateDartCall(deopt_id,
+ token_index,
+ &stub_code->CallStaticFunctionLabel(),
+ RawPcDescriptors::kOther,
+ locs);
+ const Function& function = Function::Handle(ic_data.GetTargetAt(0));
+ AddStaticCallTarget(function);
+ __ Drop(argument_count);
+ if (kNumChecks > 1) {
+ __ b(match_found);
+ }
+ } else {
+ // Receiver is Smi, but Smi is not a valid class therefore fail.
+ // (Smi class must be first in the list).
+ __ b(failed, EQ);
+ }
+ __ Bind(&after_smi_test);
+
+ ASSERT(!ic_data.IsNull() && (kNumChecks > 0));
+ GrowableArray<CidTarget> sorted(kNumChecks);
+ SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true);
+
+ // Value is not Smi,
+ const intptr_t kSortedLen = sorted.length();
+ // If kSortedLen is 0 then only a Smi check was needed; the Smi check above
+ // will fail if there was only one check and receiver is not Smi.
+ if (kSortedLen == 0) return;
+
+ __ LoadClassId(R2, R0, PP);
+ for (intptr_t i = 0; i < kSortedLen; i++) {
+ const bool kIsLastCheck = (i == (kSortedLen - 1));
+ ASSERT(sorted[i].cid != kSmiCid);
Label next_test;
- __ CompareImmediate(class_id_reg, sorted[i].cid, PP);
- if (is_last_check) {
- __ b(deopt, NE);
+ __ CompareImmediate(R2, sorted[i].cid, PP);
+ if (kIsLastCheck) {
+ __ b(failed, NE);
} else {
__ b(&next_test, NE);
}
@@ -1516,12 +1560,11 @@ void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data,
const Function& function = *sorted[i].target;
AddStaticCallTarget(function);
__ Drop(argument_count);
- if (!is_last_check) {
- __ b(&match_found);
+ if (!kIsLastCheck) {
+ __ b(match_found);
}
__ Bind(&next_test);
}
- __ Bind(&match_found);
}
« no previous file with comments | « runtime/vm/flow_graph_compiler_arm.cc ('k') | runtime/vm/flow_graph_compiler_ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698