Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 elements->set_result_cid(kArrayCid); | 411 elements->set_result_cid(kArrayCid); |
| 412 InsertBefore(call, elements, NULL, Definition::kValue); | 412 InsertBefore(call, elements, NULL, Definition::kValue); |
| 413 *array = new Value(elements); | 413 *array = new Value(elements); |
| 414 return kArrayCid; | 414 return kArrayCid; |
| 415 } | 415 } |
| 416 return class_id; | 416 return class_id; |
| 417 } | 417 } |
| 418 | 418 |
| 419 | 419 |
| 420 bool FlowGraphOptimizer::TryReplaceWithStoreIndexed(InstanceCallInstr* call) { | 420 bool FlowGraphOptimizer::TryReplaceWithStoreIndexed(InstanceCallInstr* call) { |
| 421 // TODO(fschneider): Optimize []= operator in checked mode as well. | |
| 422 if (FLAG_enable_type_checks) return false; | |
| 423 const intptr_t class_id = ReceiverClassId(call); | 421 const intptr_t class_id = ReceiverClassId(call); |
| 424 ICData& value_check = ICData::Handle(); | 422 ICData& value_check = ICData::Handle(); |
| 425 switch (class_id) { | 423 switch (class_id) { |
| 426 case kArrayCid: | 424 case kArrayCid: |
| 427 case kGrowableObjectArrayCid: | 425 case kGrowableObjectArrayCid: |
| 428 // Acceptable store index classes. | 426 // Acceptable store index classes. |
| 429 break; | 427 break; |
| 430 case kFloat64ArrayCid: { | 428 case kFloat64ArrayCid: { |
| 431 // Check that value is always double. | 429 // Check that value is always double. |
| 432 value_check = call->ic_data()->AsUnaryClassChecksForArgNr(2); | 430 value_check = call->ic_data()->AsUnaryClassChecksForArgNr(2); |
| 433 if ((value_check.NumberOfChecks() != 1) || | 431 if ((value_check.NumberOfChecks() != 1) || |
| 434 (value_check.GetReceiverClassIdAt(0) != kDoubleCid)) { | 432 (value_check.GetReceiverClassIdAt(0) != kDoubleCid)) { |
| 435 return false; | 433 return false; |
| 436 } | 434 } |
| 437 break; | 435 break; |
| 438 } | 436 } |
| 439 default: | 437 default: |
| 440 return false; | 438 return false; |
| 441 } | 439 } |
| 440 | |
| 441 if (FLAG_enable_type_checks) { | |
| 442 Value* array = call->ArgumentAt(0)->value(); | |
| 443 Value* index = call->ArgumentAt(1)->value(); | |
| 444 Value* value = call->ArgumentAt(2)->value(); | |
| 445 const Function& target = | |
| 446 Function::ZoneHandle(call->ic_data()->GetTargetAt(0)); | |
| 447 | |
| 448 // Type check for the index. | |
| 449 const AbstractType& index_type = | |
| 450 AbstractType::ZoneHandle(target.ParameterTypeAt(1)); | |
| 451 ASSERT(index_type.IsIntType()); | |
| 452 ASSERT(index_type.IsInstantiated()); | |
| 453 ConstantInstr* null_constant = new ConstantInstr(Object::ZoneHandle()); | |
| 454 InsertBefore(call, null_constant, NULL, Definition::kValue); | |
| 455 AssertAssignableInstr* assert_index = | |
| 456 new AssertAssignableInstr(call->token_pos(), | |
| 457 index->Copy(), | |
| 458 new Value(null_constant), | |
| 459 new Value(null_constant), | |
| 460 index_type, | |
| 461 String::ZoneHandle(Symbols::New("index"))); | |
| 462 InsertBefore(call, assert_index, NULL, Definition::kValue); | |
|
srdjan
2012/10/18 16:25:48
Do we need the index check at all, since it will b
Florian Schneider
2012/10/18 18:13:10
Good point. I agree that we don't need it here. Th
| |
| 463 | |
| 464 // Type check for the value. | |
| 465 const AbstractType& value_type = | |
| 466 AbstractType::ZoneHandle(target.ParameterTypeAt(2)); | |
| 467 Value* instantiator = NULL; | |
| 468 Value* type_args = NULL; | |
| 469 switch (class_id) { | |
| 470 case kArrayCid: | |
| 471 case kGrowableObjectArrayCid: { | |
| 472 const Class& instantiator_class = Class::Handle(target.Owner()); | |
| 473 intptr_t type_arguments_instance_field_offset = | |
| 474 instantiator_class.type_arguments_instance_field_offset(); | |
| 475 LoadFieldInstr* load_type_args = | |
| 476 new LoadFieldInstr(array->Copy(), | |
| 477 type_arguments_instance_field_offset, | |
| 478 Type::ZoneHandle()); // No type. | |
| 479 InsertBefore(call, load_type_args, NULL, Definition::kValue); | |
| 480 instantiator = array->Copy(); | |
| 481 type_args = new Value(load_type_args); | |
| 482 break; | |
| 483 } | |
| 484 case kFloat64ArrayCid: | |
| 485 instantiator = new Value(null_constant); | |
| 486 type_args = new Value(null_constant); | |
| 487 ASSERT(value_type.IsDoubleType()); | |
| 488 ASSERT(value_type.IsInstantiated()); | |
| 489 break; | |
| 490 default: | |
| 491 UNREACHABLE(); | |
|
regis
2012/10/18 17:07:26
How about a comment explaining that other array fl
Florian Schneider
2012/10/18 18:13:10
Done.
| |
| 492 } | |
| 493 AssertAssignableInstr* assert_value = | |
| 494 new AssertAssignableInstr(call->token_pos(), | |
| 495 value->Copy(), | |
| 496 instantiator, | |
| 497 type_args, | |
| 498 value_type, | |
| 499 String::ZoneHandle(Symbols::New("value"))); | |
| 500 InsertBefore(call, assert_value, NULL, Definition::kValue); | |
| 501 } | |
| 502 | |
| 442 Value* array = NULL; | 503 Value* array = NULL; |
| 443 Value* index = NULL; | 504 Value* index = NULL; |
| 444 intptr_t array_cid = PrepareIndexedOp(call, class_id, &array, &index); | 505 intptr_t array_cid = PrepareIndexedOp(call, class_id, &array, &index); |
| 445 Value* value = call->ArgumentAt(2)->value(); | 506 Value* value = call->ArgumentAt(2)->value(); |
| 446 // Check if store barrier is needed. | 507 // Check if store barrier is needed. |
| 447 bool needs_store_barrier = true; | 508 bool needs_store_barrier = true; |
| 448 if (class_id == kFloat64ArrayCid) { | 509 if (class_id == kFloat64ArrayCid) { |
| 449 ASSERT(!value_check.IsNull()); | 510 ASSERT(!value_check.IsNull()); |
| 450 InsertBefore(call, | 511 InsertBefore(call, |
| 451 new CheckClassInstr(value->Copy(), | 512 new CheckClassInstr(value->Copy(), |
| (...skipping 2886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3338 | 3399 |
| 3339 if (FLAG_trace_constant_propagation) { | 3400 if (FLAG_trace_constant_propagation) { |
| 3340 OS::Print("\n==== After constant propagation ====\n"); | 3401 OS::Print("\n==== After constant propagation ====\n"); |
| 3341 FlowGraphPrinter printer(*graph_); | 3402 FlowGraphPrinter printer(*graph_); |
| 3342 printer.PrintBlocks(); | 3403 printer.PrintBlocks(); |
| 3343 } | 3404 } |
| 3344 } | 3405 } |
| 3345 | 3406 |
| 3346 | 3407 |
| 3347 } // namespace dart | 3408 } // namespace dart |
| OLD | NEW |