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

Side by Side Diff: runtime/vm/flow_graph_optimizer.cc

Issue 11746024: Optimize instanceof: if all results are true and tests can be done using class only replace instanc… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/flow_graph_optimizer.h" 5 #include "vm/flow_graph_optimizer.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/cha.h" 8 #include "vm/cha.h"
9 #include "vm/flow_graph_builder.h" 9 #include "vm/flow_graph_builder.h"
10 #include "vm/flow_graph_compiler.h" 10 #include "vm/flow_graph_compiler.h"
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 } 1242 }
1243 call->ReplaceWith(d2i_instr, current_iterator()); 1243 call->ReplaceWith(d2i_instr, current_iterator());
1244 RemovePushArguments(call); 1244 RemovePushArguments(call);
1245 return true; 1245 return true;
1246 } 1246 }
1247 1247
1248 return false; 1248 return false;
1249 } 1249 }
1250 1250
1251 1251
1252 // Returns a Boolean constant if all classes in ic_data yield the same type-test
1253 // result and the type tests do not depend on type arguments. Otherwise return
1254 // Bool::null().
1255 RawBool* FlowGraphOptimizer::InstanceOfAsBool(const ICData& ic_data,
1256 const AbstractType& type) const {
1257 ASSERT(ic_data.num_args_tested() == 1); // Unary checks only.
1258 if (!type.IsInstantiated()) return Bool::null();
regis 2013/01/03 23:35:26 I suppose there is no need to check that !type.IsM
srdjan 2013/01/04 00:10:55 Added it, just in case.
1259 const Class& type_class = Class::Handle(type.type_class());
1260 if (type_class.HasTypeArguments()) return Bool::null();
1261 const ClassTable& class_table = *Isolate::Current()->class_table();
1262 Bool& prev = Bool::Handle();
1263 Class& cls = Class::Handle();
1264 for (int i = 0; i < ic_data.NumberOfChecks(); i++) {
1265 cls = class_table.At(ic_data.GetReceiverClassIdAt(i));
1266 if (cls.HasTypeArguments()) return Bool::null();
1267 const bool is_subtype = cls.IsNullClass() ?
1268 false :
regis 2013/01/03 23:35:26 I do not think this is correct, because null is an
srdjan 2013/01/04 00:10:55 Fixed.
1269 cls.IsSubtypeOf(TypeArguments::Handle(),
1270 type_class,
1271 TypeArguments::Handle(),
1272 NULL);
1273 if (prev.IsNull()) {
1274 prev = is_subtype ? Bool::True() : Bool::False();
1275 } else {
1276 if (is_subtype != prev.value()) return Bool::null();
1277 }
1278 }
1279 return prev.raw();
1280 }
1281
1282
1252 // TODO(srdjan): Use ICData to check if always true or false. 1283 // TODO(srdjan): Use ICData to check if always true or false.
1253 void FlowGraphOptimizer::ReplaceWithInstanceOf(InstanceCallInstr* call) { 1284 void FlowGraphOptimizer::ReplaceWithInstanceOf(InstanceCallInstr* call) {
1254 ASSERT(Token::IsTypeTestOperator(call->token_kind())); 1285 ASSERT(Token::IsTypeTestOperator(call->token_kind()));
1255 Value* left_val = call->ArgumentAt(0)->value(); 1286 Value* left_val = call->ArgumentAt(0)->value();
1256 Value* instantiator_val = call->ArgumentAt(1)->value(); 1287 Value* instantiator_val = call->ArgumentAt(1)->value();
1257 Value* type_args_val = call->ArgumentAt(2)->value(); 1288 Value* type_args_val = call->ArgumentAt(2)->value();
1258 const AbstractType& type = 1289 const AbstractType& type =
1259 AbstractType::Cast(call->ArgumentAt(3)->value()->BoundConstant()); 1290 AbstractType::Cast(call->ArgumentAt(3)->value()->BoundConstant());
1260 const Bool& negate = 1291 const Bool& negate =
1261 Bool::Cast(call->ArgumentAt(4)->value()->BoundConstant()); 1292 Bool::Cast(call->ArgumentAt(4)->value()->BoundConstant());
1293 const ICData& unary_checks =
1294 ICData::ZoneHandle(call->ic_data()->AsUnaryClassChecks());
1295 if (unary_checks.NumberOfChecks() <= FLAG_max_polymorphic_checks) {
1296 Bool& as_bool = Bool::ZoneHandle(InstanceOfAsBool(unary_checks, type));
1297 if (!as_bool.IsNull()) {
1298 AddCheckClass(call, left_val->Copy());
1299 if (negate.value()) {
1300 as_bool = as_bool.value() ? Bool::False() : Bool::True();
1301 }
1302 ConstantInstr* bool_const = new ConstantInstr(as_bool);
1303 call->ReplaceWith(bool_const, current_iterator());
1304 RemovePushArguments(call);
1305 return;
1306 }
1307 }
1262 InstanceOfInstr* instance_of = 1308 InstanceOfInstr* instance_of =
1263 new InstanceOfInstr(call->token_pos(), 1309 new InstanceOfInstr(call->token_pos(),
1264 left_val, 1310 left_val,
1265 instantiator_val, 1311 instantiator_val,
1266 type_args_val, 1312 type_args_val,
1267 type, 1313 type,
1268 negate.value()); 1314 negate.value());
1269 call->ReplaceWith(instance_of, current_iterator()); 1315 call->ReplaceWith(instance_of, current_iterator());
1270 RemovePushArguments(call); 1316 RemovePushArguments(call);
1271 } 1317 }
(...skipping 3105 matching lines...) Expand 10 before | Expand all | Expand 10 after
4377 4423
4378 if (FLAG_trace_constant_propagation) { 4424 if (FLAG_trace_constant_propagation) {
4379 OS::Print("\n==== After constant propagation ====\n"); 4425 OS::Print("\n==== After constant propagation ====\n");
4380 FlowGraphPrinter printer(*graph_); 4426 FlowGraphPrinter printer(*graph_);
4381 printer.PrintBlocks(); 4427 printer.PrintBlocks();
4382 } 4428 }
4383 } 4429 }
4384 4430
4385 4431
4386 } // namespace dart 4432 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698