Generate code for the given target
+.. option:: --print-supported-cpus
+
+Print supported cpu models for the given target
+
.. option:: -time
Time individual commands
When building for iPhone OS, specify the minimum version supported by your
application.
+.. option:: --print-supported-cpus
+
+ Print out a list of supported processors for the given target (specified
+ through --target=<architecture> or -arch <architecture>). If no target is
+ specified, the system default target will be used.
+
.. option:: -march=<cpu>
Specify that Clang should generate code for a specific processor family
def s : Flag<["-"], "s">, Group<Link_Group>;
def target : Joined<["--"], "target=">, Flags<[DriverOption, CoreOption]>,
HelpText<"Generate code for the given target">;
+def _print_supported_cpus : Flag<["-", "--"], "print-supported-cpus">,
+ Group<CompileOnly_Group>, Flags<[CC1Option, CoreOption]>,
+ HelpText<"Print supported cpu models for the given target (if target is not specified,"
+ " it will print the supported cpus for the default target)">;
def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[DriverOption]>,
HelpText<"Use the gcc toolchain at the given directory">;
def time : Flag<["-"], "time">,
/// Show timers for individual actions.
unsigned ShowTimers : 1;
+ /// print the supported cpus for the current target
+ unsigned PrintSupportedCPUs : 1;
+
/// Output time trace profile.
unsigned TimeTrace : 1;
}
if (C.getArgs().hasArg(options::OPT_v) ||
- C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
+ C.getArgs().hasArg(options::OPT__HASH_HASH_HASH) ||
+ C.getArgs().hasArg(options::OPT__print_supported_cpus)) {
PrintVersion(C, llvm::errs());
SuppressMissingInputWarning = true;
}
Args.ClaimAllArgs(options::OPT_cl_compile_Group);
}
+ // If the use specify --print-supported-cpus, clang will only print out
+ // supported cpu names without doing compilation.
+ if (Arg *A = Args.getLastArg(options::OPT__print_supported_cpus)) {
+ Actions.clear();
+ // the compilation now has only two phases: Input and Compile
+ // use the --prints-supported-cpus flag as the dummy input to cc1
+ Action *InputAc = C.MakeAction<InputAction>(*A, types::TY_C);
+ Actions.push_back(
+ C.MakeAction<PrecompileJobAction>(InputAc, types::TY_Nothing));
+ }
+
// Claim ignored clang-cl options.
Args.ClaimAllArgs(options::OPT_cl_ignored_Group);
Opts.ShowHelp = Args.hasArg(OPT_help);
Opts.ShowStats = Args.hasArg(OPT_print_stats);
Opts.ShowTimers = Args.hasArg(OPT_ftime_report);
+ Opts.PrintSupportedCPUs = Args.hasArg(OPT__print_supported_cpus);
Opts.TimeTrace = Args.hasArg(OPT_ftime_trace);
Opts.ShowVersion = Args.hasArg(OPT_version);
Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge);
--- /dev/null
+// Test that the --print-supported-cpus flag works
+
+// RUN: %clang --target=x86_64-unknown-linux-gnu \
+// RUN: --print-supported-cpus 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CHECK-X86
+// CHECK-X86: Target: x86_64-unknown-linux-gnu
+// CHECK-X86: corei7
+// CHECK-X86: Use -mcpu or -mtune to specify the target's processor.
+
+// RUN: %clang --target=arm-unknown-linux-android \
+// RUN: --print-supported-cpus 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CHECK-ARM
+// CHECK-ARM: Target: arm-unknown-linux-android
+// CHECK-ARM: cortex-a73
+// CHECK-ARM: cortex-a75
+// CHECK-ARM: Use -mcpu or -mtune to specify the target's processor.
//===----------------------------------------------------------------------===//
#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"
#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
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();
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())