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