Add an MDBuilder utility for creating !tbaa.struct nodes.
authorDan Gohman <gohman@apple.com>
Fri, 21 Sep 2012 23:00:37 +0000 (23:00 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 21 Sep 2012 23:00:37 +0000 (23:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164425 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MDBuilder.h

index 2aa48b0b472491e868927eb081a73306e75706a5..1867a639236e39bed5a24d0f66bb174dad4a52be 100644 (file)
@@ -134,6 +134,27 @@ namespace llvm {
       }
     }
 
+    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) {}
+    };
+
+    /// \brief Return metadata for a tbaa.struct node with the given
+    /// struct field descriptions.
+    MDNode *createTBAAStructNode(ArrayRef<TBAAStructField> Fields) {
+      SmallVector<Value *, 4> Vals(Fields.size() * 3);
+      Type *Int64 = IntegerType::get(Context, 64);
+      for (unsigned i = 0, e = Fields.size(); i != e; ++i) {
+        Vals[i * 3 + 0] = ConstantInt::get(Int64, Fields[i].Offset);
+        Vals[i * 3 + 1] = ConstantInt::get(Int64, Fields[i].Size);
+        Vals[i * 3 + 2] = Fields[i].TBAA;
+      }
+      return MDNode::get(Context, Vals);
+    }
+
   };
 
 } // end namespace llvm