clean up load and stores alot
[oota-llvm.git] / lib / Target / TargetData.cpp
index 8aea15430833caadf223e2d771db5e4263f96674..fc58f577497143d12d2ae23afcac08fb3cf72f6d 100644 (file)
@@ -21,6 +21,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constants.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
+#include "llvm/Support/MathExtras.h"
 using namespace llvm;
 
 // Handle the Pass registration stuff necessary to use TargetData's.
@@ -106,7 +107,7 @@ TargetData::TargetData(const std::string &ToolName, const Module *M) {
   PointerAlignment = PointerSize;
   DoubleAlignment  = PointerSize;
   FloatAlignment   = 4;
-  LongAlignment    = 8;
+  LongAlignment    = PointerSize;
   IntAlignment     = 4;
   ShortAlignment   = 2;
   ByteAlignment    = 1;
@@ -174,6 +175,13 @@ static inline void getTypeInfo(const Type *Ty, const TargetData *TD,
     Size = AlignedSize*ATy->getNumElements();
     return;
   }
+  case Type::PackedTyID: {
+    const PackedType *PTy = cast<PackedType>(Ty);
+    getTypeInfo(PTy->getElementType(), TD, Size, Alignment);
+    unsigned AlignedSize = (Size + Alignment - 1)/Alignment*Alignment;
+    Size = AlignedSize*PTy->getNumElements();
+    return;
+  }
   case Type::StructTyID: {
     // Get the layout annotation... which is lazily created on demand.
     const StructLayout *Layout = TD->getStructLayout(cast<StructType>(Ty));
@@ -201,6 +209,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 {