Make the 'get*AlignmentFromAttr' functions into member functions within the Attribute...
authorBill Wendling <isanbard@gmail.com>
Thu, 20 Sep 2012 16:27:05 +0000 (16:27 +0000)
committerBill Wendling <isanbard@gmail.com>
Thu, 20 Sep 2012 16:27:05 +0000 (16:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164308 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Attributes.h
lib/AsmParser/LLParser.cpp
lib/CodeGen/MachineFunction.cpp
lib/Target/CppBackend/CPPBackend.cpp
lib/VMCore/Attributes.cpp

index 01b3be8cb60f5df0abea154053b9cd2b5960a3c4..2a7e0dea4fdedf1c7735e529ac8ab41ae5f309f6 100644 (file)
@@ -205,6 +205,24 @@ public:
     return Bits & Attribute::StackAlignment_i;
   }
 
     return Bits & Attribute::StackAlignment_i;
   }
 
+  /// This returns the alignment field of an attribute as a byte alignment
+  /// value.
+  unsigned getAlignment() const {
+    if (!hasAlignmentAttr())
+      return 0;
+
+    return 1U << ((getRawAlignment() >> 16) - 1);
+  }
+
+  /// This returns the stack alignment field of an attribute as a byte alignment
+  /// value.
+  unsigned getStackAlignment() const {
+    if (!hasStackAlignmentAttr())
+      return 0;
+
+    return 1U << ((getRawStackAlignment() >> 26) - 1);
+  }
+
   // This is a "safe bool() operator".
   operator const void *() const { return Bits ? this : 0; }
   bool isEmptyOrSingleton() const { return (Bits & (Bits - 1)) == 0; }
   // This is a "safe bool() operator".
   operator const void *() const { return Bits ? this : 0; }
   bool isEmptyOrSingleton() const { return (Bits & (Bits - 1)) == 0; }
@@ -212,8 +230,9 @@ public:
     return Bits == Attrs.Bits;
   }
   bool operator != (const Attributes &Attrs) const {
     return Bits == Attrs.Bits;
   }
   bool operator != (const Attributes &Attrs) const {
-    return Bits != Attrs.Bits;
+    return !(this == Attrs);
   }
   }
+
   Attributes operator | (const Attributes &Attrs) const {
     return Attributes(Bits | Attrs.Bits);
   }
   Attributes operator | (const Attributes &Attrs) const {
     return Attributes(Bits | Attrs.Bits);
   }
@@ -294,14 +313,6 @@ inline Attributes constructAlignmentFromInt(unsigned i) {
   return Attributes((Log2_32(i)+1) << 16);
 }
 
   return Attributes((Log2_32(i)+1) << 16);
 }
 
