blob: 772d1b44deea2e08026023c92dc05e4a32371021 [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 }
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_);
Andreas Gampef39208f2017-10-19 15:06:59 -070063 map.AssignIfExists(Base::AbortOnSoftVerifierFailure, &options->abort_on_soft_verifier_failure_);
Andreas Gampe097f34c2017-08-23 08:57:51 -070064 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
80 return true;
81}
82
83#pragma GCC diagnostic push
84#pragma GCC diagnostic ignored "-Wframe-larger-than="
85
86template <typename Map, typename Builder>
87inline void AddCompilerOptionsArgumentParserOptions(Builder& b) {
88 b.
89 Define("--compiler-filter=_")
90 .template WithType<std::string>()
91 .IntoKey(Map::CompilerFilter)
92
93 .Define("--compile-pic")
94 .IntoKey(Map::PIC)
95
96 .Define("--huge-method-max=_")
97 .template WithType<unsigned int>()
98 .IntoKey(Map::HugeMethodMaxThreshold)
99 .Define("--large-method-max=_")
100 .template WithType<unsigned int>()
101 .IntoKey(Map::LargeMethodMaxThreshold)
102 .Define("--small-method-max=_")
103 .template WithType<unsigned int>()
104 .IntoKey(Map::SmallMethodMaxThreshold)
105 .Define("--tiny-method-max=_")
106 .template WithType<unsigned int>()
107 .IntoKey(Map::TinyMethodMaxThreshold)
108 .Define("--num-dex-methods=_")
109 .template WithType<unsigned int>()
110 .IntoKey(Map::NumDexMethodsThreshold)
111 .Define("--inline-max-code-units=_")
112 .template WithType<unsigned int>()
113 .IntoKey(Map::InlineMaxCodeUnitsThreshold)
114
115 .Define({"--generate-debug-info", "-g", "--no-generate-debug-info"})
116 .WithValues({true, true, false})
117 .IntoKey(Map::GenerateDebugInfo)
118 .Define({"--generate-mini-debug-info", "--no-generate-mini-debug-info"})
119 .WithValues({true, false})
120 .IntoKey(Map::GenerateMiniDebugInfo)
121
122 .Define({"--generate-build-id", "--no-generate-build-id"})
123 .WithValues({true, false})
124 .IntoKey(Map::GenerateBuildID)
125
126 .Define("--debuggable")
127 .IntoKey(Map::Debuggable)
128
129 .Define("--top-k-profile-threshold=_")
130 .template WithType<double>().WithRange(0.0, 100.0)
131 .IntoKey(Map::TopKProfileThreshold)
132
133 .Define({"--abort-on-hard-verifier-error", "--no-abort-on-hard-verifier-error"})
134 .WithValues({true, false})
135 .IntoKey(Map::AbortOnHardVerifierFailure)
Andreas Gampef39208f2017-10-19 15:06:59 -0700136 .Define({"--abort-on-soft-verifier-error", "--no-abort-on-soft-verifier-error"})
137 .WithValues({true, false})
138 .IntoKey(Map::AbortOnSoftVerifierFailure)
Andreas Gampe097f34c2017-08-23 08:57:51 -0700139
140 .Define("--dump-init-failures=_")
141 .template WithType<std::string>()
142 .IntoKey(Map::DumpInitFailures)
143
144 .Define("--dump-cfg=_")
145 .template WithType<std::string>()
146 .IntoKey(Map::DumpCFG)
147 .Define("--dump-cfg-append")
148 .IntoKey(Map::DumpCFGAppend)
149
150 .Define("--register-allocation-strategy=_")
151 .template WithType<std::string>()
152 .IntoKey(Map::RegisterAllocationStrategy)
153
154 .Define("--verbose-methods=_")
155 .template WithType<ParseStringList<','>>()
156 .IntoKey(Map::VerboseMethods);
157}
158
159#pragma GCC diagnostic pop
160
161} // namespace art
162
163#endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_