blob: c0a9a05aa6b050d02bf17cbe8fd864c162d4853b [file] [log] [blame]
Mathieu Chartier5bdab122015-01-26 18:30:19 -08001/*
2 * Copyright (C) 2015 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#include "compiler_options.h"
18
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000019#include <fstream>
20
Andreas Gampe097f34c2017-08-23 08:57:51 -070021#include "android-base/stringprintf.h"
22
23#include "base/variant_map.h"
24#include "cmdline_parser.h"
25#include "compiler_options_map-inl.h"
Roland Levillain2b03a1f2017-06-06 16:09:59 +010026#include "runtime.h"
Andreas Gampe097f34c2017-08-23 08:57:51 -070027#include "simple_compiler_options_map.h"
Roland Levillain2b03a1f2017-06-06 16:09:59 +010028
Mathieu Chartier5bdab122015-01-26 18:30:19 -080029namespace art {
30
31CompilerOptions::CompilerOptions()
Richard Uhlerf4b34872016-04-13 11:03:46 -070032 : compiler_filter_(CompilerFilter::kDefaultCompilerFilter),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080033 huge_method_threshold_(kDefaultHugeMethodThreshold),
34 large_method_threshold_(kDefaultLargeMethodThreshold),
35 small_method_threshold_(kDefaultSmallMethodThreshold),
36 tiny_method_threshold_(kDefaultTinyMethodThreshold),
37 num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold),
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000038 inline_max_code_units_(kUnsetInlineMaxCodeUnits),
Jeff Haodcdc85b2015-12-04 14:06:18 -080039 no_inline_from_(nullptr),
Vladimir Markoaad75c62016-10-03 08:46:48 +000040 boot_image_(false),
Roland Levillain2b03a1f2017-06-06 16:09:59 +010041 core_image_(false),
Vladimir Markoaad75c62016-10-03 08:46:48 +000042 app_image_(false),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080043 top_k_profile_threshold_(kDefaultTopKProfileThreshold),
Andreas Gampe7b2f09e2015-03-02 14:07:33 -080044 debuggable_(false),
David Srbecky8363c772015-05-28 16:12:43 +010045 generate_debug_info_(kDefaultGenerateDebugInfo),
David Srbecky5b1c2ca2016-01-25 17:32:41 +000046 generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo),
Alexey Alexandrovab40c112016-09-19 09:33:49 -070047 generate_build_id_(false),
Mathieu Chartier5bdab122015-01-26 18:30:19 -080048 implicit_null_checks_(true),
49 implicit_so_checks_(true),
50 implicit_suspend_checks_(false),
51 compile_pic_(false),
Nicolas Geoffray2d8801f2017-11-28 15:50:07 +000052 dump_timings_(false),
53 dump_stats_(false),
Nicolas Geoffray57c47042017-06-29 11:31:39 +010054 verbose_methods_(),
Andreas Gampe6cf49e52015-03-05 13:08:45 -080055 abort_on_hard_verifier_failure_(false),
Andreas Gampef39208f2017-10-19 15:06:59 -070056 abort_on_soft_verifier_failure_(false),
Nicolas Geoffrayc903b6a2016-01-18 12:56:06 +000057 init_failure_output_(nullptr),
58 dump_cfg_file_name_(""),
Andreas Gampeace0dc12016-01-20 13:33:13 -080059 dump_cfg_append_(false),
Matthew Gharrity2cd05b72016-08-03 16:57:37 -070060 force_determinism_(false),
Andreas Gampecac31ad2017-11-06 20:01:17 -080061 deduplicate_code_(true),
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -070062 register_allocation_strategy_(RegisterAllocator::kRegisterAllocatorDefault),
63 passes_to_run_(nullptr) {
Mathieu Chartier5bdab122015-01-26 18:30:19 -080064}
65
Vladimir Markob163bb72015-03-31 21:49:49 +010066CompilerOptions::~CompilerOptions() {
67 // The destructor looks empty but it destroys a PassManagerOptions object. We keep it here
68 // because we don't want to include the PassManagerOptions definition from the header file.
69}
70
Roland Levillain2b03a1f2017-06-06 16:09:59 +010071bool CompilerOptions::EmitRunTimeChecksInDebugMode() const {
72 // Run-time checks (e.g. Marking Register checks) are only emitted
73 // in debug mode, and
74 // - when running on device; or
75 // - when running on host, but only
76 // - when compiling the core image (which is used only for testing); or
77 // - when JIT compiling (only relevant for non-native methods).
78 // This is to prevent these checks from being emitted into pre-opted
79 // boot image or apps, as these are compiled with dex2oatd.
80 return kIsDebugBuild &&
81 (kIsTargetBuild || IsCoreImage() || Runtime::Current()->UseJitCompilation());
82}
83
Andreas Gampe097f34c2017-08-23 08:57:51 -070084bool CompilerOptions::ParseDumpInitFailures(const std::string& option, std::string* error_msg) {
85 init_failure_output_.reset(new std::ofstream(option));
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000086 if (init_failure_output_.get() == nullptr) {
Andreas Gampe097f34c2017-08-23 08:57:51 -070087 *error_msg = "Failed to construct std::ofstream";
88 return false;
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000089 } else if (init_failure_output_->fail()) {
Andreas Gampe097f34c2017-08-23 08:57:51 -070090 *error_msg = android::base::StringPrintf(
91 "Failed to open %s for writing the initialization failures.", option.c_str());
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000092 init_failure_output_.reset();
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +000093 return false;
94 }
95 return true;
96}
97
Andreas Gampe097f34c2017-08-23 08:57:51 -070098bool CompilerOptions::ParseRegisterAllocationStrategy(const std::string& option,
99 std::string* error_msg) {
100 if (option == "linear-scan") {
101 register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorLinearScan;
102 } else if (option == "graph-color") {
103 register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorGraphColor;
104 } else {
105 *error_msg = "Unrecognized register allocation strategy. Try linear-scan, or graph-color.";
106 return false;
107 }
108 return true;
109}
110
111#pragma GCC diagnostic push
112#pragma GCC diagnostic ignored "-Wframe-larger-than="
113
114bool CompilerOptions::ParseCompilerOptions(const std::vector<std::string>& options,
115 bool ignore_unrecognized,
116 std::string* error_msg) {
117 auto parser = CreateSimpleParser(ignore_unrecognized);
118 CmdlineResult parse_result = parser.Parse(options);
119 if (!parse_result.IsSuccess()) {
120 *error_msg = parse_result.GetMessage();
121 return false;
122 }
123
124 SimpleParseArgumentMap args = parser.ReleaseArgumentsMap();
125 return ReadCompilerOptions(args, this, error_msg);
126}
127
128#pragma GCC diagnostic pop
129
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800130} // namespace art