From cb6a1c44adef9ad79afe4089faf42e31186ed286 Mon Sep 17 00:00:00 2001 From: Ziang Wan Date: Fri, 14 Jun 2019 21:42:21 +0000 Subject: [PATCH] Add --print-supported-cpus flag for clang. This patch allows clang users to print out a list of supported CPU models using clang [--target=] --print-supported-cpus Then, users can select the CPU model to compile to using clang --target= -mcpu= a.c It is a handy feature to help cross compilation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363464 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCSubtargetInfo.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/MC/MCSubtargetInfo.cpp b/lib/MC/MCSubtargetInfo.cpp index 9b73800978c..9b0272cab0b 100644 --- a/lib/MC/MCSubtargetInfo.cpp +++ b/lib/MC/MCSubtargetInfo.cpp @@ -92,9 +92,16 @@ static size_t getLongestEntryLength(ArrayRef Table) { return MaxLen; } -/// Display help for feature choices. +/// Display help for feature and mcpu choices. static void Help(ArrayRef CPUTable, ArrayRef 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 CPUTable, 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 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(StringRef CPU, StringRef FS, // Check for help if (Feature == "+help") Help(ProcDesc, ProcFeatures); + else if (Feature == "+cpuHelp") + cpuHelp(ProcDesc); else ApplyFeatureFlag(Bits, Feature, ProcFeatures); } -- 2.40.0