| 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: |
| 438 // TODO(fschneider): Add support for other array types. |
| 440 return false; | 439 return false; |
| 441 } | 440 } |
| 441 |
| 442 if (FLAG_enable_type_checks) { |
| 443 Value* array = call->ArgumentAt(0)->value(); |
| 444 Value* value = call->ArgumentAt(2)->value(); |
| 445 // Only type check for the value. A type check for the index is not |
| 446 // needed here because we insert a deoptimizing smi-check for the case |
| 447 // the index is not a smi. |
| 448 const Function& target = |
| 449 Function::ZoneHandle(call->ic_data()->GetTargetAt(0)); |
| 450 const AbstractType& value_type = |
| 451 AbstractType::ZoneHandle(target.ParameterTypeAt(2)); |
| 452 Value* instantiator = NULL; |
| 453 Value* type_args = NULL; |
| 454 switch (class_id) { |
| 455 case kArrayCid: |
| 456 case kGrowableObjectArrayCid: { |
| 457 const Class& instantiator_class = Class::Handle(target.Owner()); |
| 458 intptr_t type_arguments_instance_field_offset = |
| 459 instantiator_class.type_arguments_instance_field_offset(); |
| 460 LoadFieldInstr* load_type_args = |
| 461 new LoadFieldInstr(array->Copy(), |
| 462 type_arguments_instance_field_offset, |
| 463 Type::ZoneHandle()); // No type. |
| 464 InsertBefore(call, load_type_args, NULL, Definition::kValue); |
| 465 instantiator = array->Copy(); |
| 466 type_args = new Value(load_type_args); |
| 467 break; |
| 468 } |
| 469 case kFloat64ArrayCid: { |
| 470 ConstantInstr* null_constant = new ConstantInstr(Object::ZoneHandle()); |
| 471 InsertBefore(call, null_constant, NULL, Definition::kValue); |
| 472 instantiator = new Value(null_constant); |
| 473 type_args = new Value(null_constant); |
| 474 ASSERT(value_type.IsDoubleType()); |
| 475 ASSERT(value_type.IsInstantiated()); |
| 476 break; |
| 477 } |
| 478 default: |
| 479 // TODO(fschneider): Add support for other array types. |
| 480 UNREACHABLE(); |
| 481 } |
| 482 AssertAssignableInstr* assert_value = |
| 483 new AssertAssignableInstr(call->token_pos(), |
| 484 value->Copy(), |
| 485 instantiator, |
| 486 type_args, |
| 487 value_type, |
| 488 String::ZoneHandle(Symbols::New("value"))); |
| 489 InsertBefore(call, assert_value, NULL, Definition::kValue); |
| 490 } |
| 491 |
| 442 Value* array = NULL; | 492 Value* array = NULL; |
| 443 Value* index = NULL; | 493 Value* index = NULL; |
| 444 intptr_t array_cid = PrepareIndexedOp(call, class_id, &array, &index); | 494 intptr_t array_cid = PrepareIndexedOp(call, class_id, &array, &index); |
| 445 Value* value = call->ArgumentAt(2)->value(); | 495 Value* value = call->ArgumentAt(2)->value(); |
| 446 // Check if store barrier is needed. | 496 // Check if store barrier is needed. |
| 447 bool needs_store_barrier = true; | 497 bool needs_store_barrier = true; |
| 448 if (class_id == kFloat64ArrayCid) { | 498 if (class_id == kFloat64ArrayCid) { |
| 449 ASSERT(!value_check.IsNull()); | 499 ASSERT(!value_check.IsNull()); |
| 450 InsertBefore(call, | 500 InsertBefore(call, |
| 451 new CheckClassInstr(value->Copy(), | 501 new CheckClassInstr(value->Copy(), |
| (...skipping 2890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3342 | 3392 |
| 3343 if (FLAG_trace_constant_propagation) { | 3393 if (FLAG_trace_constant_propagation) { |
| 3344 OS::Print("\n==== After constant propagation ====\n"); | 3394 OS::Print("\n==== After constant propagation ====\n"); |
| 3345 FlowGraphPrinter printer(*graph_); | 3395 FlowGraphPrinter printer(*graph_); |
| 3346 printer.PrintBlocks(); | 3396 printer.PrintBlocks(); |
| 3347 } | 3397 } |
| 3348 } | 3398 } |
| 3349 | 3399 |
| 3350 | 3400 |
| 3351 } // namespace dart | 3401 } // namespace dart |
| OLD | NEW |