From f26d8bc4406be1311a38fd1761d5ddeb2f5a38b6 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 24 Sep 2013 13:28:24 +0000 Subject: [PATCH] Remove a use of OPT_m_Joined. This patch turns the -mv* hexagon options into aliases. We should really produce errors for invalid versions in the driver, but this patch preserves the old behavior for now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191298 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 10 ++++++ lib/Driver/ToolChains.cpp | 63 ++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 529d03c422..419719d06e 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1336,6 +1336,16 @@ def _write_dependencies : Flag<["--"], "write-dependencies">, Alias; def _write_user_dependencies : Flag<["--"], "write-user-dependencies">, Alias; def _ : Joined<["--"], "">, Flags<[Unsupported]>; def mieee_rnd_near : Flag<["-"], "mieee-rnd-near">, Group; +def mv1 : Flag<["-"], "mv1">, Group, Alias, + AliasArgs<["v1"]>; +def mv2 : Flag<["-"], "mv2">, Group, Alias, + AliasArgs<["v2"]>; +def mv3 : Flag<["-"], "mv3">, Group, Alias, + AliasArgs<["v3"]>; +def mv4 : Flag<["-"], "mv4">, Group, Alias, + AliasArgs<["v4"]>; +def mv5 : Flag<["-"], "mv5">, Group, Alias, + AliasArgs<["v5"]>; // These are legacy user-facing driver-level option spellings. They are always // aliases for options that are spelled using the more common Unix / GNU flag diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index a006b52c5d..976f65c0e6 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -1671,40 +1671,47 @@ Hexagon_TC::GetCXXStdlibType(const ArgList &Args) const { return ToolChain::CST_Libstdcxx; } -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(); - } - } +static int getHexagonVersion(const ArgList &Args) { + Arg *A = Args.getLastArg(options::OPT_march_EQ, options::OPT_mcpu_EQ); + // Select the default CPU (v4) if none was given. + if (!A) + return 4; + + // FIXME: produce errors if we cannot parse the version. + StringRef WhichHexagon = A->getValue(); + if (WhichHexagon.startswith("hexagonv")) { + int Val; + if (!WhichHexagon.substr(sizeof("hexagonv") - 1).getAsInteger(10, Val)) + return Val; + } + if (WhichHexagon.startswith("v")) { + int Val; + if (!WhichHexagon.substr(1).getAsInteger(10, Val)) + return Val; } - return A; + + // FIXME: should probably be an error. + return 4; } 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) { - StringRef WhichHexagon = A->getValue(); - if (WhichHexagon.startswith("hexagon")) - return WhichHexagon.substr(sizeof("hexagon") - 1); - if (WhichHexagon != "") - return WhichHexagon; + int V = getHexagonVersion(Args); + // FIXME: We don't support versions < 4. We should error on them. + switch (V) { + default: + llvm_unreachable("Unexpected version"); + case 5: + return "v5"; + case 4: + return "v4"; + case 3: + return "v3"; + case 2: + return "v2"; + case 1: + return "v1"; } - - return "v4"; } // End Hexagon -- 2.40.0