Index: llvm/trunk/include/llvm/IR/MDBuilder.h =================================================================== --- llvm/trunk/include/llvm/IR/MDBuilder.h +++ llvm/trunk/include/llvm/IR/MDBuilder.h @@ -30,6 +30,7 @@ class ConstantAsMetadata; class MDNode; class MDString; +class Metadata; class MDBuilder { LLVMContext &Context; @@ -149,9 +150,9 @@ struct TBAAStructField { uint64_t Offset; uint64_t Size; - MDNode *TBAA; - TBAAStructField(uint64_t Offset, uint64_t Size, MDNode *TBAA) : - Offset(Offset), Size(Size), TBAA(TBAA) {} + MDNode *Type; + TBAAStructField(uint64_t Offset, uint64_t Size, MDNode *Type) : + Offset(Offset), Size(Size), Type(Type) {} }; /// \brief Return metadata for a tbaa.struct node with the given @@ -174,6 +175,20 @@ MDNode *createTBAAStructTagNode(MDNode *BaseType, MDNode *AccessType, uint64_t Offset, bool IsConstant = false); + /// \brief Return metadata for a TBAA type node in the TBAA type DAG with the + /// given parent type, size in bytes, type identifier and a list of fields. + MDNode *createTBAATypeNode(MDNode *Parent, uint64_t Size, Metadata *Id, + ArrayRef Fields = + ArrayRef()); + + /// \brief Return metadata for a TBAA access tag with the given base type, + /// final access type, offset of the access relative to the base type, size of + /// the access and flag indicating whether the accessed object can be + /// considered immutable for the purposes of the TBAA analysis. + MDNode *createTBAAAccessTag(MDNode *BaseType, MDNode *AccessType, + uint64_t Offset, uint64_t Size, + bool IsImmutable = false); + /// \brief Return metadata containing an irreducible loop header weight. MDNode *createIrrLoopHeaderWeight(uint64_t Weight); }; Index: llvm/trunk/lib/IR/MDBuilder.cpp =================================================================== --- llvm/trunk/lib/IR/MDBuilder.cpp +++ llvm/trunk/lib/IR/MDBuilder.cpp @@ -157,7 +157,7 @@ for (unsigned i = 0, e = Fields.size(); i != e; ++i) { Vals[i * 3 + 0] = createConstant(ConstantInt::get(Int64, Fields[i].Offset)); Vals[i * 3 + 1] = createConstant(ConstantInt::get(Int64, Fields[i].Size)); - Vals[i * 3 + 2] = Fields[i].TBAA; + Vals[i * 3 + 2] = Fields[i].Type; } return MDNode::get(Context, Vals); } @@ -198,6 +198,36 @@ return MDNode::get(Context, {BaseType, AccessType, createConstant(Off)}); } +MDNode *MDBuilder::createTBAATypeNode(MDNode *Parent, uint64_t Size, + Metadata *Id, + ArrayRef Fields) { + SmallVector Ops(3 + Fields.size() * 3); + Type *Int64 = Type::getInt64Ty(Context); + Ops[0] = Parent; + Ops[1] = createConstant(ConstantInt::get(Int64, Size)); + Ops[2] = Id; + for (unsigned I = 0, E = Fields.size(); I != E; ++I) { + Ops[I * 3 + 3] = Fields[I].Type; + Ops[I * 3 + 4] = createConstant(ConstantInt::get(Int64, Fields[I].Offset)); + Ops[I * 3 + 5] = createConstant(ConstantInt::get(Int64, Fields[I].Size)); + } + return MDNode::get(Context, Ops); +} + +MDNode *MDBuilder::createTBAAAccessTag(MDNode *BaseType, MDNode *AccessType, + uint64_t Offset, uint64_t Size, + bool IsImmutable) { + IntegerType *Int64 = Type::getInt64Ty(Context); + auto *OffsetNode = createConstant(ConstantInt::get(Int64, Offset)); + auto *SizeNode = createConstant(ConstantInt::get(Int64, Size)); + if (IsImmutable) { + auto *ImmutabilityFlagNode = createConstant(ConstantInt::get(Int64, 1)); + return MDNode::get(Context, {BaseType, AccessType, OffsetNode, SizeNode, + ImmutabilityFlagNode}); + } + return MDNode::get(Context, {BaseType, AccessType, OffsetNode, SizeNode}); +} + MDNode *MDBuilder::createIrrLoopHeaderWeight(uint64_t Weight) { SmallVector Vals(2); Vals[0] = createString("loop_header_weight");