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

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

This patch should not bring in any functional changes. Prepared on top of 
https://reviews.llvm.org/D38733, https://reviews.llvm.org/D38788,  
https://reviews.llvm.org/D38791 and https://reviews.llvm.org/D38793.


Repository:
  rL LLVM

https://reviews.llvm.org/D38794

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

Index: CodeGen/CodeGenFunction.h
===
--- CodeGen/CodeGenFunction.h
+++ CodeGen/CodeGenFunction.h
@@ -1939,6 +1939,7 @@
   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);
Index: CodeGen/CodeGenFunction.cpp
===
--- CodeGen/CodeGenFunction.cpp
+++ 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 expressivity gap here.
@@ -169,19 +174,21 @@
 
 LValue CodeGenFunction::MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) {
   LValueBaseInfo BaseInfo;
-  CharUnits Alignment = getNaturalTypeAlignment(T, );
+  TBAAAccessInfo TBAAInfo;
+  CharUnits Alignment = getNaturalTypeAlignment(T, , );
   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,
 /// construct an l-value with the natural pointee alignment of T.
 LValue
 CodeGenFunction::MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T) {
   LValueBaseInfo BaseInfo;
-  CharUnits Align = getNaturalTypeAlignment(T, , /*pointee*/ true);
-  return MakeAddrLValue(Address(V, Align), T, BaseInfo,
-CGM.getTBAAAccessInfo(T));
+  TBAAAccessInfo TBAAInfo;
+  CharUnits Align = getNaturalTypeAlignment(T, , ,
+/* forPointeeType= */ true);
+  return MakeAddrLValue(Address(V, Align), T, BaseInfo, TBAAInfo);
 }
 
 
Index: CodeGen/CGExpr.cpp
===
--- CodeGen/CGExpr.cpp
+++ CodeGen/CGExpr.cpp
@@ -2151,12 +2151,10 @@
  const ReferenceType *RefTy,
  LValueBaseInfo *BaseInfo,
  TBAAAccessInfo *TBAAInfo) {
-  if (TBAAInfo)
-*TBAAInfo = CGM.getTBAAAccessInfo(RefTy->getPointeeType());
-
   llvm::Value *Ptr = Builder.CreateLoad(Addr);
   return Address(Ptr, getNaturalTypeAlignment(RefTy->getPointeeType(),
-  BaseInfo, /*forPointee*/ true));
+  BaseInfo, TBAAInfo,
+  /* forPointeeType= */ true));
 }
 
 LValue CodeGenFunction::EmitLoadOfReferenceLValue(Address RefAddr,
@@ -2171,12 +2169,9 @@
const PointerType *PtrTy,
LValueBaseInfo *BaseInfo,
TBAAAccessInfo *TBAAInfo) {
-  if (TBAAInfo)
-*TBAAInfo = CGM.getTBAAAccessInfo(PtrTy->getPointeeType());
-
   llvm::Value *Addr = Builder.CreateLoad(Ptr);
   return Address(Addr, getNaturalTypeAlignment(PtrTy->getPointeeType(),
-   BaseInfo,
+   BaseInfo, TBAAInfo,
/*forPointeeType=*/true));
 }
 
@@ -2315,8 +2310,10 @@
   // FIXME: Eventually we will want to emit vector element references.
 
   // Should we be using the 

[PATCH] D38793: [CodeGen] EmitLoadOfReference() to generate TBAA info along with LValue base info

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

Repository:
  rL LLVM

https://reviews.llvm.org/D38793

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


Index: CodeGen/CodeGenFunction.h
===
--- CodeGen/CodeGenFunction.h
+++ CodeGen/CodeGenFunction.h
@@ -1944,7 +1944,8 @@
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,
Index: CodeGen/CGExpr.cpp
===
--- CodeGen/CGExpr.cpp
+++ CodeGen/CGExpr.cpp
@@ -2149,18 +2149,22 @@
 
 Address CodeGenFunction::EmitLoadOfReference(Address Addr,
  const ReferenceType *RefTy,
- LValueBaseInfo *BaseInfo) {
+ LValueBaseInfo *BaseInfo,
+ TBAAAccessInfo *TBAAInfo) {
+  if (TBAAInfo)
+*TBAAInfo = CGM.getTBAAAccessInfo(RefTy->getPointeeType());
+
   llvm::Value *Ptr = Builder.CreateLoad(Addr);
   return Address(Ptr, getNaturalTypeAlignment(RefTy->getPointeeType(),
   BaseInfo, /*forPointee*/ true));
 }
 
 LValue CodeGenFunction::EmitLoadOfReferenceLValue(Address RefAddr,
   const ReferenceType *RefTy) {
   LValueBaseInfo BaseInfo;
-  Address Addr = EmitLoadOfReference(RefAddr, RefTy, );
-  return MakeAddrLValue(Addr, RefTy->getPointeeType(), BaseInfo,
-CGM.getTBAAAccessInfo(RefTy->getPointeeType()));
+  TBAAAccessInfo TBAAInfo;
+  Address Addr = EmitLoadOfReference(RefAddr, RefTy, , );
+  return MakeAddrLValue(Addr, RefTy->getPointeeType(), BaseInfo, TBAAInfo);
 }
 
 Address CodeGenFunction::EmitLoadOfPointer(Address Ptr,


Index: CodeGen/CodeGenFunction.h
===
--- CodeGen/CodeGenFunction.h
+++ CodeGen/CodeGenFunction.h
@@ -1944,7 +1944,8 @@
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,
Index: CodeGen/CGExpr.cpp
===
--- CodeGen/CGExpr.cpp
+++ CodeGen/CGExpr.cpp
@@ -2149,18 +2149,22 @@
 
 Address CodeGenFunction::EmitLoadOfReference(Address Addr,
  const ReferenceType *RefTy,
- LValueBaseInfo *BaseInfo) {
+ LValueBaseInfo *BaseInfo,
+ TBAAAccessInfo *TBAAInfo) {
+  if (TBAAInfo)
+*TBAAInfo = CGM.getTBAAAccessInfo(RefTy->getPointeeType());
+
   llvm::Value *Ptr = Builder.CreateLoad(Addr);
   return Address(Ptr, getNaturalTypeAlignment(RefTy->getPointeeType(),
   BaseInfo, /*forPointee*/ true));
 }
 
 LValue CodeGenFunction::EmitLoadOfReferenceLValue(Address RefAddr,
   const ReferenceType *RefTy) {
   LValueBaseInfo BaseInfo;
-  Address Addr = EmitLoadOfReference(RefAddr, RefTy, );
-  return MakeAddrLValue(Addr, RefTy->getPointeeType(), BaseInfo,
-CGM.getTBAAAccessInfo(RefTy->getPointeeType()));
+  TBAAAccessInfo TBAAInfo;
+  Address Addr = EmitLoadOfReference(RefAddr, RefTy, , );
+  return MakeAddrLValue(Addr, RefTy->getPointeeType(), BaseInfo, TBAAInfo);
 }
 
 Address CodeGenFunction::EmitLoadOfPointer(Address Ptr,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38791: [CodeGen] EmitLoadOfPointerLValue() to generate TBAA info along with LValue base info

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

This patch should not bring in any functional changes. Prepared on top of 
https://reviews.llvm.org/D38733.


Repository:
  rL LLVM

https://reviews.llvm.org/D38791

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


Index: CodeGen/CodeGenFunction.h
===
--- CodeGen/CodeGenFunction.h
+++ CodeGen/CodeGenFunction.h
@@ -1948,7 +1948,8 @@
   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
Index: CodeGen/CGExpr.cpp
===
--- CodeGen/CGExpr.cpp
+++ CodeGen/CGExpr.cpp
@@ -2165,7 +2165,11 @@
 
 Address CodeGenFunction::EmitLoadOfPointer(Address Ptr,
const PointerType *PtrTy,
-   LValueBaseInfo *BaseInfo) {
+   LValueBaseInfo *BaseInfo,
+   TBAAAccessInfo *TBAAInfo) {
+  if (TBAAInfo)
+*TBAAInfo = CGM.getTBAAAccessInfo(PtrTy->getPointeeType());
+
   llvm::Value *Addr = Builder.CreateLoad(Ptr);
   return Address(Addr, getNaturalTypeAlignment(PtrTy->getPointeeType(),
BaseInfo,
@@ -2175,9 +2179,9 @@
 LValue CodeGenFunction::EmitLoadOfPointerLValue(Address PtrAddr,
 const PointerType *PtrTy) {
   LValueBaseInfo BaseInfo;
-  Address Addr = EmitLoadOfPointer(PtrAddr, PtrTy, );
-  return MakeAddrLValue(Addr, PtrTy->getPointeeType(), BaseInfo,
-CGM.getTBAAAccessInfo(PtrTy->getPointeeType()));
+  TBAAAccessInfo TBAAInfo;
+  Address Addr = EmitLoadOfPointer(PtrAddr, PtrTy, , );
+  return MakeAddrLValue(Addr, PtrTy->getPointeeType(), BaseInfo, TBAAInfo);
 }
 
 static LValue EmitGlobalVarDeclLValue(CodeGenFunction ,


Index: CodeGen/CodeGenFunction.h
===
--- CodeGen/CodeGenFunction.h
+++ CodeGen/CodeGenFunction.h
@@ -1948,7 +1948,8 @@
   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
Index: CodeGen/CGExpr.cpp
===
--- CodeGen/CGExpr.cpp
+++ CodeGen/CGExpr.cpp
@@ -2165,7 +2165,11 @@
 
 Address CodeGenFunction::EmitLoadOfPointer(Address Ptr,
const PointerType *PtrTy,
-   LValueBaseInfo *BaseInfo) {
+   LValueBaseInfo *BaseInfo,
+   TBAAAccessInfo *TBAAInfo) {
+  if (TBAAInfo)
+*TBAAInfo = CGM.getTBAAAccessInfo(PtrTy->getPointeeType());
+
   llvm::Value *Addr = Builder.CreateLoad(Ptr);
   return Address(Addr, getNaturalTypeAlignment(PtrTy->getPointeeType(),
BaseInfo,
@@ -2175,9 +2179,9 @@
 LValue CodeGenFunction::EmitLoadOfPointerLValue(Address PtrAddr,
 const PointerType *PtrTy) {
   LValueBaseInfo BaseInfo;
-  Address Addr = EmitLoadOfPointer(PtrAddr, PtrTy, );
-  return MakeAddrLValue(Addr, PtrTy->getPointeeType(), BaseInfo,
-CGM.getTBAAAccessInfo(PtrTy->getPointeeType()));
+  TBAAAccessInfo TBAAInfo;
+  Address Addr = EmitLoadOfPointer(PtrAddr, PtrTy, , );
+  return MakeAddrLValue(Addr, PtrTy->getPointeeType(), BaseInfo, TBAAInfo);
 }
 
 static LValue EmitGlobalVarDeclLValue(CodeGenFunction ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38788: [CodeGen] EmitCXXMemberDataPointerAddress() to generate TBAA info along with LValue base info

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

Prepared on top of https://reviews.llvm.org/D38733.


Repository:
  rL LLVM

https://reviews.llvm.org/D38788

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


Index: CodeGen/CodeGenFunction.h
===
--- CodeGen/CodeGenFunction.h
+++ CodeGen/CodeGenFunction.h
@@ -3327,7 +3327,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: CodeGen/CGExpr.cpp
===
--- CodeGen/CGExpr.cpp
+++ CodeGen/CGExpr.cpp
@@ -4571,11 +4571,12 @@
 = E->getRHS()->getType()->getAs();
 
   LValueBaseInfo BaseInfo;
+  TBAAAccessInfo TBAAInfo;
   Address MemberAddr =
-EmitCXXMemberDataPointerAddress(E, BaseAddr, OffsetV, MPT, );
+EmitCXXMemberDataPointerAddress(E, BaseAddr, OffsetV, MPT, ,
+);
 
-  return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), BaseInfo,
-CGM.getTBAAAccessInfo(MPT->getPointeeType()));
+  return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), BaseInfo, TBAAInfo);
 }
 
 /// Given the address of a temporary variable, produce an r-value of
Index: CodeGen/CGClass.cpp
===
--- CodeGen/CGClass.cpp
+++ CodeGen/CGClass.cpp
@@ -129,13 +129,16 @@
 CodeGenFunction::EmitCXXMemberDataPointerAddress(const Expr *E, Address base,
  llvm::Value *memberPtr,
   const MemberPointerType *memberPtrType,
- LValueBaseInfo *BaseInfo) {
+ LValueBaseInfo *BaseInfo,
+ TBAAAccessInfo *TBAAInfo) {
   // Ask the ABI to compute the actual address.
   llvm::Value *ptr =
 CGM.getCXXABI().EmitMemberDataPointerAddress(*this, E, base,
  memberPtr, memberPtrType);
 
   QualType memberType = memberPtrType->getPointeeType();
+  if (TBAAInfo)
+*TBAAInfo = CGM.getTBAAAccessInfo(memberType);
   CharUnits memberAlign = getNaturalTypeAlignment(memberType, BaseInfo);
   memberAlign =
 CGM.getDynamicOffsetAlignment(base.getAlignment(),


Index: CodeGen/CodeGenFunction.h
===
--- CodeGen/CodeGenFunction.h
+++ CodeGen/CodeGenFunction.h
@@ -3327,7 +3327,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: CodeGen/CGExpr.cpp
===
--- CodeGen/CGExpr.cpp
+++ CodeGen/CGExpr.cpp
@@ -4571,11 +4571,12 @@
 = E->getRHS()->getType()->getAs();
 
   LValueBaseInfo BaseInfo;
+  TBAAAccessInfo TBAAInfo;
   Address MemberAddr =
-EmitCXXMemberDataPointerAddress(E, BaseAddr, OffsetV, MPT, );
+EmitCXXMemberDataPointerAddress(E, BaseAddr, OffsetV, MPT, ,
+);
 
-  return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), BaseInfo,
-CGM.getTBAAAccessInfo(MPT->getPointeeType()));
+  return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), BaseInfo, TBAAInfo);
 }
 
 /// Given the address of a temporary variable, produce an r-value of
Index: CodeGen/CGClass.cpp
===
--- CodeGen/CGClass.cpp
+++ CodeGen/CGClass.cpp
@@ -129,13 +129,16 @@
 CodeGenFunction::EmitCXXMemberDataPointerAddress(const Expr *E, Address base,
  llvm::Value *memberPtr,
   const MemberPointerType *memberPtrType,
- LValueBaseInfo *BaseInfo) {
+ LValueBaseInfo 

[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 

[PATCH] D38695: [CodeGen] Do not construct complete LValue base info in trivial cases

2017-10-10 Thread Ivan A. Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315289: [CodeGen] Do not construct complete LValue base info 
in trivial cases (authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D38695?vs=118234=118335#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38695

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

Index: cfe/trunk/lib/CodeGen/CGObjC.cpp
===
--- cfe/trunk/lib/CodeGen/CGObjC.cpp
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp
@@ -162,7 +162,7 @@
   const Expr *Rhs = ALE->getElement(i);
   LValue LV = MakeAddrLValue(
   Builder.CreateConstArrayGEP(Objects, i, getPointerSize()),
-  ElementType, LValueBaseInfo(AlignmentSource::Decl, false));
+  ElementType, AlignmentSource::Decl);
 
   llvm::Value *value = EmitScalarExpr(Rhs);
   EmitStoreThroughLValue(RValue::get(value), LV, true);
@@ -174,15 +174,15 @@
   const Expr *Key = DLE->getKeyValueElement(i).Key;
   LValue KeyLV = MakeAddrLValue(
   Builder.CreateConstArrayGEP(Keys, i, getPointerSize()),
-  ElementType, LValueBaseInfo(AlignmentSource::Decl, false));
+  ElementType, AlignmentSource::Decl);
   llvm::Value *keyValue = EmitScalarExpr(Key);
   EmitStoreThroughLValue(RValue::get(keyValue), KeyLV, /*isInit=*/true);
 
   // Emit the value and store it to the appropriate array slot.
   const Expr *Value = DLE->getKeyValueElement(i).Value;
   LValue ValueLV = MakeAddrLValue(
   Builder.CreateConstArrayGEP(Objects, i, getPointerSize()),
-  ElementType, LValueBaseInfo(AlignmentSource::Decl, false));
+  ElementType, AlignmentSource::Decl);
   llvm::Value *valueValue = EmitScalarExpr(Value);
   EmitStoreThroughLValue(RValue::get(valueValue), ValueLV, /*isInit=*/true);
   if (TrackNeededObjects) {
Index: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
===
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
@@ -392,15 +392,14 @@
   continue;
 }
 
-LValueBaseInfo BaseInfo(AlignmentSource::Decl, false);
-LValue ArgLVal =
-CGF.MakeAddrLValue(LocalAddr, Args[Cnt]->getType(), BaseInfo);
+LValue ArgLVal = CGF.MakeAddrLValue(LocalAddr, Args[Cnt]->getType(),
+AlignmentSource::Decl);
 if (FD->hasCapturedVLAType()) {
   if (FO.UIntPtrCastRequired) {
 ArgLVal = CGF.MakeAddrLValue(castValueFromUintptr(CGF, FD->getType(),
   Args[Cnt]->getName(),
   ArgLVal),
- FD->getType(), BaseInfo);
+ FD->getType(), AlignmentSource::Decl);
   }
   auto *ExprArg =
   CGF.EmitLoadOfLValue(ArgLVal, SourceLocation()).getScalarVal();
@@ -497,22 +496,23 @@
   llvm::Function *WrapperF =
   emitOutlinedFunctionPrologue(WrapperCGF, Args, LocalAddrs, VLASizes,
WrapperCGF.CXXThisValue, WrapperFO);
-  LValueBaseInfo BaseInfo(AlignmentSource::Decl, false);
   llvm::SmallVector CallArgs;
   for (const auto *Arg : Args) {
 llvm::Value *CallArg;
 auto I = LocalAddrs.find(Arg);
 if (I != LocalAddrs.end()) {
   LValue LV =
-  WrapperCGF.MakeAddrLValue(I->second.second, Arg->getType(), BaseInfo);
+  WrapperCGF.MakeAddrLValue(I->second.second, Arg->getType(),
+AlignmentSource::Decl);
   CallArg = WrapperCGF.EmitLoadOfScalar(LV, SourceLocation());
 } else {
   auto EI = VLASizes.find(Arg);
   if (EI != VLASizes.end())
 CallArg = EI->second.second;
   else {
 LValue LV = WrapperCGF.MakeAddrLValue(WrapperCGF.GetAddrOfLocalVar(Arg),
-  Arg->getType(), BaseInfo);
+  Arg->getType(),
+  AlignmentSource::Decl);
 CallArg = WrapperCGF.EmitLoadOfScalar(LV, SourceLocation());
   }
 }
Index: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1131,7 +1131,7 @@
 CodeGenFunction ) {
   return CGF.MakeAddrLValue(CGF.GetAddrOfLocalVar(getThreadIDVariable()),
 getThreadIDVariable()->getType(),
-LValueBaseInfo(AlignmentSource::Decl, false));
+AlignmentSource::Decl);
 }
 
 

