[cfe-commits] [PATCH] [2/6] Hexagon TC: Move getHexagonTargetCPU from Tools.cpp to, ToolChains.cpp
Sebastian Pop
spop at codeaurora.org
Thu Sep 20 15:37:25 PDT 2012
Hi Matthew,
there are some typos below.
Matthew Curtis wrote:
> This is in anticipation of forthcoming library path changes.
>
> Also ...
> - Fixes some inconsistencies in how the arch is passed to tools.
> - Add test cases for various forms of arch flags
>
> --
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
>
> From 8d70f9a0f52bf2e74bf7582ce2b29787d6baa7ae Mon Sep 17 00:00:00 2001
> From: Matthew Curtis <mcurtis at codeaurora.org>
> Date: Fri, 14 Sep 2012 13:13:07 -0500
> Subject: [PATCH 2/6] Hexagon TC: Move getHexagonTargetCPU from Tools.cpp to
> ToolChains.cpp
>
> This is in anticipation of forthcoming library path changes.
>
> Also ...
> - Fixes some inconsistencies in how the arch is passed to tools.
> - Add test cases for various forms of arch flags
> ---
> lib/Driver/ToolChains.cpp | 41 +++++++++++++++++++++++++++
> lib/Driver/ToolChains.h | 2 +
> lib/Driver/Tools.cpp | 58 ++++-----------------------------------
> test/Driver/hexagon-toolchain.c | 38 +++++++++++++++++++++++++
> 4 files changed, 87 insertions(+), 52 deletions(-)
>
> diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
> index 2883e9a..eac99ab 100644
> --- a/lib/Driver/ToolChains.cpp
> +++ b/lib/Driver/ToolChains.cpp
> @@ -1560,6 +1560,47 @@ void Hexagon_TC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
> IncludeDir.appendComponent(Ver);
> addSystemInclude(DriverArgs, CC1Args, IncludeDir.str());
> }
> +
> +static Arg* GetLastHexagonArchArg (const ArgList &Args)
s/Arg* GetLastHexagonArchArg (const ArgList &Args)/
Arg *GetLastHexagonArchArg(const ArgList &Args)/
> +{
> + Arg * A = NULL;
s/Arg * A/Arg *A/
> +
> + 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)){
else should be on the same line as }
also please add a space between ){
> + StringRef Value = (*it)->getValue(Args,0);
> + if (Value.startswith("v")) {
> + A = *it;
> + A->claim();
> + }
> + }
> + }
> + return A;
> +}
> +
> +StringRef Hexagon_TC::GetTargetCPU(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(Args);
> + if (WhichHexagon == "")
> + return "v4";
> + else if (WhichHexagon.startswith("hexagon"))
remove all the useless "else"s as you are returning from each case.
> + return WhichHexagon.substr(sizeof("hexagon") - 1);
> + else
> + return WhichHexagon;
> + }
> + else
please remove this "else" as well: at this point, v4 is the default answer
> + return "v4";
> +}
> // End Hexagon
>
>
> diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
> index d99e9b9..f437d56 100644
> --- a/lib/Driver/ToolChains.h
> +++ b/lib/Driver/ToolChains.h
> @@ -538,6 +538,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 3c4bd95..6d1f55a 100644
> --- a/lib/Driver/Tools.cpp
> +++ b/lib/Driver/Tools.cpp
> @@ -1152,51 +1152,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(Args,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(Args);
> - 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))
> @@ -3285,7 +3248,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);
> @@ -3367,17 +3330,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 a0ae693..e9438c8 100644
> --- a/test/Driver/hexagon-toolchain.c
> +++ b/test/Driver/hexagon-toolchain.c
> @@ -69,3 +69,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=<archname> -mcpu=<archname> -mv<number>
> +// -----------------------------------------------------------------------------
> +// 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"
> --
> 1.7.8.3
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
More information about the cfe-commits
mailing list