Skip to content

Commit d474181

Browse files
committed
ArrayRef-ize the Feature and Processor tables for SubtargetFeatures.
This removes arguments passed everywhere and allows the use of standard iteration over lists. Should be no functional change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208127 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3949749 commit d474181

File tree

5 files changed

+73
-98
lines changed

5 files changed

+73
-98
lines changed

include/llvm/MC/MCSubtargetInfo.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class StringRef;
2828
///
2929
class MCSubtargetInfo {
3030
std::string TargetTriple; // Target triple
31-
const SubtargetFeatureKV *ProcFeatures; // Processor feature list
32-
const SubtargetFeatureKV *ProcDesc; // Processor descriptions
31+
ArrayRef<SubtargetFeatureKV> ProcFeatures; // Processor feature list
32+
ArrayRef<SubtargetFeatureKV> ProcDesc; // Processor descriptions
3333

3434
// Scheduler machine model
3535
const SubtargetInfoKV *ProcSchedModels;
@@ -41,21 +41,18 @@ class MCSubtargetInfo {
4141
const InstrStage *Stages; // Instruction itinerary stages
4242
const unsigned *OperandCycles; // Itinerary operand cycles
4343
const unsigned *ForwardingPaths; // Forwarding paths
44-
unsigned NumFeatures; // Number of processor features
45-
unsigned NumProcs; // Number of processors
4644
uint64_t FeatureBits; // Feature bits for current CPU + FS
4745

4846
public:
4947
void InitMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS,
50-
const SubtargetFeatureKV *PF,
51-
const SubtargetFeatureKV *PD,
48+
ArrayRef<SubtargetFeatureKV> PF,
49+
ArrayRef<SubtargetFeatureKV> PD,
5250
const SubtargetInfoKV *ProcSched,
5351
const MCWriteProcResEntry *WPR,
5452
const MCWriteLatencyEntry *WL,
5553
const MCReadAdvanceEntry *RA,
5654
const InstrStage *IS,
57-
const unsigned *OC, const unsigned *FP,
58-
unsigned NF, unsigned NP);
55+
const unsigned *OC, const unsigned *FP);
5956

6057
/// getTargetTriple - Return the target triple string.
6158
StringRef getTargetTriple() const {

include/llvm/MC/SubtargetFeature.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#ifndef LLVM_MC_SUBTARGETFEATURE_H
1919
#define LLVM_MC_SUBTARGETFEATURE_H
2020

21+
#include "llvm/ADT/ArrayRef.h"
2122
#include "llvm/ADT/Triple.h"
2223
#include "llvm/Support/DataTypes.h"
23-
#include <vector>
2424

2525
namespace llvm {
2626
class raw_ostream;
@@ -83,15 +83,12 @@ class SubtargetFeatures {
8383
/// ToggleFeature - Toggle a feature and returns the newly updated feature
8484
/// bits.
8585
uint64_t ToggleFeature(uint64_t Bits, const StringRef String,
86-
const SubtargetFeatureKV *FeatureTable,
87-
size_t FeatureTableSize);
86+
ArrayRef<SubtargetFeatureKV> FeatureTable);
8887

8988
/// Get feature bits of a CPU.
9089
uint64_t getFeatureBits(const StringRef CPU,
91-
const SubtargetFeatureKV *CPUTable,
92-
size_t CPUTableSize,
93-
const SubtargetFeatureKV *FeatureTable,
94-
size_t FeatureTableSize);
90+
ArrayRef<SubtargetFeatureKV> CPUTable,
91+
ArrayRef<SubtargetFeatureKV> FeatureTable);
9592

9693
/// Print feature string.
9794
void print(raw_ostream &OS) const;

lib/MC/MCSubtargetInfo.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ MCSchedModel MCSchedModel::DefaultSchedModel; // For unknown processors.
2424
void
2525
MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) {
2626
SubtargetFeatures Features(FS);
27-
FeatureBits = Features.getFeatureBits(CPU, ProcDesc, NumProcs,
28-
ProcFeatures, NumFeatures);
29-
27+
FeatureBits = Features.getFeatureBits(CPU, ProcDesc, ProcFeatures);
3028
InitCPUSchedModel(CPU);
3129
}
3230