[PATCH] D38126: Make TBAA information to be part of LValueBaseInfo

2017-10-09 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev added a comment.

Please take a look at https://reviews.llvm.org/D38695, if you want this by 
smaller pieces. Thanks.


https://reviews.llvm.org/D38126



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


[PATCH] D38695: [CodeGen] Do not construct complete LValue base info in trivial cases

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

Besides obvious code simplification, avoiding explicit creation of 
LValueBaseInfo objects makes it easier to make TBAA information to be part of 
such objects.

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/D38695

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.h

Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1911,15 +1911,26 @@
   //======//
 
   LValue MakeAddrLValue(Address Addr, QualType T,
-LValueBaseInfo BaseInfo =
-LValueBaseInfo(AlignmentSource::Type)) {
+AlignmentSource Source = AlignmentSource::Type) {
+return LValue::MakeAddr(Addr, T, getContext(),
+LValueBaseInfo(Source, false),
+CGM.getTBAAAccessInfo(T));
+  }
+
+  LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo) {
 return LValue::MakeAddr(Addr, T, getContext(), BaseInfo,
 CGM.getTBAAAccessInfo(T));
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
-LValueBaseInfo BaseInfo =
-LValueBaseInfo(AlignmentSource::Type)) {
+AlignmentSource Source = AlignmentSource::Type) {
+return LValue::MakeAddr(Address(V, Alignment), T, getContext(),
+LValueBaseInfo(Source, false),
+CGM.getTBAAAccessInfo(T));
+  }
+
+  LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
+LValueBaseInfo BaseInfo) {
 return LValue::MakeAddr(Address(V, Alignment), T, getContext(),
 BaseInfo, CGM.getTBAAAccessInfo(T));
   }
@@ -3058,8 +3069,15 @@
   /// the LLVM value representation.
   llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
 SourceLocation Loc,
-LValueBaseInfo BaseInfo =
-LValueBaseInfo(AlignmentSource::Type),
+AlignmentSource Source = AlignmentSource::Type,
+bool isNontemporal = false) {
+return EmitLoadOfScalar(Addr, Volatile, Ty, Loc,
+LValueBaseInfo(Source, false),
+CGM.getTBAAAccessInfo(Ty), isNontemporal);
+  }
+
+  llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
+SourceLocation Loc, LValueBaseInfo BaseInfo,
 bool isNontemporal = false) {
 return EmitLoadOfScalar(Addr, Volatile, Ty, Loc, BaseInfo,
 CGM.getTBAAAccessInfo(Ty), isNontemporal);
@@ -3081,8 +3099,14 @@
   /// the LLVM value representation.
   void EmitStoreOfScalar(llvm::Value *Value, Address Addr,
  bool Volatile, QualType Ty,
- LValueBaseInfo BaseInfo =
- LValueBaseInfo(AlignmentSource::Type),
+ AlignmentSource Source = AlignmentSource::Type,
+ bool isInit = false, bool isNontemporal = false) {
+EmitStoreOfScalar(Value, Addr, Volatile, Ty, LValueBaseInfo(Source, false),
+  CGM.getTBAAAccessInfo(Ty), isInit, isNontemporal);
+  }
+
+  void EmitStoreOfScalar(llvm::Value *Value, Address Addr,
+ bool Volatile, QualType Ty, LValueBaseInfo BaseInfo,
  bool isInit = false, bool isNontemporal = false) {
 EmitStoreOfScalar(Value, Addr, Volatile, Ty, BaseInfo,
   CGM.getTBAAAccessInfo(Ty), isInit, isNontemporal);
Index: lib/CodeGen/CGStmtOpenMP.cpp
===
--- lib/CodeGen/CGStmtOpenMP.cpp
+++ lib/CodeGen/CGStmtOpenMP.cpp
@@ -392,15 +392,14 @@
   continue;
 }
 
-LValueBaseInfo BaseInfo(AlignmentSource::Decl, false);
-LValue ArgLVal =
-CGF.MakeAddrLValue(LocalAddr, Args[Cnt]->getType(), BaseInfo);
+LValue ArgLVal = CGF.MakeAddrLValue(LocalAddr, Args[Cnt]->getType(),
+AlignmentSource::Decl);
 if (FD->hasCapturedVLAType()) {
   if (FO.UIntPtrCastRequired) {
 ArgLVal = CGF.MakeAddrLValue(castValueFromUintptr(CGF, FD->getType(),
   Args[Cnt]->getName(),
   ArgLVal),
-   

[PATCH] D38126: Make TBAA information to be part of LValueBaseInfo

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

Removed the extra ###include##.


https://reviews.llvm.org/D38126

Files:
  lib/CodeGen/CGAtomic.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CGObjCRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CGValue.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTBAA.cpp
  lib/CodeGen/CodeGenTBAA.h

Index: lib/CodeGen/CodeGenTBAA.h
===
--- lib/CodeGen/CodeGenTBAA.h
+++ lib/CodeGen/CodeGenTBAA.h
@@ -47,6 +47,20 @@
 : TBAAAccessInfo(/* AccessType= */ nullptr)
   {}
 
+  bool operator==(const TBAAAccessInfo ) const {
+return BaseType == Other.BaseType &&
+   AccessType == Other.AccessType &&
+   Offset == Other.Offset;
+  }
+
+  bool operator!=(const TBAAAccessInfo ) const {
+return !(*this == Other);
+  }
+
+  explicit operator bool() const {
+return *this != TBAAAccessInfo();
+  }
+
   /// BaseType - The base/leading access type. May be null if this access
   /// descriptor represents an access that is not considered to be an access
   /// to an aggregate or union member.
@@ -136,6 +150,19 @@
   /// getMayAliasAccessInfo - Get TBAA information that represents may-alias
   /// accesses.
   TBAAAccessInfo getMayAliasAccessInfo();
+
+  /// isMayAliasAccessInfo - Test for the may-alias TBAA access descriptor.
+  bool isMayAliasAccessInfo(TBAAAccessInfo Info);
+
+  /// mergeTBAAInfoForCast - Get merged TBAA information for the purpose of
+  /// type casts.
+  TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo,
+  TBAAAccessInfo TargetInfo);
+
+  /// mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the
+  /// purpose of conditional operator.
+  TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA,
+ TBAAAccessInfo InfoB);
 };
 
 }  // end namespace CodeGen
@@ -166,9 +193,7 @@
 
   static bool isEqual(const clang::CodeGen::TBAAAccessInfo ,
   const clang::CodeGen::TBAAAccessInfo ) {
-return LHS.BaseType == RHS.BaseType &&
-   LHS.AccessType == RHS.AccessType &&
-   LHS.Offset == RHS.Offset;
+return LHS == RHS;
   }
 };
 
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -88,18 +88,45 @@
   return false;
 }
 