-/// This returns the alignment field of an attribute as a byte alignment value.
-inline unsigned getAlignmentFromAttrs(Attributes A) {
-  if (!A.hasAlignmentAttr())
-    return 0;
-
-  return 1U << ((A.getRawAlignment() >> 16) - 1);
-}
-
 /// This turns an int stack alignment (which must be a power of 2) into
 /// the form used internally in Attributes.
 inline Attributes constructStackAlignmentFromInt(unsigned i) {
 /// This turns an int stack alignment (which must be a power of 2) into
 /// the form used internally in Attributes.
 inline Attributes constructStackAlignmentFromInt(unsigned i) {
@@ -314,15 +325,6 @@ inline Attributes constructStackAlignmentFromInt(unsigned i) {
   return Attributes((Log2_32(i)+1) << 26);
 }
 
   return Attributes((Log2_32(i)+1) << 26);
 }
 
-/// This returns the stack alignment field of an attribute as a byte alignment
-/// value.
-inline unsigned getStackAlignmentFromAttrs(Attributes A) {
-  if (!A.hasStackAlignmentAttr())
-    return 0;
-
-  return 1U << ((A.getRawStackAlignment() >> 26) - 1);
-}
-
 /// This returns an integer containing an encoding of all the
 /// LLVM attributes found in the given attribute bitset.  Any
 /// change to this encoding is a breaking change to bitcode
 /// This returns an integer containing an encoding of all the
 /// LLVM attributes found in the given attribute bitset.  Any
 /// change to this encoding is a breaking change to bitcode
@@ -450,7 +452,7 @@ public:
   /// getParamAlignment - Return the alignment for the specified function
   /// parameter.
   unsigned getParamAlignment(unsigned Idx) const {
   /// getParamAlignment - Return the alignment for the specified function
   /// parameter.
   unsigned getParamAlignment(unsigned Idx) const {
-    return Attribute::getAlignmentFromAttrs(getAttributes(Idx));
+    return getAttributes(Idx).getAlignment();
   }
 
   /// hasAttrSomewhere - Return true if the specified attribute is set for at
   }
 
   /// hasAttrSomewhere - Return true if the specified attribute is set for at
index 2e4af3abb760d0c54cfef30bf97da88a389241e0..c1d5272ca50b829c733caab9bac115098117cff1 100644 (file)
@@ -2717,7 +2717,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
 
   // If the alignment was parsed as an attribute, move to the alignment field.
   if (FuncAttrs & Attribute::Alignment) {
 
   // If the alignment was parsed as an attribute, move to the alignment field.
   if (FuncAttrs & Attribute::Alignment) {
-    Alignment = Attribute::getAlignmentFromAttrs(FuncAttrs);
+    Alignment = FuncAttrs.getAlignment();
     FuncAttrs &= ~Attribute::Alignment;
   }
 
     FuncAttrs &= ~Attribute::Alignment;
   }
 
index 328722bad48b17a817db49da7d6ea41a983fdd99..304e39e1592deb95a1b1bcb1c78bb2241c6b61ed 100644 (file)
@@ -60,8 +60,8 @@ MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM,
   MFInfo = 0;
   FrameInfo = new (Allocator) MachineFrameInfo(*TM.getFrameLowering());
   if (Fn->hasFnAttr(Attribute::StackAlignment))
   MFInfo = 0;
   FrameInfo = new (Allocator) MachineFrameInfo(*TM.getFrameLowering());
   if (Fn->hasFnAttr(Attribute::StackAlignment))
-    FrameInfo->ensureMaxAlignment(Attribute::getStackAlignmentFromAttrs(
-        Fn->getAttributes().getFnAttributes()));
+    FrameInfo->ensureMaxAlignment(Fn->getAttributes().
+                                  getFnAttributes().getStackAlignment());
   ConstantPool = new (Allocator) MachineConstantPool(TM.getTargetData());
   Alignment = TM.getTargetLowering()->getMinFunctionAlignment();
   // FIXME: Shouldn't use pref alignment if explicit alignment is set on Fn.
   ConstantPool = new (Allocator) MachineConstantPool(TM.getTargetData());
   Alignment = TM.getTargetLowering()->getMinFunctionAlignment();
   // FIXME: Shouldn't use pref alignment if explicit alignment is set on Fn.
index 4ddcd38aca6e763672499c9a30d8bc3b7959c6ad..444da2bb21eef87d517cf9a29bc1febe29b8aae8 100644 (file)
@@ -508,7 +508,7 @@ void CppWriter::printAttributes(const AttrListPtr &PAL,
 #undef HANDLE_ATTR
       if (attrs & Attribute::StackAlignment)
         Out << " | Attribute::constructStackAlignmentFromInt("
 #undef HANDLE_ATTR
       if (attrs & Attribute::StackAlignment)
         Out << " | Attribute::constructStackAlignmentFromInt("
-            << Attribute::getStackAlignmentFromAttrs(attrs)
+            << attrs.getStackAlignment()
             << ")"; 
       attrs &= ~Attribute::StackAlignment;
       assert(attrs == 0 && "Unhandled attribute!");
             << ")"; 
       attrs &= ~Attribute::StackAlignment;
       assert(attrs == 0 && "Unhandled attribute!");
index 3a87da44dd16ef1597a36b8b38487abfaa3fa46d..af8163fd40e308799cc797716ec6f926aa7b8dbe 100644 (file)
@@ -80,12 +80,12 @@ std::string Attributes::getAsString() const {
     Result += "address_safety ";
   if (hasStackAlignmentAttr()) {
     Result += "alignstack(";
     Result += "address_safety ";
   if (hasStackAlignmentAttr()) {
     Result += "alignstack(";
-    Result += utostr(Attribute::getStackAlignmentFromAttrs(*this));
+    Result += utostr(getStackAlignment());
     Result += ") ";
   }
   if (hasAlignmentAttr()) {
     Result += "align ";
     Result += ") ";
   }
   if (hasAlignmentAttr()) {
     Result += "align ";
-    Result += utostr(Attribute::getAlignmentFromAttrs(*this));
+    Result += utostr(getAlignment());
     Result += " ";
   }
   // Trim the trailing space.
     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) {
   
 #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!");
            "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 {
 /// 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;
   
   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
 }
 
 /// hasAttrSomewhere - Return true if the specified attribute is set for at
@@ -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.
 #ifndef NDEBUG
   // FIXME it is not obvious how this should work for alignment.
   // For now, say we can't change a known alignment.
-  unsigned OldAlign = Attribute::getAlignmentFromAttrs(OldAttrs);
-  unsigned NewAlign = Attribute::getAlignmentFromAttrs(Attrs);
+  unsigned OldAlign = OldAttrs.getAlignment();
+  unsigned NewAlign = Attrs.getAlignment();
   assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
          "Attempt to change alignment!");
 #endif
   assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
          "Attempt to change alignment!");
 #endif