@@ -40,16 +38,15 @@ MCSubtargetInfo::InitCPUSchedModel(StringRef CPU) {
4038

4139
void
4240
MCSubtargetInfo::InitMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS,
43-
const SubtargetFeatureKV *PF,
44-
const SubtargetFeatureKV *PD,
41+
ArrayRef<SubtargetFeatureKV> PF,
42+
ArrayRef<SubtargetFeatureKV> PD,
4543
const SubtargetInfoKV *ProcSched,
4644
const MCWriteProcResEntry *WPR,
4745
const MCWriteLatencyEntry *WL,
4846
const MCReadAdvanceEntry *RA,
4947
const InstrStage *IS,
5048
const unsigned *OC,
51-
const unsigned *FP,
52-
unsigned NF, unsigned NP) {
49+
const unsigned *FP) {
5350
TargetTriple = TT;
5451
ProcFeatures = PF;
5552
ProcDesc = PD;
@@ -61,8 +58,6 @@ MCSubtargetInfo::InitMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS,
6158
Stages = IS;
6259
OperandCycles = OC;
6360
ForwardingPaths = FP;
64-
NumFeatures = NF;
65-
NumProcs = NP;
6661

6762
InitMCProcessorInfo(CPU, FS);
6863
}
@@ -78,8 +73,7 @@ uint64_t MCSubtargetInfo::ToggleFeature(uint64_t FB) {
7873
/// bits. This version will also change all implied bits.
7974
uint64_t MCSubtargetInfo::ToggleFeature(StringRef FS) {
8075
SubtargetFeatures Features;
81-
FeatureBits = Features.ToggleFeature(FeatureBits, FS,
82-
ProcFeatures, NumFeatures);
76+
FeatureBits = Features.ToggleFeature(FeatureBits, FS, ProcFeatures);
8377
return FeatureBits;
8478
}
8579

@@ -88,6 +82,7 @@ const MCSchedModel *
8882
MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
8983
assert(ProcSchedModels && "Processor machine model not available!");
9084

85+
unsigned NumProcs = ProcDesc.size();
9186
#ifndef NDEBUG
9287
for (size_t i = 1; i < NumProcs; i++) {
9388
assert(strcmp(ProcSchedModels[i - 1].Key, ProcSchedModels[i].Key) < 0 &&

lib/MC/SubtargetFeature.cpp

Lines changed: 46 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -105,49 +105,43 @@ void SubtargetFeatures::AddFeature(const StringRef String) {
105105
}
106106

107107
/// 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) {
112110
// 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);
114112
// 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;
116114
// Return the found array item
117115
return F;
118116
}
119117

120118
/// getLongestEntryLength - Return the length of the longest entry in the table.
121119
///
122-
static size_t getLongestEntryLength(const SubtargetFeatureKV *Table,
123-
size_t Size) {
120+
static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {
124121
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));
127124
return MaxLen;
128125
}
129126

130127
/// Display help for feature choices.
131128
///
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) {
135131
// 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);
138134

139135
// Print the CPU table.
140136
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);
144139
errs() << '\n';
145140

146141
// Print the Feature table.
147142
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);
151145
errs() << '\n';
152146

153147
errs() << "Use +feature to enable a feature, or -feature to disable it.\n"
@@ -173,16 +167,13 @@ std::string SubtargetFeatures::getString() const {
173167
///
174168
static
175169
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) {
181172
if (FeatureEntry->Value == FE.Value) continue;
182173

183174
if (FeatureEntry->Implies & FE.Value) {
184175
Bits |= FE.Value;
185-
SetImpliedBits(Bits, &FE, FeatureTable, FeatureTableSize);
176+
SetImpliedBits(Bits, &FE, FeatureTable);
186177
}
187178
}
188179
}
@@ -192,41 +183,38 @@ void SetImpliedBits(uint64_t &Bits, const SubtargetFeatureKV *FeatureEntry,
192183
///
193184
static
194185
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) {
200188
if (FeatureEntry->Value == FE.Value) continue;
201189

202190
if (FE.Implies & FeatureEntry->Value) {
203191
Bits &= ~FE.Value;
204-
ClearImpliedBits(Bits, &FE, FeatureTable, FeatureTableSize);
192+
ClearImpliedBits(Bits, &FE, FeatureTable);
205193
}
206194
}
207195
}
208196

