Andreas Gampe | 097f34c | 2017-08-23 08:57:51 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 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_MAP_INL_H_ |
| 18 | #define ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_ |
| 19 | |
| 20 | #include "compiler_options_map.h" |
| 21 | |
| 22 | #include <memory> |
| 23 | |
| 24 | #include "android-base/logging.h" |
| 25 | #include "android-base/macros.h" |
| 26 | #include "android-base/stringprintf.h" |
| 27 | |
| 28 | #include "base/macros.h" |
| 29 | #include "cmdline_parser.h" |
| 30 | #include "compiler_options.h" |
| 31 | |
| 32 | namespace art { |
| 33 | |
| 34 | template <class Base> |
| 35 | inline bool ReadCompilerOptions(Base& map, CompilerOptions* options, std::string* error_msg) { |
| 36 | if (map.Exists(Base::CompilerFilter)) { |
| 37 | CompilerFilter::Filter compiler_filter; |
| 38 | if (!CompilerFilter::ParseCompilerFilter(map.Get(Base::CompilerFilter)->c_str(), |
| 39 | &compiler_filter)) { |
| 40 | *error_msg = android::base::StringPrintf("Unknown --compiler-filter value %s", |
| 41 | map.Get(Base::CompilerFilter)->c_str()); |
| 42 | return false; |
| 43 | } |
| 44 | options->SetCompilerFilter(compiler_filter); |
| 45 | } |
| 46 | if (map.Exists(Base::PIC)) { |
| 47 | options->compile_pic_ = true; |
| 48 | } |
| 49 | map.AssignIfExists(Base::HugeMethodMaxThreshold, &options->huge_method_threshold_); |
| 50 | map.AssignIfExists(Base::LargeMethodMaxThreshold, &options->large_method_threshold_); |
| 51 | map.AssignIfExists(Base::SmallMethodMaxThreshold, &options->small_method_threshold_); |
| 52 | map.AssignIfExists(Base::TinyMethodMaxThreshold, &options->tiny_method_threshold_); |
| 53 | map.AssignIfExists(Base::NumDexMethodsThreshold, &options->num_dex_methods_threshold_); |
| 54 | map.AssignIfExists(Base::InlineMaxCodeUnitsThreshold, &options->inline_max_code_units_); |
| 55 | map.AssignIfExists(Base::GenerateDebugInfo, &options->generate_debug_info_); |
| 56 | map.AssignIfExists(Base::GenerateMiniDebugInfo, &options->generate_mini_debug_info_); |
| 57 | map.AssignIfExists(Base::GenerateBuildID, &options->generate_build_id_); |
| 58 | if (map.Exists(Base::Debuggable)) { |
| 59 | options->debuggable_ = true; |
| 60 | } |
| 61 | map.AssignIfExists(Base::TopKProfileThreshold, &options->top_k_profile_threshold_); |
| 62 | map.AssignIfExists(Base::AbortOnHardVerifierFailure, &options->abort_on_hard_verifier_failure_); |
| 63 | if (map.Exists(Base::DumpInitFailures)) { |
| 64 | if (!options->ParseDumpInitFailures(*map.Get(Base::DumpInitFailures), error_msg)) { |
| 65 | return false; |
| 66 | } |
| 67 | } |
| 68 | map.AssignIfExists(Base::DumpCFG, &options->dump_cfg_file_name_); |
| 69 | if (map.Exists(Base::DumpCFGAppend)) { |
| 70 | options->dump_cfg_append_ = true; |
| 71 | } |
| 72 | if (map.Exists(Base::RegisterAllocationStrategy)) { |
| 73 | if (!options->ParseRegisterAllocationStrategy(*map.Get(Base::DumpInitFailures), error_msg)) { |
| 74 | return false; |
| 75 | } |
| 76 | } |
| 77 | map.AssignIfExists(Base::VerboseMethods, &options->verbose_methods_); |
| 78 | |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | #pragma GCC diagnostic push |
| 83 | #pragma GCC diagnostic ignored "-Wframe-larger-than=" |
| 84 | |
| 85 | template <typename Map, typename Builder> |
| 86 | inline void AddCompilerOptionsArgumentParserOptions(Builder& b) { |
| 87 | b. |
| 88 | Define("--compiler-filter=_") |
| 89 | .template WithType<std::string>() |
| 90 | .IntoKey(Map::CompilerFilter) |
| 91 | |
| 92 | .Define("--compile-pic") |
| 93 | .IntoKey(Map::PIC) |
| 94 | |
| 95 | .Define("--huge-method-max=_") |
| 96 | .template WithType<unsigned int>() |
| 97 | .IntoKey(Map::HugeMethodMaxThreshold) |
| 98 | .Define("--large-method-max=_") |
| 99 | .template WithType<unsigned int>() |
| 100 | .IntoKey(Map::LargeMethodMaxThreshold) |
| 101 | .Define("--small-method-max=_") |
| 102 | .template WithType<unsigned int>() |
| 103 | .IntoKey(Map::SmallMethodMaxThreshold) |
| 104 | .Define("--tiny-method-max=_") |
| 105 | .template WithType<unsigned int>() |
| 106 | .IntoKey(Map::TinyMethodMaxThreshold) |
| 107 | .Define("--num-dex-methods=_") |
| 108 | .template WithType<unsigned int>() |
| 109 | .IntoKey(Map::NumDexMethodsThreshold) |
| 110 | .Define("--inline-max-code-units=_") |
| 111 | .template WithType<unsigned int>() |
| 112 | .IntoKey(Map::InlineMaxCodeUnitsThreshold) |
| 113 | |
| 114 | .Define({"--generate-debug-info", "-g", "--no-generate-debug-info"}) |
| 115 | .WithValues({true, true, false}) |
| 116 | .IntoKey(Map::GenerateDebugInfo) |
| 117 | .Define({"--generate-mini-debug-info", "--no-generate-mini-debug-info"}) |
| 118 | .WithValues({true, false}) |
| 119 | .IntoKey(Map::GenerateMiniDebugInfo) |
| 120 | |
| 121 | .Define({"--generate-build-id", "--no-generate-build-id"}) |
| 122 | .WithValues({true, false}) |
| 123 | .IntoKey(Map::GenerateBuildID) |
| 124 | |
| 125 | .Define("--debuggable") |
| 126 | .IntoKey(Map::Debuggable) |
| 127 | |
| 128 | .Define("--top-k-profile-threshold=_") |
| 129 | .template WithType<double>().WithRange(0.0, 100.0) |
| 130 | .IntoKey(Map::TopKProfileThreshold) |
| 131 | |
| 132 | .Define({"--abort-on-hard-verifier-error", "--no-abort-on-hard-verifier-error"}) |
| 133 | .WithValues({true, false}) |
| 134 | .IntoKey(Map::AbortOnHardVerifierFailure) |
| 135 | |
| 136 | .Define("--dump-init-failures=_") |
| 137 | .template WithType<std::string>() |
| 138 | .IntoKey(Map::DumpInitFailures) |
| 139 | |
| 140 | .Define("--dump-cfg=_") |
| 141 | .template WithType<std::string>() |
| 142 | .IntoKey(Map::DumpCFG) |
| 143 | .Define("--dump-cfg-append") |
| 144 | .IntoKey(Map::DumpCFGAppend) |
| 145 | |
| 146 | .Define("--register-allocation-strategy=_") |
| 147 | .template WithType<std::string>() |
| 148 | .IntoKey(Map::RegisterAllocationStrategy) |
| 149 | |
| 150 | .Define("--verbose-methods=_") |
| 151 | .template WithType<ParseStringList<','>>() |
| 152 | .IntoKey(Map::VerboseMethods); |
| 153 | } |
| 154 | |
| 155 | #pragma GCC diagnostic pop |
| 156 | |
| 157 | } // namespace art |
| 158 | |
| 159 | #endif // ART_COMPILER_DRIVER_COMPILER_OPTIONS_MAP_INL_H_ |