diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index ac431269bf..7b0d570740 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -1520,6 +1520,42 @@ void Hexagon_TC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, IncludeDir.appendComponent(Ver); addSystemInclude(DriverArgs, CC1Args, IncludeDir.str()); } + +static Arg *GetLastHexagonArchArg (const ArgList &Args) +{ + Arg *A = NULL; + + for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); + it != ie; ++it) { + if ((*it)->getOption().matches(options::OPT_march_EQ) || + (*it)->getOption().matches(options::OPT_mcpu_EQ)) { + A = *it; + A->claim(); + } else if ((*it)->getOption().matches(options::OPT_m_Joined)) { + StringRef Value = (*it)->getValue(0); + if (Value.startswith("v")) { + A = *it; + A->claim(); + } + } + } + return A; +} + +StringRef Hexagon_TC::GetTargetCPU(const ArgList &Args) +{ + // Select the default CPU (v4) if none was given or detection failed. + Arg *A = GetLastHexagonArchArg (Args); + if (A) { + llvm::StringRef WhichHexagon = A->getValue(); + if (WhichHexagon.startswith("hexagon")) + return WhichHexagon.substr(sizeof("hexagon") - 1); + if (WhichHexagon != "") + return WhichHexagon; + } + + return "v4"; +} // End Hexagon /// TCEToolChain - A tool chain using the llvm bitcode tools to perform diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 61be7ec76f..7b930cd4c7 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -530,6 +530,8 @@ public: StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; } static std::string GetGnuDir(const std::string &InstalledDir); + + static StringRef GetTargetCPU(const ArgList &Args); }; /// TCEToolChain - A tool chain using the llvm bitcode tools to perform diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index f28fa68ad4..3b81115668 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1227,51 +1227,14 @@ void Clang::AddX86TargetArgs(const ArgList &Args, } } -static Arg* getLastHexagonArchArg (const ArgList &Args) -{ - Arg * A = NULL; - - for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); - it != ie; ++it) { - if ((*it)->getOption().matches(options::OPT_march_EQ) || - (*it)->getOption().matches(options::OPT_mcpu_EQ)) { - A = *it; - A->claim(); - } - else if ((*it)->getOption().matches(options::OPT_m_Joined)){ - StringRef Value = (*it)->getValue(0); - if (Value.startswith("v")) { - A = *it; - A->claim(); - } - } - } - return A; -} - -static StringRef getHexagonTargetCPU(const ArgList &Args) -{ - Arg *A; - llvm::StringRef WhichHexagon; - - // Select the default CPU (v4) if none was given or detection failed. - if ((A = getLastHexagonArchArg (Args))) { - WhichHexagon = A->getValue(); - if (WhichHexagon == "") - return "v4"; - else - return WhichHexagon; - } - else - return "v4"; -} - void Clang::AddHexagonTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { llvm::Triple Triple = getToolChain().getTriple(); CmdArgs.push_back("-target-cpu"); - CmdArgs.push_back(Args.MakeArgString("hexagon" + getHexagonTargetCPU(Args))); + CmdArgs.push_back(Args.MakeArgString( + "hexagon" + + toolchains::Hexagon_TC::GetTargetCPU(Args))); CmdArgs.push_back("-fno-signed-char"); if (Args.hasArg(options::OPT_mqdsp6_compat)) @@ -3506,7 +3469,7 @@ void hexagon::Assemble::ConstructJob(Compilation &C, const JobAction &JA, ArgStringList CmdArgs; std::string MarchString = "-march="; - MarchString += getHexagonTargetCPU(Args); + MarchString += toolchains::Hexagon_TC::GetTargetCPU(Args); CmdArgs.push_back(Args.MakeArgString(MarchString)); RenderExtraToolArgs(JA, CmdArgs); @@ -3588,17 +3551,8 @@ void hexagon::Link::ConstructJob(Compilation &C, const JobAction &JA, RenderExtraToolArgs(JA, CmdArgs); - // Add Arch Information - Arg *A; - if ((A = getLastHexagonArchArg(Args))) { - if (A->getOption().matches(options::OPT_m_Joined)) - A->render(Args, CmdArgs); - else - CmdArgs.push_back (Args.MakeArgString("-m" + getHexagonTargetCPU(Args))); - } - else { - CmdArgs.push_back (Args.MakeArgString("-m" + getHexagonTargetCPU(Args))); - } + std::string MarchString = toolchains::Hexagon_TC::GetTargetCPU(Args); + CmdArgs.push_back(Args.MakeArgString("-m" + MarchString)); CmdArgs.push_back("-mqdsp6-compat"); diff --git a/test/Driver/hexagon-toolchain.c b/test/Driver/hexagon-toolchain.c index b1c69b9a6d..04d5bcec2f 100644 --- a/test/Driver/hexagon-toolchain.c +++ b/test/Driver/hexagon-toolchain.c @@ -72,3 +72,41 @@ // CHECK006: "-cc1" // CHECK006-NOT: "-internal-isystem" "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/hexagon/include/c++/4.4.0" // CHECK006-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin/hexagon-as" + +// ----------------------------------------------------------------------------- +// Test -march= -mcpu= -mv +// ----------------------------------------------------------------------------- +// RUN: %clang -### -target hexagon-unknown-linux \ +// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ +// RUN: -march=hexagonv3 \ +// RUN: %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK007 %s +// CHECK007: "-cc1" {{.*}} "-target-cpu" "hexagonv3" +// CHECK007-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin/hexagon-as"{{.*}} "-march=v3" +// CHECK007-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin/hexagon-gcc"{{.*}} "-mv3" + +// RUN: %clang -### -target hexagon-unknown-linux \ +// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ +// RUN: -mcpu=hexagonv5 \ +// RUN: %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK008 %s +// CHECK008: "-cc1" {{.*}} "-target-cpu" "hexagonv5" +// CHECK008-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin/hexagon-as"{{.*}} "-march=v5" +// CHECK008-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin/hexagon-gcc"{{.*}} "-mv5" + +// RUN: %clang -### -target hexagon-unknown-linux \ +// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ +// RUN: -mv2 \ +// RUN: %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK009 %s +// CHECK009: "-cc1" {{.*}} "-target-cpu" "hexagonv2" +// CHECK009-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin/hexagon-as"{{.*}} "-march=v2" +// CHECK009-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin/hexagon-gcc"{{.*}} "-mv2" + +// RUN: %clang -### -target hexagon-unknown-linux \ +// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ +// RUN: %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK010 %s +// CHECK010: "-cc1" {{.*}} "-target-cpu" "hexagonv4" +// CHECK010-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin/hexagon-as"{{.*}} "-march=v4" +// CHECK010-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin/hexagon-gcc"{{.*}} "-mv4"