Add a new helper method to get log2(type alignment)
authorChris Lattner <sabre@nondot.org>
Tue, 17 Aug 2004 19:13:00 +0000 (19:13 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 17 Aug 2004 19:13:00 +0000 (19:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15887 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/TargetData.cpp

index 8aea15430833caadf223e2d771db5e4263f96674..22dde60d8f61f7b085dadab85f7e5fc2204492d2 100644 (file)
@@ -21,6 +21,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constants.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
+#include "Support/MathExtras.h"
 using namespace llvm;
 
 // Handle the Pass registration stuff necessary to use TargetData's.
@@ -201,6 +202,12 @@ unsigned char TargetData::getTypeAlignment(const Type *Ty) const {
   return Align;
 }
 
+unsigned char TargetData::getTypeAlignmentShift(const Type *Ty) const {
+  unsigned Align = getTypeAlignment(Ty);
+  assert(!(Align & (Align-1)) && "Alignment is not a power of two!");
+  return log2(Align);
+}
+
 /// getIntPtrType - Return an unsigned integer type that is the same size or
 /// greater to the host pointer size.
 const Type *TargetData::getIntPtrType() const {