From 228710dfaa8ded49d6fd4835a9d7a51f37222fe5 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Mon, 31 Aug 2015 23:19:55 +0000 Subject: [PATCH] Revert "Pull the target attribute parsing out of CGCall and onto TargetInfo." This reverts commit r246468 while we figure out what to do about Basic and AST. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246508 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/TargetInfo.h | 17 ++++++------ lib/Basic/TargetInfo.cpp | 47 -------------------------------- lib/CodeGen/CGCall.cpp | 44 ++++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 64 deletions(-) diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index 33c02bf1da..b19d57c716 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -15,9 +15,7 @@ #ifndef LLVM_CLANG_BASIC_TARGETINFO_H #define LLVM_CLANG_BASIC_TARGETINFO_H -#include "clang/AST/Attr.h" #include "clang/Basic/AddressSpaces.h" -#include "clang/Basic/Attributes.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/Specifiers.h" #include "clang/Basic/TargetCXXABI.h" @@ -742,18 +740,21 @@ public: /// language options which change the target configuration. virtual void adjust(const LangOptions &Opts); - /// \brief Parse a __target__ attribute and get the cpu/feature strings - /// out of it for later use. - typedef std::pair> ParsedTargetAttr; - ParsedTargetAttr parseTargetAttr(const TargetAttr *TA) const; - /// \brief Initialize the map with the default set of target features for the /// CPU this should include all legal feature strings on the target. /// /// \return False on error (invalid features). virtual bool initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU, - std::vector &FeatureVec) const; + std::vector &FeatureVec) const { + for (const auto &F : FeatureVec) { + const char *Name = F.c_str(); + // Apply the feature via the target. + bool Enabled = Name[0] == '+'; + setFeatureEnabled(Features, Name + 1, Enabled); + } + return true; + } /// \brief Get the ABI currently in use. virtual StringRef getABI() const { return StringRef(); } diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 2ee705272d..30378a5a75 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -650,50 +650,3 @@ bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints, return true; } - -bool TargetInfo::initFeatureMap(llvm::StringMap &Features, - DiagnosticsEngine &Diags, StringRef CPU, - std::vector &FeatureVec) const { - for (const auto &F : FeatureVec) { - const char *Name = F.c_str(); - // Apply the feature via the target. - bool Enabled = Name[0] == '+'; - setFeatureEnabled(Features, Name + 1, Enabled); - } - return true; -} - -TargetInfo::ParsedTargetAttr -TargetInfo::parseTargetAttr(const TargetAttr *TA) const { - std::pair> RetPair; - - // Grab the target attribute string. - StringRef FeaturesStr = TA->getFeatures(); - SmallVector AttrFeatures; - FeaturesStr.split(AttrFeatures, ","); - - // Grab the various features and prepend a "+" to turn on the feature to - // the backend and add them to our existing set of features. - for (auto &Feature : AttrFeatures) { - // Go ahead and trim whitespace rather than either erroring or - // accepting it weirdly. - Feature = Feature.trim(); - - // While we're here iterating check for a different target cpu. - if (Feature.startswith("arch=")) - RetPair.first = Feature.split("=").second.trim(); - else if (Feature.startswith("tune=")) - // We don't support cpu tuning this way currently. - ; - else if (Feature.startswith("fpmath=")) - // TODO: Support the fpmath option this way. It will require checking - // overall feature validity for the function with the rest of the - // attributes on the function. - ; - else if (Feature.startswith("no-")) - RetPair.second.push_back("-" + Feature.split("-").second.str()); - else - RetPair.second.push_back("+" + Feature.str()); - } - return RetPair; -} diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index aef12ec60b..74a47bfc2b 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -1499,19 +1499,45 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, const FunctionDecl *FD = dyn_cast_or_null(TargetDecl); if (FD && FD->getAttr()) { llvm::StringMap FeatureMap; - + const auto *TD = FD->getAttr(); + + // Make a copy of the features as passed on the command line. + std::vector FnFeatures = + getTarget().getTargetOpts().FeaturesAsWritten; + + // Grab the target attribute string. + StringRef FeaturesStr = TD->getFeatures(); + SmallVector AttrFeatures; + FeaturesStr.split(AttrFeatures, ","); + + // Grab the various features and prepend a "+" to turn on the feature to + // the backend and add them to our existing set of features. + for (auto &Feature : AttrFeatures) { + // Go ahead and trim whitespace rather than either erroring or + // accepting it weirdly. + Feature = Feature.trim(); + + // While we're here iterating check for a different target cpu. + if (Feature.startswith("arch=")) + TargetCPU = Feature.split("=").second.trim(); + else if (Feature.startswith("tune=")) + // We don't support cpu tuning this way currently. + ; + else if (Feature.startswith("fpmath=")) + // TODO: Support the fpmath option this way. It will require checking + // overall feature validity for the function with the rest of the + // attributes on the function. + ; + else if (Feature.startswith("no-")) + FnFeatures.push_back("-" + Feature.split("-").second.str()); + else + FnFeatures.push_back("+" + Feature.str()); + } // Now populate the feature map, first with the TargetCPU which is either // the default or a new one from the target attribute string. Then we'll // use the passed in features (FeaturesAsWritten) along with the new ones // from the attribute. - TargetInfo::ParsedTargetAttr PTA = - getTarget().parseTargetAttr(FD->getAttr()); - if (PTA.first != "") - TargetCPU = PTA.first; - PTA.second.insert(PTA.second.begin(), - getTarget().getTargetOpts().FeaturesAsWritten.begin(), - getTarget().getTargetOpts().FeaturesAsWritten.end()); - getTarget().initFeatureMap(FeatureMap, Diags, TargetCPU, PTA.second); + getTarget().initFeatureMap(FeatureMap, Diags, TargetCPU, FnFeatures); // Produce the canonical string for this set of features. std::vector Features; -- 2.40.0