]> granicus.if.org Git - clang/commitdiff
Migrate the target attribute parsing code to returning an instance
authorEric Christopher <echristo@gmail.com>
Wed, 2 Sep 2015 20:40:12 +0000 (20:40 +0000)
committerEric Christopher <echristo@gmail.com>
Wed, 2 Sep 2015 20:40:12 +0000 (20:40 +0000)
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

include/clang/Basic/Attr.td
lib/CodeGen/CGCall.cpp

index 58d82ae326ab3ca80cecba3ffc2cb960c77d1cf0..c765d08a3c2c108ade7e3d8e788b2369742d4af6 100644 (file)
@@ -1321,20 +1321,9 @@ def Target : InheritableAttr {
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [TargetDocs];
   let AdditionalMembers = [{
-    StringRef CPU;
-    std::vector<std::string> Features;
-    bool Parsed = false;
-    StringRef getCPU() {
-      if (!Parsed)
-        parse();
-      return CPU;
-    }
-    std::vector<std::string> &getFeatures() {
-      if (!Parsed)
-        parse();
-      return Features;
-    }
-    void parse() {
+    typedef std::pair<std::vector<std::string>, StringRef> ParsedTargetAttr;
+    ParsedTargetAttr parse() const {
+      ParsedTargetAttr Ret;
       SmallVector<StringRef, 1> 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;
     }
   }];
 }
index ed7bf60c024c1373717157af1f270f9f8ded5d21..2dc68622e773140152bfcb23c7c614fc3ea3901e 100644 (file)
@@ -1499,24 +1499,24 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
     const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl);
     if (FD && FD->hasAttr<TargetAttr>()) {
       llvm::StringMap<bool> FeatureMap;
-      auto *TD = FD->getAttr<TargetAttr>();
+      const auto *TD = FD->getAttr<TargetAttr>();
+      TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
 
-      // Make a copy of the features as passed on the command line.
-      std::vector<std::string> 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<std::string> &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<std::string> Features;