[cfe-commits] r39850 - in /cfe/trunk: AST/ASTContext.cpp Basic/TargetInfo.cpp CodeGen/CGExpr.cpp CodeGen/CodeGenFunction.cpp CodeGen/CodeGenModule.cpp CodeGen/CodeGenTypes.cpp CodeGen/CodeGenTypes.h Driver/Targets.cpp Sema/SemaDecl.cpp Sema/SemaExpr.cpp include/clang/AST/ASTContext.h include/clang/Basic/TargetInfo.h

Chris Lattner sabre at nondot.org
Fri Jul 13 18:29:46 PDT 2007


Author: lattner
Date: Fri Jul 13 20:29:45 2007
New Revision: 39850

URL: http://llvm.org/viewvc/llvm-project?rev=39850&view=rev
Log:
A significant refactoring of the type size stuff to also 
compute type alignment.  This info is needed for struct layout.

Modified:
    cfe/trunk/AST/ASTContext.cpp
    cfe/trunk/Basic/TargetInfo.cpp
    cfe/trunk/CodeGen/CGExpr.cpp
    cfe/trunk/CodeGen/CodeGenFunction.cpp
    cfe/trunk/CodeGen/CodeGenModule.cpp
    cfe/trunk/CodeGen/CodeGenTypes.cpp
    cfe/trunk/CodeGen/CodeGenTypes.h
    cfe/trunk/Driver/Targets.cpp
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/Basic/TargetInfo.h

Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Fri Jul 13 20:29:45 2007
@@ -140,8 +140,11 @@
 
 /// getTypeSize - Return the size of the specified type, in bits.  This method
 /// does not work on incomplete types.
-unsigned ASTContext::getTypeSize(QualType T) {
+std::pair<uint64_t, unsigned>
+ASTContext::getTypeInfo(QualType T, SourceLocation L) {
   T = T.getCanonicalType();
+  uint64_t Size;
+  unsigned Align;
   switch (T->getTypeClass()) {
   default:
   case Type::Complex:
@@ -158,33 +161,34 @@
     // implementation will suffice for play with vector support.
     switch (cast<BuiltinType>(T)->getKind()) {
     default: assert(0 && "Unknown builtin type!");
-    case BuiltinType::Void:       assert(0 && "Incomplete types have no size!");
-    case BuiltinType::Bool:       return Target.getBoolWidth(SourceLocation());
+    case BuiltinType::Void:
+      assert(0 && "Incomplete types have no size!");
+    case BuiltinType::Bool:       Target.getBoolInfo(Size, Align, L); break;
     case BuiltinType::Char_S:
     case BuiltinType::Char_U:
     case BuiltinType::UChar:
-    case BuiltinType::SChar:      return Target.getCharWidth(SourceLocation());
+    case BuiltinType::SChar:      Target.getCharInfo(Size, Align, L); break;
     case BuiltinType::UShort:
-    case BuiltinType::Short:      return Target.getShortWidth(SourceLocation());
+    case BuiltinType::Short:      Target.getShortInfo(Size, Align, L); break;
     case BuiltinType::UInt:
-    case BuiltinType::Int:        return Target.getIntWidth(SourceLocation());
+    case BuiltinType::Int:        Target.getIntInfo(Size, Align, L); break;
     case BuiltinType::ULong:
-    case BuiltinType::Long:       return Target.getLongWidth(SourceLocation());
+    case BuiltinType::Long:       Target.getLongInfo(Size, Align, L); break;
     case BuiltinType::ULongLong:
-    case BuiltinType::LongLong:return Target.getLongLongWidth(SourceLocation());
-    case BuiltinType::Float:    return Target.getFloatWidth(SourceLocation());
-    case BuiltinType::Double:   return Target.getDoubleWidth(SourceLocation());
-    case BuiltinType::LongDouble:
-      return Target.getLongDoubleWidth(SourceLocation());
+    case BuiltinType::LongLong:   Target.getLongLongInfo(Size, Align, L); break;
+    case BuiltinType::Float:      Target.getFloatInfo(Size, Align, L); break;
+    case BuiltinType::Double:     Target.getDoubleInfo(Size, Align, L); break;
+    case BuiltinType::LongDouble: Target.getLongDoubleInfo(Size, Align,L);break;
     }
   }
-  case Type::Pointer:
-    return Target.getPointerWidth(SourceLocation());
+  case Type::Pointer: Target.getPointerInfo(Size, Align, L); break;
   case Type::Reference:
     // "When applied to a reference or a reference type, the result is the size
     // of the referenced type." C++98 5.3.3p2: expr.sizeof
-    return getTypeSize(cast<ReferenceType>(T)->getReferenceeType());
+    return getTypeInfo(cast<ReferenceType>(T)->getReferenceeType(), L);
   }
+  
+  return std::make_pair(Size, Align);
 }
 
 //===----------------------------------------------------------------------===//
