Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #ifndef ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_ |
| 18 | #define ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_ |
| 19 | |
| 20 | #include "compiler_options_map.h" |
| 21 | |
| 22 | #include <memory> |
| 23 | |
| 24 | #include "android-base/logging.h" |
| 25 | #include "android-base/macros.h" |
| 26 | #include "android-base/stringprintf.h" |
| 27 | |
| 28 | #include "base/macros.h" |
| 29 | #include "cmdline_parser.h" |
| 30 | #include "compiler_options.h" |
| 31 | |
| 32 | namespace art { |
| 33 | |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 34 | template <> |
| 35 | struct CmdlineType<CompilerFilter::Filter> : CmdlineTypeParser<CompilerFilter::Filter> { |
| 36 | Result Parse(const std::string& option) { |
| 37 | CompilerFilter::Filter compiler_filter; |
| 38 | if (!CompilerFilter::ParseCompilerFilter(option.c_str(), &compiler_filter)) { |
| 39 | return Result::Failure( |
| 40 | android::base::StringPrintf("Unknown --compiler-filter value %s", option.c_str())); |
| 41 | } |
| 42 | return Result::Success(compiler_filter); |
| 43 | } |
| 44 | |
| 45 | static const char* Name() { |
| 46 | return "CompilerFilter"; |
| 47 | } |
| 48 | static const char* DescribeType() { |
| 49 | return CompilerFilter::DescribeOptions(); |
| 50 | } |
| 51 | }; |
| 52 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 53 | template <class Base> |
| 54 | inline bool ReadCompilerOptions(Base& map, CompilerOptions* options, std::string* error_msg) { |
| 55 | if (map.Exists(Base::CompilerFilter)) { |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 56 | options->SetCompilerFilter(*map.Get(Base::CompilerFilter)); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 57 | } |
David Srbecky | 4fa07a5 | 2020-03-31 20:52:09 +0100 | [diff] [blame] | 58 | map.AssignIfExists(Base::CompileArtTest, &options->compile_art_test_); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 59 | map.AssignIfExists(Base::HugeMethodMaxThreshold, &options->huge_method_threshold_); |
| 60 | map.AssignIfExists(Base::LargeMethodMaxThreshold, &options->large_method_threshold_); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 61 | map.AssignIfExists(Base::NumDexMethodsThreshold, &options->num_dex_methods_threshold_); |
| 62 | map.AssignIfExists(Base::InlineMaxCodeUnitsThreshold, &options->inline_max_code_units_); |
| 63 | map.AssignIfExists(Base::GenerateDebugInfo, &options->generate_debug_info_); |
| 64 | map.AssignIfExists(Base::GenerateMiniDebugInfo, &options->generate_mini_debug_info_); |
| 65 | map.AssignIfExists(Base::GenerateBuildID, &options->generate_build_id_); |
| 66 | if (map.Exists(Base::Debuggable)) { |
| 67 | options->debuggable_ = true; |
| 68 | } |
Nicolas Geoffray | acc56ac | 2018-10-09 08:45:24 +0100 | [diff] [blame] | 69 | if (map.Exists(Base::Baseline)) { |
| 70 | options->baseline_ = true; |
| 71 | } |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 72 | map.AssignIfExists(Base::TopKProfileThreshold, &options->top_k_profile_threshold_); |
| 73 | map.AssignIfExists(Base::AbortOnHardVerifierFailure, &options->abort_on_hard_verifier_failure_); |
Andreas Gampe | f39208f | 2017-10-19 15:06:59 -0700 | [diff] [blame] | 74 | map.AssignIfExists(Base::AbortOnSoftVerifierFailure, &options->abort_on_soft_verifier_failure_); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 75 | if (map.Exists(Base::DumpInitFailures)) { |
| 76 | if (!options->ParseDumpInitFailures(*map.Get(Base::DumpInitFailures), error_msg)) { |
| 77 | return false; |
| 78 | } |
| 79 | } |
| 80 | map.AssignIfExists(Base::DumpCFG, &options->dump_cfg_file_name_); |
| 81 | if (map.Exists(Base::DumpCFGAppend)) { |
| 82 | options->dump_cfg_append_ = true; |
| 83 | } |
| 84 | if (map.Exists(Base::RegisterAllocationStrategy)) { |
| 85 | if (!options->ParseRegisterAllocationStrategy(*map.Get(Base::DumpInitFailures), error_msg)) { |
| 86 | return false; |
| 87 | } |
| 88 | } |
| 89 | map.AssignIfExists(Base::VerboseMethods, &options->verbose_methods_); |
Andreas Gampe | cac31ad | 2017-11-06 20:01:17 -0800 | [diff] [blame] | 90 | options->deduplicate_code_ = map.GetOrDefault(Base::DeduplicateCode); |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 91 | if (map.Exists(Base::CountHotnessInCompiledCode)) { |
| 92 | options->count_hotness_in_compiled_code_ = true; |
| 93 | } |
Mathieu Chartier | cd0f38f | 2018-10-15 09:44:35 -0700 | [diff] [blame] | 94 | map.AssignIfExists(Base::ResolveStartupConstStrings, &options->resolve_startup_const_strings_); |
Mathieu Chartier | 5132e0d | 2019-07-10 09:38:48 -0700 | [diff] [blame] | 95 | map.AssignIfExists(Base::InitializeAppImageClasses, &options->initialize_app_image_classes_); |
Andreas Gampe | 5c80311 | 2018-04-13 17:28:34 -0700 | [diff] [blame] | 96 | if (map.Exists(Base::CheckProfiledMethods)) { |
| 97 | options->check_profiled_methods_ = *map.Get(Base::CheckProfiledMethods); |
| 98 | } |
Mathieu Chartier | 1a84296 | 2018-11-13 15:09:51 -0800 | [diff] [blame] | 99 | map.AssignIfExists(Base::MaxImageBlockSize, &options->max_image_block_size_); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 100 | |
Nicolas Geoffray | 2d8801f | 2017-11-28 15:50:07 +0000 | [diff] [blame] | 101 | if (map.Exists(Base::DumpTimings)) { |
| 102 | options->dump_timings_ = true; |
| 103 | } |
| 104 | |
Vladimir Marko | 2da52b0 | 2018-05-08 16:31:34 +0100 | [diff] [blame] | 105 | if (map.Exists(Base::DumpPassTimings)) { |
| 106 | options->dump_pass_timings_ = true; |
| 107 | } |
| 108 | |
Nicolas Geoffray | 2d8801f | 2017-11-28 15:50:07 +0000 | [diff] [blame] | 109 | if (map.Exists(Base::DumpStats)) { |
| 110 | options->dump_stats_ = true; |
| 111 | } |
| 112 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 113 | return true; |
| 114 | } |
| 115 | |
| 116 | #pragma GCC diagnostic push |
| 117 | #pragma GCC diagnostic ignored "-Wframe-larger-than=" |
| 118 | |
| 119 | template <typename Map, typename Builder> |
| 120 | inline void AddCompilerOptionsArgumentParserOptions(Builder& b) { |
| 121 | b. |
| 122 | Define("--compiler-filter=_") |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 123 | .template WithType<CompilerFilter::Filter>() |
| 124 | .WithHelp("Select compiler filter\n" |
| 125 | "Default: speed-profile if profile provided, speed otherwise") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 126 | .IntoKey(Map::CompilerFilter) |
| 127 | |
David Srbecky | 4fa07a5 | 2020-03-31 20:52:09 +0100 | [diff] [blame] | 128 | .Define({"--compile-art-test", "--no-compile-art-test"}) |
| 129 | .WithValues({true, false}) |
| 130 | .IntoKey(Map::CompileArtTest) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 131 | .Define("--huge-method-max=_") |
| 132 | .template WithType<unsigned int>() |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 133 | .WithHelp("threshold size for a huge method for compiler filter tuning.") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 134 | .IntoKey(Map::HugeMethodMaxThreshold) |
| 135 | .Define("--large-method-max=_") |
| 136 | .template WithType<unsigned int>() |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 137 | .WithHelp("threshold size for a large method for compiler filter tuning.") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 138 | .IntoKey(Map::LargeMethodMaxThreshold) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 139 | .Define("--num-dex-methods=_") |
| 140 | .template WithType<unsigned int>() |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 141 | .WithHelp("threshold size for a small dex file for compiler filter tuning. If the input\n" |
| 142 | "has fewer than this many methods and the filter is not interpret-only or\n" |
| 143 | "verify-none or verify-at-runtime, overrides the filter to use speed") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 144 | .IntoKey(Map::NumDexMethodsThreshold) |
| 145 | .Define("--inline-max-code-units=_") |
| 146 | .template WithType<unsigned int>() |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 147 | .WithHelp("the maximum code units that a methodcan have to be considered for inlining.\n" |
| 148 | "A zero value will disable inlining. Honored only by Optimizing. Has priority\n" |
| 149 | "over the --compiler-filter option. Intended for development/experimental use.") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 150 | .IntoKey(Map::InlineMaxCodeUnitsThreshold) |
| 151 | |
| 152 | .Define({"--generate-debug-info", "-g", "--no-generate-debug-info"}) |
| 153 | .WithValues({true, true, false}) |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 154 | .WithHelp("Generate (or don't generate) debug information for native debugging, such as\n" |
| 155 | "stack unwinding information, ELF symbols and dwarf sections. If used without\n" |
| 156 | "--debuggable it will be best effort only. Does not affect the generated\n" |
| 157 | "code. Disabled by default.") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 158 | .IntoKey(Map::GenerateDebugInfo) |
| 159 | .Define({"--generate-mini-debug-info", "--no-generate-mini-debug-info"}) |
| 160 | .WithValues({true, false}) |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 161 | .WithHelp("Whether or not to generate minimal amount of LZMA-compressed debug\n" |
| 162 | "information necessary to print backtraces (disabled by default).") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 163 | .IntoKey(Map::GenerateMiniDebugInfo) |
| 164 | |
| 165 | .Define({"--generate-build-id", "--no-generate-build-id"}) |
| 166 | .WithValues({true, false}) |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 167 | .WithHelp("Generate GNU-compatible linker build ID ELF section with SHA-1 of the file\n" |
| 168 | "content (and thus stable across identical builds)") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 169 | .IntoKey(Map::GenerateBuildID) |
| 170 | |
Andreas Gampe | cac31ad | 2017-11-06 20:01:17 -0800 | [diff] [blame] | 171 | .Define({"--deduplicate-code=_"}) |
| 172 | .template WithType<bool>() |
| 173 | .WithValueMap({{"false", false}, {"true", true}}) |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 174 | .WithHelp("enable|disable code deduplication. Deduplicated code will have an arbitrary\n" |
| 175 | "symbol tagged with [DEDUPED].") |
Andreas Gampe | cac31ad | 2017-11-06 20:01:17 -0800 | [diff] [blame] | 176 | .IntoKey(Map::DeduplicateCode) |
| 177 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 178 | .Define({"--count-hotness-in-compiled-code"}) |
| 179 | .IntoKey(Map::CountHotnessInCompiledCode) |
| 180 | |
Andreas Gampe | 5c80311 | 2018-04-13 17:28:34 -0700 | [diff] [blame] | 181 | .Define({"--check-profiled-methods=_"}) |
| 182 | .template WithType<ProfileMethodsCheck>() |
| 183 | .WithValueMap({{"log", ProfileMethodsCheck::kLog}, |
| 184 | {"abort", ProfileMethodsCheck::kAbort}}) |
| 185 | .IntoKey(Map::CheckProfiledMethods) |
| 186 | |
Nicolas Geoffray | 2d8801f | 2017-11-28 15:50:07 +0000 | [diff] [blame] | 187 | .Define({"--dump-timings"}) |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 188 | .WithHelp("Display a breakdown of where time was spent.") |
Nicolas Geoffray | 2d8801f | 2017-11-28 15:50:07 +0000 | [diff] [blame] | 189 | .IntoKey(Map::DumpTimings) |
| 190 | |
Vladimir Marko | 2da52b0 | 2018-05-08 16:31:34 +0100 | [diff] [blame] | 191 | .Define({"--dump-pass-timings"}) |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 192 | .WithHelp("Display a breakdown time spent in optimization passes for each compiled" |
| 193 | " method.") |
Vladimir Marko | 2da52b0 | 2018-05-08 16:31:34 +0100 | [diff] [blame] | 194 | .IntoKey(Map::DumpPassTimings) |
| 195 | |
Nicolas Geoffray | 2d8801f | 2017-11-28 15:50:07 +0000 | [diff] [blame] | 196 | .Define({"--dump-stats"}) |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 197 | .WithHelp("Display overall compilation statistics.") |
Nicolas Geoffray | 2d8801f | 2017-11-28 15:50:07 +0000 | [diff] [blame] | 198 | .IntoKey(Map::DumpStats) |
| 199 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 200 | .Define("--debuggable") |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 201 | .WithHelp("Produce code debuggable with a java-debugger.") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 202 | .IntoKey(Map::Debuggable) |
| 203 | |
Nicolas Geoffray | acc56ac | 2018-10-09 08:45:24 +0100 | [diff] [blame] | 204 | .Define("--baseline") |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 205 | .WithHelp("Produce code using the baseline compilation") |
Nicolas Geoffray | acc56ac | 2018-10-09 08:45:24 +0100 | [diff] [blame] | 206 | .IntoKey(Map::Baseline) |
| 207 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 208 | .Define("--top-k-profile-threshold=_") |
| 209 | .template WithType<double>().WithRange(0.0, 100.0) |
| 210 | .IntoKey(Map::TopKProfileThreshold) |
| 211 | |
| 212 | .Define({"--abort-on-hard-verifier-error", "--no-abort-on-hard-verifier-error"}) |
| 213 | .WithValues({true, false}) |
| 214 | .IntoKey(Map::AbortOnHardVerifierFailure) |
Andreas Gampe | f39208f | 2017-10-19 15:06:59 -0700 | [diff] [blame] | 215 | .Define({"--abort-on-soft-verifier-error", "--no-abort-on-soft-verifier-error"}) |
| 216 | .WithValues({true, false}) |
| 217 | .IntoKey(Map::AbortOnSoftVerifierFailure) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 218 | |
| 219 | .Define("--dump-init-failures=_") |
| 220 | .template WithType<std::string>() |
| 221 | .IntoKey(Map::DumpInitFailures) |
| 222 | |
| 223 | .Define("--dump-cfg=_") |
| 224 | .template WithType<std::string>() |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 225 | .WithHelp("Dump control-flow graphs (CFGs) to specified file.") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 226 | .IntoKey(Map::DumpCFG) |
| 227 | .Define("--dump-cfg-append") |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 228 | .WithHelp("when dumping CFGs to an existing file, append new CFG data to existing data\n" |
| 229 | "(instead of overwriting existing data with new data, which is the default\n" |
| 230 | "behavior). This option is only meaningful when used with --dump-cfg.") |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 231 | .IntoKey(Map::DumpCFGAppend) |
| 232 | |
| 233 | .Define("--register-allocation-strategy=_") |
| 234 | .template WithType<std::string>() |
| 235 | .IntoKey(Map::RegisterAllocationStrategy) |
| 236 | |
Mathieu Chartier | cd0f38f | 2018-10-15 09:44:35 -0700 | [diff] [blame] | 237 | .Define("--resolve-startup-const-strings=_") |
| 238 | .template WithType<bool>() |
| 239 | .WithValueMap({{"false", false}, {"true", true}}) |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 240 | .WithHelp("If true, the compiler eagerly resolves strings referenced from const-string\n" |
| 241 | "of startup methods.") |
Mathieu Chartier | cd0f38f | 2018-10-15 09:44:35 -0700 | [diff] [blame] | 242 | .IntoKey(Map::ResolveStartupConstStrings) |
| 243 | |
Mathieu Chartier | 5132e0d | 2019-07-10 09:38:48 -0700 | [diff] [blame] | 244 | .Define("--initialize-app-image-classes=_") |
| 245 | .template WithType<bool>() |
| 246 | .WithValueMap({{"false", false}, {"true", true}}) |
| 247 | .IntoKey(Map::InitializeAppImageClasses) |
| 248 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 249 | .Define("--verbose-methods=_") |
| 250 | .template WithType<ParseStringList<','>>() |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 251 | .WithHelp("Restrict the dumped CFG data to methods whose name is listed.\n" |
| 252 | "Eg: --verbose-methods=toString,hashCode") |
Mathieu Chartier | 1a84296 | 2018-11-13 15:09:51 -0800 | [diff] [blame] | 253 | .IntoKey(Map::VerboseMethods) |
| 254 | |
| 255 | .Define("--max-image-block-size=_") |
| 256 | .template WithType<unsigned int>() |
Alex Light | 0d47a82 | 2020-08-25 09:16:34 -0700 | [diff] [blame] | 257 | .WithHelp("Maximum solid block size for compressed images.") |
Mathieu Chartier | 1a84296 | 2018-11-13 15:09:51 -0800 | [diff] [blame] | 258 | .IntoKey(Map::MaxImageBlockSize); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | #pragma GCC diagnostic pop |
| 262 | |
| 263 | } // namespace art |
| 264 | |
| 265 | #endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_ |