]> granicus.if.org Git - clang/commitdiff
[CodeGen] Have a special function to get TBAA info for may-alias accesses
authorIvan A. Kosarev <ikosarev@accesssoftek.com>
Mon, 2 Oct 2017 11:10:04 +0000 (11:10 +0000)
committerIvan A. Kosarev <ikosarev@accesssoftek.com>
Mon, 2 Oct 2017 11:10:04 +0000 (11:10 +0000)
This is part of D37826 reworked to be a separate patch to
simplify review.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314660 91177308-0d34-0410-b5e6-96231b3b80d8

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

index b37036659cca955d992f8a8158063135f5fa1c10..ba970b9bde19db429a7f9fea03c02ac421b2d4b2 100644 (file)
@@ -1522,7 +1522,7 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(Address Addr, bool Volatile,
   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 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr,
   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 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
       // 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 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
   // 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;
 }
index 25779c044bb04ab1ca9cfbc3adf7043d1752778d..ec122b795ce79ac2c4ecbf7efeeba59072aa3e91 100644 (file)
@@ -599,6 +599,12 @@ llvm::MDNode *CodeGenModule::getTBAAStructTagInfo(QualType BaseTy,
   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 fdbf84416cab4a2c814ee44e7768eec2b434334b..1f26be6f2bd39b2c6d46b28d7606cf06423614ba 100644 (file)
@@ -662,6 +662,10 @@ public:
   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 b341754ba09afa9fe40c76c46dd9568e79988e71..7b8a023b7943383a1b2d14ddc809757658172be5 100644 (file)
@@ -326,3 +326,7 @@ CodeGenTBAA::getTBAAScalarTagInfo(llvm::MDNode *AccessNode) {
   return ScalarTagMetadataCache[AccessNode] =
     MDHelper.createTBAAStructTagNode(AccessNode, AccessNode, 0);
 }
+
+llvm::MDNode *CodeGenTBAA::getMayAliasTypeInfo() {
+  return getChar();
+}
index 9ff9e881d93df719548be72c1b0af22417844776..71c53d43f793feaabddef0a2639b592ea48d2b6d 100644 (file)
@@ -116,6 +116,10 @@ public:
 
   /// 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