Factor out cycle-finder code and make it generic.
[oota-llvm.git] / include / llvm / Attributes.h
index 2b70596b33d22d27f35f71c10f6992238a857e45..972dbfa518df570edeb0bff6ffe03b25117ef6ee 100644 (file)
@@ -79,11 +79,25 @@ Attributes typeIncompatible(const Type *Ty);
 /// This turns an int alignment (a power of 2, normally) into the
 /// form used internally in Attributes.
 inline Attributes constructAlignmentFromInt(unsigned i) {
+  // Default alignment, allow the target to define how to align it.
+  if (i == 0)
+    return 0;
+
   assert(isPowerOf2_32(i) && "Alignment must be a power of two.");
   assert(i <= 0x40000000 && "Alignment too large.");
   return (Log2_32(i)+1) << 16;
 }
 
+/// 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 == 0)
+    return 0;
+  
+  return 1U << ((Align >> 16) - 1);
+}
+  
+  
 /// The set of Attributes set in Attributes is converted to a
 /// string of equivalent mnemonics. This is, presumably, for writing out
 /// the mnemonics for the assembly writer. 
@@ -180,7 +194,7 @@ public:
   /// getParamAlignment - Return the alignment for the specified function
   /// parameter.
   unsigned getParamAlignment(unsigned Idx) const {
-    return 1ull << (((getAttributes(Idx) & Attribute::Alignment) >> 16) - 1);
+    return Attribute::getAlignmentFromAttrs(getAttributes(Idx));
   }
   
   /// hasAttrSomewhere - Return true if the specified attribute is set for at