Skip to content

Commit 46775c3

Browse files
committed
Add processor aliases back to -print-supported-cpus and -mcpu=help
They were accidentally dropped in #96249 rdar://140853882
1 parent fdb050a commit 46775c3

File tree

6 files changed

+101
-22
lines changed

6 files changed

+101
-22
lines changed

clang/test/Driver/print-supported-cpus.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// REQUIRES: x86-registered-target
44
// REQUIRES: arm-registered-target
5+
// REQUIRES: aarch64-registered-target
56

67
// RUN: %clang --target=x86_64-unknown-linux-gnu --print-supported-cpus 2>&1 | \
78
// RUN: FileCheck %s --check-prefix=CHECK-X86
@@ -25,3 +26,12 @@
2526
// CHECK-ARM: cortex-a73
2627
// CHECK-ARM: cortex-a75
2728
// CHECK-ARM: Use -mcpu or -mtune to specify the target's processor.
29+
30+
// RUN: %clang --target=arm64-apple-macosx --print-supported-cpus 2>&1 | \
31+
// RUN: FileCheck %s --check-prefix=CHECK-AARCH64 --implicit-check-not=apple-latest
32+
33+
// CHECK-AARCH64: Target: arm64-apple-macosx
34+
// CHECK-AARCH64: apple-m1
35+
// CHECK-AARCH64: apple-m2
36+
// CHECK-AARCH64: apple-m3
37+
// CHECK-AARCH64: Use -mcpu or -mtune to specify the target's processor.

