From a511ed75013f049eaf6f1978bff15cb7020524d4 Mon Sep 17 00:00:00 2001 From: "Ivan A. Kosarev" Date: Tue, 3 Oct 2017 10:52:39 +0000 Subject: [CodeGen] Introduce generic TBAA access descriptors 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 D37826 reworked to be a separate patch to simplify review. Differential Revision: https://reviews.llvm.org/D38456 llvm-svn: 314780 --- clang/lib/CodeGen/CodeGenTBAA.h | 51 +++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 12 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenTBAA.h') diff --git a/clang/lib/CodeGen/CodeGenTBAA.h b/clang/lib/CodeGen/CodeGenTBAA.h index 71c53d43f79..2b2c2d4b098 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.h +++ b/clang/lib/CodeGen/CodeGenTBAA.h @@ -30,15 +30,43 @@ namespace clang { 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; +}; + +// 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) + {} - 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; - }; + /// 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 @@ public: /// 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); -- cgit v1.2.1