summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan A. Kosarev <ikosarev@accesssoftek.com>2017-12-18 16:49:39 +0000
committerIvan A. Kosarev <ikosarev@accesssoftek.com>2017-12-18 16:49:39 +0000
commit04e1d01736d3368fd491d4bdb99a52452e9e83e1 (patch)
tree99d86b063707f7e45dda9ebd756542c076b6552e
parent09f56a54d029ad1fb6b62f66449a6abf8f00ff89 (diff)
downloadbcm5719-llvm-04e1d01736d3368fd491d4bdb99a52452e9e83e1.tar.gz
bcm5719-llvm-04e1d01736d3368fd491d4bdb99a52452e9e83e1.zip
[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 llvm-svn: 320993
-rw-r--r--llvm/include/llvm/IR/MDBuilder.h21
-rw-r--r--llvm/lib/IR/MDBuilder.cpp32
2 files changed, 49 insertions, 4 deletions
diff --git a/llvm/include/llvm/IR/MDBuilder.h b/llvm/include/llvm/IR/MDBuilder.h
index 15c1b9cb60e..dff1ca12407 100644
--- a/llvm/include/llvm/IR/MDBuilder.h
+++ b/llvm/include/llvm/IR/MDBuilder.h
@@ -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);
};
diff --git a/llvm/lib/IR/MDBuilder.cpp b/llvm/lib/IR/MDBuilder.cpp
index d8e64db7c5d..6d77a8f2d60 100644
--- a/llvm/lib/IR/MDBuilder.cpp
+++ b/llvm/lib/IR/MDBuilder.cpp
@@ -157,7 +157,7 @@ MDNode *MDBuilder::createTBAAStructNode(ArrayRef<TBAAStructField> Fields) {
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::createTBAAStructTagNode(MDNode *BaseType, MDNode *AccessType,
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");
OpenPOWER on IntegriCloud