blob: 209bb5a3c2b27d0cf9450dce8fb058359dabe996 [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),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080040 implicit_null_checks_(true),
41 implicit_so_checks_(true),
42 implicit_suspend_checks_(false),
43 compile_pic_(false),
44 verbose_methods_(nullptr),
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000045 pass_manager_options_(),
Andreas Gampe6cf49e52015-03-05 13:08:45 -080046 abort_on_hard_verifier_failure_(false),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080047 init_failure_output_(nullptr) {
48}
49
Vladimir Markob163bb72015-03-31 21:49:49 +010050CompilerOptions::~CompilerOptions() {
51 // The destructor looks empty but it destroys a PassManagerOptions object. We keep it here
52 // because we don't want to include the PassManagerOptions definition from the header file.
53}
54
Mathieu Chartier5bdab122015-01-26 18:30:19 -080055CompilerOptions::CompilerOptions(CompilerFilter compiler_filter,
56 size_t huge_method_threshold,
57 size_t large_method_threshold,
58 size_t small_method_threshold,
59 size_t tiny_method_threshold,
60 size_t num_dex_methods_threshold,
Calin Juravleec748352015-07-29 13:52:12 +010061 size_t inline_depth_limit,
62 size_t inline_max_code_units,
Jeff Haodcdc85b2015-12-04 14:06:18 -080063 const DexFile* no_inline_from,
Mathieu Chartier5bdab122015-01-26 18:30:19 -080064 bool include_patch_information,
65 double top_k_profile_threshold,
Andreas Gampe7b2f09e2015-03-02 14:07:33 -080066 bool debuggable,
David Srbecky8363c772015-05-28 16:12:43 +010067 bool generate_debug_info,
Mathieu Chartier5bdab122015-01-26 18:30:19 -080068 bool implicit_null_checks,
69 bool implicit_so_checks,
70 bool implicit_suspend_checks,
71 bool compile_pic,
72 const std::vector<std::string>* verbose_methods,
Andreas Gampe6cf49e52015-03-05 13:08:45 -080073 std::ostream* init_failure_output,
74 bool abort_on_hard_verifier_failure
Mathieu Chartier5bdab122015-01-26 18:30:19 -080075 ) : // NOLINT(whitespace/parens)
76 compiler_filter_(compiler_filter),
77 huge_method_threshold_(huge_method_threshold),
78 large_method_threshold_(large_method_threshold),
79 small_method_threshold_(small_method_threshold),
80 tiny_method_threshold_(tiny_method_threshold),
81 num_dex_methods_threshold_(num_dex_methods_threshold),
Calin Juravleec748352015-07-29 13:52:12 +010082 inline_depth_limit_(inline_depth_limit),
83 inline_max_code_units_(inline_max_code_units),
Jeff Haodcdc85b2015-12-04 14:06:18 -080084 no_inline_from_(no_inline_from),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080085 include_patch_information_(include_patch_information),
86 top_k_profile_threshold_(top_k_profile_threshold),
Andreas Gampe7b2f09e2015-03-02 14:07:33 -080087 debuggable_(debuggable),
David Srbecky0cf44932015-12-09 14:09:59 +000088 native_debuggable_(kDefaultNativeDebuggable),
David Srbecky8363c772015-05-28 16:12:43 +010089 generate_debug_info_(generate_debug_info),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080090 implicit_null_checks_(implicit_null_checks),
91 implicit_so_checks_(implicit_so_checks),
92 implicit_suspend_checks_(implicit_suspend_checks),
93 compile_pic_(compile_pic),
94 verbose_methods_(verbose_methods),
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000095 pass_manager_options_(),
Andreas Gampe6cf49e52015-03-05 13:08:45 -080096 abort_on_hard_verifier_failure_(abort_on_hard_verifier_failure),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080097 init_failure_output_(init_failure_output) {
98}
99
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000100void CompilerOptions::ParseHugeMethodMax(const StringPiece& option, UsageFn Usage) {
101 ParseUintOption(option, "--huge-method-max", &huge_method_threshold_, Usage);
102}
103
104void CompilerOptions::ParseLargeMethodMax(const StringPiece& option, UsageFn Usage) {
105 ParseUintOption(option, "--large-method-max", &large_method_threshold_, Usage);
106}
107
108void CompilerOptions::ParseSmallMethodMax(const StringPiece& option, UsageFn Usage) {
109 ParseUintOption(option, "--small-method-max", &small_method_threshold_, Usage);
110}
111
112void CompilerOptions::ParseTinyMethodMax(const StringPiece& option, UsageFn Usage) {
113 ParseUintOption(option, "--tiny-method-max", &tiny_method_threshold_, Usage);
114}
115
116void CompilerOptions::ParseNumDexMethods(const StringPiece& option, UsageFn Usage) {
117 ParseUintOption(option, "--num-dex-methods", &num_dex_methods_threshold_, Usage);
118}
119
120void CompilerOptions::ParseInlineDepthLimit(const StringPiece& option, UsageFn Usage) {
121 ParseUintOption(option, "--inline-depth-limit", &inline_depth_limit_, Usage);
122}
123
124void CompilerOptions::ParseInlineMaxCodeUnits(const StringPiece& option, UsageFn Usage) {
Nicolas Geoffray18c12bb2015-12-15 12:09:43 +0000125 ParseUintOption(option, "--inline-max-code-units", &inline_max_code_units_, Usage);
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000126}
127
128void CompilerOptions::ParseDisablePasses(const StringPiece& option,
129 UsageFn Usage ATTRIBUTE_UNUSED) {
130 DCHECK(option.starts_with("--disable-passes="));
131 const std::string disable_passes = option.substr(strlen("--disable-passes=")).data();
132 pass_manager_options_.SetDisablePassList(disable_passes);
133}
134
135void CompilerOptions::ParsePrintPasses(const StringPiece& option,
136 UsageFn Usage ATTRIBUTE_UNUSED) {
137 DCHECK(option.starts_with("--print-passes="));
138 const std::string print_passes = option.substr(strlen("--print-passes=")).data();
139 pass_manager_options_.SetPrintPassList(print_passes);
140}
141
142void CompilerOptions::ParseDumpCfgPasses(const StringPiece& option,
143 UsageFn Usage ATTRIBUTE_UNUSED) {
144 DCHECK(option.starts_with("--dump-cfg-passes="));
145 const std::string dump_passes_string = option.substr(strlen("--dump-cfg-passes=")).data();
146 pass_manager_options_.SetDumpPassList(dump_passes_string);
147}
148
149void CompilerOptions::ParsePassOptions(const StringPiece& option,
150 UsageFn Usage ATTRIBUTE_UNUSED) {
151 DCHECK(option.starts_with("--pass-options="));
152 const std::string pass_options = option.substr(strlen("--pass-options=")).data();
153 pass_manager_options_.SetOverriddenPassOptions(pass_options);
154}
155
156void CompilerOptions::ParseDumpInitFailures(const StringPiece& option,
157 UsageFn Usage ATTRIBUTE_UNUSED) {
158 DCHECK(option.starts_with("--dump-init-failures="));
159 std::string file_name = option.substr(strlen("--dump-init-failures=")).data();
160 init_failure_output_.reset(new std::ofstream(file_name));
161 if (init_failure_output_.get() == nullptr) {
162 LOG(ERROR) << "Failed to allocate ofstream";
163 } else if (init_failure_output_->fail()) {
164 LOG(ERROR) << "Failed to open " << file_name << " for writing the initialization "
165 << "failures.";
166 init_failure_output_.reset();
167 }
168}
169
170bool CompilerOptions::ParseCompilerOption(const StringPiece& option, UsageFn Usage) {
171 if (option.starts_with("--compiler-filter=")) {
172 const char* compiler_filter_string = option.substr(strlen("--compiler-filter=")).data();
173 if (strcmp(compiler_filter_string, "verify-none") == 0) {
174 compiler_filter_ = CompilerOptions::kVerifyNone;
175 } else if (strcmp(compiler_filter_string, "interpret-only") == 0) {
176 compiler_filter_ = CompilerOptions::kInterpretOnly;
177 } else if (strcmp(compiler_filter_string, "verify-at-runtime") == 0) {
178 compiler_filter_ = CompilerOptions::kVerifyAtRuntime;
179 } else if (strcmp(compiler_filter_string, "space") == 0) {
180 compiler_filter_ = CompilerOptions::kSpace;
181 } else if (strcmp(compiler_filter_string, "balanced") == 0) {
182 compiler_filter_ = CompilerOptions::kBalanced;
183 } else if (strcmp(compiler_filter_string, "speed") == 0) {
184 compiler_filter_ = CompilerOptions::kSpeed;
185 } else if (strcmp(compiler_filter_string, "everything") == 0) {
186 compiler_filter_ = CompilerOptions::kEverything;
187 } else if (strcmp(compiler_filter_string, "time") == 0) {
188 compiler_filter_ = CompilerOptions::kTime;
189 } else {
190 Usage("Unknown --compiler-filter value %s", compiler_filter_string);
191 }
192 } else if (option == "--compile-pic") {
193 compile_pic_ = true;
194 } else if (option.starts_with("--huge-method-max=")) {
195 ParseHugeMethodMax(option, Usage);
196 } else if (option.starts_with("--large-method-max=")) {
197 ParseLargeMethodMax(option, Usage);
198 } else if (option.starts_with("--small-method-max=")) {
199 ParseSmallMethodMax(option, Usage);
200 } else if (option.starts_with("--tiny-method-max=")) {
201 ParseTinyMethodMax(option, Usage);
202 } else if (option.starts_with("--num-dex-methods=")) {
203 ParseNumDexMethods(option, Usage);
204 } else if (option.starts_with("--inline-depth-limit=")) {
205 ParseInlineDepthLimit(option, Usage);
206 } else if (option.starts_with("--inline-max-code-units=")) {
207 ParseInlineMaxCodeUnits(option, Usage);
208 } else if (option == "--generate-debug-info" || option == "-g") {
209 generate_debug_info_ = true;
210 } else if (option == "--no-generate-debug-info") {
211 generate_debug_info_ = false;
212 } else if (option == "--debuggable") {
213 debuggable_ = true;
214 generate_debug_info_ = true;
David Srbecky0cf44932015-12-09 14:09:59 +0000215 } else if (option == "--native-debuggable") {
216 native_debuggable_ = true;
217 debuggable_ = true;
218 generate_debug_info_ = true;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000219 } else if (option.starts_with("--top-k-profile-threshold=")) {
220 ParseDouble(option.data(), '=', 0.0, 100.0, &top_k_profile_threshold_, Usage);
221 } else if (option == "--include-patch-information") {
222 include_patch_information_ = true;
223 } else if (option == "--no-include-patch-information") {
224 include_patch_information_ = false;
225 } else if (option == "--abort-on-hard-verifier-error") {
226 abort_on_hard_verifier_failure_ = true;
227 } else if (option == "--print-pass-names") {
228 pass_manager_options_.SetPrintPassNames(true);
229 } else if (option.starts_with("--disable-passes=")) {
230 ParseDisablePasses(option, Usage);
231 } else if (option.starts_with("--print-passes=")) {
232 ParsePrintPasses(option, Usage);
233 } else if (option == "--print-all-passes") {
234 pass_manager_options_.SetPrintAllPasses();
235 } else if (option.starts_with("--dump-cfg-passes=")) {
236 ParseDumpCfgPasses(option, Usage);
237 } else if (option == "--print-pass-options") {
238 pass_manager_options_.SetPrintPassOptions(true);
239 } else if (option.starts_with("--pass-options=")) {
240 ParsePassOptions(option, Usage);
241 } else if (option.starts_with("--dump-init-failures=")) {
242 ParseDumpInitFailures(option, Usage);
243 } else {
244 // Option not recognized.
245 return false;
246 }
247 return true;
248}
249
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800250} // namespace art