Fix the asmprinter so that a globalvalue can specify an explicit alignment
[oota-llvm.git] / lib / Target / TargetData.cpp
index 10ee707aea4df205779d6348f9da880ff623e57b..301e8c12ab452d46b83a1d4509b923144d71466c 100644 (file)
@@ -35,6 +35,7 @@ namespace {
   // Register the default SparcV9 implementation...
   RegisterPass<TargetData> X("targetdata", "Target Data Layout");
 }
+char TargetData::ID = 0;
 
 //===----------------------------------------------------------------------===//
 // Support for StructLayout
@@ -221,7 +222,8 @@ void TargetData::init(const std::string &TargetDescription) {
   }
 }
 
-TargetData::TargetData(const Module *M) {
+TargetData::TargetData(const Module *M) 
+  : ImmutablePass((intptr_t)&ID) {
   init(M->getDataLayout());
 }
 
@@ -493,9 +495,15 @@ unsigned char TargetData::getAlignment(const Type *Ty, bool abi_or_pref) const {
   case Type::DoubleTyID:
     AlignType = FLOAT_ALIGN;
     break;
-  case Type::VectorTyID:
-    AlignType = VECTOR_ALIGN;
+  case Type::VectorTyID: {
+    const VectorType *VTy = cast<VectorType>(Ty);
+    // Degenerate vectors are assumed to be scalar-ized
+    if (VTy->getNumElements() == 1)
+      return getAlignment(VTy->getElementType(), abi_or_pref);
+    else
+      AlignType = VECTOR_ALIGN;
     break;
+  }
   default:
     assert(0 && "Bad type for getAlignment!!!");
     break;