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 | namespace art { |
| 22 | |
| 23 | CompilerOptions::CompilerOptions() |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 24 | : compiler_filter_(CompilerFilter::kDefaultCompilerFilter), |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 25 | huge_method_threshold_(kDefaultHugeMethodThreshold), |
| 26 | large_method_threshold_(kDefaultLargeMethodThreshold), |
| 27 | small_method_threshold_(kDefaultSmallMethodThreshold), |
| 28 | tiny_method_threshold_(kDefaultTinyMethodThreshold), |
| 29 | num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold), |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 30 | inline_depth_limit_(kUnsetInlineDepthLimit), |
| 31 | inline_max_code_units_(kUnsetInlineMaxCodeUnits), |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 32 | no_inline_from_(nullptr), |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 33 | boot_image_(false), |
| 34 | app_image_(false), |
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 | 8363c77 | 2015-05-28 16:12:43 +0100 | [diff] [blame] | 38 | generate_debug_info_(kDefaultGenerateDebugInfo), |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame] | 39 | generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo), |
Alexey Alexandrov | ab40c11 | 2016-09-19 09:33:49 -0700 | [diff] [blame] | 40 | generate_build_id_(false), |
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), |
Andreas Gampe | 6cf49e5 | 2015-03-05 13:08:45 -0800 | [diff] [blame] | 46 | abort_on_hard_verifier_failure_(false), |
Nicolas Geoffray | c903b6a | 2016-01-18 12:56:06 +0000 | [diff] [blame] | 47 | init_failure_output_(nullptr), |
| 48 | dump_cfg_file_name_(""), |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 49 | dump_cfg_append_(false), |
Matthew Gharrity | 2cd05b7 | 2016-08-03 16:57:37 -0700 | [diff] [blame] | 50 | force_determinism_(false), |
Wojciech Staszkiewicz | 5319d3c | 2016-08-01 17:48:59 -0700 | [diff] [blame] | 51 | register_allocation_strategy_(RegisterAllocator::kRegisterAllocatorDefault), |
| 52 | passes_to_run_(nullptr) { |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 55 | CompilerOptions::~CompilerOptions() { |
| 56 | // The destructor looks empty but it destroys a PassManagerOptions object. We keep it here |
| 57 | // because we don't want to include the PassManagerOptions definition from the header file. |
| 58 | } |
| 59 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 60 | CompilerOptions::CompilerOptions(CompilerFilter::Filter compiler_filter, |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 61 | size_t huge_method_threshold, |
| 62 | size_t large_method_threshold, |
| 63 | size_t small_method_threshold, |
| 64 | size_t tiny_method_threshold, |
| 65 | size_t num_dex_methods_threshold, |
Calin Juravle | ec74835 | 2015-07-29 13:52:12 +0100 | [diff] [blame] | 66 | size_t inline_depth_limit, |
| 67 | size_t inline_max_code_units, |
Vladimir Marko | 47496c2 | 2016-01-27 16:15:08 +0000 | [diff] [blame] | 68 | const std::vector<const DexFile*>* no_inline_from, |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 69 | bool include_patch_information, |
| 70 | double top_k_profile_threshold, |
Andreas Gampe | 7b2f09e | 2015-03-02 14:07:33 -0800 | [diff] [blame] | 71 | bool debuggable, |
David Srbecky | 8363c77 | 2015-05-28 16:12:43 +0100 | [diff] [blame] | 72 | bool generate_debug_info, |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 73 | bool implicit_null_checks, |
| 74 | bool implicit_so_checks, |
| 75 | bool implicit_suspend_checks, |
| 76 | bool compile_pic, |
| 77 | const std::vector<std::string>* verbose_methods, |
Andreas Gampe | 6cf49e5 | 2015-03-05 13:08:45 -0800 | [diff] [blame] | 78 | std::ostream* init_failure_output, |
Nicolas Geoffray | c903b6a | 2016-01-18 12:56:06 +0000 | [diff] [blame] | 79 | bool abort_on_hard_verifier_failure, |
| 80 | const std::string& dump_cfg_file_name, |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 81 | bool dump_cfg_append, |
Matthew Gharrity | 2cd05b7 | 2016-08-03 16:57:37 -0700 | [diff] [blame] | 82 | bool force_determinism, |
Wojciech Staszkiewicz | 5319d3c | 2016-08-01 17:48:59 -0700 | [diff] [blame] | 83 | RegisterAllocator::Strategy regalloc_strategy, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 84 | const std::vector<std::string>* passes_to_run) |
| 85 | : compiler_filter_(compiler_filter), |
| 86 | huge_method_threshold_(huge_method_threshold), |
| 87 | large_method_threshold_(large_method_threshold), |
| 88 | small_method_threshold_(small_method_threshold), |
| 89 | tiny_method_threshold_(tiny_method_threshold), |
| 90 | num_dex_methods_threshold_(num_dex_methods_threshold), |
| 91 | inline_depth_limit_(inline_depth_limit), |
| 92 | inline_max_code_units_(inline_max_code_units), |
| 93 | no_inline_from_(no_inline_from), |
| 94 | boot_image_(false), |
| 95 | app_image_(false), |
| 96 | include_patch_information_(include_patch_information), |
| 97 | top_k_profile_threshold_(top_k_profile_threshold), |
| 98 | debuggable_(debuggable), |
| 99 | generate_debug_info_(generate_debug_info), |
| 100 | generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo), |
Alexey Alexandrov | ab40c11 | 2016-09-19 09:33:49 -0700 | [diff] [blame] | 101 | generate_build_id_(false), |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 102 | implicit_null_checks_(implicit_null_checks), |
| 103 | implicit_so_checks_(implicit_so_checks), |
| 104 | implicit_suspend_checks_(implicit_suspend_checks), |
| 105 | compile_pic_(compile_pic), |
| 106 | verbose_methods_(verbose_methods), |
| 107 | abort_on_hard_verifier_failure_(abort_on_hard_verifier_failure), |
| 108 | init_failure_output_(init_failure_output), |
| 109 | dump_cfg_file_name_(dump_cfg_file_name), |
| 110 | dump_cfg_append_(dump_cfg_append), |
| 111 | force_determinism_(force_determinism), |
| 112 | register_allocation_strategy_(regalloc_strategy), |
| 113 | passes_to_run_(passes_to_run) { |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 116 | void CompilerOptions::ParseHugeMethodMax(const StringPiece& option, UsageFn Usage) { |
| 117 | ParseUintOption(option, "--huge-method-max", &huge_method_threshold_, Usage); |
| 118 | } |
| 119 | |
| 120 | void CompilerOptions::ParseLargeMethodMax(const StringPiece& option, UsageFn Usage) { |
| 121 | ParseUintOption(option, "--large-method-max", &large_method_threshold_, Usage); |
| 122 | } |
| 123 | |
| 124 | void CompilerOptions::ParseSmallMethodMax(const StringPiece& option, UsageFn Usage) { |
| 125 | ParseUintOption(option, "--small-method-max", &small_method_threshold_, Usage); |
| 126 | } |
| 127 | |
| 128 | void CompilerOptions::ParseTinyMethodMax(const StringPiece& option, UsageFn Usage) { |
| 129 | ParseUintOption(option, "--tiny-method-max", &tiny_method_threshold_, Usage); |
| 130 | } |
| 131 | |
| 132 | void CompilerOptions::ParseNumDexMethods(const StringPiece& option, UsageFn Usage) { |
| 133 | ParseUintOption(option, "--num-dex-methods", &num_dex_methods_threshold_, Usage); |
| 134 | } |
| 135 | |
| 136 | void CompilerOptions::ParseInlineDepthLimit(const StringPiece& option, UsageFn Usage) { |
| 137 | ParseUintOption(option, "--inline-depth-limit", &inline_depth_limit_, Usage); |
| 138 | } |
| 139 | |
| 140 | void CompilerOptions::ParseInlineMaxCodeUnits(const StringPiece& option, UsageFn Usage) { |
Nicolas Geoffray | 18c12bb | 2015-12-15 12:09:43 +0000 | [diff] [blame] | 141 | ParseUintOption(option, "--inline-max-code-units", &inline_max_code_units_, Usage); |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 144 | void CompilerOptions::ParseDumpInitFailures(const StringPiece& option, |
| 145 | UsageFn Usage ATTRIBUTE_UNUSED) { |
| 146 | DCHECK(option.starts_with("--dump-init-failures=")); |
| 147 | std::string file_name = option.substr(strlen("--dump-init-failures=")).data(); |
| 148 | init_failure_output_.reset(new std::ofstream(file_name)); |
| 149 | if (init_failure_output_.get() == nullptr) { |
| 150 | LOG(ERROR) << "Failed to allocate ofstream"; |
| 151 | } else if (init_failure_output_->fail()) { |
| 152 | LOG(ERROR) << "Failed to open " << file_name << " for writing the initialization " |
| 153 | << "failures."; |
| 154 | init_failure_output_.reset(); |
| 155 | } |
| 156 | } |
| 157 | |
Matthew Gharrity | 2cd05b7 | 2016-08-03 16:57:37 -0700 | [diff] [blame] | 158 | void CompilerOptions::ParseRegisterAllocationStrategy(const StringPiece& option, |
| 159 | UsageFn Usage) { |
| 160 | DCHECK(option.starts_with("--register-allocation-strategy=")); |
| 161 | StringPiece choice = option.substr(strlen("--register-allocation-strategy=")).data(); |
| 162 | if (choice == "linear-scan") { |
| 163 | register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorLinearScan; |
| 164 | } else if (choice == "graph-color") { |
| 165 | register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorGraphColor; |
| 166 | } else { |
| 167 | Usage("Unrecognized register allocation strategy. Try linear-scan, or graph-color."); |
| 168 | } |
| 169 | } |
| 170 | |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 171 | bool CompilerOptions::ParseCompilerOption(const StringPiece& option, UsageFn Usage) { |
| 172 | if (option.starts_with("--compiler-filter=")) { |
| 173 | const char* compiler_filter_string = option.substr(strlen("--compiler-filter=")).data(); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 174 | if (!CompilerFilter::ParseCompilerFilter(compiler_filter_string, &compiler_filter_)) { |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 175 | Usage("Unknown --compiler-filter value %s", compiler_filter_string); |
| 176 | } |
| 177 | } else if (option == "--compile-pic") { |
| 178 | compile_pic_ = true; |
| 179 | } else if (option.starts_with("--huge-method-max=")) { |
| 180 | ParseHugeMethodMax(option, Usage); |
| 181 | } else if (option.starts_with("--large-method-max=")) { |
| 182 | ParseLargeMethodMax(option, Usage); |
| 183 | } else if (option.starts_with("--small-method-max=")) { |
| 184 | ParseSmallMethodMax(option, Usage); |
| 185 | } else if (option.starts_with("--tiny-method-max=")) { |
| 186 | ParseTinyMethodMax(option, Usage); |
| 187 | } else if (option.starts_with("--num-dex-methods=")) { |
| 188 | ParseNumDexMethods(option, Usage); |
| 189 | } else if (option.starts_with("--inline-depth-limit=")) { |
| 190 | ParseInlineDepthLimit(option, Usage); |
| 191 | } else if (option.starts_with("--inline-max-code-units=")) { |
| 192 | ParseInlineMaxCodeUnits(option, Usage); |
| 193 | } else if (option == "--generate-debug-info" || option == "-g") { |
| 194 | generate_debug_info_ = true; |
| 195 | } else if (option == "--no-generate-debug-info") { |
| 196 | generate_debug_info_ = false; |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame] | 197 | } else if (option == "--generate-mini-debug-info") { |
| 198 | generate_mini_debug_info_ = true; |
| 199 | } else if (option == "--no-generate-mini-debug-info") { |
| 200 | generate_mini_debug_info_ = false; |
Alexey Alexandrov | ab40c11 | 2016-09-19 09:33:49 -0700 | [diff] [blame] | 201 | } else if (option == "--generate-build-id") { |
| 202 | generate_build_id_ = true; |
| 203 | } else if (option == "--no-generate-build-id") { |
| 204 | generate_build_id_ = false; |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 205 | } else if (option == "--debuggable") { |
| 206 | debuggable_ = true; |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 207 | } else if (option.starts_with("--top-k-profile-threshold=")) { |
| 208 | ParseDouble(option.data(), '=', 0.0, 100.0, &top_k_profile_threshold_, Usage); |
| 209 | } else if (option == "--include-patch-information") { |
| 210 | include_patch_information_ = true; |
| 211 | } else if (option == "--no-include-patch-information") { |
| 212 | include_patch_information_ = false; |
| 213 | } else if (option == "--abort-on-hard-verifier-error") { |
| 214 | abort_on_hard_verifier_failure_ = true; |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 215 | } else if (option.starts_with("--dump-init-failures=")) { |
| 216 | ParseDumpInitFailures(option, Usage); |
Nicolas Geoffray | c903b6a | 2016-01-18 12:56:06 +0000 | [diff] [blame] | 217 | } else if (option.starts_with("--dump-cfg=")) { |
| 218 | dump_cfg_file_name_ = option.substr(strlen("--dump-cfg=")).data(); |
| 219 | } else if (option.starts_with("--dump-cfg-append")) { |
| 220 | dump_cfg_append_ = true; |
Matthew Gharrity | 2cd05b7 | 2016-08-03 16:57:37 -0700 | [diff] [blame] | 221 | } else if (option.starts_with("--register-allocation-strategy=")) { |
| 222 | ParseRegisterAllocationStrategy(option, Usage); |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 223 | } else { |
| 224 | // Option not recognized. |
| 225 | return false; |
| 226 | } |
| 227 | return true; |
| 228 | } |
| 229 | |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 230 | } // namespace art |