[cfe-commits] r145753 - in /cfe/trunk/lib/CodeGen: CGBlocks.cpp CGCall.cpp CGClass.cpp CGDecl.cpp CGDeclCXX.cpp CGExpr.cpp CGExprCXX.cpp CGObjC.cpp CGValue.h CodeGenFunction.h

Eli Friedman eli.friedman at gmail.com
Fri Dec 2 20:14:33 PST 2011


Author: efriedma
Date: Fri Dec  2 22:14:32 2011
New Revision: 145753

URL: http://llvm.org/viewvc/llvm-project?rev=145753&view=rev
Log:
Switch LValue so that it exposes alignment in CharUnits.  (No functional change.)


Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprCXX.cpp
    cfe/trunk/lib/CodeGen/CGObjC.cpp
    cfe/trunk/lib/CodeGen/CGValue.h
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=145753&r1=145752&r2=145753&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Dec  2 22:14:32 2011
@@ -745,8 +745,7 @@
                            declRef, VK_RValue);
       EmitExprAsInit(&l2r, &blockFieldPseudoVar,
                      MakeAddrLValue(blockField, type,
-                                    getContext().getDeclAlign(variable)
-                                                .getQuantity()),
+                                    getContext().getDeclAlign(variable)),
                      /*captured by init*/ false);
     }
 

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=145753&r1=145752&r2=145753&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Dec  2 22:14:32 2011
@@ -1060,8 +1060,9 @@
       // we need to create a temporary and reconstruct it from the
       // arguments.
       llvm::AllocaInst *Alloca = CreateMemTemp(Ty);
-      Alloca->setAlignment(getContext().getDeclAlign(Arg).getQuantity());
-      LValue LV = MakeAddrLValue(Alloca, Ty, Alloca->getAlignment());
+      CharUnits Align = getContext().getDeclAlign(Arg);
+      Alloca->setAlignment(Align.getQuantity());
+      LValue LV = MakeAddrLValue(Alloca, Ty, Align);
       llvm::Function::arg_iterator End = ExpandTypeFromArgs(Ty, LV, AI);
       EmitParmDecl(*Arg, Alloca, ArgNo);
 

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=145753&r1=145752&r2=145753&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Fri Dec  2 22:14:32 2011
@@ -434,7 +434,7 @@
 
       // Update the LValue.
       LV.setAddress(Dest);
-      unsigned Align = CGF.getContext().getTypeAlignInChars(T).getQuantity();
+      CharUnits Align = CGF.getContext().getTypeAlignInChars(T);
       LV.setAlignment(std::min(Align, LV.getAlignment()));
     }
 

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=145753&r1=145752&r2=145753&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Fri Dec  2 22:14:32 2011
@@ -972,7 +972,7 @@
     capturedByInit ? emission.Address : emission.getObjectAddress(*this);
 
   if (!emission.IsConstantAggregate) {
-    LValue lv = MakeAddrLValue(Loc, type, alignment.getQuantity());
+    LValue lv = MakeAddrLValue(Loc, type, alignment);
     lv.setNonGC(true);
     return EmitExprAsInit(Init, &D, lv, capturedByInit);
   }
@@ -1505,7 +1505,7 @@
     // Store the initial value into the alloca.
     if (doStore) {
       LValue lv = MakeAddrLValue(DeclPtr, Ty,
-                                 getContext().getDeclAlign(&D).getQuantity());
+                                 getContext().getDeclAlign(&D));
       EmitStoreOfScalar(Arg, lv);
     }
   }

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=145753&r1=145752&r2=145753&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Fri Dec  2 22:14:32 2011
@@ -28,7 +28,7 @@
   
   ASTContext &Context = CGF.getContext();
 