+/// Check if the given type is a valid base type to be used in access tags.
+static bool isValidBaseType(QualType QTy) {
+  if (QTy->isReferenceType())
+return false;
+  if (const RecordType *TTy = QTy->getAs()) {
+const RecordDecl *RD = TTy->getDecl()->getDefinition();
+// Incomplete types are not valid base access types.
+if (!RD)
+  return false;
+if (RD->hasFlexibleArrayMember())
+  return false;
+// RD can be struct, union, class, interface or enum.
+// For now, we only handle struct and class.
+if (RD->isStruct() || RD->isClass())
+  return true;
+  }
+  return false;
+}
+
 llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
   // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
   if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
 return nullptr;
 
+  // In some cases, such as dereferencing a structure member, the final access
+  // type may well itself be an aggregate. Since it is possible to dereference
+  // a member of that aggregate, this function shall be able to generate
+  // descriptors for any object types, including aggregate ones, without
+  // falling back to returning the "omnipotent char" type node.
+  // TODO: Combine getTypeInfo() and getBaseTypeInfo() into a single function.
+  if (isValidBaseType(QTy))
+return getBaseTypeInfo(QTy);
+
   // If the type has the may_alias attribute (even on a typedef), it is
   // effectively in the general char alias class.
   if (TypeHasMayAlias(QTy))
 return getChar();
 
   const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
-
   if (llvm::MDNode *N = MetadataCache[Ty])
 return N;
 
@@ -232,20 +259,6 @@
   return StructMetadataCache[Ty] = nullptr;
 }
 
-/// Check if the given type is a valid base type to be used in access tags.
-static bool isValidBaseType(QualType QTy) {
-  if (const RecordType *TTy = QTy->getAs()) {
-const RecordDecl *RD = TTy->getDecl()->getDefinition();
-if (RD->hasFlexibleArrayMember())
-  return false;
-// RD can be struct, union, class, interface or enum.
-// For now, we only handle struct and class.
-if (RD->isStruct() || RD->isClass())
-  return true;
-  }
-  return false;
-}
-
 llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
   if 

[PATCH] D38126: Make TBAA information to be part of LValueBaseInfo

2017-10-06 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev added inline comments.



Comment at: lib/CodeGen/CodeGenModule.cpp:55
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Verifier.h"  // TODO
 #include "llvm/ProfileData/InstrProfReader.h"

Oops. Will be removed.


https://reviews.llvm.org/D38126



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


[PATCH] D38126: Make TBAA information to be part of LValueBaseInfo

2017-10-06 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 118045.
kosarev edited the summary of this revision.
kosarev added a comment.

Re-based on top of the previous refinements: https://reviews.llvm.org/D38404, 
https://reviews.llvm.org/D38408, https://reviews.llvm.org/D38456, 
https://reviews.llvm.org/D38460, https://reviews.llvm.org/D38503 and 
https://reviews.llvm.org/D37826. Still large, but most of the changes are local 
and trivial. Please let me know if it is too complex to be reviewed. Thanks.


https://reviews.llvm.org/D38126

Files:
  lib/CodeGen/CGAtomic.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CGObjCRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CGValue.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTBAA.cpp
  lib/CodeGen/CodeGenTBAA.h

Index: lib/CodeGen/CodeGenTBAA.h
===
--- lib/CodeGen/CodeGenTBAA.h
+++ lib/CodeGen/CodeGenTBAA.h
@@ -47,6 +47,20 @@
 : TBAAAccessInfo(/* AccessType= */ nullptr)
   {}
 
+  bool operator==(const TBAAAccessInfo ) const {
+return BaseType == Other.BaseType &&
+   AccessType == Other.AccessType &&
+   Offset == Other.Offset;
+  }
+
+  bool operator!=(const TBAAAccessInfo ) const {
+return !(*this == Other);
+  }
+
+  explicit operator bool() const {
+return *this != TBAAAccessInfo();
+  }
+
   /// BaseType - The base/leading access type. May be null if this access
   /// descriptor represents an access that is not considered to be an access
   /// to an aggregate or union member.
@@ -136,6 +150,19 @@
   /// getMayAliasAccessInfo - Get TBAA information that represents may-alias
   /// accesses.
   TBAAAccessInfo getMayAliasAccessInfo();
+
+  /// isMayAliasAccessInfo - Test for the may-alias TBAA access descriptor.
+  bool isMayAliasAccessInfo(TBAAAccessInfo Info);
+
+  /// mergeTBAAInfoForCast - Get merged TBAA information for the purpose of
+  /// type casts.
+  TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo,
+  TBAAAccessInfo TargetInfo);
+
+  /// mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the
+  /// purpose of conditional operator.
+  TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA,
+ TBAAAccessInfo InfoB);
 };
 
 }  // end namespace CodeGen
@@ -166,9 +193,7 @@
 
   static bool isEqual(const clang::CodeGen::TBAAAccessInfo ,
   const clang::CodeGen::TBAAAccessInfo ) {
-return LHS.BaseType == RHS.BaseType &&
-   LHS.AccessType == RHS.AccessType &&
-   LHS.Offset == RHS.Offset;
+return LHS == RHS;
   }
 };
 
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -88,18 +88,45 @@
   return false;
 }
 
+/// Check if the given type is a valid base type to be used in access tags.
+static bool isValidBaseType(QualType QTy) {
+  if (QTy->isReferenceType())
+return false;
+  if (const RecordType *TTy = QTy->getAs()) {
+const RecordDecl *RD = TTy->getDecl()->getDefinition();
+// Incomplete types are not valid base access types.
+if (!RD)
+  return false;
+if (RD->hasFlexibleArrayMember())
+  return false;
+// RD can be struct, union, class, interface or enum.
+// For now, we only handle struct and class.
+if (RD->isStruct() || RD->isClass())
+  return true;
+  }
+  return false;
+}
+
 llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
   // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
   if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
 return nullptr;
 
+  // In some cases, such as dereferencing a structure member, the final access
+  // type may well itself be an aggregate. Since it is possible to dereference
+  // a member of that aggregate, this function shall be able to generate
+  // descriptors for any object types, including aggregate ones, without
+  // falling back to returning the "omnipotent char" type node.
+  // TODO: Combine getTypeInfo() and getBaseTypeInfo() into a single function.
+  if (isValidBaseType(QTy))
+return getBaseTypeInfo(QTy);
+
   // If the type has the may_alias attribute (even on a typedef), it is
   // effectively in the general char alias class.
   if (TypeHasMayAlias(QTy))
 return getChar();
 
   const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
-
   if (llvm::MDNode *N = MetadataCache[Ty])
 return N;
 
@@ -232,20 +259,6 @@
   return StructMetadataCache[Ty] = nullptr;
 }
 
-/// Check if the given type is a valid base type to be used in access tags.
-static bool isValidBaseType(QualType QTy) {
-  if (const RecordType *TTy = QTy->getAs()) {

[PATCH] D37826: Refine generation of TBAA information in clang

2017-10-06 Thread Ivan A. Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315048: Refine generation of TBAA information in clang 
(authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D37826?vs=117823=117961#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37826

Files:
  cfe/trunk/lib/CodeGen/CGAtomic.cpp
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGValue.h
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.h
  cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
  cfe/trunk/lib/CodeGen/CodeGenTBAA.h
  cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp

Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -594,6 +594,12 @@
   return TBAA->getTBAAStructInfo(QTy);
 }
 
+llvm::MDNode *CodeGenModule::getTBAABaseTypeInfo(QualType QTy) {
+  if (!TBAA)
+return nullptr;
+  return TBAA->getBaseTypeInfo(QTy);
+}
+
 llvm::MDNode *CodeGenModule::getTBAAAccessTagInfo(TBAAAccessInfo Info) {
   if (!TBAA)
 return nullptr;
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -1174,8 +1174,7 @@
   llvm::Value *V = LV.getPointer();
   Scope.ForceCleanup({});
   return LValue::MakeAddr(Address(V, LV.getAlignment()), LV.getType(),
-  getContext(), LV.getBaseInfo(),
-  LV.getTBAAAccessType());
+  getContext(), LV.getBaseInfo(), LV.getTBAAInfo());
 }
 // FIXME: Is it possible to create an ExprWithCleanups that produces a
 // bitfield lvalue or some other non-simple lvalue?
@@ -1514,7 +1513,7 @@
 
   // Atomic operations have to be done on integral types.
   LValue AtomicLValue =
-  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo.AccessType);
+  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo);
   if (Ty->isAtomicType() || LValueIsSuitableForInlineAtomic(AtomicLValue)) {
 return EmitAtomicLoad(AtomicLValue, Loc).getScalarVal();
   }
@@ -1525,11 +1524,10 @@
 Load->getContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1)));
 Load->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
-  if (TBAAInfo.AccessType) {
-if (BaseInfo.getMayAlias())
-  TBAAInfo = CGM.getTBAAMayAliasAccessInfo();
-CGM.DecorateInstructionWithTBAA(Load, TBAAInfo);
-  }
+
+  if (BaseInfo.getMayAlias())
+TBAAInfo = CGM.getTBAAMayAliasAccessInfo();
+  CGM.DecorateInstructionWithTBAA(Load, TBAAInfo);
 
   if (EmitScalarRangeCheck(Load, Ty, Loc)) {
 // In order to prevent the optimizer from throwing away the check, don't
@@ -1596,7 +1594,7 @@
   Value = EmitToMemory(Value, Ty);
 
   LValue AtomicLValue =
-  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo.AccessType);
+  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo);
   if (Ty->isAtomicType() ||
   (!isInit && LValueIsSuitableForInlineAtomic(AtomicLValue))) {
 EmitAtomicStore(RValue::get(Value), AtomicLValue, isInit);
@@ -1610,11 +1608,10 @@
   llvm::ConstantAsMetadata::get(Builder.getInt32(1)));
 Store->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
