Skip to content

Commit 05e5fd6

Browse files
committed
SubtargetFeature: Cleanup; NFC
- Fix doxygen comments - Remove duplicated comments - Remove section comments (which became wrong over time) - Use more `const` and references but less `auto` llvm-svn: 295687
1 parent 51ec0cf commit 05e5fd6

File tree

2 files changed

+65
-104
lines changed

2 files changed

+65
-104
lines changed

llvm/include/llvm/MC/SubtargetFeature.h

+34-39
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
//
88
//===----------------------------------------------------------------------===//
99
//
10-
// This file defines and manages user or tool specified CPU characteristics.
11-
// The intent is to be able to package specific features that should or should
12-
// not be used on a specific target processor. A tool, such as llc, could, as
13-
// as example, gather chip info from the command line, a long with features
14-
// that should be used on that chip.
10+
/// \file Defines and manages user or tool specified CPU characteristics.
11+
/// The intent is to be able to package specific features that should or should
12+
/// not be used on a specific target processor. A tool, such as llc, could, as
13+
/// as example, gather chip info from the command line, a long with features
14+
/// that should be used on that chip.
1515
//
1616
//===----------------------------------------------------------------------===//
1717

@@ -30,10 +30,10 @@ template <typename T> class ArrayRef;
3030
class raw_ostream;
3131
class Triple;
3232

33-
// A container class for subtarget features.
34-
// This is convenient because std::bitset does not have a constructor
35-
// with an initializer list of set bits.
3633
const unsigned MAX_SUBTARGET_FEATURES = 192;
34+
/// Container class for subtarget features.
35+
/// This is convenient because std::bitset does not have a constructor
36+
/// with an initializer list of set bits.
3737
class FeatureBitset : public std::bitset<MAX_SUBTARGET_FEATURES> {
3838
public:
3939
// Cannot inherit constructors because it's not supported by VC++..
@@ -48,82 +48,77 @@ class FeatureBitset : public std::bitset<MAX_SUBTARGET_FEATURES> {
4848
};
4949

5050
//===----------------------------------------------------------------------===//
51-
///
52-
/// SubtargetFeatureKV - Used to provide key value pairs for feature and
53-
/// CPU bit flags.
54-
//
51+
52+
/// Used to provide key value pairs for feature and CPU bit flags.
5553
struct SubtargetFeatureKV {
56-
const char *Key; // K-V key string
57-
const char *Desc; // Help descriptor
58-
FeatureBitset Value; // K-V integer value
59-
FeatureBitset Implies; // K-V bit mask
54+
const char *Key; ///< K-V key string
55+
const char *Desc; ///< Help descriptor
56+
FeatureBitset Value; ///< K-V integer value
57+
FeatureBitset Implies; ///< K-V bit mask
6058

61-
// Compare routine for std::lower_bound
59+
/// Compare routine for std::lower_bound
6260
bool operator<(StringRef S) const {
6361
return StringRef(Key) < S;
6462
}
6563

66-
// Compare routine for std::is_sorted.
64+
/// Compare routine for std::is_sorted.
6765
bool operator<(const SubtargetFeatureKV &Other) const {
6866
return StringRef(Key) < StringRef(Other.Key);
6967
}
7068
};
7169

7270
//===----------------------------------------------------------------------===//
73-
///
74-
/// SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary
75-
/// pointers.
76-
//
71+
72+
/// Used to provide key value pairs for CPU and arbitrary pointers.
7773
struct SubtargetInfoKV {
78-
const char *Key; // K-V key string
79-
const void *Value; // K-V pointer value
74+
const char *Key; ///< K-V key string
75+
const void *Value; ///< K-V pointer value
8076

81-
// Compare routine for std::lower_bound
77+
/// Compare routine for std::lower_bound
8278
bool operator<(StringRef S) const {
8379
return StringRef(Key) < S;
8480
}
8581
};
8682

8783
//===----------------------------------------------------------------------===//
84+
85+
/// Manages the enabling and disabling of subtarget specific features.
8886
///
89-
/// SubtargetFeatures - Manages the enabling and disabling of subtarget
90-
/// specific features. Features are encoded as a string of the form
87+
/// Features are encoded as a string of the form
9188
/// "+attr1,+attr2,-attr3,...,+attrN"
9289
/// A comma separates each feature from the next (all lowercase.)
9390
/// Each of the remaining features is prefixed with + or - indicating whether
9491
/// that feature should be enabled or disabled contrary to the cpu
9592
/// specification.
96-
///
97-
9893
class SubtargetFeatures {
99-
std::vector<std::string> Features; // Subtarget features as a vector
94+
std::vector<std::string> Features; ///< Subtarget features as a vector
10095

10196
public:
10297
explicit SubtargetFeatures(StringRef Initial = "");
10398

104-
/// Features string accessors.
99+
/// Returns features as a string.
105100
std::string getString() const;
106101

107-
/// Adding Features.
102+
/// Adds Features.
108103
void AddFeature(StringRef String, bool Enable = true);
109104

110-
/// ToggleFeature - Toggle a feature and update the feature bits.
105+
/// Toggles a feature and update the feature bits.
111106
static void ToggleFeature(FeatureBitset &Bits, StringRef String,
112107
ArrayRef<SubtargetFeatureKV> FeatureTable);
113108

114-
/// Apply the feature flag and update the feature bits.
109+
/// Applies the feature flag and update the feature bits.
115110
static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
116111
ArrayRef<SubtargetFeatureKV> FeatureTable);
117112

118-
/// Get feature bits of a CPU.
113+
/// Returns feature bits of a CPU.
119114
FeatureBitset getFeatureBits(StringRef CPU,
120-
ArrayRef<SubtargetFeatureKV> CPUTable,
121-
ArrayRef<SubtargetFeatureKV> FeatureTable);
115+
ArrayRef<SubtargetFeatureKV> CPUTable,
116+
ArrayRef<SubtargetFeatureKV> FeatureTable);
122117

