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