-  if (TBAAInfo.AccessType) {
-if (BaseInfo.getMayAlias())
-  TBAAInfo = CGM.getTBAAMayAliasAccessInfo();
-CGM.DecorateInstructionWithTBAA(Store, TBAAInfo);
-  }
+
+  if (BaseInfo.getMayAlias())
+TBAAInfo = CGM.getTBAAMayAliasAccessInfo();
+  CGM.DecorateInstructionWithTBAA(Store, TBAAInfo);
 }
 
 void CodeGenFunction::EmitStoreOfScalar(llvm::Value *value, LValue lvalue,
@@ -3753,30 +3750,40 @@
 
   LValue LV = MakeAddrLValue(addr, type, FieldBaseInfo);
   LV.getQuals().addCVRQualifiers(cvr);
-  if (TBAAPath) {
+
+  // Fields of may_alias structs act like 'char' for TBAA purposes.
+  // FIXME: this should get propagated down through anonymous structs
+  // and unions.
+  if (mayAlias) {
+LV.setTBAAInfo(CGM.getTBAAMayAliasAccessInfo());
+  } else if (TBAAPath) {
+// If no base type been assigned for the base access, then try to generate
+// one for this base lvalue.
+TBAAAccessInfo TBAAInfo = base.getTBAAInfo();
+if (!TBAAInfo.BaseType) {
+TBAAInfo.BaseType = CGM.getTBAABaseTypeInfo(base.getType());
+assert(!TBAAInfo.Offset &&
+   "Nonzero offset for an access with no base type!");
+}
+
+// Adjust offset to be relative to the base type.
 const ASTRecordLayout  =
 getContext().getASTRecordLayout(field->getParent());
-// Set the base type to be the base type of the base LValue and
-// update offset to be relative to the base type.
 unsigned CharWidth = 

[PATCH] D37826: Refine generation of TBAA information in clang

2017-10-05 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev added inline comments.



Comment at: lib/CodeGen/CodeGenTBAA.h:129
 
-  /// getBaseTypeInfo - Get metadata node for a given base access type.
-  llvm::MDNode *getBaseTypeInfo(QualType QType);
+  /// getTBAABaseTypeMetadata - Get metadata that describes the given base
+  /// access type. Return null if the type is not suitable for use in TBAA

Wrong function name. Will fix on next review cycle or commit.


Repository:
  rL LLVM

https://reviews.llvm.org/D37826



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


[PATCH] D37826: Refine generation of TBAA information in clang

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

- Rebased on top of https://reviews.llvm.org/D38503.
- The tbaa-for-vptr.cpp test is changed to be more specific about the 
instructions to test. Otherwise, we fail on some triples, such as 
s390x-ibm-linux and x86_64-pc-mingw32. This is due to the changes for 
EmitLoadOfScalar() and EmitStoreOfScalar() where we previously were defaulting 
to empty TBAA info and now generate a TBAA descriptor based on the specified 
access type. This results in the instructions that load the pointer-to-function 
value having their TBAA tags (the may-alias one, namely) so that these 
instructions match the pattern in the test file and NUM gets a wrong value.


Repository:
  rL LLVM

https://reviews.llvm.org/D37826

Files:
  lib/CodeGen/CGAtomic.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGValue.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTBAA.cpp
  lib/CodeGen/CodeGenTBAA.h
  test/CodeGen/tbaa-for-vptr.cpp

Index: test/CodeGen/tbaa-for-vptr.cpp
===
--- test/CodeGen/tbaa-for-vptr.cpp
+++ test/CodeGen/tbaa-for-vptr.cpp
@@ -23,12 +23,12 @@
 }
 
 // CHECK-LABEL: @_Z7CallFoo
-// CHECK: %{{.*}} = load {{.*}} !tbaa ![[NUM:[0-9]+]]
+// CHECK: %{{.*}} = load i32 (%struct.A*)**, {{.*}} !tbaa ![[NUM:[0-9]+]]
 // CHECK: br i1
-// CHECK: load {{.*}}, !tbaa ![[NUM]]
+// CHECK: load i8*, {{.*}}, !tbaa ![[NUM]]
 //
 // CHECK-LABEL: @_ZN1AC2Ev
-// CHECK: store {{.*}} !tbaa ![[NUM]]
+// CHECK: store i32 (...)** {{.*}}, !tbaa ![[NUM]]
 //
 // CHECK: [[NUM]] = !{[[TYPE:!.*]], [[TYPE]], i64 0}
 // CHECK: [[TYPE]] = !{!"vtable pointer", !{{.*}}
Index: lib/CodeGen/CodeGenTBAA.h
===
--- lib/CodeGen/CodeGenTBAA.h
+++ lib/CodeGen/CodeGenTBAA.h
@@ -32,22 +32,15 @@
 namespace CodeGen {
 class CGRecordLayout;
 
-struct TBAAPathTag {
-  TBAAPathTag(const Type *B, const llvm::MDNode *A, uint64_t O)
-: BaseT(B), AccessN(A), Offset(O) {}
-  const Type *BaseT;
-  const llvm::MDNode *AccessN;
-  uint64_t Offset;
-};
-
 // TBAAAccessInfo - Describes a memory access in terms of TBAA.
 struct TBAAAccessInfo {
-  TBAAAccessInfo(QualType BaseType, llvm::MDNode *AccessType, uint64_t Offset)
+  TBAAAccessInfo(llvm::MDNode *BaseType, llvm::MDNode *AccessType,
+ uint64_t Offset)
 : BaseType(BaseType), AccessType(AccessType), Offset(Offset)
   {}
 
   explicit TBAAAccessInfo(llvm::MDNode *AccessType)
-: TBAAAccessInfo(/* BaseType= */ QualType(), AccessType, /* Offset= */ 0)
+: TBAAAccessInfo(/* BaseType= */ nullptr, AccessType, /* Offset= */ 0)
   {}
 
   TBAAAccessInfo()
@@ -57,7 +50,7 @@
   /// BaseType - The base/leading access type. May be null if this access
   /// descriptor represents an access that is not considered to be an access
   /// to an aggregate or union member.
-  QualType BaseType;
+  llvm::MDNode *BaseType;
 
   /// AccessType - The final access type. May be null if there is no TBAA
   /// information available about this access.
@@ -82,10 +75,10 @@
   /// MetadataCache - This maps clang::Types to scalar llvm::MDNodes describing
   /// them.
   llvm::DenseMap MetadataCache;
-  /// This maps clang::Types to a struct node in the type DAG.
-  llvm::DenseMap StructTypeMetadataCache;
-  /// This maps TBAAPathTags to a tag node.
-  llvm::DenseMap StructTagMetadataCache;
+  /// This maps clang::Types to a base access type in the type DAG.
+  llvm::DenseMap BaseTypeMetadataCache;
+  /// This maps TBAA access descriptors to tag nodes.
+  llvm::DenseMap AccessTagMetadataCache;
 
   /// StructMetadataCache - This maps clang::Types to llvm::MDNodes describing
   /// them for struct assignments.
@@ -133,8 +126,10 @@
   /// the given type.
   llvm::MDNode *getTBAAStructInfo(QualType QTy);
 
-  /// getBaseTypeInfo - Get metadata node for a given base access type.
-  llvm::MDNode *getBaseTypeInfo(QualType QType);
+  /// getTBAABaseTypeMetadata - Get metadata that describes the given base
+  /// access type. Return null if the type is not suitable for use in TBAA
+  /// access tags.
+  llvm::MDNode *getBaseTypeInfo(QualType QTy);
 
   /// getAccessTagInfo - Get TBAA tag for a given memory access.
   llvm::MDNode *getAccessTagInfo(TBAAAccessInfo Info);
@@ -149,31 +144,31 @@
 
 namespace llvm {
 
-template<> struct DenseMapInfo {
-  static clang::CodeGen::TBAAPathTag getEmptyKey() {
-return clang::CodeGen::TBAAPathTag(
-  DenseMapInfo::getEmptyKey(),
-  DenseMapInfo::getEmptyKey(),
+template<> struct DenseMapInfo {
+  static clang::CodeGen::TBAAAccessInfo getEmptyKey() {
+return clang::CodeGen::TBAAAccessInfo(
+  DenseMapInfo::getEmptyKey(),
+  DenseMapInfo::getEmptyKey(),
   DenseMapInfo::getEmptyKey());
   }
 
-  static 

[PATCH] D38503: [CodeGen] Unify generation of scalar and struct-path TBAA tags

2017-10-05 Thread Ivan A. Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314977: [CodeGen] Unify generation of scalar and struct-path 
TBAA tags (authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D38503?vs=117519=117791#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38503

Files:
  cfe/trunk/lib/CodeGen/CGAtomic.cpp
  cfe/trunk/lib/CodeGen/CGClass.cpp
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGValue.h
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.h
  cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
  cfe/trunk/lib/CodeGen/CodeGenTBAA.h

Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -578,42 +578,44 @@
   return TBAA->getTypeInfo(QTy);
 }
 
-llvm::MDNode *CodeGenModule::getTBAAInfoForVTablePtr() {
+TBAAAccessInfo CodeGenModule::getTBAAAccessInfo(QualType AccessType) {
+  return TBAAAccessInfo(getTBAATypeInfo(AccessType));
+}
+
+TBAAAccessInfo CodeGenModule::getTBAAVTablePtrAccessInfo() {
   if (!TBAA)
-return nullptr;
-  return TBAA->getTBAAInfoForVTablePtr();
+return TBAAAccessInfo();
+  return TBAA->getVTablePtrAccessInfo();
 }
 
 llvm::MDNode *CodeGenModule::getTBAAStructInfo(QualType QTy) {
   if (!TBAA)
 return nullptr;
   return TBAA->getTBAAStructInfo(QTy);
 }
 
-llvm::MDNode *CodeGenModule::getTBAAStructTagInfo(TBAAAccessInfo Info) {
+llvm::MDNode *CodeGenModule::getTBAABaseTypeInfo(QualType QTy) {
   if (!TBAA)
 return nullptr;
-  return TBAA->getTBAAStructTagInfo(Info);
+  return TBAA->getBaseTypeInfo(QTy);
 }
 
-llvm::MDNode *CodeGenModule::getTBAAMayAliasTypeInfo() {
+llvm::MDNode *CodeGenModule::getTBAAAccessTagInfo(TBAAAccessInfo Info) {
   if (!TBAA)
 return nullptr;
-  return TBAA->getMayAliasTypeInfo();
+  return TBAA->getAccessTagInfo(Info);
+}
+
+TBAAAccessInfo CodeGenModule::getTBAAMayAliasAccessInfo() {
+  if (!TBAA)
+return TBAAAccessInfo();
+  return TBAA->getMayAliasAccessInfo();
 }
 
-/// Decorate the instruction with a TBAA tag. For both scalar TBAA
-/// and struct-path aware TBAA, the tag has the same format:
-/// base type, access type and offset.
-/// When ConvertTypeToTag is true, we create a tag based on the scalar type.
 void CodeGenModule::DecorateInstructionWithTBAA(llvm::Instruction *Inst,
-llvm::MDNode *TBAAInfo,
-bool ConvertTypeToTag) {
-  if (ConvertTypeToTag && TBAA)
-Inst->setMetadata(llvm::LLVMContext::MD_tbaa,
-  TBAA->getTBAAScalarTagInfo(TBAAInfo));
-  else
-Inst->setMetadata(llvm::LLVMContext::MD_tbaa, TBAAInfo);
+TBAAAccessInfo TBAAInfo) {
+  if (llvm::MDNode *Tag = getTBAAAccessTagInfo(TBAAInfo))
+Inst->setMetadata(llvm::LLVMContext::MD_tbaa, Tag);
 }
 
 void CodeGenModule::DecorateInstructionWithInvariantGroup(
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -1174,8 +1174,7 @@
   llvm::Value *V = LV.getPointer();
   Scope.ForceCleanup({});
   return LValue::MakeAddr(Address(V, LV.getAlignment()), LV.getType(),
-  getContext(), LV.getBaseInfo(),
-  LV.getTBAAAccessType());
+  getContext(), LV.getBaseInfo(), LV.getTBAAInfo());
 }
 // FIXME: Is it possible to create an ExprWithCleanups that produces a
 // bitfield lvalue or some other non-simple lvalue?
@@ -1514,7 +1513,7 @@
 
   // Atomic operations have to be done on integral types.
   LValue AtomicLValue =
-  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo.AccessType);
+  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo);
   if (Ty->isAtomicType() || LValueIsSuitableForInlineAtomic(AtomicLValue)) {
 return EmitAtomicLoad(AtomicLValue, Loc).getScalarVal();
   }
@@ -1525,14 +1524,10 @@
 Load->getContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1)));
 Load->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
-  if (TBAAInfo.AccessType) {
-bool MayAlias = BaseInfo.getMayAlias();
-llvm::MDNode *TBAA = MayAlias
-? CGM.getTBAAMayAliasTypeInfo()
-: CGM.getTBAAStructTagInfo(TBAAInfo);
-if (TBAA)
-  CGM.DecorateInstructionWithTBAA(Load, TBAA, MayAlias);
-  }
+
+  if (BaseInfo.getMayAlias())
+TBAAInfo = CGM.getTBAAMayAliasAccessInfo();
+  CGM.DecorateInstructionWithTBAA(Load, TBAAInfo);
 
   if (EmitScalarRangeCheck(Load, Ty, Loc)) {
 // In order to prevent the optimizer from throwing away the check, don't
@@ -1599,7 +1594,7 @@
   Value = 

[PATCH] D37826: Refine generation of TBAA information in clang

2017-10-04 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev added a comment.

In https://reviews.llvm.org/D37826#887820, @rjmccall wrote:

> I assume I should wait on reviewing this until all of these smaller TBAA 
> patches land?


These small patches are actually part of this diff. Generally, It depends on 
how you would like it: if you can review this re-based version as a whole, then 
that would save us some time.

Otherwise, you may want to proceed by smaller pieces, in which case 
https://reviews.llvm.org/D38503 is the next proposed piece to review.

Alternatively, if https://reviews.llvm.org/D38503 looks too complicated, please 
let me know and I will break it down into even smaller patches.

Or, if acceptable, I could commit a series of really small and simple diffs 
that all result in what is presented in https://reviews.llvm.org/D38126 and 
rely on post-commit reviews.

I'm fine with either way, provided the changes go to the mainline in time 
manner.

Thanks a lot for reviewing!


https://reviews.llvm.org/D37826



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


[PATCH] D37826: Refine generation of TBAA information in clang

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

Rebased.

This is how how the rebased patch differs from the mainline:

- It incorporates changes from (not landed yet) https://reviews.llvm.org/D38503.
- Simplifies generation of TBAA info in EmitLValueForField().
- Replaces TBAAPathTag with TBAAAccessInfo for caching purposes.
- Decorated atomic accesses with complete TBAA info and not just final access 
types (propagation of TBAA info for atomic accesses is already fixed in 
https://reviews.llvm.org/D38460).
- Fixes the bug with writing to a wrong cache in getTBAAStructTypeInfo() / 
getBaseTypeInfo().


https://reviews.llvm.org/D37826

Files:
  lib/CodeGen/CGAtomic.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGValue.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTBAA.cpp
  lib/CodeGen/CodeGenTBAA.h

Index: lib/CodeGen/CodeGenTBAA.h
===
--- lib/CodeGen/CodeGenTBAA.h
+++ lib/CodeGen/CodeGenTBAA.h
@@ -32,22 +32,15 @@
 namespace CodeGen {
 class CGRecordLayout;
 
-struct TBAAPathTag {
-  TBAAPathTag(const Type *B, const llvm::MDNode *A, uint64_t O)
-: BaseT(B), AccessN(A), Offset(O) {}
-  const Type *BaseT;
-  const llvm::MDNode *AccessN;
-  uint64_t Offset;
-};
-
 // TBAAAccessInfo - Describes a memory access in terms of TBAA.
 struct TBAAAccessInfo {
-  TBAAAccessInfo(QualType BaseType, llvm::MDNode *AccessType, uint64_t Offset)
+  TBAAAccessInfo(llvm::MDNode *BaseType, llvm::MDNode *AccessType,
+ uint64_t Offset)
 : BaseType(BaseType), AccessType(AccessType), Offset(Offset)
   {}
 
   explicit TBAAAccessInfo(llvm::MDNode *AccessType)
-: TBAAAccessInfo(/* BaseType= */ QualType(), AccessType, /* Offset= */ 0)
+: TBAAAccessInfo(/* BaseType= */ nullptr, AccessType, /* Offset= */ 0)
   {}
 
   TBAAAccessInfo()
@@ -57,7 +50,7 @@
   /// BaseType - The base/leading access type. May be null if this access
   /// descriptor represents an access that is not considered to be an access
   /// to an aggregate or union member.
-  QualType BaseType;
+  llvm::MDNode *BaseType;
 
   /// AccessType - The final access type. May be null if there is no TBAA
   /// information available about this access.
@@ -82,12 +75,10 @@
   /// MetadataCache - This maps clang::Types to scalar llvm::MDNodes describing
   /// them.
   llvm::DenseMap MetadataCache;
-  /// This maps clang::Types to a struct node in the type DAG.
-  llvm::DenseMap StructTypeMetadataCache;
-  /// This maps TBAAPathTags to a tag node.
-  llvm::DenseMap StructTagMetadataCache;
-  /// This maps a scalar type to a scalar tag node.
-  llvm::DenseMap ScalarTagMetadataCache;
+  /// This maps clang::Types to a base access type in the type DAG.
+  llvm::DenseMap BaseTypeMetadataCache;
+  /// This maps TBAA access descriptors to tag nodes.
+  llvm::DenseMap AccessTagMetadataCache;
 
   /// StructMetadataCache - This maps clang::Types to llvm::MDNodes describing
   /// them for struct assignments.
@@ -127,58 +118,57 @@
   /// given type.
   llvm::MDNode *getTypeInfo(QualType QTy);
 
-  /// getTBAAInfoForVTablePtr - Get the TBAA MDNode to be used for a
-  /// dereference of a vtable pointer.
-  llvm::MDNode *getTBAAInfoForVTablePtr();
+  /// getVTablePtrAccessInfo - Get the TBAA information that describes an
+  /// access to a virtual table pointer.
+  TBAAAccessInfo getVTablePtrAccessInfo();
 
   /// getTBAAStructInfo - Get the TBAAStruct MDNode to be used for a memcpy of
   /// the given type.
   llvm::MDNode *getTBAAStructInfo(QualType QTy);
 
-  /// Get the MDNode in the type DAG for given struct type QType.
-  llvm::MDNode *getTBAAStructTypeInfo(QualType QType);
-
-  /// Get path-aware TBAA tag for a given memory access.
-  llvm::MDNode *getTBAAStructTagInfo(TBAAAccessInfo Info);
+  /// getTBAABaseTypeMetadata - Get metadata that describes the given base
+  /// access type. Return null if the type is not suitable for use in TBAA
+  /// access tags.
+  llvm::MDNode *getBaseTypeInfo(QualType QTy);
 
-  /// Get the scalar tag MDNode for a given scalar type.
-  llvm::MDNode *getTBAAScalarTagInfo(llvm::MDNode *AccessNode);
+  /// getAccessTagInfo - Get TBAA tag for a given memory access.
+  llvm::MDNode *getAccessTagInfo(TBAAAccessInfo Info);
 
-  /// getMayAliasTypeInfo - Get TBAA information that represents may-alias
+  /// getMayAliasAccessInfo - Get TBAA information that represents may-alias
   /// accesses.
-  llvm::MDNode *getMayAliasTypeInfo();
+  TBAAAccessInfo getMayAliasAccessInfo();
 };
 
 }  // end namespace CodeGen
 }  // end namespace clang
 
 namespace llvm {
 
-template<> struct DenseMapInfo {
-  static clang::CodeGen::TBAAPathTag getEmptyKey() {
-return clang::CodeGen::TBAAPathTag(
-  DenseMapInfo::getEmptyKey(),
-  

[PATCH] D38503: [CodeGen] Unify generation of scalar and struct-path TBAA tags

2017-10-03 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev added a comment.

Just in case, please let me know if you think this change should further be 
broken down into smaller pieces. Thanks.


Repository:
  rL LLVM

https://reviews.llvm.org/D38503



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


[PATCH] D38503: [CodeGen] Unify generation of scalar and struct-path TBAA tags

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

This patch makes it possible to produce access tags in a uniform manner 
regardless whether the resulting tag will be a scalar or a struct-path one. 
getAccessTagInfo() now takes care of the actual translation of access 
descriptors to tags and can handle all kinds of accesses. Facilities that 
specific to scalar accesses are eliminated.

Some more details:

- DecorateInstructionWithTBAA() is not responsible for conversion of types to 
access tags anymore. Instead, it takes an access descriptor (TBAAAccessInfo) 
and generates corresponding access tag from it.
- getTBAAInfoForVTablePtr() reworked to getTBAAVTablePtrAccessInfo() that now 
returns the virtual-pointer access descriptor and not the virtual-point type 
metadata.
- Added function getTBAAMayAliasAccessInfo() that returns the descriptor for 
may-alias accesses.
- getTBAAStructTagInfo() renamed to getTBAAAccessTagInfo() as now it is the 
only way to generate access tag by a given access descriptor. It is capable of 
producing both scalar and struct-path tags, depending on options and 
availability of the base access type. getTBAAScalarTagInfo() and its cache 
ScalarTagMetadataCache are eliminated.
- Now that we do not need to care about whether the resulting access tag should 
be a scalar or struct-path one, getTBAAStructTypeInfo() is renamed to 
getBaseTypeInfo().
- Added function getTBAAAccessInfo() that constructs access descriptor by a 
given QualType access type.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D38503

Files:
  lib/CodeGen/CGAtomic.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTBAA.cpp
  lib/CodeGen/CodeGenTBAA.h

Index: lib/CodeGen/CodeGenTBAA.h
===
--- lib/CodeGen/CodeGenTBAA.h
+++ lib/CodeGen/CodeGenTBAA.h
@@ -86,8 +86,6 @@
   llvm::DenseMap StructTypeMetadataCache;
   /// This maps TBAAPathTags to a tag node.
   llvm::DenseMap StructTagMetadataCache;
-  /// This maps a scalar type to a scalar tag node.
-  llvm::DenseMap ScalarTagMetadataCache;
 
   /// StructMetadataCache - This maps clang::Types to llvm::MDNodes describing
   /// them for struct assignments.
@@ -127,26 +125,23 @@
   /// given type.
   llvm::MDNode *getTypeInfo(QualType QTy);
 
-  /// getTBAAInfoForVTablePtr - Get the TBAA MDNode to be used for a
-  /// dereference of a vtable pointer.
-  llvm::MDNode *getTBAAInfoForVTablePtr();
+  /// getVTablePtrAccessInfo - Get the TBAA information that describes an
+  /// access to a virtual table pointer.
+  TBAAAccessInfo getVTablePtrAccessInfo();
 
   /// getTBAAStructInfo - Get the TBAAStruct MDNode to be used for a memcpy of
   /// the given type.
   llvm::MDNode *getTBAAStructInfo(QualType QTy);
 
-  /// Get the MDNode in the type DAG for given struct type QType.
-  llvm::MDNode *getTBAAStructTypeInfo(QualType QType);
+  /// getBaseTypeInfo - Get metadata node for a given base access type.
+  llvm::MDNode *getBaseTypeInfo(QualType QType);
 
-  /// Get path-aware TBAA tag for a given memory access.
-  llvm::MDNode *getTBAAStructTagInfo(TBAAAccessInfo Info);
+  /// getAccessTagInfo - Get TBAA tag for a given memory access.
+  llvm::MDNode *getAccessTagInfo(TBAAAccessInfo Info);
 
-  /// Get the scalar tag MDNode for a given scalar type.
-  llvm::MDNode *getTBAAScalarTagInfo(llvm::MDNode *AccessNode);
-
-  /// getMayAliasTypeInfo - Get TBAA information that represents may-alias
+  /// getMayAliasAccessInfo - Get TBAA information that represents may-alias
   /// accesses.
-  llvm::MDNode *getMayAliasTypeInfo();
+  TBAAAccessInfo getMayAliasAccessInfo();
 };
 
 }  // end namespace CodeGen
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -171,8 +171,8 @@
   return MetadataCache[Ty] = getChar();
 }
 
-llvm::MDNode *CodeGenTBAA::getTBAAInfoForVTablePtr() {
-  return createTBAAScalarType("vtable pointer", getRoot());
+TBAAAccessInfo CodeGenTBAA::getVTablePtrAccessInfo() {
+  return TBAAAccessInfo(createTBAAScalarType("vtable pointer", getRoot()));
 }
 
 bool
@@ -211,8 +211,8 @@
   /* Otherwise, treat whatever it is as a field. */
   uint64_t Offset = BaseOffset;
   uint64_t Size = Context.getTypeSizeInChars(QTy).getQuantity();
-  llvm::MDNode *TBAAInfo = MayAlias ? getChar() : getTypeInfo(QTy);
-  llvm::MDNode *TBAATag = getTBAAScalarTagInfo(TBAAInfo);
+  llvm::MDNode *TBAAType = MayAlias ? getChar() : getTypeInfo(QTy);
+  llvm::MDNode *TBAATag = getAccessTagInfo(TBAAAccessInfo(TBAAType));
   Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
   return true;
 }
@@ -232,8 +232,10 @@
   return StructMetadataCache[Ty] = nullptr;
 }
 

[PATCH] D38460: [CodeGen] Fix propagation of TBAA info for atomic accesses

2017-10-03 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev added a comment.

Answering your question: it's just to keep functional changes apart from purely 
refactoring patches.


Repository:
  rL LLVM

https://reviews.llvm.org/D38460



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


[PATCH] D38460: [CodeGen] Fix propagation of TBAA info for atomic accesses

2017-10-03 Thread Ivan A. Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314784: [CodeGen] Fix propagation of TBAA info for atomic 
accesses (authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D38460?vs=117349=117498#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38460

Files:
  cfe/trunk/lib/CodeGen/CGAtomic.cpp


Index: cfe/trunk/lib/CodeGen/CGAtomic.cpp
===
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp
@@ -98,7 +98,7 @@
 LVal = LValue::MakeBitfield(Address(Addr, lvalue.getAlignment()),
 BFI, lvalue.getType(),
 lvalue.getBaseInfo());
-LVal.setTBAAAccessType(lvalue.getTBAAAccessType());
+LVal.setTBAAInfo(lvalue.getTBAAInfo());
 AtomicTy = C.getIntTypeForBitwidth(AtomicSizeInBits, OrigBFI.IsSigned);
 if (AtomicTy.isNull()) {
   llvm::APInt Size(
@@ -1692,8 +1692,8 @@
   DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
   AtomicLVal.getBaseInfo());
 }
-UpdateLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
-DesiredLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
+UpdateLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
+DesiredLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
 UpRVal = CGF.EmitLoadOfLValue(UpdateLVal, SourceLocation());
   }
   // Store new value in the corresponding memory area
@@ -1789,7 +1789,7 @@
 DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
 AtomicLVal.getBaseInfo());
   }
-  DesiredLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
+  DesiredLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
   // Store new value in the corresponding memory area
   assert(UpdateRVal.isScalar());
   CGF.EmitStoreThroughLValue(UpdateRVal, DesiredLVal);


Index: cfe/trunk/lib/CodeGen/CGAtomic.cpp
===
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp
@@ -98,7 +98,7 @@
 LVal = LValue::MakeBitfield(Address(Addr, lvalue.getAlignment()),
 BFI, lvalue.getType(),
 lvalue.getBaseInfo());
-LVal.setTBAAAccessType(lvalue.getTBAAAccessType());
+LVal.setTBAAInfo(lvalue.getTBAAInfo());
 AtomicTy = C.getIntTypeForBitwidth(AtomicSizeInBits, OrigBFI.IsSigned);
 if (AtomicTy.isNull()) {
   llvm::APInt Size(
@@ -1692,8 +1692,8 @@
   DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
   AtomicLVal.getBaseInfo());
 }
-UpdateLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
-DesiredLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
+UpdateLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
+DesiredLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
 UpRVal = CGF.EmitLoadOfLValue(UpdateLVal, SourceLocation());
   }
   // Store new value in the corresponding memory area
@@ -1789,7 +1789,7 @@
 DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
 AtomicLVal.getBaseInfo());
   }
-  DesiredLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
+  DesiredLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
   // Store new value in the corresponding memory area
   assert(UpdateRVal.isScalar());
   CGF.EmitStoreThroughLValue(UpdateRVal, DesiredLVal);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38456: [CodeGen] Introduce generic TBAA access descriptors

2017-10-03 Thread Ivan A. Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314780: [CodeGen] Introduce generic TBAA access descriptors 
(authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D38456?vs=117339=117494#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38456

Files:
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGValue.h
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.h
  cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
  cfe/trunk/lib/CodeGen/CodeGenTBAA.h

Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -23,7 +23,6 @@
 #include "CGOpenMPRuntimeNVPTX.h"
 #include "CodeGenFunction.h"
 #include "CodeGenPGO.h"
-#include "CodeGenTBAA.h"
 #include "ConstantEmitter.h"
 #include "CoverageMappingGen.h"
 #include "TargetInfo.h"
@@ -591,12 +590,10 @@
   return TBAA->getTBAAStructInfo(QTy);
 }
 
-llvm::MDNode *CodeGenModule::getTBAAStructTagInfo(QualType BaseTy,
-  llvm::MDNode *AccessN,
-  uint64_t O) {
+llvm::MDNode *CodeGenModule::getTBAAStructTagInfo(TBAAAccessInfo Info) {
   if (!TBAA)
 return nullptr;
-  return TBAA->getTBAAStructTagInfo(BaseTy, AccessN, O);
+  return TBAA->getTBAAStructTagInfo(Info);
 }
 
 llvm::MDNode *CodeGenModule::getTBAAMayAliasTypeInfo() {
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -1375,9 +1375,7 @@
SourceLocation Loc) {
   return EmitLoadOfScalar(lvalue.getAddress(), lvalue.isVolatile(),
   lvalue.getType(), Loc, lvalue.getBaseInfo(),
-  lvalue.getTBAAAccessType(),
-  lvalue.getTBAABaseType(), lvalue.getTBAAOffset(),
-  lvalue.isNontemporal());
+  lvalue.getTBAAInfo(), lvalue.isNontemporal());
 }
 
 static bool hasBooleanRepresentation(QualType Ty) {
@@ -1487,9 +1485,7 @@
QualType Ty,
SourceLocation Loc,
LValueBaseInfo BaseInfo,
-   llvm::MDNode *TBAAAccessType,
-   QualType TBAABaseType,
-   uint64_t TBAAOffset,
+   TBAAAccessInfo TBAAInfo,
bool isNontemporal) {
   if (!CGM.getCodeGenOpts().PreserveVec3Type) {
 // For better performance, handle vector loads differently.
@@ -1518,7 +1514,7 @@
 
   // Atomic operations have to be done on integral types.
   LValue AtomicLValue =
-  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAAccessType);
+  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo.AccessType);
   if (Ty->isAtomicType() || LValueIsSuitableForInlineAtomic(AtomicLValue)) {
 return EmitAtomicLoad(AtomicLValue, Loc).getScalarVal();
   }
@@ -1529,11 +1525,11 @@
 Load->getContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1)));
 Load->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
