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. |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 108 | static const SubtargetFeatureKV *Find(StringRef S, const SubtargetFeatureKV *A, |
| 109 | size_t L) { |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 110 | // Determine the end of the array |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 111 | const SubtargetFeatureKV *Hi = A + L; |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 112 | // Binary search the array |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 113 | const SubtargetFeatureKV *F = std::lower_bound(A, Hi, S); |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 114 | // If not found then return NULL |
Craig Topper | bb694de | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 115 | if (F == Hi || StringRef(F->Key) != S) return nullptr; |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 116 | // Return the found array item |
| 117 | return F; |
| 118 | } |
| 119 | |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 120 | /// getLongestEntryLength - Return the length of the longest entry in the table. |
| 121 | /// |
| 122 | static size_t getLongestEntryLength(const SubtargetFeatureKV *Table, |
| 123 | size_t Size) { |
| 124 | size_t MaxLen = 0; |
| 125 | for (size_t i = 0; i < Size; i++) |
| 126 | MaxLen = std::max(MaxLen, std::strlen(Table[i].Key)); |
| 127 | return MaxLen; |
| 128 | } |
| 129 | |
Jim Laskey | 27d628d | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 130 | /// Display help for feature choices. |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 131 | /// |
Eric Christopher | a9f3a5c | 2014-05-06 16:29:50 +0000 | [diff] [blame^] | 132 | static void Help(const SubtargetFeatureKV *CPUTable, size_t CPUTableSize, |
Eric Christopher | fbed044 | 2014-05-05 22:01:47 +0000 | [diff] [blame] | 133 | const SubtargetFeatureKV *FeatTable, |
| 134 | size_t FeatTableSize) { |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 135 | // Determine the length of the longest CPU and Feature entries. |
| 136 | unsigned MaxCPULen = getLongestEntryLength(CPUTable, CPUTableSize); |
| 137 | unsigned MaxFeatLen = getLongestEntryLength(FeatTable, FeatTableSize); |
Chris Lattner | f64f840 | 2005-10-23 05:33:39 +0000 | [diff] [blame] | 138 | |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 139 | // Print the CPU table. |
Chris Lattner | f31ef09 | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 140 | errs() << "Available CPUs for this target:\n\n"; |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 141 | for (size_t i = 0; i != CPUTableSize; i++) |
Benjamin Kramer | cc863b2 | 2011-10-16 16:30:34 +0000 | [diff] [blame] | 142 | errs() << format(" %-*s - %s.\n", |
| 143 | MaxCPULen, CPUTable[i].Key, CPUTable[i].Desc); |
| 144 | errs() << '\n'; |
| 145 | |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 146 | // Print the Feature table. |
Chris Lattner | f31ef09 | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 147 | errs() << "Available features for this target:\n\n"; |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 148 | for (size_t i = 0; i != FeatTableSize; i++) |
Benjamin Kramer | cc863b2 | 2011-10-16 16:30:34 +0000 | [diff] [blame] | 149 | errs() << format(" %-*s - %s.\n", |
| 150 | MaxFeatLen, FeatTable[i].Key, FeatTable[i].Desc); |
| 151 | errs() << '\n'; |
| 152 | |
Chris Lattner | f31ef09 | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 153 | 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] | 154 | "For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n"; |
Jim Laskey | 27d628d | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 157 | //===----------------------------------------------------------------------===// |
| 158 | // SubtargetFeatures Implementation |
| 159 | //===----------------------------------------------------------------------===// |
| 160 | |
Evan Cheng | d8e27a5 | 2011-07-01 00:23:10 +0000 | [diff] [blame] | 161 | SubtargetFeatures::SubtargetFeatures(const StringRef Initial) { |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 162 | // Break up string into separate features |
| 163 | Split(Features, Initial); |
| 164 | } |
| 165 | |
| 166 | |
Rafael Espindola | 968af4f | 2011-07-01 04:40:50 +0000 | [diff] [blame] | 167 | std::string SubtargetFeatures::getString() const { |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 168 | return Join(Features); |
| 169 | } |
Chris Lattner | 18a70c3 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 170 | |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 171 | /// SetImpliedBits - For each feature that is (transitively) implied by this |
| 172 | /// feature, set it. |
Anton Korobeynikov | 08bf4c0 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 173 | /// |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 174 | static |
Evan Cheng | a2e6129 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 175 | void SetImpliedBits(uint64_t &Bits, const SubtargetFeatureKV *FeatureEntry, |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 176 | const SubtargetFeatureKV *FeatureTable, |
| 177 | size_t FeatureTableSize) { |
| 178 | for (size_t i = 0; i < FeatureTableSize; ++i) { |
| 179 | const SubtargetFeatureKV &FE = FeatureTable[i]; |
| 180 | |
| 181 | if (FeatureEntry->Value == FE.Value) continue; |
| 182 | |
| 183 | if (FeatureEntry->Implies & FE.Value) { |
| 184 | Bits |= FE.Value; |
| 185 | SetImpliedBits(Bits, &FE, FeatureTable, FeatureTableSize); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | /// ClearImpliedBits - For each feature that (transitively) implies this |
| 191 | /// feature, clear it. |
Jim Grosbach | dc1e36e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 192 | /// |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 193 | static |
Evan Cheng | a2e6129 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 194 | void ClearImpliedBits(uint64_t &Bits, const SubtargetFeatureKV *FeatureEntry, |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 195 | const SubtargetFeatureKV *FeatureTable, |
| 196 | size_t FeatureTableSize) { |
| 197 | for (size_t i = 0; i < FeatureTableSize; ++i) { |
| 198 | const SubtargetFeatureKV &FE = FeatureTable[i]; |
| 199 | |
| 200 | if (FeatureEntry->Value == FE.Value) continue; |
| 201 | |
| 202 | if (FE.Implies & FeatureEntry->Value) { |
| 203 | Bits &= ~FE.Value; |
| 204 | ClearImpliedBits(Bits, &FE, FeatureTable, FeatureTableSize); |
| 205 | } |
| 206 | } |
| 207 | } |
Jim Laskey | db4621a | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 208 | |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 209 | /// ToggleFeature - Toggle a feature and returns the newly updated feature |
| 210 | /// bits. |
| 211 | uint64_t |
| 212 | SubtargetFeatures::ToggleFeature(uint64_t Bits, const StringRef Feature, |
| 213 | const SubtargetFeatureKV *FeatureTable, |
| 214 | size_t FeatureTableSize) { |
| 215 | // Find feature in table. |
| 216 | const SubtargetFeatureKV *FeatureEntry = |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 217 | Find(StripFlag(Feature), FeatureTable, FeatureTableSize); |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 218 | // If there is a match |
| 219 | if (FeatureEntry) { |
| 220 | if ((Bits & FeatureEntry->Value) == FeatureEntry->Value) { |
| 221 | Bits &= ~FeatureEntry->Value; |
| 222 | |
| 223 | // For each feature that implies this, clear it. |
| 224 | ClearImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize); |
| 225 | } else { |
| 226 | Bits |= FeatureEntry->Value; |
| 227 | |
| 228 | // For each feature that this implies, set it. |
| 229 | SetImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize); |
| 230 | } |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 231 | } else { |
| 232 | errs() << "'" << Feature |
| 233 | << "' is not a recognized feature for this target" |
| 234 | << " (ignoring feature)\n"; |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | return Bits; |
| 238 | } |
Jim Grosbach | dc1e36e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 239 | |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 240 | |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 241 | /// getFeatureBits - Get feature bits a CPU. |
Jim Laskey | db4621a | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 242 | /// |
Evan Cheng | d8e27a5 | 2011-07-01 00:23:10 +0000 | [diff] [blame] | 243 | uint64_t SubtargetFeatures::getFeatureBits(const StringRef CPU, |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 244 | const SubtargetFeatureKV *CPUTable, |
| 245 | size_t CPUTableSize, |
| 246 | const SubtargetFeatureKV *FeatureTable, |
| 247 | size_t FeatureTableSize) { |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 248 | if (!FeatureTableSize || !CPUTableSize) |
| 249 | return 0; |
| 250 | |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 251 | #ifndef NDEBUG |
| 252 | for (size_t i = 1; i < CPUTableSize; i++) { |
| 253 | assert(strcmp(CPUTable[i - 1].Key, CPUTable[i].Key) < 0 && |
| 254 | "CPU table is not sorted"); |
| 255 | } |
| 256 | for (size_t i = 1; i < FeatureTableSize; i++) { |
| 257 | assert(strcmp(FeatureTable[i - 1].Key, FeatureTable[i].Key) < 0 && |
| 258 | "CPU features table is not sorted"); |
| 259 | } |
| 260 | #endif |
Evan Cheng | a2e6129 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 261 | uint64_t Bits = 0; // Resulting bits |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 262 | |
Jim Laskey | db4621a | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 263 | // Check if help is needed |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 264 | if (CPU == "help") |
Eric Christopher | a9f3a5c | 2014-05-06 16:29:50 +0000 | [diff] [blame^] | 265 | Help(CPUTable, CPUTableSize, FeatureTable, FeatureTableSize); |
Jim Grosbach | dc1e36e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 266 | |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 267 | // Find CPU entry if CPU name is specified. |
Eric Christopher | a9f3a5c | 2014-05-06 16:29:50 +0000 | [diff] [blame^] | 268 | else if (!CPU.empty()) { |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 269 | const SubtargetFeatureKV *CPUEntry = Find(CPU, CPUTable, CPUTableSize); |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 270 | // If there is a match |
| 271 | if (CPUEntry) { |
| 272 | // Set base feature bits |
| 273 | Bits = CPUEntry->Value; |
Bill Wendling | f413419 | 2007-06-27 23:34:06 +0000 | [diff] [blame] | 274 | |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 275 | // Set the feature implied by this CPU feature, if any. |
| 276 | for (size_t i = 0; i < FeatureTableSize; ++i) { |
| 277 | const SubtargetFeatureKV &FE = FeatureTable[i]; |
| 278 | if (CPUEntry->Value & FE.Value) |
| 279 | SetImpliedBits(Bits, &FE, FeatureTable, FeatureTableSize); |
| 280 | } |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 281 | } else { |
| 282 | errs() << "'" << CPU |
| 283 | << "' is not a recognized processor for this target" |
| 284 | << " (ignoring processor)\n"; |
Bill Wendling | f413419 | 2007-06-27 23:34:06 +0000 | [diff] [blame] | 285 | } |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 286 | } |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 287 | |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 288 | // Iterate through each feature |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 289 | for (size_t i = 0, E = Features.size(); i < E; i++) { |
Evan Cheng | d8e27a5 | 2011-07-01 00:23:10 +0000 | [diff] [blame] | 290 | const StringRef Feature = Features[i]; |
Jim Grosbach | dc1e36e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 291 | |
Jim Laskey | 27d628d | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 292 | // Check for help |
Chris Lattner | 8ff9df2 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 293 | if (Feature == "+help") |
Eric Christopher | a9f3a5c | 2014-05-06 16:29:50 +0000 | [diff] [blame^] | 294 | Help(CPUTable, CPUTableSize, FeatureTable, FeatureTableSize); |
Jim Grosbach | dc1e36e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 295 | |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 296 | // Find feature in table. |
| 297 | const SubtargetFeatureKV *FeatureEntry = |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 298 | Find(StripFlag(Feature), FeatureTable, FeatureTableSize); |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 299 | // If there is a match |
| 300 | if (FeatureEntry) { |
| 301 | // Enable/disable feature in bits |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 302 | if (isEnabled(Feature)) { |
| 303 | Bits |= FeatureEntry->Value; |
| 304 | |
| 305 | // For each feature that this implies, set it. |
| 306 | SetImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize); |
| 307 | } else { |
| 308 | Bits &= ~FeatureEntry->Value; |
| 309 | |
| 310 | // For each feature that implies this, clear it. |
| 311 | ClearImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize); |
| 312 | } |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 313 | } else { |
| 314 | errs() << "'" << Feature |
| 315 | << "' is not a recognized feature for this target" |
| 316 | << " (ignoring feature)\n"; |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 317 | } |
| 318 | } |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 319 | |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 320 | return Bits; |
| 321 | } |
| 322 | |
Jim Laskey | db4621a | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 323 | /// print - Print feature string. |
| 324 | /// |
Chris Lattner | f31ef09 | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 325 | void SubtargetFeatures::print(raw_ostream &OS) const { |
| 326 | for (size_t i = 0, e = Features.size(); i != e; ++i) |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 327 | OS << Features[i] << " "; |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 328 | OS << "\n"; |
| 329 | } |
| 330 | |
Manman Ren | 49d684e | 2012-09-12 05:06:18 +0000 | [diff] [blame] | 331 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Jim Laskey | db4621a | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 332 | /// dump - Dump feature info. |
| 333 | /// |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 334 | void SubtargetFeatures::dump() const { |
David Greene | 24328b9 | 2010-01-05 01:29:36 +0000 | [diff] [blame] | 335 | print(dbgs()); |
Jim Laskey | 3fee6a5 | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 336 | } |
Manman Ren | c3366cc | 2012-09-06 19:55:56 +0000 | [diff] [blame] | 337 | #endif |
Viktor Kutuzov | c3e2b6b | 2009-11-18 20:20:05 +0000 | [diff] [blame] | 338 | |
Rafael Espindola | 41d630f | 2013-10-07 13:34:05 +0000 | [diff] [blame] | 339 | /// Adds the default features for the specified target triple. |
Viktor Kutuzov | c3e2b6b | 2009-11-18 20:20:05 +0000 | [diff] [blame] | 340 | /// |
| 341 | /// FIXME: This is an inelegant way of specifying the features of a |
| 342 | /// subtarget. It would be better if we could encode this information |
| 343 | /// into the IR. See <rdar://5972456>. |
| 344 | /// |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 345 | void SubtargetFeatures::getDefaultSubtargetFeatures(const Triple& Triple) { |
Bill Wendling | 508f661 | 2010-05-11 20:46:04 +0000 | [diff] [blame] | 346 | if (Triple.getVendor() == Triple::Apple) { |
| 347 | if (Triple.getArch() == Triple::ppc) { |
| 348 | // powerpc-apple-* |
| 349 | AddFeature("altivec"); |
| 350 | } else if (Triple.getArch() == Triple::ppc64) { |
| 351 | // powerpc64-apple-* |
| 352 | AddFeature("64bit"); |
| 353 | AddFeature("altivec"); |
Viktor Kutuzov | c3e2b6b | 2009-11-18 20:20:05 +0000 | [diff] [blame] | 354 | } |
Bill Wendling | a12c1ff | 2010-05-11 00:30:02 +0000 | [diff] [blame] | 355 | } |
Viktor Kutuzov | c3e2b6b | 2009-11-18 20:20:05 +0000 | [diff] [blame] | 356 | } |