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

Unified Diff: runtime/vm/intermediate_language.cc

Issue 2379733002: Recognize and optimize a.runtimeType == b.runtimeType pattern. (Closed)
Patch Set: fix lint Created 4 years, 2 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/intermediate_language.h ('k') | runtime/vm/intrinsifier_arm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intermediate_language.cc
diff --git a/runtime/vm/intermediate_language.cc b/runtime/vm/intermediate_language.cc
index c3359f1f23fe46637922f5369b64a07f62f3c7f3..622151bc0271977cc16e0fcfb61d3d4afc92aade 100644
--- a/runtime/vm/intermediate_language.cc
+++ b/runtime/vm/intermediate_language.cc
@@ -3231,6 +3231,67 @@ void PolymorphicInstanceCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
#endif
+RawType* PolymorphicInstanceCallInstr::ComputeRuntimeType(
+ const ICData& ic_data) {
+ bool is_string = true;
+ bool is_integer = true;
+ bool is_double = true;
+
+ const intptr_t num_checks = ic_data.NumberOfChecks();
+ for (intptr_t i = 0; i < num_checks; i++) {
+ const intptr_t cid = ic_data.GetReceiverClassIdAt(i);
+ is_string = is_string && RawObject::IsStringClassId(cid);
+ is_integer = is_integer && RawObject::IsIntegerClassId(cid);
+ is_double = is_double && (cid == kDoubleCid);
+ }
+
+ if (is_string) {
+ return Type::StringType();
+ } else if (is_integer) {
+ return Type::IntType();
+ } else if (is_double) {
+ return Type::Double();
+ }
+
+ return Type::null();
+}
+
+
+Definition* PolymorphicInstanceCallInstr::Canonicalize(FlowGraph* flow_graph) {
+ if (!HasSingleRecognizedTarget() || with_checks()) {
+ return this;
+ }
+
+ const Function& target = Function::Handle(ic_data().GetTargetAt(0));
+ if (target.recognized_kind() == MethodRecognizer::kObjectRuntimeType) {
+ const AbstractType& type =
+ AbstractType::Handle(ComputeRuntimeType(ic_data()));
+ if (!type.IsNull()) {
+ return flow_graph->GetConstant(type);
+ }
+ }
+
+ return this;
+}
+
+
+Definition* StaticCallInstr::Canonicalize(FlowGraph* flow_graph) {
+ if (!FLAG_precompiled_mode) {
+ return this;
+ }
+
+ if (function().recognized_kind() == MethodRecognizer::kObjectRuntimeType) {
+ if (input_use_list() == NULL) {
+ // This function has only environment uses. In precompiled mode it is
+ // fine to remove it - because we will never deoptimize.
+ return flow_graph->constant_dead();
+ }
+ }
+
+ return this;
+}
+
+
LocationSummary* StaticCallInstr::MakeLocationSummary(Zone* zone,
bool optimizing) const {
return MakeCallSummary(zone);
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | runtime/vm/intrinsifier_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698