-  if (TBAAAccessType) {
+  if (TBAAInfo.AccessType) {
 bool MayAlias = BaseInfo.getMayAlias();
 llvm::MDNode *TBAA = MayAlias
 ? CGM.getTBAAMayAliasTypeInfo()
-: CGM.getTBAAStructTagInfo(TBAABaseType, TBAAAccessType, TBAAOffset);
+: CGM.getTBAAStructTagInfo(TBAAInfo);
 if (TBAA)
   CGM.DecorateInstructionWithTBAA(Load, TBAA, MayAlias);
   }
@@ -1576,11 +1572,8 @@
 void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr,
 bool Volatile, QualType Ty,
 LValueBaseInfo BaseInfo,
-llvm::MDNode *TBAAAccessType,
-bool isInit, QualType TBAABaseType,
-uint64_t TBAAOffset,
-bool isNontemporal) {
-
+TBAAAccessInfo TBAAInfo,
+bool isInit, bool isNontemporal) {
   if (!CGM.getCodeGenOpts().PreserveVec3Type) {
 // Handle vectors differently to get better performance.
 if (Ty->isVectorType()) {
@@ -1606,7 +1599,7 @@
   Value = EmitToMemory(Value, Ty);
 
   LValue AtomicLValue =
-  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAAccessType);
+  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, 

[PATCH] D38460: [CodeGen] Fix propagation of TBAA info for atomic accesses

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

This patch fixes clang to propagate complete TBAA information for atomic 
accesses and not just the final access types. Prepared against 
https://reviews.llvm.org/D38456 and requires it to be committed first.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D38460

Files:
  lib/CodeGen/CGAtomic.cpp


Index: lib/CodeGen/CGAtomic.cpp
===
--- lib/CodeGen/CGAtomic.cpp
+++ lib/CodeGen/CGAtomic.cpp
@@ -98,7 +98,7 @@
 LVal = LValue::MakeBitfield(Address(Addr, lvalue.getAlignment()),
 BFI, lvalue.getType(),
 lvalue.getBaseInfo());
-LVal.setTBAAAccessType(lvalue.getTBAAAccessType());
+LVal.setTBAAInfo(lvalue.getTBAAInfo());
 AtomicTy = C.getIntTypeForBitwidth(AtomicSizeInBits, OrigBFI.IsSigned);
 if (AtomicTy.isNull()) {
   llvm::APInt Size(
@@ -1692,8 +1692,8 @@
   DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
   AtomicLVal.getBaseInfo());
 }
-UpdateLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
-DesiredLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
+UpdateLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
+DesiredLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
 UpRVal = CGF.EmitLoadOfLValue(UpdateLVal, SourceLocation());
   }
   // Store new value in the corresponding memory area
@@ -1789,7 +1789,7 @@
 DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
 AtomicLVal.getBaseInfo());
   }
