diff options
| author | Ziang Wan <ziangw2@illinois.edu> | 2019-06-14 21:42:21 +0000 | 
|---|---|---|
| committer | Ziang Wan <ziangw2@illinois.edu> | 2019-06-14 21:42:21 +0000 | 
| commit | af857b93df36a983a27a82455c0dea39f53da5b1 (patch) | |
| tree | 49e18150fe961decbffbd73a7951e2a415250e3a /llvm | |
| parent | 5501dda2479580ae84291d0237e794feeb38a8d9 (diff) | |
| download | bcm5719-llvm-af857b93df36a983a27a82455c0dea39f53da5b1.tar.gz bcm5719-llvm-af857b93df36a983a27a82455c0dea39f53da5b1.zip  | |
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.
llvm-svn: 363464
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/MC/MCSubtargetInfo.cpp | 35 | 
1 files changed, 34 insertions, 1 deletions
diff --git a/llvm/lib/MC/MCSubtargetInfo.cpp b/llvm/lib/MC/MCSubtargetInfo.cpp index 9b73800978c..9b0272cab0b 100644 --- a/llvm/lib/MC/MCSubtargetInfo.cpp +++ b/llvm/lib/MC/MCSubtargetInfo.cpp @@ -92,9 +92,16 @@ static size_t getLongestEntryLength(ArrayRef<T> Table) {    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<SubtargetSubTypeKV> 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<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(StringRef CPU, StringRef FS,      // Check for help      if (Feature == "+help")        Help(ProcDesc, ProcFeatures); +    else if (Feature == "+cpuHelp") +      cpuHelp(ProcDesc);      else        ApplyFeatureFlag(Bits, Feature, ProcFeatures);    }  | 