@@ -460,34 +464,6 @@
   return IntTy; 
 }
 
-/// getIntegerBitwidth - Return the bitwidth of the specified integer type
-/// according to the target.  'Loc' specifies the source location that
-/// requires evaluation of this property.
-unsigned ASTContext::getIntegerBitwidth(QualType T, SourceLocation Loc) {
-  if (const TagType *TT = dyn_cast<TagType>(T.getCanonicalType())) {
-    assert(TT->getDecl()->getKind() == Decl::Enum && "not an int or enum");
-    assert(0 && "FIXME: getIntegerBitwidth(enum) unimplemented!");
-  }
-  
-  const BuiltinType *BT = cast<BuiltinType>(T.getCanonicalType());
-  switch (BT->getKind()) {
-  default: assert(0 && "getIntegerBitwidth(): not a built-in integer");
-  case BuiltinType::Bool:      return Target.getBoolWidth(Loc);
-  case BuiltinType::Char_S:
-  case BuiltinType::Char_U:
-  case BuiltinType::SChar:
-  case BuiltinType::UChar:     return Target.getCharWidth(Loc);
-  case BuiltinType::Short:
-  case BuiltinType::UShort:    return Target.getShortWidth(Loc);
-  case BuiltinType::Int:
-  case BuiltinType::UInt:      return Target.getIntWidth(Loc);
-  case BuiltinType::Long:
-  case BuiltinType::ULong:     return Target.getLongWidth(Loc);
-  case BuiltinType::LongLong:
-  case BuiltinType::ULongLong: return Target.getLongLongWidth(Loc);
-  }
-}
-
 /// getIntegerRank - Return an integer conversion rank (C99 6.3.1.1p1). This
 /// routine will assert if passed a built-in type that isn't an integer or enum.
 static int getIntegerRank(QualType t) {

Modified: cfe/trunk/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/TargetInfo.cpp?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/Basic/TargetInfo.cpp Fri Jul 13 20:29:45 2007
@@ -157,14 +157,17 @@
 /// ComputeWCharWidth - Determine the width of the wchar_t type for the primary
 /// target, diagnosing whether this is non-portable across the secondary
 /// targets.
-void TargetInfo::ComputeWCharWidth(SourceLocation Loc) {
-  WCharWidth = PrimaryTarget->getWCharWidth();
+void TargetInfo::ComputeWCharInfo(SourceLocation Loc) {
+  PrimaryTarget->getWCharInfo(WCharWidth, WCharAlign);
   
   // Check whether this is portable across the secondary targets if the T-U is
   // portable so far.
-  for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i)
-    if (SecondaryTargets[i]->getWCharWidth() != WCharWidth)
+  for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i) {
+    unsigned Width, Align;
+    SecondaryTargets[i]->getWCharInfo(Width, Align);
+    if (Width != WCharWidth || Align != WCharAlign)
       return DiagnoseNonPortability(Loc, diag::port_wchar_t);
+  }
 }
 
 

Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Fri Jul 13 20:29:45 2007
@@ -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");

Modified: cfe/trunk/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.cpp?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.cpp Fri Jul 13 20:29:45 2007
@@ -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;

Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Fri Jul 13 20:29:45 2007
@@ -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;