-  DesiredLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
+  DesiredLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
   // Store new value in the corresponding memory area
   assert(UpdateRVal.isScalar());
   CGF.EmitStoreThroughLValue(UpdateRVal, DesiredLVal);


Index: lib/CodeGen/CGAtomic.cpp
===
--- lib/CodeGen/CGAtomic.cpp
+++ lib/CodeGen/CGAtomic.cpp
@@ -98,7 +98,7 @@
 LVal = LValue::MakeBitfield(Address(Addr, lvalue.getAlignment()),
 BFI, lvalue.getType(),
 lvalue.getBaseInfo());
-LVal.setTBAAAccessType(lvalue.getTBAAAccessType());
+LVal.setTBAAInfo(lvalue.getTBAAInfo());
 AtomicTy = C.getIntTypeForBitwidth(AtomicSizeInBits, OrigBFI.IsSigned);
 if (AtomicTy.isNull()) {
   llvm::APInt Size(
@@ -1692,8 +1692,8 @@
   DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
   AtomicLVal.getBaseInfo());
 }
-UpdateLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
-DesiredLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
+UpdateLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
+DesiredLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
 UpRVal = CGF.EmitLoadOfLValue(UpdateLVal, SourceLocation());
   }
   // Store new value in the corresponding memory area
@@ -1789,7 +1789,7 @@
 DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
 AtomicLVal.getBaseInfo());
   }
-  DesiredLVal.setTBAAAccessType(AtomicLVal.getTBAAAccessType());
+  DesiredLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
   // Store new value in the corresponding memory area
   assert(UpdateRVal.isScalar());
   CGF.EmitStoreThroughLValue(UpdateRVal, DesiredLVal);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38456: [CodeGen] Introduce generic TBAA access descriptors

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

With this patch we implement a concept of TBAA access descriptors that are 
capable of representing both scalar and struct-path accesses in a generic way.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D38456

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGValue.h
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTBAA.cpp
  lib/CodeGen/CodeGenTBAA.h

Index: lib/CodeGen/CodeGenTBAA.h
===
--- lib/CodeGen/CodeGenTBAA.h
+++ lib/CodeGen/CodeGenTBAA.h
@@ -30,15 +30,43 @@
   class Type;
 
 namespace CodeGen {
-  class CGRecordLayout;
+class CGRecordLayout;
 
-  struct TBAAPathTag {
-TBAAPathTag(const Type *B, const llvm::MDNode *A, uint64_t O)
-  : BaseT(B), AccessN(A), Offset(O) {}
-const Type *BaseT;
-const llvm::MDNode *AccessN;
-uint64_t Offset;
-  };
+struct TBAAPathTag {
+  TBAAPathTag(const Type *B, const llvm::MDNode *A, uint64_t O)
+: BaseT(B), AccessN(A), Offset(O) {}
+  const Type *BaseT;
+  const llvm::MDNode *AccessN;
+  uint64_t Offset;
+};
+
+// TBAAAccessInfo - Describes a memory access in terms of TBAA.
+struct TBAAAccessInfo {
+  TBAAAccessInfo(QualType BaseType, llvm::MDNode *AccessType, uint64_t Offset)
+: BaseType(BaseType), AccessType(AccessType), Offset(Offset)
+  {}
+
+  explicit TBAAAccessInfo(llvm::MDNode *AccessType)
+: TBAAAccessInfo(/* BaseType= */ QualType(), AccessType, /* Offset= */ 0)
+  {}
+
+  TBAAAccessInfo()
+: TBAAAccessInfo(/* AccessType= */ nullptr)
+  {}
+
+  /// BaseType - The base/leading access type. May be null if this access
+  /// descriptor represents an access that is not considered to be an access
+  /// to an aggregate or union member.
+  QualType BaseType;
+
+  /// AccessType - The final access type. May be null if there is no TBAA
+  /// information available about this access.
+  llvm::MDNode *AccessType;
+
+  /// Offset - The byte offset of the final access within the base one. Must be
+  /// zero if the base access type is not specified.
+  uint64_t Offset;
+};
 
 /// CodeGenTBAA - This class organizes the cross-module state that is used
 /// while lowering AST types to LLVM types.
@@ -109,10 +137,9 @@
 
   /// Get the MDNode in the type DAG for given struct type QType.
   llvm::MDNode *getTBAAStructTypeInfo(QualType QType);
-  /// Get the tag MDNode for a given base type, the actual scalar access MDNode
-  /// and offset into the base type.
-  llvm::MDNode *getTBAAStructTagInfo(QualType BaseQType,
- llvm::MDNode *AccessNode, uint64_t Offset);
+
+  /// Get path-aware TBAA tag for a given memory access.
+  llvm::MDNode *getTBAAStructTagInfo(TBAAAccessInfo Info);
 
   /// Get the scalar tag MDNode for a given scalar type.
   llvm::MDNode *getTBAAScalarTagInfo(llvm::MDNode *AccessNode);
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -291,29 +291,28 @@
 }
 
 /// Return a TBAA tag node for both scalar TBAA and struct-path aware TBAA.
-llvm::MDNode *
-CodeGenTBAA::getTBAAStructTagInfo(QualType BaseQTy, llvm::MDNode *AccessNode,
-  uint64_t Offset) {
-  if (!AccessNode)
+llvm::MDNode *CodeGenTBAA::getTBAAStructTagInfo(TBAAAccessInfo Info) {
+  if (!Info.AccessType)
 return nullptr;
 
   if (!CodeGenOpts.StructPathTBAA)
-return getTBAAScalarTagInfo(AccessNode);
+return getTBAAScalarTagInfo(Info.AccessType);
 
-  const Type *BTy = Context.getCanonicalType(BaseQTy).getTypePtr();
-  TBAAPathTag PathTag = TBAAPathTag(BTy, AccessNode, Offset);
+  const Type *BTy = Context.getCanonicalType(Info.BaseType).getTypePtr();
+  TBAAPathTag PathTag = TBAAPathTag(BTy, Info.AccessType, Info.Offset);
   if (llvm::MDNode *N = StructTagMetadataCache[PathTag])
 return N;
 
   llvm::MDNode *BNode = nullptr;
-  if (isTBAAPathStruct(BaseQTy))
-BNode  = getTBAAStructTypeInfo(BaseQTy);
+  if (isTBAAPathStruct(Info.BaseType))
+BNode = getTBAAStructTypeInfo(Info.BaseType);
   if (!BNode)
 return StructTagMetadataCache[PathTag] =
-   MDHelper.createTBAAStructTagNode(AccessNode, AccessNode, 0);
+   MDHelper.createTBAAStructTagNode(Info.AccessType, Info.AccessType,
+/* Offset= */ 0);
 
   return StructTagMetadataCache[PathTag] =
-MDHelper.createTBAAStructTagNode(BNode, AccessNode, Offset);
+MDHelper.createTBAAStructTagNode(BNode, Info.AccessType, Info.Offset);
 }
 
 llvm::MDNode *
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -658,9 +658,9 @@
 
   llvm::MDNode 

[PATCH] D38408: [CodeGen] Have a special function to get TBAA info for may-alias accesses

2017-10-02 Thread Ivan A. Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314660: [CodeGen] Have a special function to get TBAA info 
for may-alias accesses (authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D38408?vs=117162=117321#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38408

Files:
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.h
  cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
  cfe/trunk/lib/CodeGen/CodeGenTBAA.h

Index: cfe/trunk/lib/CodeGen/CodeGenModule.h
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.h
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h
@@ -662,6 +662,10 @@
   llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
  uint64_t O);
 
+  /// getTBAAMayAliasTypeInfo - Get TBAA information that represents
+  /// may-alias accesses.
+  llvm::MDNode *getTBAAMayAliasTypeInfo();
+
   bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
 
   bool isPaddedAtomicType(QualType type);
Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -599,6 +599,12 @@
   return TBAA->getTBAAStructTagInfo(BaseTy, AccessN, O);
 }
 
