compiler_options.h revision 57c47043f3ee4233f31bad921ea91a5c411f1dad
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
20#include <ostream>
21#include <string>
22#include <vector>
23
24#include "base/macros.h"
25#include "compiler_filter.h"
26#include "globals.h"
27#include "optimizing/register_allocator.h"
28#include "utils.h"
29
30namespace art {
31
32namespace verifier {
33  class VerifierDepsTest;
34}  // namespace verifier
35
36class DexFile;
37
38class CompilerOptions FINAL {
39 public:
40  // Guide heuristics to determine whether to compile method if profile data not available.
41  static const size_t kDefaultHugeMethodThreshold = 10000;
42  static const size_t kDefaultLargeMethodThreshold = 600;
43  static const size_t kDefaultSmallMethodThreshold = 60;
44  static const size_t kDefaultTinyMethodThreshold = 20;
45  static const size_t kDefaultNumDexMethodsThreshold = 900;
46  static constexpr double kDefaultTopKProfileThreshold = 90.0;
47  static const bool kDefaultGenerateDebugInfo = false;
48  static const bool kDefaultGenerateMiniDebugInfo = false;
49  static const size_t kDefaultInlineMaxCodeUnits = 32;
50  static constexpr size_t kUnsetInlineMaxCodeUnits = -1;
51
52  CompilerOptions();
53  ~CompilerOptions();
54
55  CompilerFilter::Filter GetCompilerFilter() const {
56    return compiler_filter_;
57  }
58
59  void SetCompilerFilter(CompilerFilter::Filter compiler_filter) {
60    compiler_filter_ = compiler_filter;
61  }
62
63  bool IsAotCompilationEnabled() const {
64    return CompilerFilter::IsAotCompilationEnabled(compiler_filter_);
65  }
66
67  bool IsJniCompilationEnabled() const {
68    return CompilerFilter::IsJniCompilationEnabled(compiler_filter_);
69  }
70
71  bool IsQuickeningCompilationEnabled() const {
72    return CompilerFilter::IsQuickeningCompilationEnabled(compiler_filter_);
73  }
74
75  bool IsVerificationEnabled() const {
76    return CompilerFilter::IsVerificationEnabled(compiler_filter_);
77  }
78
79  bool AssumeClassesAreVerified() const {
80    return compiler_filter_ == CompilerFilter::kAssumeVerified;
81  }
82
83  bool VerifyAtRuntime() const {
84    return compiler_filter_ == CompilerFilter::kExtract;
85  }
86
87  bool IsAnyCompilationEnabled() const {
88    return CompilerFilter::IsAnyCompilationEnabled(compiler_filter_);
89  }
90
91  size_t GetHugeMethodThreshold() const {
92    return huge_method_threshold_;
93  }
94
95  size_t GetLargeMethodThreshold() const {
96    return large_method_threshold_;
97  }
98
99  size_t GetSmallMethodThreshold() const {
100    return small_method_threshold_;
101  }
102
103  size_t GetTinyMethodThreshold() const {
104    return tiny_method_threshold_;
105  }
106
107  bool IsHugeMethod(size_t num_dalvik_instructions) const {
108    return num_dalvik_instructions > huge_method_threshold_;
109  }
110
111  bool IsLargeMethod(size_t num_dalvik_instructions) const {
112    return num_dalvik_instructions > large_method_threshold_;
113  }
114
115  bool IsSmallMethod(size_t num_dalvik_instructions) const {
116    return num_dalvik_instructions > small_method_threshold_;
117  }
118
119  bool IsTinyMethod(size_t num_dalvik_instructions) const {
120    return num_dalvik_instructions > tiny_method_threshold_;
121  }
122
123  size_t GetNumDexMethodsThreshold() const {
124    return num_dex_methods_threshold_;
125  }
126
127  size_t GetInlineMaxCodeUnits() const {
128    return inline_max_code_units_;
129  }
130  void SetInlineMaxCodeUnits(size_t units) {
131    inline_max_code_units_ = units;
132  }
133
134  double GetTopKProfileThreshold() const {
135    return top_k_profile_threshold_;
136  }
137
138  bool GetDebuggable() const {
139    return debuggable_;
140  }
141
142  void SetDebuggable(bool value) {
143    debuggable_ = value;
144  }
145
146  bool GetNativeDebuggable() const {
147    return GetDebuggable() && GetGenerateDebugInfo();
148  }
149
150  // This flag controls whether the compiler collects debugging information.
151  // The other flags control how the information is written to disk.
152  bool GenerateAnyDebugInfo() const {
153    return GetGenerateDebugInfo() || GetGenerateMiniDebugInfo();
154  }
155
156  bool GetGenerateDebugInfo() const {
157    return generate_debug_info_;
158  }
159
160  bool GetGenerateMiniDebugInfo() const {
161    return generate_mini_debug_info_;
162  }
163
164  bool GetGenerateBuildId() const {
165    return generate_build_id_;
166  }
167
168  bool GetImplicitNullChecks() const {
169    return implicit_null_checks_;
170  }
171
172  bool GetImplicitStackOverflowChecks() const {
173    return implicit_so_checks_;
174  }
175
176  bool GetImplicitSuspendChecks() const {
177    return implicit_suspend_checks_;
178  }
179
180  bool IsBootImage() const {
181    return boot_image_;
182  }
183
184  bool IsAppImage() const {
185    return app_image_;
186  }
187
188  // Should the code be compiled as position independent?
189  bool GetCompilePic() const {
190    return compile_pic_;
191  }
192
193  bool HasVerboseMethods() const {
194    return !verbose_methods_.empty();
195  }
196
197  bool IsVerboseMethod(const std::string& pretty_method) const {
198    for (const std::string& cur_method : verbose_methods_) {
199      if (pretty_method.find(cur_method) != std::string::npos) {
200        return true;
201      }
202    }
203    return false;
204  }
205
206  std::ostream* GetInitFailureOutput() const {
207    return init_failure_output_.get();
208  }
209
210  bool AbortOnHardVerifierFailure() const {
211    return abort_on_hard_verifier_failure_;
212  }
213
214  const std::vector<const DexFile*>* GetNoInlineFromDexFile() const {
215    return no_inline_from_;
216  }
217
218  bool ParseCompilerOption(const StringPiece& option, UsageFn Usage);
219
220  void SetNonPic() {
221    compile_pic_ = false;
222  }
223
224  const std::string& GetDumpCfgFileName() const {
225    return dump_cfg_file_name_;
226  }
227
228  bool GetDumpCfgAppend() const {
229    return dump_cfg_append_;
230  }
231
232  bool IsForceDeterminism() const {
233    return force_determinism_;
234  }
235
236  RegisterAllocator::Strategy GetRegisterAllocationStrategy() const {
237    return register_allocation_strategy_;
238  }
239
240  const std::vector<std::string>* GetPassesToRun() const {
241    return passes_to_run_;
242  }
243
244 private:
245  void ParseDumpInitFailures(const StringPiece& option, UsageFn Usage);
246  void ParseDumpCfgPasses(const StringPiece& option, UsageFn Usage);
247  void ParseInlineMaxCodeUnits(const StringPiece& option, UsageFn Usage);
248  void ParseNumDexMethods(const StringPiece& option, UsageFn Usage);
249  void ParseTinyMethodMax(const StringPiece& option, UsageFn Usage);
250  void ParseSmallMethodMax(const StringPiece& option, UsageFn Usage);
251  void ParseLargeMethodMax(const StringPiece& option, UsageFn Usage);
252  void ParseHugeMethodMax(const StringPiece& option, UsageFn Usage);
253  void ParseRegisterAllocationStrategy(const StringPiece& option, UsageFn Usage);
254
255  CompilerFilter::Filter compiler_filter_;
256  size_t huge_method_threshold_;
257  size_t large_method_threshold_;
258  size_t small_method_threshold_;
259  size_t tiny_method_threshold_;
260  size_t num_dex_methods_threshold_;
261  size_t inline_max_code_units_;
262
263  // Dex files from which we should not inline code.
264  // This is usually a very short list (i.e. a single dex file), so we
265  // prefer vector<> over a lookup-oriented container, such as set<>.
266  const std::vector<const DexFile*>* no_inline_from_;
267
268  bool boot_image_;
269  bool app_image_;
270  // When using a profile file only the top K% of the profiled samples will be compiled.
271  double top_k_profile_threshold_;
272  bool debuggable_;
273  bool generate_debug_info_;
274  bool generate_mini_debug_info_;
275  bool generate_build_id_;
276  bool implicit_null_checks_;
277  bool implicit_so_checks_;
278  bool implicit_suspend_checks_;
279  bool compile_pic_;
280
281  // Vector of methods to have verbose output enabled for.
282  std::vector<std::string> verbose_methods_;
283
284  // Abort compilation with an error if we find a class that fails verification with a hard
285  // failure.
286  bool abort_on_hard_verifier_failure_;
287
288  // Log initialization of initialization failures to this stream if not null.
289  std::unique_ptr<std::ostream> init_failure_output_;
290
291  std::string dump_cfg_file_name_;
292  bool dump_cfg_append_;
293
294  // Whether the compiler should trade performance for determinism to guarantee exactly reproducible
295  // outcomes.
296  bool force_determinism_;
297
298  RegisterAllocator::Strategy register_allocation_strategy_;
299
300  // If not null, specifies optimization passes which will be run instead of defaults.
301  // Note that passes_to_run_ is not checked for correctness and providing an incorrect
302  // list of passes can lead to unexpected compiler behaviour. This is caused by dependencies
303  // between passes. Failing to satisfy them can for example lead to compiler crashes.
304  // Passing pass names which are not recognized by the compiler will result in
305  // compiler-dependant behavior.
306  const std::vector<std::string>* passes_to_run_;
307
308  friend class Dex2Oat;
309  friend class DexToDexDecompilerTest;
310  friend class CommonCompilerTest;
311  friend class verifier::VerifierDepsTest;
312
313  DISALLOW_COPY_AND_ASSIGN(CompilerOptions);
314};
315
316}  // namespace art
317
318#endif  // ART_COMPILER_DRIVER_COMPILER_OPTIONS_H_
319