blob: 3bf89214d7847a0c494a5df4da4f01a3eebc4e1a [file] [log] [blame]
Mathieu Chartier5bdab122015-01-26 18:30:19 -08001/*
2 * Copyright (C) 2015 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#include "compiler_options.h"
18
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000019#include <fstream>
20
Mathieu Chartier5bdab122015-01-26 18:30:19 -080021#include "dex/pass_manager.h"
22
23namespace art {
24
25CompilerOptions::CompilerOptions()
26 : compiler_filter_(kDefaultCompilerFilter),
27 huge_method_threshold_(kDefaultHugeMethodThreshold),
28 large_method_threshold_(kDefaultLargeMethodThreshold),
29 small_method_threshold_(kDefaultSmallMethodThreshold),
30 tiny_method_threshold_(kDefaultTinyMethodThreshold),
31 num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold),
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000032 inline_depth_limit_(kUnsetInlineDepthLimit),
33 inline_max_code_units_(kUnsetInlineMaxCodeUnits),
Jeff Haodcdc85b2015-12-04 14:06:18 -080034 no_inline_from_(nullptr),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080035 include_patch_information_(kDefaultIncludePatchInformation),
36 top_k_profile_threshold_(kDefaultTopKProfileThreshold),
Andreas Gampe7b2f09e2015-03-02 14:07:33 -080037 debuggable_(false),
David Srbecky0cf44932015-12-09 14:09:59 +000038 native_debuggable_(kDefaultNativeDebuggable),
David Srbecky8363c772015-05-28 16:12:43 +010039 generate_debug_info_(kDefaultGenerateDebugInfo),
David Srbecky5b1c2ca2016-01-25 17:32:41 +000040 generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080041 implicit_null_checks_(true),
42 implicit_so_checks_(true),
43 implicit_suspend_checks_(false),
44 compile_pic_(false),
45 verbose_methods_(nullptr),
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000046 pass_manager_options_(),
Andreas Gampe6cf49e52015-03-05 13:08:45 -080047 abort_on_hard_verifier_failure_(false),
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +000048 init_failure_output_(nullptr),
49 dump_cfg_file_name_(""),
Andreas Gampeace0dc12016-01-20 13:33:13 -080050 dump_cfg_append_(false),
51 force_determinism_(false) {
Mathieu Chartier5bdab122015-01-26 18:30:19 -080052}
53
Vladimir Markob163bb72015-03-31 21:49:49 +010054CompilerOptions::~CompilerOptions() {
55 // The destructor looks empty but it destroys a PassManagerOptions object. We keep it here
56 // because we don't want to include the PassManagerOptions definition from the header file.
57}
58
Mathieu Chartier5bdab122015-01-26 18:30:19 -080059CompilerOptions::CompilerOptions(CompilerFilter compiler_filter,
60 size_t huge_method_threshold,
61 size_t large_method_threshold,
62 size_t small_method_threshold,
63 size_t tiny_method_threshold,
64 size_t num_dex_methods_threshold,
Calin Juravleec748352015-07-29 13:52:12 +010065 size_t inline_depth_limit,
66 size_t inline_max_code_units,
Vladimir Marko47496c22016-01-27 16:15:08 +000067 const std::vector<const DexFile*>* no_inline_from,
Mathieu Chartier5bdab122015-01-26 18:30:19 -080068 bool include_patch_information,
69 double top_k_profile_threshold,
Andreas Gampe7b2f09e2015-03-02 14:07:33 -080070 bool debuggable,
David Srbecky8363c772015-05-28 16:12:43 +010071 bool generate_debug_info,
Mathieu Chartier5bdab122015-01-26 18:30:19 -080072 bool implicit_null_checks,
73 bool implicit_so_checks,
74 bool implicit_suspend_checks,
75 bool compile_pic,
76 const std::vector<std::string>* verbose_methods,
Andreas Gampe6cf49e52015-03-05 13:08:45 -080077 std::ostream* init_failure_output,
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +000078 bool abort_on_hard_verifier_failure,
79 const std::string& dump_cfg_file_name,
Andreas Gampeace0dc12016-01-20 13:33:13 -080080 bool dump_cfg_append,
81 bool force_determinism
Mathieu Chartier5bdab122015-01-26 18:30:19 -080082 ) : // NOLINT(whitespace/parens)
83 compiler_filter_(compiler_filter),
84 huge_method_threshold_(huge_method_threshold),
85 large_method_threshold_(large_method_threshold),
86 small_method_threshold_(small_method_threshold),
87 tiny_method_threshold_(tiny_method_threshold),
88 num_dex_methods_threshold_(num_dex_methods_threshold),
Calin Juravleec748352015-07-29 13:52:12 +010089 inline_depth_limit_(inline_depth_limit),
90 inline_max_code_units_(inline_max_code_units),
Jeff Haodcdc85b2015-12-04 14:06:18 -080091 no_inline_from_(no_inline_from),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080092 include_patch_information_(include_patch_information),
93 top_k_profile_threshold_(top_k_profile_threshold),
Andreas Gampe7b2f09e2015-03-02 14:07:33 -080094 debuggable_(debuggable),
David Srbecky0cf44932015-12-09 14:09:59 +000095 native_debuggable_(kDefaultNativeDebuggable),
David Srbecky8363c772015-05-28 16:12:43 +010096 generate_debug_info_(generate_debug_info),
David Srbecky5b1c2ca2016-01-25 17:32:41 +000097 generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080098 implicit_null_checks_(implicit_null_checks),
99 implicit_so_checks_(implicit_so_checks),
100 implicit_suspend_checks_(implicit_suspend_checks),
101 compile_pic_(compile_pic),
102 verbose_methods_(verbose_methods),
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000103 pass_manager_options_(),
Andreas Gampe6cf49e52015-03-05 13:08:45 -0800104 abort_on_hard_verifier_failure_(abort_on_hard_verifier_failure),
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +0000105 init_failure_output_(init_failure_output),
106 dump_cfg_file_name_(dump_cfg_file_name),
Andreas Gampeace0dc12016-01-20 13:33:13 -0800107 dump_cfg_append_(dump_cfg_append),
108 force_determinism_(force_determinism) {
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800109}
110
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000111void CompilerOptions::ParseHugeMethodMax(const StringPiece& option, UsageFn Usage) {
112 ParseUintOption(option, "--huge-method-max", &huge_method_threshold_, Usage);
113}
114
115void CompilerOptions::ParseLargeMethodMax(const StringPiece& option, UsageFn Usage) {
116 ParseUintOption(option, "--large-method-max", &large_method_threshold_, Usage);
117}
118
119void CompilerOptions::ParseSmallMethodMax(const StringPiece& option, UsageFn Usage) {
120 ParseUintOption(option, "--small-method-max", &small_method_threshold_, Usage);
121}
122
123void CompilerOptions::ParseTinyMethodMax(const StringPiece& option, UsageFn Usage) {
124 ParseUintOption(option, "--tiny-method-max", &tiny_method_threshold_, Usage);
125}
126
127void CompilerOptions::ParseNumDexMethods(const StringPiece& option, UsageFn Usage) {
128 ParseUintOption(option, "--num-dex-methods", &num_dex_methods_threshold_, Usage);
129}
130
131void CompilerOptions::ParseInlineDepthLimit(const StringPiece& option, UsageFn Usage) {
132 ParseUintOption(option, "--inline-depth-limit", &inline_depth_limit_, Usage);
133}
134
135void CompilerOptions::ParseInlineMaxCodeUnits(const StringPiece& option, UsageFn Usage) {
Nicolas Geoffray18c12bb2015-12-15 12:09:43 +0000136 ParseUintOption(option, "--inline-max-code-units", &inline_max_code_units_, Usage);
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000137}
138
139void CompilerOptions::ParseDisablePasses(const StringPiece& option,
140 UsageFn Usage ATTRIBUTE_UNUSED) {
141 DCHECK(option.starts_with("--disable-passes="));
142 const std::string disable_passes = option.substr(strlen("--disable-passes=")).data();
143 pass_manager_options_.SetDisablePassList(disable_passes);
144}
145
146void CompilerOptions::ParsePrintPasses(const StringPiece& option,
147 UsageFn Usage ATTRIBUTE_UNUSED) {
148 DCHECK(option.starts_with("--print-passes="));
149 const std::string print_passes = option.substr(strlen("--print-passes=")).data();
150 pass_manager_options_.SetPrintPassList(print_passes);
151}
152
153void CompilerOptions::ParseDumpCfgPasses(const StringPiece& option,
154 UsageFn Usage ATTRIBUTE_UNUSED) {
155 DCHECK(option.starts_with("--dump-cfg-passes="));
156 const std::string dump_passes_string = option.substr(strlen("--dump-cfg-passes=")).data();
157 pass_manager_options_.SetDumpPassList(dump_passes_string);
158}
159
160void CompilerOptions::ParsePassOptions(const StringPiece& option,
161 UsageFn Usage ATTRIBUTE_UNUSED) {
162 DCHECK(option.starts_with("--pass-options="));
163 const std::string pass_options = option.substr(strlen("--pass-options=")).data();
164 pass_manager_options_.SetOverriddenPassOptions(pass_options);
165}
166
167void CompilerOptions::ParseDumpInitFailures(const StringPiece& option,
168 UsageFn Usage ATTRIBUTE_UNUSED) {
169 DCHECK(option.starts_with("--dump-init-failures="));
170 std::string file_name = option.substr(strlen("--dump-init-failures=")).data();
171 init_failure_output_.reset(new std::ofstream(file_name));
172 if (init_failure_output_.get() == nullptr) {
173 LOG(ERROR) << "Failed to allocate ofstream";
174 } else if (init_failure_output_->fail()) {
175 LOG(ERROR) << "Failed to open " << file_name << " for writing the initialization "
176 << "failures.";
177 init_failure_output_.reset();
178 }
179}
180
181bool CompilerOptions::ParseCompilerOption(const StringPiece& option, UsageFn Usage) {
182 if (option.starts_with("--compiler-filter=")) {
183 const char* compiler_filter_string = option.substr(strlen("--compiler-filter=")).data();
184 if (strcmp(compiler_filter_string, "verify-none") == 0) {
185 compiler_filter_ = CompilerOptions::kVerifyNone;
186 } else if (strcmp(compiler_filter_string, "interpret-only") == 0) {
187 compiler_filter_ = CompilerOptions::kInterpretOnly;
188 } else if (strcmp(compiler_filter_string, "verify-at-runtime") == 0) {
189 compiler_filter_ = CompilerOptions::kVerifyAtRuntime;
190 } else if (strcmp(compiler_filter_string, "space") == 0) {
191 compiler_filter_ = CompilerOptions::kSpace;
192 } else if (strcmp(compiler_filter_string, "balanced") == 0) {
193 compiler_filter_ = CompilerOptions::kBalanced;
194 } else if (strcmp(compiler_filter_string, "speed") == 0) {
195 compiler_filter_ = CompilerOptions::kSpeed;
196 } else if (strcmp(compiler_filter_string, "everything") == 0) {
197 compiler_filter_ = CompilerOptions::kEverything;
198 } else if (strcmp(compiler_filter_string, "time") == 0) {
199 compiler_filter_ = CompilerOptions::kTime;
200 } else {
201 Usage("Unknown --compiler-filter value %s", compiler_filter_string);
202 }
203 } else if (option == "--compile-pic") {
204 compile_pic_ = true;
205 } else if (option.starts_with("--huge-method-max=")) {
206 ParseHugeMethodMax(option, Usage);
207 } else if (option.starts_with("--large-method-max=")) {
208 ParseLargeMethodMax(option, Usage);
209 } else if (option.starts_with("--small-method-max=")) {
210 ParseSmallMethodMax(option, Usage);
211 } else if (option.starts_with("--tiny-method-max=")) {
212 ParseTinyMethodMax(option, Usage);
213 } else if (option.starts_with("--num-dex-methods=")) {
214 ParseNumDexMethods(option, Usage);
215 } else if (option.starts_with("--inline-depth-limit=")) {
216 ParseInlineDepthLimit(option, Usage);
217 } else if (option.starts_with("--inline-max-code-units=")) {
218 ParseInlineMaxCodeUnits(option, Usage);
219 } else if (option == "--generate-debug-info" || option == "-g") {
220 generate_debug_info_ = true;
221 } else if (option == "--no-generate-debug-info") {
222 generate_debug_info_ = false;
David Srbecky5b1c2ca2016-01-25 17:32:41 +0000223 } else if (option == "--generate-mini-debug-info") {
224 generate_mini_debug_info_ = true;
225 } else if (option == "--no-generate-mini-debug-info") {
226 generate_mini_debug_info_ = false;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000227 } else if (option == "--debuggable") {
228 debuggable_ = true;
David Srbecky0cf44932015-12-09 14:09:59 +0000229 } else if (option == "--native-debuggable") {
230 native_debuggable_ = true;
231 debuggable_ = true;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000232 } else if (option.starts_with("--top-k-profile-threshold=")) {
233 ParseDouble(option.data(), '=', 0.0, 100.0, &top_k_profile_threshold_, Usage);
234 } else if (option == "--include-patch-information") {
235 include_patch_information_ = true;
236 } else if (option == "--no-include-patch-information") {
237 include_patch_information_ = false;
238 } else if (option == "--abort-on-hard-verifier-error") {
239 abort_on_hard_verifier_failure_ = true;
240 } else if (option == "--print-pass-names") {
241 pass_manager_options_.SetPrintPassNames(true);
242 } else if (option.starts_with("--disable-passes=")) {
243 ParseDisablePasses(option, Usage);
244 } else if (option.starts_with("--print-passes=")) {
245 ParsePrintPasses(option, Usage);
246 } else if (option == "--print-all-passes") {
247 pass_manager_options_.SetPrintAllPasses();
248 } else if (option.starts_with("--dump-cfg-passes=")) {
249 ParseDumpCfgPasses(option, Usage);
250 } else if (option == "--print-pass-options") {
251 pass_manager_options_.SetPrintPassOptions(true);
252 } else if (option.starts_with("--pass-options=")) {
253 ParsePassOptions(option, Usage);
254 } else if (option.starts_with("--dump-init-failures=")) {
255 ParseDumpInitFailures(option, Usage);
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +0000256 } else if (option.starts_with("--dump-cfg=")) {
257 dump_cfg_file_name_ = option.substr(strlen("--dump-cfg=")).data();
258 } else if (option.starts_with("--dump-cfg-append")) {
259 dump_cfg_append_ = true;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000260 } else {
261 // Option not recognized.
262 return false;
263 }
264 return true;
265}
266
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800267} // namespace art