blob: cc1af3e108c4b392ccf7f4b6782ef31fdac71e60 [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
Andreas Gampe097f34c2017-08-23 08:57:51 -070021#include "android-base/stringprintf.h"
22
Andreas Gampe2a5d7282018-01-02 11:53:35 -080023#include "base/runtime_debug.h"
Andreas Gampe097f34c2017-08-23 08:57:51 -070024#include "base/variant_map.h"
25#include "cmdline_parser.h"
26#include "compiler_options_map-inl.h"
Roland Levillain2b03a1f2017-06-06 16:09:59 +010027#include "runtime.h"
Andreas Gampe097f34c2017-08-23 08:57:51 -070028#include "simple_compiler_options_map.h"
Roland Levillain2b03a1f2017-06-06 16:09:59 +010029
Mathieu Chartier5bdab122015-01-26 18:30:19 -080030namespace art {
31
32CompilerOptions::CompilerOptions()
Richard Uhlerf4b34872016-04-13 11:03:46 -070033 : compiler_filter_(CompilerFilter::kDefaultCompilerFilter),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080034 huge_method_threshold_(kDefaultHugeMethodThreshold),
35 large_method_threshold_(kDefaultLargeMethodThreshold),
36 small_method_threshold_(kDefaultSmallMethodThreshold),
37 tiny_method_threshold_(kDefaultTinyMethodThreshold),
38 num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold),
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000039 inline_max_code_units_(kUnsetInlineMaxCodeUnits),
Vladimir Markodc4bcce2018-06-21 16:15:42 +010040 no_inline_from_(),
Vladimir Marko213ee2d2018-06-22 11:56:34 +010041 dex_files_for_oat_file_(),
Vladimir Markodc4bcce2018-06-21 16:15:42 +010042 image_classes_(),
Vladimir Markoaad75c62016-10-03 08:46:48 +000043 boot_image_(false),
Roland Levillain2b03a1f2017-06-06 16:09:59 +010044 core_image_(false),
Vladimir Markoaad75c62016-10-03 08:46:48 +000045 app_image_(false),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080046 top_k_profile_threshold_(kDefaultTopKProfileThreshold),
Andreas Gampe7b2f09e2015-03-02 14:07:33 -080047 debuggable_(false),
David Srbecky8363c772015-05-28 16:12:43 +010048 generate_debug_info_(kDefaultGenerateDebugInfo),
David Srbecky5b1c2ca2016-01-25 17:32:41 +000049 generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo),
Alexey Alexandrovab40c112016-09-19 09:33:49 -070050 generate_build_id_(false),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080051 implicit_null_checks_(true),
52 implicit_so_checks_(true),
53 implicit_suspend_checks_(false),
54 compile_pic_(false),
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +000055 dump_timings_(false),
Vladimir Marko2da52b02018-05-08 16:31:34 +010056 dump_pass_timings_(false),
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +000057 dump_stats_(false),
Nicolas Geoffray57c47042017-06-29 11:31:39 +010058 verbose_methods_(),
Andreas Gampe6cf49e52015-03-05 13:08:45 -080059 abort_on_hard_verifier_failure_(false),
Andreas Gampef39208f2017-10-19 15:06:59 -070060 abort_on_soft_verifier_failure_(false),
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +000061 init_failure_output_(nullptr),
62 dump_cfg_file_name_(""),
Andreas Gampeace0dc12016-01-20 13:33:13 -080063 dump_cfg_append_(false),
Matthew Gharrity2cd05b72016-08-03 16:57:37 -070064 force_determinism_(false),
Andreas Gampecac31ad2017-11-06 20:01:17 -080065 deduplicate_code_(true),
Nicolas Geoffray8d728322018-01-18 22:44:32 +000066 count_hotness_in_compiled_code_(false),
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -070067 register_allocation_strategy_(RegisterAllocator::kRegisterAllocatorDefault),
68 passes_to_run_(nullptr) {
Mathieu Chartier5bdab122015-01-26 18:30:19 -080069}
70
Vladimir Markob163bb72015-03-31 21:49:49 +010071CompilerOptions::~CompilerOptions() {
Vladimir Markodc4bcce2018-06-21 16:15:42 +010072 // Everything done by member destructors.
73 // The definitions of classes forward-declared in the header have now been #included.
Vladimir Markob163bb72015-03-31 21:49:49 +010074}
75
Andreas Gampe2a5d7282018-01-02 11:53:35 -080076namespace {
77
78bool kEmitRuntimeReadBarrierChecks = kIsDebugBuild &&
79 RegisterRuntimeDebugFlag(&kEmitRuntimeReadBarrierChecks);
80
81} // namespace
82
Roland Levillain2b03a1f2017-06-06 16:09:59 +010083bool CompilerOptions::EmitRunTimeChecksInDebugMode() const {
Andreas Gampe2a5d7282018-01-02 11:53:35 -080084 // Run-time checks (e.g. Marking Register checks) are only emitted in slow-debug mode.
85 return kEmitRuntimeReadBarrierChecks;
Roland Levillain2b03a1f2017-06-06 16:09:59 +010086}
87
Andreas Gampe097f34c2017-08-23 08:57:51 -070088bool CompilerOptions::ParseDumpInitFailures(const std::string& option, std::string* error_msg) {
89 init_failure_output_.reset(new std::ofstream(option));
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000090 if (init_failure_output_.get() == nullptr) {
Andreas Gampe097f34c2017-08-23 08:57:51 -070091 *error_msg = "Failed to construct std::ofstream";
92 return false;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000093 } else if (init_failure_output_->fail()) {
Andreas Gampe097f34c2017-08-23 08:57:51 -070094 *error_msg = android::base::StringPrintf(
95 "Failed to open %s for writing the initialization failures.", option.c_str());
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000096 init_failure_output_.reset();
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000097 return false;
98 }
99 return true;
100}
101
Andreas Gampe097f34c2017-08-23 08:57:51 -0700102bool CompilerOptions::ParseRegisterAllocationStrategy(const std::string& option,
103 std::string* error_msg) {
104 if (option == "linear-scan") {
105 register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorLinearScan;
106 } else if (option == "graph-color") {
107 register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorGraphColor;
108 } else {
109 *error_msg = "Unrecognized register allocation strategy. Try linear-scan, or graph-color.";
110 return false;
111 }
112 return true;
113}
114
115#pragma GCC diagnostic push
116#pragma GCC diagnostic ignored "-Wframe-larger-than="
117
118bool CompilerOptions::ParseCompilerOptions(const std::vector<std::string>& options,
119 bool ignore_unrecognized,
120 std::string* error_msg) {
121 auto parser = CreateSimpleParser(ignore_unrecognized);
122 CmdlineResult parse_result = parser.Parse(options);
123 if (!parse_result.IsSuccess()) {
124 *error_msg = parse_result.GetMessage();
125 return false;
126 }
127
128 SimpleParseArgumentMap args = parser.ReleaseArgumentsMap();
129 return ReadCompilerOptions(args, this, error_msg);
130}
131
132#pragma GCC diagnostic pop
133
Vladimir Markodc4bcce2018-06-21 16:15:42 +0100134bool CompilerOptions::IsImageClass(const char* descriptor) const {
135 // Historical note: We used to hold the set indirectly and there was a distinction between an
136 // empty set and a null, null meaning to include all classes. However, the distiction has been
137 // removed; if we don't have a profile, we treat it as an empty set of classes. b/77340429
138 return image_classes_.find(StringPiece(descriptor)) != image_classes_.end();
139}
140
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800141} // namespace art