[PATCH] D38733: [CodeGen] Generate TBAA info along with LValue base info

2017-10-12 Thread Ivan Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315575: [CodeGen] Generate TBAA info along with LValue base 
info (authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D38733?vs=118551=118771#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38733

Files:
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h

Index: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -980,7 +980,8 @@
   SharedLVal = CGF.MakeAddrLValue(
   CGF.Builder.CreateElementBitCast(SharedLVal.getAddress(),
CGF.ConvertTypeForMem(SharedType)),
-  SharedType, SharedAddresses[N].first.getBaseInfo());
+  SharedType, SharedAddresses[N].first.getBaseInfo(),
+  CGF.CGM.getTBAAAccessInfo(SharedType));
   if (isa(ClausesData[N].Ref) ||
   CGF.getContext().getAsArrayType(PrivateVD->getType())) {
 emitAggregateInitialization(CGF, N, PrivateAddr, SharedLVal, DRD);
@@ -1033,7 +1034,8 @@
   return CGF.MakeAddrLValue(
   CGF.Builder.CreateElementBitCast(BaseLV.getAddress(),
CGF.ConvertTypeForMem(ElTy)),
-  BaseLV.getType(), BaseLV.getBaseInfo());
+  BaseLV.getType(), BaseLV.getBaseInfo(),
+  CGF.CGM.getTBAAAccessInfo(BaseLV.getType()));
 }
 
 static Address castToBase(CodeGenFunction , QualType BaseTy, QualType ElTy,
@@ -4072,7 +4074,8 @@
 Address(SharedRefLValue.getPointer(), C.getDeclAlign(OriginalVD)),
 SharedRefLValue.getType(),
 LValueBaseInfo(AlignmentSource::Decl,
-   SharedRefLValue.getBaseInfo().getMayAlias()));
+   SharedRefLValue.getBaseInfo().getMayAlias()),
+CGF.CGM.getTBAAAccessInfo(SharedRefLValue.getType()));
 QualType Type = OriginalVD->getType();
 if (Type->isArrayType()) {
   // Initialize firstprivate array.
Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
@@ -180,7 +180,8 @@
 CodeGenFunction::MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T) {
   LValueBaseInfo BaseInfo;
   CharUnits Align = getNaturalTypeAlignment(T, , /*pointee*/ true);
-  return MakeAddrLValue(Address(V, Align), T, BaseInfo);
+  return MakeAddrLValue(Address(V, Align), T, BaseInfo,
+CGM.getTBAAAccessInfo(T));
 }
 
 
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -2159,7 +2159,8 @@
   const ReferenceType *RefTy) {
   LValueBaseInfo BaseInfo;
   Address Addr = EmitLoadOfReference(RefAddr, RefTy, );
-  return MakeAddrLValue(Addr, RefTy->getPointeeType(), BaseInfo);
+  return MakeAddrLValue(Addr, RefTy->getPointeeType(), BaseInfo,
+CGM.getTBAAAccessInfo(RefTy->getPointeeType()));
 }
 
 Address CodeGenFunction::EmitLoadOfPointer(Address Ptr,
@@ -2175,7 +2176,8 @@
 const PointerType *PtrTy) {
   LValueBaseInfo BaseInfo;
   Address Addr = EmitLoadOfPointer(PtrAddr, PtrTy, );
-  return MakeAddrLValue(Addr, PtrTy->getPointeeType(), BaseInfo);
+  return MakeAddrLValue(Addr, PtrTy->getPointeeType(), BaseInfo,
+CGM.getTBAAAccessInfo(PtrTy->getPointeeType()));
 }
 
 static LValue EmitGlobalVarDeclLValue(CodeGenFunction ,
@@ -2328,7 +2330,8 @@
 bool MayAlias = CapLVal.getBaseInfo().getMayAlias();
 return MakeAddrLValue(
 Address(CapLVal.getPointer(), getContext().getDeclAlign(VD)),
-CapLVal.getType(), LValueBaseInfo(AlignmentSource::Decl, MayAlias));
+CapLVal.getType(), LValueBaseInfo(AlignmentSource::Decl, MayAlias),
+CGM.getTBAAAccessInfo(CapLVal.getType()));
   }
 
   assert(isa(CurCodeDecl));
@@ -2440,7 +2443,7 @@
 
 LValueBaseInfo BaseInfo;
 Address Addr = EmitPointerWithAlignment(E->getSubExpr(), );
