From 5c92b9ab4e4dce3233ea3e400a02c443f9afd372 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Fri, 19 Jul 2013 16:51:51 +0000 Subject: [PATCH] [SystemZ] Add -march= command-line option git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186694 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 11 +++++++++++ lib/Driver/Tools.cpp | 23 +++++++++++++++++++++-- lib/Driver/Tools.h | 2 ++ test/Driver/linux-as.c | 11 ++++++++++- test/Driver/systemz-march.c | 13 +++++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 test/Driver/systemz-march.c diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index d2781f56d5..c236924c2d 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -4396,6 +4396,17 @@ namespace { virtual BuiltinVaListKind getBuiltinVaListKind() const { return TargetInfo::SystemZBuiltinVaList; } + virtual bool setCPU(const std::string &Name) { + bool CPUKnown = llvm::StringSwitch(Name) + .Case("z10", true) + .Case("z196", true) + .Case("zEC12", true) + .Default(false); + + // No need to store the CPU yet. There aren't any CPU-specific + // macros to define. + return CPUKnown; + } }; const char *const SystemZTargetInfo::GCCRegNames[] = { diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 8df0578e7d..c2a0205b72 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1217,6 +1217,19 @@ void Clang::AddSparcTargetArgs(const ArgList &Args, } } +static const char *getSystemZTargetCPU(const ArgList &Args) { + if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) + return A->getValue(); + return "z10"; +} + +void Clang::AddSystemZTargetArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { + const char *CPUName = getSystemZTargetCPU(Args); + CmdArgs.push_back("-target-cpu"); + CmdArgs.push_back(CPUName); +} + static const char *getX86TargetCPU(const ArgList &Args, const llvm::Triple &Triple) { if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { @@ -2454,6 +2467,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, AddSparcTargetArgs(Args, CmdArgs); break; + case llvm::Triple::systemz: + AddSystemZTargetArgs(Args, CmdArgs); + break; + case llvm::Triple::x86: case llvm::Triple::x86_64: AddX86TargetArgs(Args, CmdArgs); @@ -5926,8 +5943,10 @@ void gnutools::Assemble::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-KPIC"); } } else if (getToolChain().getArch() == llvm::Triple::systemz) { - // At the moment we always produce z10 code. - CmdArgs.push_back("-march=z10"); + // Always pass an -march option, since our default of z10 is later + // than the GNU assembler's default. + StringRef CPUName = getSystemZTargetCPU(Args); + CmdArgs.push_back(Args.MakeArgString("-march=" + CPUName)); } Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, diff --git a/lib/Driver/Tools.h b/lib/Driver/Tools.h index cc229af44e..1dd4d5edfe 100644 --- a/lib/Driver/Tools.h +++ b/lib/Driver/Tools.h @@ -59,6 +59,8 @@ using llvm::opt::ArgStringList; llvm::opt::ArgStringList &CmdArgs) const; void AddSparcTargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; + void AddSystemZTargetArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const; void AddX86TargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; void AddHexagonTargetArgs(const llvm::opt::ArgList &Args, diff --git a/test/Driver/linux-as.c b/test/Driver/linux-as.c index b3265da234..11bf0caee1 100644 --- a/test/Driver/linux-as.c +++ b/test/Driver/linux-as.c @@ -1,4 +1,4 @@ -// Check passing options to the assembler for ARM targets. +// Check passing options to the assembler for various linux targets. // // RUN: %clang -target arm-linux -### \ // RUN: -no-integrated-as -c %s 2>&1 \ @@ -54,3 +54,12 @@ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=PPC-NO-MCPU %s // CHECK-PPC-NO-MCPU-NOT: as{{.*}} "-mcpu=invalid-cpu" +// +// RUN: %clang -target s390x-linux -### -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=Z-DEFAULT-ARCH %s +// CHECK-Z-DEFAULT-ARCH: as{{.*}} "-march=z10" +// +// RUN: %clang -target s390x-linux -march=z196 -### \ +// RUN: -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=Z-ARCH-Z196 %s +// CHECK-Z-ARCH-Z196: as{{.*}} "-march=z196" diff --git a/test/Driver/systemz-march.c b/test/Driver/systemz-march.c new file mode 100644 index 0000000000..ebe6e07875 --- /dev/null +++ b/test/Driver/systemz-march.c @@ -0,0 +1,13 @@ +// Check that -march works for all supported targets. + +// RUN: not %clang -target s390x -S -emit-llvm -march=z9 %s -o - 2>&1 | FileCheck --check-prefix=CHECK-Z9 %s +// RUN: %clang -target s390x -S -emit-llvm -march=z10 %s +// RUN: %clang -target s390x -S -emit-llvm -march=z196 %s +// RUN: %clang -target s390x -S -emit-llvm -march=zEC12 %s + +// CHECK-Z9: error: unknown target CPU 'z9' +// CHECK-Z10: "-target-cpu" "z10" +// CHECK-Z196: "-target-cpu" "z196" +// CHECK-ZEC12: "-target-cpu" "zEC12" + +int x; -- 2.50.1