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