diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.h b/clang/lib/Driver/ToolChains/Arch/Sparc.h --- a/clang/lib/Driver/ToolChains/Arch/Sparc.h +++ b/clang/lib/Driver/ToolChains/Arch/Sparc.h @@ -28,6 +28,9 @@ FloatABI getSparcFloatABI(const Driver &D, const llvm::opt::ArgList &Args); +std::string getSparcTargetCPU(const Driver &D, const llvm::opt::ArgList &Args, + const llvm::Triple &Triple); + void getSparcTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args, std::vector &Features); const char *getSparcAsmModeForCPU(llvm::StringRef Name, diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp --- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp +++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp @@ -12,6 +12,7 @@ #include "clang/Driver/Options.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Option/ArgList.h" +#include "llvm/Support/Host.h" using namespace clang::driver; using namespace clang::driver::tools; @@ -113,6 +114,30 @@ return ABI; } +std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args, + const llvm::Triple &Triple) { + if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) { + D.Diag(diag::err_drv_unsupported_opt_for_target) + << A->getSpelling() << Triple.getTriple(); + return ""; + } + + if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) { + StringRef CPUName = A->getValue(); + if (CPUName == "native") { + std::string CPU = std::string(llvm::sys::getHostCPUName()); + if (!CPU.empty() && CPU != "generic") + return CPU; + return ""; + } + return std::string(CPUName); + } + + if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris()) + return "v9"; + return ""; +} + void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args, std::vector &Features) { sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2213,6 +2213,18 @@ CmdArgs.push_back("-mfloat-abi"); CmdArgs.push_back("hard"); } + + if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) { + StringRef Name = A->getValue(); + std::string TuneCPU; + if (Name == "native") + TuneCPU = std::string(llvm::sys::getHostCPUName()); + else + TuneCPU = std::string(Name); + + CmdArgs.push_back("-tune-cpu"); + CmdArgs.push_back(Args.MakeArgString(TuneCPU)); + } } void Clang::AddSystemZTargetArgs(const ArgList &Args, diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -12,6 +12,7 @@ #include "Arch/M68k.h" #include "Arch/Mips.h" #include "Arch/PPC.h" +#include "Arch/Sparc.h" #include "Arch/SystemZ.h" #include "Arch/VE.h" #include "Arch/X86.h" @@ -431,15 +432,15 @@ case llvm::Triple::bpfel: case llvm::Triple::bpfeb: - case llvm::Triple::sparc: - case llvm::Triple::sparcel: - case llvm::Triple::sparcv9: if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) return A->getValue(); - if (T.getArch() == llvm::Triple::sparc && T.isOSSolaris()) - return "v9"; return ""; + case llvm::Triple::sparc: + case llvm::Triple::sparcel: + case llvm::Triple::sparcv9: + return sparc::getSparcTargetCPU(D, Args, T); + case llvm::Triple::x86: case llvm::Triple::x86_64: return x86::getX86TargetCPU(D, Args, T); diff --git a/clang/test/Driver/sparc-march.c b/clang/test/Driver/sparc-march.c new file mode 100644 --- /dev/null +++ b/clang/test/Driver/sparc-march.c @@ -0,0 +1,4 @@ +// RUN: %clang -target sparcv9 -march=v9 -### -c %s 2>&1 | FileCheck %s +// RUN: %clang -target sparc64 -march=v9 -### -c %s 2>&1 | FileCheck %s +// RUN: %clang -target sparc -march=v9 -### -c %s 2>&1 | FileCheck %s +// CHECK: error: unsupported option '-march=' for target diff --git a/clang/test/Driver/sparc-mcpu.c b/clang/test/Driver/sparc-mcpu.c new file mode 100644 --- /dev/null +++ b/clang/test/Driver/sparc-mcpu.c @@ -0,0 +1,21 @@ +// RUN: %clang -target sparcv9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9 %s +// SPARCV9: "-cc1"{{.*}} "-triple" "sparcv9" + +// RUN: %clang -target sparc64 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC64 %s +// SPARC64: "-cc1"{{.*}} "-triple" "sparc64" + +// RUN: %clang -target sparcv9 -mcpu=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_V9 %s +// SPARCV9_V9: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-target-cpu" "v9" + +// RUN: %clang -target sparcv9 -mcpu=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_US %s +// SPARCV9_US: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-target-cpu" "ultrasparc" + +// RUN: %clang -target sparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC %s +// SPARC: "-cc1"{{.*}} "-triple" "sparc" + +// RUN: %clang -target sparc -mcpu=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_V9 %s +// SPARC_V9: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-target-cpu" "v9" + +// RUN: %clang -target sparc -mcpu=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_US %s +// SPARC_US: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-target-cpu" "ultrasparc" + diff --git a/clang/test/Driver/sparc-mtune.c b/clang/test/Driver/sparc-mtune.c new file mode 100644 --- /dev/null +++ b/clang/test/Driver/sparc-mtune.c @@ -0,0 +1,21 @@ +// RUN: %clang -target sparcv9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9 %s +// SPARCV9: "-cc1"{{.*}} "-triple" "sparcv9" + +// RUN: %clang -target sparc64 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC64 %s +// SPARC64: "-cc1"{{.*}} "-triple" "sparc64" + +// RUN: %clang -target sparcv9 -mtune=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_V9 %s +// SPARCV9_V9: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-tune-cpu" "v9" + +// RUN: %clang -target sparcv9 -mtune=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARCV9_US %s +// SPARCV9_US: "-cc1"{{.*}} "-triple" "sparcv9"{{.*}} "-tune-cpu" "ultrasparc" + +// RUN: %clang -target sparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC %s +// SPARC: "-cc1"{{.*}} "-triple" "sparc" + +// RUN: %clang -target sparc -mtune=v9 -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_V9 %s +// SPARC_V9: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-tune-cpu" "v9" + +// RUN: %clang -target sparc -mtune=ultrasparc -### -c %s 2>&1 | FileCheck -check-prefix=SPARC_US %s +// SPARC_US: "-cc1"{{.*}} "-triple" "sparc"{{.*}} "-tune-cpu" "ultrasparc" +