• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::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   // clang-format off
122   b.
123       Define("--compiler-filter=_")
124           .template WithType<CompilerFilter::Filter>()
125           .WithHelp("Select compiler filter\n"
126                     "Default: speed-profile if profile provided, speed otherwise")
127           .IntoKey(Map::CompilerFilter)
128 
129       .Define({"--compile-art-test", "--no-compile-art-test"})
130           .WithValues({true, false})
131           .IntoKey(Map::CompileArtTest)
132       .Define("--huge-method-max=_")
133           .template WithType<unsigned int>()
134           .WithHelp("threshold size for a huge method for compiler filter tuning.")
135           .IntoKey(Map::HugeMethodMaxThreshold)
136       .Define("--large-method-max=_")
137           .template WithType<unsigned int>()
138           .WithHelp("threshold size for a large method for compiler filter tuning.")
139           .IntoKey(Map::LargeMethodMaxThreshold)
140       .Define("--num-dex-methods=_")
141           .template WithType<unsigned int>()
142           .WithHelp("threshold size for a small dex file for compiler filter tuning. If the input\n"
143                     "has fewer than this many methods and the filter is not interpret-only or\n"
144                     "verify-none or verify-at-runtime, overrides the filter to use speed")
145           .IntoKey(Map::NumDexMethodsThreshold)
146       .Define("--inline-max-code-units=_")
147           .template WithType<unsigned int>()
148           .WithHelp("the maximum code units that a methodcan have to be considered for inlining.\n"
149                     "A zero value will disable inlining. Honored only by Optimizing. Has priority\n"
150                     "over the --compiler-filter option. Intended for development/experimental use.")
151           .IntoKey(Map::InlineMaxCodeUnitsThreshold)
152 
153       .Define({"--generate-debug-info", "-g", "--no-generate-debug-info"})
154           .WithValues({true, true, false})
155           .WithHelp("Generate (or don't generate) debug information for native debugging, such as\n"
156                     "stack unwinding information, ELF symbols and dwarf sections. If used without\n"
157                     "--debuggable it will be best effort only. Does not affect the generated\n"
158                     "code. Disabled by default.")
159           .IntoKey(Map::GenerateDebugInfo)
160       .Define({"--generate-mini-debug-info", "--no-generate-mini-debug-info"})
161           .WithValues({true, false})
162           .WithHelp("Whether or not to generate minimal amount of LZMA-compressed debug\n"
163                     "information necessary to print backtraces (disabled by default).")
164           .IntoKey(Map::GenerateMiniDebugInfo)
165 
166       .Define({"--generate-build-id", "--no-generate-build-id"})
167           .WithValues({true, false})
168           .WithHelp("Generate GNU-compatible linker build ID ELF section with SHA-1 of the file\n"
169                     "content (and thus stable across identical builds)")
170           .IntoKey(Map::GenerateBuildID)
171 
172       .Define({"--deduplicate-code=_"})
173           .template WithType<bool>()
174           .WithValueMap({{"false", false}, {"true", true}})
175           .WithHelp("enable|disable code deduplication. Deduplicated code will have an arbitrary\n"
176                     "symbol tagged with [DEDUPED].")
177           .IntoKey(Map::DeduplicateCode)
178 
179       .Define({"--count-hotness-in-compiled-code"})
180           .IntoKey(Map::CountHotnessInCompiledCode)
181 
182       .Define({"--check-profiled-methods=_"})
183           .template WithType<ProfileMethodsCheck>()
184           .WithValueMap({{"log", ProfileMethodsCheck::kLog},
185                          {"abort", ProfileMethodsCheck::kAbort}})
186           .IntoKey(Map::CheckProfiledMethods)
187 
188       .Define({"--dump-timings"})
189           .WithHelp("Display a breakdown of where time was spent.")
190           .IntoKey(Map::DumpTimings)
191 
192       .Define({"--dump-pass-timings"})
193           .WithHelp("Display a breakdown time spent in optimization passes for each compiled"
194                     " method.")
195           .IntoKey(Map::DumpPassTimings)
196 
197       .Define({"--dump-stats"})
198           .WithHelp("Display overall compilation statistics.")
199           .IntoKey(Map::DumpStats)
200 
201       .Define("--debuggable")
202           .WithHelp("Produce code debuggable with a java-debugger.")
203           .IntoKey(Map::Debuggable)
204 
205       .Define("--baseline")
206           .WithHelp("Produce code using the baseline compilation")
207           .IntoKey(Map::Baseline)
208 
209       .Define("--top-k-profile-threshold=_")
210           .template WithType<double>().WithRange(0.0, 100.0)
211           .IntoKey(Map::TopKProfileThreshold)
212 
213       .Define({"--abort-on-hard-verifier-error", "--no-abort-on-hard-verifier-error"})
214           .WithValues({true, false})
215           .IntoKey(Map::AbortOnHardVerifierFailure)
216       .Define({"--abort-on-soft-verifier-error", "--no-abort-on-soft-verifier-error"})
217           .WithValues({true, false})
218           .IntoKey(Map::AbortOnSoftVerifierFailure)
219 
220       .Define("--dump-init-failures=_")
221           .template WithType<std::string>()
222           .IntoKey(Map::DumpInitFailures)
223 
224       .Define("--dump-cfg=_")
225           .template WithType<std::string>()
226           .WithHelp("Dump control-flow graphs (CFGs) to specified file.")
227           .IntoKey(Map::DumpCFG)
228       .Define("--dump-cfg-append")
229           .WithHelp("when dumping CFGs to an existing file, append new CFG data to existing data\n"
230                     "(instead of overwriting existing data with new data, which is the default\n"
231                     "behavior). This option is only meaningful when used with --dump-cfg.")
232           .IntoKey(Map::DumpCFGAppend)
233 
234       .Define("--register-allocation-strategy=_")
235           .template WithType<std::string>()
236           .IntoKey(Map::RegisterAllocationStrategy)
237 
238       .Define("--resolve-startup-const-strings=_")
239           .template WithType<bool>()
240           .WithValueMap({{"false", false}, {"true", true}})
241           .WithHelp("If true, the compiler eagerly resolves strings referenced from const-string\n"
242                     "of startup methods.")
243           .IntoKey(Map::ResolveStartupConstStrings)
244 
245       .Define("--initialize-app-image-classes=_")
246           .template WithType<bool>()
247           .WithValueMap({{"false", false}, {"true", true}})
248           .IntoKey(Map::InitializeAppImageClasses)
249 
250       .Define("--verbose-methods=_")
251           .template WithType<ParseStringList<','>>()
252           .WithHelp("Restrict the dumped CFG data to methods whose name is listed.\n"
253                     "Eg: --verbose-methods=toString,hashCode")
254           .IntoKey(Map::VerboseMethods)
255 
256       .Define("--max-image-block-size=_")
257           .template WithType<unsigned int>()
258           .WithHelp("Maximum solid block size for compressed images.")
259           .IntoKey(Map::MaxImageBlockSize);
260   // clang-format on
261 }
262 
263 #pragma GCC diagnostic pop
264 
265 }  // namespace art
266 
267 #endif  // ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_
268