@@ -105,49 +105,43 @@ void SubtargetFeatures::AddFeature(const StringRef String) {
105
105
}
106
106
107
107
// / Find KV in array using binary search.
108
- static const SubtargetFeatureKV *Find (StringRef S, const SubtargetFeatureKV *A,
109
- size_t L) {
110
- // Determine the end of the array
111
- const SubtargetFeatureKV *Hi = A + L;
108
+ static const SubtargetFeatureKV *Find (StringRef S,
109
+ ArrayRef<SubtargetFeatureKV> A) {
112
110
// Binary search the array
113
- const SubtargetFeatureKV * F = std::lower_bound (A, Hi , S);
111
+ auto F = std::lower_bound (A. begin (), A. end () , S);
114
112
// If not found then return NULL
115
- if (F == Hi || StringRef (F->Key ) != S) return nullptr ;
113
+ if (F == A. end () || StringRef (F->Key ) != S) return nullptr ;
116
114
// Return the found array item
117
115
return F;
118
116
}
119
117
120
118
// / getLongestEntryLength - Return the length of the longest entry in the table.
121
119
// /
122
- static size_t getLongestEntryLength (const SubtargetFeatureKV *Table,
123
- size_t Size) {
120
+ static size_t getLongestEntryLength (ArrayRef<SubtargetFeatureKV> Table) {
124
121
size_t MaxLen = 0 ;
125
- for (size_t i = 0 ; i < Size; i++ )
126
- MaxLen = std::max (MaxLen, std::strlen (Table[i] .Key ));
122
+ for (auto &I : Table )
123
+ MaxLen = std::max (MaxLen, std::strlen (I .Key ));
127
124
return MaxLen;
128
125
}
129
126
130
127
// / Display help for feature choices.
131
128
// /
132
- static void Help (const SubtargetFeatureKV *CPUTable, size_t CPUTableSize,
133
- const SubtargetFeatureKV *FeatTable,
134
- size_t FeatTableSize) {
129
+ static void Help (ArrayRef<SubtargetFeatureKV> CPUTable,
130
+ ArrayRef<SubtargetFeatureKV> FeatTable) {
135
131
// Determine the length of the longest CPU and Feature entries.
136
- unsigned MaxCPULen = getLongestEntryLength (CPUTable, CPUTableSize );
137
- unsigned MaxFeatLen = getLongestEntryLength (FeatTable, FeatTableSize );
132
+ unsigned MaxCPULen = getLongestEntryLength (CPUTable);
133
+ unsigned MaxFeatLen = getLongestEntryLength (FeatTable);
138
134
139
135
// Print the CPU table.
140
136
errs () << " Available CPUs for this target:\n\n " ;
141
- for (size_t i = 0 ; i != CPUTableSize; i++)
142
- errs () << format (" %-*s - %s.\n " ,
143
- MaxCPULen, CPUTable[i].Key , CPUTable[i].Desc );
137
+ for (auto &CPU : CPUTable)
138
+ errs () << format (" %-*s - %s.\n " , MaxCPULen, CPU.Key , CPU.Desc );
144
139
errs () << ' \n ' ;
145
140
146
141
// Print the Feature table.
147
142
errs () << " Available features for this target:\n\n " ;
148
- for (size_t i = 0 ; i != FeatTableSize; i++)
149
- errs () << format (" %-*s - %s.\n " ,
150
- MaxFeatLen, FeatTable[i].Key , FeatTable[i].Desc );
143
+ for (auto &Feature : FeatTable)
144
+ errs () << format (" %-*s - %s.\n " , MaxFeatLen, Feature.Key , Feature.Desc );
151
145
errs () << ' \n ' ;
152
146
153
147
errs () << " Use +feature to enable a feature, or -feature to disable it.\n "
@@ -173,16 +167,13 @@ std::string SubtargetFeatures::getString() const {
173
167
// /
174
168
static
175
169
void SetImpliedBits (uint64_t &Bits, const SubtargetFeatureKV *FeatureEntry,
176
- const SubtargetFeatureKV *FeatureTable,
177
- size_t FeatureTableSize) {
178
- for (size_t i = 0 ; i < FeatureTableSize; ++i) {
179
- const SubtargetFeatureKV &FE = FeatureTable[i];
180
-
170
+ ArrayRef<SubtargetFeatureKV> FeatureTable) {
171
+ for (auto &FE : FeatureTable) {
181
172
if (FeatureEntry->Value == FE.Value ) continue ;
182
173
183
174
if (FeatureEntry->Implies & FE.Value ) {
184
175
Bits |= FE.Value ;
185
- SetImpliedBits (Bits, &FE, FeatureTable, FeatureTableSize );
176
+ SetImpliedBits (Bits, &FE, FeatureTable);
186
177
}
187
178
}
188
179
}
@@ -192,41 +183,38 @@ void SetImpliedBits(uint64_t &Bits, const SubtargetFeatureKV *FeatureEntry,
192
183
// /
193
184
static
194
185
void ClearImpliedBits (uint64_t &Bits, const SubtargetFeatureKV *FeatureEntry,
195
- const SubtargetFeatureKV *FeatureTable,
196
- size_t FeatureTableSize) {
197
- for (size_t i = 0 ; i < FeatureTableSize; ++i) {
198
- const SubtargetFeatureKV &FE = FeatureTable[i];
199
-
186
+ ArrayRef<SubtargetFeatureKV> FeatureTable) {
187
+ for (auto &FE : FeatureTable) {
200
188
if (FeatureEntry->Value == FE.Value ) continue ;
201
189
202
190
if (FE.Implies & FeatureEntry->Value ) {
203
191
Bits &= ~FE.Value ;
204
- ClearImpliedBits (Bits, &FE, FeatureTable, FeatureTableSize );
192
+ ClearImpliedBits (Bits, &FE, FeatureTable);
205
193
}
206
194
}
207
195
}
208
196
209
197
// / ToggleFeature - Toggle a feature and returns the newly updated feature
210
198
// / bits.
211
- uint64_t
212
- SubtargetFeatures::ToggleFeature ( uint64_t Bits, const StringRef Feature,
213
- const SubtargetFeatureKV * FeatureTable,
214
- size_t FeatureTableSize) {
199
+ uint64_t SubtargetFeatures::ToggleFeature (
200
+ uint64_t Bits, const StringRef Feature,
201
+ ArrayRef< SubtargetFeatureKV> FeatureTable) {
202
+
215
203
// Find feature in table.
216
204
const SubtargetFeatureKV *FeatureEntry =
217
- Find (StripFlag (Feature), FeatureTable, FeatureTableSize );
205
+ Find (StripFlag (Feature), FeatureTable);
218
206
// If there is a match
219
207
if (FeatureEntry) {
220
208
if ((Bits & FeatureEntry->Value ) == FeatureEntry->Value ) {
221
209
Bits &= ~FeatureEntry->Value ;
222
210
223
211
// For each feature that implies this, clear it.
224
- ClearImpliedBits (Bits, FeatureEntry, FeatureTable, FeatureTableSize );
212
+ ClearImpliedBits (Bits, FeatureEntry, FeatureTable);
225
213
} else {
226
214
Bits |= FeatureEntry->Value ;
227
215
228
216
// For each feature that this implies, set it.
229
- SetImpliedBits (Bits, FeatureEntry, FeatureTable, FeatureTableSize );
217
+ SetImpliedBits (Bits, FeatureEntry, FeatureTable);
230
218
}
231
219
} else {
232
220
errs () << " '" << Feature
@@ -240,20 +228,20 @@ SubtargetFeatures::ToggleFeature(uint64_t Bits, const StringRef Feature,
240
228
241
229
// / getFeatureBits - Get feature bits a CPU.
242
230
// /
243
- uint64_t SubtargetFeatures::getFeatureBits ( const StringRef CPU,
244
- const SubtargetFeatureKV *CPUTable ,
245
- size_t CPUTableSize ,
246
- const SubtargetFeatureKV * FeatureTable,
247
- size_t FeatureTableSize) {
248
- if (!FeatureTableSize || !CPUTableSize )
231
+ uint64_t
232
+ SubtargetFeatures::getFeatureBits ( const StringRef CPU ,
233
+ ArrayRef<SubtargetFeatureKV> CPUTable ,
234
+ ArrayRef< SubtargetFeatureKV> FeatureTable) {
235
+
236
+ if (CPUTable. empty () || FeatureTable. empty () )
249
237
return 0 ;
250
238
251
239
#ifndef NDEBUG
252
- for (size_t i = 1 ; i < CPUTableSize; i++ ) {
240
+ for (size_t i = 1 , e = CPUTable. size () ; i != e; ++i ) {
253
241
assert (strcmp (CPUTable[i - 1 ].Key , CPUTable[i].Key ) < 0 &&
254
242
" CPU table is not sorted" );
255
243
}
256
- for (size_t i = 1 ; i < FeatureTableSize; i++ ) {
244
+ for (size_t i = 1 , e = FeatureTable. size () ; i != e; ++i ) {
257
245
assert (strcmp (FeatureTable[i - 1 ].Key , FeatureTable[i].Key ) < 0 &&
258
246
" CPU features table is not sorted" );
259
247
}
@@ -262,21 +250,21 @@ uint64_t SubtargetFeatures::getFeatureBits(const StringRef CPU,
262
250
263
251
// Check if help is needed
264
252
if (CPU == " help" )
265
- Help (CPUTable, CPUTableSize, FeatureTable, FeatureTableSize );
253
+ Help (CPUTable, FeatureTable);
266
254
267
255
// Find CPU entry if CPU name is specified.
268
256
else if (!CPU.empty ()) {
269
- const SubtargetFeatureKV *CPUEntry = Find (CPU, CPUTable, CPUTableSize);
257
+ const SubtargetFeatureKV *CPUEntry = Find (CPU, CPUTable);
258
+
270
259
// If there is a match
271
260
if (CPUEntry) {
272
261
// Set base feature bits
273
262
Bits = CPUEntry->Value ;
274
263
275
264
// Set the feature implied by this CPU feature, if any.
276
- for (size_t i = 0 ; i < FeatureTableSize; ++i) {
277
- const SubtargetFeatureKV &FE = FeatureTable[i];
265
+ for (auto &FE : FeatureTable) {
278
266
if (CPUEntry->Value & FE.Value )
279
- SetImpliedBits (Bits, &FE, FeatureTable, FeatureTableSize );
267
+ SetImpliedBits (Bits, &FE, FeatureTable);
280
268
}
281
269
} else {
282
270
errs () << " '" << CPU
@@ -286,29 +274,27 @@ uint64_t SubtargetFeatures::getFeatureBits(const StringRef CPU,
286
274
}
287
275
288
276
// Iterate through each feature
289
- for (size_t i = 0 , E = Features.size (); i < E; i++) {
290
- const StringRef Feature = Features[i];
291
-
277
+ for (auto &Feature : Features) {
292
278
// Check for help
293
279
if (Feature == " +help" )
294
- Help (CPUTable, CPUTableSize, FeatureTable, FeatureTableSize );
280
+ Help (CPUTable, FeatureTable);
295
281
296
282
// Find feature in table.
297
283
const SubtargetFeatureKV *FeatureEntry =
298
- Find (StripFlag (Feature), FeatureTable, FeatureTableSize );
284
+ Find (StripFlag (Feature), FeatureTable);
299
285
// If there is a match
300
286
if (FeatureEntry) {
301
287
// Enable/disable feature in bits
302
288
if (isEnabled (Feature)) {
303
289
Bits |= FeatureEntry->Value ;
304
290
305
291
// For each feature that this implies, set it.
306
- SetImpliedBits (Bits, FeatureEntry, FeatureTable, FeatureTableSize );
292
+ SetImpliedBits (Bits, FeatureEntry, FeatureTable);
307
293
} else {
308
294
Bits &= ~FeatureEntry->Value ;
309
295
310
296
// For each feature that implies this, clear it.
311
- ClearImpliedBits (Bits, FeatureEntry, FeatureTable, FeatureTableSize );
297
+ ClearImpliedBits (Bits, FeatureEntry, FeatureTable);
312
298
}
313
299
} else {
314
300
errs () << " '" << Feature
0 commit comments