Prechádzať zdrojové kódy

[CodeGen] getNaturalTypeAlignment() to generate TBAA info along with LValue base info

This patch should not bring in any functional changes.

Differential Revision: https://reviews.llvm.org/D38794


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315708 91177308-0d34-0410-b5e6-96231b3b80d8
Ivan A. Kosarev 7 rokov pred
rodič
commit
8ebf4572cb

+ 2 - 3
lib/CodeGen/CGClass.cpp

@@ -137,9 +137,8 @@ CodeGenFunction::EmitCXXMemberDataPointerAddress(const Expr *E, Address base,
                                                  memberPtr, memberPtrType);
                                                  memberPtr, memberPtrType);
 
 
   QualType memberType = memberPtrType->getPointeeType();
   QualType memberType = memberPtrType->getPointeeType();
-  if (TBAAInfo)
-    *TBAAInfo = CGM.getTBAAAccessInfo(memberType);
-  CharUnits memberAlign = getNaturalTypeAlignment(memberType, BaseInfo);
+  CharUnits memberAlign = getNaturalTypeAlignment(memberType, BaseInfo,
+                                                  TBAAInfo);
   memberAlign =
   memberAlign =
     CGM.getDynamicOffsetAlignment(base.getAlignment(),
     CGM.getDynamicOffsetAlignment(base.getAlignment(),
                             memberPtrType->getClass()->getAsCXXRecordDecl(),
                             memberPtrType->getClass()->getAsCXXRecordDecl(),

+ 9 - 11
lib/CodeGen/CGExpr.cpp

@@ -2151,12 +2151,10 @@ Address CodeGenFunction::EmitLoadOfReference(Address Addr,
                                              const ReferenceType *RefTy,
                                              const ReferenceType *RefTy,
                                              LValueBaseInfo *BaseInfo,
                                              LValueBaseInfo *BaseInfo,
                                              TBAAAccessInfo *TBAAInfo) {
                                              TBAAAccessInfo *TBAAInfo) {
-  if (TBAAInfo)
-    *TBAAInfo = CGM.getTBAAAccessInfo(RefTy->getPointeeType());
-
   llvm::Value *Ptr = Builder.CreateLoad(Addr);
   llvm::Value *Ptr = Builder.CreateLoad(Addr);
   return Address(Ptr, getNaturalTypeAlignment(RefTy->getPointeeType(),
   return Address(Ptr, getNaturalTypeAlignment(RefTy->getPointeeType(),
-                                              BaseInfo, /*forPointee*/ true));
+                                              BaseInfo, TBAAInfo,
+                                              /* forPointeeType= */ true));
 }
 }
 
 
 LValue CodeGenFunction::EmitLoadOfReferenceLValue(Address RefAddr,
 LValue CodeGenFunction::EmitLoadOfReferenceLValue(Address RefAddr,
@@ -2171,12 +2169,9 @@ Address CodeGenFunction::EmitLoadOfPointer(Address Ptr,
                                            const PointerType *PtrTy,
                                            const PointerType *PtrTy,
                                            LValueBaseInfo *BaseInfo,
                                            LValueBaseInfo *BaseInfo,
                                            TBAAAccessInfo *TBAAInfo) {
                                            TBAAAccessInfo *TBAAInfo) {
-  if (TBAAInfo)
-    *TBAAInfo = CGM.getTBAAAccessInfo(PtrTy->getPointeeType());
-
   llvm::Value *Addr = Builder.CreateLoad(Ptr);
   llvm::Value *Addr = Builder.CreateLoad(Ptr);
   return Address(Addr, getNaturalTypeAlignment(PtrTy->getPointeeType(),
   return Address(Addr, getNaturalTypeAlignment(PtrTy->getPointeeType(),
-                                               BaseInfo,
+                                               BaseInfo, TBAAInfo,
                                                /*forPointeeType=*/true));
                                                /*forPointeeType=*/true));
 }
 }
 
 
@@ -2315,8 +2310,10 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
       // FIXME: Eventually we will want to emit vector element references.
       // FIXME: Eventually we will want to emit vector element references.
 
 
       // Should we be using the alignment of the constant pointer we emitted?
       // Should we be using the alignment of the constant pointer we emitted?
-      CharUnits Alignment = getNaturalTypeAlignment(E->getType(), nullptr,
-                                                    /*pointee*/ true);
+      CharUnits Alignment = getNaturalTypeAlignment(E->getType(),
+                                                    /* BaseInfo= */ nullptr,
+                                                    /* TBAAInfo= */ nullptr,
+                                                    /* forPointeeType= */ true);
       return MakeAddrLValue(Address(Val, Alignment), T, AlignmentSource::Decl);
       return MakeAddrLValue(Address(Val, Alignment), T, AlignmentSource::Decl);
     }
     }
 
 
