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