Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "compiler_options.h" |
| 18 | |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 19 | #include <fstream> |
| 20 | |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 21 | #include "dex/pass_manager.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | CompilerOptions::CompilerOptions() |
| 26 | : compiler_filter_(kDefaultCompilerFilter), |
| 27 | huge_method_threshold_(kDefaultHugeMethodThreshold), |
| 28 | large_method_threshold_(kDefaultLargeMethodThreshold), |
| 29 | small_method_threshold_(kDefaultSmallMethodThreshold), |
| 30 | tiny_method_threshold_(kDefaultTinyMethodThreshold), |
| 31 | num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold), |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 32 | inline_depth_limit_(kUnsetInlineDepthLimit), |
| 33 | inline_max_code_units_(kUnsetInlineMaxCodeUnits), |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 34 | no_inline_from_(nullptr), |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 35 | include_patch_information_(kDefaultIncludePatchInformation), |
| 36 | top_k_profile_threshold_(kDefaultTopKProfileThreshold), |
Andreas Gampe | 7b2f09e | 2015-03-02 14:07:33 -0800 | [diff] [blame] | 37 | debuggable_(false), |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 38 | native_debuggable_(kDefaultNativeDebuggable), |
David Srbecky | 8363c77 | 2015-05-28 16:12:43 +0100 | [diff] [blame] | 39 | generate_debug_info_(kDefaultGenerateDebugInfo), |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame^] | 40 | generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo), |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 41 | implicit_null_checks_(true), |
| 42 | implicit_so_checks_(true), |
| 43 | implicit_suspend_checks_(false), |
| 44 | compile_pic_(false), |
| 45 | verbose_methods_(nullptr), |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 46 | pass_manager_options_(), |
Andreas Gampe | 6cf49e5 | 2015-03-05 13:08:45 -0800 | [diff] [blame] | 47 | abort_on_hard_verifier_failure_(false), |
Nicolas Geoffray | c903b6a | 2016-01-18 12:56:06 +0000 | [diff] [blame] | 48 | init_failure_output_(nullptr), |
| 49 | dump_cfg_file_name_(""), |
| 50 | dump_cfg_append_(false) { |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 53 | CompilerOptions::~CompilerOptions() { |
| 54 | // The destructor looks empty but it destroys a PassManagerOptions object. We keep it here |
| 55 | // because we don't want to include the PassManagerOptions definition from the header file. |
| 56 | } |
| 57 | |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 58 | CompilerOptions::CompilerOptions(CompilerFilter compiler_filter, |
| 59 | size_t huge_method_threshold, |
| 60 | size_t large_method_threshold, |
| 61 | size_t small_method_threshold, |
| 62 | size_t tiny_method_threshold, |
| 63 | size_t num_dex_methods_threshold, |
Calin Juravle | ec74835 | 2015-07-29 13:52:12 +0100 | [diff] [blame] | 64 | size_t inline_depth_limit, |
| 65 | size_t inline_max_code_units, |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 66 | const DexFile* no_inline_from, |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 67 | bool include_patch_information, |
| 68 | double top_k_profile_threshold, |
Andreas Gampe | 7b2f09e | 2015-03-02 14:07:33 -0800 | [diff] [blame] | 69 | bool debuggable, |
David Srbecky | 8363c77 | 2015-05-28 16:12:43 +0100 | [diff] [blame] | 70 | bool generate_debug_info, |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 71 | bool implicit_null_checks, |
| 72 | bool implicit_so_checks, |
| 73 | bool implicit_suspend_checks, |
| 74 | bool compile_pic, |
| 75 | const std::vector<std::string>* verbose_methods, |
Andreas Gampe | 6cf49e5 | 2015-03-05 13:08:45 -0800 | [diff] [blame] | 76 | std::ostream* init_failure_output, |
Nicolas Geoffray | c903b6a | 2016-01-18 12:56:06 +0000 | [diff] [blame] | 77 | bool abort_on_hard_verifier_failure, |
| 78 | const std::string& dump_cfg_file_name, |
| 79 | bool dump_cfg_append |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 80 | ) : // NOLINT(whitespace/parens) |
| 81 | compiler_filter_(compiler_filter), |
| 82 | huge_method_threshold_(huge_method_threshold), |
| 83 | large_method_threshold_(large_method_threshold), |
| 84 | small_method_threshold_(small_method_threshold), |
| 85 | tiny_method_threshold_(tiny_method_threshold), |
| 86 | num_dex_methods_threshold_(num_dex_methods_threshold), |
Calin Juravle | ec74835 | 2015-07-29 13:52:12 +0100 | [diff] [blame] | 87 | inline_depth_limit_(inline_depth_limit), |
| 88 | inline_max_code_units_(inline_max_code_units), |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 89 | no_inline_from_(no_inline_from), |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 90 | include_patch_information_(include_patch_information), |
| 91 | top_k_profile_threshold_(top_k_profile_threshold), |
Andreas Gampe | 7b2f09e | 2015-03-02 14:07:33 -0800 | [diff] [blame] | 92 | debuggable_(debuggable), |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 93 | native_debuggable_(kDefaultNativeDebuggable), |
David Srbecky | 8363c77 | 2015-05-28 16:12:43 +0100 | [diff] [blame] | 94 | generate_debug_info_(generate_debug_info), |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame^] | 95 | generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo), |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 96 | implicit_null_checks_(implicit_null_checks), |
| 97 | implicit_so_checks_(implicit_so_checks), |
| 98 | implicit_suspend_checks_(implicit_suspend_checks), |
| 99 | compile_pic_(compile_pic), |
| 100 | verbose_methods_(verbose_methods), |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 101 | pass_manager_options_(), |
Andreas Gampe | 6cf49e5 | 2015-03-05 13:08:45 -0800 | [diff] [blame] | 102 | abort_on_hard_verifier_failure_(abort_on_hard_verifier_failure), |
Nicolas Geoffray | c903b6a | 2016-01-18 12:56:06 +0000 | [diff] [blame] | 103 | init_failure_output_(init_failure_output), |
| 104 | dump_cfg_file_name_(dump_cfg_file_name), |
| 105 | dump_cfg_append_(dump_cfg_append) { |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 108 | void CompilerOptions::ParseHugeMethodMax(const StringPiece& option, UsageFn Usage) { |
| 109 | ParseUintOption(option, "--huge-method-max", &huge_method_threshold_, Usage); |
| 110 | } |
| 111 | |
| 112 | void CompilerOptions::ParseLargeMethodMax(const StringPiece& option, UsageFn Usage) { |
| 113 | ParseUintOption(option, "--large-method-max", &large_method_threshold_, Usage); |
| 114 | } |
| 115 | |
| 116 | void CompilerOptions::ParseSmallMethodMax(const StringPiece& option, UsageFn Usage) { |
| 117 | ParseUintOption(option, "--small-method-max", &small_method_threshold_, Usage); |
| 118 | } |
| 119 | |
| 120 | void CompilerOptions::ParseTinyMethodMax(const StringPiece& option, UsageFn Usage) { |
| 121 | ParseUintOption(option, "--tiny-method-max", &tiny_method_threshold_, Usage); |
| 122 | } |
| 123 | |
| 124 | void CompilerOptions::ParseNumDexMethods(const StringPiece& option, UsageFn Usage) { |
| 125 | ParseUintOption(option, "--num-dex-methods", &num_dex_methods_threshold_, Usage); |
| 126 | } |
| 127 | |
| 128 | void CompilerOptions::ParseInlineDepthLimit(const StringPiece& option, UsageFn Usage) { |
| 129 | ParseUintOption(option, "--inline-depth-limit", &inline_depth_limit_, Usage); |
| 130 | } |
| 131 | |
| 132 | void CompilerOptions::ParseInlineMaxCodeUnits(const StringPiece& option, UsageFn Usage) { |
Nicolas Geoffray | 18c12bb | 2015-12-15 12:09:43 +0000 | [diff] [blame] | 133 | ParseUintOption(option, "--inline-max-code-units", &inline_max_code_units_, Usage); |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void CompilerOptions::ParseDisablePasses(const StringPiece& option, |
| 137 | UsageFn Usage ATTRIBUTE_UNUSED) { |
| 138 | DCHECK(option.starts_with("--disable-passes=")); |
| 139 | const std::string disable_passes = option.substr(strlen("--disable-passes=")).data(); |
| 140 | pass_manager_options_.SetDisablePassList(disable_passes); |
| 141 | } |
| 142 | |
| 143 | void CompilerOptions::ParsePrintPasses(const StringPiece& option, |
| 144 | UsageFn Usage ATTRIBUTE_UNUSED) { |
| 145 | DCHECK(option.starts_with("--print-passes=")); |
| 146 | const std::string print_passes = option.substr(strlen("--print-passes=")).data(); |
| 147 | pass_manager_options_.SetPrintPassList(print_passes); |
| 148 | } |
| 149 | |
| 150 | void CompilerOptions::ParseDumpCfgPasses(const StringPiece& option, |
| 151 | UsageFn Usage ATTRIBUTE_UNUSED) { |
| 152 | DCHECK(option.starts_with("--dump-cfg-passes=")); |
| 153 | const std::string dump_passes_string = option.substr(strlen("--dump-cfg-passes=")).data(); |
| 154 | pass_manager_options_.SetDumpPassList(dump_passes_string); |
| 155 | } |
| 156 | |
| 157 | void CompilerOptions::ParsePassOptions(const StringPiece& option, |
| 158 | UsageFn Usage ATTRIBUTE_UNUSED) { |
| 159 | DCHECK(option.starts_with("--pass-options=")); |
| 160 | const std::string pass_options = option.substr(strlen("--pass-options=")).data(); |
| 161 | pass_manager_options_.SetOverriddenPassOptions(pass_options); |
| 162 | } |
| 163 | |
| 164 | void CompilerOptions::ParseDumpInitFailures(const StringPiece& option, |
| 165 | UsageFn Usage ATTRIBUTE_UNUSED) { |
| 166 | DCHECK(option.starts_with("--dump-init-failures=")); |
| 167 | std::string file_name = option.substr(strlen("--dump-init-failures=")).data(); |
| 168 | init_failure_output_.reset(new std::ofstream(file_name)); |
| 169 | if (init_failure_output_.get() == nullptr) { |
| 170 | LOG(ERROR) << "Failed to allocate ofstream"; |
| 171 | } else if (init_failure_output_->fail()) { |
| 172 | LOG(ERROR) << "Failed to open " << file_name << " for writing the initialization " |
| 173 | << "failures."; |
| 174 | init_failure_output_.reset(); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | bool CompilerOptions::ParseCompilerOption(const StringPiece& option, UsageFn Usage) { |
| 179 | if (option.starts_with("--compiler-filter=")) { |
| 180 | const char* compiler_filter_string = option.substr(strlen("--compiler-filter=")).data(); |
| 181 | if (strcmp(compiler_filter_string, "verify-none") == 0) { |
| 182 | compiler_filter_ = CompilerOptions::kVerifyNone; |
| 183 | } else if (strcmp(compiler_filter_string, "interpret-only") == 0) { |
| 184 | compiler_filter_ = CompilerOptions::kInterpretOnly; |
| 185 | } else if (strcmp(compiler_filter_string, "verify-at-runtime") == 0) { |
| 186 | compiler_filter_ = CompilerOptions::kVerifyAtRuntime; |
| 187 | } else if (strcmp(compiler_filter_string, "space") == 0) { |
| 188 | compiler_filter_ = CompilerOptions::kSpace; |
| 189 | } else if (strcmp(compiler_filter_string, "balanced") == 0) { |
| 190 | compiler_filter_ = CompilerOptions::kBalanced; |
| 191 | } else if (strcmp(compiler_filter_string, "speed") == 0) { |
| 192 | compiler_filter_ = CompilerOptions::kSpeed; |
| 193 | } else if (strcmp(compiler_filter_string, "everything") == 0) { |
| 194 | compiler_filter_ = CompilerOptions::kEverything; |
| 195 | } else if (strcmp(compiler_filter_string, "time") == 0) { |
| 196 | compiler_filter_ = CompilerOptions::kTime; |
| 197 | } else { |
| 198 | Usage("Unknown --compiler-filter value %s", compiler_filter_string); |
| 199 | } |
| 200 | } else if (option == "--compile-pic") { |
| 201 | compile_pic_ = true; |
| 202 | } else if (option.starts_with("--huge-method-max=")) { |
| 203 | ParseHugeMethodMax(option, Usage); |
| 204 | } else if (option.starts_with("--large-method-max=")) { |
| 205 | ParseLargeMethodMax(option, Usage); |
| 206 | } else if (option.starts_with("--small-method-max=")) { |
| 207 | ParseSmallMethodMax(option, Usage); |
| 208 | } else if (option.starts_with("--tiny-method-max=")) { |
| 209 | ParseTinyMethodMax(option, Usage); |
| 210 | } else if (option.starts_with("--num-dex-methods=")) { |
| 211 | ParseNumDexMethods(option, Usage); |
| 212 | } else if (option.starts_with("--inline-depth-limit=")) { |
| 213 | ParseInlineDepthLimit(option, Usage); |
| 214 | } else if (option.starts_with("--inline-max-code-units=")) { |
| 215 | ParseInlineMaxCodeUnits(option, Usage); |
| 216 | } else if (option == "--generate-debug-info" || option == "-g") { |
| 217 | generate_debug_info_ = true; |
| 218 | } else if (option == "--no-generate-debug-info") { |
| 219 | generate_debug_info_ = false; |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame^] | 220 | } else if (option == "--generate-mini-debug-info") { |
| 221 | generate_mini_debug_info_ = true; |
| 222 | } else if (option == "--no-generate-mini-debug-info") { |
| 223 | generate_mini_debug_info_ = false; |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 224 | } else if (option == "--debuggable") { |
| 225 | debuggable_ = true; |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 226 | } else if (option == "--native-debuggable") { |
| 227 | native_debuggable_ = true; |
| 228 | debuggable_ = true; |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 229 | } else if (option.starts_with("--top-k-profile-threshold=")) { |
| 230 | ParseDouble(option.data(), '=', 0.0, 100.0, &top_k_profile_threshold_, Usage); |
| 231 | } else if (option == "--include-patch-information") { |
| 232 | include_patch_information_ = true; |
| 233 | } else if (option == "--no-include-patch-information") { |
| 234 | include_patch_information_ = false; |
| 235 | } else if (option == "--abort-on-hard-verifier-error") { |
| 236 | abort_on_hard_verifier_failure_ = true; |
| 237 | } else if (option == "--print-pass-names") { |
| 238 | pass_manager_options_.SetPrintPassNames(true); |
| 239 | } else if (option.starts_with("--disable-passes=")) { |
| 240 | ParseDisablePasses(option, Usage); |
| 241 | } else if (option.starts_with("--print-passes=")) { |
| 242 | ParsePrintPasses(option, Usage); |
| 243 | } else if (option == "--print-all-passes") { |
| 244 | pass_manager_options_.SetPrintAllPasses(); |
| 245 | } else if (option.starts_with("--dump-cfg-passes=")) { |
| 246 | ParseDumpCfgPasses(option, Usage); |
| 247 | } else if (option == "--print-pass-options") { |
| 248 | pass_manager_options_.SetPrintPassOptions(true); |
| 249 | } else if (option.starts_with("--pass-options=")) { |
| 250 | ParsePassOptions(option, Usage); |
| 251 | } else if (option.starts_with("--dump-init-failures=")) { |
| 252 | ParseDumpInitFailures(option, Usage); |
Nicolas Geoffray | c903b6a | 2016-01-18 12:56:06 +0000 | [diff] [blame] | 253 | } else if (option.starts_with("--dump-cfg=")) { |
| 254 | dump_cfg_file_name_ = option.substr(strlen("--dump-cfg=")).data(); |
| 255 | } else if (option.starts_with("--dump-cfg-append")) { |
| 256 | dump_cfg_append_ = true; |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 257 | } else { |
| 258 | // Option not recognized. |
| 259 | return false; |
| 260 | } |
| 261 | return true; |
| 262 | } |
| 263 | |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 264 | } // namespace art |