From d40722e26787a6e080e0de30d8980bc15da93ec9 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Mon, 31 Aug 2015 18:39:22 +0000 Subject: Pull the target attribute parsing out of CGCall and onto TargetInfo. Also: - Add a typedef to make working with the result easier. - Update callers to use the new function. - Make initFeatureMap out of line. llvm-svn: 246468 --- clang/lib/CodeGen/CGCall.cpp | 44 +++++++++----------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) (limited to 'clang/lib/CodeGen') diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 74a47bfc2b6..aef12ec60b6 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1499,45 +1499,19 @@ 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. - getTarget().initFeatureMap(FeatureMap, Diags, TargetCPU, FnFeatures); + 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); // Produce the canonical string for this set of features. std::vector Features; -- cgit v1.2.3