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 <> 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 53 template <class Base> 54 inline bool ReadCompilerOptions(Base& map, CompilerOptions* options, std::string* error_msg) { 55 if (map.Exists(Base::CompilerFilter)) { 56 options->SetCompilerFilter(*map.Get(Base::CompilerFilter)); 57 } 58 map.AssignIfExists(Base::CompileArtTest, &options->compile_art_test_); 59 map.AssignIfExists(Base::HugeMethodMaxThreshold, &options->huge_method_threshold_); 60 map.AssignIfExists(Base::LargeMethodMaxThreshold, &options->large_method_threshold_); 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 } 69 if (map.Exists(Base::Baseline)) { 70 options->baseline_ = true; 71 } 72 map.AssignIfExists(Base::TopKProfileThreshold, &options->top_k_profile_threshold_); 73 map.AssignIfExists(Base::AbortOnHardVerifierFailure, &options->abort_on_hard_verifier_failure_); 74 map.AssignIfExists(Base::AbortOnSoftVerifierFailure, &options->abort_on_soft_verifier_failure_); 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_); 90 options->deduplicate_code_ = map.GetOrDefault(Base::DeduplicateCode); 91 if (map.Exists(Base::CountHotnessInCompiledCode)) { 92 options->count_hotness_in_compiled_code_ = true; 93 } 94 map.AssignIfExists(Base::ResolveStartupConstStrings, &options->resolve_startup_const_strings_); 95 map.AssignIfExists(Base::InitializeAppImageClasses, &options->initialize_app_image_classes_); 96 if (map.Exists(Base::CheckProfiledMethods)) { 97 options->check_profiled_methods_ = *map.Get(Base::CheckProfiledMethods); 98 } 99 map.AssignIfExists(Base::MaxImageBlockSize, &options->max_image_block_size_); 100 101 if (map.Exists(Base::DumpTimings)) { 102 options->dump_timings_ = true; 103 } 104 105 if (map.Exists(Base::DumpPassTimings)) { 106 options->dump_pass_timings_ = true; 107 } 108 109 if (map.Exists(Base::DumpStats)) { 110 options->dump_stats_ = true; 111 } 112 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=_") 123 .template WithType<CompilerFilter::Filter>() 124 .WithHelp("Select compiler filter\n" 125 "Default: speed-profile if profile provided, speed otherwise") 126 .IntoKey(Map::CompilerFilter) 127 128 .Define({"--compile-art-test", "--no-compile-art-test"}) 129 .WithValues({true, false}) 130 .IntoKey(Map::CompileArtTest) 131 .Define("--huge-method-max=_") 132 .template WithType<unsigned int>() 133 .WithHelp("threshold size for a huge method for compiler filter tuning.") 134 .IntoKey(Map::HugeMethodMaxThreshold) 135 .Define("--large-method-max=_") 136 .template WithType<unsigned int>() 137 .WithHelp("threshold size for a large method for compiler filter tuning.") 138 .IntoKey(Map::LargeMethodMaxThreshold) 139 .Define("--num-dex-methods=_") 140 .template WithType<unsigned int>() 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") 144 .IntoKey(Map::NumDexMethodsThreshold) 145 .Define("--inline-max-code-units=_") 146 .template WithType<unsigned int>() 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.") 150 .IntoKey(Map::InlineMaxCodeUnitsThreshold) 151 152 .Define({"--generate-debug-info", "-g", "--no-generate-debug-info"}) 153 .WithValues({true, true, false}) 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.") 158 .IntoKey(Map::GenerateDebugInfo) 159 .Define({"--generate-mini-debug-info", "--no-generate-mini-debug-info"}) 160 .WithValues({true, false}) 161 .WithHelp("Whether or not to generate minimal amount of LZMA-compressed debug\n" 162 "information necessary to print backtraces (disabled by default).") 163 .IntoKey(Map::GenerateMiniDebugInfo) 164 165 .Define({"--generate-build-id", "--no-generate-build-id"}) 166 .WithValues({true, false}) 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)") 169 .IntoKey(Map::GenerateBuildID) 170 171 .Define({"--deduplicate-code=_"}) 172 .template WithType<bool>() 173 .WithValueMap({{"false", false}, {"true", true}}) 174 .WithHelp("enable|disable code deduplication. Deduplicated code will have an arbitrary\n" 175 "symbol tagged with [DEDUPED].") 176 .IntoKey(Map::DeduplicateCode) 177 178 .Define({"--count-hotness-in-compiled-code"}) 179 .IntoKey(Map::CountHotnessInCompiledCode) 180 181 .Define({"--check-profiled-methods=_"}) 182 .template WithType<ProfileMethodsCheck>() 183 .WithValueMap({{"log", ProfileMethodsCheck::kLog}, 184 {"abort", ProfileMethodsCheck::kAbort}}) 185 .IntoKey(Map::CheckProfiledMethods) 186 187 .Define({"--dump-timings"}) 188 .WithHelp("Display a breakdown of where time was spent.") 189 .IntoKey(Map::DumpTimings) 190 191 .Define({"--dump-pass-timings"}) 192 .WithHelp("Display a breakdown time spent in optimization passes for each compiled" 193 " method.") 194 .IntoKey(Map::DumpPassTimings) 195 196 .Define({"--dump-stats"}) 197 .WithHelp("Display overall compilation statistics.") 198 .IntoKey(Map::DumpStats) 199 200 .Define("--debuggable") 201 .WithHelp("Produce code debuggable with a java-debugger.") 202 .IntoKey(Map::Debuggable) 203 204 .Define("--baseline") 205 .WithHelp("Produce code using the baseline compilation") 206 .IntoKey(Map::Baseline) 207 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) 215 .Define({"--abort-on-soft-verifier-error", "--no-abort-on-soft-verifier-error"}) 216 .WithValues({true, false}) 217 .IntoKey(Map::AbortOnSoftVerifierFailure) 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>() 225 .WithHelp("Dump control-flow graphs (CFGs) to specified file.") 226 .IntoKey(Map::DumpCFG) 227 .Define("--dump-cfg-append") 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.") 231 .IntoKey(Map::DumpCFGAppend) 232 233 .Define("--register-allocation-strategy=_") 234 .template WithType<std::string>() 235 .IntoKey(Map::RegisterAllocationStrategy) 236 237 .Define("--resolve-startup-const-strings=_") 238 .template WithType<bool>() 239 .WithValueMap({{"false", false}, {"true", true}}) 240 .WithHelp("If true, the compiler eagerly resolves strings referenced from const-string\n" 241 "of startup methods.") 242 .IntoKey(Map::ResolveStartupConstStrings) 243 244 .Define("--initialize-app-image-classes=_") 245 .template WithType<bool>() 246 .WithValueMap({{"false", false}, {"true", true}}) 247 .IntoKey(Map::InitializeAppImageClasses) 248 249 .Define("--verbose-methods=_") 250 .template WithType<ParseStringList<','>>() 251 .WithHelp("Restrict the dumped CFG data to methods whose name is listed.\n" 252 "Eg: --verbose-methods=toString,hashCode") 253 .IntoKey(Map::VerboseMethods) 254 255 .Define("--max-image-block-size=_") 256 .template WithType<unsigned int>() 257 .WithHelp("Maximum solid block size for compressed images.") 258 .IntoKey(Map::MaxImageBlockSize); 259 } 260 261 #pragma GCC diagnostic pop 262 263 } // namespace art 264 265 #endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_ 266