From: Eric Christopher Date: Wed, 2 Sep 2015 20:40:12 +0000 (+0000) Subject: Migrate the target attribute parsing code to returning an instance X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9cf766fc9830166928bcba1bd9ef7b59a194eabf;p=clang Migrate the target attribute parsing code to returning an instance every time it's called rather than attempting to cache the result. It's unlikely to be called frequently and the overhead of using it in the first place is already factored out. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246706 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index 58d82ae326..c765d08a3c 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -1321,20 +1321,9 @@ def Target : InheritableAttr { let Subjects = SubjectList<[Function], ErrorDiag>; let Documentation = [TargetDocs]; let AdditionalMembers = [{ - StringRef CPU; - std::vector Features; - bool Parsed = false; - StringRef getCPU() { - if (!Parsed) - parse(); - return CPU; - } - std::vector &getFeatures() { - if (!Parsed) - parse(); - return Features; - } - void parse() { + typedef std::pair, StringRef> ParsedTargetAttr; + ParsedTargetAttr parse() const { + ParsedTargetAttr Ret; SmallVector AttrFeatures; getFeaturesStr().split(AttrFeatures, ","); @@ -1354,13 +1343,13 @@ def Target : InheritableAttr { // While we're here iterating check for a different target cpu. if (Feature.startswith("arch=")) - CPU = Feature.split("=").second.trim(); + Ret.second = Feature.split("=").second.trim(); else if (Feature.startswith("no-")) - Features.push_back("-" + Feature.split("-").second.str()); + Ret.first.push_back("-" + Feature.split("-").second.str()); else - Features.push_back("+" + Feature.str()); + Ret.first.push_back("+" + Feature.str()); } - Parsed = true; + return Ret; } }]; } diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index ed7bf60c02..2dc68622e7 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -1499,24 +1499,24 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, const FunctionDecl *FD = dyn_cast_or_null(TargetDecl); if (FD && FD->hasAttr()) { llvm::StringMap FeatureMap; - auto *TD = FD->getAttr(); + const auto *TD = FD->getAttr(); + TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse(); - // Make a copy of the features as passed on the command line. - std::vector FnFeatures = - getTarget().getTargetOpts().FeaturesAsWritten; + // Make a copy of the features as passed on the command line into the + // beginning of the additional features from the function to override. + ParsedAttr.first.insert( + ParsedAttr.first.begin(), + getTarget().getTargetOpts().FeaturesAsWritten.begin(), + getTarget().getTargetOpts().FeaturesAsWritten.end()); - std::vector &AttrFeatures = TD->getFeatures(); - std::copy(AttrFeatures.begin(), AttrFeatures.end(), - std::back_inserter(FnFeatures)); - - if (TD->getCPU() != "") - TargetCPU = TD->getCPU(); + if (ParsedAttr.second != "") + TargetCPU = ParsedAttr.second; // 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); + getTarget().initFeatureMap(FeatureMap, Diags, TargetCPU, ParsedAttr.first); // Produce the canonical string for this set of features. std::vector Features;