-LValue LV = MakeAddrLValue(Addr, T, BaseInfo);
+LValue LV = MakeAddrLValue(Addr, T, BaseInfo, CGM.getTBAAAccessInfo(T));
 LV.getQuals().setAddressSpace(ExprTy.getAddressSpace());
 
 // We should not generate __weak write barrier on indirect reference
@@ -2472,7 +2475,8 @@
   (E->getOpcode() == UO_Real
  ? emitAddrOfRealComponent(LV.getAddress(), LV.getType())
  : emitAddrOfImagComponent(LV.getAddress(), LV.getType()));
-LValue ElemLV = MakeAddrLValue(Component, T, LV.getBaseInfo());
+LValue ElemLV = 

[PATCH] D38733: [CodeGen] Generate TBAA info along with LValue base info

2017-10-11 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Sure.


https://reviews.llvm.org/D38733



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38733: [CodeGen] Generate TBAA info along with LValue base info

2017-10-11 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 118551.
kosarev added a comment.

Removed changes related to functions like getNaturalTypeAlignment() that 
generate LValue base info objects to simplify the patch. These removed changes 
will be addressed with separate patches.


https://reviews.llvm.org/D38733

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h

Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1917,9 +1917,9 @@
 CGM.getTBAAAccessInfo(T));
   }
 
-  LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo) {
-return LValue::MakeAddr(Addr, T, getContext(), BaseInfo,
-CGM.getTBAAAccessInfo(T));
+  LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo,
+TBAAAccessInfo TBAAInfo) {
+return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo);
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
@@ -1930,9 +1930,9 @@
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
-LValueBaseInfo BaseInfo) {
+LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
 return LValue::MakeAddr(Address(V, Alignment), T, getContext(),
-BaseInfo, CGM.getTBAAAccessInfo(T));
+BaseInfo, TBAAInfo);
   }
 
   LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T);
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -180,7 +180,8 @@
 CodeGenFunction::MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T) {
   LValueBaseInfo BaseInfo;
   CharUnits Align = getNaturalTypeAlignment(T, , /*pointee*/ true);
-  return MakeAddrLValue(Address(V, Align), T, BaseInfo);
+  return MakeAddrLValue(Address(V, Align), T, BaseInfo,
+CGM.getTBAAAccessInfo(T));
 }
 
 
Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -980,7 +980,8 @@
   SharedLVal = CGF.MakeAddrLValue(
   CGF.Builder.CreateElementBitCast(SharedLVal.getAddress(),
CGF.ConvertTypeForMem(SharedType)),
-  SharedType, SharedAddresses[N].first.getBaseInfo());
+  SharedType, SharedAddresses[N].first.getBaseInfo(),
+  CGF.CGM.getTBAAAccessInfo(SharedType));
   if (isa(ClausesData[N].Ref) ||
   CGF.getContext().getAsArrayType(PrivateVD->getType())) {
 emitAggregateInitialization(CGF, N, PrivateAddr, SharedLVal, DRD);
@@ -1033,7 +1034,8 @@
   return CGF.MakeAddrLValue(
   CGF.Builder.CreateElementBitCast(BaseLV.getAddress(),
CGF.ConvertTypeForMem(ElTy)),
-  BaseLV.getType(), BaseLV.getBaseInfo());
+  BaseLV.getType(), BaseLV.getBaseInfo(),
+  CGF.CGM.getTBAAAccessInfo(BaseLV.getType()));
 }
 
 static Address castToBase(CodeGenFunction , QualType BaseTy, QualType ElTy,
@@ -4072,7 +4074,8 @@
 Address(SharedRefLValue.getPointer(), C.getDeclAlign(OriginalVD)),
 SharedRefLValue.getType(),
 LValueBaseInfo(AlignmentSource::Decl,
-   SharedRefLValue.getBaseInfo().getMayAlias()));
+   SharedRefLValue.getBaseInfo().getMayAlias()),
+CGF.CGM.getTBAAAccessInfo(SharedRefLValue.getType()));
 QualType Type = OriginalVD->getType();
 if (Type->isArrayType()) {
   // Initialize firstprivate array.
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -2159,7 +2159,8 @@
   const ReferenceType *RefTy) {
   LValueBaseInfo BaseInfo;
   Address Addr = EmitLoadOfReference(RefAddr, RefTy, );
-  return MakeAddrLValue(Addr, RefTy->getPointeeType(), BaseInfo);
+  return MakeAddrLValue(Addr, RefTy->getPointeeType(), BaseInfo,
+CGM.getTBAAAccessInfo(RefTy->getPointeeType()));
 }
 
 Address CodeGenFunction::EmitLoadOfPointer(Address Ptr,
@@ -2175,7 +2176,8 @@
 const PointerType *PtrTy) {
   LValueBaseInfo BaseInfo;
   Address Addr = EmitLoadOfPointer(PtrAddr, PtrTy, );
-  return MakeAddrLValue(Addr, PtrTy->getPointeeType(), BaseInfo);
+  return MakeAddrLValue(Addr, PtrTy->getPointeeType(), BaseInfo,
+CGM.getTBAAAccessInfo(PtrTy->getPointeeType()));
 }
 
 static LValue EmitGlobalVarDeclLValue(CodeGenFunction ,
@@ -2328,7 +2330,8 @@
 bool MayAlias = 

[PATCH] D38733: [CodeGen] Generate TBAA info along with LValue base info

2017-10-10 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev created this revision.
kosarev added a project: clang.

This patch enables explicit generation of TBAA information in all cases where 
LValue base info is propagated or constructed in non-trivial ways. Eventually, 
we will consider each of these cases to make sure the TBAA information is 
correct and not too conservative. For now, we just fall back to generating TBAA 
info from the access type.

This patch should not bring in any functional changes.

This is part of https://reviews.llvm.org/D38126 reworked to be a separate patch 
to simplify review.


Repository:
  rL LLVM

https://reviews.llvm.org/D38733

Files:
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h

Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1917,9 +1917,9 @@
 CGM.getTBAAAccessInfo(T));
   }
 
