blob: 0592f0cf1e8b7c5d73d8e7410afb3e5d70396078 [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"
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070024#include "globals.h"
Ian Rogersc7dd2952014-10-21 23:31:19 -070025
Brian Carlstrom6449c622014-02-10 23:48:36 -080026namespace art {
27
Ian Rogersc7dd2952014-10-21 23:31:19 -070028class CompilerOptions FINAL {
Brian Carlstrom6449c622014-02-10 23:48:36 -080029 public:
30 enum CompilerFilter {
Jeff Hao4a200f52014-04-01 14:58:49 -070031 kVerifyNone, // Skip verification and compile nothing except JNI stubs.
32 kInterpretOnly, // Compile nothing except JNI stubs.
Brian Carlstrom6449c622014-02-10 23:48:36 -080033 kSpace, // Maximize space savings.
34 kBalanced, // Try to get the best performance return on compilation investment.
35 kSpeed, // Maximize runtime performance.
Nicolas Geoffray88157ef2014-09-12 10:29:53 +010036 kEverything, // Force compilation (Note: excludes compilation of class initializers).
Igor Murashkind6dee672014-10-16 18:36:16 -070037 kTime, // Compile methods, but minimize compilation time.
Brian Carlstrom6449c622014-02-10 23:48:36 -080038 };
39
40 // Guide heuristics to determine whether to compile method if profile data not available.
Dave Allison39c3bfb2014-01-28 18:33:52 -080041#if ART_SMALL_MODE
Calin Juravlec1b643c2014-05-30 23:44:11 +010042 static const CompilerFilter kDefaultCompilerFilter = kInterpretOnly;
Dave Allison39c3bfb2014-01-28 18:33:52 -080043#else
Brian Carlstrom6449c622014-02-10 23:48:36 -080044 static const CompilerFilter kDefaultCompilerFilter = kSpeed;
Dave Allison39c3bfb2014-01-28 18:33:52 -080045#endif
Brian Carlstrom6449c622014-02-10 23:48:36 -080046 static const size_t kDefaultHugeMethodThreshold = 10000;
47 static const size_t kDefaultLargeMethodThreshold = 600;
48 static const size_t kDefaultSmallMethodThreshold = 60;
49 static const size_t kDefaultTinyMethodThreshold = 20;
50 static const size_t kDefaultNumDexMethodsThreshold = 900;
Calin Juravlec1b643c2014-05-30 23:44:11 +010051 static constexpr double kDefaultTopKProfileThreshold = 90.0;
Alex Light78382fa2014-06-06 15:45:32 -070052 static const bool kDefaultIncludeDebugSymbols = kIsDebugBuild;
Alex Light53cb16b2014-06-12 11:26:29 -070053 static const bool kDefaultIncludePatchInformation = false;
Brian Carlstrom6449c622014-02-10 23:48:36 -080054
55 CompilerOptions() :
56 compiler_filter_(kDefaultCompilerFilter),
57 huge_method_threshold_(kDefaultHugeMethodThreshold),
58 large_method_threshold_(kDefaultLargeMethodThreshold),
59 small_method_threshold_(kDefaultSmallMethodThreshold),
60 tiny_method_threshold_(kDefaultTinyMethodThreshold),
Mark Mendellae9fd932014-02-10 16:14:35 -080061 num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold),
Calin Juravlec1b643c2014-05-30 23:44:11 +010062 generate_gdb_information_(false),
Alex Light53cb16b2014-06-12 11:26:29 -070063 include_patch_information_(kDefaultIncludePatchInformation),
Alex Light78382fa2014-06-06 15:45:32 -070064 top_k_profile_threshold_(kDefaultTopKProfileThreshold),
Andreas Gampe5655e842014-06-17 16:36:07 -070065 include_debug_symbols_(kDefaultIncludeDebugSymbols),
Dave Allison69dfe512014-07-11 17:11:58 +000066 implicit_null_checks_(false),
67 implicit_so_checks_(false),
Igor Murashkind6dee672014-10-16 18:36:16 -070068 implicit_suspend_checks_(false),
Ian Rogersc7dd2952014-10-21 23:31:19 -070069 compile_pic_(false),
Brian Carlstrom6449c622014-02-10 23:48:36 -080070#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -070071 sea_ir_mode_(false),
Brian Carlstrom6449c622014-02-10 23:48:36 -080072#endif
Ian Rogersc7dd2952014-10-21 23:31:19 -070073 verbose_methods_(nullptr) {
74 }
Brian Carlstrom6449c622014-02-10 23:48:36 -080075
76 CompilerOptions(CompilerFilter compiler_filter,
77 size_t huge_method_threshold,
78 size_t large_method_threshold,
79 size_t small_method_threshold,
80 size_t tiny_method_threshold,
Mark Mendellae9fd932014-02-10 16:14:35 -080081 size_t num_dex_methods_threshold,
Calin Juravlec1b643c2014-05-30 23:44:11 +010082 bool generate_gdb_information,
Alex Light53cb16b2014-06-12 11:26:29 -070083 bool include_patch_information,
Alex Light78382fa2014-06-06 15:45:32 -070084 double top_k_profile_threshold,
Andreas Gampe5655e842014-06-17 16:36:07 -070085 bool include_debug_symbols,
Dave Allison69dfe512014-07-11 17:11:58 +000086 bool implicit_null_checks,
87 bool implicit_so_checks,
Igor Murashkind6dee672014-10-16 18:36:16 -070088 bool implicit_suspend_checks,
Ian Rogersc7dd2952014-10-21 23:31:19 -070089 bool compile_pic,
Brian Carlstrom6449c622014-02-10 23:48:36 -080090#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -070091 bool sea_ir_mode,
Brian Carlstrom6449c622014-02-10 23:48:36 -080092#endif
Ian Rogersc7dd2952014-10-21 23:31:19 -070093 const std::vector<std::string>* verbose_methods
Brian Carlstrom6449c622014-02-10 23:48:36 -080094 ) : // NOLINT(whitespace/parens)
95 compiler_filter_(compiler_filter),
96 huge_method_threshold_(huge_method_threshold),
97 large_method_threshold_(large_method_threshold),
98 small_method_threshold_(small_method_threshold),
99 tiny_method_threshold_(tiny_method_threshold),
Mark Mendellae9fd932014-02-10 16:14:35 -0800100 num_dex_methods_threshold_(num_dex_methods_threshold),
Calin Juravlec1b643c2014-05-30 23:44:11 +0100101 generate_gdb_information_(generate_gdb_information),
Alex Light53cb16b2014-06-12 11:26:29 -0700102 include_patch_information_(include_patch_information),
Alex Light78382fa2014-06-06 15:45:32 -0700103 top_k_profile_threshold_(top_k_profile_threshold),
Andreas Gampe5655e842014-06-17 16:36:07 -0700104 include_debug_symbols_(include_debug_symbols),
Dave Allison69dfe512014-07-11 17:11:58 +0000105 implicit_null_checks_(implicit_null_checks),
106 implicit_so_checks_(implicit_so_checks),
Igor Murashkind6dee672014-10-16 18:36:16 -0700107 implicit_suspend_checks_(implicit_suspend_checks),
Ian Rogersc7dd2952014-10-21 23:31:19 -0700108 compile_pic_(compile_pic),
Brian Carlstrom6449c622014-02-10 23:48:36 -0800109#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -0700110 sea_ir_mode_(sea_ir_mode),
Brian Carlstrom6449c622014-02-10 23:48:36 -0800111#endif
Ian Rogersc7dd2952014-10-21 23:31:19 -0700112 verbose_methods_(verbose_methods) {
113 }
Brian Carlstrom6449c622014-02-10 23:48:36 -0800114
115 CompilerFilter GetCompilerFilter() const {
116 return compiler_filter_;
117 }
118
119 void SetCompilerFilter(CompilerFilter compiler_filter) {
120 compiler_filter_ = compiler_filter;
121 }
122
Jeff Hao4a200f52014-04-01 14:58:49 -0700123 bool IsCompilationEnabled() const {
124 return ((compiler_filter_ != CompilerOptions::kVerifyNone) &&
125 (compiler_filter_ != CompilerOptions::kInterpretOnly));
126 }
127
128 bool IsVerificationEnabled() const {
129 return (compiler_filter_ != CompilerOptions::kVerifyNone);
130 }
131
Brian Carlstrom6449c622014-02-10 23:48:36 -0800132 size_t GetHugeMethodThreshold() const {
133 return huge_method_threshold_;
134 }
135
136 size_t GetLargeMethodThreshold() const {
137 return large_method_threshold_;
138 }
139
140 size_t GetSmallMethodThreshold() const {
141 return small_method_threshold_;
142 }
143
144 size_t GetTinyMethodThreshold() const {
145 return tiny_method_threshold_;
146 }
147
148 bool IsHugeMethod(size_t num_dalvik_instructions) const {
149 return num_dalvik_instructions > huge_method_threshold_;
150 }
151
152 bool IsLargeMethod(size_t num_dalvik_instructions) const {
153 return num_dalvik_instructions > large_method_threshold_;
154 }
155
156 bool IsSmallMethod(size_t num_dalvik_instructions) const {
157 return num_dalvik_instructions > small_method_threshold_;
158 }
159
160 bool IsTinyMethod(size_t num_dalvik_instructions) const {
161 return num_dalvik_instructions > tiny_method_threshold_;
162 }
163
164 size_t GetNumDexMethodsThreshold() const {
165 return num_dex_methods_threshold_;
166 }
167
Calin Juravlec1b643c2014-05-30 23:44:11 +0100168 double GetTopKProfileThreshold() const {
169 return top_k_profile_threshold_;
170 }
171
Alex Light78382fa2014-06-06 15:45:32 -0700172 bool GetIncludeDebugSymbols() const {
173 return include_debug_symbols_;
174 }
175
Dave Allison69dfe512014-07-11 17:11:58 +0000176 bool GetImplicitNullChecks() const {
177 return implicit_null_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700178 }
179
Dave Allison69dfe512014-07-11 17:11:58 +0000180 bool GetImplicitStackOverflowChecks() const {
181 return implicit_so_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700182 }
183
Dave Allison69dfe512014-07-11 17:11:58 +0000184 bool GetImplicitSuspendChecks() const {
185 return implicit_suspend_checks_;
Andreas Gampe5655e842014-06-17 16:36:07 -0700186 }
187
Brian Carlstrom6449c622014-02-10 23:48:36 -0800188#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -0700189 bool GetSeaIrMode() const {
190 return sea_ir_mode_;
191 }
Brian Carlstrom6449c622014-02-10 23:48:36 -0800192#endif
193
Mark Mendellae9fd932014-02-10 16:14:35 -0800194 bool GetGenerateGDBInformation() const {
195 return generate_gdb_information_;
196 }
197
Alex Light53cb16b2014-06-12 11:26:29 -0700198 bool GetIncludePatchInformation() const {
199 return include_patch_information_;
200 }
201
Igor Murashkind6dee672014-10-16 18:36:16 -0700202 // Should the code be compiled as position independent?
203 bool GetCompilePic() const {
204 return compile_pic_;
205 }
206
Ian Rogersc7dd2952014-10-21 23:31:19 -0700207 bool HasVerboseMethods() const {
208 return verbose_methods_ != nullptr && !verbose_methods_->empty();
209 }
210
211 bool IsVerboseMethod(const std::string& pretty_method) const {
212 for (const std::string& cur_method : *verbose_methods_) {
213 if (pretty_method.find(cur_method) != std::string::npos) {
214 return true;
215 }
216 }
217 return false;
218 }
219
Brian Carlstrom6449c622014-02-10 23:48:36 -0800220 private:
221 CompilerFilter compiler_filter_;
Ian Rogersc7dd2952014-10-21 23:31:19 -0700222 const size_t huge_method_threshold_;
223 const size_t large_method_threshold_;
224 const size_t small_method_threshold_;
225 const size_t tiny_method_threshold_;
226 const size_t num_dex_methods_threshold_;
227 const bool generate_gdb_information_;
228 const bool include_patch_information_;
Calin Juravlec1b643c2014-05-30 23:44:11 +0100229 // When using a profile file only the top K% of the profiled samples will be compiled.
Ian Rogersc7dd2952014-10-21 23:31:19 -0700230 const double top_k_profile_threshold_;
231 const bool include_debug_symbols_;
232 const bool implicit_null_checks_;
233 const bool implicit_so_checks_;
234 const bool implicit_suspend_checks_;
235 const bool compile_pic_;
236
Brian Carlstrom6449c622014-02-10 23:48:36 -0800237#ifdef ART_SEA_IR_MODE
Ian Rogersc7dd2952014-10-21 23:31:19 -0700238 const bool sea_ir_mode_;
Brian Carlstrom6449c622014-02-10 23:48:36 -0800239#endif
Ian Rogersc7dd2952014-10-21 23:31:19 -0700240
241 // Vector of methods to have verbose output enabled for.
242 const std::vector<std::string>* const verbose_methods_;
243
244 DISALLOW_COPY_AND_ASSIGN(CompilerOptions);
Brian Carlstrom6449c622014-02-10 23:48:36 -0800245};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700246std::ostream& operator<<(std::ostream& os, const CompilerOptions::CompilerFilter& rhs);
Brian Carlstrom6449c622014-02-10 23:48:36 -0800247
248} // namespace art
249
250#endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_