-  unsigned alignment = Context.getDeclAlign(&D).getQuantity();
+  CharUnits alignment = Context.getDeclAlign(&D);
   QualType type = D.getType();
   LValue lv = CGF.MakeAddrLValue(DeclPtr, type, alignment);
 

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=145753&r1=145752&r2=145753&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Dec  2 22:14:32 2011
@@ -750,8 +750,8 @@
 
 llvm::Value *CodeGenFunction::EmitLoadOfScalar(LValue lvalue) {
   return EmitLoadOfScalar(lvalue.getAddress(), lvalue.isVolatile(),
-                          lvalue.getAlignment(), lvalue.getType(),
-                          lvalue.getTBAAInfo());
+                          lvalue.getAlignment().getQuantity(),
+                          lvalue.getType(), lvalue.getTBAAInfo());
 }
 
 llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
@@ -812,7 +812,7 @@
 
 void CodeGenFunction::EmitStoreOfScalar(llvm::Value *value, LValue lvalue) {
   EmitStoreOfScalar(value, lvalue.getAddress(), lvalue.isVolatile(),
-                    lvalue.getAlignment(), lvalue.getType(),
+                    lvalue.getAlignment().getQuantity(), lvalue.getType(),
                     lvalue.getTBAAInfo());
 }
 
@@ -1335,12 +1335,12 @@
   llvm::Value *V = CGF.CGM.GetAddrOfGlobalVar(VD);
   llvm::Type *RealVarTy = CGF.getTypes().ConvertTypeForMem(VD->getType());
   V = EmitBitCastOfLValueToProperType(CGF, V, RealVarTy);
-  unsigned Alignment = CGF.getContext().getDeclAlign(VD).getQuantity();
+  CharUnits Alignment = CGF.getContext().getDeclAlign(VD);
   QualType T = E->getType();
   LValue LV;
   if (VD->getType()->isReferenceType()) {
     llvm::LoadInst *LI = CGF.Builder.CreateLoad(V);
-    LI->setAlignment(Alignment);
+    LI->setAlignment(Alignment.getQuantity());
     V = LI;
     LV = CGF.MakeNaturalAlignAddrLValue(V, T);
   } else {
@@ -1365,13 +1365,13 @@
       V = CGF.Builder.CreateBitCast(V, CGF.ConvertType(NoProtoType));
     }
   }
-  unsigned Alignment = CGF.getContext().getDeclAlign(FD).getQuantity();
+  CharUnits Alignment = CGF.getContext().getDeclAlign(FD);
   return CGF.MakeAddrLValue(V, E->getType(), Alignment);
 }
 
 LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
   const NamedDecl *ND = E->getDecl();
