A significant refactoring of the type size stuff to also 
compute type alignment.  This info is needed for struct layout.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39850 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp
index 9f535b5..0b1ac8f 100644
--- a/CodeGen/CGExpr.cpp
+++ b/CodeGen/CGExpr.cpp
@@ -1168,7 +1168,8 @@
     QualType LHSElementType = LHSPtrType->getPointeeType();
     assert(LHSElementType == RHSPtrType->getPointeeType() &&
       "can't subtract pointers with differing element types");
-    unsigned ElementSize = getContext().getTypeSize(LHSElementType) / 8;
+    unsigned ElementSize = getContext().getTypeSize(LHSElementType,
+                                                    SourceLocation()) / 8;
     const llvm::Type *ResultType = ConvertType(ResTy);
     llvm::Value *CastLHS = Builder.CreatePtrToInt(LHSValue, ResultType,
                                                   "sub.ptr.lhs.cast");
diff --git a/CodeGen/CodeGenFunction.cpp b/CodeGen/CodeGenFunction.cpp
index 662c3b5..0cdda6c 100644
--- a/CodeGen/CodeGenFunction.cpp
+++ b/CodeGen/CodeGenFunction.cpp
@@ -51,7 +51,9 @@
 
 void CodeGenFunction::GenerateCode(const FunctionDecl *FD) {
   LLVMIntTy = ConvertType(getContext().IntTy);
-  LLVMPointerWidth = Target.getPointerWidth(SourceLocation());
+  LLVMPointerWidth =
+    getContext().getTypeSize(getContext().getPointerType(getContext().VoidTy),
+                             SourceLocation());
   
   CurFn = cast<llvm::Function>(CGM.GetAddrOfGlobalDecl(FD));
   CurFuncDecl = FD;
diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp
index d091dd7..262469e 100644
--- a/CodeGen/CodeGenModule.cpp
+++ b/CodeGen/CodeGenModule.cpp
@@ -26,7 +26,7 @@
 
 
 CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M)
-  : Context(C), TheModule(M), Types(C.Target) {}
+  : Context(C), TheModule(M), Types(C) {}
 
 llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const Decl *D) {
   // See if it is already in the map.
@@ -68,7 +68,8 @@
   if (D->getInit() == 0) {
     Init = llvm::Constant::getNullValue(GV->getType()->getElementType());
   } else if (D->getType()->isIntegerType()) {
-    llvm::APSInt Value(getContext().getTypeSize(D->getInit()->getType()));
+    llvm::APSInt Value(getContext().getTypeSize(D->getInit()->getType(),
+                                                SourceLocation()));
     if (D->getInit()->isIntegerConstantExpr(Value))
       Init = llvm::ConstantInt::get(Value);
   }
@@ -103,7 +104,9 @@
 llvm::Function *CodeGenModule::getMemCpyFn() {
   if (MemCpyFn) return MemCpyFn;
   llvm::Intrinsic::ID IID;
-  switch (Context.Target.getPointerWidth(SourceLocation())) {
+  uint64_t Size; unsigned Align;
+  Context.Target.getPointerInfo(Size, Align, SourceLocation());
+  switch (Size) {
   default: assert(0 && "Unknown ptr width");
   case 32: IID = llvm::Intrinsic::memcpy_i32; break;
   case 64: IID = llvm::Intrinsic::memcpy_i64; break;
diff --git a/CodeGen/CodeGenTypes.cpp b/CodeGen/CodeGenTypes.cpp
index a75ac4c..5bae791 100644
--- a/CodeGen/CodeGenTypes.cpp
+++ b/CodeGen/CodeGenTypes.cpp
@@ -19,6 +19,9 @@
 using namespace clang;
 using namespace CodeGen;
 
+CodeGenTypes::CodeGenTypes(ASTContext &Ctx)
+  : Context(Ctx), Target(Ctx.Target) {
+}
 
 /// ConvertType - Convert the specified type to its LLVM form.
 const llvm::Type *CodeGenTypes::ConvertType(QualType T) {
@@ -31,32 +34,26 @@
     case BuiltinType::Void:
       // LLVM void type can only be used as the result of a function call.  Just
       // map to the same as char.
-    case BuiltinType::Char_S:
-    case BuiltinType::Char_U:
-    case BuiltinType::SChar:
-    case BuiltinType::UChar:
-      return llvm::IntegerType::get(Target.getCharWidth(SourceLocation()));
+      return llvm::IntegerType::get(8);
 
     case BuiltinType::Bool:
       // FIXME: This is very strange.  We want scalars to be i1, but in memory
       // they can be i1 or i32.  Should the codegen handle this issue?
       return llvm::Type::Int1Ty;
       
+    case BuiltinType::Char_S:
+    case BuiltinType::Char_U:
+    case BuiltinType::SChar:
+    case BuiltinType::UChar:
     case BuiltinType::Short:
     case BuiltinType::UShort:
-      return llvm::IntegerType::get(Target.getShortWidth(SourceLocation()));
-      
     case BuiltinType::Int:
     case BuiltinType::UInt:
-      return llvm::IntegerType::get(Target.getIntWidth(SourceLocation()));
-
     case BuiltinType::Long:
     case BuiltinType::ULong:
-      return llvm::IntegerType::get(Target.getLongWidth(SourceLocation()));
-
     case BuiltinType::LongLong:
     case BuiltinType::ULongLong:
-      return llvm::IntegerType::get(Target.getLongLongWidth(SourceLocation()));
+      return llvm::IntegerType::get(Context.getTypeSize(T, SourceLocation()));
       
     case BuiltinType::Float:      return llvm::Type::FloatTy;
     case BuiltinType::Double:     return llvm::Type::DoubleTy;
diff --git a/CodeGen/CodeGenTypes.h b/CodeGen/CodeGenTypes.h
index 3d87564..1b49dce 100644
--- a/CodeGen/CodeGenTypes.h
+++ b/CodeGen/CodeGenTypes.h
@@ -21,6 +21,7 @@
 }
 
 namespace clang {
+  class ASTContext;
   class TargetInfo;
   class QualType;
   class FunctionTypeProto;
@@ -30,10 +31,11 @@
 /// CodeGenTypes - This class organizes the cross-module state that is used
 /// while lowering AST types to LLVM types.
 class CodeGenTypes {
+  ASTContext &Context;
   TargetInfo &Target;
   
 public:
-  CodeGenTypes(TargetInfo &target) : Target(target) {}
+  CodeGenTypes(ASTContext &Ctx);
   
   TargetInfo &getTarget() const { return Target; }