blob: 76f0ae9202652a08f00504f0784aa7de8e22d86c [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_max_code_units_(kUnsetInlineMaxCodeUnits),
Jeff Haodcdc85b2015-12-04 14:06:18 -080031 no_inline_from_(nullptr),
Vladimir Markoaad75c62016-10-03 08:46:48 +000032 boot_image_(false),
33 app_image_(false),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080034 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),
Alexey Alexandrovab40c112016-09-19 09:33:49 -070038 generate_build_id_(false),
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),
Nicolas Geoffray57c47042017-06-29 11:31:39 +010043 verbose_methods_(),
Andreas Gampe6cf49e52015-03-05 13:08:45 -080044 abort_on_hard_verifier_failure_(false),
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +000045 init_failure_output_(nullptr),
46 dump_cfg_file_name_(""),
Andreas Gampeace0dc12016-01-20 13:33:13 -080047 dump_cfg_append_(false),
Matthew Gharrity2cd05b72016-08-03 16:57:37 -070048 force_determinism_(false),
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -070049 register_allocation_strategy_(RegisterAllocator::kRegisterAllocatorDefault),
50 passes_to_run_(nullptr) {
Mathieu Chartier5bdab122015-01-26 18:30:19 -080051}
52
Vladimir Markob163bb72015-03-31 21:49:49 +010053CompilerOptions::~CompilerOptions() {
54 // The destructor looks empty but it destroys a PassManagerOptions object. We keep it here
55 // because we don't want to include the PassManagerOptions definition from the header file.
56}
57
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000058void CompilerOptions::ParseHugeMethodMax(const StringPiece& option, UsageFn Usage) {
59 ParseUintOption(option, "--huge-method-max", &huge_method_threshold_, Usage);
60}
61
62void CompilerOptions::ParseLargeMethodMax(const StringPiece& option, UsageFn Usage) {
63 ParseUintOption(option, "--large-method-max", &large_method_threshold_, Usage);
64}
65
66void CompilerOptions::ParseSmallMethodMax(const StringPiece& option, UsageFn Usage) {
67 ParseUintOption(option, "--small-method-max", &small_method_threshold_, Usage);
68}
69
70void CompilerOptions::ParseTinyMethodMax(const StringPiece& option, UsageFn Usage) {
71 ParseUintOption(option, "--tiny-method-max", &tiny_method_threshold_, Usage);
72}
73
74void CompilerOptions::ParseNumDexMethods(const StringPiece& option, UsageFn Usage) {
75 ParseUintOption(option, "--num-dex-methods", &num_dex_methods_threshold_, Usage);
76}
77
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000078void CompilerOptions::ParseInlineMaxCodeUnits(const StringPiece& option, UsageFn Usage) {
Nicolas Geoffray18c12bb2015-12-15 12:09:43 +000079 ParseUintOption(option, "--inline-max-code-units", &inline_max_code_units_, Usage);
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000080}
81
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000082void CompilerOptions::ParseDumpInitFailures(const StringPiece& option,
83 UsageFn Usage ATTRIBUTE_UNUSED) {
84 DCHECK(option.starts_with("--dump-init-failures="));
85 std::string file_name = option.substr(strlen("--dump-init-failures=")).data();
86 init_failure_output_.reset(new std::ofstream(file_name));
87 if (init_failure_output_.get() == nullptr) {
88 LOG(ERROR) << "Failed to allocate ofstream";
89 } else if (init_failure_output_->fail()) {
90 LOG(ERROR) << "Failed to open " << file_name << " for writing the initialization "
91 << "failures.";
92 init_failure_output_.reset();
93 }
94}
95
Matthew Gharrity2cd05b72016-08-03 16:57:37 -070096void CompilerOptions::ParseRegisterAllocationStrategy(const StringPiece& option,
97 UsageFn Usage) {
98 DCHECK(option.starts_with("--register-allocation-strategy="));
99 StringPiece choice = option.substr(strlen("--register-allocation-strategy=")).data();
100 if (choice == "linear-scan") {
101 register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorLinearScan;
102 } else if (choice == "graph-color") {
103 register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorGraphColor;
104 } else {
105 Usage("Unrecognized register allocation strategy. Try linear-scan, or graph-color.");
106 }
107}
108
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000109bool CompilerOptions::ParseCompilerOption(const StringPiece& option, UsageFn Usage) {
110 if (option.starts_with("--compiler-filter=")) {
111 const char* compiler_filter_string = option.substr(strlen("--compiler-filter=")).data();
Andreas Gampe29d38e72016-03-23 15:31:51 +0000112 if (!CompilerFilter::ParseCompilerFilter(compiler_filter_string, &compiler_filter_)) {
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000113 Usage("Unknown --compiler-filter value %s", compiler_filter_string);
114 }
115 } else if (option == "--compile-pic") {
116 compile_pic_ = true;
117 } else if (option.starts_with("--huge-method-max=")) {
118 ParseHugeMethodMax(option, Usage);
119 } else if (option.starts_with("--large-method-max=")) {
120 ParseLargeMethodMax(option, Usage);
121 } else if (option.starts_with("--small-method-max=")) {
122 ParseSmallMethodMax(option, Usage);
123 } else if (option.starts_with("--tiny-method-max=")) {
124 ParseTinyMethodMax(option, Usage);
125 } else if (option.starts_with("--num-dex-methods=")) {
126 ParseNumDexMethods(option, Usage);
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000127 } else if (option.starts_with("--inline-max-code-units=")) {
128 ParseInlineMaxCodeUnits(option, Usage);
129 } else if (option == "--generate-debug-info" || option == "-g") {
130 generate_debug_info_ = true;
131 } else if (option == "--no-generate-debug-info") {
132 generate_debug_info_ = false;
David Srbecky5b1c2ca2016-01-25 17:32:41 +0000133 } else if (option == "--generate-mini-debug-info") {
134 generate_mini_debug_info_ = true;
135 } else if (option == "--no-generate-mini-debug-info") {
136 generate_mini_debug_info_ = false;
Alexey Alexandrovab40c112016-09-19 09:33:49 -0700137 } else if (option == "--generate-build-id") {
138 generate_build_id_ = true;
139 } else if (option == "--no-generate-build-id") {
140 generate_build_id_ = false;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000141 } else if (option == "--debuggable") {
142 debuggable_ = true;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000143 } else if (option.starts_with("--top-k-profile-threshold=")) {
144 ParseDouble(option.data(), '=', 0.0, 100.0, &top_k_profile_threshold_, Usage);
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000145 } else if (option == "--abort-on-hard-verifier-error") {
146 abort_on_hard_verifier_failure_ = true;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000147 } else if (option.starts_with("--dump-init-failures=")) {
148 ParseDumpInitFailures(option, Usage);
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +0000149 } else if (option.starts_with("--dump-cfg=")) {
150 dump_cfg_file_name_ = option.substr(strlen("--dump-cfg=")).data();
Roland Levillainf5bea5e2017-05-02 12:46:07 +0100151 } else if (option == "--dump-cfg-append") {
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +0000152 dump_cfg_append_ = true;
Matthew Gharrity2cd05b72016-08-03 16:57:37 -0700153 } else if (option.starts_with("--register-allocation-strategy=")) {
154 ParseRegisterAllocationStrategy(option, Usage);
Nicolas Geoffray57c47042017-06-29 11:31:39 +0100155 } else if (option.starts_with("--verbose-methods=")) {
156 // TODO: rather than switch off compiler logging, make all VLOG(compiler) messages
157 // conditional on having verbose methods.
158 gLogVerbosity.compiler = false;
159 Split(option.substr(strlen("--verbose-methods=")).ToString(), ',', &verbose_methods_);
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000160 } else {
161 // Option not recognized.
162 return false;
163 }
164 return true;
165}
166
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800167} // namespace art