Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 1 | //===- SubtargetFeature.cpp - CPU characteristics Implementation ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the SubtargetFeature interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Evan Cheng | 8264e27 | 2011-06-29 01:14:12 +0000 | [diff] [blame] | 14 | #include "llvm/MC/SubtargetFeature.h" |
Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/ArrayRef.h" |
Benjamin Kramer | 5377ad6 | 2015-05-28 11:45:32 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringExtras.h" |
David Greene | 24328b9 | 2010-01-05 01:29:36 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Debug.h" |
Benjamin Kramer | cc863b2 | 2011-10-16 16:30:34 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Format.h" |
Chris Lattner | f31ef09 | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 19 | #include "llvm/Support/raw_ostream.h" |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 20 | #include <algorithm> |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 21 | #include <cassert> |
Jeff Cohen | a6dde99 | 2005-09-02 02:51:42 +0000 | [diff] [blame] | 22 | #include <cctype> |
Nick Lewycky | 0de20af | 2010-12-19 20:43:38 +0000 | [diff] [blame] | 23 | #include <cstdlib> |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 26 | //===----------------------------------------------------------------------===// |
| 27 | // Static Helper Functions |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | |
| 30 | /// hasFlag - Determine if a feature has a flag; '+' or '-' |
| 31 | /// |
Craig Topper | 6dc4a8bc | 2014-08-30 16:48:02 +0000 | [diff] [blame] | 32 | static inline bool hasFlag(StringRef Feature) { |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 33 | assert(!Feature.empty() && "Empty string"); |
| 34 | // Get first character |
| 35 | char Ch = Feature[0]; |
| 36 | // Check if first character is '+' or '-' flag |
| 37 | return Ch == '+' || Ch =='-'; |
| 38 | } |
| 39 | |
| 40 | /// StripFlag - Return string stripped of flag. |
| 41 | /// |
Craig Topper | 6dc4a8bc | 2014-08-30 16:48:02 +0000 | [diff] [blame] | 42 | static inline std::string StripFlag(StringRef Feature) { |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 43 | return hasFlag(Feature) ? Feature.substr(1) : Feature; |
| 44 | } |
| 45 | |
| 46 | /// isEnabled - Return true if enable flag; '+'. |
| 47 | /// |
Craig Topper | 6dc4a8bc | 2014-08-30 16:48:02 +0000 | [diff] [blame] | 48 | static inline bool isEnabled(StringRef Feature) { |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 49 | assert(!Feature.empty() && "Empty string"); |
| 50 | // Get first character |
| 51 | char Ch = Feature[0]; |
| 52 | // Check if first character is '+' for enabled |
| 53 | return Ch == '+'; |
| 54 | } |
| 55 | |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 56 | /// Split - Splits a string of comma separated items in to a vector of strings. |
| 57 | /// |
Craig Topper | 6dc4a8bc | 2014-08-30 16:48:02 +0000 | [diff] [blame] | 58 | static void Split(std::vector<std::string> &V, StringRef S) { |
Hans Wennborg | 4fa2fd1 | 2014-08-11 02:21:32 +0000 | [diff] [blame] | 59 | SmallVector<StringRef, 3> Tmp; |
Chandler Carruth | e4405e9 | 2015-09-10 06:12:31 +0000 | [diff] [blame] | 60 | S.split(Tmp, ',', -1, false /* KeepEmpty */); |
Eric Christopher | addf51d | 2014-05-13 19:55:17 +0000 | [diff] [blame] | 61 | V.assign(Tmp.begin(), Tmp.end()); |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 64 | /// Adding features. |
Craig Topper | f8cfe1d | 2015-03-31 05:52:57 +0000 | [diff] [blame] | 65 | void SubtargetFeatures::AddFeature(StringRef String, bool Enable) { |
Craig Topper | 28f550b | 2015-03-28 03:24:19 +0000 | [diff] [blame] | 66 | // Don't add empty features. |
Eric Christopher | 7eba3f9 | 2014-05-06 02:37:26 +0000 | [diff] [blame] | 67 | if (!String.empty()) |
| 68 | // Convert to lowercase, prepend flag if we don't already have a flag. |
Craig Topper | f8cfe1d | 2015-03-31 05:52:57 +0000 | [diff] [blame] | 69 | Features.push_back(hasFlag(String) ? String.lower() |
| 70 | : (Enable ? "+" : "-") + String.lower()); |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Jim Laskey | db4621a | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 73 | /// Find KV in array using binary search. |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 74 | static const SubtargetFeatureKV *Find(StringRef S, |
| 75 | ArrayRef<SubtargetFeatureKV> A) { |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 76 | // Binary search the array |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 77 | auto F = std::lower_bound(A.begin(), A.end(), S); |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 78 | // If not found then return NULL |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 79 | if (F == A.end() || StringRef(F->Key) != S) return nullptr; |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 80 | // Return the found array item |
| 81 | return F; |
| 82 | } |
| 83 | |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 84 | /// getLongestEntryLength - Return the length of the longest entry in the table. |
| 85 | /// |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 86 | static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) { |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 87 | size_t MaxLen = 0; |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 88 | for (auto &I : Table) |
| 89 | MaxLen = std::max(MaxLen, std::strlen(I.Key)); |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 90 | return MaxLen; |
| 91 | } |
| 92 | |
Jim Laskey | 27d628d | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 93 | /// Display help for feature choices. |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 94 | /// |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 95 | static void Help(ArrayRef<SubtargetFeatureKV> CPUTable, |
| 96 | ArrayRef<SubtargetFeatureKV> FeatTable) { |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 97 | // Determine the length of the longest CPU and Feature entries. |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 98 | unsigned MaxCPULen = getLongestEntryLength(CPUTable); |
| 99 | unsigned MaxFeatLen = getLongestEntryLength(FeatTable); |
Chris Lattner | f64f840 | 2005-10-23 05:33:39 +0000 | [diff] [blame] | 100 | |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 101 | // Print the CPU table. |
Chris Lattner | f31ef09 | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 102 | errs() << "Available CPUs for this target:\n\n"; |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 103 | for (auto &CPU : CPUTable) |
| 104 | errs() << format(" %-*s - %s.\n", MaxCPULen, CPU.Key, CPU.Desc); |
Benjamin Kramer | cc863b2 | 2011-10-16 16:30:34 +0000 | [diff] [blame] | 105 | errs() << '\n'; |
| 106 | |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 107 | // Print the Feature table. |
Chris Lattner | f31ef09 | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 108 | errs() << "Available features for this target:\n\n"; |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 109 | for (auto &Feature : FeatTable) |
| 110 | errs() << format(" %-*s - %s.\n", MaxFeatLen, Feature.Key, Feature.Desc); |
Benjamin Kramer | cc863b2 | 2011-10-16 16:30:34 +0000 | [diff] [blame] | 111 | errs() << '\n'; |
| 112 | |
Chris Lattner | f31ef09 | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 113 | errs() << "Use +feature to enable a feature, or -feature to disable it.\n" |
Benjamin Kramer | cc863b2 | 2011-10-16 16:30:34 +0000 | [diff] [blame] | 114 | "For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n"; |
Jim Laskey | 27d628d | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 117 | //===----------------------------------------------------------------------===// |
| 118 | // SubtargetFeatures Implementation |
| 119 | //===----------------------------------------------------------------------===// |
| 120 | |
Craig Topper | 6dc4a8bc | 2014-08-30 16:48:02 +0000 | [diff] [blame] | 121 | SubtargetFeatures::SubtargetFeatures(StringRef Initial) { |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 122 | // Break up string into separate features |
| 123 | Split(Features, Initial); |
| 124 | } |
| 125 | |
| 126 | |
Rafael Espindola | 968af4f | 2011-07-01 04:40:50 +0000 | [diff] [blame] | 127 | std::string SubtargetFeatures::getString() const { |
Benjamin Kramer | 5377ad6 | 2015-05-28 11:45:32 +0000 | [diff] [blame] | 128 | return join(Features.begin(), Features.end(), ","); |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 129 | } |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 130 | |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 131 | /// SetImpliedBits - For each feature that is (transitively) implied by this |
| 132 | /// feature, set it. |
Anton Korobeynikov | 08bf4c0 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 133 | /// |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 134 | static |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 135 | void SetImpliedBits(FeatureBitset &Bits, const SubtargetFeatureKV *FeatureEntry, |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 136 | ArrayRef<SubtargetFeatureKV> FeatureTable) { |
| 137 | for (auto &FE : FeatureTable) { |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 138 | if (FeatureEntry->Value == FE.Value) continue; |
| 139 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 140 | if ((FeatureEntry->Implies & FE.Value).any()) { |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 141 | Bits |= FE.Value; |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 142 | SetImpliedBits(Bits, &FE, FeatureTable); |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | /// ClearImpliedBits - For each feature that (transitively) implies this |
| 148 | /// feature, clear it. |
Jim Grosbach | dc1e36e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 149 | /// |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 150 | static |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 151 | void ClearImpliedBits(FeatureBitset &Bits, |
| 152 | const SubtargetFeatureKV *FeatureEntry, |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 153 | ArrayRef<SubtargetFeatureKV> FeatureTable) { |
| 154 | for (auto &FE : FeatureTable) { |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 155 | if (FeatureEntry->Value == FE.Value) continue; |
| 156 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 157 | if ((FE.Implies & FeatureEntry->Value).any()) { |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 158 | Bits &= ~FE.Value; |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 159 | ClearImpliedBits(Bits, &FE, FeatureTable); |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | } |
Jim Laskey | db4621a | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 163 | |
Artyom Skrobov | 8c69923 | 2016-01-05 10:25:56 +0000 | [diff] [blame] | 164 | /// ToggleFeature - Toggle a feature and update the feature bits. |
| 165 | void |
| 166 | SubtargetFeatures::ToggleFeature(FeatureBitset &Bits, StringRef Feature, |
Eric Christopher | 0e6f41c | 2014-05-06 21:04:27 +0000 | [diff] [blame] | 167 | ArrayRef<SubtargetFeatureKV> FeatureTable) { |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 168 | |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 169 | // Find feature in table. |
| 170 | const SubtargetFeatureKV *FeatureEntry = |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 171 | Find(StripFlag(Feature), FeatureTable); |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 172 | // If there is a match |
| 173 | if (FeatureEntry) { |
| 174 | if ((Bits & FeatureEntry->Value) == FeatureEntry->Value) { |
| 175 | Bits &= ~FeatureEntry->Value; |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 176 | // For each feature that implies this, clear it. |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 177 | ClearImpliedBits(Bits, FeatureEntry, FeatureTable); |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 178 | } else { |
| 179 | Bits |= FeatureEntry->Value; |
| 180 | |
| 181 | // For each feature that this implies, set it. |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 182 | SetImpliedBits(Bits, FeatureEntry, FeatureTable); |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 183 | } |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 184 | } else { |
| 185 | errs() << "'" << Feature |
| 186 | << "' is not a recognized feature for this target" |
| 187 | << " (ignoring feature)\n"; |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 188 | } |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 189 | } |
Jim Grosbach | dc1e36e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 190 | |
Artyom Skrobov | 8c69923 | 2016-01-05 10:25:56 +0000 | [diff] [blame] | 191 | void SubtargetFeatures::ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature, |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 192 | ArrayRef<SubtargetFeatureKV> FeatureTable) { |
| 193 | |
| 194 | assert(hasFlag(Feature)); |
| 195 | |
| 196 | // Find feature in table. |
| 197 | const SubtargetFeatureKV *FeatureEntry = |
| 198 | Find(StripFlag(Feature), FeatureTable); |
| 199 | // If there is a match |
| 200 | if (FeatureEntry) { |
| 201 | // Enable/disable feature in bits |
| 202 | if (isEnabled(Feature)) { |
Artyom Skrobov | 8c69923 | 2016-01-05 10:25:56 +0000 | [diff] [blame] | 203 | Bits |= FeatureEntry->Value; |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 204 | |
| 205 | // For each feature that this implies, set it. |
| 206 | SetImpliedBits(Bits, FeatureEntry, FeatureTable); |
| 207 | } else { |
| 208 | Bits &= ~FeatureEntry->Value; |
| 209 | |
| 210 | // For each feature that implies this, clear it. |
| 211 | ClearImpliedBits(Bits, FeatureEntry, FeatureTable); |
| 212 | } |
| 213 | } else { |
| 214 | errs() << "'" << Feature |
| 215 | << "' is not a recognized feature for this target" |
| 216 | << " (ignoring feature)\n"; |
| 217 | } |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 220 | |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 221 | /// getFeatureBits - Get feature bits a CPU. |
Jim Laskey | db4621a | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 222 | /// |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 223 | FeatureBitset |
Craig Topper | 6dc4a8bc | 2014-08-30 16:48:02 +0000 | [diff] [blame] | 224 | SubtargetFeatures::getFeatureBits(StringRef CPU, |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 225 | ArrayRef<SubtargetFeatureKV> CPUTable, |
| 226 | ArrayRef<SubtargetFeatureKV> FeatureTable) { |
| 227 | |
| 228 | if (CPUTable.empty() || FeatureTable.empty()) |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 229 | return FeatureBitset(); |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 230 | |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 231 | #ifndef NDEBUG |
Craig Topper | 5f16772 | 2016-01-03 07:33:45 +0000 | [diff] [blame] | 232 | assert(std::is_sorted(std::begin(CPUTable), std::end(CPUTable)) && |
| 233 | "CPU table is not sorted"); |
| 234 | assert(std::is_sorted(std::begin(FeatureTable), std::end(FeatureTable)) && |
| 235 | "CPU features table is not sorted"); |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 236 | #endif |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 237 | // Resulting bits |
| 238 | FeatureBitset Bits; |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 239 | |
Jim Laskey | db4621a | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 240 | // Check if help is needed |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 241 | if (CPU == "help") |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 242 | Help(CPUTable, FeatureTable); |
Jim Grosbach | dc1e36e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 243 | |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 244 | // Find CPU entry if CPU name is specified. |
Eric Christopher | a9f3a5c | 2014-05-06 16:29:50 +0000 | [diff] [blame] | 245 | else if (!CPU.empty()) { |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 246 | const SubtargetFeatureKV *CPUEntry = Find(CPU, CPUTable); |
| 247 | |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 248 | // If there is a match |
| 249 | if (CPUEntry) { |
| 250 | // Set base feature bits |
| 251 | Bits = CPUEntry->Value; |
Bill Wendling | f413419 | 2007-06-27 23:34:06 +0000 | [diff] [blame] | 252 | |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 253 | // Set the feature implied by this CPU feature, if any. |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 254 | for (auto &FE : FeatureTable) { |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 255 | if ((CPUEntry->Value & FE.Value).any()) |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 256 | SetImpliedBits(Bits, &FE, FeatureTable); |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 257 | } |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 258 | } else { |
| 259 | errs() << "'" << CPU |
| 260 | << "' is not a recognized processor for this target" |
| 261 | << " (ignoring processor)\n"; |
Bill Wendling | f413419 | 2007-06-27 23:34:06 +0000 | [diff] [blame] | 262 | } |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 263 | } |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 264 | |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 265 | // Iterate through each feature |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 266 | for (auto &Feature : Features) { |
Jim Laskey | 27d628d | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 267 | // Check for help |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 268 | if (Feature == "+help") |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 269 | Help(CPUTable, FeatureTable); |
Jim Grosbach | dc1e36e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 270 | |
Artyom Skrobov | 8c69923 | 2016-01-05 10:25:56 +0000 | [diff] [blame] | 271 | ApplyFeatureFlag(Bits, Feature, FeatureTable); |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 272 | } |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 273 | |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 274 | return Bits; |
| 275 | } |
| 276 | |
Jim Laskey | db4621a | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 277 | /// print - Print feature string. |
| 278 | /// |
Chris Lattner | f31ef09 | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 279 | void SubtargetFeatures::print(raw_ostream &OS) const { |
Eric Christopher | 9c92847 | 2014-05-06 21:20:29 +0000 | [diff] [blame] | 280 | for (auto &F : Features) |
| 281 | OS << F << " "; |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 282 | OS << "\n"; |
| 283 | } |
| 284 | |
Manman Ren | 49d684e | 2012-09-12 05:06:18 +0000 | [diff] [blame] | 285 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Jim Laskey | db4621a | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 286 | /// dump - Dump feature info. |
| 287 | /// |
Yaron Keren | eb2a254 | 2016-01-29 20:50:44 +0000 | [diff] [blame] | 288 | LLVM_DUMP_METHOD void SubtargetFeatures::dump() const { |
David Greene | 24328b9 | 2010-01-05 01:29:36 +0000 | [diff] [blame] | 289 | print(dbgs()); |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 290 | } |
Manman Ren | c3366cc | 2012-09-06 19:55:56 +0000 | [diff] [blame] | 291 | #endif |
Viktor Kutuzov | c3e2b6b | 2009-11-18 20:20:05 +0000 | [diff] [blame] | 292 | |
Rafael Espindola | 41d630f | 2013-10-07 13:34:05 +0000 | [diff] [blame] | 293 | /// Adds the default features for the specified target triple. |
Viktor Kutuzov | c3e2b6b | 2009-11-18 20:20:05 +0000 | [diff] [blame] | 294 | /// |
| 295 | /// FIXME: This is an inelegant way of specifying the features of a |
| 296 | /// subtarget. It would be better if we could encode this information |
| 297 | /// into the IR. See <rdar://5972456>. |
| 298 | /// |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 299 | void SubtargetFeatures::getDefaultSubtargetFeatures(const Triple& Triple) { |
Bill Wendling | 508f661 | 2010-05-11 20:46:04 +0000 | [diff] [blame] | 300 | if (Triple.getVendor() == Triple::Apple) { |
| 301 | if (Triple.getArch() == Triple::ppc) { |
| 302 | // powerpc-apple-* |
| 303 | AddFeature("altivec"); |
| 304 | } else if (Triple.getArch() == Triple::ppc64) { |
| 305 | // powerpc64-apple-* |
| 306 | AddFeature("64bit"); |
| 307 | AddFeature("altivec"); |
Viktor Kutuzov | c3e2b6b | 2009-11-18 20:20:05 +0000 | [diff] [blame] | 308 | } |
Bill Wendling | a12c1ff | 2010-05-11 00:30:02 +0000 | [diff] [blame] | 309 | } |
Viktor Kutuzov | c3e2b6b | 2009-11-18 20:20:05 +0000 | [diff] [blame] | 310 | } |