7
7
//
8
8
// ===----------------------------------------------------------------------===//
9
9
//
10
- // This file implements the SubtargetFeature interface.
10
+ // / \ file Implements the SubtargetFeature interface.
11
11
//
12
12
// ===----------------------------------------------------------------------===//
13
13
31
31
32
32
using namespace llvm ;
33
33
34
- // ===----------------------------------------------------------------------===//
35
- // Static Helper Functions
36
- // ===----------------------------------------------------------------------===//
37
-
38
- // / hasFlag - Determine if a feature has a flag; '+' or '-'
39
- // /
34
+ // / Determine if a feature has a flag; '+' or '-'
40
35
static inline bool hasFlag (StringRef Feature) {
41
36
assert (!Feature.empty () && " Empty string" );
42
37
// Get first character
@@ -45,14 +40,12 @@ static inline bool hasFlag(StringRef Feature) {
45
40
return Ch == ' +' || Ch ==' -' ;
46
41
}
47
42
48
- // / StripFlag - Return string stripped of flag.
49
- // /
43
+ // / Return string stripped of flag.
50
44
static inline std::string StripFlag (StringRef Feature) {
51
45
return hasFlag (Feature) ? Feature.substr (1 ) : Feature;
52
46
}
53
47
54
- // / isEnabled - Return true if enable flag; '+'.
55
- // /
48
+ // / Return true if enable flag; '+'.
56
49
static inline bool isEnabled (StringRef Feature) {
57
50
assert (!Feature.empty () && " Empty string" );
58
51
// Get first character
@@ -61,15 +54,13 @@ static inline bool isEnabled(StringRef Feature) {
61
54
return Ch == ' +' ;
62
55
}
63
56
64
- // / Split - Splits a string of comma separated items in to a vector of strings.
65
- // /
57
+ // / Splits a string of comma separated items in to a vector of strings.
66
58
static void Split (std::vector<std::string> &V, StringRef S) {
67
59
SmallVector<StringRef, 3 > Tmp;
68
60
S.split (Tmp, ' ,' , -1 , false /* KeepEmpty */ );
69
61
V.assign (Tmp.begin (), Tmp.end ());
70
62
}
71
63
72
- // / Adding features.
73
64
void SubtargetFeatures::AddFeature (StringRef String, bool Enable) {
74
65
// Don't add empty features.
75
66
if (!String.empty ())
@@ -89,8 +80,7 @@ static const SubtargetFeatureKV *Find(StringRef S,
89
80
return F;
90
81
}
91
82
92
- // / getLongestEntryLength - Return the length of the longest entry in the table.
93
- // /
83
+ // / Return the length of the longest entry in the table.
94
84
static size_t getLongestEntryLength (ArrayRef<SubtargetFeatureKV> Table) {
95
85
size_t MaxLen = 0 ;
96
86
for (auto &I : Table)
@@ -99,7 +89,6 @@ static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {
99
89
}
100
90
101
91
// / Display help for feature choices.
102
- // /
103
92
static void Help (ArrayRef<SubtargetFeatureKV> CPUTable,
104
93
ArrayRef<SubtargetFeatureKV> FeatTable) {
105
94
// Determine the length of the longest CPU and Feature entries.
@@ -122,10 +111,6 @@ static void Help(ArrayRef<SubtargetFeatureKV> CPUTable,
122
111
" For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n " ;
123
112
}
124
113
125
- // ===----------------------------------------------------------------------===//
126
- // SubtargetFeatures Implementation
127
- // ===----------------------------------------------------------------------===//
128
-
129
114
SubtargetFeatures::SubtargetFeatures (StringRef Initial) {
130
115
// Break up string into separate features
131
116
Split (Features, Initial);
@@ -135,40 +120,35 @@ std::string SubtargetFeatures::getString() const {
135
120
return join (Features.begin (), Features.end (), " ," );
136
121
}
137
122
138
- // / SetImpliedBits - For each feature that is (transitively) implied by this
139
- // / feature, set it.
140
- // /
123
+ // / For each feature that is (transitively) implied by this feature, set it.
141
124
static
142
- void SetImpliedBits (FeatureBitset &Bits, const SubtargetFeatureKV * FeatureEntry,
125
+ void SetImpliedBits (FeatureBitset &Bits, const SubtargetFeatureKV & FeatureEntry,
143
126
ArrayRef<SubtargetFeatureKV> FeatureTable) {
144
- for (auto &FE : FeatureTable) {
145
- if (FeatureEntry-> Value == FE.Value ) continue ;
127
+ for (const SubtargetFeatureKV &FE : FeatureTable) {
128
+ if (FeatureEntry. Value == FE.Value ) continue ;
146
129
147
- if ((FeatureEntry-> Implies & FE.Value ).any ()) {
130
+ if ((FeatureEntry. Implies & FE.Value ).any ()) {
148
131
Bits |= FE.Value ;
149
- SetImpliedBits (Bits, & FE, FeatureTable);
132
+ SetImpliedBits (Bits, FE, FeatureTable);
150
133
}
151
134
}
152
135
}
153
136
154
- // / ClearImpliedBits - For each feature that (transitively) implies this
155
- // / feature, clear it.
156
- // /
137
+ // / For each feature that (transitively) implies this feature, clear it.
157
138
static
158
- void ClearImpliedBits (FeatureBitset &Bits,
159
- const SubtargetFeatureKV * FeatureEntry,
139
+ void ClearImpliedBits (FeatureBitset &Bits,
140
+ const SubtargetFeatureKV & FeatureEntry,
160
141
ArrayRef<SubtargetFeatureKV> FeatureTable) {
161
- for (auto &FE : FeatureTable) {
162
- if (FeatureEntry-> Value == FE.Value ) continue ;
142
+ for (const SubtargetFeatureKV &FE : FeatureTable) {
143
+ if (FeatureEntry. Value == FE.Value ) continue ;
163
144
164
- if ((FE.Implies & FeatureEntry-> Value ).any ()) {
145
+ if ((FE.Implies & FeatureEntry. Value ).any ()) {
165
146
Bits &= ~FE.Value ;
166
- ClearImpliedBits (Bits, & FE, FeatureTable);
147
+ ClearImpliedBits (Bits, FE, FeatureTable);
167
148
}
168
149
}
169
150
}
170
151
171
- // / ToggleFeature - Toggle a feature and update the feature bits.
172
152
void
173
153
SubtargetFeatures::ToggleFeature (FeatureBitset &Bits, StringRef Feature,
174
154
ArrayRef<SubtargetFeatureKV> FeatureTable) {
@@ -180,16 +160,15 @@ SubtargetFeatures::ToggleFeature(FeatureBitset &Bits, StringRef Feature,
180
160
if ((Bits & FeatureEntry->Value ) == FeatureEntry->Value ) {
181
161
Bits &= ~FeatureEntry->Value ;
182
162
// For each feature that implies this, clear it.
183
- ClearImpliedBits (Bits, FeatureEntry, FeatureTable);
163
+ ClearImpliedBits (Bits, * FeatureEntry, FeatureTable);
184
164
} else {
185
165
Bits |= FeatureEntry->Value ;
186
166
187
167
// For each feature that this implies, set it.
188
- SetImpliedBits (Bits, FeatureEntry, FeatureTable);
168
+ SetImpliedBits (Bits, * FeatureEntry, FeatureTable);
189
169
}
190
170
} else {
191
- errs () << " '" << Feature
192
- << " ' is not a recognized feature for this target"
171
+ errs () << " '" << Feature << " ' is not a recognized feature for this target"
193
172
<< " (ignoring feature)\n " ;
194
173
}
195
174
}
@@ -208,35 +187,30 @@ void SubtargetFeatures::ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
208
187
Bits |= FeatureEntry->Value ;
209
188
210
189
// For each feature that this implies, set it.
211
- SetImpliedBits (Bits, FeatureEntry, FeatureTable);
190
+ SetImpliedBits (Bits, * FeatureEntry, FeatureTable);
212
191
} else {
213
192
Bits &= ~FeatureEntry->Value ;
214
193
215
194
// For each feature that implies this, clear it.
216
- ClearImpliedBits (Bits, FeatureEntry, FeatureTable);
195
+ ClearImpliedBits (Bits, * FeatureEntry, FeatureTable);
217
196
}
218
197
} else {
219
- errs () << " '" << Feature
220
- << " ' is not a recognized feature for this target"
198
+ errs () << " '" << Feature << " ' is not a recognized feature for this target"
221
199
<< " (ignoring feature)\n " ;
222
200
}
223
201
}
224
202
225
- // / getFeatureBits - Get feature bits a CPU.
226
- // /
227
203
FeatureBitset
228
204
SubtargetFeatures::getFeatureBits (StringRef CPU,
229
205
ArrayRef<SubtargetFeatureKV> CPUTable,
230
206
ArrayRef<SubtargetFeatureKV> FeatureTable) {
231
207
if (CPUTable.empty () || FeatureTable.empty ())
232
208
return FeatureBitset ();
233
209
234
- #ifndef NDEBUG
235
210
assert (std::is_sorted (std::begin (CPUTable), std::end (CPUTable)) &&
236
211
" CPU table is not sorted" );
237
212
assert (std::is_sorted (std::begin (FeatureTable), std::end (FeatureTable)) &&
238
213
" CPU features table is not sorted" );
239
- #endif
240
214
// Resulting bits
241
215
FeatureBitset Bits;
242
216
@@ -256,17 +230,16 @@ SubtargetFeatures::getFeatureBits(StringRef CPU,
256
230
// Set the feature implied by this CPU feature, if any.
257
231
for (auto &FE : FeatureTable) {
258
232
if ((CPUEntry->Value & FE.Value ).any ())
259
- SetImpliedBits (Bits, & FE, FeatureTable);
233
+ SetImpliedBits (Bits, FE, FeatureTable);
260
234
}
261
235
} else {
262
- errs () << " '" << CPU
263
- << " ' is not a recognized processor for this target"
236
+ errs () << " '" << CPU << " ' is not a recognized processor for this target"
264
237
<< " (ignoring processor)\n " ;
265
238
}
266
239
}
267
240
268
241
// Iterate through each feature
269
- for (auto &Feature : Features) {
242
+ for (const std::string &Feature : Features) {
270
243
// Check for help
271
244
if (Feature == " +help" )
272
245
Help (CPUTable, FeatureTable);
@@ -277,29 +250,22 @@ SubtargetFeatures::getFeatureBits(StringRef CPU,
277
250
return Bits;
278
251
}
279
252
280
- // / print - Print feature string.
281
- // /
282
253
void SubtargetFeatures::print (raw_ostream &OS) const {
283
254
for (auto &F : Features)
284
255
OS << F << " " ;
285
256
OS << " \n " ;
286
257
}
287
258
288
259
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
289
- // / dump - Dump feature info.
290
- // /
291
260
LLVM_DUMP_METHOD void SubtargetFeatures::dump () const {
292
261
print (dbgs ());
293
262
}
294
263
#endif
295
264
296
- // / Adds the default features for the specified target triple.
297
- // /
298
- // / FIXME: This is an inelegant way of specifying the features of a
299
- // / subtarget. It would be better if we could encode this information
300
- // / into the IR. See <rdar://5972456>.
301
- // /
302
265
void SubtargetFeatures::getDefaultSubtargetFeatures (const Triple& Triple) {
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>.
303
269
if (Triple.getVendor () == Triple::Apple) {
304
270
if (Triple.getArch () == Triple::ppc) {
305
271
// powerpc-apple-*
0 commit comments