123-
/// Print feature string.
118+
/// Prints feature string.
124119
void print(raw_ostream &OS) const;
125120

126-
// Dump feature info.
121+
// Dumps feature info.
127122
void dump() const;
128123

129124
/// Adds the default features for the specified target triple.

llvm/lib/MC/SubtargetFeature.cpp

+31-65
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88
//===----------------------------------------------------------------------===//
99
//
10-
// This file implements the SubtargetFeature interface.
10+
/// \file Implements the SubtargetFeature interface.
1111
//
1212
//===----------------------------------------------------------------------===//
1313

@@ -31,12 +31,7 @@
3131

3232
using namespace llvm;
3333

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 '-'
4035
static inline bool hasFlag(StringRef Feature) {
4136
assert(!Feature.empty() && "Empty string");
4237
// Get first character
@@ -45,14 +40,12 @@ static inline bool hasFlag(StringRef Feature) {
4540
return Ch == '+' || Ch =='-';
4641
}
4742

48-
/// StripFlag - Return string stripped of flag.
49-
///
43+
/// Return string stripped of flag.
5044
static inline std::string StripFlag(StringRef Feature) {
5145
return hasFlag(Feature) ? Feature.substr(1) : Feature;
5246
}
5347

54-
/// isEnabled - Return true if enable flag; '+'.
55-
///
48+
/// Return true if enable flag; '+'.
5649
static inline bool isEnabled(StringRef Feature) {
5750
assert(!Feature.empty() && "Empty string");
5851
// Get first character
@@ -61,15 +54,13 @@ static inline bool isEnabled(StringRef Feature) {
6154
return Ch == '+';
6255
}
6356

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.
6658
static void Split(std::vector<std::string> &V, StringRef S) {
6759
SmallVector<StringRef, 3> Tmp;
6860
S.split(Tmp, ',', -1, false /* KeepEmpty */);
6961
V.assign(Tmp.begin(), Tmp.end());
7062
}
7163

72-
/// Adding features.
7364
void SubtargetFeatures::AddFeature(StringRef String, bool Enable) {
7465
// Don't add empty features.
7566
if (!String.empty())
@@ -89,8 +80,7 @@ static const SubtargetFeatureKV *Find(StringRef S,
8980
return F;
9081
}
9182

92-
/// getLongestEntryLength - Return the length of the longest entry in the table.
93-
///
83+
/// Return the length of the longest entry in the table.
9484
static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {
9585
size_t MaxLen = 0;
9686
for (auto &I : Table)
@@ -99,7 +89,6 @@ static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {
9989
}
10090

10191
/// Display help for feature choices.
102-
///
10392
static void Help(ArrayRef<SubtargetFeatureKV> CPUTable,
10493
ArrayRef<SubtargetFeatureKV> FeatTable) {
10594
// Determine the length of the longest CPU and Feature entries.
@@ -122,10 +111,6 @@ static void Help(ArrayRef<SubtargetFeatureKV> CPUTable,
122111
"For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n";
123112
}
124113

125-
//===----------------------------------------------------------------------===//
126-
// SubtargetFeatures Implementation
127-
//===----------------------------------------------------------------------===//
128-
129114
SubtargetFeatures::SubtargetFeatures(StringRef Initial) {
130115
// Break up string into separate features
131116
Split(Features, Initial);
@@ -135,40 +120,35 @@ std::string SubtargetFeatures::getString() const {
135120
return join(Features.begin(), Features.end(), ",");
136121
}
137122

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.
141124
static
142-
void SetImpliedBits(FeatureBitset &Bits, const SubtargetFeatureKV *FeatureEntry,
125+
void SetImpliedBits(FeatureBitset &Bits, const SubtargetFeatureKV &FeatureEntry,
143126
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;
146129

147-
if ((FeatureEntry->Implies & FE.Value).any()) {
130+
if ((FeatureEntry.Implies & FE.Value).any()) {
148131
Bits |= FE.Value;
149-
SetImpliedBits(Bits, &FE, FeatureTable);
132+
SetImpliedBits(Bits, FE, FeatureTable);
150133
}
151134
}
152135
}
153136

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.
157138
static
158-
void ClearImpliedBits(FeatureBitset &Bits,
159-
const SubtargetFeatureKV *FeatureEntry,
139+
void ClearImpliedBits(FeatureBitset &Bits,
140+
const SubtargetFeatureKV &FeatureEntry,
160141
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;
163144

164-
if ((FE.Implies & FeatureEntry->Value).any()) {
145+
if ((FE.Implies & FeatureEntry.Value).any()) {
165146
Bits &= ~FE.Value;
166-
ClearImpliedBits(Bits, &FE, FeatureTable);
147+
ClearImpliedBits(Bits, FE, FeatureTable);
167148
}
168149
}
169150
}
170151

171-
/// ToggleFeature - Toggle a feature and update the feature bits.
172152
void
173153
SubtargetFeatures::ToggleFeature(FeatureBitset &Bits, StringRef Feature,
174154
ArrayRef<SubtargetFeatureKV> FeatureTable) {
@@ -180,16 +160,15 @@ SubtargetFeatures::ToggleFeature(FeatureBitset &Bits, StringRef Feature,
180160
if ((Bits & FeatureEntry->Value) == FeatureEntry->Value) {
181161
Bits &= ~FeatureEntry->Value;
182162
// For each feature that implies this, clear it.
183-
ClearImpliedBits(Bits, FeatureEntry, FeatureTable);
163+
ClearImpliedBits(Bits, *FeatureEntry, FeatureTable);
184164
} else {
185165
Bits |= FeatureEntry->Value;
186166

187167
// For each feature that this implies, set it.
188-
SetImpliedBits(Bits, FeatureEntry, FeatureTable);
168+
SetImpliedBits(Bits, *FeatureEntry, FeatureTable);
189169
}
190170
} else {
191-
errs() << "'" << Feature
192-
<< "' is not a recognized feature for this target"
171+
errs() << "'" << Feature << "' is not a recognized feature for this target"
193172
<< " (ignoring feature)\n";
194173
}
195174
}
@@ -208,35 +187,30 @@ void SubtargetFeatures::ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
208187
Bits |= FeatureEntry->Value;
209188

210189
// For each feature that this implies, set it.
211-
SetImpliedBits(Bits, FeatureEntry, FeatureTable);
190+
SetImpliedBits(Bits, *FeatureEntry, FeatureTable);
212191
} else {
213192
Bits &= ~FeatureEntry->Value;
214193

215194
// For each feature that implies this, clear it.
216-
ClearImpliedBits(Bits, FeatureEntry, FeatureTable);
195+
ClearImpliedBits(Bits, *FeatureEntry, FeatureTable);
217196
}
218197
} else {
219-
errs() << "'" << Feature
220-
<< "' is not a recognized feature for this target"
198+
errs() << "'" << Feature << "' is not a recognized feature for this target"
221199
<< " (ignoring feature)\n";
222200
}
223201
}
224202

225-
/// getFeatureBits - Get feature bits a CPU.
226-
///
227203
FeatureBitset
228204
SubtargetFeatures::getFeatureBits(StringRef CPU,
229205
ArrayRef<SubtargetFeatureKV> CPUTable,
230206
ArrayRef<SubtargetFeatureKV> FeatureTable) {
231207
if (CPUTable.empty() || FeatureTable.empty())
232208
return FeatureBitset();
233209

234-
#ifndef NDEBUG
235210
assert(std::is_sorted(std::begin(CPUTable), std::end(CPUTable)) &&
236211
"CPU table is not sorted");
237212
assert(std::is_sorted(std::begin(FeatureTable), std::end(FeatureTable)) &&
238213
"CPU features table is not sorted");
239-
#endif
240214
// Resulting bits
241215
FeatureBitset Bits;
242216

@@ -256,17 +230,16 @@ SubtargetFeatures::getFeatureBits(StringRef CPU,
256230
// Set the feature implied by this CPU feature, if any.
257231
for (auto &FE : FeatureTable) {
258232
if ((CPUEntry->Value & FE.Value).any())
259-
SetImpliedBits(Bits, &FE, FeatureTable);
233+
SetImpliedBits(Bits, FE, FeatureTable);
260234
}
261235
} else {
262-
errs() << "'" << CPU
263-
<< "' is not a recognized processor for this target"
236+
errs() << "'" << CPU << "' is not a recognized processor for this target"
264237
<< " (ignoring processor)\n";
265238
}
266239
}
267240

268241
// Iterate through each feature
269-
for (auto &Feature : Features) {
242+
for (const std::string &Feature : Features) {
270243
// Check for help
271244
if (Feature == "+help")
272245
Help(CPUTable, FeatureTable);
@@ -277,29 +250,22 @@ SubtargetFeatures::getFeatureBits(StringRef CPU,
277250
return Bits;
278251
}
279252

280-
/// print - Print feature string.
281-
///
282253
void SubtargetFeatures::print(raw_ostream &OS) const {
283254
for (auto &F : Features)
284255
OS << F << " ";
285256
OS << "\n";
286257
}
287258

288259
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
289-
/// dump - Dump feature info.
290-
///
291260
LLVM_DUMP_METHOD void SubtargetFeatures::dump() const {
292261
print(dbgs());
293262
}
294263
#endif
295264

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-
///
302265
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>.
303269
if (Triple.getVendor() == Triple::Apple) {
304270
if (Triple.getArch() == Triple::ppc) {
305271
// powerpc-apple-*

0 commit comments

Comments
 (0)