1 /*
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 
32 namespace art {
33 
34 template <class Base>
ReadCompilerOptions(Base & map,CompilerOptions * options,std::string * error_msg)35 inline 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   }
46   if (map.Exists(Base::PIC)) {
47     options->compile_pic_ = true;
48   }
49   map.AssignIfExists(Base::HugeMethodMaxThreshold, &options->huge_method_threshold_);
50   map.AssignIfExists(Base::LargeMethodMaxThreshold, &options->large_method_threshold_);
51   map.AssignIfExists(Base::SmallMethodMaxThreshold, &options->small_method_threshold_);
52   map.AssignIfExists(Base::TinyMethodMaxThreshold, &options->tiny_method_threshold_);
53   map.AssignIfExists(Base::NumDexMethodsThreshold, &options->num_dex_methods_threshold_);
54   map.AssignIfExists(Base::InlineMaxCodeUnitsThreshold, &options->inline_max_code_units_);
55   map.AssignIfExists(Base::GenerateDebugInfo, &options->generate_debug_info_);
56   map.AssignIfExists(Base::GenerateMiniDebugInfo, &options->generate_mini_debug_info_);
57   map.AssignIfExists(Base::GenerateBuildID, &options->generate_build_id_);
58   if (map.Exists(Base::Debuggable)) {
59     options->debuggable_ = true;
60   }
61   map.AssignIfExists(Base::TopKProfileThreshold, &options->top_k_profile_threshold_);
62   map.AssignIfExists(Base::AbortOnHardVerifierFailure, &options->abort_on_hard_verifier_failure_);
63   map.AssignIfExists(Base::AbortOnSoftVerifierFailure, &options->abort_on_soft_verifier_failure_);
64   if (map.Exists(Base::DumpInitFailures)) {
65     if (!options->ParseDumpInitFailures(*map.Get(Base::DumpInitFailures), error_msg)) {
66       return false;
67     }
68   }
69   map.AssignIfExists(Base::DumpCFG, &options->dump_cfg_file_name_);
70   if (map.Exists(Base::DumpCFGAppend)) {
71     options->dump_cfg_append_ = true;
72   }
73   if (map.Exists(Base::RegisterAllocationStrategy)) {
74     if (!options->ParseRegisterAllocationStrategy(*map.Get(Base::DumpInitFailures), error_msg)) {
75       return false;
76     }
77   }
78   map.AssignIfExists(Base::VerboseMethods, &options->verbose_methods_);
79   options->deduplicate_code_ = map.GetOrDefault(Base::DeduplicateCode);
80   if (map.Exists(Base::CountHotnessInCompiledCode)) {
81     options->count_hotness_in_compiled_code_ = true;
82   }
83 
84   if (map.Exists(Base::DumpTimings)) {
85     options->dump_timings_ = true;
86   }
87 
88   if (map.Exists(Base::DumpStats)) {
89     options->dump_stats_ = true;
90   }
91 
92   return true;
93 }
94 
95 #pragma GCC diagnostic push
96 #pragma GCC diagnostic ignored "-Wframe-larger-than="
97 
98 template <typename Map, typename Builder>
AddCompilerOptionsArgumentParserOptions(Builder & b)99 inline void AddCompilerOptionsArgumentParserOptions(Builder& b) {
100   b.
101       Define("--compiler-filter=_")
102           .template WithType<std::string>()
103           .IntoKey(Map::CompilerFilter)
104 
105       .Define("--compile-pic")
106           .IntoKey(Map::PIC)
107 
108       .Define("--huge-method-max=_")
109           .template WithType<unsigned int>()
110           .IntoKey(Map::HugeMethodMaxThreshold)
111       .Define("--large-method-max=_")
112           .template WithType<unsigned int>()
113           .IntoKey(Map::LargeMethodMaxThreshold)
114       .Define("--small-method-max=_")
115           .template WithType<unsigned int>()
116           .IntoKey(Map::SmallMethodMaxThreshold)
117       .Define("--tiny-method-max=_")
118           .template WithType<unsigned int>()
119           .IntoKey(Map::TinyMethodMaxThreshold)
120       .Define("--num-dex-methods=_")
121           .template WithType<unsigned int>()
122           .IntoKey(Map::NumDexMethodsThreshold)
123       .Define("--inline-max-code-units=_")
124           .template WithType<unsigned int>()
125           .IntoKey(Map::InlineMaxCodeUnitsThreshold)
126 
127       .Define({"--generate-debug-info", "-g", "--no-generate-debug-info"})
128           .WithValues({true, true, false})
129           .IntoKey(Map::GenerateDebugInfo)
130       .Define({"--generate-mini-debug-info", "--no-generate-mini-debug-info"})
131           .WithValues({true, false})
132           .IntoKey(Map::GenerateMiniDebugInfo)
133 
134       .Define({"--generate-build-id", "--no-generate-build-id"})
135           .WithValues({true, false})
136           .IntoKey(Map::GenerateBuildID)
137 
138       .Define({"--deduplicate-code=_"})
139           .template WithType<bool>()
140           .WithValueMap({{"false", false}, {"true", true}})
141           .IntoKey(Map::DeduplicateCode)
142 
143       .Define({"--count-hotness-in-compiled-code"})
144           .IntoKey(Map::CountHotnessInCompiledCode)
145 
146       .Define({"--dump-timings"})
147           .IntoKey(Map::DumpTimings)
148 
149       .Define({"--dump-stats"})
150           .IntoKey(Map::DumpStats)
151 
152       .Define("--debuggable")
153           .IntoKey(Map::Debuggable)
154 
155       .Define("--top-k-profile-threshold=_")
156           .template WithType<double>().WithRange(0.0, 100.0)
157           .IntoKey(Map::TopKProfileThreshold)
158 
159       .Define({"--abort-on-hard-verifier-error", "--no-abort-on-hard-verifier-error"})
160           .WithValues({true, false})
161           .IntoKey(Map::AbortOnHardVerifierFailure)
162       .Define({"--abort-on-soft-verifier-error", "--no-abort-on-soft-verifier-error"})
163           .WithValues({true, false})
164           .IntoKey(Map::AbortOnSoftVerifierFailure)
165 
166       .Define("--dump-init-failures=_")
167           .template WithType<std::string>()
168           .IntoKey(Map::DumpInitFailures)
169 
170       .Define("--dump-cfg=_")
171           .template WithType<std::string>()
172           .IntoKey(Map::DumpCFG)
173       .Define("--dump-cfg-append")
174           .IntoKey(Map::DumpCFGAppend)
175 
176       .Define("--register-allocation-strategy=_")
177           .template WithType<std::string>()
178           .IntoKey(Map::RegisterAllocationStrategy)
179 
180       .Define("--verbose-methods=_")
181           .template WithType<ParseStringList<','>>()
182           .IntoKey(Map::VerboseMethods);
183 }
184 
185 #pragma GCC diagnostic pop
186 
187 }  // namespace art
188 
189 #endif  // ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_
190