[cfe-commits] r94681 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/AST/ExprConstant.cpp lib/CodeGen/CGBlocks.cpp lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDecl.cpp lib/CodeGen/CodeGenModule.cpp

Ken Dyck ken.dyck at onsemi.com
Wed Jan 27 09:10:57 PST 2010


Author: kjdyck
Date: Wed Jan 27 11:10:57 2010
New Revision: 94681

URL: http://llvm.org/viewvc/llvm-project?rev=94681&view=rev
Log:
Change the return type of ASTContext::getDeclAlignInBytes() to CharUnits and,
now that the "InBytes" part of the name is implied by the return type, rename
it to getDeclAlign().


Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Jan 27 11:10:57 2010
@@ -846,7 +846,12 @@
   /// a data type.
   unsigned getPreferredTypeAlign(const Type *T);
 
-  unsigned getDeclAlignInBytes(const Decl *D, bool RefAsPointee = false);
+  /// getDeclAlign - Return a conservative estimate of the alignment of
+  /// the specified decl.  Note that bitfields do not have a valid alignment, so
+  /// this method will assert on them.
+  /// If @p RefAsPointee, references are treated like their underlying type
+  /// (for alignof), else they're treated like pointers (for CodeGen).
+  CharUnits getDeclAlign(const Decl *D, bool RefAsPointee = false);
 
   /// getASTRecordLayout - Get or compute information about the layout of the
   /// specified record (struct/union/class), which indicates its size and field

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

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Jan 27 11:10:57 2010
@@ -533,12 +533,12 @@
   }
 }
 
-/// getDeclAlignInBytes - Return a conservative estimate of the alignment of the
+/// getDeclAlign - Return a conservative estimate of the alignment of the
 /// specified decl.  Note that bitfields do not have a valid alignment, so
 /// this method will assert on them.
 /// If @p RefAsPointee, references are treated like their underlying type
 /// (for alignof), else they're treated like pointers (for CodeGen).
-unsigned ASTContext::getDeclAlignInBytes(const Decl *D, bool RefAsPointee) {
+CharUnits ASTContext::getDeclAlign(const Decl *D, bool RefAsPointee) {
   unsigned Align = Target.getCharWidth();
 
   if (const AlignedAttr* AA = D->getAttr<AlignedAttr>())
@@ -561,7 +561,7 @@
     }
   }
 
-  return Align / Target.getCharWidth();
+  return CharUnits::fromQuantity(Align / Target.getCharWidth());
 }
 
 /// getTypeSize - Return the size of the specified type, in bits.  This method

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=94681&r1=94680&r2=94681&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Jan 27 11:10:57 2010
@@ -849,8 +849,8 @@
   bool VisitUnaryImag(const UnaryOperator *E);
 
 private:
-  unsigned GetAlignOfExpr(const Expr *E);
-  unsigned GetAlignOfType(QualType T);
+  CharUnits GetAlignOfExpr(const Expr *E);
+  CharUnits GetAlignOfType(QualType T);
   // FIXME: Missing: array subscript of vector, member of vector
 };
 } // end anonymous namespace
@@ -1288,7 +1288,7 @@
   return Visit(Cond ? E->getTrueExpr() : E->getFalseExpr());
 }
 
