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 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame^] | 21 | #include "runtime.h" |
| 22 | |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 23 | namespace art { |
| 24 | |
| 25 | CompilerOptions::CompilerOptions() |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 26 | : compiler_filter_(CompilerFilter::kDefaultCompilerFilter), |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 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_max_code_units_(kUnsetInlineMaxCodeUnits), |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 33 | no_inline_from_(nullptr), |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 34 | boot_image_(false), |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame^] | 35 | core_image_(false), |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 36 | app_image_(false), |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 37 | top_k_profile_threshold_(kDefaultTopKProfileThreshold), |
Andreas Gampe | 7b2f09e | 2015-03-02 14:07:33 -0800 | [diff] [blame] | 38 | debuggable_(false), |
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), |
Alexey Alexandrov | ab40c11 | 2016-09-19 09:33:49 -0700 | [diff] [blame] | 41 | generate_build_id_(false), |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 42 | implicit_null_checks_(true), |
| 43 | implicit_so_checks_(true), |
| 44 | implicit_suspend_checks_(false), |
| 45 | compile_pic_(false), |
Nicolas Geoffray | 57c4704 | 2017-06-29 11:31:39 +0100 | [diff] [blame] | 46 | verbose_methods_(), |
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_(""), |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 50 | dump_cfg_append_(false), |
Matthew Gharrity | 2cd05b7 | 2016-08-03 16:57:37 -0700 | [diff] [blame] | 51 | force_determinism_(false), |
Wojciech Staszkiewicz | 5319d3c | 2016-08-01 17:48:59 -0700 | [diff] [blame] | 52 | register_allocation_strategy_(RegisterAllocator::kRegisterAllocatorDefault), |
| 53 | passes_to_run_(nullptr) { |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 56 | CompilerOptions::~CompilerOptions() { |
| 57 | // The destructor looks empty but it destroys a PassManagerOptions object. We keep it here |
| 58 | // because we don't want to include the PassManagerOptions definition from the header file. |
| 59 | } |
| 60 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame^] | 61 | bool CompilerOptions::EmitRunTimeChecksInDebugMode() const { |
| 62 | // Run-time checks (e.g. Marking Register checks) are only emitted |
| 63 | // in debug mode, and |
| 64 | // - when running on device; or |
| 65 | // - when running on host, but only |
| 66 | // - when compiling the core image (which is used only for testing); or |
| 67 | // - when JIT compiling (only relevant for non-native methods). |
| 68 | // This is to prevent these checks from being emitted into pre-opted |
| 69 | // boot image or apps, as these are compiled with dex2oatd. |
| 70 | return kIsDebugBuild && |
| 71 | (kIsTargetBuild || IsCoreImage() || Runtime::Current()->UseJitCompilation()); |
| 72 | } |
| 73 | |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 74 | void CompilerOptions::ParseHugeMethodMax(const StringPiece& option, UsageFn Usage) { |
| 75 | ParseUintOption(option, "--huge-method-max", &huge_method_threshold_, Usage); |
| 76 | } |
| 77 | |
| 78 | void CompilerOptions::ParseLargeMethodMax(const StringPiece& option, UsageFn Usage) { |
| 79 | ParseUintOption(option, "--large-method-max", &large_method_threshold_, Usage); |
| 80 | } |
| 81 | |
| 82 | void CompilerOptions::ParseSmallMethodMax(const StringPiece& option, UsageFn Usage) { |
| 83 | ParseUintOption(option, "--small-method-max", &small_method_threshold_, Usage); |
| 84 | } |
| 85 | |
| 86 | void CompilerOptions::ParseTinyMethodMax(const StringPiece& option, UsageFn Usage) { |
| 87 | ParseUintOption(option, "--tiny-method-max", &tiny_method_threshold_, Usage); |
| 88 | } |
| 89 | |
| 90 | void CompilerOptions::ParseNumDexMethods(const StringPiece& option, UsageFn Usage) { |
| 91 | ParseUintOption(option, "--num-dex-methods", &num_dex_methods_threshold_, Usage); |
| 92 | } |
| 93 | |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 94 | void CompilerOptions::ParseInlineMaxCodeUnits(const StringPiece& option, UsageFn Usage) { |
Nicolas Geoffray | 18c12bb | 2015-12-15 12:09:43 +0000 | [diff] [blame] | 95 | ParseUintOption(option, "--inline-max-code-units", &inline_max_code_units_, Usage); |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 98 | void CompilerOptions::ParseDumpInitFailures(const StringPiece& option, |
| 99 | UsageFn Usage ATTRIBUTE_UNUSED) { |
| 100 | DCHECK(option.starts_with("--dump-init-failures=")); |
| 101 | std::string file_name = option.substr(strlen("--dump-init-failures=")).data(); |
| 102 | init_failure_output_.reset(new std::ofstream(file_name)); |
| 103 | if (init_failure_output_.get() == nullptr) { |
| 104 | LOG(ERROR) << "Failed to allocate ofstream"; |
| 105 | } else if (init_failure_output_->fail()) { |
| 106 | LOG(ERROR) << "Failed to open " << file_name << " for writing the initialization " |
| 107 | << "failures."; |
| 108 | init_failure_output_.reset(); |
| 109 | } |
| 110 | } |
| 111 | |
Matthew Gharrity | 2cd05b7 | 2016-08-03 16:57:37 -0700 | [diff] [blame] | 112 | void CompilerOptions::ParseRegisterAllocationStrategy(const StringPiece& option, |
| 113 | UsageFn Usage) { |
| 114 | DCHECK(option.starts_with("--register-allocation-strategy=")); |
| 115 | StringPiece choice = option.substr(strlen("--register-allocation-strategy=")).data(); |
| 116 | if (choice == "linear-scan") { |
| 117 | register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorLinearScan; |
| 118 | } else if (choice == "graph-color") { |
| 119 | register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorGraphColor; |
| 120 | } else { |
| 121 | Usage("Unrecognized register allocation strategy. Try linear-scan, or graph-color."); |
| 122 | } |
| 123 | } |
| 124 | |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 125 | bool CompilerOptions::ParseCompilerOption(const StringPiece& option, UsageFn Usage) { |
| 126 | if (option.starts_with("--compiler-filter=")) { |
| 127 | const char* compiler_filter_string = option.substr(strlen("--compiler-filter=")).data(); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 128 | if (!CompilerFilter::ParseCompilerFilter(compiler_filter_string, &compiler_filter_)) { |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 129 | Usage("Unknown --compiler-filter value %s", compiler_filter_string); |
| 130 | } |
| 131 | } else if (option == "--compile-pic") { |
| 132 | compile_pic_ = true; |
| 133 | } else if (option.starts_with("--huge-method-max=")) { |
| 134 | ParseHugeMethodMax(option, Usage); |
| 135 | } else if (option.starts_with("--large-method-max=")) { |
| 136 | ParseLargeMethodMax(option, Usage); |
| 137 | } else if (option.starts_with("--small-method-max=")) { |
| 138 | ParseSmallMethodMax(option, Usage); |
| 139 | } else if (option.starts_with("--tiny-method-max=")) { |
| 140 | ParseTinyMethodMax(option, Usage); |
| 141 | } else if (option.starts_with("--num-dex-methods=")) { |
| 142 | ParseNumDexMethods(option, Usage); |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 143 | } else if (option.starts_with("--inline-max-code-units=")) { |
| 144 | ParseInlineMaxCodeUnits(option, Usage); |
| 145 | } else if (option == "--generate-debug-info" || option == "-g") { |
| 146 | generate_debug_info_ = true; |
| 147 | } else if (option == "--no-generate-debug-info") { |
| 148 | generate_debug_info_ = false; |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame] | 149 | } else if (option == "--generate-mini-debug-info") { |
| 150 | generate_mini_debug_info_ = true; |
| 151 | } else if (option == "--no-generate-mini-debug-info") { |
| 152 | generate_mini_debug_info_ = false; |
Alexey Alexandrov | ab40c11 | 2016-09-19 09:33:49 -0700 | [diff] [blame] | 153 | } else if (option == "--generate-build-id") { |
| 154 | generate_build_id_ = true; |
| 155 | } else if (option == "--no-generate-build-id") { |
| 156 | generate_build_id_ = false; |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 157 | } else if (option == "--debuggable") { |
| 158 | debuggable_ = true; |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 159 | } else if (option.starts_with("--top-k-profile-threshold=")) { |
| 160 | ParseDouble(option.data(), '=', 0.0, 100.0, &top_k_profile_threshold_, Usage); |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 161 | } else if (option == "--abort-on-hard-verifier-error") { |
| 162 | abort_on_hard_verifier_failure_ = true; |
Andreas Gampe | fdfb4d4 | 2017-07-27 12:12:22 -0700 | [diff] [blame] | 163 | } else if (option == "--no-abort-on-hard-verifier-error") { |
| 164 | abort_on_hard_verifier_failure_ = false; |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 165 | } else if (option.starts_with("--dump-init-failures=")) { |
| 166 | ParseDumpInitFailures(option, Usage); |
Nicolas Geoffray | c903b6a | 2016-01-18 12:56:06 +0000 | [diff] [blame] | 167 | } else if (option.starts_with("--dump-cfg=")) { |
| 168 | dump_cfg_file_name_ = option.substr(strlen("--dump-cfg=")).data(); |
Roland Levillain | f5bea5e | 2017-05-02 12:46:07 +0100 | [diff] [blame] | 169 | } else if (option == "--dump-cfg-append") { |
Nicolas Geoffray | c903b6a | 2016-01-18 12:56:06 +0000 | [diff] [blame] | 170 | dump_cfg_append_ = true; |
Matthew Gharrity | 2cd05b7 | 2016-08-03 16:57:37 -0700 | [diff] [blame] | 171 | } else if (option.starts_with("--register-allocation-strategy=")) { |
| 172 | ParseRegisterAllocationStrategy(option, Usage); |
Nicolas Geoffray | 57c4704 | 2017-06-29 11:31:39 +0100 | [diff] [blame] | 173 | } else if (option.starts_with("--verbose-methods=")) { |
| 174 | // TODO: rather than switch off compiler logging, make all VLOG(compiler) messages |
| 175 | // conditional on having verbose methods. |
| 176 | gLogVerbosity.compiler = false; |
| 177 | Split(option.substr(strlen("--verbose-methods=")).ToString(), ',', &verbose_methods_); |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 178 | } else { |
| 179 | // Option not recognized. |
| 180 | return false; |
| 181 | } |
| 182 | return true; |
| 183 | } |
| 184 | |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 185 | } // namespace art |