From owner-svn-src-stable@FreeBSD.ORG Fri Mar 1 17:37:59 2013 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id EF9D9CB9; Fri, 1 Mar 2013 17:37:58 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id DFA21B62; Fri, 1 Mar 2013 17:37:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r21Hbwsf026404; Fri, 1 Mar 2013 17:37:58 GMT (envelope-from dim@svn.freebsd.org) Received: (from dim@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r21Hbw8i026402; Fri, 1 Mar 2013 17:37:58 GMT (envelope-from dim@svn.freebsd.org) Message-Id: <201303011737.r21Hbw8i026402@svn.freebsd.org> From: Dimitry Andric Date: Fri, 1 Mar 2013 17:37:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r247557 - stable/9/contrib/llvm/tools/clang/lib/Driver X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Mar 2013 17:37:59 -0000 Author: dim Date: Fri Mar 1 17:37:57 2013 New Revision: 247557 URL: http://svnweb.freebsd.org/changeset/base/247557 Log: MFC r247166: Pull in r172354 from upstream clang trunk: Refactor the x86 CPU name logic in the driver and pass -march and -mcpu flag information down from the Clang driver into the Gold linker plugin for LTO. This allows specifying -march on the linker commandline and should hopefully have it pass all the way through to the LTO optimizer. Fixes PR14697. Pull in r175919 from upstream clang trunk: Driver: Pass down the -march setting down to -cc1as on x86 too. The assembler historically didn't make use of any target features, but this has changed when support for old CPUs that don't support long nops was added. This should fix the long nops that still occurred in crt*.o, and possibly other object files, if the system was compiled for a CPU that does not support those, such as Geode. Note that gcc on i386 also does not pass through any -march, -mcpu or -mtune setting to gas, but this has not caused any trouble yet, because gas defaults to i386. Reported by: lev Modified: stable/9/contrib/llvm/tools/clang/lib/Driver/Tools.cpp stable/9/contrib/llvm/tools/clang/lib/Driver/Tools.h Directory Properties: stable/9/contrib/llvm/ (props changed) stable/9/contrib/llvm/tools/clang/ (props changed) Modified: stable/9/contrib/llvm/tools/clang/lib/Driver/Tools.cpp ============================================================================== --- stable/9/contrib/llvm/tools/clang/lib/Driver/Tools.cpp Fri Mar 1 17:10:52 2013 (r247556) +++ stable/9/contrib/llvm/tools/clang/lib/Driver/Tools.cpp Fri Mar 1 17:37:57 2013 (r247557) @@ -1114,10 +1114,59 @@ void Clang::AddSparcTargetArgs(const Arg } } +static const char *getX86TargetCPU(const ArgList &Args, + const llvm::Triple &Triple) { + if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { + if (StringRef(A->getValue()) != "native") + return A->getValue(); + + // FIXME: Reject attempts to use -march=native unless the target matches + // the host. + // + // FIXME: We should also incorporate the detected target features for use + // with -native. + std::string CPU = llvm::sys::getHostCPUName(); + if (!CPU.empty() && CPU != "generic") + return Args.MakeArgString(CPU); + } + + // Select the default CPU if none was given (or detection failed). + + if (Triple.getArch() != llvm::Triple::x86_64 && + Triple.getArch() != llvm::Triple::x86) + return 0; // This routine is only handling x86 targets. + + bool Is64Bit = Triple.getArch() == llvm::Triple::x86_64; + + // FIXME: Need target hooks. + if (Triple.isOSDarwin()) + return Is64Bit ? "core2" : "yonah"; + + // Everything else goes to x86-64 in 64-bit mode. + if (Is64Bit) + return "x86-64"; + + if (Triple.getOSName().startswith("haiku")) + return "i586"; + if (Triple.getOSName().startswith("openbsd")) + return "i486"; + if (Triple.getOSName().startswith("bitrig")) + return "i686"; + if (Triple.getOSName().startswith("freebsd")) + return "i486"; + if (Triple.getOSName().startswith("netbsd")) + return "i486"; + // All x86 devices running Android have core2 as their common + // denominator. This makes a better choice than pentium4. + if (Triple.getEnvironment() == llvm::Triple::Android) + return "core2"; + + // Fallback to p4. + return "pentium4"; +} + void Clang::AddX86TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { - const bool isAndroid = - getToolChain().getTriple().getEnvironment() == llvm::Triple::Android; if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone, true) || @@ -1130,65 +1179,7 @@ void Clang::AddX86TargetArgs(const ArgLi false)) CmdArgs.push_back("-no-implicit-float"); - const char *CPUName = 0; - if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { - if (StringRef(A->getValue()) == "native") { - // FIXME: Reject attempts to use -march=native unless the target matches - // the host. - // - // FIXME: We should also incorporate the detected target features for use - // with -native. - std::string CPU = llvm::sys::getHostCPUName(); - if (!CPU.empty() && CPU != "generic") - CPUName = Args.MakeArgString(CPU); - } else - CPUName = A->getValue(); - } - - // Select the default CPU if none was given (or detection failed). - if (!CPUName) { - // FIXME: Need target hooks. - if (getToolChain().getTriple().isOSDarwin()) { - if (getToolChain().getArch() == llvm::Triple::x86_64) - CPUName = "core2"; - else if (getToolChain().getArch() == llvm::Triple::x86) - CPUName = "yonah"; - } else if (getToolChain().getOS().startswith("haiku")) { - if (getToolChain().getArch() == llvm::Triple::x86_64) - CPUName = "x86-64"; - else if (getToolChain().getArch() == llvm::Triple::x86) - CPUName = "i586"; - } else if (getToolChain().getOS().startswith("openbsd")) { - if (getToolChain().getArch() == llvm::Triple::x86_64) - CPUName = "x86-64"; - else if (getToolChain().getArch() == llvm::Triple::x86) - CPUName = "i486"; - } else if (getToolChain().getOS().startswith("bitrig")) { - if (getToolChain().getArch() == llvm::Triple::x86_64) - CPUName = "x86-64"; - else if (getToolChain().getArch() == llvm::Triple::x86) - CPUName = "i686"; - } else if (getToolChain().getOS().startswith("freebsd")) { - if (getToolChain().getArch() == llvm::Triple::x86_64) - CPUName = "x86-64"; - else if (getToolChain().getArch() == llvm::Triple::x86) - CPUName = "i486"; - } else if (getToolChain().getOS().startswith("netbsd")) { - if (getToolChain().getArch() == llvm::Triple::x86_64) - CPUName = "x86-64"; - else if (getToolChain().getArch() == llvm::Triple::x86) - CPUName = "i486"; - } else { - if (getToolChain().getArch() == llvm::Triple::x86_64) - CPUName = "x86-64"; - else if (getToolChain().getArch() == llvm::Triple::x86) - // All x86 devices running Android have core2 as their common - // denominator. This makes a better choice than pentium4. - CPUName = isAndroid ? "core2" : "pentium4"; - } - } - - if (CPUName) { + if (const char *CPUName = getX86TargetCPU(Args, getToolChain().getTriple())) { CmdArgs.push_back("-target-cpu"); CmdArgs.push_back(CPUName); } @@ -3091,6 +3082,15 @@ void ClangAs::AddARMTargetArgs(const Arg addFPMathArgs(D, A, Args, CmdArgs, getARMTargetCPU(Args, Triple)); } +void ClangAs::AddX86TargetArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { + // Set the CPU based on -march=. + if (const char *CPUName = getX86TargetCPU(Args, getToolChain().getTriple())) { + CmdArgs.push_back("-target-cpu"); + CmdArgs.push_back(CPUName); + } +} + /// Add options related to the Objective-C runtime/ABI. /// /// Returns true if the runtime is non-fragile. @@ -3261,6 +3261,11 @@ void ClangAs::ConstructJob(Compilation & case llvm::Triple::thumb: AddARMTargetArgs(Args, CmdArgs); break; + + case llvm::Triple::x86: + case llvm::Triple::x86_64: + AddX86TargetArgs(Args, CmdArgs); + break; } // Ignore explicit -force_cpusubtype_ALL option. @@ -6068,8 +6073,27 @@ void linuxtools::Link::ConstructJob(Comp CmdArgs.push_back("-plugin"); std::string Plugin = ToolChain.getDriver().Dir + "/../lib/LLVMgold.so"; CmdArgs.push_back(Args.MakeArgString(Plugin)); + + // Try to pass driver level flags relevant to LTO code generation down to + // the plugin. + + // Handle architecture-specific flags for selecting CPU variants. + if (ToolChain.getArch() == llvm::Triple::x86 || + ToolChain.getArch() == llvm::Triple::x86_64) + CmdArgs.push_back( + Args.MakeArgString(Twine("-plugin-opt=mcpu=") + + getX86TargetCPU(Args, ToolChain.getTriple()))); + else if (ToolChain.getArch() == llvm::Triple::arm || + ToolChain.getArch() == llvm::Triple::thumb) + CmdArgs.push_back( + Args.MakeArgString(Twine("-plugin-opt=mcpu=") + + getARMTargetCPU(Args, ToolChain.getTriple()))); + + // FIXME: Factor out logic for MIPS, PPC, and other targets to support this + // as well. } + if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) CmdArgs.push_back("--no-demangle"); Modified: stable/9/contrib/llvm/tools/clang/lib/Driver/Tools.h ============================================================================== --- stable/9/contrib/llvm/tools/clang/lib/Driver/Tools.h Fri Mar 1 17:10:52 2013 (r247556) +++ stable/9/contrib/llvm/tools/clang/lib/Driver/Tools.h Fri Mar 1 17:37:57 2013 (r247557) @@ -68,6 +68,7 @@ namespace tools { /// \brief Clang integrated assembler tool. class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool { void AddARMTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; + void AddX86TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const; public: ClangAs(const ToolChain &TC) : Tool("clang::as", "clang integrated assembler", TC) {}