| 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/globals.h" // Needed here to get TARGET_ARCH_XXX. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_XXX. |
| 6 | 6 |
| 7 #include "vm/flow_graph_compiler.h" | 7 #include "vm/flow_graph_compiler.h" |
| 8 | 8 |
| 9 #include "vm/bit_vector.h" | 9 #include "vm/bit_vector.h" |
| 10 #include "vm/cha.h" | 10 #include "vm/cha.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "vm/object_store.h" | 23 #include "vm/object_store.h" |
| 24 #include "vm/parser.h" | 24 #include "vm/parser.h" |
| 25 #include "vm/raw_object.h" | 25 #include "vm/raw_object.h" |
| 26 #include "vm/stack_frame.h" | 26 #include "vm/stack_frame.h" |
| 27 #include "vm/stub_code.h" | 27 #include "vm/stub_code.h" |
| 28 #include "vm/symbols.h" | 28 #include "vm/symbols.h" |
| 29 #include "vm/timeline.h" | 29 #include "vm/timeline.h" |
| 30 | 30 |
| 31 namespace dart { | 31 namespace dart { |
| 32 | 32 |
| 33 DEFINE_FLAG(bool, allow_absolute_addresses, true, | |
| 34 "Allow embedding absolute addresses in generated code."); | |
| 35 DEFINE_FLAG(bool, always_megamorphic_calls, false, | |
| 36 "Instance call always as megamorphic."); | |
| 37 DEFINE_FLAG(bool, enable_simd_inline, true, | 33 DEFINE_FLAG(bool, enable_simd_inline, true, |
| 38 "Enable inlining of SIMD related method calls."); | 34 "Enable inlining of SIMD related method calls."); |
| 39 DEFINE_FLAG(int, min_optimization_counter_threshold, 5000, | 35 DEFINE_FLAG(int, min_optimization_counter_threshold, 5000, |
| 40 "The minimum invocation count for a function."); | 36 "The minimum invocation count for a function."); |
| 41 DEFINE_FLAG(int, optimization_counter_scale, 2000, | 37 DEFINE_FLAG(int, optimization_counter_scale, 2000, |
| 42 "The scale of invocation count, by size of the function."); | 38 "The scale of invocation count, by size of the function."); |
| 43 DEFINE_FLAG(bool, source_lines, false, "Emit source line as assembly comment."); | 39 DEFINE_FLAG(bool, source_lines, false, "Emit source line as assembly comment."); |
| 44 DEFINE_FLAG(bool, trace_inlining_intervals, false, | 40 DEFINE_FLAG(bool, trace_inlining_intervals, false, |
| 45 "Inlining interval diagnostics"); | 41 "Inlining interval diagnostics"); |
| 46 DEFINE_FLAG(bool, use_megamorphic_stub, true, "Out of line megamorphic lookup"); | 42 DEFINE_FLAG(bool, use_megamorphic_stub, true, "Out of line megamorphic lookup"); |
| 47 | 43 |
| 48 DECLARE_FLAG(bool, background_compilation); | |
| 49 DECLARE_FLAG(bool, code_comments); | 44 DECLARE_FLAG(bool, code_comments); |
| 50 DECLARE_FLAG(bool, collect_dynamic_function_names); | |
| 51 DECLARE_FLAG(bool, deoptimize_alot); | |
| 52 DECLARE_FLAG(int, deoptimize_every); | |
| 53 DECLARE_FLAG(charp, deoptimize_filter); | 45 DECLARE_FLAG(charp, deoptimize_filter); |
| 54 DECLARE_FLAG(bool, emit_edge_counters); | |
| 55 DECLARE_FLAG(bool, fields_may_be_reset); | |
| 56 DECLARE_FLAG(bool, ic_range_profiling); | |
| 57 DECLARE_FLAG(bool, intrinsify); | 46 DECLARE_FLAG(bool, intrinsify); |
| 58 DECLARE_FLAG(bool, load_deferred_eagerly); | |
| 59 DECLARE_FLAG(int, optimization_counter_threshold); | |
| 60 DECLARE_FLAG(bool, propagate_ic_data); | 47 DECLARE_FLAG(bool, propagate_ic_data); |
| 61 DECLARE_FLAG(int, regexp_optimization_counter_threshold); | 48 DECLARE_FLAG(int, regexp_optimization_counter_threshold); |
| 62 DECLARE_FLAG(int, reoptimization_counter_threshold); | 49 DECLARE_FLAG(int, reoptimization_counter_threshold); |
| 63 DECLARE_FLAG(int, stacktrace_every); | 50 DECLARE_FLAG(int, stacktrace_every); |
| 64 DECLARE_FLAG(charp, stacktrace_filter); | 51 DECLARE_FLAG(charp, stacktrace_filter); |
| 65 DECLARE_FLAG(bool, use_field_guards); | |
| 66 DECLARE_FLAG(bool, use_osr); | |
| 67 DECLARE_FLAG(bool, print_stop_message); | |
| 68 DECLARE_FLAG(bool, interpret_irregexp); | |
| 69 DECLARE_FLAG(bool, link_natives_lazily); | |
| 70 DECLARE_FLAG(bool, trace_compiler); | 52 DECLARE_FLAG(bool, trace_compiler); |
| 71 DECLARE_FLAG(int, inlining_hotness); | 53 DECLARE_FLAG(int, inlining_hotness); |
| 72 DECLARE_FLAG(int, inlining_size_threshold); | 54 DECLARE_FLAG(int, inlining_size_threshold); |
| 73 DECLARE_FLAG(int, inlining_callee_size_threshold); | 55 DECLARE_FLAG(int, inlining_callee_size_threshold); |
| 74 DECLARE_FLAG(int, inline_getters_setters_smaller_than); | 56 DECLARE_FLAG(int, inline_getters_setters_smaller_than); |
| 75 DECLARE_FLAG(int, inlining_depth_threshold); | 57 DECLARE_FLAG(int, inlining_depth_threshold); |
| 76 DECLARE_FLAG(int, inlining_caller_size_threshold); | 58 DECLARE_FLAG(int, inlining_caller_size_threshold); |
| 77 DECLARE_FLAG(int, inlining_constant_arguments_max_size_threshold); | 59 DECLARE_FLAG(int, inlining_constant_arguments_max_size_threshold); |
| 78 DECLARE_FLAG(int, inlining_constant_arguments_min_size_threshold); | 60 DECLARE_FLAG(int, inlining_constant_arguments_min_size_threshold); |
| 79 | 61 |
| 80 bool FLAG_precompilation = false; | 62 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 81 static void PrecompilationModeHandler(bool value) { | 63 static void PrecompilationModeHandler(bool value) { |
| 82 if (value) { | 64 if (value) { |
| 83 #if defined(TARGET_ARCH_IA32) | 65 #if defined(TARGET_ARCH_IA32) |
| 84 FATAL("Precompilation not supported on IA32"); | 66 FATAL("Precompilation not supported on IA32"); |
| 85 #endif | 67 #endif |
| 86 FLAG_precompilation = true; | |
| 87 | 68 |
| 88 FLAG_always_megamorphic_calls = true; | 69 #if defined(PRODUCT) |
| 89 FLAG_optimization_counter_threshold = -1; | 70 FATAL("dart_noopt not supported in product mode"); |
| 90 FLAG_use_field_guards = false; | 71 #else |
| 91 FLAG_use_osr = false; | |
| 92 FLAG_emit_edge_counters = false; | |
| 93 #ifndef PRODUCT | |
| 94 FLAG_support_debugger = false; | 72 FLAG_support_debugger = false; |
| 95 #endif // !PRODUCT | |
| 96 FLAG_ic_range_profiling = false; | |
| 97 FLAG_collect_code = false; | |
| 98 FLAG_load_deferred_eagerly = true; | |
| 99 FLAG_deoptimize_alot = false; // Used in some tests. | |
| 100 FLAG_deoptimize_every = 0; // Used in some tests. | |
| 101 // Calling the PrintStopMessage stub is not supported in precompiled code | |
| 102 // since it is done at places where no pool pointer is loaded. | |
| 103 FLAG_print_stop_message = false; | |
| 104 | 73 |
| 105 FLAG_interpret_irregexp = true; | 74 // Flags affecting compilation only: |
| 106 #ifndef PRODUCT | |
| 107 FLAG_enable_mirrors = false; | |
| 108 #endif // !PRODUCT | |
| 109 FLAG_link_natives_lazily = true; | |
| 110 FLAG_fields_may_be_reset = true; | |
| 111 FLAG_allow_absolute_addresses = false; | |
| 112 | |
| 113 // There is no counter feedback in precompilation, so ignore the counter | 75 // There is no counter feedback in precompilation, so ignore the counter |
| 114 // when making inlining decisions. | 76 // when making inlining decisions. |
| 115 FLAG_inlining_hotness = 0; | 77 FLAG_inlining_hotness = 0; |
| 116 // Use smaller thresholds in precompilation as we are compiling everything | 78 // Use smaller thresholds in precompilation as we are compiling everything |
| 117 // with the optimizing compiler instead of only hot functions. | 79 // with the optimizing compiler instead of only hot functions. |
| 118 FLAG_inlining_size_threshold = 5; | 80 FLAG_inlining_size_threshold = 5; |
| 119 FLAG_inline_getters_setters_smaller_than = 5; | 81 FLAG_inline_getters_setters_smaller_than = 5; |
| 120 FLAG_inlining_callee_size_threshold = 20; | 82 FLAG_inlining_callee_size_threshold = 20; |
| 121 FLAG_inlining_depth_threshold = 2; | 83 FLAG_inlining_depth_threshold = 2; |
| 122 FLAG_inlining_caller_size_threshold = 1000; | 84 FLAG_inlining_caller_size_threshold = 1000; |
| 123 | |
| 124 FLAG_inlining_constant_arguments_max_size_threshold = 100; | 85 FLAG_inlining_constant_arguments_max_size_threshold = 100; |
| 125 FLAG_inlining_constant_arguments_min_size_threshold = 30; | 86 FLAG_inlining_constant_arguments_min_size_threshold = 30; |
| 126 | 87 |
| 127 // Background compilation relies on two-stage compilation pipeline, | 88 FLAG_allow_absolute_addresses = false; |
| 128 // while precompilation has only one. | 89 FLAG_always_megamorphic_calls = true; |
| 129 FLAG_background_compilation = false; | 90 FLAG_background_compilation = false; |
| 91 FLAG_collect_code = false; |
| 130 FLAG_collect_dynamic_function_names = true; | 92 FLAG_collect_dynamic_function_names = true; |
| 131 #if !defined(DART_PRECOMPILED_RUNTIME) && !defined(PRODUCT) | 93 FLAG_deoptimize_alot = false; // Used in some tests. |
| 94 FLAG_deoptimize_every = 0; // Used in some tests. |
| 95 FLAG_emit_edge_counters = false; |
| 96 FLAG_enable_mirrors = false; |
| 97 FLAG_fields_may_be_reset = true; |
| 98 FLAG_ic_range_profiling = false; |
| 99 FLAG_interpret_irregexp = true; |
| 132 FLAG_lazy_dispatchers = false; | 100 FLAG_lazy_dispatchers = false; |
| 101 FLAG_link_natives_lazily = true; |
| 102 FLAG_load_deferred_eagerly = true; |
| 103 FLAG_optimization_counter_threshold = -1; |
| 133 FLAG_polymorphic_with_deopt = false; | 104 FLAG_polymorphic_with_deopt = false; |
| 134 // Precompilation finalizes all classes and thus allows CHA optimizations. | 105 FLAG_precompiled_mode = true; |
| 135 // Do not require CHA triggered deoptimization. | 106 FLAG_print_stop_message = false; |
| 136 FLAG_use_cha_deopt = false; | 107 FLAG_use_cha_deopt = false; |
| 137 #elif defined(DART_PRECOMPILED_RUNTIME) | 108 FLAG_use_field_guards = false; |
| 138 // Precompiled product and release mode. | 109 FLAG_use_osr = false; |
| 139 COMPILE_ASSERT(!FLAG_lazy_dispatchers); | 110 #endif // PRODUCT |
| 140 COMPILE_ASSERT(!FLAG_polymorphic_with_deopt); | |
| 141 COMPILE_ASSERT(!FLAG_use_cha_deopt); | |
| 142 #elif defined(PRODUCT) | |
| 143 // Jit product and release mode. | |
| 144 COMPILE_ASSERT(FLAG_lazy_dispatchers); | |
| 145 COMPILE_ASSERT(FLAG_polymorphic_with_deopt); | |
| 146 COMPILE_ASSERT(FLAG_use_cha_deopt); | |
| 147 #endif | |
| 148 } | 111 } |
| 149 } | 112 } |
| 150 | 113 |
| 151 | |
| 152 DEFINE_FLAG_HANDLER(PrecompilationModeHandler, | 114 DEFINE_FLAG_HANDLER(PrecompilationModeHandler, |
| 153 precompilation, | 115 precompilation, |
| 154 "Precompilation mode"); | 116 "Precompilation mode"); |
| 155 | 117 |
| 118 #else // DART_PRECOMPILED_RUNTIME |
| 119 |
| 120 COMPILE_ASSERT(!FLAG_allow_absolute_addresses); |
| 121 COMPILE_ASSERT(!FLAG_background_compilation); |
| 122 COMPILE_ASSERT(!FLAG_collect_code); |
| 123 COMPILE_ASSERT(!FLAG_deoptimize_alot); // Used in some tests. |
| 124 COMPILE_ASSERT(!FLAG_emit_edge_counters); |
| 125 COMPILE_ASSERT(!FLAG_enable_mirrors); |
| 126 COMPILE_ASSERT(!FLAG_ic_range_profiling); |
| 127 COMPILE_ASSERT(!FLAG_lazy_dispatchers); |
| 128 COMPILE_ASSERT(!FLAG_polymorphic_with_deopt); |
| 129 COMPILE_ASSERT(!FLAG_print_stop_message); |
| 130 COMPILE_ASSERT(!FLAG_use_cha_deopt); |
| 131 COMPILE_ASSERT(!FLAG_use_field_guards); |
| 132 COMPILE_ASSERT(!FLAG_use_osr); |
| 133 COMPILE_ASSERT(FLAG_always_megamorphic_calls); |
| 134 COMPILE_ASSERT(FLAG_collect_dynamic_function_names); |
| 135 COMPILE_ASSERT(FLAG_deoptimize_every == 0); // Used in some tests. |
| 136 COMPILE_ASSERT(FLAG_fields_may_be_reset); |
| 137 COMPILE_ASSERT(FLAG_interpret_irregexp); |
| 138 COMPILE_ASSERT(FLAG_link_natives_lazily); |
| 139 COMPILE_ASSERT(FLAG_load_deferred_eagerly); |
| 140 COMPILE_ASSERT(FLAG_optimization_counter_threshold == -1); |
| 141 COMPILE_ASSERT(FLAG_precompiled_mode); |
| 142 |
| 143 #endif // DART_PRECOMPILED_RUNTIME |
| 144 |
| 156 | 145 |
| 157 // Assign locations to incoming arguments, i.e., values pushed above spill slots | 146 // Assign locations to incoming arguments, i.e., values pushed above spill slots |
| 158 // with PushArgument. Recursively allocates from outermost to innermost | 147 // with PushArgument. Recursively allocates from outermost to innermost |
| 159 // environment. | 148 // environment. |
| 160 void CompilerDeoptInfo::AllocateIncomingParametersRecursive( | 149 void CompilerDeoptInfo::AllocateIncomingParametersRecursive( |
| 161 Environment* env, | 150 Environment* env, |
| 162 intptr_t* stack_height) { | 151 intptr_t* stack_height) { |
| 163 if (env == NULL) return; | 152 if (env == NULL) return; |
| 164 AllocateIncomingParametersRecursive(env->outer(), stack_height); | 153 AllocateIncomingParametersRecursive(env->outer(), stack_height); |
| 165 for (Environment::ShallowIterator it(env); !it.Done(); it.Advance()) { | 154 for (Environment::ShallowIterator it(env); !it.Done(); it.Advance()) { |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 } | 924 } |
| 936 | 925 |
| 937 | 926 |
| 938 Label* FlowGraphCompiler::AddDeoptStub(intptr_t deopt_id, | 927 Label* FlowGraphCompiler::AddDeoptStub(intptr_t deopt_id, |
| 939 ICData::DeoptReasonId reason, | 928 ICData::DeoptReasonId reason, |
| 940 uint32_t flags) { | 929 uint32_t flags) { |
| 941 if (intrinsic_mode()) { | 930 if (intrinsic_mode()) { |
| 942 return &intrinsic_slow_path_label_; | 931 return &intrinsic_slow_path_label_; |
| 943 } | 932 } |
| 944 | 933 |
| 945 // No deoptimization allowed when 'FLAG_precompilation' is set. | 934 // No deoptimization allowed when 'FLAG_precompiled_mode' is set. |
| 946 if (FLAG_precompilation) { | 935 if (FLAG_precompiled_mode) { |
| 947 if (FLAG_trace_compiler) { | 936 if (FLAG_trace_compiler) { |
| 948 THR_Print( | 937 THR_Print( |
| 949 "Retrying compilation %s, suppressing inlining of deopt_id:%" Pd "\n", | 938 "Retrying compilation %s, suppressing inlining of deopt_id:%" Pd "\n", |
| 950 parsed_function_.function().ToFullyQualifiedCString(), deopt_id); | 939 parsed_function_.function().ToFullyQualifiedCString(), deopt_id); |
| 951 } | 940 } |
| 952 ASSERT(deopt_id != 0); // longjmp must return non-zero value. | 941 ASSERT(deopt_id != 0); // longjmp must return non-zero value. |
| 953 Thread::Current()->long_jump_base()->Jump( | 942 Thread::Current()->long_jump_base()->Jump( |
| 954 deopt_id, Object::speculative_inlining_error()); | 943 deopt_id, Object::speculative_inlining_error()); |
| 955 } | 944 } |
| 956 | 945 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 984 const PcDescriptors& descriptors = PcDescriptors::Handle( | 973 const PcDescriptors& descriptors = PcDescriptors::Handle( |
| 985 pc_descriptors_list_->FinalizePcDescriptors(code.EntryPoint())); | 974 pc_descriptors_list_->FinalizePcDescriptors(code.EntryPoint())); |
| 986 if (!is_optimizing_) descriptors.Verify(parsed_function_.function()); | 975 if (!is_optimizing_) descriptors.Verify(parsed_function_.function()); |
| 987 code.set_pc_descriptors(descriptors); | 976 code.set_pc_descriptors(descriptors); |
| 988 code.set_lazy_deopt_pc_offset(lazy_deopt_pc_offset_); | 977 code.set_lazy_deopt_pc_offset(lazy_deopt_pc_offset_); |
| 989 } | 978 } |
| 990 | 979 |
| 991 | 980 |
| 992 RawArray* FlowGraphCompiler::CreateDeoptInfo(Assembler* assembler) { | 981 RawArray* FlowGraphCompiler::CreateDeoptInfo(Assembler* assembler) { |
| 993 // No deopt information if we precompile (no deoptimization allowed). | 982 // No deopt information if we precompile (no deoptimization allowed). |
| 994 if (FLAG_precompilation) { | 983 if (FLAG_precompiled_mode) { |
| 995 return Array::empty_array().raw(); | 984 return Array::empty_array().raw(); |
| 996 } | 985 } |
| 997 // For functions with optional arguments, all incoming arguments are copied | 986 // For functions with optional arguments, all incoming arguments are copied |
| 998 // to spill slots. The deoptimization environment does not track them. | 987 // to spill slots. The deoptimization environment does not track them. |
| 999 const Function& function = parsed_function().function(); | 988 const Function& function = parsed_function().function(); |
| 1000 const intptr_t incoming_arg_count = | 989 const intptr_t incoming_arg_count = |
| 1001 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters(); | 990 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters(); |
| 1002 DeoptInfoBuilder builder(zone(), incoming_arg_count, assembler); | 991 DeoptInfoBuilder builder(zone(), incoming_arg_count, assembler); |
| 1003 | 992 |
| 1004 intptr_t deopt_info_table_size = DeoptTable::SizeFor(deopt_infos_.length()); | 993 intptr_t deopt_info_table_size = DeoptTable::SizeFor(deopt_infos_.length()); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 } | 1130 } |
| 1142 | 1131 |
| 1143 | 1132 |
| 1144 void FlowGraphCompiler::GenerateInstanceCall( | 1133 void FlowGraphCompiler::GenerateInstanceCall( |
| 1145 intptr_t deopt_id, | 1134 intptr_t deopt_id, |
| 1146 TokenPosition token_pos, | 1135 TokenPosition token_pos, |
| 1147 intptr_t argument_count, | 1136 intptr_t argument_count, |
| 1148 LocationSummary* locs, | 1137 LocationSummary* locs, |
| 1149 const ICData& ic_data_in) { | 1138 const ICData& ic_data_in) { |
| 1150 const ICData& ic_data = ICData::ZoneHandle(ic_data_in.Original()); | 1139 const ICData& ic_data = ICData::ZoneHandle(ic_data_in.Original()); |
| 1151 if (FLAG_precompilation) { | 1140 if (FLAG_precompiled_mode) { |
| 1152 EmitSwitchableInstanceCall(ic_data, argument_count, | 1141 EmitSwitchableInstanceCall(ic_data, argument_count, |
| 1153 deopt_id, token_pos, locs); | 1142 deopt_id, token_pos, locs); |
| 1154 return; | 1143 return; |
| 1155 } | 1144 } |
| 1156 if (FLAG_always_megamorphic_calls) { | 1145 if (FLAG_always_megamorphic_calls) { |
| 1157 EmitMegamorphicInstanceCall(ic_data, argument_count, | 1146 EmitMegamorphicInstanceCall(ic_data, argument_count, |
| 1158 deopt_id, token_pos, locs); | 1147 deopt_id, token_pos, locs); |
| 1159 return; | 1148 return; |
| 1160 } | 1149 } |
| 1161 ASSERT(!ic_data.IsNull()); | 1150 ASSERT(!ic_data.IsNull()); |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 | 1870 |
| 1882 | 1871 |
| 1883 void FlowGraphCompiler::FrameStateClear() { | 1872 void FlowGraphCompiler::FrameStateClear() { |
| 1884 ASSERT(!is_optimizing()); | 1873 ASSERT(!is_optimizing()); |
| 1885 frame_state_.TruncateTo(0); | 1874 frame_state_.TruncateTo(0); |
| 1886 } | 1875 } |
| 1887 #endif | 1876 #endif |
| 1888 | 1877 |
| 1889 | 1878 |
| 1890 } // namespace dart | 1879 } // namespace dart |
| OLD | NEW |