diff options
Diffstat (limited to 'clang/lib/CodeGen/CodeGenTBAA.h')
-rw-r--r-- | clang/lib/CodeGen/CodeGenTBAA.h | 80 |
1 files changed, 45 insertions, 35 deletions
diff --git a/clang/lib/CodeGen/CodeGenTBAA.h b/clang/lib/CodeGen/CodeGenTBAA.h index 75f32950d5d..2b2c2d4b098 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.h +++ b/clang/lib/CodeGen/CodeGenTBAA.h @@ -32,15 +32,22 @@ namespace clang { 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(llvm::MDNode *BaseType, llvm::MDNode *AccessType, - uint64_t Offset) + TBAAAccessInfo(QualType BaseType, llvm::MDNode *AccessType, uint64_t Offset) : BaseType(BaseType), AccessType(AccessType), Offset(Offset) {} explicit TBAAAccessInfo(llvm::MDNode *AccessType) - : TBAAAccessInfo(/* BaseType= */ nullptr, AccessType, /* Offset= */ 0) + : TBAAAccessInfo(/* BaseType= */ QualType(), AccessType, /* Offset= */ 0) {} TBAAAccessInfo() @@ -50,7 +57,7 @@ struct 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. - llvm::MDNode *BaseType; + QualType BaseType; /// AccessType - The final access type. May be null if there is no TBAA /// information available about this access. @@ -75,10 +82,12 @@ class CodeGenTBAA { /// MetadataCache - This maps clang::Types to scalar llvm::MDNodes describing /// them. llvm::DenseMap<const Type *, llvm::MDNode *> MetadataCache; - /// This maps clang::Types to a base access type in the type DAG. - llvm::DenseMap<const Type *, llvm::MDNode *> BaseTypeMetadataCache; - /// This maps TBAA access descriptors to tag nodes. - llvm::DenseMap<TBAAAccessInfo, llvm::MDNode *> AccessTagMetadataCache; + /// This maps clang::Types to a struct node in the type DAG. + llvm::DenseMap<const Type *, llvm::MDNode *> StructTypeMetadataCache; + /// This maps TBAAPathTags to a tag node. + llvm::DenseMap<TBAAPathTag, llvm::MDNode *> StructTagMetadataCache; + /// This maps a scalar type to a scalar tag node. + llvm::DenseMap<const llvm::MDNode *, llvm::MDNode *> ScalarTagMetadataCache; /// StructMetadataCache - This maps clang::Types to llvm::MDNodes describing /// them for struct assignments. @@ -118,25 +127,26 @@ public: /// given type. llvm::MDNode *getTypeInfo(QualType QTy); - /// getVTablePtrAccessInfo - Get the TBAA information that describes an - /// access to a virtual table pointer. - TBAAAccessInfo getVTablePtrAccessInfo(); + /// getTBAAInfoForVTablePtr - Get the TBAA MDNode to be used for a + /// dereference of a vtable pointer. + llvm::MDNode *getTBAAInfoForVTablePtr(); /// getTBAAStructInfo - Get the TBAAStruct MDNode to be used for a memcpy of /// the given type. llvm::MDNode *getTBAAStructInfo(QualType QTy); - /// 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 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); - /// 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); - /// getMayAliasAccessInfo - Get TBAA information that represents may-alias + /// getMayAliasTypeInfo - Get TBAA information that represents may-alias /// accesses. - TBAAAccessInfo getMayAliasAccessInfo(); + llvm::MDNode *getMayAliasTypeInfo(); }; } // end namespace CodeGen @@ -144,31 +154,31 @@ public: namespace llvm { -template<> struct DenseMapInfo<clang::CodeGen::TBAAAccessInfo> { - static clang::CodeGen::TBAAAccessInfo getEmptyKey() { - return clang::CodeGen::TBAAAccessInfo( - DenseMapInfo<MDNode *>::getEmptyKey(), - DenseMapInfo<MDNode *>::getEmptyKey(), +template<> struct DenseMapInfo<clang::CodeGen::TBAAPathTag> { + static clang::CodeGen::TBAAPathTag getEmptyKey() { + return clang::CodeGen::TBAAPathTag( + DenseMapInfo<const clang::Type *>::getEmptyKey(), + DenseMapInfo<const MDNode *>::getEmptyKey(), DenseMapInfo<uint64_t>::getEmptyKey()); } - static clang::CodeGen::TBAAAccessInfo getTombstoneKey() { - return clang::CodeGen::TBAAAccessInfo( - DenseMapInfo<MDNode *>::getTombstoneKey(), - DenseMapInfo<MDNode *>::getTombstoneKey(), + static clang::CodeGen::TBAAPathTag getTombstoneKey() { + return clang::CodeGen::TBAAPathTag( + DenseMapInfo<const clang::Type *>::getTombstoneKey(), + DenseMapInfo<const MDNode *>::getTombstoneKey(), DenseMapInfo<uint64_t>::getTombstoneKey()); } - static unsigned getHashValue(const clang::CodeGen::TBAAAccessInfo &Val) { - return DenseMapInfo<MDNode *>::getHashValue(Val.BaseType) ^ - DenseMapInfo<MDNode *>::getHashValue(Val.AccessType) ^ + static unsigned getHashValue(const clang::CodeGen::TBAAPathTag &Val) { + return DenseMapInfo<const clang::Type *>::getHashValue(Val.BaseT) ^ + DenseMapInfo<const MDNode *>::getHashValue(Val.AccessN) ^ DenseMapInfo<uint64_t>::getHashValue(Val.Offset); } - static bool isEqual(const clang::CodeGen::TBAAAccessInfo &LHS, - const clang::CodeGen::TBAAAccessInfo &RHS) { - return LHS.BaseType == RHS.BaseType && - LHS.AccessType == RHS.AccessType && + static bool isEqual(const clang::CodeGen::TBAAPathTag &LHS, + const clang::CodeGen::TBAAPathTag &RHS) { + return LHS.BaseT == RHS.BaseT && + LHS.AccessN == RHS.AccessN && LHS.Offset == RHS.Offset; } }; |