]> granicus.if.org Git - clang/commitdiff
Switch LValue so that it exposes alignment in CharUnits. (No functional change.)
authorEli Friedman <eli.friedman@gmail.com>
Sat, 3 Dec 2011 04:14:32 +0000 (04:14 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 3 Dec 2011 04:14:32 +0000 (04:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145753 91177308-0d34-0410-b5e6-96231b3b80d8

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

index e713492cc0adf63a27432d7a1dc002f92a502c38..8fc43442018cd41a58b4433cd7630ac5437bcb8f 100644 (file)
@@ -745,8 +745,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) {
                            declRef, VK_RValue);
       EmitExprAsInit(&l2r, &blockFieldPseudoVar,
                      MakeAddrLValue(blockField, type,
-                                    getContext().getDeclAlign(variable)
-                                                .getQuantity()),
+                                    getContext().getDeclAlign(variable)),
                      /*captured by init*/ false);
     }
 
index 93bc1753ce89e831f1959853081b4900837fb8e9..3457b5bc141ba689541b7fc5ead3fb448b3f2266 100644 (file)
@@ -1060,8 +1060,9 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
       // 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);
 
index eabc201cc47155e41a56a654ddaae6452a8b492e..8a305fde2d480426ef32c301aafbe28ce5663c0e 100644 (file)
@@ -434,7 +434,7 @@ static void EmitAggMemberInitializer(CodeGenFunction &CGF,
 
       // 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()));
     }
 
index c7bc87ba1ef4c954c56f54ce5eeb688cee447918..ff85fc56886eb43b014713c3c93b2c8a05f4d37f 100644 (file)
@@ -972,7 +972,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
     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 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, llvm::Value *Arg,
     // Store the initial value into the alloca.
     if (doStore) {
       LValue lv = MakeAddrLValue(DeclPtr, Ty,
-                                 getContext().getDeclAlign(&D).getQuantity());
+                                 getContext().getDeclAlign(&D));
       EmitStoreOfScalar(Arg, lv);
     }
   }
index 3b8f830278b2edbdf5dd71517b26550ad4039679..2f32381c5efcbadb3e5a4c31b2f2e02405d4feff 100644 (file)
@@ -28,7 +28,7 @@ static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D,
   
   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);
 
index a8c134b2ae83d704c9f9f79c55390792c54f70c7..2ed7b1ad81426e4413a0c50e30e70f32a0edec48 100644 (file)
@@ -750,8 +750,8 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
 
 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, llvm::Value *Addr,
 
 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 @@ static LValue EmitGlobalVarDeclLValue(CodeGenFunction &CGF,
   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 @@ static LValue EmitFunctionDeclLValue(CodeGenFunction &CGF,
       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 CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
     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::EmitDeclRefLValue(const DeclRefExpr *E) {
 }
 
 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 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
   // 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 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
          "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 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value *baseAddr,
 
   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 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value *baseAddr,
     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 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value *baseAddr,
       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 @@ CodeGenFunction::EmitLValueForFieldInitialization(llvm::Value *BaseValue,
   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);
 }
 
index da1ca2ccf3f350853c6686c3fc158d7108a97809..ed7605e34b852c36c6462278647f0ae30f82c82d 100644 (file)
@@ -753,7 +753,7 @@ static void StoreAnyExprIntoOneUnit(CodeGenFunction &CGF, const CXXNewExpr *E,
   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, 
index 686f0e68334b6077fdcfc3da039fcf1835dde481..4e5915a3ae5e9ab102c6235c04dcfee05015feda 100644 (file)
@@ -1700,7 +1700,8 @@ llvm::Value *CodeGenFunction::EmitARCStoreStrong(LValue dst,
   // 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 @@ CodeGenFunction::EmitARCStoreStrong(const BinaryOperator *e,
   // 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 @@ CodeGenFunction::EmitARCStoreAutoreleasing(const BinaryOperator *e) {
   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);
 }
index fd85fb24894a936b1dbc6cb736d28a1d45a35368..b8fe2a25b467ddcce72af21234135d9c15acf8be 100644 (file)
@@ -151,12 +151,14 @@ class LValue {
   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 @@ public:
 
   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 @@ public:
   }
 
   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 @@ public:
                                 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);
   }
 
index 74f48c3d805d46778c2fb91518b4ef47db886a6b..d611996bd1e6ae36db5d47a4deb8628ed1494797 100644 (file)
@@ -1537,16 +1537,15 @@ public:
   //                                  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));
   }