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 HIDDEN { 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::InlineMaxCodeUnitsThreshold, &options->inline_max_code_units_); 61 map.AssignIfExists(Base::GenerateDebugInfo, &options->generate_debug_info_); 62 map.AssignIfExists(Base::GenerateMiniDebugInfo, &options->generate_mini_debug_info_); 63 map.AssignIfExists(Base::GenerateBuildID, &options->generate_build_id_); 64 if (map.Exists(Base::Debuggable)) { 65 options->debuggable_ = true; 66 } 67 if (map.Exists(Base::Baseline)) { 68 options->baseline_ = true; 69 } 70 if (map.Exists(Base::ProfileBranches)) { 71 options->profile_branches_ = true; 72 } 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 map.AssignIfExists(Base::VerboseMethods, &options->verbose_methods_); 85 options->deduplicate_code_ = map.GetOrDefault(Base::DeduplicateCode); 86 if (map.Exists(Base::CountHotnessInCompiledCode)) { 87 options->count_hotness_in_compiled_code_ = true; 88 } 89 map.AssignIfExists(Base::ResolveStartupConstStrings, &options->resolve_startup_const_strings_); 90 map.AssignIfExists(Base::InitializeAppImageClasses, &options->initialize_app_image_classes_); 91 if (map.Exists(Base::CheckProfiledMethods)) { 92 options->check_profiled_methods_ = *map.Get(Base::CheckProfiledMethods); 93 } 94 map.AssignIfExists(Base::MaxImageBlockSize, &options->max_image_block_size_); 95 96 if (map.Exists(Base::DumpTimings)) { 97 options->dump_timings_ = true; 98 } 99 100 if (map.Exists(Base::DumpPassTimings)) { 101 options->dump_pass_timings_ = true; 102 } 103 104 if (map.Exists(Base::DumpStats)) { 105 options->dump_stats_ = true; 106 } 107 108 return true; 109 } 110 111 #pragma GCC diagnostic push 112 #pragma GCC diagnostic ignored "-Wframe-larger-than=" 113 114 template <typename Map, typename Builder> 115 NO_INLINE void AddCompilerOptionsArgumentParserOptions(Builder& b) { 116 // clang-format off 117 b. 118 Define("--compiler-filter=_") 119 .template WithType<CompilerFilter::Filter>() 120 .WithHelp("Select compiler filter\n" 121 "Default: speed-profile if profile provided, speed otherwise") 122 .IntoKey(Map::CompilerFilter) 123 124 .Define({"--compile-art-test", "--no-compile-art-test"}) 125 .WithValues({true, false}) 126 .IntoKey(Map::CompileArtTest) 127 .Define("--huge-method-max=_") 128 .template WithType<unsigned int>() 129 .WithHelp("threshold size for a huge method for compiler filter tuning.") 130 .IntoKey(Map::HugeMethodMaxThreshold) 131 .Define("--inline-max-code-units=_") 132 .template WithType<unsigned int>() 133 .WithHelp("the maximum code units that a methodcan have to be considered for inlining.\n" 134 "A zero value will disable inlining. Honored only by Optimizing. Has priority\n" 135 "over the --compiler-filter option. Intended for development/experimental use.") 136 .IntoKey(Map::InlineMaxCodeUnitsThreshold) 137 138 .Define({"--generate-debug-info", "-g", "--no-generate-debug-info"}) 139 .WithValues({true, true, false}) 140 .WithHelp("Generate (or don't generate) debug information for native debugging, such as\n" 141 "stack unwinding information, ELF symbols and dwarf sections. If used without\n" 142 "--debuggable it will be best effort only. Does not affect the generated\n" 143 "code. Disabled by default.") 144 .IntoKey(Map::GenerateDebugInfo) 145 .Define({"--generate-mini-debug-info", "--no-generate-mini-debug-info"}) 146 .WithValues({true, false}) 147 .WithHelp("Whether or not to generate minimal amount of LZMA-compressed debug\n" 148 "information necessary to print backtraces (disabled by default).") 149 .IntoKey(Map::GenerateMiniDebugInfo) 150 151 .Define({"--generate-build-id", "--no-generate-build-id"}) 152 .WithValues({true, false}) 153 .WithHelp("Generate GNU-compatible linker build ID ELF section with SHA-1 of the file\n" 154 "content (and thus stable across identical builds)") 155 .IntoKey(Map::GenerateBuildID) 156 157 .Define({"--deduplicate-code=_"}) 158 .template WithType<bool>() 159 .WithValueMap({{"false", false}, {"true", true}}) 160 .WithHelp("enable|disable code deduplication. Deduplicated code will have an arbitrary\n" 161 "symbol tagged with [DEDUPED].") 162 .IntoKey(Map::DeduplicateCode) 163 164 .Define({"--count-hotness-in-compiled-code"}) 165 .IntoKey(Map::CountHotnessInCompiledCode) 166 167 .Define({"--check-profiled-methods=_"}) 168 .template WithType<ProfileMethodsCheck>() 169 .WithValueMap({{"log", ProfileMethodsCheck::kLog}, 170 {"abort", ProfileMethodsCheck::kAbort}}) 171 .IntoKey(Map::CheckProfiledMethods) 172 173 .Define({"--dump-timings"}) 174 .WithHelp("Display a breakdown of where time was spent.") 175 .IntoKey(Map::DumpTimings) 176 177 .Define({"--dump-pass-timings"}) 178 .WithHelp("Display a breakdown time spent in optimization passes for each compiled" 179 " method.") 180 .IntoKey(Map::DumpPassTimings) 181 182 .Define({"--dump-stats"}) 183 .WithHelp("Display overall compilation statistics.") 184 .IntoKey(Map::DumpStats) 185 186 .Define("--debuggable") 187 .WithHelp("Produce code debuggable with a java-debugger.") 188 .IntoKey(Map::Debuggable) 189 190 .Define("--baseline") 191 .WithHelp("Produce code using the baseline compilation") 192 .IntoKey(Map::Baseline) 193 194 .Define("--profile-branches") 195 .WithHelp("Profile branches in baseline generated code") 196 .IntoKey(Map::ProfileBranches) 197 198 .Define({"--abort-on-hard-verifier-error", "--no-abort-on-hard-verifier-error"}) 199 .WithValues({true, false}) 200 .IntoKey(Map::AbortOnHardVerifierFailure) 201 .Define({"--abort-on-soft-verifier-error", "--no-abort-on-soft-verifier-error"}) 202 .WithValues({true, false}) 203 .IntoKey(Map::AbortOnSoftVerifierFailure) 204 205 .Define("--dump-init-failures=_") 206 .template WithType<std::string>() 207 .IntoKey(Map::DumpInitFailures) 208 209 .Define("--dump-cfg=_") 210 .template WithType<std::string>() 211 .WithHelp("Dump control-flow graphs (CFGs) to specified file.") 212 .IntoKey(Map::DumpCFG) 213 .Define("--dump-cfg-append") 214 .WithHelp("when dumping CFGs to an existing file, append new CFG data to existing data\n" 215 "(instead of overwriting existing data with new data, which is the default\n" 216 "behavior). This option is only meaningful when used with --dump-cfg.") 217 .IntoKey(Map::DumpCFGAppend) 218 219 .Define("--resolve-startup-const-strings=_") 220 .template WithType<bool>() 221 .WithValueMap({{"false", false}, {"true", true}}) 222 .WithHelp("If true, the compiler eagerly resolves strings referenced from const-string\n" 223 "of startup methods.") 224 .IntoKey(Map::ResolveStartupConstStrings) 225 226 .Define("--initialize-app-image-classes=_") 227 .template WithType<bool>() 228 .WithValueMap({{"false", false}, {"true", true}}) 229 .IntoKey(Map::InitializeAppImageClasses) 230 231 .Define("--verbose-methods=_") 232 .template WithType<ParseStringList<','>>() 233 .WithHelp("Restrict the dumped CFG data to methods whose name is listed.\n" 234 "Eg: --verbose-methods=toString,hashCode") 235 .IntoKey(Map::VerboseMethods) 236 237 .Define("--max-image-block-size=_") 238 .template WithType<unsigned int>() 239 .WithHelp("Maximum solid block size for compressed images.") 240 .IntoKey(Map::MaxImageBlockSize) 241 // Obsolete flags 242 .Ignore({ 243 "--num-dex-methods=_", 244 "--top-k-profile-threshold=_", 245 "--large-method-max=_", 246 "--register-allocation-strategy=_" 247 }); 248 // clang-format on 249 } 250 251 #pragma GCC diagnostic pop 252 253 } // namespace art 254 255 #endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_ 256