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

Reply via email to