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

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() || type.IsMalformed()) return Bool::null();
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 // TODO(regis): Fix Class::TypeTest to support NullClass.
regis 2013/01/04 01:39:16 I am pretty sure that Class::TypeTest is supportin
srdjan 2013/01/04 21:10:25 Removed TODO. Discussed off-line changes to Class:
1268 bool is_subtype = false;
1269 if (cls.IsNullClass()) {
1270 is_subtype = type_class.IsDynamicClass() || type_class.IsObjectClass();
1271 } else {
1272 is_subtype = cls.IsSubtypeOf(TypeArguments::Handle(),
1273 type_class,
1274 TypeArguments::Handle(),
1275 NULL);
1276 }
1277 if (prev.IsNull()) {
1278 prev = is_subtype ? Bool::True() : Bool::False();
1279 } else {
1280 if (is_subtype != prev.value()) return Bool::null();
1281 }
1282 }
1283 return prev.raw();
1284 }
1285
1286
1252 // TODO(srdjan): Use ICData to check if always true or false. 1287 // TODO(srdjan): Use ICData to check if always true or false.
1253 void FlowGraphOptimizer::ReplaceWithInstanceOf(InstanceCallInstr* call) { 1288 void FlowGraphOptimizer::ReplaceWithInstanceOf(InstanceCallInstr* call) {
1254 ASSERT(Token::IsTypeTestOperator(call->token_kind())); 1289 ASSERT(Token::IsTypeTestOperator(call->token_kind()));
1255 Value* left_val = call->ArgumentAt(0)->value(); 1290 Value* left_val = call->ArgumentAt(0)->value();
1256 Value* instantiator_val = call->ArgumentAt(1)->value(); 1291 Value* instantiator_val = call->ArgumentAt(1)->value();
1257 Value* type_args_val = call->ArgumentAt(2)->value(); 1292 Value* type_args_val = call->ArgumentAt(2)->value();
1258 const AbstractType& type = 1293 const AbstractType& type =
1259 AbstractType::Cast(call->ArgumentAt(3)->value()->BoundConstant()); 1294 AbstractType::Cast(call->ArgumentAt(3)->value()->BoundConstant());
1260 const Bool& negate = 1295 const Bool& negate =
Florian Schneider 2013/01/04 11:35:41 Maybe just bool negate = Bool::Cast(call->Argum
srdjan 2013/01/04 21:10:25 Done.
1261 Bool::Cast(call->ArgumentAt(4)->value()->BoundConstant()); 1296 Bool::Cast(call->ArgumentAt(4)->value()->BoundConstant());
1297 const ICData& unary_checks =
1298 ICData::ZoneHandle(call->ic_data()->AsUnaryClassChecks());
1299 if (unary_checks.NumberOfChecks() <= FLAG_max_polymorphic_checks) {
1300 Bool& as_bool = Bool::ZoneHandle(InstanceOfAsBool(unary_checks, type));
1301 if (!as_bool.IsNull()) {
1302 AddCheckClass(call, left_val->Copy());
1303 if (negate.value()) {
1304 as_bool = as_bool.value() ? Bool::False() : Bool::True();
1305 }
1306 ConstantInstr* bool_const = new ConstantInstr(as_bool);
1307 call->ReplaceWith(bool_const, current_iterator());
1308 RemovePushArguments(call);
1309 return;
1310 }
1311 }
1262 InstanceOfInstr* instance_of = 1312 InstanceOfInstr* instance_of =
1263 new InstanceOfInstr(call->token_pos(), 1313 new InstanceOfInstr(call->token_pos(),
1264 left_val, 1314 left_val,
1265 instantiator_val, 1315 instantiator_val,
1266 type_args_val, 1316 type_args_val,
1267 type, 1317 type,
1268 negate.value()); 1318 negate.value());
1269 call->ReplaceWith(instance_of, current_iterator()); 1319 call->ReplaceWith(instance_of, current_iterator());
1270 RemovePushArguments(call); 1320 RemovePushArguments(call);
1271 } 1321 }
(...skipping 3105 matching lines...) Expand 10 before | Expand all | Expand 10 after
4377 4427
4378 if (FLAG_trace_constant_propagation) { 4428 if (FLAG_trace_constant_propagation) {
4379 OS::Print("\n==== After constant propagation ====\n"); 4429 OS::Print("\n==== After constant propagation ====\n");
4380 FlowGraphPrinter printer(*graph_); 4430 FlowGraphPrinter printer(*graph_);
4381 printer.PrintBlocks(); 4431 printer.PrintBlocks();
4382 } 4432 }
4383 } 4433 }
4384 4434
4385 4435
4386 } // namespace dart 4436 } // 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