From 260e28d65a702a304bd8d19eee123e0467b561ca Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 18 Mar 2013 20:48:54 +0000 Subject: [PATCH] Centralize the recording of which tools have been constructed. llvm-svn: 177319 --- clang/include/clang/Driver/ToolChain.h | 10 +- clang/lib/Driver/ToolChain.cpp | 24 +++ clang/lib/Driver/ToolChains.cpp | 330 ++++++++------------------------- clang/lib/Driver/ToolChains.h | 38 ++-- clang/lib/Driver/WindowsToolChain.cpp | 24 +-- 5 files changed, 130 insertions(+), 296 deletions(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 4a81bdc..6abf85f 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -10,6 +10,7 @@ #ifndef CLANG_DRIVER_TOOLCHAIN_H_ #define CLANG_DRIVER_TOOLCHAIN_H_ +#include "clang/Driver/Action.h" #include "clang/Driver/Types.h" #include "clang/Driver/Util.h" #include "llvm/ADT/SmallVector.h" @@ -57,9 +58,13 @@ private: /// programs. path_list ProgramPaths; + mutable llvm::DenseMap Tools; + protected: ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args); + virtual Tool *constructTool(Action::ActionClass AC) const = 0; + /// \name Utilities for implementing subclasses. ///@{ static void addSystemInclude(const ArgList &DriverArgs, @@ -112,9 +117,8 @@ public: return 0; } - /// SelectTool - Choose a tool to use to handle the action \p JA with the - /// given \p Inputs. - virtual Tool &SelectTool(const JobAction &JA) const = 0; + /// Choose a tool to use to handle the action \p JA. + Tool &SelectTool(const JobAction &JA) const; // Helper methods diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 83c1646..e5ddfd1 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "Tools.h" #include "clang/Driver/ToolChain.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Driver/Action.h" @@ -27,6 +28,10 @@ ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, } ToolChain::~ToolChain() { + // Free tool implementations. + for (llvm::DenseMap::iterator + it = Tools.begin(), ie = Tools.end(); it != ie; ++it) + delete it->second; } const Driver &ToolChain::getDriver() const { @@ -58,6 +63,25 @@ bool ToolChain::IsUnwindTablesDefault() const { return false; } +Tool &ToolChain::SelectTool(const JobAction &JA) const { + Action::ActionClass Key; + if (getDriver().ShouldUseClangCompiler(JA)) + Key = Action::AnalyzeJobClass; + else + Key = JA.getKind(); + + Tool *&T = Tools[Key]; + if (T) + return *T; + + if (getDriver().ShouldUseClangCompiler(JA)) + T = new tools::Clang(*this); + else + T = constructTool(Key); + + return *T; +} + std::string ToolChain::GetFilePath(const char *Name) const { return D.GetFilePath(Name, *this); diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 8506b97..22600ea 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -151,10 +151,6 @@ StringRef Darwin::getDarwinArchName(const ArgList &Args) const { } Darwin::~Darwin() { - // Free tool implementations. - for (llvm::DenseMap::iterator - it = Tools.begin(), ie = Tools.end(); it != ie; ++it) - delete it->second; } std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, @@ -176,19 +172,8 @@ std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, void Generic_ELF::anchor() {} -Tool &Darwin::SelectTool(const JobAction &JA) const { - Action::ActionClass Key = JA.getKind(); - - if (getDriver().ShouldUseClangCompiler(JA)) { - // FIXME: This seems like a hacky way to choose clang frontend. - Key = Action::AnalyzeJobClass; - } - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *Darwin::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::InputClass: case Action::BindArchClass: llvm_unreachable("Invalid tool kind."); @@ -197,25 +182,23 @@ Tool &Darwin::SelectTool(const JobAction &JA) const { case Action::MigrateJobClass: case Action::PrecompileJobClass: case Action::CompileJobClass: - T = new tools::Clang(*this); break; + return new tools::Clang(*this); case Action::AssembleJobClass: { if (useIntegratedAs()) - T = new tools::ClangAs(*this); + return new tools::ClangAs(*this); else - T = new tools::darwin::Assemble(*this); + return new tools::darwin::Assemble(*this); break; } case Action::LinkJobClass: - T = new tools::darwin::Link(*this); break; + return new tools::darwin::Link(*this); case Action::LipoJobClass: - T = new tools::darwin::Lipo(*this); break; + return new tools::darwin::Lipo(*this); case Action::DsymutilJobClass: - T = new tools::darwin::Dsymutil(*this); break; + return new tools::darwin::Dsymutil(*this); case Action::VerifyJobClass: - T = new tools::darwin::VerifyDebug(*this); break; + return new tools::darwin::VerifyDebug(*this); } - - return *T; } @@ -1377,52 +1360,36 @@ Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple& Triple, } Generic_GCC::~Generic_GCC() { - // Free tool implementations. - for (llvm::DenseMap::iterator - it = Tools.begin(), ie = Tools.end(); it != ie; ++it) - delete it->second; } -Tool &Generic_GCC::SelectTool(const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *Generic_GCC::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::InputClass: case Action::BindArchClass: llvm_unreachable("Invalid tool kind."); case Action::PreprocessJobClass: - T = new tools::gcc::Preprocess(*this); break; + return new tools::gcc::Preprocess(*this); case Action::PrecompileJobClass: - T = new tools::gcc::Precompile(*this); break; + return new tools::gcc::Precompile(*this); case Action::AnalyzeJobClass: case Action::MigrateJobClass: - T = new tools::Clang(*this); break; + return new tools::Clang(*this); case Action::CompileJobClass: - T = new tools::gcc::Compile(*this); break; + return new tools::gcc::Compile(*this); case Action::AssembleJobClass: - T = new tools::gcc::Assemble(*this); break; + return new tools::gcc::Assemble(*this); case Action::LinkJobClass: - T = new tools::gcc::Link(*this); break; + return new tools::gcc::Link(*this); // This is a bit ungeneric, but the only platform using a driver // driver is Darwin. case Action::LipoJobClass: - T = new tools::darwin::Lipo(*this); break; + return new tools::darwin::Lipo(*this); case Action::DsymutilJobClass: - T = new tools::darwin::Dsymutil(*this); break; + return new tools::darwin::Dsymutil(*this); case Action::VerifyJobClass: - T = new tools::darwin::VerifyDebug(*this); break; + return new tools::darwin::VerifyDebug(*this); } - - return *T; } bool Generic_GCC::IsUnwindTablesDefault() const { @@ -1547,38 +1514,18 @@ Hexagon_TC::Hexagon_TC(const Driver &D, const llvm::Triple &Triple, } Hexagon_TC::~Hexagon_TC() { - // Free tool implementations. - for (llvm::DenseMap::iterator - it = Tools.begin(), ie = Tools.end(); it != ie; ++it) - delete it->second; } -Tool &Hexagon_TC::SelectTool(const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { - case Action::InputClass: - case Action::BindArchClass: - assert(0 && "Invalid tool kind."); - case Action::AnalyzeJobClass: - T = new tools::Clang(*this); break; +Tool *Hexagon_TC::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::AssembleJobClass: - T = new tools::hexagon::Assemble(*this); break; + return new tools::hexagon::Assemble(*this); case Action::LinkJobClass: - T = new tools::hexagon::Link(*this); break; + return new tools::hexagon::Link(*this); default: assert(false && "Unsupported action for Hexagon target."); + return Linux::constructTool(AC); } - - return *T; } void Hexagon_TC::AddClangSystemIncludeArgs(const ArgList &DriverArgs, @@ -1681,9 +1628,6 @@ TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple& Triple, } TCEToolChain::~TCEToolChain() { - for (llvm::DenseMap::iterator - it = Tools.begin(), ie = Tools.end(); it != ie; ++it) - delete it->second; } bool TCEToolChain::IsMathErrnoDefault() const { @@ -1698,23 +1642,15 @@ bool TCEToolChain::isPICDefaultForced() const { return false; } -Tool &TCEToolChain::SelectTool(const JobAction &JA) const { - Action::ActionClass Key; - Key = Action::AnalyzeJobClass; - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *TCEToolChain::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::PreprocessJobClass: - T = new tools::gcc::Preprocess(*this); break; + return new tools::gcc::Preprocess(*this); case Action::AnalyzeJobClass: - T = new tools::Clang(*this); break; + return new tools::Clang(*this); default: llvm_unreachable("Unsupported action for TCE target."); } - return *T; } /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. @@ -1725,32 +1661,20 @@ OpenBSD::OpenBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Arg getFilePaths().push_back("/usr/lib"); } -Tool &OpenBSD::SelectTool(const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *OpenBSD::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::AssembleJobClass: { if (useIntegratedAs()) - T = new tools::ClangAs(*this); + return new tools::ClangAs(*this); else - T = new tools::openbsd::Assemble(*this); + return new tools::openbsd::Assemble(*this); break; } case Action::LinkJobClass: - T = new tools::openbsd::Link(*this); break; + return new tools::openbsd::Link(*this); default: - return Generic_GCC::SelectTool(JA); + return Generic_GCC::constructTool(AC); } - - return *T; } /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly. @@ -1761,32 +1685,20 @@ Bitrig::Bitrig(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) getFilePaths().push_back("/usr/lib"); } -Tool &Bitrig::SelectTool(const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *Bitrig::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::AssembleJobClass: { if (useIntegratedAs()) - T = new tools::ClangAs(*this); + return new tools::ClangAs(*this); else - T = new tools::bitrig::Assemble(*this); + return new tools::bitrig::Assemble(*this); break; } case Action::LinkJobClass: - T = new tools::bitrig::Link(*this); break; + return new tools::bitrig::Link(*this); break; default: - return Generic_GCC::SelectTool(JA); + return Generic_GCC::constructTool(AC); } - - return *T; } void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, @@ -1849,31 +1761,19 @@ FreeBSD::FreeBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Arg getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); } -Tool &FreeBSD::SelectTool(const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *FreeBSD::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::AssembleJobClass: if (useIntegratedAs()) - T = new tools::ClangAs(*this); + return new tools::ClangAs(*this); else - T = new tools::freebsd::Assemble(*this); + return new tools::freebsd::Assemble(*this); break; case Action::LinkJobClass: - T = new tools::freebsd::Link(*this); break; + return new tools::freebsd::Link(*this); break; default: - return Generic_GCC::SelectTool(JA); + return Generic_GCC::constructTool(AC); } - - return *T; } bool FreeBSD::UseSjLjExceptions() const { @@ -1907,32 +1807,20 @@ NetBSD::NetBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) } } -Tool &NetBSD::SelectTool( const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *NetBSD::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::AssembleJobClass: if (useIntegratedAs()) - T = new tools::ClangAs(*this); + return new tools::ClangAs(*this); else - T = new tools::netbsd::Assemble(*this); + return new tools::netbsd::Assemble(*this); break; case Action::LinkJobClass: - T = new tools::netbsd::Link(*this); + return new tools::netbsd::Link(*this); break; default: - return Generic_GCC::SelectTool(JA); + return Generic_GCC::constructTool(AC); } - - return *T; } /// Minix - Minix tool chain which can call as(1) and ld(1) directly. @@ -1943,27 +1831,15 @@ Minix::Minix(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) getFilePaths().push_back("/usr/lib"); } -Tool &Minix::SelectTool(const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *Minix::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::AssembleJobClass: - T = new tools::minix::Assemble(*this); break; + return new tools::minix::Assemble(*this); case Action::LinkJobClass: - T = new tools::minix::Link(*this); break; + return new tools::minix::Link(*this); default: - return Generic_GCC::SelectTool(JA); + return Generic_GCC::constructTool(AC); } - - return *T; } /// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly. @@ -1984,27 +1860,15 @@ AuroraUX::AuroraUX(const Driver &D, const llvm::Triple& Triple, } -Tool &AuroraUX::SelectTool(const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *AuroraUX::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::AssembleJobClass: - T = new tools::auroraux::Assemble(*this); break; + return new tools::auroraux::Assemble(*this); case Action::LinkJobClass: - T = new tools::auroraux::Link(*this); break; + return new tools::auroraux::Link(*this); default: - return Generic_GCC::SelectTool(JA); + return Generic_GCC::constructTool(AC); } - - return *T; } /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. @@ -2021,27 +1885,15 @@ Solaris::Solaris(const Driver &D, const llvm::Triple& Triple, getFilePaths().push_back("/usr/lib"); } -Tool &Solaris::SelectTool(const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *Solaris::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::AssembleJobClass: - T = new tools::solaris::Assemble(*this); break; + return new tools::solaris::Assemble(*this); case Action::LinkJobClass: - T = new tools::solaris::Link(*this); break; + return new tools::solaris::Link(*this); default: - return Generic_GCC::SelectTool(JA); + return Generic_GCC::constructTool(AC); } - - return *T; } /// Linux toolchain (very bare-bones at the moment). @@ -2410,31 +2262,19 @@ bool Linux::HasNativeLLVMSupport() const { return true; } -Tool &Linux::SelectTool( const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *Linux::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::AssembleJobClass: if (useIntegratedAs()) - T = new tools::ClangAs(*this); + return new tools::ClangAs(*this); else - T = new tools::linuxtools::Assemble(*this); + return new tools::linuxtools::Assemble(*this); break; case Action::LinkJobClass: - T = new tools::linuxtools::Link(*this); break; + return new tools::linuxtools::Link(*this); break; default: - return Generic_GCC::SelectTool(JA); + return Generic_GCC::constructTool(AC); } - - return *T; } void Linux::addClangTargetOptions(const ArgList &DriverArgs, @@ -2663,25 +2503,13 @@ DragonFly::DragonFly(const Driver &D, const llvm::Triple& Triple, const ArgList getFilePaths().push_back("/usr/lib/gcc41"); } -Tool &DragonFly::SelectTool(const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *DragonFly::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::AssembleJobClass: - T = new tools::dragonfly::Assemble(*this); break; + return new tools::dragonfly::Assemble(*this); case Action::LinkJobClass: - T = new tools::dragonfly::Link(*this); break; + return new tools::dragonfly::Link(*this); default: - return Generic_GCC::SelectTool(JA); + return Generic_GCC::constructTool(AC); } - - return *T; } diff --git a/clang/lib/Driver/ToolChains.h b/clang/lib/Driver/ToolChains.h index a11ae14..a2b84c9 100644 --- a/clang/lib/Driver/ToolChains.h +++ b/clang/lib/Driver/ToolChains.h @@ -117,13 +117,11 @@ protected: GCCInstallationDetector GCCInstallation; - mutable llvm::DenseMap Tools; - public: Generic_GCC(const Driver &D, const llvm::Triple& Triple, const ArgList &Args); ~Generic_GCC(); - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; virtual bool IsUnwindTablesDefault() const; virtual bool isPICDefault() const; @@ -149,8 +147,6 @@ public: unsigned DarwinVersion[3]; private: - mutable llvm::DenseMap Tools; - /// Whether the information on the target has been initialized. // // FIXME: This should be eliminated. What we want to do is make this part of @@ -268,7 +264,7 @@ public: virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args, const char *BoundArch) const; - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; virtual bool IsBlocksDefault() const { // Always allow blocks on Darwin; users interested in versioning are @@ -392,14 +388,14 @@ class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC { public: AuroraUX(const Driver &D, const llvm::Triple& Triple, const ArgList &Args); - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; }; class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC { public: Solaris(const Driver &D, const llvm::Triple& Triple, const ArgList &Args); - virtual Tool &SelectTool( const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; virtual bool IsIntegratedAssemblerDefault() const { return true; } }; @@ -412,7 +408,7 @@ public: virtual bool IsMathErrnoDefault() const { return false; } virtual bool IsObjCNonFragileABIDefault() const { return true; } - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; }; class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF { @@ -423,7 +419,7 @@ public: virtual bool IsObjCNonFragileABIDefault() const { return true; } virtual bool IsObjCLegacyDispatchDefault() const { return false; } - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; virtual void AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const; @@ -441,7 +437,7 @@ public: virtual bool IsMathErrnoDefault() const { return false; } virtual bool IsObjCNonFragileABIDefault() const { return true; } - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; virtual bool UseSjLjExceptions() const; }; @@ -452,14 +448,14 @@ public: virtual bool IsMathErrnoDefault() const { return false; } virtual bool IsObjCNonFragileABIDefault() const { return true; } - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; }; class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF { public: Minix(const Driver &D, const llvm::Triple& Triple, const ArgList &Args); - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; }; class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF { @@ -468,7 +464,7 @@ public: virtual bool IsMathErrnoDefault() const { return false; } - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; }; class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF { @@ -477,7 +473,7 @@ public: virtual bool HasNativeLLVMSupport() const; - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const; @@ -509,7 +505,7 @@ public: const ArgList &Args); ~Hexagon_TC(); - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const; @@ -532,23 +528,17 @@ public: const ArgList &Args); ~TCEToolChain(); - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; bool IsMathErrnoDefault() const; bool isPICDefault() const; bool isPICDefaultForced() const; - -private: - mutable llvm::DenseMap Tools; - }; class LLVM_LIBRARY_VISIBILITY Windows : public ToolChain { - mutable llvm::DenseMap Tools; - public: Windows(const Driver &D, const llvm::Triple& Triple, const ArgList &Args); - virtual Tool &SelectTool(const JobAction &JA) const; + virtual Tool *constructTool(Action::ActionClass AC) const; virtual bool IsIntegratedAssemblerDefault() const; virtual bool IsUnwindTablesDefault() const; diff --git a/clang/lib/Driver/WindowsToolChain.cpp b/clang/lib/Driver/WindowsToolChain.cpp index 60781ca..985039e 100644 --- a/clang/lib/Driver/WindowsToolChain.cpp +++ b/clang/lib/Driver/WindowsToolChain.cpp @@ -36,18 +36,8 @@ Windows::Windows(const Driver &D, const llvm::Triple& Triple, : ToolChain(D, Triple, Args) { } -Tool &Windows::SelectTool(const JobAction &JA) const { - Action::ActionClass Key; - if (getDriver().ShouldUseClangCompiler(JA)) - Key = Action::AnalyzeJobClass; - else - Key = JA.getKind(); - - Tool *&T = Tools[Key]; - if (T) - return *T; - - switch (Key) { +Tool *Windows::constructTool(Action::ActionClass AC) const { + switch (AC) { case Action::InputClass: case Action::BindArchClass: case Action::LipoJobClass: @@ -58,19 +48,17 @@ Tool &Windows::SelectTool(const JobAction &JA) const { case Action::AnalyzeJobClass: case Action::MigrateJobClass: case Action::CompileJobClass: - T = new tools::Clang(*this); break; + return new tools::Clang(*this); case Action::AssembleJobClass: if (!useIntegratedAs() && getTriple().getEnvironment() == llvm::Triple::MachO) - T = new tools::darwin::Assemble(*this); + return new tools::darwin::Assemble(*this); else - T = new tools::ClangAs(*this); + return new tools::ClangAs(*this); break; case Action::LinkJobClass: - T = new tools::visualstudio::Link(*this); break; + return new tools::visualstudio::Link(*this); } - - return *T; } bool Windows::IsIntegratedAssemblerDefault() const { -- 2.7.4