-  unsigned Alignment = getContext().getDeclAlign(ND).getQuantity();
+  CharUnits Alignment = getContext().getDeclAlign(ND);
   QualType T = E->getType();
 
   if (ND->hasAttr<WeakRefAttr>()) {
@@ -1401,7 +1401,7 @@
     LValue LV;
     if (VD->getType()->isReferenceType()) {
       llvm::LoadInst *LI = Builder.CreateLoad(V);
-      LI->setAlignment(Alignment);
+      LI->setAlignment(Alignment.getQuantity());
       V = LI;
       LV = MakeNaturalAlignAddrLValue(V, T);
     } else {
@@ -1427,8 +1427,7 @@
 }
 
 LValue CodeGenFunction::EmitBlockDeclRefLValue(const BlockDeclRefExpr *E) {
-  unsigned Alignment =
-    getContext().getDeclAlign(E->getDecl()).getQuantity();
+  CharUnits Alignment = getContext().getDeclAlign(E->getDecl());
   return MakeAddrLValue(GetAddrOfBlockDecl(E), E->getType(), Alignment);
 }
 
@@ -1636,7 +1635,7 @@
   // We know that the pointer points to a type of the correct size, unless the
   // size is a VLA or Objective-C interface.
   llvm::Value *Address = 0;
-  unsigned ArrayAlignment = 0;
+  CharUnits ArrayAlignment;
   if (const VariableArrayType *vla =
         getContext().getAsVariableArrayType(E->getType())) {
     // The base must be a pointer, which is not an aggregate.  Emit
@@ -1704,8 +1703,8 @@
          "CodeGenFunction::EmitArraySubscriptExpr(): Illegal base type");
 
   // Limit the alignment to that of the result type.
-  if (ArrayAlignment) {
-    unsigned Align = getContext().getTypeAlignInChars(T).getQuantity();
+  if (!ArrayAlignment.isZero()) {
+    CharUnits Align = getContext().getTypeAlignInChars(T);
     ArrayAlignment = std::min(Align, ArrayAlignment);
   }
 
@@ -1866,7 +1865,7 @@
 
   const RecordDecl *rec = field->getParent();
   QualType type = field->getType();
-  unsigned alignment = getContext().getDeclAlign(field).getQuantity();
+  CharUnits alignment = getContext().getDeclAlign(field);
 
   bool mayAlias = rec->hasAttr<MayAliasAttr>();
 
@@ -1883,7 +1882,7 @@
     if (const ReferenceType *refType = type->getAs<ReferenceType>()) {
       llvm::LoadInst *load = Builder.CreateLoad(addr, "ref");
       if (cvr & Qualifiers::Volatile) load->setVolatile(true);
-      load->setAlignment(alignment);
+      load->setAlignment(alignment.getQuantity());
 
       if (CGM.shouldUseTBAA()) {
         llvm::MDNode *tbaa;
@@ -1898,9 +1897,9 @@
       mayAlias = false;
       type = refType->getPointeeType();
       if (type->isIncompleteType())
-        alignment = 0;
+        alignment = CharUnits();
       else
-        alignment = getContext().getTypeAlignInChars(type).getQuantity();
+        alignment = getContext().getTypeAlignInChars(type);
       cvr = 0; // qualifiers don't recursively apply to referencee
     }
   }
@@ -1956,7 +1955,7 @@
   unsigned AS = cast<llvm::PointerType>(V->getType())->getAddressSpace();
   V = Builder.CreateBitCast(V, llvmType->getPointerTo(AS));
   
-  unsigned Alignment = getContext().getDeclAlign(Field).getQuantity();
+  CharUnits Alignment = getContext().getDeclAlign(Field);
   return MakeAddrLValue(V, FieldType, Alignment);
 }
 

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=145753&r1=145752&r2=145753&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Fri Dec  2 22:14:32 2011
@@ -753,7 +753,7 @@
   CharUnits Alignment = CGF.getContext().getTypeAlignInChars(AllocType);
   if (!CGF.hasAggregateLLVMType(AllocType))
     CGF.EmitScalarInit(Init, 0, CGF.MakeAddrLValue(NewPtr, AllocType,
-                                                   Alignment.getQuantity()),
+                                                   Alignment),
                        false);
   else if (AllocType->isAnyComplexType())
     CGF.EmitComplexExprIntoAddr(Init, NewPtr, 

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=145753&r1=145752&r2=145753&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Fri Dec  2 22:14:32 2011
@@ -1700,7 +1700,8 @@
   // lvalue is inadequately aligned.
   if (shouldUseFusedARCCalls() &&
       !isBlock &&
-      !(dst.getAlignment() && dst.getAlignment() < PointerAlignInBytes)) {
+      (dst.getAlignment().isZero() ||
+       dst.getAlignment() >= CharUnits::fromQuantity(PointerAlignInBytes))) {
     return EmitARCStoreStrongCall(dst.getAddress(), newValue, ignored);
   }
 
@@ -2416,12 +2417,8 @@
   // If the RHS was emitted retained, expand this.
   if (hasImmediateRetain) {
     llvm::Value *oldValue =
-      EmitLoadOfScalar(lvalue.getAddress(), lvalue.isVolatileQualified(),
-                       lvalue.getAlignment(), e->getType(),
-                       lvalue.getTBAAInfo());
-    EmitStoreOfScalar(value, lvalue.getAddress(),
-                      lvalue.isVolatileQualified(), lvalue.getAlignment(),
-                      e->getType(), lvalue.getTBAAInfo());
+      EmitLoadOfScalar(lvalue);
+    EmitStoreOfScalar(value, lvalue);
     EmitARCRelease(oldValue, /*precise*/ false);
   } else {
     value = EmitARCStoreStrong(lvalue, value, ignored);
@@ -2435,9 +2432,7 @@
   llvm::Value *value = EmitARCRetainAutoreleaseScalarExpr(e->getRHS());
   LValue lvalue = EmitLValue(e->getLHS());
 
-  EmitStoreOfScalar(value, lvalue.getAddress(),
-                    lvalue.isVolatileQualified(), lvalue.getAlignment(),
-                    e->getType(), lvalue.getTBAAInfo());
+  EmitStoreOfScalar(value, lvalue);
 
   return std::pair<LValue,llvm::Value*>(lvalue, value);
 }

Modified: cfe/trunk/lib/CodeGen/CGValue.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGValue.h?rev=145753&r1=145752&r2=145753&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGValue.h (original)
+++ cfe/trunk/lib/CodeGen/CGValue.h Fri Dec  2 22:14:32 2011
@@ -151,12 +151,14 @@
   llvm::MDNode *TBAAInfo;
 
 private:
-  void Initialize(QualType Type, Qualifiers Quals, unsigned Alignment = 0,
+  void Initialize(QualType Type, Qualifiers Quals,
+                  CharUnits Alignment = CharUnits(),
                   llvm::MDNode *TBAAInfo = 0) {
     this->Type = Type;
     this->Quals = Quals;
-    this->Alignment = Alignment;
-    assert(this->Alignment == Alignment && "Alignment exceeds allowed max!");
+    this->Alignment = Alignment.getQuantity();
+    assert(this->Alignment == Alignment.getQuantity() &&
+           "Alignment exceeds allowed max!");
 
     // Initialize Objective-C flags.
     this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
@@ -220,8 +222,8 @@
 
   unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
 
-  unsigned getAlignment() const { return Alignment; }
-  void setAlignment(unsigned A) { Alignment = A; }
+  CharUnits getAlignment() const { return CharUnits::fromQuantity(Alignment); }
+  void setAlignment(CharUnits A) { Alignment = A.getQuantity(); }
 
   // simple lvalue
   llvm::Value *getAddress() const { assert(isSimple()); return V; }
@@ -252,7 +254,7 @@
   }
 
   static LValue MakeAddr(llvm::Value *address, QualType type,
-                         unsigned alignment, ASTContext &Context,
+                         CharUnits alignment, ASTContext &Context,
                          llvm::MDNode *TBAAInfo = 0) {
     Qualifiers qs = type.getQualifiers();
     qs.setObjCGCAttr(Context.getObjCGCAttrKind(type));
@@ -393,7 +395,7 @@
                                 NeedsGCBarriers_t needsGC,
                                 IsAliased_t isAliased,
                                 IsZeroed_t isZeroed = IsNotZeroed) {
-    return forAddr(LV.getAddress(), CharUnits::fromQuantity(LV.getAlignment()),
+    return forAddr(LV.getAddress(), LV.getAlignment(),
                    LV.getQuals(), isDestructed, needsGC, isAliased, isZeroed);
   }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=145753&r1=145752&r2=145753&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Dec  2 22:14:32 2011
@@ -1537,16 +1537,15 @@
   //                                  Helpers
   //===--------------------------------------------------------------------===//
 
-  LValue MakeAddrLValue(llvm::Value *V, QualType T, unsigned Alignment = 0) {
+  LValue MakeAddrLValue(llvm::Value *V, QualType T,
+                        CharUnits Alignment = CharUnits()) {
     return LValue::MakeAddr(V, T, Alignment, getContext(),
                             CGM.getTBAAInfo(T));
   }
   LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) {
-    unsigned Alignment;
-    if (T->isIncompleteType())
-      Alignment = 0;
-    else
-      Alignment = getContext().getTypeAlignInChars(T).getQuantity();
+    CharUnits Alignment;
+    if (!T->isIncompleteType())
+      Alignment = getContext().getTypeAlignInChars(T);
     return LValue::MakeAddr(V, T, Alignment, getContext(),
                             CGM.getTBAAInfo(T));
   }





More information about the cfe-commits mailing list