[llvm] r320993 - [IR] Add MDBuilder helpers for the new TBAA metadata format
Ivan A. Kosarev via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 18 08:49:39 PST 2017
Author: kosarev
Date: Mon Dec 18 08:49:39 2017
New Revision: 320993
URL: http://llvm.org/viewvc/llvm-project?rev=320993&view=rev
Log:
[IR] Add MDBuilder helpers for the new TBAA metadata format
The new helpers are supposed to be used in clang to generate TBAA
information in the new format proposed in this thread:
http://lists.llvm.org/pipermail/llvm-dev/2017-November/118748.html
Differential Revision: https://reviews.llvm.org/D39956
Modified:
llvm/trunk/include/llvm/IR/MDBuilder.h
llvm/trunk/lib/IR/MDBuilder.cpp
Modified: llvm/trunk/include/llvm/IR/MDBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/MDBuilder.h?rev=320993&r1=320992&r2=320993&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/MDBuilder.h (original)
+++ llvm/trunk/include/llvm/IR/MDBuilder.h Mon Dec 18 08:49:39 2017
@@ -30,6 +30,7 @@ class Constant;
class ConstantAsMetadata;
class MDNode;
class MDString;
+class Metadata;
class MDBuilder {
LLVMContext &Context;
@@ -149,9 +150,9 @@ public:
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 @@ public:
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<TBAAStructField> Fields =
+ ArrayRef<TBAAStructField>());
+
+ /// \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);
};
Modified: llvm/trunk/lib/IR/MDBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/MDBuilder.cpp?rev=320993&r1=320992&r2=320993&view=diff
==============================================================================
--- llvm/trunk/lib/IR/MDBuilder.cpp (original)
+++ llvm/trunk/lib/IR/MDBuilder.cpp Mon Dec 18 08:49:39 2017
@@ -157,7 +157,7 @@ MDNode *MDBuilder::createTBAAStructNode(
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 @@ MDNode *MDBuilder::createTBAAStructTagNo
return MDNode::get(Context, {BaseType, AccessType, createConstant(Off)});
}
+MDNode *MDBuilder::createTBAATypeNode(MDNode *Parent, uint64_t Size,
+ Metadata *Id,
+ ArrayRef<TBAAStructField> Fields) {
+ SmallVector<Metadata *, 4> 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<Metadata *, 2> Vals(2);
Vals[0] = createString("loop_header_weight");
More information about the llvm-commits
mailing list