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 | |
| 34 | template <class Base> |
| 35 | inline bool ReadCompilerOptions(Base& map, CompilerOptions* options, std::string* error_msg) { |
| 36 | if (map.Exists(Base::CompilerFilter)) { |
| 37 | CompilerFilter::Filter compiler_filter; |
| 38 | if (!CompilerFilter::ParseCompilerFilter(map.Get(Base::CompilerFilter)->c_str(), |
| 39 | &compiler_filter)) { |
| 40 | *error_msg = android::base::StringPrintf("Unknown --compiler-filter value %s", |
| 41 | map.Get(Base::CompilerFilter)->c_str()); |
| 42 | return false; |
| 43 | } |
| 44 | options->SetCompilerFilter(compiler_filter); |
| 45 | } |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 46 | map.AssignIfExists(Base::HugeMethodMaxThreshold, &options->huge_method_threshold_); |
| 47 | map.AssignIfExists(Base::LargeMethodMaxThreshold, &options->large_method_threshold_); |
| 48 | map.AssignIfExists(Base::SmallMethodMaxThreshold, &options->small_method_threshold_); |
| 49 | map.AssignIfExists(Base::TinyMethodMaxThreshold, &options->tiny_method_threshold_); |
| 50 | map.AssignIfExists(Base::NumDexMethodsThreshold, &options->num_dex_methods_threshold_); |
| 51 | map.AssignIfExists(Base::InlineMaxCodeUnitsThreshold, &options->inline_max_code_units_); |
| 52 | map.AssignIfExists(Base::GenerateDebugInfo, &options->generate_debug_info_); |
| 53 | map.AssignIfExists(Base::GenerateMiniDebugInfo, &options->generate_mini_debug_info_); |
| 54 | map.AssignIfExists(Base::GenerateBuildID, &options->generate_build_id_); |
| 55 | if (map.Exists(Base::Debuggable)) { |
| 56 | options->debuggable_ = true; |
| 57 | } |
Nicolas Geoffray | acc56ac | 2018-10-09 08:45:24 +0100 | [diff] [blame] | 58 | if (map.Exists(Base::Baseline)) { |
| 59 | options->baseline_ = true; |
| 60 | } |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 61 | map.AssignIfExists(Base::TopKProfileThreshold, &options->top_k_profile_threshold_); |
| 62 | map.AssignIfExists(Base::AbortOnHardVerifierFailure, &options->abort_on_hard_verifier_failure_); |
Andreas Gampe | f39208f | 2017-10-19 15:06:59 -0700 | [diff] [blame] | 63 | map.AssignIfExists(Base::AbortOnSoftVerifierFailure, &options->abort_on_soft_verifier_failure_); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 64 | if (map.Exists(Base::DumpInitFailures)) { |
| 65 | if (!options->ParseDumpInitFailures(*map.Get(Base::DumpInitFailures), error_msg)) { |
| 66 | return false; |
| 67 | } |
| 68 | } |
| 69 | map.AssignIfExists(Base::DumpCFG, &options->dump_cfg_file_name_); |
| 70 | if (map.Exists(Base::DumpCFGAppend)) { |
| 71 | options->dump_cfg_append_ = true; |
| 72 | } |
| 73 | if (map.Exists(Base::RegisterAllocationStrategy)) { |
| 74 | if (!options->ParseRegisterAllocationStrategy(*map.Get(Base::DumpInitFailures), error_msg)) { |
| 75 | return false; |
| 76 | } |
| 77 | } |
| 78 | map.AssignIfExists(Base::VerboseMethods, &options->verbose_methods_); |
Andreas Gampe | cac31ad | 2017-11-06 20:01:17 -0800 | [diff] [blame] | 79 | options->deduplicate_code_ = map.GetOrDefault(Base::DeduplicateCode); |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 80 | if (map.Exists(Base::CountHotnessInCompiledCode)) { |
| 81 | options->count_hotness_in_compiled_code_ = true; |
| 82 | } |
Mathieu Chartier | cd0f38f | 2018-10-15 09:44:35 -0700 | [diff] [blame] | 83 | map.AssignIfExists(Base::ResolveStartupConstStrings, &options->resolve_startup_const_strings_); |
Andreas Gampe | 5c80311 | 2018-04-13 17:28:34 -0700 | [diff] [blame] | 84 | if (map.Exists(Base::CheckProfiledMethods)) { |
| 85 | options->check_profiled_methods_ = *map.Get(Base::CheckProfiledMethods); |
| 86 | } |
Mathieu Chartier | 1a84296 | 2018-11-13 15:09:51 -0800 | [diff] [blame] | 87 | map.AssignIfExists(Base::MaxImageBlockSize, &options->max_image_block_size_); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 88 | |
Nicolas Geoffray | 2d8801f | 2017-11-28 15:50:07 +0000 | [diff] [blame] | 89 | if (map.Exists(Base::DumpTimings)) { |
| 90 | options->dump_timings_ = true; |
| 91 | } |
| 92 | |
Vladimir Marko | 2da52b0 | 2018-05-08 16:31:34 +0100 | [diff] [blame] | 93 | if (map.Exists(Base::DumpPassTimings)) { |
| 94 | options->dump_pass_timings_ = true; |
| 95 | } |
| 96 | |
Nicolas Geoffray | 2d8801f | 2017-11-28 15:50:07 +0000 | [diff] [blame] | 97 | if (map.Exists(Base::DumpStats)) { |
| 98 | options->dump_stats_ = true; |
| 99 | } |
| 100 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 101 | return true; |
| 102 | } |
| 103 | |
| 104 | #pragma GCC diagnostic push |
| 105 | #pragma GCC diagnostic ignored "-Wframe-larger-than=" |
| 106 | |
| 107 | template <typename Map, typename Builder> |
| 108 | inline void AddCompilerOptionsArgumentParserOptions(Builder& b) { |
| 109 | b. |
| 110 | Define("--compiler-filter=_") |
| 111 | .template WithType<std::string>() |
| 112 | .IntoKey(Map::CompilerFilter) |
| 113 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 114 | .Define("--huge-method-max=_") |
| 115 | .template WithType<unsigned int>() |
| 116 | .IntoKey(Map::HugeMethodMaxThreshold) |
| 117 | .Define("--large-method-max=_") |
| 118 | .template WithType<unsigned int>() |
| 119 | .IntoKey(Map::LargeMethodMaxThreshold) |
| 120 | .Define("--small-method-max=_") |
| 121 | .template WithType<unsigned int>() |
| 122 | .IntoKey(Map::SmallMethodMaxThreshold) |
| 123 | .Define("--tiny-method-max=_") |
| 124 | .template WithType<unsigned int>() |
| 125 | .IntoKey(Map::TinyMethodMaxThreshold) |
| 126 | .Define("--num-dex-methods=_") |
| 127 | .template WithType<unsigned int>() |
| 128 | .IntoKey(Map::NumDexMethodsThreshold) |
| 129 | .Define("--inline-max-code-units=_") |
| 130 | .template WithType<unsigned int>() |
| 131 | .IntoKey(Map::InlineMaxCodeUnitsThreshold) |
| 132 | |
| 133 | .Define({"--generate-debug-info", "-g", "--no-generate-debug-info"}) |
| 134 | .WithValues({true, true, false}) |
| 135 | .IntoKey(Map::GenerateDebugInfo) |
| 136 | .Define({"--generate-mini-debug-info", "--no-generate-mini-debug-info"}) |
| 137 | .WithValues({true, false}) |
| 138 | .IntoKey(Map::GenerateMiniDebugInfo) |
| 139 | |
| 140 | .Define({"--generate-build-id", "--no-generate-build-id"}) |
| 141 | .WithValues({true, false}) |
| 142 | .IntoKey(Map::GenerateBuildID) |
| 143 | |
Andreas Gampe | cac31ad | 2017-11-06 20:01:17 -0800 | [diff] [blame] | 144 | .Define({"--deduplicate-code=_"}) |
| 145 | .template WithType<bool>() |
| 146 | .WithValueMap({{"false", false}, {"true", true}}) |
| 147 | .IntoKey(Map::DeduplicateCode) |
| 148 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 149 | .Define({"--count-hotness-in-compiled-code"}) |
| 150 | .IntoKey(Map::CountHotnessInCompiledCode) |
| 151 | |
Andreas Gampe | 5c80311 | 2018-04-13 17:28:34 -0700 | [diff] [blame] | 152 | .Define({"--check-profiled-methods=_"}) |
| 153 | .template WithType<ProfileMethodsCheck>() |
| 154 | .WithValueMap({{"log", ProfileMethodsCheck::kLog}, |
| 155 | {"abort", ProfileMethodsCheck::kAbort}}) |
| 156 | .IntoKey(Map::CheckProfiledMethods) |
| 157 | |
Nicolas Geoffray | 2d8801f | 2017-11-28 15:50:07 +0000 | [diff] [blame] | 158 | .Define({"--dump-timings"}) |
| 159 | .IntoKey(Map::DumpTimings) |
| 160 | |
Vladimir Marko | 2da52b0 | 2018-05-08 16:31:34 +0100 | [diff] [blame] | 161 | .Define({"--dump-pass-timings"}) |
| 162 | .IntoKey(Map::DumpPassTimings) |
| 163 | |
Nicolas Geoffray | 2d8801f | 2017-11-28 15:50:07 +0000 | [diff] [blame] | 164 | .Define({"--dump-stats"}) |
| 165 | .IntoKey(Map::DumpStats) |
| 166 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 167 | .Define("--debuggable") |
| 168 | .IntoKey(Map::Debuggable) |
| 169 | |
Nicolas Geoffray | acc56ac | 2018-10-09 08:45:24 +0100 | [diff] [blame] | 170 | .Define("--baseline") |
| 171 | .IntoKey(Map::Baseline) |
| 172 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 173 | .Define("--top-k-profile-threshold=_") |
| 174 | .template WithType<double>().WithRange(0.0, 100.0) |
| 175 | .IntoKey(Map::TopKProfileThreshold) |
| 176 | |
| 177 | .Define({"--abort-on-hard-verifier-error", "--no-abort-on-hard-verifier-error"}) |
| 178 | .WithValues({true, false}) |
| 179 | .IntoKey(Map::AbortOnHardVerifierFailure) |
Andreas Gampe | f39208f | 2017-10-19 15:06:59 -0700 | [diff] [blame] | 180 | .Define({"--abort-on-soft-verifier-error", "--no-abort-on-soft-verifier-error"}) |
| 181 | .WithValues({true, false}) |
| 182 | .IntoKey(Map::AbortOnSoftVerifierFailure) |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 183 | |
| 184 | .Define("--dump-init-failures=_") |
| 185 | .template WithType<std::string>() |
| 186 | .IntoKey(Map::DumpInitFailures) |
| 187 | |
| 188 | .Define("--dump-cfg=_") |
| 189 | .template WithType<std::string>() |
| 190 | .IntoKey(Map::DumpCFG) |
| 191 | .Define("--dump-cfg-append") |
| 192 | .IntoKey(Map::DumpCFGAppend) |
| 193 | |
| 194 | .Define("--register-allocation-strategy=_") |
| 195 | .template WithType<std::string>() |
| 196 | .IntoKey(Map::RegisterAllocationStrategy) |
| 197 | |
Mathieu Chartier | cd0f38f | 2018-10-15 09:44:35 -0700 | [diff] [blame] | 198 | .Define("--resolve-startup-const-strings=_") |
| 199 | .template WithType<bool>() |
| 200 | .WithValueMap({{"false", false}, {"true", true}}) |
| 201 | .IntoKey(Map::ResolveStartupConstStrings) |
| 202 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 203 | .Define("--verbose-methods=_") |
| 204 | .template WithType<ParseStringList<','>>() |
Mathieu Chartier | 1a84296 | 2018-11-13 15:09:51 -0800 | [diff] [blame] | 205 | .IntoKey(Map::VerboseMethods) |
| 206 | |
| 207 | .Define("--max-image-block-size=_") |
| 208 | .template WithType<unsigned int>() |
| 209 | .IntoKey(Map::MaxImageBlockSize); |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | #pragma GCC diagnostic pop |
| 213 | |
| 214 | } // namespace art |
| 215 | |
| 216 | #endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_ |