blob: 34ad1c5c087a1e58bfbcbce042ab14ca3c10ebc0 [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),
Vladimir Markoaad75c62016-10-03 08:46:48 +000033 boot_image_(false),
34 app_image_(false),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080035 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),
David Srbecky5b1c2ca2016-01-25 17:32:41 +000038 generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo),
Alexey Alexandrovab40c112016-09-19 09:33:49 -070039 generate_build_id_(false),
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),
Andreas Gampe6cf49e52015-03-05 13:08:45 -080045 abort_on_hard_verifier_failure_(false),
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +000046 init_failure_output_(nullptr),
47 dump_cfg_file_name_(""),
Andreas Gampeace0dc12016-01-20 13:33:13 -080048 dump_cfg_append_(false),
Matthew Gharrity2cd05b72016-08-03 16:57:37 -070049 force_determinism_(false),
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -070050 register_allocation_strategy_(RegisterAllocator::kRegisterAllocatorDefault),
51 passes_to_run_(nullptr) {
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
Andreas Gampe29d38e72016-03-23 15:31:51 +000059CompilerOptions::CompilerOptions(CompilerFilter::Filter compiler_filter,
Mathieu Chartier5bdab122015-01-26 18:30:19 -080060 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 double top_k_profile_threshold,
Andreas Gampe7b2f09e2015-03-02 14:07:33 -080069 bool debuggable,
David Srbecky8363c772015-05-28 16:12:43 +010070 bool generate_debug_info,
Mathieu Chartier5bdab122015-01-26 18:30:19 -080071 bool implicit_null_checks,
72 bool implicit_so_checks,
73 bool implicit_suspend_checks,
74 bool compile_pic,
75 const std::vector<std::string>* verbose_methods,
Andreas Gampe6cf49e52015-03-05 13:08:45 -080076 std::ostream* init_failure_output,
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +000077 bool abort_on_hard_verifier_failure,
78 const std::string& dump_cfg_file_name,
Andreas Gampeace0dc12016-01-20 13:33:13 -080079 bool dump_cfg_append,
Matthew Gharrity2cd05b72016-08-03 16:57:37 -070080 bool force_determinism,
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -070081 RegisterAllocator::Strategy regalloc_strategy,
Vladimir Markoaad75c62016-10-03 08:46:48 +000082 const std::vector<std::string>* passes_to_run)
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),
89 inline_depth_limit_(inline_depth_limit),
90 inline_max_code_units_(inline_max_code_units),
91 no_inline_from_(no_inline_from),
92 boot_image_(false),
93 app_image_(false),
Vladimir Markoaad75c62016-10-03 08:46:48 +000094 top_k_profile_threshold_(top_k_profile_threshold),
95 debuggable_(debuggable),
96 generate_debug_info_(generate_debug_info),
97 generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo),
Alexey Alexandrovab40c112016-09-19 09:33:49 -070098 generate_build_id_(false),
Vladimir Markoaad75c62016-10-03 08:46:48 +000099 implicit_null_checks_(implicit_null_checks),
100 implicit_so_checks_(implicit_so_checks),
101 implicit_suspend_checks_(implicit_suspend_checks),
102 compile_pic_(compile_pic),
103 verbose_methods_(verbose_methods),
104 abort_on_hard_verifier_failure_(abort_on_hard_verifier_failure),
105 init_failure_output_(init_failure_output),
106 dump_cfg_file_name_(dump_cfg_file_name),
107 dump_cfg_append_(dump_cfg_append),
108 force_determinism_(force_determinism),
109 register_allocation_strategy_(regalloc_strategy),
110 passes_to_run_(passes_to_run) {
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800111}
112
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000113void CompilerOptions::ParseHugeMethodMax(const StringPiece& option, UsageFn Usage) {
114 ParseUintOption(option, "--huge-method-max", &huge_method_threshold_, Usage);
115}
116
117void CompilerOptions::ParseLargeMethodMax(const StringPiece& option, UsageFn Usage) {
118 ParseUintOption(option, "--large-method-max", &large_method_threshold_, Usage);
119}
120
121void CompilerOptions::ParseSmallMethodMax(const StringPiece& option, UsageFn Usage) {
122 ParseUintOption(option, "--small-method-max", &small_method_threshold_, Usage);
123}
124
125void CompilerOptions::ParseTinyMethodMax(const StringPiece& option, UsageFn Usage) {
126 ParseUintOption(option, "--tiny-method-max", &tiny_method_threshold_, Usage);
127}
128
129void CompilerOptions::ParseNumDexMethods(const StringPiece& option, UsageFn Usage) {
130 ParseUintOption(option, "--num-dex-methods", &num_dex_methods_threshold_, Usage);
131}
132
133void CompilerOptions::ParseInlineDepthLimit(const StringPiece& option, UsageFn Usage) {
134 ParseUintOption(option, "--inline-depth-limit", &inline_depth_limit_, Usage);
135}
136
137void CompilerOptions::ParseInlineMaxCodeUnits(const StringPiece& option, UsageFn Usage) {
Nicolas Geoffray18c12bb2015-12-15 12:09:43 +0000138 ParseUintOption(option, "--inline-max-code-units", &inline_max_code_units_, Usage);
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000139}
140
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000141void CompilerOptions::ParseDumpInitFailures(const StringPiece& option,
142 UsageFn Usage ATTRIBUTE_UNUSED) {
143 DCHECK(option.starts_with("--dump-init-failures="));
144 std::string file_name = option.substr(strlen("--dump-init-failures=")).data();
145 init_failure_output_.reset(new std::ofstream(file_name));
146 if (init_failure_output_.get() == nullptr) {
147 LOG(ERROR) << "Failed to allocate ofstream";
148 } else if (init_failure_output_->fail()) {
149 LOG(ERROR) << "Failed to open " << file_name << " for writing the initialization "
150 << "failures.";
151 init_failure_output_.reset();
152 }
153}
154
Matthew Gharrity2cd05b72016-08-03 16:57:37 -0700155void CompilerOptions::ParseRegisterAllocationStrategy(const StringPiece& option,
156 UsageFn Usage) {
157 DCHECK(option.starts_with("--register-allocation-strategy="));
158 StringPiece choice = option.substr(strlen("--register-allocation-strategy=")).data();
159 if (choice == "linear-scan") {
160 register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorLinearScan;
161 } else if (choice == "graph-color") {
162 register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorGraphColor;
163 } else {
164 Usage("Unrecognized register allocation strategy. Try linear-scan, or graph-color.");
165 }
166}
167
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000168bool CompilerOptions::ParseCompilerOption(const StringPiece& option, UsageFn Usage) {
169 if (option.starts_with("--compiler-filter=")) {
170 const char* compiler_filter_string = option.substr(strlen("--compiler-filter=")).data();
Andreas Gampe29d38e72016-03-23 15:31:51 +0000171 if (!CompilerFilter::ParseCompilerFilter(compiler_filter_string, &compiler_filter_)) {
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000172 Usage("Unknown --compiler-filter value %s", compiler_filter_string);
173 }
174 } else if (option == "--compile-pic") {
175 compile_pic_ = true;
176 } else if (option.starts_with("--huge-method-max=")) {
177 ParseHugeMethodMax(option, Usage);
178 } else if (option.starts_with("--large-method-max=")) {
179 ParseLargeMethodMax(option, Usage);
180 } else if (option.starts_with("--small-method-max=")) {
181 ParseSmallMethodMax(option, Usage);
182 } else if (option.starts_with("--tiny-method-max=")) {
183 ParseTinyMethodMax(option, Usage);
184 } else if (option.starts_with("--num-dex-methods=")) {
185 ParseNumDexMethods(option, Usage);
186 } else if (option.starts_with("--inline-depth-limit=")) {
187 ParseInlineDepthLimit(option, Usage);
188 } else if (option.starts_with("--inline-max-code-units=")) {
189 ParseInlineMaxCodeUnits(option, Usage);
190 } else if (option == "--generate-debug-info" || option == "-g") {
191 generate_debug_info_ = true;
192 } else if (option == "--no-generate-debug-info") {
193 generate_debug_info_ = false;
David Srbecky5b1c2ca2016-01-25 17:32:41 +0000194 } else if (option == "--generate-mini-debug-info") {
195 generate_mini_debug_info_ = true;
196 } else if (option == "--no-generate-mini-debug-info") {
197 generate_mini_debug_info_ = false;
Alexey Alexandrovab40c112016-09-19 09:33:49 -0700198 } else if (option == "--generate-build-id") {
199 generate_build_id_ = true;
200 } else if (option == "--no-generate-build-id") {
201 generate_build_id_ = false;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000202 } else if (option == "--debuggable") {
203 debuggable_ = true;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000204 } else if (option.starts_with("--top-k-profile-threshold=")) {
205 ParseDouble(option.data(), '=', 0.0, 100.0, &top_k_profile_threshold_, Usage);
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000206 } else if (option == "--abort-on-hard-verifier-error") {
207 abort_on_hard_verifier_failure_ = true;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000208 } else if (option.starts_with("--dump-init-failures=")) {
209 ParseDumpInitFailures(option, Usage);
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +0000210 } else if (option.starts_with("--dump-cfg=")) {
211 dump_cfg_file_name_ = option.substr(strlen("--dump-cfg=")).data();
212 } else if (option.starts_with("--dump-cfg-append")) {
213 dump_cfg_append_ = true;
Matthew Gharrity2cd05b72016-08-03 16:57:37 -0700214 } else if (option.starts_with("--register-allocation-strategy=")) {
215 ParseRegisterAllocationStrategy(option, Usage);
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000216 } else {
217 // Option not recognized.
218 return false;
219 }
220 return true;
221}
222
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800223} // namespace art