Add a 'StringRef' version of hasAttribute.
authorBill Wendling <isanbard@gmail.com>
Wed, 6 Feb 2013 01:33:42 +0000 (01:33 +0000)
committerBill Wendling <isanbard@gmail.com>
Wed, 6 Feb 2013 01:33:42 +0000 (01:33 +0000)
Fix the 'operator==' and 'hasAttributes' queries to take into account
target-dependent attributes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174481 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Attributes.h
lib/IR/Attributes.cpp

index d0fe2e15bc7d864a848b6a3b654b1120c61c6ca9..e73be5db22fddbf6cfc14362a40aef84cce1de98 100644 (file)
@@ -404,6 +404,10 @@ public:
   /// \brief Return true if the builder has the specified attribute.
   bool contains(Attribute::AttrKind A) const;
 
+  /// \brief Return true if the builder has the specified target-dependent
+  /// attribute.
+  bool contains(StringRef A) const;
+
   /// \brief Return true if the builder has IR-level attributes.
   bool hasAttributes() const;
 
index 67ab4eaa699e866396e6cb0e2d189a7ccb274696..99fafae88e88bbb91fed8ea37f340f2d229e3414 100644 (file)
@@ -977,8 +977,12 @@ bool AttrBuilder::contains(Attribute::AttrKind A) const {
   return Attrs.count(A);
 }
 
+bool AttrBuilder::contains(StringRef A) const {
+  return TargetDepAttrs.find(A) != TargetDepAttrs.end();
+}
+
 bool AttrBuilder::hasAttributes() const {
-  return !Attrs.empty();
+  return !Attrs.empty() || !TargetDepAttrs.empty();
 }
 
 bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const {
@@ -1005,9 +1009,17 @@ bool AttrBuilder::hasAlignmentAttr() const {
 }
 
 bool AttrBuilder::operator==(const AttrBuilder &B) {
-  SmallVector<Attribute::AttrKind, 8> This(Attrs.begin(), Attrs.end());
-  SmallVector<Attribute::AttrKind, 8> That(B.Attrs.begin(), B.Attrs.end());
-  return This == That;
+  for (DenseSet<Attribute::AttrKind>::iterator I = Attrs.begin(),
+         E = Attrs.end(); I != E; ++I)
+    if (!B.Attrs.count(*I))
+      return false;
+
+  for (td_const_iterator I = TargetDepAttrs.begin(),
+         E = TargetDepAttrs.end(); I != E; ++I)
+    if (B.TargetDepAttrs.find(I->first) == B.TargetDepAttrs.end())
+      return false;
+
+  return Alignment == B.Alignment && StackAlignment == B.StackAlignment;
 }
 
 AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) {