Modified: cfe/trunk/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenTypes.cpp?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenTypes.cpp Fri Jul 13 20:29:45 2007
@@ -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;

Modified: cfe/trunk/CodeGen/CodeGenTypes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenTypes.h?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenTypes.h (original)
+++ cfe/trunk/CodeGen/CodeGenTypes.h Fri Jul 13 20:29:45 2007
@@ -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; }
   

Modified: cfe/trunk/Driver/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/Targets.cpp?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/Driver/Targets.cpp (original)
+++ cfe/trunk/Driver/Targets.cpp Fri Jul 13 20:29:45 2007
@@ -378,6 +378,7 @@
   LinuxTargetInfo() {
     // Note: I have no idea if this is right, just for testing.
     WCharWidth = 16;
+    WCharAlign = 16;
   }
   
   virtual void getTargetDefines(std::vector<std::string> &Defines) const {

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Jul 13 20:29:45 2007
@@ -1005,7 +1005,7 @@
          curType.getCanonicalType().getAsString());
     return QualType();
   }
-  unsigned typeSize = Context.getTypeSize(curType);
+  unsigned typeSize = Context.getTypeSize(curType, rawAttr->getAttributeLoc());
   // vecSize is specified in bytes - convert to bits.
   unsigned vectorSize = vecSize.getZExtValue() * 8; 
   

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Fri Jul 13 20:29:45 2007
@@ -115,7 +115,7 @@
   if (Tok.getLength() == 1) {
     const char *t = PP.getSourceManager().getCharacterData(Tok.getLocation());
     
-    unsigned IntSize = Context.Target.getIntWidth(Tok.getLocation());
+    unsigned IntSize = Context.getTypeSize(Context.IntTy, Tok.getLocation());
     return ExprResult(new IntegerLiteral(llvm::APInt(IntSize, *t-'0'),
                                          Context.IntTy, 
                                          Tok.getLocation()));
@@ -141,7 +141,7 @@
       // If this value didn't fit into uintmax_t, warn and force to ull.
       Diag(Tok.getLocation(), diag::warn_integer_too_large);
       t = Context.UnsignedLongLongTy;
-      assert(Context.getIntegerBitwidth(t, Tok.getLocation()) == 
+      assert(Context.getTypeSize(t, Tok.getLocation()) == 
              ResultVal.getBitWidth() && "long long is not intmax_t?");
     } else {
       // If this value fits into a ULL, try to figure out what else it fits into
@@ -153,7 +153,7 @@
 
       // Check from smallest to largest, picking the smallest type we can.
       if (!Literal.isLong) {  // Are int/unsigned possibilities?
-        unsigned IntSize = Context.Target.getIntWidth(Tok.getLocation());
+        unsigned IntSize = Context.getTypeSize(Context.IntTy,Tok.getLocation());
         // Does it fit in a unsigned int?
         if (ResultVal.isIntN(IntSize)) {
           // Does it fit in a signed int?
@@ -169,7 +169,8 @@
       
       // Are long/unsigned long possibilities?
       if (t.isNull() && !Literal.isLongLong) {
-        unsigned LongSize = Context.Target.getLongWidth(Tok.getLocation());
+        unsigned LongSize = Context.getTypeSize(Context.LongTy,
+                                                Tok.getLocation());
      
         // Does it fit in a unsigned long?
         if (ResultVal.isIntN(LongSize)) {
@@ -186,7 +187,7 @@
       // Finally, check long long if needed.
       if (t.isNull()) {
         unsigned LongLongSize =
-          Context.Target.getLongLongWidth(Tok.getLocation());
+          Context.getTypeSize(Context.LongLongTy, Tok.getLocation());
         
         // Does it fit in a unsigned long long?
         if (ResultVal.isIntN(LongLongSize)) {

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Jul 13 20:29:45 2007
@@ -54,12 +54,23 @@
   ~ASTContext();
   
   void PrintStats() const;
-  
+
+  /// getTypeInfo - Get the size and alignment of the specified complete type in
+  /// bits.
+  std::pair<uint64_t, unsigned> getTypeInfo(QualType T, SourceLocation L);
+
   /// getTypeSize - Return the size of the specified type, in bits.  This method
   /// does not work on incomplete types.
-  unsigned getTypeSize(QualType T);
-  //TODO: unsigned getTypeAlign(QualType T);
-
+  uint64_t getTypeSize(QualType T, SourceLocation L) {
+    return getTypeInfo(T, L).first;
+  }
+  
+  /// getTypeAlign - Return the alignment of the specified type, in bits.  This
+  /// method does not work on incomplete types.
+  unsigned getTypeAlign(QualType T, SourceLocation L) {
+    return getTypeInfo(T, L).second;
+  }    
+  
   /// getComplexType - Return the uniqued reference to the type for a complex
   /// number with the specified element type.
   QualType getComplexType(QualType T);

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=39850&r1=39849&r2=39850&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Jul 13 20:29:45 2007
@@ -55,7 +55,7 @@
   bool NonPortable;
 
   /// These are all caches for target values.
-  unsigned WCharWidth;
+  unsigned WCharWidth, WCharAlign;
   
 public:
   TargetInfo(const TargetInfoImpl *Primary, Diagnostic *D = 0) {
@@ -105,67 +105,71 @@
   
   /// getPointerWidth - Return the width of pointers on this target, we
   /// currently assume one pointer type.
-  unsigned getPointerWidth(SourceLocation Loc) {
-    return 32;   // FIXME: implement correctly.
+  void getPointerInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+    Size = 32;  // FIXME: implement correctly.
+    Align = 32;
   }
   
-  /// getBoolWidth - Return the size of '_Bool' and C++ 'bool' for this target,
+  /// getBoolInfo - Return the size of '_Bool' and C++ 'bool' for this target,
   /// in bits.  
-  unsigned getBoolWidth(SourceLocation Loc) {
-    return 8;    // FIXME: implement correctly: wrong for ppc32.
+  void getBoolInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+    Size = Align = 8;    // FIXME: implement correctly: wrong for ppc32.
   }
   
-  /// getCharWidth - Return the size of 'char', 'signed char' and
+  /// getCharInfo - Return the size of 'char', 'signed char' and
   /// 'unsigned char' for this target, in bits.  
-  unsigned getCharWidth(SourceLocation Loc) {
-    return 8; // FIXME: implement correctly.
+  void getCharInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+    Size = Align = 8; // FIXME: implement correctly.
   }
   
-  /// getShortWidth - Return the size of 'signed short' and 'unsigned short' for
+  /// getShortInfo - Return the size of 'signed short' and 'unsigned short' for
   /// this target, in bits.  
-  unsigned getShortWidth(SourceLocation Loc) {
-    return 16; // FIXME: implement correctly.
+  void getShortInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+    Size = Align = 16; // FIXME: implement correctly.
   }
   
-  /// getIntWidth - Return the size of 'signed int' and 'unsigned int' for this
+  /// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this
   /// target, in bits.  
-  unsigned getIntWidth(SourceLocation Loc) {
-    return 32; // FIXME: implement correctly.
+  void getIntInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+    Size = Align = 32; // FIXME: implement correctly.
   }
   
-  /// getLongWidth - Return the size of 'signed long' and 'unsigned long' for
+  /// getLongInfo - Return the size of 'signed long' and 'unsigned long' for
   /// this target, in bits.  
-  unsigned getLongWidth(SourceLocation Loc) {
-    return 32;  // FIXME: implement correctly: wrong for ppc64/x86-64
+  void getLongInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+    Size = Align = 32;  // FIXME: implement correctly: wrong for ppc64/x86-64
   }
 
-  /// getLongLongWidth - Return the size of 'signed long long' and
+  /// getLongLongInfo - Return the size of 'signed long long' and
   /// 'unsigned long long' for this target, in bits.  
-  unsigned getLongLongWidth(SourceLocation Loc) {
-    return 64; // FIXME: implement correctly.
+  void getLongLongInfo(uint64_t &Size, unsigned &Align, 
+                            SourceLocation Loc) {
+    Size = Align = 64; // FIXME: implement correctly.
   }
   
-  /// getFloatWidth - Return the size of 'float' for this target, in bits.  
-  unsigned getFloatWidth(SourceLocation Loc) {
-    return 32;  // FIXME: implement correctly.
+  /// getFloatInfo - Return the size of 'float' for this target, in bits.  
+  void getFloatInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+    Align = Size = 32;  // FIXME: implement correctly.
   }
 
-  /// getDoubleWidth - Return the size of 'double' for this target, in bits.  
-  unsigned getDoubleWidth(SourceLocation Loc) {
-    return 64;  // FIXME: implement correctly.
+  /// getDoubleInfo - Return the size of 'double' for this target, in bits.  
+  void getDoubleInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+    Size = Align = 64;  // FIXME: implement correctly.
   }
 
-  /// getLongDoubleWidth - Return the size of 'long double' for this target, in
+  /// getLongDoubleInfo - Return the size of 'long double' for this target, in
   /// bits.  
-  unsigned getLongDoubleWidth(SourceLocation Loc) {
-    return 64;  // FIXME: implement correctly.
+  void getLongDoubleInfo(uint64_t &Size, unsigned &Align,
+                             SourceLocation Loc) {
+    Size = Align = 64;  // FIXME: implement correctly.
   }
   
-  /// getWCharWidth - Return the size of wchar_t in bits.
+  /// getWCharInfo - Return the size of wchar_t in bits.
   ///
-  unsigned getWCharWidth(SourceLocation Loc) {
-    if (!WCharWidth) ComputeWCharWidth(Loc);
-    return WCharWidth;
+  void getWCharInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) {
+    if (!WCharWidth) ComputeWCharInfo(Loc);
+    Size = WCharWidth;
+    Align = WCharAlign;
   }
   
   /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
@@ -181,8 +185,28 @@
   void getTargetBuiltins(const Builtin::Info *&Records, unsigned &NumRecords,
                          std::vector<const char *> &NonPortableBuiltins) const;
 
+  ///===---- Some helper methods ------------------------------------------===//
+
+  unsigned getCharWidth(SourceLocation Loc) {
+    uint64_t Size; unsigned Align;
+    getCharInfo(Size, Align, Loc);
+    return Size;
+  }
+  
+  unsigned getWCharWidth(SourceLocation Loc) {
+    uint64_t Size; unsigned Align;
+    getWCharInfo(Size, Align, Loc);
+    return Size;
+  }
+  
+  unsigned getIntWidth(SourceLocation Loc) {
+    uint64_t Size; unsigned Align;
+    getIntInfo(Size, Align, Loc);
+    return Size;
+  }
+  
 private:
-  void ComputeWCharWidth(SourceLocation Loc);
+  void ComputeWCharInfo(SourceLocation Loc);
 };
 
 
@@ -195,8 +219,9 @@
 class TargetInfoImpl {
 protected:
   unsigned WCharWidth;    /// sizeof(wchar_t) in bits.  Default value is 32.
+  unsigned WCharAlign;    /// alignof(wchar_t) in bits.  Default value is 32.
 public:
-  TargetInfoImpl() : WCharWidth(32) {}
+  TargetInfoImpl() : WCharWidth(32), WCharAlign(32) {}
   virtual ~TargetInfoImpl() {}
   
   /// getTargetDefines - Return a list of the target-specific #define values set
@@ -206,7 +231,10 @@
 
   /// getWCharWidth - Return the size of wchar_t in bits.
   ///
-  unsigned getWCharWidth() const { return WCharWidth; }
+  void getWCharInfo(unsigned &Size, unsigned &Align) const {
+    Size = WCharWidth;
+    Align = WCharAlign;
+  }
   
   /// getTargetBuiltins - Return information about target-specific builtins for
   /// the target.





More information about the cfe-commits mailing list