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

Unified Diff: runtime/vm/intermediate_language.cc

Issue 2379733002: Recognize and optimize a.runtimeType == b.runtimeType pattern. (Closed)
Patch Set: port to all arch, make AOT opt non-speculative 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
Index: runtime/vm/intermediate_language.cc
diff --git a/runtime/vm/intermediate_language.cc b/runtime/vm/intermediate_language.cc
index ab7c878e846a2b9d1be3bdb19ac5608f1ed6a5f1..e343eaab4a1e761bf6ed22302260877d06475947 100644
--- a/runtime/vm/intermediate_language.cc
+++ b/runtime/vm/intermediate_language.cc
@@ -3226,6 +3226,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++) {
Florian Schneider 2016/10/06 18:03:19 I'd rather use the propagated type of the receiver
Vyacheslav Egorov (Google) 2016/10/24 20:23:03 This is also called from a place where type propag
+ 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);

Powered by Google App Engine
This is Rietveld 408576698