-  LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo) {
-return LValue::MakeAddr(Addr, T, getContext(), BaseInfo,
-CGM.getTBAAAccessInfo(T));
+  LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo,
+TBAAAccessInfo TBAAInfo) {
+return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo);
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
@@ -1930,25 +1930,28 @@
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
-LValueBaseInfo BaseInfo) {
+LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
 return LValue::MakeAddr(Address(V, Alignment), T, getContext(),
-BaseInfo, CGM.getTBAAAccessInfo(T));
+BaseInfo, TBAAInfo);
   }
 
   LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T);
   LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T);
   CharUnits getNaturalTypeAlignment(QualType T,
 LValueBaseInfo *BaseInfo = nullptr,
+TBAAAccessInfo *TBAAInfo = nullptr,
 bool forPointeeType = false);
   CharUnits getNaturalPointeeTypeAlignment(QualType T,
LValueBaseInfo *BaseInfo = nullptr);
 
   Address EmitLoadOfReference(Address Ref, const ReferenceType *RefTy,
-  LValueBaseInfo *BaseInfo = nullptr);
+  LValueBaseInfo *BaseInfo = nullptr,
+  TBAAAccessInfo *TBAAInfo = nullptr);
   LValue EmitLoadOfReferenceLValue(Address Ref, const ReferenceType *RefTy);
 
   Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy,
-LValueBaseInfo *BaseInfo = nullptr);
+LValueBaseInfo *BaseInfo = nullptr,
+TBAAAccessInfo *TBAAInfo = nullptr);
   LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy);
 
   /// CreateTempAlloca - This creates an alloca and inserts it into the entry
@@ -3327,7 +3330,8 @@
   Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base,
   llvm::Value *memberPtr,
   const MemberPointerType *memberPtrType,
-  LValueBaseInfo *BaseInfo = nullptr);
+  LValueBaseInfo *BaseInfo = nullptr,
+  TBAAAccessInfo *TBAAInfo = nullptr);
   RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E,
   ReturnValueSlot ReturnValue);
 
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -120,12 +120,17 @@
 CharUnits CodeGenFunction::getNaturalPointeeTypeAlignment(QualType T,
 LValueBaseInfo *BaseInfo) {
   return getNaturalTypeAlignment(T->getPointeeType(), BaseInfo,
- /*forPointee*/ true);
+ /* TBAAInfo= */ nullptr,
+ /* forPointeeType= */ true);
 }
 
 CharUnits CodeGenFunction::getNaturalTypeAlignment(QualType T,
LValueBaseInfo *BaseInfo,
+   TBAAAccessInfo *TBAAInfo,
bool forPointeeType) {
+  if (TBAAInfo)
+*TBAAInfo = CGM.getTBAAAccessInfo(T);
+
   // Honor alignment typedef attributes even on incomplete types.
   // We also honor them straight for C++ class types, even as pointees;
   // there's an