[llvm-commits] [llvm] r164307 - in /llvm/trunk: include/llvm/Attributes.h lib/VMCore/Attributes.cpp

Bill Wendling isanbard at gmail.com
Thu Sep 20 08:20:36 PDT 2012


Author: void
Date: Thu Sep 20 10:20:36 2012
New Revision: 164307

URL: http://llvm.org/viewvc/llvm-project?rev=164307&view=rev
Log:
Remove more bare uses of the different Attribute enums.

Modified:
    llvm/trunk/include/llvm/Attributes.h
    llvm/trunk/lib/VMCore/Attributes.cpp

Modified: llvm/trunk/include/llvm/Attributes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Attributes.h?rev=164307&r1=164306&r2=164307&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Attributes.h (original)
+++ llvm/trunk/include/llvm/Attributes.h Thu Sep 20 10:20:36 2012
@@ -109,7 +109,12 @@
 
   // Attribute query methods.
   // FIXME: StackAlignment & Alignment attributes have no predicate methods.
-  bool hasAttributes() const { return Bits != 0; }
+  bool hasAttributes() const {
+    return Bits != 0;
+  }
+  bool hasAttributes(const Attributes &A) const {
+    return Bits & A.Bits;
+  }
 
   bool hasZExtAttr() const {
     return Bits & Attribute::ZExt_i;
@@ -159,6 +164,9 @@
   bool hasStackProtectReqAttr() const {
     return Bits & Attribute::StackProtectReq_i;
   }
+  bool hasAlignmentAttr() const {
+    return Bits & Attribute::Alignment_i;
+  }
   bool hasNoCaptureAttr() const {
     return Bits & Attribute::NoCapture_i;
   }
@@ -177,6 +185,9 @@
   bool hasReturnsTwiceAttr() const {
     return Bits & Attribute::ReturnsTwice_i;
   }
+  bool hasStackAlignmentAttr() const {
+    return Bits & Attribute::StackAlignment_i;
+  }
   bool hasUWTableAttr() const {
     return Bits & Attribute::UWTable_i;
   }
@@ -187,6 +198,13 @@
     return Bits & Attribute::AddressSafety_i;
   }
 
+  uint64_t getRawAlignment() const {
+    return Bits & Attribute::Alignment_i;
+  }
+  uint64_t getRawStackAlignment() const {
+    return Bits & Attribute::StackAlignment_i;
+  }
+
   // This is a "safe bool() operator".
   operator const void *() const { return Bits ? this : 0; }
   bool isEmptyOrSingleton() const { return (Bits & (Bits - 1)) == 0; }
@@ -278,11 +296,10 @@
 
 /// This returns the alignment field of an attribute as a byte alignment value.
 inline unsigned getAlignmentFromAttrs(Attributes A) {
-  Attributes Align = A & Attribute::Alignment;
-  if (!Align)
+  if (!A.hasAlignmentAttr())
     return 0;
 
-  return 1U << ((Align.Raw() >> 16) - 1);
+  return 1U << ((A.getRawAlignment() >> 16) - 1);
 }
 
 /// This turns an int stack alignment (which must be a power of 2) into
@@ -300,11 +317,10 @@
 /// This returns the stack alignment field of an attribute as a byte alignment
 /// value.
 inline unsigned getStackAlignmentFromAttrs(Attributes A) {
-  Attributes StackAlign = A & Attribute::StackAlignment;
-  if (!StackAlign)
+  if (!A.hasStackAlignmentAttr())
     return 0;
 
-  return 1U << ((StackAlign.Raw() >> 26) - 1);
+  return 1U << ((A.getRawStackAlignment() >> 26) - 1);
 }
 
 /// This returns an integer containing an encoding of all the
@@ -324,9 +340,9 @@
   // 11 bits.
 
   uint64_t EncodedAttrs = Attrs.Raw() & 0xffff;
-  if (Attrs & Attribute::Alignment)
+  if (Attrs.hasAlignmentAttr())
     EncodedAttrs |= (1ull << 16) <<
-      (((Attrs & Attribute::Alignment).Raw()-1) >> 16);
+      ((Attrs.getRawAlignment() - 1) >> 16);
   EncodedAttrs |= (Attrs.Raw() & (0xfffull << 21)) << 11;
 
   return EncodedAttrs;
@@ -428,7 +444,7 @@
   /// paramHasAttr - Return true if the specified parameter index has the
   /// specified attribute set.
   bool paramHasAttr(unsigned Idx, Attributes Attr) const {
-    return getAttributes(Idx) & Attr;
+    return getAttributes(Idx).hasAttributes(Attr);
   }
 
   /// getParamAlignment - Return the alignment for the specified function

Modified: llvm/trunk/lib/VMCore/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Attributes.cpp?rev=164307&r1=164306&r2=164307&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Attributes.cpp (original)
+++ llvm/trunk/lib/VMCore/Attributes.cpp Thu Sep 20 10:20:36 2012
@@ -78,12 +78,12 @@
     Result += "nonlazybind ";
   if (hasAddressSafetyAttr())
     Result += "address_safety ";
-  if (*this & Attribute::StackAlignment) { // FIXME
+  if (hasStackAlignmentAttr()) {
     Result += "alignstack(";
     Result += utostr(Attribute::getStackAlignmentFromAttrs(*this));
     Result += ") ";
   }
-  if (*this & Attribute::Alignment) { // FIXME
+  if (hasAlignmentAttr()) {
     Result += "align ";
     Result += utostr(Attribute::getAlignmentFromAttrs(*this));
     Result += " ";
@@ -263,7 +263,7 @@
   
   const SmallVector<AttributeWithIndex, 4> &Attrs = AttrList->Attrs;
   for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
-    if (Attrs[i].Attrs & Attr)
+    if (Attrs[i].Attrs.hasAttributes(Attr))
       return true;
   return false;
 }
@@ -274,8 +274,8 @@
 #ifndef NDEBUG
   // FIXME it is not obvious how this should work for alignment.
   // For now, say we can't change a known alignment.
-  Attributes OldAlign = OldAttrs & Attribute::Alignment;
-  Attributes NewAlign = Attrs & Attribute::Alignment;
+  unsigned OldAlign = Attribute::getAlignmentFromAttrs(OldAttrs);
+  unsigned NewAlign = Attribute::getAlignmentFromAttrs(Attrs);
   assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
          "Attempt to change alignment!");
 #endif
@@ -314,7 +314,7 @@
 #ifndef NDEBUG
   // FIXME it is not obvious how this should work for alignment.
   // For now, say we can't pass in alignment, which no current use does.
-  assert(!(Attrs & Attribute::Alignment) && "Attempt to exclude alignment!");
+  assert(!Attrs.hasAlignmentAttr() && "Attempt to exclude alignment!");
 #endif
   if (AttrList == 0) return AttrListPtr();
   





More information about the llvm-commits mailing list