[llvm] r363464 - Add --print-supported-cpus flag for clang.
Ziang Wan via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 14 14:42:22 PDT 2019
Author: ziangwan725
Date: Fri Jun 14 14:42:21 2019
New Revision: 363464
URL: http://llvm.org/viewvc/llvm-project?rev=363464&view=rev
Log:
Add --print-supported-cpus flag for clang.
This patch allows clang users to print out a list of supported CPU models using
clang [--target=<target triple>] --print-supported-cpus
Then, users can select the CPU model to compile to using
clang --target=<triple> -mcpu=<model> a.c
It is a handy feature to help cross compilation.
Modified:
llvm/trunk/lib/MC/MCSubtargetInfo.cpp
Modified: llvm/trunk/lib/MC/MCSubtargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSubtargetInfo.cpp?rev=363464&r1=363463&r2=363464&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCSubtargetInfo.cpp (original)
+++ llvm/trunk/lib/MC/MCSubtargetInfo.cpp Fri Jun 14 14:42:21 2019
@@ -92,9 +92,16 @@ static size_t getLongestEntryLength(Arra
return MaxLen;
}
-/// Display help for feature choices.
+/// Display help for feature and mcpu choices.
static void Help(ArrayRef<SubtargetSubTypeKV> CPUTable,
ArrayRef<SubtargetFeatureKV> FeatTable) {
+ // the static variable ensures that the help information only gets
+ // printed once even though a target machine creates multiple subtargets
+ static bool PrintOnce = false;
+ if (PrintOnce) {
+ return;
+ }
+
// Determine the length of the longest CPU and Feature entries.
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
unsigned MaxFeatLen = getLongestEntryLength(FeatTable);
@@ -114,6 +121,30 @@ static void Help(ArrayRef<SubtargetSubTy
errs() << "Use +feature to enable a feature, or -feature to disable it.\n"
"For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n";
+
+ PrintOnce = true;
+}
+
+/// Display help for mcpu choices only
+static void cpuHelp(ArrayRef<SubtargetSubTypeKV> CPUTable) {
+ // the static variable ensures that the help information only gets
+ // printed once even though a target machine creates multiple subtargets
+ static bool PrintOnce = false;
+ if (PrintOnce) {
+ return;
+ }
+
+ // Print the CPU table.
+ errs() << "Available CPUs for this target:\n\n";
+ for (auto &CPU : CPUTable)
+ errs() << "\t" << CPU.Key << "\n";
+ errs() << '\n';
+
+ errs() << "Use -mcpu or -mtune to specify the target's processor.\n"
+ "For example, clang --target=aarch64-unknown-linux-gui "
+ "-mcpu=cortex-a35\n";
+
+ PrintOnce = true;
}
static FeatureBitset getFeatures(StringRef CPU, StringRef FS,
@@ -154,6 +185,8 @@ static FeatureBitset getFeatures(StringR
// Check for help
if (Feature == "+help")
Help(ProcDesc, ProcFeatures);
+ else if (Feature == "+cpuHelp")
+ cpuHelp(ProcDesc);
else
ApplyFeatureFlag(Bits, Feature, ProcFeatures);
}
More information about the llvm-commits
mailing list