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