Index: cfe/trunk/include/clang/Driver/Options.td =================================================================== --- cfe/trunk/include/clang/Driver/Options.td +++ cfe/trunk/include/clang/Driver/Options.td @@ -1524,6 +1524,10 @@ 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, Index: cfe/trunk/include/clang/Frontend/CodeGenOptions.def =================================================================== --- cfe/trunk/include/clang/Frontend/CodeGenOptions.def +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def @@ -34,6 +34,7 @@ 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. Index: cfe/trunk/lib/CodeGen/CGCall.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CGCall.cpp +++ cfe/trunk/lib/CodeGen/CGCall.cpp @@ -1714,6 +1714,8 @@ 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 Index: cfe/trunk/lib/Driver/Tools.cpp =================================================================== --- cfe/trunk/lib/Driver/Tools.cpp +++ cfe/trunk/lib/Driver/Tools.cpp @@ -1655,6 +1655,12 @@ } } +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 @@ AddSparcTargetArgs(Args, CmdArgs); break; + case llvm::Triple::systemz: + AddSystemZTargetArgs(Args, CmdArgs); + break; + case llvm::Triple::x86: case llvm::Triple::x86_64: AddX86TargetArgs(Args, CmdArgs); Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp =================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp @@ -782,6 +782,8 @@ Opts.CudaGpuBinaryFileNames = Args.getAllArgValues(OPT_fcuda_include_gpubinary); + Opts.Backchain = Args.hasArg(OPT_mbackchain); + return Success; } Index: cfe/trunk/test/CodeGen/mbackchain-2.c =================================================================== --- cfe/trunk/test/CodeGen/mbackchain-2.c +++ cfe/trunk/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" {{.*}} } Index: cfe/trunk/test/CodeGen/mbackchain-3.c =================================================================== --- cfe/trunk/test/CodeGen/mbackchain-3.c +++ cfe/trunk/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" Index: cfe/trunk/test/CodeGen/mbackchain.c =================================================================== --- cfe/trunk/test/CodeGen/mbackchain.c +++ cfe/trunk/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" {{.*}} }