blob: a522e0c7b524560e0ed5430a55dc3ed713df6fac [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 -080021namespace art {
22
23CompilerOptions::CompilerOptions()
Richard Uhlerf4b34872016-04-13 11:03:46 -070024 : compiler_filter_(CompilerFilter::kDefaultCompilerFilter),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080025 huge_method_threshold_(kDefaultHugeMethodThreshold),
26 large_method_threshold_(kDefaultLargeMethodThreshold),
27 small_method_threshold_(kDefaultSmallMethodThreshold),
28 tiny_method_threshold_(kDefaultTinyMethodThreshold),
29 num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold),
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000030 inline_depth_limit_(kUnsetInlineDepthLimit),
31 inline_max_code_units_(kUnsetInlineMaxCodeUnits),
Jeff Haodcdc85b2015-12-04 14:06:18 -080032 no_inline_from_(nullptr),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080033 include_patch_information_(kDefaultIncludePatchInformation),
34 top_k_profile_threshold_(kDefaultTopKProfileThreshold),
Andreas Gampe7b2f09e2015-03-02 14:07:33 -080035 debuggable_(false),
David Srbecky8363c772015-05-28 16:12:43 +010036 generate_debug_info_(kDefaultGenerateDebugInfo),
David Srbecky5b1c2ca2016-01-25 17:32:41 +000037 generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo),
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),
Andreas Gampe6cf49e52015-03-05 13:08:45 -080043 abort_on_hard_verifier_failure_(false),
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +000044 init_failure_output_(nullptr),
45 dump_cfg_file_name_(""),
Andreas Gampeace0dc12016-01-20 13:33:13 -080046 dump_cfg_append_(false),
Matthew Gharrity2cd05b72016-08-03 16:57:37 -070047 force_determinism_(false),
48 register_allocation_strategy_(RegisterAllocator::kRegisterAllocatorDefault) {
Mathieu Chartier5bdab122015-01-26 18:30:19 -080049}
50
Vladimir Markob163bb72015-03-31 21:49:49 +010051CompilerOptions::~CompilerOptions() {
52 // The destructor looks empty but it destroys a PassManagerOptions object. We keep it here
53 // because we don't want to include the PassManagerOptions definition from the header file.
54}
55
Andreas Gampe29d38e72016-03-23 15:31:51 +000056CompilerOptions::CompilerOptions(CompilerFilter::Filter compiler_filter,
Mathieu Chartier5bdab122015-01-26 18:30:19 -080057 size_t huge_method_threshold,
58 size_t large_method_threshold,
59 size_t small_method_threshold,
60 size_t tiny_method_threshold,
61 size_t num_dex_methods_threshold,
Calin Juravleec748352015-07-29 13:52:12 +010062 size_t inline_depth_limit,
63 size_t inline_max_code_units,
Vladimir Marko47496c22016-01-27 16:15:08 +000064 const std::vector<const DexFile*>* no_inline_from,
Mathieu Chartier5bdab122015-01-26 18:30:19 -080065 bool include_patch_information,
66 double top_k_profile_threshold,
Andreas Gampe7b2f09e2015-03-02 14:07:33 -080067 bool debuggable,
David Srbecky8363c772015-05-28 16:12:43 +010068 bool generate_debug_info,
Mathieu Chartier5bdab122015-01-26 18:30:19 -080069 bool implicit_null_checks,
70 bool implicit_so_checks,
71 bool implicit_suspend_checks,
72 bool compile_pic,
73 const std::vector<std::string>* verbose_methods,
Andreas Gampe6cf49e52015-03-05 13:08:45 -080074 std::ostream* init_failure_output,
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +000075 bool abort_on_hard_verifier_failure,
76 const std::string& dump_cfg_file_name,
Andreas Gampeace0dc12016-01-20 13:33:13 -080077 bool dump_cfg_append,
Matthew Gharrity2cd05b72016-08-03 16:57:37 -070078 bool force_determinism,
79 RegisterAllocator::Strategy regalloc_strategy
Mathieu Chartier5bdab122015-01-26 18:30:19 -080080 ) : // NOLINT(whitespace/parens)
81 compiler_filter_(compiler_filter),
82 huge_method_threshold_(huge_method_threshold),
83 large_method_threshold_(large_method_threshold),
84 small_method_threshold_(small_method_threshold),
85 tiny_method_threshold_(tiny_method_threshold),
86 num_dex_methods_threshold_(num_dex_methods_threshold),
Calin Juravleec748352015-07-29 13:52:12 +010087 inline_depth_limit_(inline_depth_limit),
88 inline_max_code_units_(inline_max_code_units),
Jeff Haodcdc85b2015-12-04 14:06:18 -080089 no_inline_from_(no_inline_from),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080090 include_patch_information_(include_patch_information),
91 top_k_profile_threshold_(top_k_profile_threshold),
Andreas Gampe7b2f09e2015-03-02 14:07:33 -080092 debuggable_(debuggable),
David Srbecky8363c772015-05-28 16:12:43 +010093 generate_debug_info_(generate_debug_info),
David Srbecky5b1c2ca2016-01-25 17:32:41 +000094 generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080095 implicit_null_checks_(implicit_null_checks),
96 implicit_so_checks_(implicit_so_checks),
97 implicit_suspend_checks_(implicit_suspend_checks),
98 compile_pic_(compile_pic),
99 verbose_methods_(verbose_methods),
Andreas Gampe6cf49e52015-03-05 13:08:45 -0800100 abort_on_hard_verifier_failure_(abort_on_hard_verifier_failure),
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +0000101 init_failure_output_(init_failure_output),
102 dump_cfg_file_name_(dump_cfg_file_name),
Andreas Gampeace0dc12016-01-20 13:33:13 -0800103 dump_cfg_append_(dump_cfg_append),
Matthew Gharrity2cd05b72016-08-03 16:57:37 -0700104 force_determinism_(force_determinism),
105 register_allocation_strategy_(regalloc_strategy) {
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800106}
107
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000108void CompilerOptions::ParseHugeMethodMax(const StringPiece& option, UsageFn Usage) {
109 ParseUintOption(option, "--huge-method-max", &huge_method_threshold_, Usage);
110}
111
112void CompilerOptions::ParseLargeMethodMax(const StringPiece& option, UsageFn Usage) {
113 ParseUintOption(option, "--large-method-max", &large_method_threshold_, Usage);
114}
115
116void CompilerOptions::ParseSmallMethodMax(const StringPiece& option, UsageFn Usage) {
117 ParseUintOption(option, "--small-method-max", &small_method_threshold_, Usage);
118}
119
120void CompilerOptions::ParseTinyMethodMax(const StringPiece& option, UsageFn Usage) {
121 ParseUintOption(option, "--tiny-method-max", &tiny_method_threshold_, Usage);
122}
123
124void CompilerOptions::ParseNumDexMethods(const StringPiece& option, UsageFn Usage) {
125 ParseUintOption(option, "--num-dex-methods", &num_dex_methods_threshold_, Usage);
126}
127
128void CompilerOptions::ParseInlineDepthLimit(const StringPiece& option, UsageFn Usage) {
129 ParseUintOption(option, "--inline-depth-limit", &inline_depth_limit_, Usage);
130}
131
132void CompilerOptions::ParseInlineMaxCodeUnits(const StringPiece& option, UsageFn Usage) {
Nicolas Geoffray18c12bb2015-12-15 12:09:43 +0000133 ParseUintOption(option, "--inline-max-code-units", &inline_max_code_units_, Usage);
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000134}
135
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000136void CompilerOptions::ParseDumpInitFailures(const StringPiece& option,
137 UsageFn Usage ATTRIBUTE_UNUSED) {
138 DCHECK(option.starts_with("--dump-init-failures="));
139 std::string file_name = option.substr(strlen("--dump-init-failures=")).data();
140 init_failure_output_.reset(new std::ofstream(file_name));
141 if (init_failure_output_.get() == nullptr) {
142 LOG(ERROR) << "Failed to allocate ofstream";
143 } else if (init_failure_output_->fail()) {
144 LOG(ERROR) << "Failed to open " << file_name << " for writing the initialization "
145 << "failures.";
146 init_failure_output_.reset();
147 }
148}
149
Matthew Gharrity2cd05b72016-08-03 16:57:37 -0700150void CompilerOptions::ParseRegisterAllocationStrategy(const StringPiece& option,
151 UsageFn Usage) {
152 DCHECK(option.starts_with("--register-allocation-strategy="));
153 StringPiece choice = option.substr(strlen("--register-allocation-strategy=")).data();
154 if (choice == "linear-scan") {
155 register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorLinearScan;
156 } else if (choice == "graph-color") {
157 register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorGraphColor;
158 } else {
159 Usage("Unrecognized register allocation strategy. Try linear-scan, or graph-color.");
160 }
161}
162
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000163bool CompilerOptions::ParseCompilerOption(const StringPiece& option, UsageFn Usage) {
164 if (option.starts_with("--compiler-filter=")) {
165 const char* compiler_filter_string = option.substr(strlen("--compiler-filter=")).data();
Andreas Gampe29d38e72016-03-23 15:31:51 +0000166 if (!CompilerFilter::ParseCompilerFilter(compiler_filter_string, &compiler_filter_)) {
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000167 Usage("Unknown --compiler-filter value %s", compiler_filter_string);
168 }
169 } else if (option == "--compile-pic") {
170 compile_pic_ = true;
171 } else if (option.starts_with("--huge-method-max=")) {
172 ParseHugeMethodMax(option, Usage);
173 } else if (option.starts_with("--large-method-max=")) {
174 ParseLargeMethodMax(option, Usage);
175 } else if (option.starts_with("--small-method-max=")) {
176 ParseSmallMethodMax(option, Usage);
177 } else if (option.starts_with("--tiny-method-max=")) {
178 ParseTinyMethodMax(option, Usage);
179 } else if (option.starts_with("--num-dex-methods=")) {
180 ParseNumDexMethods(option, Usage);
181 } else if (option.starts_with("--inline-depth-limit=")) {
182 ParseInlineDepthLimit(option, Usage);
183 } else if (option.starts_with("--inline-max-code-units=")) {
184 ParseInlineMaxCodeUnits(option, Usage);
185 } else if (option == "--generate-debug-info" || option == "-g") {
186 generate_debug_info_ = true;
187 } else if (option == "--no-generate-debug-info") {
188 generate_debug_info_ = false;
David Srbecky5b1c2ca2016-01-25 17:32:41 +0000189 } else if (option == "--generate-mini-debug-info") {
190 generate_mini_debug_info_ = true;
191 } else if (option == "--no-generate-mini-debug-info") {
192 generate_mini_debug_info_ = false;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000193 } else if (option == "--debuggable") {
194 debuggable_ = true;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000195 } else if (option.starts_with("--top-k-profile-threshold=")) {
196 ParseDouble(option.data(), '=', 0.0, 100.0, &top_k_profile_threshold_, Usage);
197 } else if (option == "--include-patch-information") {
198 include_patch_information_ = true;
199 } else if (option == "--no-include-patch-information") {
200 include_patch_information_ = false;
201 } else if (option == "--abort-on-hard-verifier-error") {
202 abort_on_hard_verifier_failure_ = true;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000203 } else if (option.starts_with("--dump-init-failures=")) {
204 ParseDumpInitFailures(option, Usage);
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +0000205 } else if (option.starts_with("--dump-cfg=")) {
206 dump_cfg_file_name_ = option.substr(strlen("--dump-cfg=")).data();
207 } else if (option.starts_with("--dump-cfg-append")) {
208 dump_cfg_append_ = true;
Matthew Gharrity2cd05b72016-08-03 16:57:37 -0700209 } else if (option.starts_with("--register-allocation-strategy=")) {
210 ParseRegisterAllocationStrategy(option, Usage);
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000211 } else {
212 // Option not recognized.
213 return false;
214 }
215 return true;
216}
217
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800218} // namespace art