Index: include/llvm/CodeGen/TargetSubtargetInfo.h =================================================================== --- include/llvm/CodeGen/TargetSubtargetInfo.h +++ include/llvm/CodeGen/TargetSubtargetInfo.h @@ -42,6 +42,7 @@ class SDep; class SelectionDAGTargetInfo; struct SubtargetFeatureKV; +struct SubtargetSubTypeKV; struct SubtargetInfoKV; class SUnit; class TargetFrameLowering; @@ -62,7 +63,7 @@ protected: // Can only create subclasses... TargetSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS, ArrayRef PF, - ArrayRef PD, + ArrayRef PD, const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR, const MCWriteLatencyEntry *WL, Index: include/llvm/MC/MCSubtargetInfo.h =================================================================== --- include/llvm/MC/MCSubtargetInfo.h +++ include/llvm/MC/MCSubtargetInfo.h @@ -50,6 +50,24 @@ //===----------------------------------------------------------------------===// +/// Used to provide key value pairs for feature and CPU bit flags. +struct SubtargetSubTypeKV { + const char *Key; ///< K-V key string + FeatureBitArray Implies; ///< K-V bit mask + + /// Compare routine for std::lower_bound + bool operator<(StringRef S) const { + return StringRef(Key) < S; + } + + /// Compare routine for std::is_sorted. + bool operator<(const SubtargetSubTypeKV &Other) const { + return StringRef(Key) < StringRef(Other.Key); + } +}; + +//===----------------------------------------------------------------------===// + /// Used to provide key value pairs for CPU and arbitrary pointers. struct SubtargetInfoKV { const char *Key; ///< K-V key string @@ -74,7 +92,7 @@ Triple TargetTriple; std::string CPU; // CPU being targeted. ArrayRef ProcFeatures; // Processor feature list - ArrayRef ProcDesc; // Processor descriptions + ArrayRef ProcDesc; // Processor descriptions // Scheduler machine model const SubtargetInfoKV *ProcSchedModels; @@ -92,7 +110,7 @@ MCSubtargetInfo(const MCSubtargetInfo &) = default; MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS, ArrayRef PF, - ArrayRef PD, + ArrayRef PD, const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR, const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA, const InstrStage *IS, Index: lib/CodeGen/TargetSubtargetInfo.cpp =================================================================== --- lib/CodeGen/TargetSubtargetInfo.cpp +++ lib/CodeGen/TargetSubtargetInfo.cpp @@ -16,7 +16,7 @@ TargetSubtargetInfo::TargetSubtargetInfo( const Triple &TT, StringRef CPU, StringRef FS, - ArrayRef PF, ArrayRef PD, + ArrayRef PF, ArrayRef PD, const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR, const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA, const InstrStage *IS, const unsigned *OC, const unsigned *FP) Index: lib/MC/MCSubtargetInfo.cpp =================================================================== --- lib/MC/MCSubtargetInfo.cpp +++ lib/MC/MCSubtargetInfo.cpp @@ -21,8 +21,8 @@ using namespace llvm; /// Find KV in array using binary search. -static const SubtargetFeatureKV *Find(StringRef S, - ArrayRef A) { +template +static const T *Find(StringRef S, ArrayRef A) { // Binary search the array auto F = std::lower_bound(A.begin(), A.end(), S); // If not found then return NULL @@ -83,7 +83,8 @@ } /// Return the length of the longest entry in the table. -static size_t getLongestEntryLength(ArrayRef Table) { +template +static size_t getLongestEntryLength(ArrayRef Table) { size_t MaxLen = 0; for (auto &I : Table) MaxLen = std::max(MaxLen, std::strlen(I.Key)); @@ -91,7 +92,7 @@ } /// Display help for feature choices. -static void Help(ArrayRef CPUTable, +static void Help(ArrayRef CPUTable, ArrayRef FeatTable) { // Determine the length of the longest CPU and Feature entries. unsigned MaxCPULen = getLongestEntryLength(CPUTable); @@ -100,7 +101,8 @@ // Print the CPU table. errs() << "Available CPUs for this target:\n\n"; for (auto &CPU : CPUTable) - errs() << format(" %-*s - %s.\n", MaxCPULen, CPU.Key, CPU.Desc); + errs() << format(" %-*s - Select the %s processor.\n", MaxCPULen, CPU.Key, + CPU.Key); errs() << '\n'; // Print the Feature table. @@ -114,7 +116,7 @@ } static FeatureBitset getFeatures(StringRef CPU, StringRef FS, - ArrayRef ProcDesc, + ArrayRef ProcDesc, ArrayRef ProcFeatures) { SubtargetFeatures Features(FS); @@ -134,7 +136,7 @@ // Find CPU entry if CPU name is specified. else if (!CPU.empty()) { - const SubtargetFeatureKV *CPUEntry = Find(CPU, ProcDesc); + const SubtargetSubTypeKV *CPUEntry = Find(CPU, ProcDesc); // If there is a match if (CPUEntry) { @@ -172,7 +174,7 @@ MCSubtargetInfo::MCSubtargetInfo( const Triple &TT, StringRef C, StringRef FS, - ArrayRef PF, ArrayRef PD, + ArrayRef PF, ArrayRef PD, const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR, const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA, const InstrStage *IS, const unsigned *OC, const unsigned *FP) Index: utils/TableGen/SubtargetEmitter.cpp =================================================================== --- utils/TableGen/SubtargetEmitter.cpp +++ utils/TableGen/SubtargetEmitter.cpp @@ -257,7 +257,7 @@ // Begin processor table OS << "// Sorted (by key) array of values for CPU subtype.\n" - << "extern const llvm::SubtargetFeatureKV " << Target + << "extern const llvm::SubtargetSubTypeKV " << Target << "SubTypeKV[] = {\n"; // For each processor @@ -266,10 +266,8 @@ RecVec FeatureList = Processor->getValueAsListOfDefs("Features"); // Emit as { "cpu", "description", 0, { f1 , f2 , ... fn } }, - // The 0 is for the feature id which isn't used for CPUs. OS << " { " - << "\"" << Name << "\", " - << "\"Select the " << Name << " processor\", 0, "; + << "\"" << Name << "\", "; printFeatureMask(OS, FeatureList, FeatureMap); @@ -1760,7 +1758,7 @@ << "GenMCSubtargetInfo : public MCSubtargetInfo {\n"; OS << " " << Target << "GenMCSubtargetInfo(const Triple &TT, \n" << " StringRef CPU, StringRef FS, ArrayRef PF,\n" - << " ArrayRef PD,\n" + << " ArrayRef PD,\n" << " const SubtargetInfoKV *ProcSched,\n" << " const MCWriteProcResEntry *WPR,\n" << " const MCWriteLatencyEntry *WL,\n" @@ -1917,7 +1915,7 @@ OS << "#include \"llvm/CodeGen/TargetSchedule.h\"\n\n"; OS << "namespace llvm {\n"; OS << "extern const llvm::SubtargetFeatureKV " << Target << "FeatureKV[];\n"; - OS << "extern const llvm::SubtargetFeatureKV " << Target << "SubTypeKV[];\n"; + OS << "extern const llvm::SubtargetSubTypeKV " << Target << "SubTypeKV[];\n"; OS << "extern const llvm::SubtargetInfoKV " << Target << "ProcSchedKV[];\n"; OS << "extern const llvm::MCWriteProcResEntry " << Target << "WriteProcResTable[];\n";