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 /clang/tools/driver/cc1_main.cpp | |
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 'clang/tools/driver/cc1_main.cpp')
-rw-r--r-- | clang/tools/driver/cc1_main.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp index 2ed27c22708..01a42489333 100644 --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/tools/driver/cc1_main.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "clang/Basic/Stack.h" +#include "clang/Basic/TargetOptions.h" #include "clang/CodeGen/ObjectFilePCHContainerOperations.h" #include "clang/Config/config.h" #include "clang/Driver/DriverDiagnostic.h" @@ -36,10 +37,12 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Path.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/TimeProfiler.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetMachine.h" #include <cstdio> #ifdef CLANG_HAVE_RLIMITS @@ -166,6 +169,23 @@ static void ensureSufficientStack() { static void ensureSufficientStack() {} #endif +/// print supported cpus of the given target +int PrintSupportedCPUs(std::string TargetStr) { + std::string Error; + const llvm::Target *TheTarget = + llvm::TargetRegistry::lookupTarget(TargetStr, Error); + if (!TheTarget) { + llvm::errs() << Error; + return 1; + } + + // the target machine will handle the mcpu printing + llvm::TargetOptions Options; + std::unique_ptr<llvm::TargetMachine> TheTargetMachine( + TheTarget->createTargetMachine(TargetStr, "", "+cpuHelp", Options, None)); + return 0; +} + int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { ensureSufficientStack(); @@ -199,6 +219,11 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { if (Clang->getFrontendOpts().TimeTrace) llvm::timeTraceProfilerInitialize(); + // --print-supported-cpus takes priority over the actual compilation + if (Clang->getFrontendOpts().PrintSupportedCPUs) { + return PrintSupportedCPUs(Clang->getTargetOpts().Triple); + } + // Infer the builtin include path if unspecified. if (Clang->getHeaderSearchOpts().UseBuiltinIncludes && Clang->getHeaderSearchOpts().ResourceDir.empty()) |