| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/intermediate_language.h" | 5 #include "vm/intermediate_language.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/bootstrap.h" | 8 #include "vm/bootstrap.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/constant_propagator.h" | 10 #include "vm/constant_propagator.h" |
| (...skipping 3034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3045 // Unoptimized code. | 3045 // Unoptimized code. |
| 3046 ASSERT(!HasICData()); | 3046 ASSERT(!HasICData()); |
| 3047 bool is_smi_two_args_op = false; | 3047 bool is_smi_two_args_op = false; |
| 3048 const StubEntry* stub_entry = TwoArgsSmiOpInlineCacheEntry(token_kind()); | 3048 const StubEntry* stub_entry = TwoArgsSmiOpInlineCacheEntry(token_kind()); |
| 3049 if (stub_entry != NULL) { | 3049 if (stub_entry != NULL) { |
| 3050 // We have a dedicated inline cache stub for this operation, add an | 3050 // We have a dedicated inline cache stub for this operation, add an |
| 3051 // an initial Smi/Smi check with count 0. | 3051 // an initial Smi/Smi check with count 0. |
| 3052 ASSERT(call_ic_data->NumArgsTested() == 2); | 3052 ASSERT(call_ic_data->NumArgsTested() == 2); |
| 3053 const String& name = String::Handle(zone, call_ic_data->target_name()); | 3053 const String& name = String::Handle(zone, call_ic_data->target_name()); |
| 3054 const Class& smi_class = Class::Handle(zone, Smi::Class()); | 3054 const Class& smi_class = Class::Handle(zone, Smi::Class()); |
| 3055 const Function& smi_op_target = | 3055 const Function& smi_op_target = Function::Handle(zone, |
| 3056 Function::Handle(Resolver::ResolveDynamicAnyArgs(smi_class, name)); | 3056 Resolver::ResolveDynamicAnyArgs(zone, smi_class, name)); |
| 3057 if (call_ic_data->NumberOfChecks() == 0) { | 3057 if (call_ic_data->NumberOfChecks() == 0) { |
| 3058 GrowableArray<intptr_t> class_ids(2); | 3058 GrowableArray<intptr_t> class_ids(2); |
| 3059 class_ids.Add(kSmiCid); | 3059 class_ids.Add(kSmiCid); |
| 3060 class_ids.Add(kSmiCid); | 3060 class_ids.Add(kSmiCid); |
| 3061 call_ic_data->AddCheck(class_ids, smi_op_target); | 3061 call_ic_data->AddCheck(class_ids, smi_op_target); |
| 3062 // 'AddCheck' sets the initial count to 1. | 3062 // 'AddCheck' sets the initial count to 1. |
| 3063 call_ic_data->SetCountAt(0, 0); | 3063 call_ic_data->SetCountAt(0, 0); |
| 3064 is_smi_two_args_op = true; | 3064 is_smi_two_args_op = true; |
| 3065 } else if (call_ic_data->NumberOfChecks() == 1) { | 3065 } else if (call_ic_data->NumberOfChecks() == 1) { |
| 3066 GrowableArray<intptr_t> class_ids(2); | 3066 GrowableArray<intptr_t> class_ids(2); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3473 | 3473 |
| 3474 CreateArrayInstr* create_array = value()->definition()->AsCreateArray(); | 3474 CreateArrayInstr* create_array = value()->definition()->AsCreateArray(); |
| 3475 ASSERT(create_array != NULL); | 3475 ASSERT(create_array != NULL); |
| 3476 // Check if the string interpolation has only constant inputs. | 3476 // Check if the string interpolation has only constant inputs. |
| 3477 Value* num_elements = create_array->num_elements(); | 3477 Value* num_elements = create_array->num_elements(); |
| 3478 if (!num_elements->BindsToConstant() || | 3478 if (!num_elements->BindsToConstant() || |
| 3479 !num_elements->BoundConstant().IsSmi()) { | 3479 !num_elements->BoundConstant().IsSmi()) { |
| 3480 return this; | 3480 return this; |
| 3481 } | 3481 } |
| 3482 const intptr_t length = Smi::Cast(num_elements->BoundConstant()).Value(); | 3482 const intptr_t length = Smi::Cast(num_elements->BoundConstant()).Value(); |
| 3483 Zone* zone = Thread::Current()->zone(); | 3483 Thread* thread = Thread::Current(); |
| 3484 Zone* zone = thread->zone(); |
| 3484 GrowableHandlePtrArray<const String> pieces(zone, length); | 3485 GrowableHandlePtrArray<const String> pieces(zone, length); |
| 3485 for (intptr_t i = 0; i < length; i++) { | 3486 for (intptr_t i = 0; i < length; i++) { |
| 3486 pieces.Add(Object::null_string()); | 3487 pieces.Add(Object::null_string()); |
| 3487 } | 3488 } |
| 3488 | 3489 |
| 3489 for (Value::Iterator it(create_array->input_use_list()); | 3490 for (Value::Iterator it(create_array->input_use_list()); |
| 3490 !it.Done(); | 3491 !it.Done(); |
| 3491 it.Advance()) { | 3492 it.Advance()) { |
| 3492 Instruction* curr = it.Current()->instruction(); | 3493 Instruction* curr = it.Current()->instruction(); |
| 3493 if (curr == this) continue; | 3494 if (curr == this) continue; |
| 3494 | 3495 |
| 3495 StoreIndexedInstr* store = curr->AsStoreIndexed(); | 3496 StoreIndexedInstr* store = curr->AsStoreIndexed(); |
| 3496 if (!store->index()->BindsToConstant() || | 3497 if (!store->index()->BindsToConstant() || |
| 3497 !store->index()->BoundConstant().IsSmi()) { | 3498 !store->index()->BoundConstant().IsSmi()) { |
| 3498 return this; | 3499 return this; |
| 3499 } | 3500 } |
| 3500 intptr_t store_index = Smi::Cast(store->index()->BoundConstant()).Value(); | 3501 intptr_t store_index = Smi::Cast(store->index()->BoundConstant()).Value(); |
| 3501 ASSERT(store_index < length); | 3502 ASSERT(store_index < length); |
| 3502 ASSERT(store != NULL); | 3503 ASSERT(store != NULL); |
| 3503 if (store->value()->definition()->IsConstant()) { | 3504 if (store->value()->definition()->IsConstant()) { |
| 3504 ASSERT(store->index()->BindsToConstant()); | 3505 ASSERT(store->index()->BindsToConstant()); |
| 3505 const Object& obj = store->value()->definition()->AsConstant()->value(); | 3506 const Object& obj = store->value()->definition()->AsConstant()->value(); |
| 3506 // TODO(srdjan): Verify if any other types should be converted as well. | 3507 // TODO(srdjan): Verify if any other types should be converted as well. |
| 3507 if (obj.IsString()) { | 3508 if (obj.IsString()) { |
| 3508 pieces.SetAt(store_index, String::Cast(obj)); | 3509 pieces.SetAt(store_index, String::Cast(obj)); |
| 3509 } else if (obj.IsSmi()) { | 3510 } else if (obj.IsSmi()) { |
| 3510 const char* cstr = obj.ToCString(); | 3511 const char* cstr = obj.ToCString(); |
| 3511 pieces.SetAt(store_index, String::Handle(zone, Symbols::New(cstr))); | 3512 pieces.SetAt(store_index, String::Handle(zone, String::New(cstr))); |
| 3512 } else if (obj.IsBool()) { | 3513 } else if (obj.IsBool()) { |
| 3513 pieces.SetAt(store_index, | 3514 pieces.SetAt(store_index, |
| 3514 Bool::Cast(obj).value() ? Symbols::True() : Symbols::False()); | 3515 Bool::Cast(obj).value() ? Symbols::True() : Symbols::False()); |
| 3515 } else if (obj.IsNull()) { | 3516 } else if (obj.IsNull()) { |
| 3516 pieces.SetAt(store_index, Symbols::Null()); | 3517 pieces.SetAt(store_index, Symbols::Null()); |
| 3517 } else { | 3518 } else { |
| 3518 return this; | 3519 return this; |
| 3519 } | 3520 } |
| 3520 } else { | 3521 } else { |
| 3521 return this; | 3522 return this; |
| 3522 } | 3523 } |
| 3523 } | 3524 } |
| 3524 | 3525 |
| 3525 ASSERT(pieces.length() == length); | |
| 3526 const String& concatenated = String::ZoneHandle(zone, | 3526 const String& concatenated = String::ZoneHandle(zone, |
| 3527 Symbols::FromConcatAll(pieces)); | 3527 Symbols::FromConcatAll(thread, pieces)); |
| 3528 return flow_graph->GetConstant(concatenated); | 3528 return flow_graph->GetConstant(concatenated); |
| 3529 } | 3529 } |
| 3530 | 3530 |
| 3531 | 3531 |
| 3532 InvokeMathCFunctionInstr::InvokeMathCFunctionInstr( | 3532 InvokeMathCFunctionInstr::InvokeMathCFunctionInstr( |
| 3533 ZoneGrowableArray<Value*>* inputs, | 3533 ZoneGrowableArray<Value*>* inputs, |
| 3534 intptr_t deopt_id, | 3534 intptr_t deopt_id, |
| 3535 MethodRecognizer::Kind recognized_kind, | 3535 MethodRecognizer::Kind recognized_kind, |
| 3536 TokenPosition token_pos) | 3536 TokenPosition token_pos) |
| 3537 : PureDefinition(deopt_id), | 3537 : PureDefinition(deopt_id), |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3751 set_native_c_function(native_function); | 3751 set_native_c_function(native_function); |
| 3752 function().SetIsNativeAutoSetupScope(auto_setup_scope); | 3752 function().SetIsNativeAutoSetupScope(auto_setup_scope); |
| 3753 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); | 3753 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); |
| 3754 bool is_bootstrap_native = Bootstrap::IsBootstapResolver(resolver); | 3754 bool is_bootstrap_native = Bootstrap::IsBootstapResolver(resolver); |
| 3755 set_is_bootstrap_native(is_bootstrap_native); | 3755 set_is_bootstrap_native(is_bootstrap_native); |
| 3756 } | 3756 } |
| 3757 | 3757 |
| 3758 #undef __ | 3758 #undef __ |
| 3759 | 3759 |
| 3760 } // namespace dart | 3760 } // namespace dart |
| OLD | NEW |