Make the 'get*AlignmentFromAttr' functions into member functions within the Attribute...
[oota-llvm.git] / lib / VMCore / Attributes.cpp
index 7d85ecb60d8be1e90900a9201554038af0264bd4..af8163fd40e308799cc797716ec6f926aa7b8dbe 100644 (file)
@@ -26,66 +26,66 @@ using namespace llvm;
 // Attribute Function Definitions
 //===----------------------------------------------------------------------===//
 
-std::string Attribute::getAsString(Attributes Attrs) {
+std::string Attributes::getAsString() const {
   std::string Result;
-  if (Attrs.hasZExtAttr())
+  if (hasZExtAttr())
     Result += "zeroext ";
-  if (Attrs.hasSExtAttr())
+  if (hasSExtAttr())
     Result += "signext ";
-  if (Attrs.hasNoReturnAttr())
+  if (hasNoReturnAttr())
     Result += "noreturn ";
-  if (Attrs.hasNoUnwindAttr())
+  if (hasNoUnwindAttr())
     Result += "nounwind ";
-  if (Attrs.hasUWTableAttr())
+  if (hasUWTableAttr())
     Result += "uwtable ";
-  if (Attrs.hasReturnsTwiceAttr())
+  if (hasReturnsTwiceAttr())
     Result += "returns_twice ";
-  if (Attrs.hasInRegAttr())
+  if (hasInRegAttr())
     Result += "inreg ";
-  if (Attrs.hasNoAliasAttr())
+  if (hasNoAliasAttr())
     Result += "noalias ";
-  if (Attrs.hasNoCaptureAttr())
+  if (hasNoCaptureAttr())
     Result += "nocapture ";
-  if (Attrs.hasStructRetAttr())
+  if (hasStructRetAttr())
     Result += "sret ";
-  if (Attrs.hasByValAttr())
+  if (hasByValAttr())
     Result += "byval ";
-  if (Attrs.hasNestAttr())
+  if (hasNestAttr())
     Result += "nest ";
-  if (Attrs.hasReadNoneAttr())
+  if (hasReadNoneAttr())
     Result += "readnone ";
-  if (Attrs.hasReadOnlyAttr())
+  if (hasReadOnlyAttr())
     Result += "readonly ";
-  if (Attrs.hasOptimizeForSizeAttr())
+  if (hasOptimizeForSizeAttr())
     Result += "optsize ";
-  if (Attrs.hasNoInlineAttr())
+  if (hasNoInlineAttr())
     Result += "noinline ";
-  if (Attrs.hasInlineHintAttr())
+  if (hasInlineHintAttr())
     Result += "inlinehint ";
-  if (Attrs.hasAlwaysInlineAttr())
+  if (hasAlwaysInlineAttr())
     Result += "alwaysinline ";
-  if (Attrs.hasStackProtectAttr())
+  if (hasStackProtectAttr())
     Result += "ssp ";
-  if (Attrs.hasStackProtectReqAttr())
+  if (hasStackProtectReqAttr())
     Result += "sspreq ";
-  if (Attrs.hasNoRedZoneAttr())
+  if (hasNoRedZoneAttr())
     Result += "noredzone ";
-  if (Attrs.hasNoImplicitFloatAttr())
+  if (hasNoImplicitFloatAttr())
     Result += "noimplicitfloat ";
-  if (Attrs.hasNakedAttr())
+  if (hasNakedAttr())
     Result += "naked ";
-  if (Attrs.hasNonLazyBindAttr())
+  if (hasNonLazyBindAttr())
     Result += "nonlazybind ";
-  if (Attrs.hasAddressSafetyAttr())
+  if (hasAddressSafetyAttr())
     Result += "address_safety ";
-  if (Attrs & Attribute::StackAlignment) {
+  if (hasStackAlignmentAttr()) {
     Result += "alignstack(";
-    Result += utostr(Attribute::getStackAlignmentFromAttrs(Attrs));
+    Result += utostr(getStackAlignment());
     Result += ") ";
   }
-  if (Attrs & Attribute::Alignment) {
+  if (hasAlignmentAttr()) {
     Result += "align ";
-    Result += utostr(Attribute::getAlignmentFromAttrs(Attrs));
+    Result += utostr(getAlignment());
     Result += " ";
   }
   // Trim the trailing space.
@@ -174,7 +174,7 @@ AttrListPtr AttrListPtr::get(ArrayRef<AttributeWithIndex> Attrs) {
   
 #ifndef NDEBUG
   for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
-    assert(Attrs[i].Attrs != Attribute::None && 
+    assert(Attrs[i].Attrs.hasAttributes() && 
            "Pointless attribute!");
     assert((!i || Attrs[i-1].Index < Attrs[i].Index) &&
            "Misordered AttributesList!");
@@ -247,13 +247,14 @@ const AttributeWithIndex &AttrListPtr::getSlot(unsigned Slot) const {
 /// returned.  Attributes for the result are denoted with Idx = 0.
 /// Function notes are denoted with idx = ~0.
 Attributes AttrListPtr::getAttributes(unsigned Idx) const {
-  if (AttrList == 0) return Attribute::None;
+  if (AttrList == 0) return Attributes();
   
   const SmallVector<AttributeWithIndex, 4> &Attrs = AttrList->Attrs;
   for (unsigned i = 0, e = Attrs.size(); i != e && Attrs[i].Index <= Idx; ++i)
     if (Attrs[i].Index == Idx)
       return Attrs[i].Attrs;
-  return Attribute::None;
+
+  return Attributes();
 }
 
 /// hasAttrSomewhere - Return true if the specified attribute is set for at
@@ -263,7 +264,7 @@ bool AttrListPtr::hasAttrSomewhere(Attributes Attr) const {
   
   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 +275,8 @@ AttrListPtr AttrListPtr::addAttr(unsigned Idx, Attributes Attrs) const {
 #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 = OldAttrs.getAlignment();
+  unsigned NewAlign = Attrs.getAlignment();
   assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
          "Attempt to change alignment!");
 #endif
@@ -314,7 +315,7 @@ AttrListPtr AttrListPtr::removeAttr(unsigned Idx, Attributes Attrs) const {
 #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();