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

Unified Diff: runtime/vm/flow_graph_optimizer.cc

Issue 13190014: Optimizes 'as' operation in similar way as 'instanceof': collect type feedback in unoptimized mode… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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_optimizer.h ('k') | runtime/vm/intermediate_language.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/flow_graph_optimizer.cc
===================================================================
--- runtime/vm/flow_graph_optimizer.cc (revision 20744)
+++ runtime/vm/flow_graph_optimizer.cc (working copy)
@@ -1835,6 +1835,45 @@
}
+void FlowGraphOptimizer::ReplaceWithTypeCast(InstanceCallInstr* call) {
+ ASSERT(Token::IsTypeCastOperator(call->token_kind()));
+ Definition* left = call->ArgumentAt(0);
+ Definition* instantiator = call->ArgumentAt(1);
+ Definition* type_args = call->ArgumentAt(2);
+ const AbstractType& type =
+ AbstractType::Cast(call->ArgumentAt(3)->AsConstant()->value());
+ ASSERT(!type.IsMalformed());
+ const ICData& unary_checks =
+ ICData::ZoneHandle(call->ic_data()->AsUnaryClassChecks());
+ if (unary_checks.NumberOfChecks() <= FLAG_max_polymorphic_checks) {
+ Bool& as_bool = Bool::ZoneHandle(InstanceOfAsBool(unary_checks, type));
+ if (as_bool.raw() == Bool::True().raw()) {
+ AddReceiverCheck(call);
+ // Remove the original push arguments.
+ for (intptr_t i = 0; i < call->ArgumentCount(); ++i) {
+ PushArgumentInstr* push = call->PushArgumentAt(i);
+ push->ReplaceUsesWith(push->value()->definition());
+ push->RemoveFromGraph();
+ }
+ // Remove call, replace it with 'left'.
+ call->ReplaceUsesWith(left);
+ call->RemoveFromGraph();
+ return;
+ }
+ }
+ const String& dst_name = String::ZoneHandle(
+ Symbols::New(Exceptions::kCastErrorDstName));
+ AssertAssignableInstr* assert_as =
+ new AssertAssignableInstr(call->token_pos(),
+ new Value(left),
+ new Value(instantiator),
+ new Value(type_args),
+ type,
+ dst_name);
+ ReplaceCall(call, assert_as);
+}
+
+
// Tries to optimize instance call by replacing it with a faster instruction
// (e.g, binary op, field load, ..).
void FlowGraphOptimizer::VisitInstanceCall(InstanceCallInstr* instr) {
@@ -1849,6 +1888,11 @@
return;
}
+ if (Token::IsTypeCastOperator(op_kind)) {
+ ReplaceWithTypeCast(instr);
+ return;
+ }
+
const ICData& unary_checks =
ICData::ZoneHandle(instr->ic_data()->AsUnaryClassChecks());
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/intermediate_language.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698