blob: fcbc0f2f5c66deae80e36cd8b8b404f9a36d631c [file] [log] [blame]
Andreas Gampe097f34c2017-08-23 08:57:51 -07001/*
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
32namespace art {
33
Alex Light0d47a822020-08-25 09:16:34 -070034template <>
35struct 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 Gampe097f34c2017-08-23 08:57:51 -070053template <class Base>
54inline bool ReadCompilerOptions(Base& map, CompilerOptions* options, std::string* error_msg) {
55 if (map.Exists(Base::CompilerFilter)) {
Alex Light0d47a822020-08-25 09:16:34 -070056 options->SetCompilerFilter(*map.Get(Base::CompilerFilter));
Andreas Gampe097f34c2017-08-23 08:57:51 -070057 }
David Srbecky4fa07a52020-03-31 20:52:09 +010058 map.AssignIfExists(Base::CompileArtTest, &options->compile_art_test_);
Andreas Gampe097f34c2017-08-23 08:57:51 -070059 map.AssignIfExists(Base::HugeMethodMaxThreshold, &options->huge_method_threshold_);
60 map.AssignIfExists(Base::LargeMethodMaxThreshold, &options->large_method_threshold_);
Andreas Gampe097f34c2017-08-23 08:57:51 -070061 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 Geoffrayacc56ac2018-10-09 08:45:24 +010069 if (map.Exists(Base::Baseline)) {
70 options->baseline_ = true;
71 }
Andreas Gampe097f34c2017-08-23 08:57:51 -070072 map.AssignIfExists(Base::TopKProfileThreshold, &options->top_k_profile_threshold_);
73 map.AssignIfExists(Base::AbortOnHardVerifierFailure, &options->abort_on_hard_verifier_failure_);
Andreas Gampef39208f2017-10-19 15:06:59 -070074 map.AssignIfExists(Base::AbortOnSoftVerifierFailure, &options->abort_on_soft_verifier_failure_);
Andreas Gampe097f34c2017-08-23 08:57:51 -070075 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 Gampecac31ad2017-11-06 20:01:17 -080090 options->deduplicate_code_ = map.GetOrDefault(Base::DeduplicateCode);
Nicolas Geoffray8d728322018-01-18 22:44:32 +000091 if (map.Exists(Base::CountHotnessInCompiledCode)) {
92 options->count_hotness_in_compiled_code_ = true;
93 }
Mathieu Chartiercd0f38f2018-10-15 09:44:35 -070094 map.AssignIfExists(Base::ResolveStartupConstStrings, &options->resolve_startup_const_strings_);
Mathieu Chartier5132e0d2019-07-10 09:38:48 -070095 map.AssignIfExists(Base::InitializeAppImageClasses, &options->initialize_app_image_classes_);
Andreas Gampe5c803112018-04-13 17:28:34 -070096 if (map.Exists(Base::CheckProfiledMethods)) {
97 options->check_profiled_methods_ = *map.Get(Base::CheckProfiledMethods);
98 }
Mathieu Chartier1a842962018-11-13 15:09:51 -080099 map.AssignIfExists(Base::MaxImageBlockSize, &options->max_image_block_size_);
Andreas Gampe097f34c2017-08-23 08:57:51 -0700100
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +0000101 if (map.Exists(Base::DumpTimings)) {
102 options->dump_timings_ = true;
103 }
104
Vladimir Marko2da52b02018-05-08 16:31:34 +0100105 if (map.Exists(Base::DumpPassTimings)) {
106 options->dump_pass_timings_ = true;
107 }
108
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +0000109 if (map.Exists(Base::DumpStats)) {
110 options->dump_stats_ = true;
111 }
112
Andreas Gampe097f34c2017-08-23 08:57:51 -0700113 return true;
114}
115
116#pragma GCC diagnostic push
117#pragma GCC diagnostic ignored "-Wframe-larger-than="
118
119template <typename Map, typename Builder>
120inline void AddCompilerOptionsArgumentParserOptions(Builder& b) {
121 b.
122 Define("--compiler-filter=_")
Alex Light0d47a822020-08-25 09:16:34 -0700123 .template WithType<CompilerFilter::Filter>()
124 .WithHelp("Select compiler filter\n"
125 "Default: speed-profile if profile provided, speed otherwise")
Andreas Gampe097f34c2017-08-23 08:57:51 -0700126 .IntoKey(Map::CompilerFilter)
127
David Srbecky4fa07a52020-03-31 20:52:09 +0100128 .Define({"--compile-art-test", "--no-compile-art-test"})
129 .WithValues({true, false})
130 .IntoKey(Map::CompileArtTest)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700131 .Define("--huge-method-max=_")
132 .template WithType<unsigned int>()
Alex Light0d47a822020-08-25 09:16:34 -0700133 .WithHelp("threshold size for a huge method for compiler filter tuning.")
Andreas Gampe097f34c2017-08-23 08:57:51 -0700134 .IntoKey(Map::HugeMethodMaxThreshold)
135 .Define("--large-method-max=_")
136 .template WithType<unsigned int>()
Alex Light0d47a822020-08-25 09:16:34 -0700137 .WithHelp("threshold size for a large method for compiler filter tuning.")
Andreas Gampe097f34c2017-08-23 08:57:51 -0700138 .IntoKey(Map::LargeMethodMaxThreshold)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700139 .Define("--num-dex-methods=_")
140 .template WithType<unsigned int>()
Alex Light0d47a822020-08-25 09:16:34 -0700141 .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 Gampe097f34c2017-08-23 08:57:51 -0700144 .IntoKey(Map::NumDexMethodsThreshold)
145 .Define("--inline-max-code-units=_")
146 .template WithType<unsigned int>()
Alex Light0d47a822020-08-25 09:16:34 -0700147 .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 Gampe097f34c2017-08-23 08:57:51 -0700150 .IntoKey(Map::InlineMaxCodeUnitsThreshold)
151
152 .Define({"--generate-debug-info", "-g", "--no-generate-debug-info"})
153 .WithValues({true, true, false})
Alex Light0d47a822020-08-25 09:16:34 -0700154 .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 Gampe097f34c2017-08-23 08:57:51 -0700158 .IntoKey(Map::GenerateDebugInfo)
159 .Define({"--generate-mini-debug-info", "--no-generate-mini-debug-info"})
160 .WithValues({true, false})
Alex Light0d47a822020-08-25 09:16:34 -0700161 .WithHelp("Whether or not to generate minimal amount of LZMA-compressed debug\n"
162 "information necessary to print backtraces (disabled by default).")
Andreas Gampe097f34c2017-08-23 08:57:51 -0700163 .IntoKey(Map::GenerateMiniDebugInfo)
164
165 .Define({"--generate-build-id", "--no-generate-build-id"})
166 .WithValues({true, false})
Alex Light0d47a822020-08-25 09:16:34 -0700167 .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 Gampe097f34c2017-08-23 08:57:51 -0700169 .IntoKey(Map::GenerateBuildID)
170
Andreas Gampecac31ad2017-11-06 20:01:17 -0800171 .Define({"--deduplicate-code=_"})
172 .template WithType<bool>()
173 .WithValueMap({{"false", false}, {"true", true}})
Alex Light0d47a822020-08-25 09:16:34 -0700174 .WithHelp("enable|disable code deduplication. Deduplicated code will have an arbitrary\n"
175 "symbol tagged with [DEDUPED].")
Andreas Gampecac31ad2017-11-06 20:01:17 -0800176 .IntoKey(Map::DeduplicateCode)
177
Nicolas Geoffray8d728322018-01-18 22:44:32 +0000178 .Define({"--count-hotness-in-compiled-code"})
179 .IntoKey(Map::CountHotnessInCompiledCode)
180
Andreas Gampe5c803112018-04-13 17:28:34 -0700181 .Define({"--check-profiled-methods=_"})
182 .template WithType<ProfileMethodsCheck>()
183 .WithValueMap({{"log", ProfileMethodsCheck::kLog},
184 {"abort", ProfileMethodsCheck::kAbort}})
185 .IntoKey(Map::CheckProfiledMethods)
186
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +0000187 .Define({"--dump-timings"})
Alex Light0d47a822020-08-25 09:16:34 -0700188 .WithHelp("Display a breakdown of where time was spent.")
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +0000189 .IntoKey(Map::DumpTimings)
190
Vladimir Marko2da52b02018-05-08 16:31:34 +0100191 .Define({"--dump-pass-timings"})
Alex Light0d47a822020-08-25 09:16:34 -0700192 .WithHelp("Display a breakdown time spent in optimization passes for each compiled"
193 " method.")
Vladimir Marko2da52b02018-05-08 16:31:34 +0100194 .IntoKey(Map::DumpPassTimings)
195
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +0000196 .Define({"--dump-stats"})
Alex Light0d47a822020-08-25 09:16:34 -0700197 .WithHelp("Display overall compilation statistics.")
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +0000198 .IntoKey(Map::DumpStats)
199
Andreas Gampe097f34c2017-08-23 08:57:51 -0700200 .Define("--debuggable")
Alex Light0d47a822020-08-25 09:16:34 -0700201 .WithHelp("Produce code debuggable with a java-debugger.")
Andreas Gampe097f34c2017-08-23 08:57:51 -0700202 .IntoKey(Map::Debuggable)
203
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100204 .Define("--baseline")
Alex Light0d47a822020-08-25 09:16:34 -0700205 .WithHelp("Produce code using the baseline compilation")
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100206 .IntoKey(Map::Baseline)
207
Andreas Gampe097f34c2017-08-23 08:57:51 -0700208 .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 Gampef39208f2017-10-19 15:06:59 -0700215 .Define({"--abort-on-soft-verifier-error", "--no-abort-on-soft-verifier-error"})
216 .WithValues({true, false})
217 .IntoKey(Map::AbortOnSoftVerifierFailure)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700218
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 Light0d47a822020-08-25 09:16:34 -0700225 .WithHelp("Dump control-flow graphs (CFGs) to specified file.")
Andreas Gampe097f34c2017-08-23 08:57:51 -0700226 .IntoKey(Map::DumpCFG)
227 .Define("--dump-cfg-append")
Alex Light0d47a822020-08-25 09:16:34 -0700228 .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 Gampe097f34c2017-08-23 08:57:51 -0700231 .IntoKey(Map::DumpCFGAppend)
232
233 .Define("--register-allocation-strategy=_")
234 .template WithType<std::string>()
235 .IntoKey(Map::RegisterAllocationStrategy)
236
Mathieu Chartiercd0f38f2018-10-15 09:44:35 -0700237 .Define("--resolve-startup-const-strings=_")
238 .template WithType<bool>()
239 .WithValueMap({{"false", false}, {"true", true}})
Alex Light0d47a822020-08-25 09:16:34 -0700240 .WithHelp("If true, the compiler eagerly resolves strings referenced from const-string\n"
241 "of startup methods.")
Mathieu Chartiercd0f38f2018-10-15 09:44:35 -0700242 .IntoKey(Map::ResolveStartupConstStrings)
243
Mathieu Chartier5132e0d2019-07-10 09:38:48 -0700244 .Define("--initialize-app-image-classes=_")
245 .template WithType<bool>()
246 .WithValueMap({{"false", false}, {"true", true}})
247 .IntoKey(Map::InitializeAppImageClasses)
248
Andreas Gampe097f34c2017-08-23 08:57:51 -0700249 .Define("--verbose-methods=_")
250 .template WithType<ParseStringList<','>>()
Alex Light0d47a822020-08-25 09:16:34 -0700251 .WithHelp("Restrict the dumped CFG data to methods whose name is listed.\n"
252 "Eg: --verbose-methods=toString,hashCode")
Mathieu Chartier1a842962018-11-13 15:09:51 -0800253 .IntoKey(Map::VerboseMethods)
254
255 .Define("--max-image-block-size=_")
256 .template WithType<unsigned int>()
Alex Light0d47a822020-08-25 09:16:34 -0700257 .WithHelp("Maximum solid block size for compressed images.")
Mathieu Chartier1a842962018-11-13 15:09:51 -0800258 .IntoKey(Map::MaxImageBlockSize);
Andreas Gampe097f34c2017-08-23 08:57:51 -0700259}
260
261#pragma GCC diagnostic pop
262
263} // namespace art
264
265#endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_