llvm/include/llvm/CodeGen/TargetSubtargetInfo.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ class Triple;
6363
class TargetSubtargetInfo : public MCSubtargetInfo {
6464
protected: // Can only create subclasses...
6565
TargetSubtargetInfo(const Triple &TT, StringRef CPU, StringRef TuneCPU,
66-
StringRef FS, ArrayRef<SubtargetFeatureKV> PF,
66+
StringRef FS,
67+
ArrayRef<StringRef> PN,
68+
ArrayRef<SubtargetFeatureKV> PF,
6769
ArrayRef<SubtargetSubTypeKV> PD,
6870
const MCWriteProcResEntry *WPR,
6971
const MCWriteLatencyEntry *WL,

llvm/include/llvm/MC/MCSubtargetInfo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class MCSubtargetInfo {
7777
Triple TargetTriple;
7878
std::string CPU; // CPU being targeted.
7979
std::string TuneCPU; // CPU being tuned for.
80+
ArrayRef<StringRef> ProcNames; // Processor list, including aliases
8081
ArrayRef<SubtargetFeatureKV> ProcFeatures; // Processor feature list
8182
ArrayRef<SubtargetSubTypeKV> ProcDesc; // Processor descriptions
8283

@@ -95,7 +96,9 @@ class MCSubtargetInfo {
9596
public:
9697
MCSubtargetInfo(const MCSubtargetInfo &) = default;
9798
MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef TuneCPU,
98-
StringRef FS, ArrayRef<SubtargetFeatureKV> PF,
99+
StringRef FS,
100+
ArrayRef<StringRef> PN,
101+
ArrayRef<SubtargetFeatureKV> PF,
99102
ArrayRef<SubtargetSubTypeKV> PD,
100103
const MCWriteProcResEntry *WPR, const MCWriteLatencyEntry *WL,
101104
const MCReadAdvanceEntry *RA, const InstrStage *IS,

llvm/lib/CodeGen/TargetSubtargetInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ using namespace llvm;
1616

1717
TargetSubtargetInfo::TargetSubtargetInfo(
1818
const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS,
19+
ArrayRef<StringRef> PN,
1920
ArrayRef<SubtargetFeatureKV> PF, ArrayRef<SubtargetSubTypeKV> PD,
2021
const MCWriteProcResEntry *WPR, const MCWriteLatencyEntry *WL,
2122
const MCReadAdvanceEntry *RA, const InstrStage *IS, const unsigned *OC,
2223
const unsigned *FP)
23-
: MCSubtargetInfo(TT, CPU, TuneCPU, FS, PF, PD, WPR, WL, RA, IS, OC, FP) {}
24+
: MCSubtargetInfo(TT, CPU, TuneCPU, FS, PN, PF, PD, WPR, WL, RA, IS, OC, FP) {}
2425

2526
TargetSubtargetInfo::~TargetSubtargetInfo() = default;
2627

llvm/lib/MC/MCSubtargetInfo.cpp

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,22 @@ static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
8585
}
8686

8787
/// Return the length of the longest entry in the table.
88-
template <typename T>
89-
static size_t getLongestEntryLength(ArrayRef<T> Table) {
88+
static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {
9089
size_t MaxLen = 0;
9190
for (auto &I : Table)
9291
MaxLen = std::max(MaxLen, std::strlen(I.Key));
9392
return MaxLen;
9493
}
9594

95+
static size_t getLongestEntryLength(ArrayRef<StringRef> Table) {
96+
size_t MaxLen = 0;
97+
for (StringRef I : Table)
98+
MaxLen = std::max(MaxLen, I.size());
99+
return MaxLen;
100+
}
101+
96102
/// Display help for feature and mcpu choices.
97-
static void Help(ArrayRef<SubtargetSubTypeKV> CPUTable,
103+
static void Help(ArrayRef<StringRef> CPUNames,
98104
ArrayRef<SubtargetFeatureKV> FeatTable) {
99105
// the static variable ensures that the help information only gets
100106
// printed once even though a target machine creates multiple subtargets
@@ -104,14 +110,17 @@ static void Help(ArrayRef<SubtargetSubTypeKV> CPUTable,
104110
}
105111

106112
// Determine the length of the longest CPU and Feature entries.
107-
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
113+
unsigned MaxCPULen = getLongestEntryLength(CPUNames);
108114
unsigned MaxFeatLen = getLongestEntryLength(FeatTable);
109115

110116
// Print the CPU table.
111117
errs() << "Available CPUs for this target:\n\n";
112-
for (auto &CPU : CPUTable)
113-
errs() << format(" %-*s - Select the %s processor.\n", MaxCPULen, CPU.Key,
114-
CPU.Key);
118+
for (auto &CPUName : CPUNames) {
119+
if (CPUName == "apple-latest")
120+
continue;
121+
errs() << format(" %-*s - Select the %s processor.\n", MaxCPULen, CPUName.str().c_str(),
122+
CPUName.str().c_str());
123+
}
115124
errs() << '\n';
116125

117126
// Print the Feature table.
@@ -127,7 +136,7 @@ static void Help(ArrayRef<SubtargetSubTypeKV> CPUTable,
127136
}
128137

129138
/// Display help for mcpu choices only
130-
static void cpuHelp(ArrayRef<SubtargetSubTypeKV> CPUTable) {
139+
static void cpuHelp(ArrayRef<StringRef> CPUNames) {
131140
// the static variable ensures that the help information only gets
132141
// printed once even though a target machine creates multiple subtargets
133142
static bool PrintOnce = false;
@@ -137,8 +146,11 @@ static void cpuHelp(ArrayRef<SubtargetSubTypeKV> CPUTable) {
137146

138147
// Print the CPU table.
139148
errs() << "Available CPUs for this target:\n\n";
140-
for (auto &CPU : CPUTable)
141-
errs() << "\t" << CPU.Key << "\n";
149+
for (auto &CPU : CPUNames) {
150+
if (CPU == "apple-latest")
151+
continue;
152+
errs() << "\t" << CPU << "\n";
153+
}
142154
errs() << '\n';
143155

144156
errs() << "Use -mcpu or -mtune to specify the target's processor.\n"
@@ -148,7 +160,9 @@ static void cpuHelp(ArrayRef<SubtargetSubTypeKV> CPUTable) {
148160
PrintOnce = true;
149161
}
150162

151-
static FeatureBitset getFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS,
163+
static FeatureBitset getFeatures(MCSubtargetInfo &STI,
164+
StringRef CPU, StringRef TuneCPU, StringRef FS,
165+
ArrayRef<StringRef> ProcNames,
152166
ArrayRef<SubtargetSubTypeKV> ProcDesc,
153167
ArrayRef<SubtargetFeatureKV> ProcFeatures) {
154168
SubtargetFeatures Features(FS);
@@ -163,7 +177,7 @@ static FeatureBitset getFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS,
163177

164178
// Check if help is needed
165179
if (CPU == "help")
166-
Help(ProcDesc, ProcFeatures);
180+
Help(ProcNames, ProcFeatures);
167181

168182
// Find CPU entry if CPU name is specified.
169183
else if (!CPU.empty()) {
@@ -196,9 +210,9 @@ static FeatureBitset getFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS,
196210
for (const std::string &Feature : Features.getFeatures()) {
197211
// Check for help
198212
if (Feature == "+help")
199-
Help(ProcDesc, ProcFeatures);
213+
Help(ProcNames, ProcFeatures);
200214
else if (Feature == "+cpuhelp")
201-
cpuHelp(ProcDesc);
215+
cpuHelp(ProcNames);
202216
else
203217
ApplyFeatureFlag(Bits, Feature, ProcFeatures);
204218
}
@@ -208,7 +222,7 @@ static FeatureBitset getFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS,
208222

209223
void MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef TuneCPU,
210224
StringRef FS) {
211-
FeatureBits = getFeatures(CPU, TuneCPU, FS, ProcDesc, ProcFeatures);
225+
FeatureBits = getFeatures(*this, CPU, TuneCPU, FS, ProcNames, ProcDesc, ProcFeatures);
212226
FeatureString = std::string(FS);
213227

214228
if (!TuneCPU.empty())
@@ -219,20 +233,22 @@ void MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef TuneCPU,
219233

220234
void MCSubtargetInfo::setDefaultFeatures(StringRef CPU, StringRef TuneCPU,
221235
StringRef FS) {
222-
FeatureBits = getFeatures(CPU, TuneCPU, FS, ProcDesc, ProcFeatures);
236+
FeatureBits = getFeatures(*this, CPU, TuneCPU, FS, ProcNames, ProcDesc, ProcFeatures);
223237
FeatureString = std::string(FS);
224238
}
225239

226240
MCSubtargetInfo::MCSubtargetInfo(const Triple &TT, StringRef C, StringRef TC,
227-
StringRef FS, ArrayRef<SubtargetFeatureKV> PF,
241+
StringRef FS,
242+
ArrayRef<StringRef> PN,
243+
ArrayRef<SubtargetFeatureKV> PF,
228244
ArrayRef<SubtargetSubTypeKV> PD,
229245
const MCWriteProcResEntry *WPR,
230246
const MCWriteLatencyEntry *WL,
231247
const MCReadAdvanceEntry *RA,
232248
const InstrStage *IS, const unsigned *OC,
233249
const unsigned *FP)
234250
: TargetTriple(TT), CPU(std::string(C)), TuneCPU(std::string(TC)),
235-
ProcFeatures(PF), ProcDesc(PD), WriteProcResTable(WPR),
251+
ProcNames(PN), ProcFeatures(PF), ProcDesc(PD), WriteProcResTable(WPR),
236252
WriteLatencyTable(WL), ReadAdvanceTable(RA), Stages(IS),
237253
OperandCycles(OC), ForwardingPaths(FP) {
238254
InitMCProcessorInfo(CPU, TuneCPU, FS);

llvm/utils/TableGen/SubtargetEmitter.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/SmallPtrSet.h"
2121
#include "llvm/ADT/StringExtras.h"
2222
#include "llvm/ADT/StringMap.h"
23+
#include "llvm/ADT/StringSwitch.h"
2324
#include "llvm/ADT/StringRef.h"
2425
#include "llvm/MC/MCInstrItineraries.h"
2526
#include "llvm/MC/MCSchedule.h"
@@ -91,6 +92,7 @@ class SubtargetEmitter {
9192
void emitSubtargetInfoMacroCalls(raw_ostream &OS);
9293
unsigned featureKeyValues(raw_ostream &OS, const FeatureMapTy &FeatureMap);
9394
unsigned cpuKeyValues(raw_ostream &OS, const FeatureMapTy &FeatureMap);
95+
unsigned cpuNames(raw_ostream &OS);
9496
void formItineraryStageString(const std::string &Names,
9597
const Record *ItinData, std::string &ItinString,
9698
unsigned &NStages);
@@ -297,6 +299,39 @@ unsigned SubtargetEmitter::featureKeyValues(raw_ostream &OS,
297299
return FeatureList.size();
298300
}
299301

302+
unsigned SubtargetEmitter::cpuNames(raw_ostream &OS) {
303+
// Begin processor name table.
304+
OS << "// Sorted array of names of CPU subtypes, including aliases.\n"
305+
<< "extern const llvm::StringRef " << Target << "Names[] = {\n";
306+
307+
std::vector<const Record *> ProcessorList =
308+
Records.getAllDerivedDefinitions("Processor");
309+
310+
std::vector<const Record *> ProcessorAliasList =
311+
Records.getAllDerivedDefinitionsIfDefined("ProcessorAlias");
312+
313+
SmallVector<StringRef> Names;
314+
Names.reserve(ProcessorList.size() + ProcessorAliasList.size());
315+
316+
for (const Record *Processor : ProcessorList) {
317+
StringRef Name = Processor->getValueAsString("Name");
318+
Names.push_back(Name);
319+
}
320+
321+
for (const Record *Rec : ProcessorAliasList) {
322+
auto Name = Rec->getValueAsString("Name");
323+
Names.push_back(Name);
324+
}
325+
326+
llvm::sort(Names);
327+
llvm::interleave(Names, OS, [&](StringRef Name) { OS << '"' << Name << '"'; }, ",\n");
328+
329+
// End processor name table.
330+
OS << "};\n";
331+
332+
return Names.size();
333+
}
334+
300335
//
301336
// CPUKeyValues - Emit data of all the subtarget processors. Used by command
302337
// line.
@@ -1926,13 +1961,14 @@ void SubtargetEmitter::emitGenMCSubtargetInfo(raw_ostream &OS) {
19261961
<< "GenMCSubtargetInfo : public MCSubtargetInfo {\n";
19271962
OS << " " << Target << "GenMCSubtargetInfo(const Triple &TT,\n"
19281963
<< " StringRef CPU, StringRef TuneCPU, StringRef FS,\n"
1964+
<< " ArrayRef<StringRef> PN,\n"
19291965
<< " ArrayRef<SubtargetFeatureKV> PF,\n"
19301966
<< " ArrayRef<SubtargetSubTypeKV> PD,\n"
19311967
<< " const MCWriteProcResEntry *WPR,\n"
19321968
<< " const MCWriteLatencyEntry *WL,\n"
19331969
<< " const MCReadAdvanceEntry *RA, const InstrStage *IS,\n"
19341970
<< " const unsigned *OC, const unsigned *FP) :\n"
1935-
<< " MCSubtargetInfo(TT, CPU, TuneCPU, FS, PF, PD,\n"
1971+
<< " MCSubtargetInfo(TT, CPU, TuneCPU, FS, PN, PF, PD,\n"
19361972
<< " WPR, WL, RA, IS, OC, FP) { }\n\n"
19371973
<< " unsigned resolveVariantSchedClass(unsigned SchedClass,\n"
19381974
<< " const MCInst *MI, const MCInstrInfo *MCII,\n"
@@ -2001,6 +2037,8 @@ void SubtargetEmitter::run(raw_ostream &OS) {
20012037
OS << "\n";
20022038
unsigned NumProcs = cpuKeyValues(OS, FeatureMap);
20032039
OS << "\n";
2040+
unsigned NumNames = cpuNames(OS);
2041+
OS << "\n";
20042042

20052043
// MCInstrInfo initialization routine.
20062044
emitGenMCSubtargetInfo(OS);
@@ -2013,6 +2051,10 @@ void SubtargetEmitter::run(raw_ostream &OS) {
20132051
<< " TuneCPU = AArch64::resolveCPUAlias(TuneCPU);\n";
20142052
OS << " return new " << Target
20152053
<< "GenMCSubtargetInfo(TT, CPU, TuneCPU, FS, ";
2054+
if (NumNames)
2055+
OS << Target << "Names, ";
2056+
else
2057+
OS << "{}, ";
20162058
if (NumFeatures)
20172059
OS << Target << "FeatureKV, ";
20182060
else
@@ -2096,6 +2138,7 @@ void SubtargetEmitter::run(raw_ostream &OS) {
20962138

20972139
OS << "#include \"llvm/CodeGen/TargetSchedule.h\"\n\n";
20982140
OS << "namespace llvm {\n";
2141+
OS << "extern const llvm::StringRef " << Target << "Names[];\n";
20992142
OS << "extern const llvm::SubtargetFeatureKV " << Target << "FeatureKV[];\n";
21002143
OS << "extern const llvm::SubtargetSubTypeKV " << Target << "SubTypeKV[];\n";
21012144
OS << "extern const llvm::MCWriteProcResEntry " << Target
@@ -2119,6 +2162,10 @@ void SubtargetEmitter::run(raw_ostream &OS) {
21192162
<< " AArch64::resolveCPUAlias(TuneCPU), FS, ";
21202163
else
21212164
OS << " : TargetSubtargetInfo(TT, CPU, TuneCPU, FS, ";
2165+
if (NumNames)
2166+
OS << "ArrayRef(" << Target << "Names, " << NumNames << "), ";
2167+
else
2168+
OS << "{}, ";
21222169
if (NumFeatures)
21232170
OS << "ArrayRef(" << Target << "FeatureKV, " << NumFeatures << "), ";
21242171
else

0 commit comments

Comments
 (0)