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