Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 1 | /* |
| 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 Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 19 | #include <fstream> |
| 20 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 21 | #include "android-base/stringprintf.h" |
| 22 | |
Andreas Gampe | 2a5d728 | 2018-01-02 11:53:35 -0800 | [diff] [blame^] | 23 | #include "base/runtime_debug.h" |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 24 | #include "base/variant_map.h" |
| 25 | #include "cmdline_parser.h" |
| 26 | #include "compiler_options_map-inl.h" |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 27 | #include "runtime.h" |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 28 | #include "simple_compiler_options_map.h" |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 29 | |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 30 | namespace art { |
| 31 | |
| 32 | CompilerOptions::CompilerOptions() |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 33 | : compiler_filter_(CompilerFilter::kDefaultCompilerFilter), |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 34 | huge_method_threshold_(kDefaultHugeMethodThreshold), |
| 35 | large_method_threshold_(kDefaultLargeMethodThreshold), |
| 36 | small_method_threshold_(kDefaultSmallMethodThreshold), |
| 37 | tiny_method_threshold_(kDefaultTinyMethodThreshold), |
| 38 | num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold), |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 39 | inline_max_code_units_(kUnsetInlineMaxCodeUnits), |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 40 | no_inline_from_(nullptr), |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 41 | boot_image_(false), |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 42 | core_image_(false), |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 43 | app_image_(false), |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 44 | top_k_profile_threshold_(kDefaultTopKProfileThreshold), |
Andreas Gampe | 7b2f09e | 2015-03-02 14:07:33 -0800 | [diff] [blame] | 45 | debuggable_(false), |
David Srbecky | 8363c77 | 2015-05-28 16:12:43 +0100 | [diff] [blame] | 46 | generate_debug_info_(kDefaultGenerateDebugInfo), |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame] | 47 | generate_mini_debug_info_(kDefaultGenerateMiniDebugInfo), |
Alexey Alexandrov | ab40c11 | 2016-09-19 09:33:49 -0700 | [diff] [blame] | 48 | generate_build_id_(false), |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 49 | implicit_null_checks_(true), |
| 50 | implicit_so_checks_(true), |
| 51 | implicit_suspend_checks_(false), |
| 52 | compile_pic_(false), |
Nicolas Geoffray | 2d8801f | 2017-11-28 15:50:07 +0000 | [diff] [blame] | 53 | dump_timings_(false), |
| 54 | dump_stats_(false), |
Nicolas Geoffray | 57c4704 | 2017-06-29 11:31:39 +0100 | [diff] [blame] | 55 | verbose_methods_(), |
Andreas Gampe | 6cf49e5 | 2015-03-05 13:08:45 -0800 | [diff] [blame] | 56 | abort_on_hard_verifier_failure_(false), |
Andreas Gampe | f39208f | 2017-10-19 15:06:59 -0700 | [diff] [blame] | 57 | abort_on_soft_verifier_failure_(false), |
Nicolas Geoffray | c903b6a | 2016-01-18 12:56:06 +0000 | [diff] [blame] | 58 | init_failure_output_(nullptr), |
| 59 | dump_cfg_file_name_(""), |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 60 | dump_cfg_append_(false), |
Matthew Gharrity | 2cd05b7 | 2016-08-03 16:57:37 -0700 | [diff] [blame] | 61 | force_determinism_(false), |
Andreas Gampe | cac31ad | 2017-11-06 20:01:17 -0800 | [diff] [blame] | 62 | deduplicate_code_(true), |
Wojciech Staszkiewicz | 5319d3c | 2016-08-01 17:48:59 -0700 | [diff] [blame] | 63 | register_allocation_strategy_(RegisterAllocator::kRegisterAllocatorDefault), |
| 64 | passes_to_run_(nullptr) { |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 67 | CompilerOptions::~CompilerOptions() { |
| 68 | // The destructor looks empty but it destroys a PassManagerOptions object. We keep it here |
| 69 | // because we don't want to include the PassManagerOptions definition from the header file. |
| 70 | } |
| 71 | |
Andreas Gampe | 2a5d728 | 2018-01-02 11:53:35 -0800 | [diff] [blame^] | 72 | namespace { |
| 73 | |
| 74 | bool kEmitRuntimeReadBarrierChecks = kIsDebugBuild && |
| 75 | RegisterRuntimeDebugFlag(&kEmitRuntimeReadBarrierChecks); |
| 76 | |
| 77 | } // namespace |
| 78 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 79 | bool CompilerOptions::EmitRunTimeChecksInDebugMode() const { |
Andreas Gampe | 2a5d728 | 2018-01-02 11:53:35 -0800 | [diff] [blame^] | 80 | // Run-time checks (e.g. Marking Register checks) are only emitted in slow-debug mode. |
| 81 | return kEmitRuntimeReadBarrierChecks; |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 84 | bool CompilerOptions::ParseDumpInitFailures(const std::string& option, std::string* error_msg) { |
| 85 | init_failure_output_.reset(new std::ofstream(option)); |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 86 | if (init_failure_output_.get() == nullptr) { |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 87 | *error_msg = "Failed to construct std::ofstream"; |
| 88 | return false; |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 89 | } else if (init_failure_output_->fail()) { |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 90 | *error_msg = android::base::StringPrintf( |
| 91 | "Failed to open %s for writing the initialization failures.", option.c_str()); |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 92 | init_failure_output_.reset(); |
Nicolas Geoffray | abbb0f7 | 2015-10-29 18:55:58 +0000 | [diff] [blame] | 93 | return false; |
| 94 | } |
| 95 | return true; |
| 96 | } |
| 97 | |
Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame] | 98 | bool 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 | |
| 114 | bool 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 Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 130 | } // namespace art |