blob: fb7aeb9b0628959699bf7ab34bc51aec8d0bf4ab [file] [log] [blame]
Brian Carlstrom6449c622014-02-10 23:48:36 -08001/*
2 * Copyright (C) 2014 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_H_
18#define ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_
19
Ian Rogersc7dd2952014-10-21 23:31:19 -070020#include <string>
21#include <vector>
22
23#include "base/macros.h"
24
Brian Carlstrom6449c622014-02-10 23:48:36 -080025namespace art {
26
Ian Rogersc7dd2952014-10-21 23:31:19 -070027class CompilerOptions FINAL {
Brian Carlstrom6449c622014-02-10 23:48:36 -080028 public:
29 enum CompilerFilter {
Jeff Hao4a200f52014-04-01 14:58:49 -070030 kVerifyNone, // Skip verification and compile nothing except JNI stubs.
31 kInterpretOnly, // Compile nothing except JNI stubs.
Brian Carlstrom6449c622014-02-10 23:48:36 -080032 kSpace, // Maximize space savings.
33 kBalanced, // Try to get the best performance return on compilation investment.
34 kSpeed, // Maximize runtime performance.
Nicolas Geoffray88157ef2014-09-12 10:29:53 +010035 kEverything, // Force compilation (Note: excludes compilation of class initializers).
Igor Murashkind6dee672014-10-16 18:36:16 -070036 kTime, // Compile methods, but minimize compilation time.
Brian Carlstrom6449c622014-02-10 23:48:36 -080037 };
38
39 // Guide heuristics to determine whether to compile method if profile data not available.
Dave Allison39c3bfb2014-01-28 18:33:52 -080040#if ART_SMALL_MODE
Calin Juravlec1b643c2014-05-30 23:44:11 +010041 static const CompilerFilter kDefaultCompilerFilter = kInterpretOnly;
Dave Allison39c3bfb2014-01-28 18:33:52 -080042#else
Brian Carlstrom6449c622014-02-10 23:48:36 -080043 static const CompilerFilter kDefaultCompilerFilter = kSpeed;
Dave Allison39c3bfb2014-01-28 18:33:52 -080044#endif
Brian Carlstrom6449c622014-02-10 23:48:36 -080045 static const size_t kDefaultHugeMethodThreshold = 10000;
46 static const size_t kDefaultLargeMethodThreshold = 600;
47 static const size_t kDefaultSmallMethodThreshold = 60;
48 static const size_t kDefaultTinyMethodThreshold = 20;
49 static const size_t kDefaultNumDexMethodsThreshold = 900;
Calin Juravlec1b643c2014-05-30 23:44:11 +010050 static constexpr double kDefaultTopKProfileThreshold = 90.0;
Alex Light78382fa2014-06-06 15:45:32 -070051 static const bool kDefaultIncludeDebugSymbols = kIsDebugBuild;
Alex Light53cb16b2014-06-12 11:26:29 -070052 static const bool kDefaultIncludePatchInformation = false;
Brian Carlstrom6449c622014-02-10 23:48:36 -080053
54 CompilerOptions() :
55 compiler_filter_(kDefaultCompilerFilter),
56 huge_method_threshold_(kDefaultHugeMethodThreshold),
57 large_method_threshold_(kDefaultLargeMethodThreshold),
58 small_method_threshold_(kDefaultSmallMethodThreshold),
59 tiny_method_threshold_(kDefaultTinyMethodThreshold),
Mark Mendellae9fd932014-02-10 16:14:35 -080060 num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold),
Calin Juravlec1b643c2014-05-30 23:44:11 +010061 generate_gdb_information_(false),
Alex Light53cb16b2014-06-12 11:26:29 -070062 include_patch_information_(kDefaultIncludePatchInformation),
Alex Light78382fa2014-06-06 15:45:32 -070063 top_k_profile_threshold_(kDefaultTopKProfileThreshold),
Andreas Gampe5655e842014-06-17 16:36:07 -070064 include_debug_symbols_(kDefaultIncludeDebugSymbols),
Dave Allison69dfe512014-07-11 17:11:58 +000065 implicit_null_checks_(false),
66 implicit_so_checks_(false),
Igor Murashkind6dee672014-10-16 18:36:16 -070067 implicit_suspend_checks_(false),
Ian Rogersc7dd2952014-10-21 23:31:19 -070068 compile_pic_(false),
Brian Carlstrom6449c622014-02-10 23:48:36 -080069#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -070070 sea_ir_mode_(false),
Brian Carlstrom6449c622014-02-10 23:48:36 -080071#endif
Ian Rogersc7dd2952014-10-21 23:31:19 -070072 verbose_methods_(nullptr) {
73 }
Brian Carlstrom6449c622014-02-10 23:48:36 -080074
75 CompilerOptions(CompilerFilter compiler_filter,
76 size_t huge_method_threshold,
77 size_t large_method_threshold,
78 size_t small_method_threshold,
79 size_t tiny_method_threshold,
Mark Mendellae9fd932014-02-10 16:14:35 -080080 size_t num_dex_methods_threshold,
Calin Juravlec1b643c2014-05-30 23:44:11 +010081 bool generate_gdb_information,
Alex Light53cb16b2014-06-12 11:26:29 -070082 bool include_patch_information,
Alex Light78382fa2014-06-06 15:45:32 -070083 double top_k_profile_threshold,
Andreas Gampe5655e842014-06-17 16:36:07 -070084 bool include_debug_symbols,
Dave Allison69dfe512014-07-11 17:11:58 +000085 bool implicit_null_checks,
86 bool implicit_so_checks,
Igor Murashkind6dee672014-10-16 18:36:16 -070087 bool implicit_suspend_checks,
Ian Rogersc7dd2952014-10-21 23:31:19 -070088 bool compile_pic,
Brian Carlstrom6449c622014-02-10 23:48:36 -080089#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -070090 bool sea_ir_mode,
Brian Carlstrom6449c622014-02-10 23:48:36 -080091#endif
Ian Rogersc7dd2952014-10-21 23:31:19 -070092 const std::vector<std::string>* verbose_methods
Brian Carlstrom6449c622014-02-10 23:48:36 -080093 ) : // NOLINT(whitespace/parens)
94 compiler_filter_(compiler_filter),
95 huge_method_threshold_(huge_method_threshold),
96 large_method_threshold_(large_method_threshold),
97 small_method_threshold_(small_method_threshold),
98 tiny_method_threshold_(tiny_method_threshold),
Mark Mendellae9fd932014-02-10 16:14:35 -080099 num_dex_methods_threshold_(num_dex_methods_threshold),
Calin Juravlec1b643c2014-05-30 23:44:11 +0100100 generate_gdb_information_(generate_gdb_information),
Alex Light53cb16b2014-06-12 11:26:29 -0700101 include_patch_information_(include_patch_information),
Alex Light78382fa2014-06-06 15:45:32 -0700102 top_k_profile_threshold_(top_k_profile_threshold),
Andreas Gampe5655e842014-06-17 16:36:07 -0700103 include_debug_symbols_(include_debug_symbols),
Dave Allison69dfe512014-07-11 17:11:58 +0000104 implicit_null_checks_(implicit_null_checks),
105 implicit_so_checks_(implicit_so_checks),
Igor Murashkind6dee672014-10-16 18:36:16 -0700106 implicit_suspend_checks_(implicit_suspend_checks),
Ian Rogersc7dd2952014-10-21 23:31:19 -0700107 compile_pic_(compile_pic),
Brian Carlstrom6449c622014-02-10 23:48:36 -0800108#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -0700109 sea_ir_mode_(sea_ir_mode),
Brian Carlstrom6449c622014-02-10 23:48:36 -0800110#endif
Ian Rogersc7dd2952014-10-21 23:31:19 -0700111 verbose_methods_(verbose_methods) {
112 }
Brian Carlstrom6449c622014-02-10 23:48:36 -0800113
114 CompilerFilter GetCompilerFilter() const {
115 return compiler_filter_;
116 }
117
118 void SetCompilerFilter(CompilerFilter compiler_filter) {
119 compiler_filter_ = compiler_filter;
120 }
121
Jeff Hao4a200f52014-04-01 14:58:49 -0700122 bool IsCompilationEnabled() const {
123 return ((compiler_filter_ != CompilerOptions::kVerifyNone) &&
124 (compiler_filter_ != CompilerOptions::kInterpretOnly));
125 }
126
127 bool IsVerificationEnabled() const {
128 return (compiler_filter_ != CompilerOptions::kVerifyNone);
129 }
130
Brian Carlstrom6449c622014-02-10 23:48:36 -0800131 size_t GetHugeMethodThreshold() const {
132 return huge_method_threshold_;
133 }
134
135 size_t GetLargeMethodThreshold() const {
136 return large_method_threshold_;
137 }
138
139 size_t GetSmallMethodThreshold() const {
140 return small_method_threshold_;
141 }
142
143 size_t GetTinyMethodThreshold() const {
144 return tiny_method_threshold_;
145 }
146
147 bool IsHugeMethod(size_t num_dalvik_instructions) const {
148 return num_dalvik_instructions > huge_method_threshold_;
149 }
150
151 bool IsLargeMethod(size_t num_dalvik_instructions) const {
152 return num_dalvik_instructions > large_method_threshold_;
153 }
154
155 bool IsSmallMethod(size_t num_dalvik_instructions) const {
156 return num_dalvik_instructions > small_method_threshold_;
157 }
158
159 bool IsTinyMethod(size_t num_dalvik_instructions) const {
160 return num_dalvik_instructions > tiny_method_threshold_;
161 }
162
163 size_t GetNumDexMethodsThreshold() const {
164 return num_dex_methods_threshold_;
165 }
166
Calin Juravlec1b643c2014-05-30 23:44:11 +0100167 double GetTopKProfileThreshold() const {
168 return top_k_profile_threshold_;
169 }
170
Alex Light78382fa2014-06-06 15:45:32 -0700171 bool GetIncludeDebugSymbols() const {
172 return include_debug_symbols_;
173 }
174
Dave Allison69dfe512014-07-11 17:11:58 +0000175 bool GetImplicitNullChecks() const {
176 return implicit_null_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700177 }
178
Dave Allison69dfe512014-07-11 17:11:58 +0000179 bool GetImplicitStackOverflowChecks() const {
180 return implicit_so_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700181 }
182
Dave Allison69dfe512014-07-11 17:11:58 +0000183 bool GetImplicitSuspendChecks() const {
184 return implicit_suspend_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700185 }
186
Brian Carlstrom6449c622014-02-10 23:48:36 -0800187#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -0700188 bool GetSeaIrMode() const {
189 return sea_ir_mode_;
190 }
Brian Carlstrom6449c622014-02-10 23:48:36 -0800191#endif
192
Mark Mendellae9fd932014-02-10 16:14:35 -0800193 bool GetGenerateGDBInformation() const {
194 return generate_gdb_information_;
195 }
196
Alex Light53cb16b2014-06-12 11:26:29 -0700197 bool GetIncludePatchInformation() const {
198 return include_patch_information_;
199 }
200
Igor Murashkind6dee672014-10-16 18:36:16 -0700201 // Should the code be compiled as position independent?
202 bool GetCompilePic() const {
203 return compile_pic_;
204 }
205
Ian Rogersc7dd2952014-10-21 23:31:19 -0700206 bool HasVerboseMethods() const {
207 return verbose_methods_ != nullptr && !verbose_methods_->empty();
208 }
209
210 bool IsVerboseMethod(const std::string& pretty_method) const {
211 for (const std::string& cur_method : *verbose_methods_) {
212 if (pretty_method.find(cur_method) != std::string::npos) {
213 return true;
214 }
215 }
216 return false;
217 }
218
Brian Carlstrom6449c622014-02-10 23:48:36 -0800219 private:
220 CompilerFilter compiler_filter_;
Ian Rogersc7dd2952014-10-21 23:31:19 -0700221 const size_t huge_method_threshold_;
222 const size_t large_method_threshold_;
223 const size_t small_method_threshold_;
224 const size_t tiny_method_threshold_;
225 const size_t num_dex_methods_threshold_;
226 const bool generate_gdb_information_;
227 const bool include_patch_information_;
Calin Juravlec1b643c2014-05-30 23:44:11 +0100228 // When using a profile file only the top K% of the profiled samples will be compiled.
Ian Rogersc7dd2952014-10-21 23:31:19 -0700229 const double top_k_profile_threshold_;
230 const bool include_debug_symbols_;
231 const bool implicit_null_checks_;
232 const bool implicit_so_checks_;
233 const bool implicit_suspend_checks_;
234 const bool compile_pic_;
235
Brian Carlstrom6449c622014-02-10 23:48:36 -0800236#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -0700237 const bool sea_ir_mode_;
Brian Carlstrom6449c622014-02-10 23:48:36 -0800238#endif
Ian Rogersc7dd2952014-10-21 23:31:19 -0700239
240 // Vector of methods to have verbose output enabled for.
241 const std::vector<std::string>* const verbose_methods_;
242
243 DISALLOW_COPY_AND_ASSIGN(CompilerOptions);
Brian Carlstrom6449c622014-02-10 23:48:36 -0800244};
245
246} // namespace art
247
248#endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_