Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 1 | /* |
| 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 Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include "base/macros.h" |
| 24 | |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 25 | namespace art { |
| 26 | |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 27 | class CompilerOptions FINAL { |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 28 | public: |
| 29 | enum CompilerFilter { |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 30 | kVerifyNone, // Skip verification and compile nothing except JNI stubs. |
| 31 | kInterpretOnly, // Compile nothing except JNI stubs. |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 32 | kSpace, // Maximize space savings. |
| 33 | kBalanced, // Try to get the best performance return on compilation investment. |
| 34 | kSpeed, // Maximize runtime performance. |
Nicolas Geoffray | 88157ef | 2014-09-12 10:29:53 +0100 | [diff] [blame] | 35 | kEverything, // Force compilation (Note: excludes compilation of class initializers). |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 36 | kTime, // Compile methods, but minimize compilation time. |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | // Guide heuristics to determine whether to compile method if profile data not available. |
Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 40 | #if ART_SMALL_MODE |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 41 | static const CompilerFilter kDefaultCompilerFilter = kInterpretOnly; |
Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 42 | #else |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 43 | static const CompilerFilter kDefaultCompilerFilter = kSpeed; |
Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 44 | #endif |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 45 | 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 Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 50 | static constexpr double kDefaultTopKProfileThreshold = 90.0; |
Alex Light | 78382fa | 2014-06-06 15:45:32 -0700 | [diff] [blame] | 51 | static const bool kDefaultIncludeDebugSymbols = kIsDebugBuild; |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 52 | static const bool kDefaultIncludePatchInformation = false; |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 53 | |
| 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 Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 60 | num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold), |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 61 | generate_gdb_information_(false), |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 62 | include_patch_information_(kDefaultIncludePatchInformation), |
Alex Light | 78382fa | 2014-06-06 15:45:32 -0700 | [diff] [blame] | 63 | top_k_profile_threshold_(kDefaultTopKProfileThreshold), |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 64 | include_debug_symbols_(kDefaultIncludeDebugSymbols), |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 65 | implicit_null_checks_(false), |
| 66 | implicit_so_checks_(false), |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 67 | implicit_suspend_checks_(false), |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 68 | compile_pic_(false), |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 69 | #ifdef ART_SEA_IR_MODE |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 70 | sea_ir_mode_(false), |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 71 | #endif |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 72 | verbose_methods_(nullptr) { |
| 73 | } |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 74 | |
| 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 Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 80 | size_t num_dex_methods_threshold, |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 81 | bool generate_gdb_information, |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 82 | bool include_patch_information, |
Alex Light | 78382fa | 2014-06-06 15:45:32 -0700 | [diff] [blame] | 83 | double top_k_profile_threshold, |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 84 | bool include_debug_symbols, |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 85 | bool implicit_null_checks, |
| 86 | bool implicit_so_checks, |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 87 | bool implicit_suspend_checks, |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 88 | bool compile_pic, |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 89 | #ifdef ART_SEA_IR_MODE |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 90 | bool sea_ir_mode, |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 91 | #endif |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 92 | const std::vector<std::string>* verbose_methods |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 93 | ) : // 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 Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 99 | num_dex_methods_threshold_(num_dex_methods_threshold), |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 100 | generate_gdb_information_(generate_gdb_information), |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 101 | include_patch_information_(include_patch_information), |
Alex Light | 78382fa | 2014-06-06 15:45:32 -0700 | [diff] [blame] | 102 | top_k_profile_threshold_(top_k_profile_threshold), |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 103 | include_debug_symbols_(include_debug_symbols), |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 104 | implicit_null_checks_(implicit_null_checks), |
| 105 | implicit_so_checks_(implicit_so_checks), |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 106 | implicit_suspend_checks_(implicit_suspend_checks), |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 107 | compile_pic_(compile_pic), |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 108 | #ifdef ART_SEA_IR_MODE |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 109 | sea_ir_mode_(sea_ir_mode), |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 110 | #endif |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 111 | verbose_methods_(verbose_methods) { |
| 112 | } |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 113 | |
| 114 | CompilerFilter GetCompilerFilter() const { |
| 115 | return compiler_filter_; |
| 116 | } |
| 117 | |
| 118 | void SetCompilerFilter(CompilerFilter compiler_filter) { |
| 119 | compiler_filter_ = compiler_filter; |
| 120 | } |
| 121 | |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 122 | 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 Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 131 | 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 Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 167 | double GetTopKProfileThreshold() const { |
| 168 | return top_k_profile_threshold_; |
| 169 | } |
| 170 | |
Alex Light | 78382fa | 2014-06-06 15:45:32 -0700 | [diff] [blame] | 171 | bool GetIncludeDebugSymbols() const { |
| 172 | return include_debug_symbols_; |
| 173 | } |
| 174 | |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 175 | bool GetImplicitNullChecks() const { |
| 176 | return implicit_null_checks_; |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 179 | bool GetImplicitStackOverflowChecks() const { |
| 180 | return implicit_so_checks_; |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 183 | bool GetImplicitSuspendChecks() const { |
| 184 | return implicit_suspend_checks_; |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 187 | #ifdef ART_SEA_IR_MODE |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 188 | bool GetSeaIrMode() const { |
| 189 | return sea_ir_mode_; |
| 190 | } |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 191 | #endif |
| 192 | |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 193 | bool GetGenerateGDBInformation() const { |
| 194 | return generate_gdb_information_; |
| 195 | } |
| 196 | |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 197 | bool GetIncludePatchInformation() const { |
| 198 | return include_patch_information_; |
| 199 | } |
| 200 | |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 201 | // Should the code be compiled as position independent? |
| 202 | bool GetCompilePic() const { |
| 203 | return compile_pic_; |
| 204 | } |
| 205 | |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 206 | 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 Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 219 | private: |
| 220 | CompilerFilter compiler_filter_; |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 221 | 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 Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 228 | // When using a profile file only the top K% of the profiled samples will be compiled. |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 229 | 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 Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 236 | #ifdef ART_SEA_IR_MODE |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 237 | const bool sea_ir_mode_; |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 238 | #endif |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame^] | 239 | |
| 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 Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | } // namespace art |
| 247 | |
| 248 | #endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_ |