[PATCH] D39956: [IR] Add MDBuilder helpers for the new TBAA metadata format
Ivan Kosarev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 21 05:25:36 PST 2017
kosarev updated this revision to Diff 123770.
kosarev added a comment.
Changed the order of metadata nodes describing structure fields so that the type node comes first. This agrees with the order of nodes in access tags and type nodes in the old format where offsets come after type nodes. Also simplifies adopting the existing code to the new format a bit.
https://reviews.llvm.org/D39956
Files:
include/llvm/IR/MDBuilder.h
lib/IR/MDBuilder.cpp
Index: lib/IR/MDBuilder.cpp
===================================================================
--- lib/IR/MDBuilder.cpp
+++ 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<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");
Index: include/llvm/IR/MDBuilder.h
===================================================================
--- include/llvm/IR/MDBuilder.h
+++ 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<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);
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39956.123770.patch
Type: text/x-patch
Size: 4101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171121/65c8eeb7/attachment.bin>
More information about the llvm-commits
mailing list