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/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/flow_graph_allocator.h" | 10 #include "vm/flow_graph_allocator.h" |
11 #include "vm/flow_graph_builder.h" | 11 #include "vm/flow_graph_builder.h" |
12 #include "vm/flow_graph_compiler.h" | 12 #include "vm/flow_graph_compiler.h" |
13 #include "vm/flow_graph_optimizer.h" | 13 #include "vm/flow_graph_optimizer.h" |
14 #include "vm/locations.h" | 14 #include "vm/locations.h" |
15 #include "vm/object.h" | 15 #include "vm/object.h" |
16 #include "vm/object_store.h" | 16 #include "vm/object_store.h" |
17 #include "vm/os.h" | 17 #include "vm/os.h" |
18 #include "vm/resolver.h" | 18 #include "vm/resolver.h" |
19 #include "vm/scopes.h" | 19 #include "vm/scopes.h" |
20 #include "vm/stub_code.h" | 20 #include "vm/stub_code.h" |
21 #include "vm/symbols.h" | 21 #include "vm/symbols.h" |
22 | 22 |
23 #include "vm/il_printer.h" | |
24 | |
23 namespace dart { | 25 namespace dart { |
24 | 26 |
25 DEFINE_FLAG(int, max_equality_polymorphic_checks, 32, | 27 DEFINE_FLAG(int, max_equality_polymorphic_checks, 32, |
26 "Maximum number of polymorphic checks in equality operator," | 28 "Maximum number of polymorphic checks in equality operator," |
27 " otherwise use megamorphic dispatch."); | 29 " otherwise use megamorphic dispatch."); |
28 DEFINE_FLAG(bool, new_identity_spec, true, | 30 DEFINE_FLAG(bool, new_identity_spec, true, |
29 "Use new identity check rules for numbers."); | 31 "Use new identity check rules for numbers."); |
30 DEFINE_FLAG(bool, propagate_ic_data, true, | 32 DEFINE_FLAG(bool, propagate_ic_data, true, |
31 "Propagate IC data from unoptimized to optimized IC calls."); | 33 "Propagate IC data from unoptimized to optimized IC calls."); |
32 DECLARE_FLAG(bool, enable_type_checks); | 34 DECLARE_FLAG(bool, enable_type_checks); |
(...skipping 2657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2690 Library::PrivateCoreLibName(Symbols::Interpolate()), | 2692 Library::PrivateCoreLibName(Symbols::Interpolate()), |
2691 kNumberOfArguments, | 2693 kNumberOfArguments, |
2692 kNoArgumentNames, | 2694 kNoArgumentNames, |
2693 Resolver::kIsQualified); | 2695 Resolver::kIsQualified); |
2694 } | 2696 } |
2695 ASSERT(!function_.IsNull()); | 2697 ASSERT(!function_.IsNull()); |
2696 return function_; | 2698 return function_; |
2697 } | 2699 } |
2698 | 2700 |
2699 | 2701 |
2702 // Replace StringInterpolateInstr with a constant string if all inputs are | |
2703 // constant. Leave the CreateArrayInstr and StoreIndexedInstr in the | |
2704 // stream in case deoptimization occurs. | |
2705 Definition* StringInterpolateInstr::Canonicalize(FlowGraph* flow_graph) { | |
2706 // The following graph structure is generated by the graph builder: | |
2707 // v2 <- CreateArray(v0) | |
2708 // StoreIndexed(v2, v3, v4) -- v3:constant index, v4: value. | |
2709 // .. | |
2710 // v8 <- StringInterpolate(v2) | |
2711 CreateArrayInstr* create_array = value()->definition()->AsCreateArray(); | |
2712 ASSERT(create_array != NULL); | |
2713 // Check if the string interpolation has only constant inputs. | |
2714 GrowableArray<ConstantInstr*> constants(create_array->num_elements()); | |
2715 for (intptr_t i = 0; i < create_array->num_elements(); i++) { | |
2716 constants.Add(NULL); | |
2717 } | |
2718 for (Value::Iterator it(create_array->input_use_list()); | |
2719 !it.Done(); | |
2720 it.Advance()) { | |
2721 Instruction* curr = it.Current()->instruction(); | |
2722 if (curr != this) { | |
2723 StoreIndexedInstr* store = curr->AsStoreIndexed(); | |
2724 ASSERT(store != NULL); | |
2725 if (store->value()->definition()->IsConstant()) { | |
2726 ASSERT(store->index()->BindsToConstant()); | |
2727 constants[Smi::Cast(store->index()->BoundConstant()).Value()] = | |
2728 store->value()->definition()->AsConstant(); | |
2729 } else { | |
2730 return this; | |
2731 } | |
2732 } | |
2733 } | |
2734 // Interpolate string at compile time. | |
2735 const Array& array_argument = | |
2736 Array::Handle(Array::New(create_array->num_elements())); | |
2737 for (intptr_t i = 0; i < constants.length(); i++) { | |
2738 array_argument.SetAt(i, constants[i]->value()); | |
2739 } | |
2740 // Build argument array to pass to the interpolation function. | |
2741 const Array& interpolate_arg = Array::Handle(Array::New(1)); | |
2742 interpolate_arg.SetAt(0, array_argument); | |
2743 // Call interpolation function. | |
2744 String& concatenated = String::ZoneHandle(); | |
2745 concatenated ^= | |
2746 DartEntry::InvokeFunction(CallFunction(), interpolate_arg); | |
2747 if (concatenated.IsUnhandledException()) { | |
2748 return this; | |
Florian Schneider
2013/10/23 17:32:39
Please make sure that the case of an exception is
srdjan
2013/10/23 20:39:02
Changed the code to allow only numbers, strings, b
| |
2749 } | |
2750 concatenated = Symbols::New(concatenated); | |
2751 return flow_graph->GetConstant(concatenated); | |
2752 } | |
2753 | |
2754 | |
2700 InvokeMathCFunctionInstr::InvokeMathCFunctionInstr( | 2755 InvokeMathCFunctionInstr::InvokeMathCFunctionInstr( |
2701 ZoneGrowableArray<Value*>* inputs, | 2756 ZoneGrowableArray<Value*>* inputs, |
2702 intptr_t original_deopt_id, | 2757 intptr_t original_deopt_id, |
2703 MethodRecognizer::Kind recognized_kind) | 2758 MethodRecognizer::Kind recognized_kind) |
2704 : inputs_(inputs), | 2759 : inputs_(inputs), |
2705 locs_(NULL), | 2760 locs_(NULL), |
2706 recognized_kind_(recognized_kind) { | 2761 recognized_kind_(recognized_kind) { |
2707 ASSERT(inputs_->length() == ArgumentCountFor(recognized_kind_)); | 2762 ASSERT(inputs_->length() == ArgumentCountFor(recognized_kind_)); |
2708 for (intptr_t i = 0; i < inputs_->length(); ++i) { | 2763 for (intptr_t i = 0; i < inputs_->length(); ++i) { |
2709 ASSERT((*inputs)[i] != NULL); | 2764 ASSERT((*inputs)[i] != NULL); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2801 return kCosRuntimeEntry; | 2856 return kCosRuntimeEntry; |
2802 default: | 2857 default: |
2803 UNREACHABLE(); | 2858 UNREACHABLE(); |
2804 } | 2859 } |
2805 return kSinRuntimeEntry; | 2860 return kSinRuntimeEntry; |
2806 } | 2861 } |
2807 | 2862 |
2808 #undef __ | 2863 #undef __ |
2809 | 2864 |
2810 } // namespace dart | 2865 } // namespace dart |
OLD | NEW |