Index: cfe/trunk/include/clang/Driver/ToolChain.h =================================================================== --- cfe/trunk/include/clang/Driver/ToolChain.h +++ cfe/trunk/include/clang/Driver/ToolChain.h @@ -40,6 +40,7 @@ class Compilation; class Driver; class JobAction; + class RegisterEffectiveTriple; class SanitizerArgs; class Tool; @@ -91,6 +92,14 @@ mutable std::unique_ptr SanitizerArguments; + /// The effective clang triple for the current Job. + mutable llvm::Triple EffectiveTriple; + + /// Set the toolchain's effective clang triple. + void setEffectiveTriple(llvm::Triple ET) const { EffectiveTriple = ET; } + + friend class RegisterEffectiveTriple; + protected: MultilibSet Multilibs; const char *DefaultLinker = "ld"; @@ -141,6 +150,12 @@ return Triple.getTriple(); } + /// Get the toolchain's effective clang triple. + const llvm::Triple &getEffectiveTriple() const { + assert(!EffectiveTriple.getTriple().empty() && "No effective triple"); + return EffectiveTriple; + } + path_list &getFilePaths() { return FilePaths; } const path_list &getFilePaths() const { return FilePaths; } @@ -432,6 +447,19 @@ virtual VersionTuple getMSVCVersionFromExe() const { return VersionTuple(); } }; +/// Set a ToolChain's effective triple. Reset it when the registration object +/// is destroyed. +class RegisterEffectiveTriple { + const ToolChain &TC; + +public: + RegisterEffectiveTriple(const ToolChain &TC, llvm::Triple T) : TC(TC) { + TC.setEffectiveTriple(T); + } + + ~RegisterEffectiveTriple() { TC.setEffectiveTriple(llvm::Triple()); } +}; + } // end namespace driver } // end namespace clang Index: cfe/trunk/lib/Driver/Driver.cpp =================================================================== --- cfe/trunk/lib/Driver/Driver.cpp +++ cfe/trunk/lib/Driver/Driver.cpp @@ -2247,6 +2247,19 @@ InputInfos.append(OffloadDependencesInputInfo.begin(), OffloadDependencesInputInfo.end()); + // Set the effective triple of the toolchain for the duration of this job. + llvm::Triple EffectiveTriple; + const ToolChain &ToolTC = T->getToolChain(); + const ArgList &Args = C.getArgsForToolChain(TC, BoundArch); + if (InputInfos.size() != 1) { + EffectiveTriple = llvm::Triple(ToolTC.ComputeEffectiveClangTriple(Args)); + } else { + // Pass along the input type if it can be unambiguously determined. + EffectiveTriple = llvm::Triple( + ToolTC.ComputeEffectiveClangTriple(Args, InputInfos[0].getType())); + } + RegisterEffectiveTriple TripleRAII(ToolTC, EffectiveTriple); + // Determine the place to write output to, if any. InputInfo Result; if (JA->getType() == types::TY_Nothing) Index: cfe/trunk/lib/Driver/ToolChain.cpp =================================================================== --- cfe/trunk/lib/Driver/ToolChain.cpp +++ cfe/trunk/lib/Driver/ToolChain.cpp @@ -68,7 +68,8 @@ ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), - CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { + CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)), + EffectiveTriple() { if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) if (!isThreadModelSupported(A->getValue())) D.Diag(diag::err_drv_invalid_thread_model_for_target) Index: cfe/trunk/lib/Driver/ToolChains.h =================================================================== --- cfe/trunk/lib/Driver/ToolChains.h +++ cfe/trunk/lib/Driver/ToolChains.h @@ -312,9 +312,6 @@ /// @name ToolChain Implementation /// { - std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, - types::ID InputType) const override; - types::ID LookupTypeForExtension(const char *Ext) const override; bool HasNativeLLVMSupport() const override; Index: cfe/trunk/lib/Driver/ToolChains.cpp =================================================================== --- cfe/trunk/lib/Driver/ToolChains.cpp +++ cfe/trunk/lib/Driver/ToolChains.cpp @@ -176,13 +176,6 @@ MachO::~MachO() {} -std::string MachO::ComputeEffectiveClangTriple(const ArgList &Args, - types::ID InputType) const { - llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); - - return Triple.getTriple(); -} - std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, types::ID InputType) const { llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); Index: cfe/trunk/lib/Driver/Tools.cpp =================================================================== --- cfe/trunk/lib/Driver/Tools.cpp +++ cfe/trunk/lib/Driver/Tools.cpp @@ -764,7 +764,7 @@ // -mfloat-abi=. arm::FloatABI arm::getARMFloatABI(const ToolChain &TC, const ArgList &Args) { const Driver &D = TC.getDriver(); - const llvm::Triple Triple(TC.ComputeEffectiveClangTriple(Args)); + const llvm::Triple &Triple = TC.getEffectiveTriple(); auto SubArch = getARMSubArchVersionNumber(Triple); arm::FloatABI ABI = FloatABI::Invalid; if (Arg *A = @@ -1165,8 +1165,7 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { - std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); - llvm::Triple Triple(TripleStr); + const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone, true) || Args.hasArg(options::OPT_mkernel) || @@ -3838,8 +3837,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { - std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); - const llvm::Triple Triple(TripleStr); + const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); + const std::string &TripleStr = Triple.getTriple(); bool KernelOrKext = Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext); @@ -6500,9 +6499,8 @@ assert(Inputs.size() == 1 && "Unexpected number of inputs."); const InputInfo &Input = Inputs[0]; - std::string TripleStr = - getToolChain().ComputeEffectiveClangTriple(Args, Input.getType()); - const llvm::Triple Triple(TripleStr); + const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); + const std::string &TripleStr = Triple.getTriple(); // Don't warn about "clang -w -c foo.s" Args.ClaimAllArgs(options::OPT_w); @@ -8878,9 +8876,7 @@ break; case llvm::Triple::armeb: case llvm::Triple::thumbeb: - arm::appendEBLinkFlags( - Args, CmdArgs, - llvm::Triple(getToolChain().ComputeEffectiveClangTriple(Args))); + arm::appendEBLinkFlags(Args, CmdArgs, getToolChain().getEffectiveTriple()); CmdArgs.push_back("-m"); switch (getToolChain().getTriple().getEnvironment()) { case llvm::Triple::EABI: @@ -9044,8 +9040,7 @@ const char *LinkingOutput) const { claimNoWarnArgs(Args); - std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); - llvm::Triple Triple = llvm::Triple(TripleStr); + const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); ArgStringList CmdArgs; @@ -9380,8 +9375,7 @@ static_cast(getToolChain()); const Driver &D = ToolChain.getDriver(); - std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); - llvm::Triple Triple = llvm::Triple(TripleStr); + const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); const llvm::Triple::ArchType Arch = ToolChain.getArch(); const bool isAndroid = ToolChain.getTriple().isAndroid();