From ca26808da95ca9811550f2af51758612a515e5ef Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 5 Mar 2019 18:54:34 +0000 Subject: [PATCH] [Subtarget] Create a separate SubtargetSubtargetKV struct for ProcDesc to remove fields from the stack tables that aren't needed for CPUs The description for CPUs was just the CPU name wrapped with "Select the " and " processor". We can just do that directly in the help printer instead of making a separate version in the binary for each CPU. Also remove the Value field that isn't needed and was always 0. Differential Revision: https://reviews.llvm.org/D58938 llvm-svn: 355429 --- llvm/include/llvm/CodeGen/TargetSubtargetInfo.h | 3 ++- llvm/include/llvm/MC/MCSubtargetInfo.h | 22 ++++++++++++++++++++-- llvm/lib/CodeGen/TargetSubtargetInfo.cpp | 2 +- llvm/lib/MC/MCSubtargetInfo.cpp | 18 ++++++++++-------- llvm/utils/TableGen/SubtargetEmitter.cpp | 10 ++++------ 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/llvm/include/llvm/CodeGen/TargetSubtargetInfo.h b/llvm/include/llvm/CodeGen/TargetSubtargetInfo.h index bf0e9b2..eb811de 100644 --- a/llvm/include/llvm/CodeGen/TargetSubtargetInfo.h +++ b/llvm/include/llvm/CodeGen/TargetSubtargetInfo.h @@ -42,6 +42,7 @@ class RegisterBankInfo; class SDep; class SelectionDAGTargetInfo; struct SubtargetFeatureKV; +struct SubtargetSubTypeKV; struct SubtargetInfoKV; class SUnit; class TargetFrameLowering; @@ -62,7 +63,7 @@ class TargetSubtargetInfo : public MCSubtargetInfo { 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, diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h b/llvm/include/llvm/MC/MCSubtargetInfo.h index 4da1664..f784172 100644 --- a/llvm/include/llvm/MC/MCSubtargetInfo.h +++ b/llvm/include/llvm/MC/MCSubtargetInfo.h @@ -50,6 +50,24 @@ struct SubtargetFeatureKV { //===----------------------------------------------------------------------===// +/// 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 @@ class MCSubtargetInfo { 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 @@ public: 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, diff --git a/llvm/lib/CodeGen/TargetSubtargetInfo.cpp b/llvm/lib/CodeGen/TargetSubtargetInfo.cpp index 7b29b68..c0520a9 100644 --- a/llvm/lib/CodeGen/TargetSubtargetInfo.cpp +++ b/llvm/lib/CodeGen/TargetSubtargetInfo.cpp @@ -16,7 +16,7 @@ using namespace llvm; 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) diff --git a/llvm/lib/MC/MCSubtargetInfo.cpp b/llvm/lib/MC/MCSubtargetInfo.cpp index 5cb51ed..ca174c7 100644 --- a/llvm/lib/MC/MCSubtargetInfo.cpp +++ b/llvm/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 @@ -84,7 +84,8 @@ static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature, } /// 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)); @@ -92,7 +93,7 @@ static size_t getLongestEntryLength(ArrayRef Table) { } /// 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); @@ -101,7 +102,8 @@ static void Help(ArrayRef CPUTable, // 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. @@ -115,7 +117,7 @@ static void Help(ArrayRef CPUTable, } static FeatureBitset getFeatures(StringRef CPU, StringRef FS, - ArrayRef ProcDesc, + ArrayRef ProcDesc, ArrayRef ProcFeatures) { SubtargetFeatures Features(FS); @@ -135,7 +137,7 @@ static FeatureBitset getFeatures(StringRef CPU, StringRef FS, // 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) { @@ -173,7 +175,7 @@ void MCSubtargetInfo::setDefaultFeatures(StringRef CPU, StringRef FS) { 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) diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp index 950eea8..198e5b4 100644 --- a/llvm/utils/TableGen/SubtargetEmitter.cpp +++ b/llvm/utils/TableGen/SubtargetEmitter.cpp @@ -257,7 +257,7 @@ SubtargetEmitter::CPUKeyValues(raw_ostream &OS, // 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 @@ SubtargetEmitter::CPUKeyValues(raw_ostream &OS, 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 @@ void SubtargetEmitter::emitGenMCSubtargetInfo(raw_ostream &OS) { << "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 @@ void SubtargetEmitter::run(raw_ostream &OS) { 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"; -- 2.7.4