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