+llvm::MDNode *CodeGenModule::getTBAAMayAliasTypeInfo() {
+  if (!TBAA)
+return nullptr;
+  return TBAA->getMayAliasTypeInfo();
+}
+
 /// Decorate the instruction with a TBAA tag. For both scalar TBAA
 /// and struct-path aware TBAA, the tag has the same format:
 /// base type, access type and offset.
Index: cfe/trunk/lib/CodeGen/CodeGenTBAA.h
===
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.h
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.h
@@ -116,6 +116,10 @@
 
   /// Get the scalar tag MDNode for a given scalar type.
   llvm::MDNode *getTBAAScalarTagInfo(llvm::MDNode *AccessNode);
+
+  /// getMayAliasTypeInfo - Get TBAA information that represents may-alias
+  /// accesses.
+  llvm::MDNode *getMayAliasTypeInfo();
 };
 
 }  // end namespace CodeGen
Index: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
@@ -326,3 +326,7 @@
   return ScalarTagMetadataCache[AccessNode] =
 MDHelper.createTBAAStructTagNode(AccessNode, AccessNode, 0);
 }
+
+llvm::MDNode *CodeGenTBAA::getMayAliasTypeInfo() {
+  return getChar();
+}
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -1522,7 +1522,7 @@
   if (TBAAAccessType) {
 bool MayAlias = BaseInfo.getMayAlias();
 llvm::MDNode *TBAA = MayAlias
-? CGM.getTBAATypeInfo(getContext().CharTy)
+? CGM.getTBAAMayAliasTypeInfo()
 : CGM.getTBAAStructTagInfo(TBAABaseType, TBAAAccessType, TBAAOffset);
 if (TBAA)
   CGM.DecorateInstructionWithTBAA(Load, TBAA, MayAlias);
@@ -1613,7 +1613,7 @@
   if (TBAAAccessType) {
 bool MayAlias = BaseInfo.getMayAlias();
 llvm::MDNode *TBAA = MayAlias
-? CGM.getTBAATypeInfo(getContext().CharTy)
+? CGM.getTBAAMayAliasTypeInfo()
 : CGM.getTBAAStructTagInfo(TBAABaseType, TBAAAccessType, TBAAOffset);
 if (TBAA)
   CGM.DecorateInstructionWithTBAA(Store, TBAA, MayAlias);
@@ -3724,11 +3724,8 @@
   // Loading the reference will disable path-aware TBAA.
   TBAAPath = false;
   if (CGM.shouldUseTBAA()) {
-llvm::MDNode *tbaa;
-if (mayAlias)
-  tbaa = CGM.getTBAATypeInfo(getContext().CharTy);
-else
-  tbaa = CGM.getTBAATypeInfo(type);
+llvm::MDNode *tbaa = mayAlias ? CGM.getTBAAMayAliasTypeInfo() :
+CGM.getTBAATypeInfo(type);
 if (tbaa)
   CGM.DecorateInstructionWithTBAA(load, tbaa);
   }
@@ -3780,7 +3777,7 @@
   // FIXME: this should get propagated down through anonymous structs
   // and unions.
   if (mayAlias && LV.getTBAAAccessType())
-LV.setTBAAAccessType(CGM.getTBAATypeInfo(getContext().CharTy));
+LV.setTBAAAccessType(CGM.getTBAAMayAliasTypeInfo());
 
   return LV;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38404: [CodeGen] Do not refer to complete TBAA info where we actually deal with just TBAA access types

2017-10-02 Thread Ivan A. Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314657: [CodeGen] Do not refer to complete TBAA info where 
we actually deal with just… (authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D38404?vs=117143=117315#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38404

Files:
  cfe/trunk/lib/CodeGen/CGAtomic.cpp
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGValue.h
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.h
  cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
  cfe/trunk/lib/CodeGen/CodeGenTBAA.h

Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -573,10 +573,10 @@
   Types.RefreshTypeCacheForClass(RD);
 }
 
-llvm::MDNode *CodeGenModule::getTBAAInfo(QualType QTy) {
+llvm::MDNode *CodeGenModule::getTBAATypeInfo(QualType QTy) {
   if (!TBAA)
 return nullptr;
-  return TBAA->getTBAAInfo(QTy);
+  return TBAA->getTypeInfo(QTy);
 }
 
 llvm::MDNode *CodeGenModule::getTBAAInfoForVTablePtr() {
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -1165,7 +1165,7 @@
   Scope.ForceCleanup({});
   return LValue::MakeAddr(Address(V, LV.getAlignment()), LV.getType(),
   getContext(), LV.getBaseInfo(),
-  LV.getTBAAInfo());
+  LV.getTBAAAccessType());
 }
 // FIXME: Is it possible to create an ExprWithCleanups that produces a
 // bitfield lvalue or some other non-simple lvalue?
@@ -1365,7 +1365,7 @@
SourceLocation Loc) {
   return EmitLoadOfScalar(lvalue.getAddress(), lvalue.isVolatile(),
   lvalue.getType(), Loc, lvalue.getBaseInfo(),
-  lvalue.getTBAAInfo(),
+  lvalue.getTBAAAccessType(),
   lvalue.getTBAABaseType(), lvalue.getTBAAOffset(),
   lvalue.isNontemporal());
 }
@@ -1477,7 +1477,7 @@
QualType Ty,
SourceLocation Loc,
LValueBaseInfo BaseInfo,
-   llvm::MDNode *TBAAInfo,
+   llvm::MDNode *TBAAAccessType,
QualType TBAABaseType,
uint64_t TBAAOffset,
bool isNontemporal) {
@@ -1508,7 +1508,7 @@
 
   // Atomic operations have to be done on integral types.
   LValue AtomicLValue =
-  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo);
+  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAAccessType);
   if (Ty->isAtomicType() || LValueIsSuitableForInlineAtomic(AtomicLValue)) {
 return EmitAtomicLoad(AtomicLValue, Loc).getScalarVal();
   }
@@ -1519,11 +1519,11 @@
 Load->getContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1)));
 Load->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
-  if (TBAAInfo) {
+  if (TBAAAccessType) {
 bool MayAlias = BaseInfo.getMayAlias();
 llvm::MDNode *TBAA = MayAlias
-? CGM.getTBAAInfo(getContext().CharTy)
-: CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo, TBAAOffset);
+? CGM.getTBAATypeInfo(getContext().CharTy)
+: CGM.getTBAAStructTagInfo(TBAABaseType, TBAAAccessType, TBAAOffset);
 if (TBAA)
   CGM.DecorateInstructionWithTBAA(Load, TBAA, MayAlias);
   }
@@ -1566,7 +1566,7 @@
 void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr,
 bool Volatile, QualType Ty,
 LValueBaseInfo BaseInfo,
-llvm::MDNode *TBAAInfo,
+llvm::MDNode *TBAAAccessType,
 bool isInit, QualType TBAABaseType,
 uint64_t TBAAOffset,
 bool isNontemporal) {
@@ -1596,7 +1596,7 @@
   Value = EmitToMemory(Value, Ty);
 
   LValue AtomicLValue =
-  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo);
+  LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAAccessType);
   if (Ty->isAtomicType() ||
   (!isInit && LValueIsSuitableForInlineAtomic(AtomicLValue))) {
 EmitAtomicStore(RValue::get(Value), AtomicLValue, isInit);
@@ -1610,11 +1610,11 @@
   

[PATCH] D38408: [CodeGen] Have a special function to get TBAA info for may-alias accesses

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

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


Repository:
  rL LLVM

https://reviews.llvm.org/D38408

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTBAA.cpp
  lib/CodeGen/CodeGenTBAA.h

Index: lib/CodeGen/CodeGenTBAA.h
===
--- lib/CodeGen/CodeGenTBAA.h
+++ lib/CodeGen/CodeGenTBAA.h
@@ -116,6 +116,10 @@
 
   /// Get the scalar tag MDNode for a given scalar type.
   llvm::MDNode *getTBAAScalarTagInfo(llvm::MDNode *AccessNode);
+
+  /// getMayAliasAccessInfo - Get TBAA information that represents may-alias
+  /// accesses.
+  llvm::MDNode *getMayAliasTypeInfo();
 };
 
 }  // end namespace CodeGen
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -327,3 +327,7 @@
   return ScalarTagMetadataCache[AccessNode] =
 MDHelper.createTBAAStructTagNode(AccessNode, AccessNode, 0);
 }
+
+llvm::MDNode *CodeGenTBAA::getMayAliasTypeInfo() {
+  return getChar();
+}
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -659,6 +659,10 @@
   llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
  uint64_t O);
 
+  /// getTBAAMayAliasTypeInfo - Get TBAA information that represents
+  /// may-alias accesses.
+  llvm::MDNode *getTBAAMayAliasTypeInfo();
+
   bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
 
   bool isPaddedAtomicType(QualType type);
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -599,6 +599,12 @@
   return TBAA->getTBAAStructTagInfo(BaseTy, AccessN, O);
 }
 
+llvm::MDNode *CodeGenModule::getTBAAMayAliasTypeInfo() {
+  if (!TBAA)
+return nullptr;
+  return TBAA->getMayAliasTypeInfo();
+}
+
 /// Decorate the instruction with a TBAA tag. For both scalar TBAA
 /// and struct-path aware TBAA, the tag has the same format:
 /// base type, access type and offset.
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1519,7 +1519,7 @@
   if (TBAAInfo) {
 bool MayAlias = BaseInfo.getMayAlias();
 llvm::MDNode *TBAA = MayAlias
-? CGM.getTBAAInfo(getContext().CharTy)
+? CGM.getTBAAMayAliasTypeInfo()
 : CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo, TBAAOffset);
 if (TBAA)
   CGM.DecorateInstructionWithTBAA(Load, TBAA, MayAlias);
@@ -1610,7 +1610,7 @@
   if (TBAAInfo) {
 bool MayAlias = BaseInfo.getMayAlias();
 llvm::MDNode *TBAA = MayAlias
-? CGM.getTBAAInfo(getContext().CharTy)
+? CGM.getTBAAMayAliasTypeInfo()
 : CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo, TBAAOffset);
 if (TBAA)
   CGM.DecorateInstructionWithTBAA(Store, TBAA, MayAlias);
@@ -3720,11 +3720,8 @@
   // Loading the reference will disable path-aware TBAA.
   TBAAPath = false;
   if (CGM.shouldUseTBAA()) {
-llvm::MDNode *tbaa;
-if (mayAlias)
-  tbaa = CGM.getTBAAInfo(getContext().CharTy);
-else
-  tbaa = CGM.getTBAAInfo(type);
+llvm::MDNode *tbaa = mayAlias ? CGM.getTBAAMayAliasTypeInfo() :
+CGM.getTBAAInfo(type);
 if (tbaa)
   CGM.DecorateInstructionWithTBAA(load, tbaa);
   }
@@ -3776,7 +3773,7 @@
   // FIXME: this should get propagated down through anonymous structs
   // and unions.
   if (mayAlias && LV.getTBAAInfo())
-LV.setTBAAInfo(CGM.getTBAAInfo(getContext().CharTy));
+LV.setTBAAInfo(CGM.getTBAAMayAliasTypeInfo());
 
   return LV;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38404: [CodeGen] Do not refer to complete TBAA info where we actually deal with just TBAA access types

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

This patch fixes misleading names of entities related to getting, setting and 
generation of TBAA access type descriptors.

This is effectively an attempt to provide a review for 
https://reviews.llvm.org/D37826 by breaking it into smaller pieces.


Repository:
  rL LLVM

https://reviews.llvm.org/D38404

Files:
  CodeGen/CGAtomic.cpp
  CodeGen/CGExpr.cpp
  CodeGen/CGValue.h
  CodeGen/CodeGenFunction.cpp
  CodeGen/CodeGenFunction.h
  CodeGen/CodeGenModule.cpp
  CodeGen/CodeGenModule.h
  CodeGen/CodeGenTBAA.cpp
  CodeGen/CodeGenTBAA.h

Index: CodeGen/CodeGenTBAA.h
===
--- CodeGen/CodeGenTBAA.h
+++ CodeGen/CodeGenTBAA.h
@@ -95,9 +95,9 @@
   MangleContext );
   ~CodeGenTBAA();
 
-  /// getTBAAInfo - Get the TBAA MDNode to be used for a dereference
-  /// of the given type.
-  llvm::MDNode *getTBAAInfo(QualType QTy);
+  /// getTypeInfo - Get metadata used to describe accesses to objects of the
+  /// given type.
+  llvm::MDNode *getTypeInfo(QualType QTy);
 
   /// getTBAAInfoForVTablePtr - Get the TBAA MDNode to be used for a
   /// dereference of a vtable pointer.
