[PATCH] D35574: Convert attribute 'target' parsing from a 'pair' to a 'struct' to make further improvements easier

2017-07-18 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308357: Convert attribute 'target' parsing from a 'pair' to 
a 'struct' to make further… (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D35574?vs=107131=107171#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35574

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp


Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -4499,18 +4499,19 @@
 
 // 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(),
+ParsedAttr.Features.insert(ParsedAttr.Features.begin(),
 Target.getTargetOpts().FeaturesAsWritten.begin(),
 Target.getTargetOpts().FeaturesAsWritten.end());
 
-if (ParsedAttr.second != "")
-  TargetCPU = ParsedAttr.second;
+if (ParsedAttr.Architecture != "")
+  TargetCPU = ParsedAttr.Architecture ;
 
 // 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.
-Target.initFeatureMap(FeatureMap, getDiags(), TargetCPU, ParsedAttr.first);
+Target.initFeatureMap(FeatureMap, getDiags(), TargetCPU,
+  ParsedAttr.Features);
   } else {
 Target.initFeatureMap(FeatureMap, getDiags(), TargetCPU,
   Target.getTargetOpts().Features);
Index: cfe/trunk/lib/CodeGen/CGCall.cpp
===
--- cfe/trunk/lib/CodeGen/CGCall.cpp
+++ cfe/trunk/lib/CodeGen/CGCall.cpp
@@ -1877,8 +1877,8 @@
   // the function.
   const auto *TD = FD->getAttr();
   TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
-  if (ParsedAttr.second != "")
-TargetCPU = ParsedAttr.second;
+  if (ParsedAttr.Architecture != "")
+TargetCPU = ParsedAttr.Architecture;
   if (TargetCPU != "")
 FuncAttrs.addAttribute("target-cpu", TargetCPU);
   if (!Features.empty()) {
Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -1802,11 +1802,18 @@
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [TargetDocs];
   let AdditionalMembers = [{
-typedef std::pair ParsedTargetAttr;
+struct ParsedTargetAttr {
+  std::vector Features;
+  StringRef Architecture;
+  bool DuplicateArchitecture = false;
+};
 ParsedTargetAttr parse() const {
+  return parse(getFeaturesStr());
+}
+static ParsedTargetAttr parse(StringRef Features) {
   ParsedTargetAttr Ret;
   SmallVector AttrFeatures;
-  getFeaturesStr().split(AttrFeatures, ",");
+  Features.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.
@@ -1823,12 +1830,15 @@
  continue;
 
 // While we're here iterating check for a different target cpu.
-if (Feature.startswith("arch="))
-  Ret.second = Feature.split("=").second.trim();
-else if (Feature.startswith("no-"))
-  Ret.first.push_back("-" + Feature.split("-").second.str());
+if (Feature.startswith("arch=")) {
+  if (!Ret.Architecture.empty())
+Ret.DuplicateArchitecture = true;
+  else
+Ret.Architecture = Feature.split("=").second.trim();
+} else if (Feature.startswith("no-"))
+  Ret.Features.push_back("-" + Feature.split("-").second.str());
 else
-  Ret.first.push_back("+" + Feature.str());
+  Ret.Features.push_back("+" + Feature.str());
   }
   return Ret;
 }


Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -4499,18 +4499,19 @@
 
 // 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(),
+ParsedAttr.Features.insert(ParsedAttr.Features.begin(),
 Target.getTargetOpts().FeaturesAsWritten.begin(),
 Target.getTargetOpts().FeaturesAsWritten.end());
 
-if 

[PATCH] D35574: Convert attribute 'target' parsing from a 'pair' to a 'struct' to make further improvements easier

2017-07-18 Thread Eric Christopher via Phabricator via cfe-commits
echristo accepted this revision.
echristo added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D35574



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35574: Convert attribute 'target' parsing from a 'pair' to a 'struct' to make further improvements easier

2017-07-18 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.

The attribute 'target' parse function previously returned a pair.  Convert this 
to a 'pair' in order to add more functionality, and improve usability.


https://reviews.llvm.org/D35574

Files:
  include/clang/Basic/Attr.td
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CodeGenModule.cpp


Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -4499,18 +4499,19 @@
 
 // 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(),
+ParsedAttr.Features.insert(ParsedAttr.Features.begin(),
 Target.getTargetOpts().FeaturesAsWritten.begin(),
 Target.getTargetOpts().FeaturesAsWritten.end());
 
-if (ParsedAttr.second != "")
-  TargetCPU = ParsedAttr.second;
+if (ParsedAttr.Architecture != "")
+  TargetCPU = ParsedAttr.Architecture ;
 
 // 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.
-Target.initFeatureMap(FeatureMap, getDiags(), TargetCPU, ParsedAttr.first);
+Target.initFeatureMap(FeatureMap, getDiags(), TargetCPU,
+  ParsedAttr.Features);
   } else {
 Target.initFeatureMap(FeatureMap, getDiags(), TargetCPU,
   Target.getTargetOpts().Features);
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1877,8 +1877,8 @@
   // the function.
   const auto *TD = FD->getAttr();
   TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
-  if (ParsedAttr.second != "")
-TargetCPU = ParsedAttr.second;
+  if (ParsedAttr.Architecture != "")
+TargetCPU = ParsedAttr.Architecture;
   if (TargetCPU != "")
 FuncAttrs.addAttribute("target-cpu", TargetCPU);
   if (!Features.empty()) {
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1802,11 +1802,18 @@
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [TargetDocs];
   let AdditionalMembers = [{
-typedef std::pair ParsedTargetAttr;
+struct ParsedTargetAttr {
+  std::vector Features;
+  StringRef Architecture;
+  bool DuplicateArchitecture = false;
+};
 ParsedTargetAttr parse() const {
+  return parse(getFeaturesStr());
+}
+static ParsedTargetAttr parse(StringRef Features) {
   ParsedTargetAttr Ret;
   SmallVector AttrFeatures;
-  getFeaturesStr().split(AttrFeatures, ",");
+  Features.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.
@@ -1823,12 +1830,15 @@
  continue;
 
 // While we're here iterating check for a different target cpu.
-if (Feature.startswith("arch="))
-  Ret.second = Feature.split("=").second.trim();
-else if (Feature.startswith("no-"))
-  Ret.first.push_back("-" + Feature.split("-").second.str());
+if (Feature.startswith("arch=")) {
+  if (!Ret.Architecture.empty())
+Ret.DuplicateArchitecture = true;
+  else
+Ret.Architecture = Feature.split("=").second.trim();
+} else if (Feature.startswith("no-"))
+  Ret.Features.push_back("-" + Feature.split("-").second.str());
 else
-  Ret.first.push_back("+" + Feature.str());
+  Ret.Features.push_back("+" + Feature.str());
   }
   return Ret;
 }


Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -4499,18 +4499,19 @@
 
 // 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(),
+ParsedAttr.Features.insert(ParsedAttr.Features.begin(),
 Target.getTargetOpts().FeaturesAsWritten.begin(),
 Target.getTargetOpts().FeaturesAsWritten.end());
 
-if (ParsedAttr.second != "")
-  TargetCPU = ParsedAttr.second;
+if (ParsedAttr.Architecture != "")
+  TargetCPU = ParsedAttr.Architecture ;
 
 // Now populate the feature map, first with the TargetCPU which is either
 // the default or a new one from the target