209197
/// ToggleFeature - Toggle a feature and returns the newly updated feature
210198
/// 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+
215203
// Find feature in table.
216204
const SubtargetFeatureKV *FeatureEntry =
217-
Find(StripFlag(Feature), FeatureTable, FeatureTableSize);
205+
Find(StripFlag(Feature), FeatureTable);
218206
// If there is a match
219207
if (FeatureEntry) {
220208
if ((Bits & FeatureEntry->Value) == FeatureEntry->Value) {
221209
Bits &= ~FeatureEntry->Value;
222210

223211
// For each feature that implies this, clear it.
224-
ClearImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize);
212+
ClearImpliedBits(Bits, FeatureEntry, FeatureTable);
225213
} else {
226214
Bits |= FeatureEntry->Value;
227215

228216
// For each feature that this implies, set it.
229-
SetImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize);
217+
SetImpliedBits(Bits, FeatureEntry, FeatureTable);
230218
}
231219
} else {
232220
errs() << "'" << Feature
@@ -240,20 +228,20 @@ SubtargetFeatures::ToggleFeature(uint64_t Bits, const StringRef Feature,
240228

241229
/// getFeatureBits - Get feature bits a CPU.
242230
///
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())
249237
return 0;
250238

251239
#ifndef NDEBUG
252-
for (size_t i = 1; i < CPUTableSize; i++) {
240+
for (size_t i = 1, e = CPUTable.size(); i != e; ++i) {
253241
assert(strcmp(CPUTable[i - 1].Key, CPUTable[i].Key) < 0 &&
254242
"CPU table is not sorted");
255243
}
256-
for (size_t i = 1; i < FeatureTableSize; i++) {
244+
for (size_t i = 1, e = FeatureTable.size(); i != e; ++i) {
257245
assert(strcmp(FeatureTable[i - 1].Key, FeatureTable[i].Key) < 0 &&
258246
"CPU features table is not sorted");
259247
}
@@ -262,21 +250,21 @@ uint64_t SubtargetFeatures::getFeatureBits(const StringRef CPU,
262250

263251
// Check if help is needed
264252
if (CPU == "help")
265-
Help(CPUTable, CPUTableSize, FeatureTable, FeatureTableSize);
253+
Help(CPUTable, FeatureTable);
266254

267255
// Find CPU entry if CPU name is specified.
268256
else if (!CPU.empty()) {
269-
const SubtargetFeatureKV *CPUEntry = Find(CPU, CPUTable, CPUTableSize);
257+
const SubtargetFeatureKV *CPUEntry = Find(CPU, CPUTable);
258+
270259
// If there is a match
271260
if (CPUEntry) {
272261
// Set base feature bits
273262
Bits = CPUEntry->Value;
274263

275264
// 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) {
278266
if (CPUEntry->Value & FE.Value)
279-
SetImpliedBits(Bits, &FE, FeatureTable, FeatureTableSize);
267+
SetImpliedBits(Bits, &FE, FeatureTable);
280268
}
281269
} else {
282270
errs() << "'" << CPU
@@ -286,29 +274,27 @@ uint64_t SubtargetFeatures::getFeatureBits(const StringRef CPU,
286274
}
287275

288276
// 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) {
292278
// Check for help
293279
if (Feature == "+help")
294-
Help(CPUTable, CPUTableSize, FeatureTable, FeatureTableSize);
280+
Help(CPUTable, FeatureTable);
295281

296282
// Find feature in table.
297283
const SubtargetFeatureKV *FeatureEntry =
298-
Find(StripFlag(Feature), FeatureTable, FeatureTableSize);
284+
Find(StripFlag(Feature), FeatureTable);
299285
// If there is a match
300286
if (FeatureEntry) {
301287
// Enable/disable feature in bits
302288
if (isEnabled(Feature)) {
303289
Bits |= FeatureEntry->Value;
304290

305291
// For each feature that this implies, set it.
306-
SetImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize);
292+
SetImpliedBits(Bits, FeatureEntry, FeatureTable);
307293
} else {
308294
Bits &= ~FeatureEntry->Value;
309295

310296
// For each feature that implies this, clear it.
311-
ClearImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize);
297+
ClearImpliedBits(Bits, FeatureEntry, FeatureTable);
312298
}
313299
} else {
314300
errs() << "'" << Feature

0 commit comments

Comments
 (0)