Index: CodeGen/CodeGenTBAA.cpp
===
--- CodeGen/CodeGenTBAA.cpp
+++ CodeGen/CodeGenTBAA.cpp
@@ -88,8 +88,7 @@
   return false;
 }
 
-llvm::MDNode *
-CodeGenTBAA::getTBAAInfo(QualType QTy) {
+llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
   // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
   if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
 return nullptr;
@@ -120,15 +119,15 @@
 
 // Unsigned types can alias their corresponding signed types.
 case BuiltinType::UShort:
-  return getTBAAInfo(Context.ShortTy);
+  return getTypeInfo(Context.ShortTy);
 case BuiltinType::UInt:
-  return getTBAAInfo(Context.IntTy);
+  return getTypeInfo(Context.IntTy);
 case BuiltinType::ULong:
-  return getTBAAInfo(Context.LongTy);
+  return getTypeInfo(Context.LongTy);
 case BuiltinType::ULongLong:
-  return getTBAAInfo(Context.LongLongTy);
+  return getTypeInfo(Context.LongLongTy);
 case BuiltinType::UInt128:
-  return getTBAAInfo(Context.Int128Ty);
+  return getTypeInfo(Context.Int128Ty);
 
 // Treat all other builtin types as distinct types. This includes
 // treating wchar_t, char16_t, and char32_t as distinct from their
@@ -212,7 +211,7 @@
   /* Otherwise, treat whatever it is as a field. */
   uint64_t Offset = BaseOffset;
   uint64_t Size = Context.getTypeSizeInChars(QTy).getQuantity();
-  llvm::MDNode *TBAAInfo = MayAlias ? getChar() : getTBAAInfo(QTy);
+  llvm::MDNode *TBAAInfo = MayAlias ? getChar() : getTypeInfo(QTy);
   llvm::MDNode *TBAATag = getTBAAScalarTagInfo(TBAAInfo);
   Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
   return true;
@@ -268,7 +267,7 @@
   if (isTBAAPathStruct(FieldQTy))
 FieldNode = getTBAAStructTypeInfo(FieldQTy);
   else
-FieldNode = getTBAAInfo(FieldQTy);
+FieldNode = getTypeInfo(FieldQTy);
   if (!FieldNode)
 return StructTypeMetadataCache[Ty] = nullptr;
   Fields.push_back(std::make_pair(
Index: CodeGen/CodeGenModule.h
===
--- CodeGen/CodeGenModule.h
+++ CodeGen/CodeGenModule.h
@@ -652,7 +652,10 @@
   CtorList () { return GlobalCtors; }
   CtorList () { return GlobalDtors; }
 
-  llvm::MDNode *getTBAAInfo(QualType QTy);
+  /// getTBAATypeInfo - Get metadata used to describe accesses to objects of
+  /// the given type.
+  llvm::MDNode *getTBAATypeInfo(QualType QTy);
+
   llvm::MDNode *getTBAAInfoForVTablePtr();
   llvm::MDNode *getTBAAStructInfo(QualType QTy);
   /// Return the path-aware tag for given base type, access node and offset.
Index: CodeGen/CodeGenModule.cpp
===
--- CodeGen/CodeGenModule.cpp
+++ CodeGen/CodeGenModule.cpp
@@ -573,10 +573,10 @@
   Types.RefreshTypeCacheForClass(RD);
 }
 
-llvm::MDNode *CodeGenModule::getTBAAInfo(QualType QTy) {
+llvm::MDNode *CodeGenModule::getTBAATypeInfo(QualType QTy) {
   if (!TBAA)
 return nullptr;
-  return TBAA->getTBAAInfo(QTy);
+  return TBAA->getTypeInfo(QTy);
 }
 
 llvm::MDNode *CodeGenModule::getTBAAInfoForVTablePtr() {
Index: CodeGen/CodeGenFunction.h
===
--- CodeGen/CodeGenFunction.h
+++ CodeGen/CodeGenFunction.h
@@ -1910,14 +1910,14 @@
 LValueBaseInfo BaseInfo =
 LValueBaseInfo(AlignmentSource::Type)) {
 return LValue::MakeAddr(Addr, T, getContext(), BaseInfo,
-CGM.getTBAAInfo(T));
+CGM.getTBAATypeInfo(T));
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, 

[PATCH] D37826: Refine generation of TBAA information in clang

2017-09-27 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev added a comment.

Colleagues, please let me know if I can do anything else to help with reviewing 
the patch. Thanks.


https://reviews.llvm.org/D37826



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


[PATCH] D38074: Fix TBAA information for reference accesses

2017-09-26 Thread Ivan A. Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314209: Fix TBAA information for reference accesses 
(authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D38074?vs=116326=116721#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38074

Files:
  cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
  cfe/trunk/test/CodeGen/tbaa-reference.cpp


Index: cfe/trunk/test/CodeGen/tbaa-reference.cpp
===
--- cfe/trunk/test/CodeGen/tbaa-reference.cpp
+++ cfe/trunk/test/CodeGen/tbaa-reference.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm 
-o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for reference accesses.
+
+struct S;
+
+struct B {
+  S 
+  B(S ) : s(s) {}
+  void bar();
+};
+
+void foo(S ) {
+  B b(s);
+  b.bar();
+}
+
+// CHECK-LABEL: _Z3fooR1S
+// Check initialization of the reference parameter in foo().
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa 
[[TAG_pointer:!.*]]
+//
+// CHECK-LABEL: _ZN1BC2ER1S
+// TODO: Check loading of the reference parameter in B::B(S&).
+// Check initialization of B::s in B::B(S&).
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
+//
+// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 
0}
+// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
+// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
Index: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
@@ -145,10 +145,10 @@
   if (Ty->isStdByteType())
 return MetadataCache[Ty] = getChar();
 
-  // Handle pointers.
+  // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
-  if (Ty->isPointerType())
+  if (Ty->isPointerType() || Ty->isReferenceType())
 return MetadataCache[Ty] = createTBAAScalarType("any pointer",
 getChar());
 


Index: cfe/trunk/test/CodeGen/tbaa-reference.cpp
===
--- cfe/trunk/test/CodeGen/tbaa-reference.cpp
+++ cfe/trunk/test/CodeGen/tbaa-reference.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for reference accesses.
+
+struct S;
+
+struct B {
+  S 
+  B(S ) : s(s) {}
+  void bar();
+};
+
+void foo(S ) {
+  B b(s);
+  b.bar();
+}
+
+// CHECK-LABEL: _Z3fooR1S
+// Check initialization of the reference parameter in foo().
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer:!.*]]
+//
+// CHECK-LABEL: _ZN1BC2ER1S
+// TODO: Check loading of the reference parameter in B::B(S&).
+// Check initialization of B::s in B::B(S&).
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
+//
+// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0}
+// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
+// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
Index: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
@@ -145,10 +145,10 @@
   if (Ty->isStdByteType())
 return MetadataCache[Ty] = getChar();
 
-  // Handle pointers.
+  // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
-  if (Ty->isPointerType())
+  if (Ty->isPointerType() || Ty->isReferenceType())
 return MetadataCache[Ty] = createTBAAScalarType("any pointer",
 getChar());
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38074: Fix TBAA information for reference accesses

2017-09-22 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 116326.
kosarev added a comment.

Refined the TODO wording.


https://reviews.llvm.org/D38074

Files:
  lib/CodeGen/CodeGenTBAA.cpp
  test/CodeGen/tbaa-reference.cpp


Index: test/CodeGen/tbaa-reference.cpp
===
--- test/CodeGen/tbaa-reference.cpp
+++ test/CodeGen/tbaa-reference.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm 
-o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for reference accesses.
+
+struct S;
+
+struct B {
+  S 
+  B(S ) : s(s) {}
+  void bar();
+};
+
+void foo(S ) {
+  B b(s);
+  b.bar();
+}
+
+// CHECK-LABEL: _Z3fooR1S
+// Check initialization of the reference parameter in foo().
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa 
[[TAG_pointer:!.*]]
+//
+// CHECK-LABEL: _ZN1BC2ER1S
+// TODO: Check loading of the reference parameter in B::B(S&).
+// Check initialization of B::s in B::B(S&).
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
+//
+// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 
0}
+// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
+// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -145,10 +145,10 @@
   if (Ty->isStdByteType())
 return MetadataCache[Ty] = getChar();
 
-  // Handle pointers.
+  // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
-  if (Ty->isPointerType())
+  if (Ty->isPointerType() || Ty->isReferenceType())
 return MetadataCache[Ty] = createTBAAScalarType("any pointer",
 getChar());
 


Index: test/CodeGen/tbaa-reference.cpp
===
--- test/CodeGen/tbaa-reference.cpp
+++ test/CodeGen/tbaa-reference.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for reference accesses.
+
+struct S;
+
+struct B {
+  S 
+  B(S ) : s(s) {}
+  void bar();
+};
+
+void foo(S ) {
+  B b(s);
+  b.bar();
+}
+
+// CHECK-LABEL: _Z3fooR1S
+// Check initialization of the reference parameter in foo().
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer:!.*]]
+//
+// CHECK-LABEL: _ZN1BC2ER1S
+// TODO: Check loading of the reference parameter in B::B(S&).
+// Check initialization of B::s in B::B(S&).
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
+//
+// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0}
+// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
+// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -145,10 +145,10 @@
   if (Ty->isStdByteType())
 return MetadataCache[Ty] = getChar();
 
-  // Handle pointers.
+  // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
-  if (Ty->isPointerType())
+  if (Ty->isPointerType() || Ty->isReferenceType())
 return MetadataCache[Ty] = createTBAAScalarType("any pointer",
 getChar());
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38074: Fix TBAA information for reference accesses

2017-09-22 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 116325.
kosarev added a comment.

Added a check for the initialization of the reference member in B::B(S&). (That 
in fact was my original intent; thanks for catching it.)

As to reference loads, we generate them with 
CodeGenFunction::EmitLoadOfReference() that, in contrast to 
CodeGenFunction::EmitLoadOfScalar(), is not TBAA-ready yet and looks to be a 
subject to a separate patch. So, what if we land 
https://reviews.llvm.org/D38126 first and then eventually re-consider the 
issue? Thanks again.


https://reviews.llvm.org/D38074

Files:
  lib/CodeGen/CodeGenTBAA.cpp
  test/CodeGen/tbaa-reference.cpp


Index: test/CodeGen/tbaa-reference.cpp
===
--- test/CodeGen/tbaa-reference.cpp
+++ test/CodeGen/tbaa-reference.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm 
-o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for reference accesses.
+
+struct S;
+
+struct B {
+  S 
+  B(S ) : s(s) {}
+  void bar();
+};
+
+void foo(S ) {
+  B b(s);
+  b.bar();
+}
+
+// CHECK-LABEL: _Z3fooR1S
+// Check initialization of the reference parameter in foo().
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa 
[[TAG_pointer:!.*]]
+//
+// CHECK-LABEL: _ZN1BC2ER1S
+// TODO: Check initialization of the parameter s in B::B(S&).
+// Check initialization of B::s in B::B(S&).
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
+//
+// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 
0}
+// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
+// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -145,10 +145,10 @@
   if (Ty->isStdByteType())
 return MetadataCache[Ty] = getChar();
 
-  // Handle pointers.
+  // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
-  if (Ty->isPointerType())
+  if (Ty->isPointerType() || Ty->isReferenceType())
 return MetadataCache[Ty] = createTBAAScalarType("any pointer",
 getChar());
 


Index: test/CodeGen/tbaa-reference.cpp
===
--- test/CodeGen/tbaa-reference.cpp
+++ test/CodeGen/tbaa-reference.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for reference accesses.
+
+struct S;
+
+struct B {
+  S 
+  B(S ) : s(s) {}
+  void bar();
+};
+
+void foo(S ) {
+  B b(s);
+  b.bar();
+}
+
+// CHECK-LABEL: _Z3fooR1S
+// Check initialization of the reference parameter in foo().
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer:!.*]]
+//
+// CHECK-LABEL: _ZN1BC2ER1S
+// TODO: Check initialization of the parameter s in B::B(S&).
+// Check initialization of B::s in B::B(S&).
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
+//
+// CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0}
+// CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
+// CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -145,10 +145,10 @@
   if (Ty->isStdByteType())
 return MetadataCache[Ty] = getChar();
 
-  // Handle pointers.
+  // Handle pointers and references.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
-  if (Ty->isPointerType())
+  if (Ty->isPointerType() || Ty->isReferenceType())
 return MetadataCache[Ty] = createTBAAScalarType("any pointer",
 getChar());
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38126: Make TBAA information to be part of LValueBaseInfo

2017-09-22 Thread Ivan A. Kosarev via Phabricator via cfe-commits
kosarev added a comment.

Sure, will do. Just added it to https://reviews.llvm.org/D38074. Thanks.


https://reviews.llvm.org/D38126



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