-unsigned IntExprEvaluator::GetAlignOfType(QualType T) {
+CharUnits IntExprEvaluator::GetAlignOfType(QualType T) {
   // C++ [expr.sizeof]p2: "When applied to a reference or a reference type,
   //   the result is the size of the referenced type."
   // C++ [expr.alignof]p3: "When alignof is applied to a reference type, the
@@ -1300,20 +1300,22 @@
   unsigned CharSize = Info.Ctx.Target.getCharWidth();
 
   // __alignof is defined to return the preferred alignment.
-  return Info.Ctx.getPreferredTypeAlign(T.getTypePtr()) / CharSize;
+  return CharUnits::fromQuantity(
+      Info.Ctx.getPreferredTypeAlign(T.getTypePtr()) / CharSize);
 }
 
-unsigned IntExprEvaluator::GetAlignOfExpr(const Expr *E) {
+CharUnits IntExprEvaluator::GetAlignOfExpr(const Expr *E) {
   E = E->IgnoreParens();
 
   // alignof decl is always accepted, even if it doesn't make sense: we default
   // to 1 in those cases.
   if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
-    return Info.Ctx.getDeclAlignInBytes(DRE->getDecl(), /*RefAsPointee*/true);
+    return Info.Ctx.getDeclAlign(DRE->getDecl(), 
+                                 /*RefAsPointee*/true);
 
   if (const MemberExpr *ME = dyn_cast<MemberExpr>(E))
-    return Info.Ctx.getDeclAlignInBytes(ME->getMemberDecl(),
-                                        /*RefAsPointee*/true);
+    return Info.Ctx.getDeclAlign(ME->getMemberDecl(),
+                                 /*RefAsPointee*/true);
 
   return GetAlignOfType(E->getType());
 }
@@ -1325,9 +1327,9 @@
   // Handle alignof separately.
   if (!E->isSizeOf()) {
     if (E->isArgumentType())
-      return Success(GetAlignOfType(E->getArgumentType()), E);
+      return Success(GetAlignOfType(E->getArgumentType()).getQuantity(), E);
     else
-      return Success(GetAlignOfExpr(E->getArgumentExpr()), E);
+      return Success(GetAlignOfExpr(E->getArgumentExpr()).getQuantity(), E);
   }
 
   QualType SrcTy = E->getTypeOfArgument();

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=94681&r1=94680&r2=94681&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Jan 27 11:10:57 2010
@@ -812,8 +812,7 @@
   const ValueDecl *D = dyn_cast<ValueDecl>(BDRE->getDecl());
 
   CharUnits Size = getContext().getTypeSizeInChars(D->getType());
-  CharUnits Align = 
-    CharUnits::fromQuantity(getContext().getDeclAlignInBytes(D));
+  CharUnits Align = getContext().getDeclAlign(D);
 
   if (BDRE->isByRef()) {
     Size = getContext().getTypeSizeInChars(getContext().VoidPtrTy);

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=94681&r1=94680&r2=94681&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Jan 27 11:10:57 2010
@@ -1333,10 +1333,11 @@
       FieldOffset += FieldSize;
     }
     
-    unsigned Align = CGM.getContext().getDeclAlignInBytes(Decl);
-    if (Align > CGM.getContext().Target.getPointerAlign(0) / 8) {
+    CharUnits Align = CGM.getContext().getDeclAlign(Decl);
+    if (Align > CharUnits::fromQuantity(
+          CGM.getContext().Target.getPointerAlign(0) / 8)) {
       unsigned AlignedOffsetInBytes
-        = llvm::RoundUpToAlignment(FieldOffset/8, Align);
+        = llvm::RoundUpToAlignment(FieldOffset/8, Align.getQuantity());
       unsigned NumPaddingBytes
         = AlignedOffsetInBytes - FieldOffset/8;
 
@@ -1359,7 +1360,7 @@
     FType = Type;
     FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
     FieldSize = CGM.getContext().getTypeSize(FType);
-    FieldAlign = Align*8;
+    FieldAlign = Align.getQuantity()*8;
     
     FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
                                              Decl->getName(), DefUnit,
@@ -1510,10 +1511,11 @@
       FieldOffset += FieldSize;
     }
     
-    unsigned Align = CGM.getContext().getDeclAlignInBytes(Decl);
-    if (Align > CGM.getContext().Target.getPointerAlign(0) / 8) {
+    CharUnits Align = CGM.getContext().getDeclAlign(Decl);
+    if (Align > CharUnits::fromQuantity(
+          CGM.getContext().Target.getPointerAlign(0) / 8)) {
       unsigned AlignedOffsetInBytes
-        = llvm::RoundUpToAlignment(FieldOffset/8, Align);
+        = llvm::RoundUpToAlignment(FieldOffset/8, Align.getQuantity());
       unsigned NumPaddingBytes
         = AlignedOffsetInBytes - FieldOffset/8;
 
@@ -1536,7 +1538,7 @@
     FType = Type;
     FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
     FieldSize = CGM.getContext().getTypeSize(FType);
-    FieldAlign = Align*8;
+    FieldAlign = Align.getQuantity()*8;
     
     XOffset = FieldOffset;
     FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=94681&r1=94680&r2=94681&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Wed Jan 27 11:10:57 2010
@@ -120,7 +120,7 @@
                              Ty.isConstant(getContext()), Linkage,
                              CGM.EmitNullConstant(D.getType()), Name, 0,
                              D.isThreadSpecified(), Ty.getAddressSpace());
-  GV->setAlignment(getContext().getDeclAlignInBytes(&D));
+  GV->setAlignment(getContext().getDeclAlign(&D).getQuantity());
   return GV;
 }
 
@@ -286,8 +286,8 @@
   }
 
   bool Packed = false;
-  unsigned Align = getContext().getDeclAlignInBytes(D);
-  if (Align > Target.getPointerAlign(0) / 8) {
+  CharUnits Align = getContext().getDeclAlign(D);
+  if (Align > CharUnits::fromQuantity(Target.getPointerAlign(0) / 8)) {
     // We have to insert padding.
     
     // The struct above has 2 32-bit integers.
@@ -299,7 +299,7 @@
     
     // Align the offset.
     unsigned AlignedOffsetInBytes = 
-      llvm::RoundUpToAlignment(CurrentOffsetInBytes, Align);
+      llvm::RoundUpToAlignment(CurrentOffsetInBytes, Align.getQuantity());
     
     unsigned NumPaddingBytes = AlignedOffsetInBytes - CurrentOffsetInBytes;
     if (NumPaddingBytes > 0) {
@@ -339,7 +339,7 @@
   QualType Ty = D.getType();
   bool isByRef = D.hasAttr<BlocksAttr>();
   bool needsDispose = false;
-  unsigned Align = 0;
+  CharUnits Align = CharUnits::Zero();
   bool IsSimpleConstantInitializer = false;
 
   llvm::Value *DeclPtr;
@@ -369,10 +369,11 @@
       llvm::AllocaInst *Alloc = CreateTempAlloca(LTy);
       Alloc->setName(D.getNameAsString());
 
-      Align = getContext().getDeclAlignInBytes(&D);
+      Align = getContext().getDeclAlign(&D);
       if (isByRef)
-        Align = std::max(Align, unsigned(Target.getPointerAlign(0) / 8));
-      Alloc->setAlignment(Align);
+        Align = std::max(Align, 
+            CharUnits::fromQuantity(Target.getPointerAlign(0) / 8));
+      Alloc->setAlignment(Align.getQuantity());
       DeclPtr = Alloc;
     } else {
       // Targets that don't support recursion emit locals as globals.
@@ -425,7 +426,7 @@
     // Allocate memory for the array.
     llvm::AllocaInst *VLA = 
       Builder.CreateAlloca(llvm::Type::getInt8Ty(VMContext), VLASize, "vla");
-    VLA->setAlignment(getContext().getDeclAlignInBytes(&D));
+    VLA->setAlignment(getContext().getDeclAlign(&D).getQuantity());
 
     DeclPtr = Builder.CreateBitCast(VLA, LElemPtrTy, "tmp");
   }
@@ -473,7 +474,8 @@
       assert(Init != 0 && "Wasn't a simple constant init?");
       
       llvm::Value *AlignVal = 
-        llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), Align);
+        llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 
+            Align.getQuantity());
       const llvm::Type *IntPtr =
         llvm::IntegerType::get(VMContext, LLVMPointerWidth);
       llvm::Value *SizeVal =
@@ -497,7 +499,7 @@
           new llvm::GlobalVariable(CGM.getModule(), Init->getType(), true,
                                    llvm::GlobalValue::InternalLinkage,
                                    Init, Name, 0, false, 0);
-        GV->setAlignment(Align);
+        GV->setAlignment(Align.getQuantity());
 
         llvm::Value *SrcPtr = GV;
         if (SrcPtr->getType() != BP)
@@ -565,12 +567,13 @@
     if (flags & BLOCK_HAS_COPY_DISPOSE) {
       BlockHasCopyDispose = true;
       llvm::Value *copy_helper = Builder.CreateStructGEP(DeclPtr, 4);
-      Builder.CreateStore(BuildbyrefCopyHelper(DeclPtr->getType(), flag, Align),
+      Builder.CreateStore(BuildbyrefCopyHelper(DeclPtr->getType(), flag, 
+                                               Align.getQuantity()),
                           copy_helper);
 
       llvm::Value *destroy_helper = Builder.CreateStructGEP(DeclPtr, 5);
       Builder.CreateStore(BuildbyrefDestroyHelper(DeclPtr->getType(), flag,
-                                                  Align),
+                                                  Align.getQuantity()),
                           destroy_helper);
     }
   }

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Jan 27 11:10:57 2010
@@ -1065,7 +1065,7 @@
   if (!NonConstInit && DeclIsConstantGlobal(Context, D))
     GV->setConstant(true);
 
-  GV->setAlignment(getContext().getDeclAlignInBytes(D));
+  GV->setAlignment(getContext().getDeclAlign(D).getQuantity());
 
   // Set the llvm linkage type as appropriate.
   GVALinkage Linkage = GetLinkageForVariable(getContext(), D);





More information about the cfe-commits mailing list