From 49062a51b444ecf222013eebfee29ad2a5d21609 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Tue, 22 Dec 2015 03:12:34 +0000 Subject: [PATCH] Pull out a bunch of duplicated option handling code into its own function and use for the targets that can easily support it. llvm-svn: 256230 --- clang/lib/Driver/Tools.cpp | 65 ++++++++++++++------------------------ 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index efba28cfb5d9..fb50d72491bd 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -52,6 +52,24 @@ using namespace clang::driver::tools; using namespace clang; using namespace llvm::opt; +static void handleTargetFeaturesGroup(const ArgList &Args, + std::vector &Features, + OptSpecifier Group) { + for (const Arg *A : Args.filtered(Group)) { + StringRef Name = A->getOption().getName(); + A->claim(); + + // Skip over "-m". + assert(Name.startswith("m") && "Invalid feature name."); + Name = Name.substr(1); + + bool IsNegative = Name.startswith("no-"); + if (IsNegative) + Name = Name.substr(3); + Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); + } +} + static const char *getSparcAsmModeForCPU(StringRef Name, const llvm::Triple &Triple) { if (Triple.getArch() == llvm::Triple::sparcv9) { @@ -1410,19 +1428,7 @@ static std::string getPPCTargetCPU(const ArgList &Args) { static void getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector &Features) { - for (const Arg *A : Args.filtered(options::OPT_m_ppc_Features_Group)) { - StringRef Name = A->getOption().getName(); - A->claim(); - - // Skip over "-m". - assert(Name.startswith("m") && "Invalid feature name."); - Name = Name.substr(1); - - bool IsNegative = Name.startswith("no-"); - if (IsNegative) - Name = Name.substr(3); - Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); - } + handleTargetFeaturesGroup(Args, Features, options::OPT_m_ppc_Features_Group); ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args); if (FloatABI == ppc::FloatABI::Soft && @@ -2005,20 +2011,7 @@ static void getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple, // Now add any that the user explicitly requested on the command line, // which may override the defaults. - for (const Arg *A : Args.filtered(options::OPT_m_x86_Features_Group)) { - StringRef Name = A->getOption().getName(); - A->claim(); - - // Skip over "-m". - assert(Name.startswith("m") && "Invalid feature name."); - Name = Name.substr(1); - - bool IsNegative = Name.startswith("no-"); - if (IsNegative) - Name = Name.substr(3); - - Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); - } + handleTargetFeaturesGroup(Args, Features, options::OPT_m_x86_Features_Group); } void Clang::AddX86TargetArgs(const ArgList &Args, @@ -2247,6 +2240,9 @@ static void getHexagonTargetFeatures(const ArgList &Args, std::vector &Features) { bool HasHVX = false, HasHVXD = false; + // FIXME: This should be able to use handleTargetFeaturesGroup except it is + // doing dependent option handling here rather than in initFeatureMap or a + // similar handler. for (auto &A : Args) { auto &Opt = A->getOption(); if (Opt.matches(options::OPT_mhexagon_hvx)) @@ -2268,20 +2264,7 @@ static void getHexagonTargetFeatures(const ArgList &Args, static void getWebAssemblyTargetFeatures(const ArgList &Args, std::vector &Features) { - for (const Arg *A : Args.filtered(options::OPT_m_wasm_Features_Group)) { - StringRef Name = A->getOption().getName(); - A->claim(); - - // Skip over "-m". - assert(Name.startswith("m") && "Invalid feature name."); - Name = Name.substr(1); - - bool IsNegative = Name.startswith("no-"); - if (IsNegative) - Name = Name.substr(3); - - Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); - } + handleTargetFeaturesGroup(Args, Features, options::OPT_m_wasm_Features_Group); } static void getTargetFeatures(const ToolChain &TC, const llvm::Triple &Triple,