blob: aebde101c8f6874a6f97e02f6fa7a203b7c089b5 [file] [log] [blame]
Andreas Gampe097f34c2017-08-23 08:57:51 -07001/*
2 * Copyright (C) 2017 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#ifndef ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_
18#define ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_
19
20#include "compiler_options_map.h"
21
22#include <memory>
23
24#include "android-base/logging.h"
25#include "android-base/macros.h"
26#include "android-base/stringprintf.h"
27
28#include "base/macros.h"
29#include "cmdline_parser.h"
30#include "compiler_options.h"
31
32namespace art {
33
34template <class Base>
35inline bool ReadCompilerOptions(Base& map, CompilerOptions* options, std::string* error_msg) {
36 if (map.Exists(Base::CompilerFilter)) {
37 CompilerFilter::Filter compiler_filter;
38 if (!CompilerFilter::ParseCompilerFilter(map.Get(Base::CompilerFilter)->c_str(),
39 &compiler_filter)) {
40 *error_msg = android::base::StringPrintf("Unknown --compiler-filter value %s",
41 map.Get(Base::CompilerFilter)->c_str());
42 return false;
43 }
44 options->SetCompilerFilter(compiler_filter);
45 }
Andreas Gampe097f34c2017-08-23 08:57:51 -070046 map.AssignIfExists(Base::HugeMethodMaxThreshold, &options->huge_method_threshold_);
47 map.AssignIfExists(Base::LargeMethodMaxThreshold, &options->large_method_threshold_);
Andreas Gampe097f34c2017-08-23 08:57:51 -070048 map.AssignIfExists(Base::NumDexMethodsThreshold, &options->num_dex_methods_threshold_);
49 map.AssignIfExists(Base::InlineMaxCodeUnitsThreshold, &options->inline_max_code_units_);
50 map.AssignIfExists(Base::GenerateDebugInfo, &options->generate_debug_info_);
51 map.AssignIfExists(Base::GenerateMiniDebugInfo, &options->generate_mini_debug_info_);
52 map.AssignIfExists(Base::GenerateBuildID, &options->generate_build_id_);
53 if (map.Exists(Base::Debuggable)) {
54 options->debuggable_ = true;
55 }
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +010056 if (map.Exists(Base::Baseline)) {
57 options->baseline_ = true;
58 }
Andreas Gampe097f34c2017-08-23 08:57:51 -070059 map.AssignIfExists(Base::TopKProfileThreshold, &options->top_k_profile_threshold_);
60 map.AssignIfExists(Base::AbortOnHardVerifierFailure, &options->abort_on_hard_verifier_failure_);
Andreas Gampef39208f2017-10-19 15:06:59 -070061 map.AssignIfExists(Base::AbortOnSoftVerifierFailure, &options->abort_on_soft_verifier_failure_);
Andreas Gampe097f34c2017-08-23 08:57:51 -070062 if (map.Exists(Base::DumpInitFailures)) {
63 if (!options->ParseDumpInitFailures(*map.Get(Base::DumpInitFailures), error_msg)) {
64 return false;
65 }
66 }
67 map.AssignIfExists(Base::DumpCFG, &options->dump_cfg_file_name_);
68 if (map.Exists(Base::DumpCFGAppend)) {
69 options->dump_cfg_append_ = true;
70 }
71 if (map.Exists(Base::RegisterAllocationStrategy)) {
72 if (!options->ParseRegisterAllocationStrategy(*map.Get(Base::DumpInitFailures), error_msg)) {
73 return false;
74 }
75 }
76 map.AssignIfExists(Base::VerboseMethods, &options->verbose_methods_);
Andreas Gampecac31ad2017-11-06 20:01:17 -080077 options->deduplicate_code_ = map.GetOrDefault(Base::DeduplicateCode);
Nicolas Geoffray8d728322018-01-18 22:44:32 +000078 if (map.Exists(Base::CountHotnessInCompiledCode)) {
79 options->count_hotness_in_compiled_code_ = true;
80 }
Mathieu Chartiercd0f38f2018-10-15 09:44:35 -070081 map.AssignIfExists(Base::ResolveStartupConstStrings, &options->resolve_startup_const_strings_);
Andreas Gampe5c803112018-04-13 17:28:34 -070082 if (map.Exists(Base::CheckProfiledMethods)) {
83 options->check_profiled_methods_ = *map.Get(Base::CheckProfiledMethods);
84 }
Mathieu Chartier1a842962018-11-13 15:09:51 -080085 map.AssignIfExists(Base::MaxImageBlockSize, &options->max_image_block_size_);
Andreas Gampe097f34c2017-08-23 08:57:51 -070086
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +000087 if (map.Exists(Base::DumpTimings)) {
88 options->dump_timings_ = true;
89 }
90
Vladimir Marko2da52b02018-05-08 16:31:34 +010091 if (map.Exists(Base::DumpPassTimings)) {
92 options->dump_pass_timings_ = true;
93 }
94
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +000095 if (map.Exists(Base::DumpStats)) {
96 options->dump_stats_ = true;
97 }
98
Andreas Gampe097f34c2017-08-23 08:57:51 -070099 return true;
100}
101
102#pragma GCC diagnostic push
103#pragma GCC diagnostic ignored "-Wframe-larger-than="
104
105template <typename Map, typename Builder>
106inline void AddCompilerOptionsArgumentParserOptions(Builder& b) {
107 b.
108 Define("--compiler-filter=_")
109 .template WithType<std::string>()
110 .IntoKey(Map::CompilerFilter)
111
Andreas Gampe097f34c2017-08-23 08:57:51 -0700112 .Define("--huge-method-max=_")
113 .template WithType<unsigned int>()
114 .IntoKey(Map::HugeMethodMaxThreshold)
115 .Define("--large-method-max=_")
116 .template WithType<unsigned int>()
117 .IntoKey(Map::LargeMethodMaxThreshold)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700118 .Define("--num-dex-methods=_")
119 .template WithType<unsigned int>()
120 .IntoKey(Map::NumDexMethodsThreshold)
121 .Define("--inline-max-code-units=_")
122 .template WithType<unsigned int>()
123 .IntoKey(Map::InlineMaxCodeUnitsThreshold)
124
125 .Define({"--generate-debug-info", "-g", "--no-generate-debug-info"})
126 .WithValues({true, true, false})
127 .IntoKey(Map::GenerateDebugInfo)
128 .Define({"--generate-mini-debug-info", "--no-generate-mini-debug-info"})
129 .WithValues({true, false})
130 .IntoKey(Map::GenerateMiniDebugInfo)
131
132 .Define({"--generate-build-id", "--no-generate-build-id"})
133 .WithValues({true, false})
134 .IntoKey(Map::GenerateBuildID)
135
Andreas Gampecac31ad2017-11-06 20:01:17 -0800136 .Define({"--deduplicate-code=_"})
137 .template WithType<bool>()
138 .WithValueMap({{"false", false}, {"true", true}})
139 .IntoKey(Map::DeduplicateCode)
140
Nicolas Geoffray8d728322018-01-18 22:44:32 +0000141 .Define({"--count-hotness-in-compiled-code"})
142 .IntoKey(Map::CountHotnessInCompiledCode)
143
Andreas Gampe5c803112018-04-13 17:28:34 -0700144 .Define({"--check-profiled-methods=_"})
145 .template WithType<ProfileMethodsCheck>()
146 .WithValueMap({{"log", ProfileMethodsCheck::kLog},
147 {"abort", ProfileMethodsCheck::kAbort}})
148 .IntoKey(Map::CheckProfiledMethods)
149
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +0000150 .Define({"--dump-timings"})
151 .IntoKey(Map::DumpTimings)
152
Vladimir Marko2da52b02018-05-08 16:31:34 +0100153 .Define({"--dump-pass-timings"})
154 .IntoKey(Map::DumpPassTimings)
155
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +0000156 .Define({"--dump-stats"})
157 .IntoKey(Map::DumpStats)
158
Andreas Gampe097f34c2017-08-23 08:57:51 -0700159 .Define("--debuggable")
160 .IntoKey(Map::Debuggable)
161
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100162 .Define("--baseline")
163 .IntoKey(Map::Baseline)
164
Andreas Gampe097f34c2017-08-23 08:57:51 -0700165 .Define("--top-k-profile-threshold=_")
166 .template WithType<double>().WithRange(0.0, 100.0)
167 .IntoKey(Map::TopKProfileThreshold)
168
169 .Define({"--abort-on-hard-verifier-error", "--no-abort-on-hard-verifier-error"})
170 .WithValues({true, false})
171 .IntoKey(Map::AbortOnHardVerifierFailure)
Andreas Gampef39208f2017-10-19 15:06:59 -0700172 .Define({"--abort-on-soft-verifier-error", "--no-abort-on-soft-verifier-error"})
173 .WithValues({true, false})
174 .IntoKey(Map::AbortOnSoftVerifierFailure)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700175
176 .Define("--dump-init-failures=_")
177 .template WithType<std::string>()
178 .IntoKey(Map::DumpInitFailures)
179
180 .Define("--dump-cfg=_")
181 .template WithType<std::string>()
182 .IntoKey(Map::DumpCFG)
183 .Define("--dump-cfg-append")
184 .IntoKey(Map::DumpCFGAppend)
185
186 .Define("--register-allocation-strategy=_")
187 .template WithType<std::string>()
188 .IntoKey(Map::RegisterAllocationStrategy)
189
Mathieu Chartiercd0f38f2018-10-15 09:44:35 -0700190 .Define("--resolve-startup-const-strings=_")
191 .template WithType<bool>()
192 .WithValueMap({{"false", false}, {"true", true}})
193 .IntoKey(Map::ResolveStartupConstStrings)
194
Andreas Gampe097f34c2017-08-23 08:57:51 -0700195 .Define("--verbose-methods=_")
196 .template WithType<ParseStringList<','>>()
Mathieu Chartier1a842962018-11-13 15:09:51 -0800197 .IntoKey(Map::VerboseMethods)
198
199 .Define("--max-image-block-size=_")
200 .template WithType<unsigned int>()
201 .IntoKey(Map::MaxImageBlockSize);
Andreas Gampe097f34c2017-08-23 08:57:51 -0700202}
203
204#pragma GCC diagnostic pop
205
206} // namespace art
207
208#endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_