@@ -3729,7 +3726,8 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
       type = refType->getPointeeType();
       type = refType->getPointeeType();
 
 
       CharUnits alignment =
       CharUnits alignment =
-        getNaturalTypeAlignment(type, &FieldBaseInfo, /*pointee*/ true);
+        getNaturalTypeAlignment(type, &FieldBaseInfo, /* TBAAInfo= */ nullptr,
+                                /* forPointeeType= */ true);
       FieldBaseInfo.setMayAlias(false);
       FieldBaseInfo.setMayAlias(false);
       addr = Address(load, alignment);
       addr = Address(load, alignment);
 
 

+ 13 - 6
lib/CodeGen/CodeGenFunction.cpp

@@ -120,12 +120,17 @@ CodeGenFunction::~CodeGenFunction() {
 CharUnits CodeGenFunction::getNaturalPointeeTypeAlignment(QualType T,
 CharUnits CodeGenFunction::getNaturalPointeeTypeAlignment(QualType T,
                                                     LValueBaseInfo *BaseInfo) {
                                                     LValueBaseInfo *BaseInfo) {
   return getNaturalTypeAlignment(T->getPointeeType(), BaseInfo,
   return getNaturalTypeAlignment(T->getPointeeType(), BaseInfo,
-                                 /*forPointee*/ true);
+                                 /* TBAAInfo= */ nullptr,
+                                 /* forPointeeType= */ true);
 }
 }
 
 
 CharUnits CodeGenFunction::getNaturalTypeAlignment(QualType T,
 CharUnits CodeGenFunction::getNaturalTypeAlignment(QualType T,
                                                    LValueBaseInfo *BaseInfo,
                                                    LValueBaseInfo *BaseInfo,
+                                                   TBAAAccessInfo *TBAAInfo,
                                                    bool forPointeeType) {
                                                    bool forPointeeType) {
+  if (TBAAInfo)
+    *TBAAInfo = CGM.getTBAAAccessInfo(T);
+
   // Honor alignment typedef attributes even on incomplete types.
   // Honor alignment typedef attributes even on incomplete types.
   // We also honor them straight for C++ class types, even as pointees;
   // We also honor them straight for C++ class types, even as pointees;
   // there's an expressivity gap here.
   // there's an expressivity gap here.
@@ -169,9 +174,10 @@ CharUnits CodeGenFunction::getNaturalTypeAlignment(QualType T,
 
 
 LValue CodeGenFunction::MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) {
 LValue CodeGenFunction::MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) {
   LValueBaseInfo BaseInfo;
   LValueBaseInfo BaseInfo;
-  CharUnits Alignment = getNaturalTypeAlignment(T, &BaseInfo);
+  TBAAAccessInfo TBAAInfo;
+  CharUnits Alignment = getNaturalTypeAlignment(T, &BaseInfo, &TBAAInfo);
   return LValue::MakeAddr(Address(V, Alignment), T, getContext(), BaseInfo,
   return LValue::MakeAddr(Address(V, Alignment), T, getContext(), BaseInfo,
-                          CGM.getTBAAAccessInfo(T));
+                          TBAAInfo);
 }
 }
 
 
 /// Given a value of type T* that may not be to a complete object,
 /// Given a value of type T* that may not be to a complete object,
@@ -179,9 +185,10 @@ LValue CodeGenFunction::MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) {
 LValue
 LValue
 CodeGenFunction::MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T) {
 CodeGenFunction::MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T) {
   LValueBaseInfo BaseInfo;
   LValueBaseInfo BaseInfo;
-  CharUnits Align = getNaturalTypeAlignment(T, &BaseInfo, /*pointee*/ true);
-  return MakeAddrLValue(Address(V, Align), T, BaseInfo,
-                        CGM.getTBAAAccessInfo(T));
+  TBAAAccessInfo TBAAInfo;
+  CharUnits Align = getNaturalTypeAlignment(T, &BaseInfo, &TBAAInfo,
+                                            /* forPointeeType= */ true);
+  return MakeAddrLValue(Address(V, Align), T, BaseInfo, TBAAInfo);
 }
 }
 
 
 
 

+ 1 - 0
lib/CodeGen/CodeGenFunction.h

@@ -1939,6 +1939,7 @@ public:
   LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T);
   LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T);
   CharUnits getNaturalTypeAlignment(QualType T,
   CharUnits getNaturalTypeAlignment(QualType T,
                                     LValueBaseInfo *BaseInfo = nullptr,
                                     LValueBaseInfo *BaseInfo = nullptr,
+                                    TBAAAccessInfo *TBAAInfo = nullptr,
                                     bool forPointeeType = false);
                                     bool forPointeeType = false);
   CharUnits getNaturalPointeeTypeAlignment(QualType T,
   CharUnits getNaturalPointeeTypeAlignment(QualType T,
                                            LValueBaseInfo *BaseInfo = nullptr);
                                            LValueBaseInfo *BaseInfo = nullptr);