From: Marcin Koscielnicki Date: Wed, 4 May 2016 23:37:40 +0000 (+0000) Subject: [SystemZ] Add -mbackchain option. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49edd29c346fff43705460794a3ea6d4c68b955e;p=clang [SystemZ] Add -mbackchain option. This option, like the corresponding gcc option, is SystemZ-specific and enables storing frame backchain links, as specified in the ABI. Differential Revision: http://reviews.llvm.org/D19891 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@268575 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 150a35caa5..3cc7f205ae 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1524,6 +1524,10 @@ def fno_zvector : Flag<["-"], "fno-zvector">, Group, def mzvector : Flag<["-"], "mzvector">, Alias; def mno_zvector : Flag<["-"], "mno-zvector">, Alias; +def mbackchain : Flag<["-"], "mbackchain">, Group, Flags<[DriverOption,CC1Option]>, + HelpText<"Link stack frames through backchain on System Z">; +def mno_backchain : Flag<["-"], "mno-backchain">, Group, Flags<[DriverOption,CC1Option]>; + def mno_warn_nonportable_cfstrings : Flag<["-"], "mno-warn-nonportable-cfstrings">, Group; def mno_omit_leaf_frame_pointer : Flag<["-"], "mno-omit-leaf-frame-pointer">, Group; def momit_leaf_frame_pointer : Flag<["-"], "momit-leaf-frame-pointer">, Group, diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 49b306fd77..6ef55b0bb7 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -34,6 +34,7 @@ CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm. CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) operator new CODEGENOPT(Autolink , 1, 1) ///< -fno-autolink CODEGENOPT(ObjCAutoRefCountExceptions , 1, 0) ///< Whether ARC should be EH-safe. +CODEGENOPT(Backchain , 1, 0) ///< -mbackchain CODEGENOPT(CoverageExtraChecksum, 1, 0) ///< Whether we need a second checksum for functions in GCNO files. CODEGENOPT(CoverageNoFunctionNamesInData, 1, 0) ///< Do not include function names in GCDA files. CODEGENOPT(CoverageExitBlockBeforeBody, 1, 0) ///< Whether to emit the exit block before the body blocks in GCNO files. diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 50ea7f7cc3..8a26db2116 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -1714,6 +1714,8 @@ void CodeGenModule::ConstructAttributeList( if (CodeGenOpts.StackRealignment) FuncAttrs.addAttribute("stackrealign"); + if (CodeGenOpts.Backchain) + FuncAttrs.addAttribute("backchain"); // Add target-cpu and target-features attributes to functions. If // we have a decl for the function and it has a target attribute then diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 1cc1369f33..c688763e69 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1655,6 +1655,12 @@ void Clang::AddSparcTargetArgs(const ArgList &Args, } } +void Clang::AddSystemZTargetArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { + if (Args.hasFlag(options::OPT_mbackchain, options::OPT_mno_backchain, false)) + CmdArgs.push_back("-mbackchain"); +} + static const char *getSystemZTargetCPU(const ArgList &Args) { if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) return A->getValue(); @@ -4241,6 +4247,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); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 2091ec4af3..0b154b6743 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -782,6 +782,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.CudaGpuBinaryFileNames = Args.getAllArgValues(OPT_fcuda_include_gpubinary); + Opts.Backchain = Args.hasArg(OPT_mbackchain); + return Success; } diff --git a/test/CodeGen/mbackchain-2.c b/test/CodeGen/mbackchain-2.c new file mode 100644 index 0000000000..e76afaf768 --- /dev/null +++ b/test/CodeGen/mbackchain-2.c @@ -0,0 +1,7 @@ +// RUN: %clang -mbackchain --target=s390x-linux -S -emit-llvm -o - %s | FileCheck %s + +// CHECK: define void @foo() [[NUW:#[0-9]+]] +void foo(void) { +} + +// CHECK: attributes [[NUW]] = { {{.*}} "backchain" {{.*}} } diff --git a/test/CodeGen/mbackchain-3.c b/test/CodeGen/mbackchain-3.c new file mode 100644 index 0000000000..b115861f5e --- /dev/null +++ b/test/CodeGen/mbackchain-3.c @@ -0,0 +1,7 @@ +// RUN: %clang -mno-backchain --target=s390x-linux -S -emit-llvm -o - %s | FileCheck %s + +// CHECK: define void @foo() [[NUW:#[0-9]+]] +void foo(void) { +} + +// CHECK-NOT: "backchain" diff --git a/test/CodeGen/mbackchain.c b/test/CodeGen/mbackchain.c new file mode 100644 index 0000000000..e7cfc3aec5 --- /dev/null +++ b/test/CodeGen/mbackchain.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -mbackchain -triple s390x-linux -emit-llvm -o - %s | FileCheck %s + +// CHECK: define void @foo() [[NUW:#[0-9]+]] +void foo(void) { +} + +// CHECK: attributes [[NUW]] = { {{.*}} "backchain" {{.*}} }