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