Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 1 | //===- SubtargetFeature.cpp - CPU characteristics Implementation ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 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 | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the SubtargetFeature interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Target/SubtargetFeature.h" |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 15 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 54195c1 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringExtras.h" |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 17 | #include <algorithm> |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 18 | #include <cassert> |
Jeff Cohen | 7cd57f4 | 2005-09-02 02:51:42 +0000 | [diff] [blame] | 19 | #include <cctype> |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
Chris Lattner | 54195c1 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 22 | //===----------------------------------------------------------------------===// |
| 23 | // Static Helper Functions |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | /// hasFlag - Determine if a feature has a flag; '+' or '-' |
| 27 | /// |
| 28 | static inline bool hasFlag(const std::string &Feature) { |
| 29 | assert(!Feature.empty() && "Empty string"); |
| 30 | // Get first character |
| 31 | char Ch = Feature[0]; |
| 32 | // Check if first character is '+' or '-' flag |
| 33 | return Ch == '+' || Ch =='-'; |
| 34 | } |
| 35 | |
| 36 | /// StripFlag - Return string stripped of flag. |
| 37 | /// |
| 38 | static inline std::string StripFlag(const std::string &Feature) { |
| 39 | return hasFlag(Feature) ? Feature.substr(1) : Feature; |
| 40 | } |
| 41 | |
| 42 | /// isEnabled - Return true if enable flag; '+'. |
| 43 | /// |
| 44 | static inline bool isEnabled(const std::string &Feature) { |
| 45 | assert(!Feature.empty() && "Empty string"); |
| 46 | // Get first character |
| 47 | char Ch = Feature[0]; |
| 48 | // Check if first character is '+' for enabled |
| 49 | return Ch == '+'; |
| 50 | } |
| 51 | |
| 52 | /// PrependFlag - Return a string with a prepended flag; '+' or '-'. |
| 53 | /// |
| 54 | static inline std::string PrependFlag(const std::string &Feature, |
| 55 | bool IsEnabled) { |
| 56 | assert(!Feature.empty() && "Empty string"); |
| 57 | if (hasFlag(Feature)) return Feature; |
| 58 | return std::string(IsEnabled ? "+" : "-") + Feature; |
| 59 | } |
| 60 | |
| 61 | /// Split - Splits a string of comma separated items in to a vector of strings. |
| 62 | /// |
| 63 | static void Split(std::vector<std::string> &V, const std::string &S) { |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 64 | // Start at beginning of string. |
| 65 | size_t Pos = 0; |
| 66 | while (true) { |
| 67 | // Find the next comma |
| 68 | size_t Comma = S.find(',', Pos); |
| 69 | // If no comma found then the the rest of the string is used |
| 70 | if (Comma == std::string::npos) { |
| 71 | // Add string to vector |
| 72 | V.push_back(S.substr(Pos)); |
| 73 | break; |
| 74 | } |
| 75 | // Otherwise add substring to vector |
| 76 | V.push_back(S.substr(Pos, Comma - Pos)); |
| 77 | // Advance to next item |
| 78 | Pos = Comma + 1; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /// Join a vector of strings to a string with a comma separating each element. |
Chris Lattner | 54195c1 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 83 | /// |
| 84 | static std::string Join(const std::vector<std::string> &V) { |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 85 | // Start with empty string. |
| 86 | std::string Result; |
| 87 | // If the vector is not empty |
| 88 | if (!V.empty()) { |
| 89 | // Start with the CPU feature |
| 90 | Result = V[0]; |
| 91 | // For each successive feature |
| 92 | for (size_t i = 1; i < V.size(); i++) { |
| 93 | // Add a comma |
| 94 | Result += ","; |
| 95 | // Add the feature |
| 96 | Result += V[i]; |
| 97 | } |
| 98 | } |
| 99 | // Return the features string |
| 100 | return Result; |
| 101 | } |
| 102 | |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 103 | /// Adding features. |
| 104 | void SubtargetFeatures::AddFeature(const std::string &String, |
| 105 | bool IsEnabled) { |
| 106 | // Don't add empty features |
| 107 | if (!String.empty()) { |
| 108 | // Convert to lowercase, prepend flag and add to vector |
Chris Lattner | 54195c1 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 109 | Features.push_back(PrependFlag(LowercaseString(String), IsEnabled)); |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
Jim Laskey | 34bd5d5 | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 113 | /// Find KV in array using binary search. |
| 114 | template<typename T> const T *Find(const std::string &S, const T *A, size_t L) { |
Jeff Cohen | 9471c8a | 2006-01-26 20:41:32 +0000 | [diff] [blame] | 115 | // Make the lower bound element we're looking for |
| 116 | T KV; |
| 117 | KV.Key = S.c_str(); |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 118 | // Determine the end of the array |
Jim Laskey | 34bd5d5 | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 119 | const T *Hi = A + L; |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 120 | // Binary search the array |
Jeff Cohen | 9471c8a | 2006-01-26 20:41:32 +0000 | [diff] [blame] | 121 | const T *F = std::lower_bound(A, Hi, KV); |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 122 | // If not found then return NULL |
| 123 | if (F == Hi || std::string(F->Key) != S) return NULL; |
| 124 | // Return the found array item |
| 125 | return F; |
| 126 | } |
| 127 | |
Chris Lattner | 3e808a4 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 128 | /// getLongestEntryLength - Return the length of the longest entry in the table. |
| 129 | /// |
| 130 | static size_t getLongestEntryLength(const SubtargetFeatureKV *Table, |
| 131 | size_t Size) { |
| 132 | size_t MaxLen = 0; |
| 133 | for (size_t i = 0; i < Size; i++) |
| 134 | MaxLen = std::max(MaxLen, std::strlen(Table[i].Key)); |
| 135 | return MaxLen; |
| 136 | } |
| 137 | |
Jim Laskey | 839615a | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 138 | /// Display help for feature choices. |
Chris Lattner | 54195c1 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 139 | /// |
Chris Lattner | 3e808a4 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 140 | static void Help(const SubtargetFeatureKV *CPUTable, size_t CPUTableSize, |
| 141 | const SubtargetFeatureKV *FeatTable, size_t FeatTableSize) { |
| 142 | // Determine the length of the longest CPU and Feature entries. |
| 143 | unsigned MaxCPULen = getLongestEntryLength(CPUTable, CPUTableSize); |
| 144 | unsigned MaxFeatLen = getLongestEntryLength(FeatTable, FeatTableSize); |
Chris Lattner | ba76c21 | 2005-10-23 05:33:39 +0000 | [diff] [blame] | 145 | |
Chris Lattner | 3e808a4 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 146 | // Print the CPU table. |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 147 | errs() << "Available CPUs for this target:\n\n"; |
Chris Lattner | 3e808a4 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 148 | for (size_t i = 0; i != CPUTableSize; i++) |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 149 | errs() << " " << CPUTable[i].Key |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame] | 150 | << std::string(MaxCPULen - std::strlen(CPUTable[i].Key), ' ') |
| 151 | << " - " << CPUTable[i].Desc << ".\n"; |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 152 | errs() << "\n"; |
Chris Lattner | 3e808a4 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 153 | |
| 154 | // Print the Feature table. |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 155 | errs() << "Available features for this target:\n\n"; |
Chris Lattner | 3e808a4 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 156 | for (size_t i = 0; i != FeatTableSize; i++) |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 157 | errs() << " " << FeatTable[i].Key |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame] | 158 | << std::string(MaxFeatLen - std::strlen(FeatTable[i].Key), ' ') |
| 159 | << " - " << FeatTable[i].Desc << ".\n"; |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 160 | errs() << "\n"; |
Chris Lattner | 3e808a4 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 161 | |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 162 | errs() << "Use +feature to enable a feature, or -feature to disable it.\n" |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame] | 163 | << "For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n"; |
Chris Lattner | 54195c1 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 164 | exit(1); |
Jim Laskey | 839615a | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Chris Lattner | 54195c1 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 167 | //===----------------------------------------------------------------------===// |
| 168 | // SubtargetFeatures Implementation |
| 169 | //===----------------------------------------------------------------------===// |
| 170 | |
| 171 | SubtargetFeatures::SubtargetFeatures(const std::string &Initial) { |
| 172 | // Break up string into separate features |
| 173 | Split(Features, Initial); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | std::string SubtargetFeatures::getString() const { |
| 178 | return Join(Features); |
| 179 | } |
| 180 | void SubtargetFeatures::setString(const std::string &Initial) { |
| 181 | // Throw out old features |
| 182 | Features.clear(); |
| 183 | // Break up string into separate features |
| 184 | Split(Features, LowercaseString(Initial)); |
| 185 | } |
| 186 | |
Jim Laskey | 34bd5d5 | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 187 | |
Anton Korobeynikov | 41a0243 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 188 | /// setCPU - Set the CPU string. Replaces previous setting. Setting to "" |
Chris Lattner | 54195c1 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 189 | /// clears CPU. |
| 190 | void SubtargetFeatures::setCPU(const std::string &String) { |
| 191 | Features[0] = LowercaseString(String); |
| 192 | } |
| 193 | |
| 194 | |
Jim Laskey | 34bd5d5 | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 195 | /// setCPUIfNone - Setting CPU string only if no string is set. |
Chris Lattner | 54195c1 | 2005-10-23 05:26:26 +0000 | [diff] [blame] | 196 | /// |
Jim Laskey | 34bd5d5 | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 197 | void SubtargetFeatures::setCPUIfNone(const std::string &String) { |
| 198 | if (Features[0].empty()) setCPU(String); |
| 199 | } |
| 200 | |
Anton Korobeynikov | 41a0243 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 201 | /// getCPU - Returns current CPU. |
| 202 | /// |
| 203 | const std::string & SubtargetFeatures::getCPU() const { |
| 204 | return Features[0]; |
| 205 | } |
| 206 | |
| 207 | |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 208 | /// SetImpliedBits - For each feature that is (transitively) implied by this |
| 209 | /// feature, set it. |
Anton Korobeynikov | 41a0243 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 210 | /// |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 211 | static |
| 212 | void SetImpliedBits(uint32_t &Bits, const SubtargetFeatureKV *FeatureEntry, |
| 213 | const SubtargetFeatureKV *FeatureTable, |
| 214 | size_t FeatureTableSize) { |
| 215 | for (size_t i = 0; i < FeatureTableSize; ++i) { |
| 216 | const SubtargetFeatureKV &FE = FeatureTable[i]; |
| 217 | |
| 218 | if (FeatureEntry->Value == FE.Value) continue; |
| 219 | |
| 220 | if (FeatureEntry->Implies & FE.Value) { |
| 221 | Bits |= FE.Value; |
| 222 | SetImpliedBits(Bits, &FE, FeatureTable, FeatureTableSize); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /// ClearImpliedBits - For each feature that (transitively) implies this |
| 228 | /// feature, clear it. |
| 229 | /// |
| 230 | static |
| 231 | void ClearImpliedBits(uint32_t &Bits, const SubtargetFeatureKV *FeatureEntry, |
| 232 | const SubtargetFeatureKV *FeatureTable, |
| 233 | size_t FeatureTableSize) { |
| 234 | for (size_t i = 0; i < FeatureTableSize; ++i) { |
| 235 | const SubtargetFeatureKV &FE = FeatureTable[i]; |
| 236 | |
| 237 | if (FeatureEntry->Value == FE.Value) continue; |
| 238 | |
| 239 | if (FE.Implies & FeatureEntry->Value) { |
| 240 | Bits &= ~FE.Value; |
| 241 | ClearImpliedBits(Bits, &FE, FeatureTable, FeatureTableSize); |
| 242 | } |
| 243 | } |
| 244 | } |
Jim Laskey | 34bd5d5 | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 245 | |
| 246 | /// getBits - Get feature bits. |
| 247 | /// |
| 248 | uint32_t SubtargetFeatures::getBits(const SubtargetFeatureKV *CPUTable, |
| 249 | size_t CPUTableSize, |
| 250 | const SubtargetFeatureKV *FeatureTable, |
| 251 | size_t FeatureTableSize) { |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 252 | assert(CPUTable && "missing CPU table"); |
| 253 | assert(FeatureTable && "missing features table"); |
| 254 | #ifndef NDEBUG |
| 255 | for (size_t i = 1; i < CPUTableSize; i++) { |
| 256 | assert(strcmp(CPUTable[i - 1].Key, CPUTable[i].Key) < 0 && |
| 257 | "CPU table is not sorted"); |
| 258 | } |
| 259 | for (size_t i = 1; i < FeatureTableSize; i++) { |
| 260 | assert(strcmp(FeatureTable[i - 1].Key, FeatureTable[i].Key) < 0 && |
| 261 | "CPU features table is not sorted"); |
| 262 | } |
| 263 | #endif |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 264 | uint32_t Bits = 0; // Resulting bits |
Chris Lattner | 3e808a4 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 265 | |
Jim Laskey | 34bd5d5 | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 266 | // Check if help is needed |
| 267 | if (Features[0] == "help") |
Chris Lattner | 3e808a4 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 268 | Help(CPUTable, CPUTableSize, FeatureTable, FeatureTableSize); |
| 269 | |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 270 | // Find CPU entry |
| 271 | const SubtargetFeatureKV *CPUEntry = |
| 272 | Find(Features[0], CPUTable, CPUTableSize); |
| 273 | // If there is a match |
| 274 | if (CPUEntry) { |
| 275 | // Set base feature bits |
| 276 | Bits = CPUEntry->Value; |
Bill Wendling | 1a636de | 2007-06-27 23:34:06 +0000 | [diff] [blame] | 277 | |
| 278 | // Set the feature implied by this CPU feature, if any. |
| 279 | for (size_t i = 0; i < FeatureTableSize; ++i) { |
| 280 | const SubtargetFeatureKV &FE = FeatureTable[i]; |
| 281 | if (CPUEntry->Value & FE.Value) |
| 282 | SetImpliedBits(Bits, &FE, FeatureTable, FeatureTableSize); |
| 283 | } |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 284 | } else { |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 285 | errs() << "'" << Features[0] |
| 286 | << "' is not a recognized processor for this target" |
| 287 | << " (ignoring processor)\n"; |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 288 | } |
| 289 | // Iterate through each feature |
| 290 | for (size_t i = 1; i < Features.size(); i++) { |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 291 | const std::string &Feature = Features[i]; |
Chris Lattner | 3e808a4 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 292 | |
Jim Laskey | 839615a | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 293 | // Check for help |
Chris Lattner | 3e808a4 | 2005-10-23 22:23:13 +0000 | [diff] [blame] | 294 | if (Feature == "+help") |
| 295 | Help(CPUTable, CPUTableSize, FeatureTable, FeatureTableSize); |
| 296 | |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 297 | // Find feature in table. |
| 298 | const SubtargetFeatureKV *FeatureEntry = |
| 299 | Find(StripFlag(Feature), FeatureTable, FeatureTableSize); |
| 300 | // If there is a match |
| 301 | if (FeatureEntry) { |
| 302 | // Enable/disable feature in bits |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 303 | if (isEnabled(Feature)) { |
| 304 | Bits |= FeatureEntry->Value; |
| 305 | |
| 306 | // For each feature that this implies, set it. |
| 307 | SetImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize); |
| 308 | } else { |
| 309 | Bits &= ~FeatureEntry->Value; |
| 310 | |
| 311 | // For each feature that implies this, clear it. |
| 312 | ClearImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize); |
| 313 | } |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 314 | } else { |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 315 | errs() << "'" << Feature |
| 316 | << "' is not a recognized feature for this target" |
| 317 | << " (ignoring feature)\n"; |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 320 | |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 321 | return Bits; |
| 322 | } |
| 323 | |
Jim Laskey | 34bd5d5 | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 324 | /// Get info pointer |
| 325 | void *SubtargetFeatures::getInfo(const SubtargetInfoKV *Table, |
| 326 | size_t TableSize) { |
| 327 | assert(Table && "missing table"); |
| 328 | #ifndef NDEBUG |
| 329 | for (size_t i = 1; i < TableSize; i++) { |
| 330 | assert(strcmp(Table[i - 1].Key, Table[i].Key) < 0 && "Table is not sorted"); |
| 331 | } |
| 332 | #endif |
| 333 | |
| 334 | // Find entry |
| 335 | const SubtargetInfoKV *Entry = Find(Features[0], Table, TableSize); |
| 336 | |
| 337 | if (Entry) { |
| 338 | return Entry->Value; |
| 339 | } else { |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 340 | errs() << "'" << Features[0] |
| 341 | << "' is not a recognized processor for this target" |
| 342 | << " (ignoring processor)\n"; |
Jim Laskey | 34bd5d5 | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 343 | return NULL; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | /// print - Print feature string. |
| 348 | /// |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 349 | void SubtargetFeatures::print(raw_ostream &OS) const { |
| 350 | for (size_t i = 0, e = Features.size(); i != e; ++i) |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 351 | OS << Features[i] << " "; |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 352 | OS << "\n"; |
| 353 | } |
| 354 | |
Jim Laskey | 34bd5d5 | 2005-10-25 15:15:28 +0000 | [diff] [blame] | 355 | /// dump - Dump feature info. |
| 356 | /// |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 357 | void SubtargetFeatures::dump() const { |
Chris Lattner | e0c86af | 2009-08-23 21:41:43 +0000 | [diff] [blame] | 358 | print(errs()); |
Jim Laskey | b3302db | 2005-09-01 21:36:18 +0000 | [diff] [blame] | 359 | } |
Viktor Kutuzov | e823db8 | 2009-11-18 20:20:05 +0000 | [diff] [blame] | 360 | |
| 361 | /// getDefaultSubtargetFeatures - Return a string listing |
| 362 | /// the features associated with the target triple. |
| 363 | /// |
| 364 | /// FIXME: This is an inelegant way of specifying the features of a |
| 365 | /// subtarget. It would be better if we could encode this information |
| 366 | /// into the IR. See <rdar://5972456>. |
| 367 | /// |
| 368 | std::string SubtargetFeatures::getDefaultSubtargetFeatures( |
| 369 | const Triple& Triple) { |
| 370 | switch (Triple.getVendor()) { |
| 371 | case Triple::Apple: |
| 372 | switch (Triple.getArch()) { |
| 373 | case Triple::ppc: // powerpc-apple-* |
| 374 | return std::string("altivec"); |
| 375 | case Triple::ppc64: // powerpc64-apple-* |
| 376 | return std::string("64bit,altivec"); |
| 377 | default: |
| 378 | break; |
| 379 | } |
| 380 | break; |
| 381 | default: |
| 382 | break; |
| 383 | } |
| 384 | |
| 385 | return std::string(""); |
| 386 | } |