llvm.org GIT mirror llvm / b6a6388
Increase SubtargetFeatureKV Value and Implies fields to 64 bits since some targets are getting very close to 32 subtarget features. Also teach tablegen to error when there are more than 64 features to guard against undefined behavior. rdar://9282332 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129590 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 9 years ago
3 changed file(s) with 19 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
3434 struct SubtargetFeatureKV {
3535 const char *Key; // K-V key string
3636 const char *Desc; // Help descriptor
37 uint32_t Value; // K-V integer value
38 uint32_t Implies; // K-V bit mask
37 uint64_t Value; // K-V integer value
38 uint64_t Implies; // K-V bit mask
3939
4040 // Compare routine for std binary search
4141 bool operator<(const SubtargetFeatureKV &S) const {
9393 void AddFeature(const std::string &String, bool IsEnabled = true);
9494
9595 /// Get feature bits.
96 uint32_t getBits(const SubtargetFeatureKV *CPUTable,
96 uint64_t getBits(const SubtargetFeatureKV *CPUTable,
9797 size_t CPUTableSize,
9898 const SubtargetFeatureKV *FeatureTable,
9999 size_t FeatureTableSize);
210210 /// feature, set it.
211211 ///
212212 static
213 void SetImpliedBits(uint32_t &Bits, const SubtargetFeatureKV *FeatureEntry,
213 void SetImpliedBits(uint64_t &Bits, const SubtargetFeatureKV *FeatureEntry,
214214 const SubtargetFeatureKV *FeatureTable,
215215 size_t FeatureTableSize) {
216216 for (size_t i = 0; i < FeatureTableSize; ++i) {
229229 /// feature, clear it.
230230 ///
231231 static
232 void ClearImpliedBits(uint32_t &Bits, const SubtargetFeatureKV *FeatureEntry,
232 void ClearImpliedBits(uint64_t &Bits, const SubtargetFeatureKV *FeatureEntry,
233233 const SubtargetFeatureKV *FeatureTable,
234234 size_t FeatureTableSize) {
235235 for (size_t i = 0; i < FeatureTableSize; ++i) {
246246
247247 /// getBits - Get feature bits.
248248 ///
249 uint32_t SubtargetFeatures::getBits(const SubtargetFeatureKV *CPUTable,
249 uint64_t SubtargetFeatures::getBits(const SubtargetFeatureKV *CPUTable,
250250 size_t CPUTableSize,
251251 const SubtargetFeatureKV *FeatureTable,
252252 size_t FeatureTableSize) {
262262 "CPU features table is not sorted");
263263 }
264264 #endif
265 uint32_t Bits = 0; // Resulting bits
265 uint64_t Bits = 0; // Resulting bits
266266
267267 // Check if help is needed
268268 if (Features[0] == "help")
3232 OS << "enum {\n";
3333
3434 // For each record
35 for (unsigned i = 0, N = DefList.size(); i < N;) {
35 unsigned N = DefList.size();
36 if (N > 64) {
37 errs() << "Too many (> 64) subtarget features!\n";
38 exit(1);
39 }
40
41 for (unsigned i = 0; i < N;) {
3642 // Next record
3743 Record *Def = DefList[i];
3844
4046 OS << " " << Def->getName();
4147
4248 // If bit flags then emit expression (1 << i)
43 if (isBits) OS << " = " << " 1 << " << i;
49 if (isBits) OS << " = " << " 1ULL << " << i;
4450
4551 // Depending on 'if more in the list' emit comma
4652 if (++i < N) OS << ",";
8793 Feature->getValueAsListOfDefs("Implies");
8894
8995 if (ImpliesList.empty()) {
90 OS << "0";
96 OS << "0ULL";
9197 } else {
9298 for (unsigned j = 0, M = ImpliesList.size(); j < M;) {
9399 OS << ImpliesList[j]->getName();
141147 << "\"Select the " << Name << " processor\", ";
142148
143149 if (FeatureList.empty()) {
144 OS << "0";
150 OS << "0ULL";
145151 } else {
146152 for (unsigned j = 0, M = FeatureList.size(); j < M;) {
147153 OS << FeatureList[j]->getName();
150156 }
151157
152158 // The "0" is for the "implies" section of this data structure.
153 OS << ", 0 }";
159 OS << ", 0ULL }";
154160
155161 // Depending on 'if more in the list' emit comma
156162 if (++i < N) OS << ",";
607613 << " DEBUG(dbgs() << \"\\nCPU:\" << CPU);\n"
608614 << " SubtargetFeatures Features(FS);\n"
609615 << " Features.setCPUIfNone(CPU);\n"
610 << " uint32_t Bits = Features.getBits(SubTypeKV, SubTypeKVSize,\n"
616 << " uint64_t Bits = Features.getBits(SubTypeKV, SubTypeKVSize,\n"
611617 << " FeatureKV, FeatureKVSize);\n";
612618
613619 for (unsigned i = 0; i < Features.size(); i++) {