Use MDBuilder to help with metadata creation.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154767 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenTBAA.cpp b/lib/CodeGen/CodeGenTBAA.cpp
index 9ee3f1d..34f91e1 100644
--- a/lib/CodeGen/CodeGenTBAA.cpp
+++ b/lib/CodeGen/CodeGenTBAA.cpp
@@ -28,7 +28,7 @@
 CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext& VMContext,
                          const LangOptions &Features, MangleContext &MContext)
   : Context(Ctx), VMContext(VMContext), Features(Features), MContext(MContext),
-    Root(0), Char(0) {
+    MDHelper(VMContext), Root(0), Char(0) {
 }
 
 CodeGenTBAA::~CodeGenTBAA() {
@@ -40,7 +40,7 @@
   // (or a different version of this front-end), their TBAA trees will
   // remain distinct, and the optimizer will treat them conservatively.
   if (!Root)
-    Root = getTBAAInfoForNamedType("Simple C/C++ TBAA", 0);
+    Root = MDHelper.CreateTBAARoot("Simple C/C++ TBAA");
 
   return Root;
 }
@@ -51,33 +51,11 @@
   // these special powers only cover user-accessible memory, and doesn't
   // include things like vtables.
   if (!Char)
-    Char = getTBAAInfoForNamedType("omnipotent char", getRoot());
+    Char = MDHelper.CreateTBAANode("omnipotent char", getRoot());
 
   return Char;
 }
 
-/// getTBAAInfoForNamedType - Create a TBAA tree node with the given string
-/// as its identifier, and the given Parent node as its tree parent.
-llvm::MDNode *CodeGenTBAA::getTBAAInfoForNamedType(StringRef NameStr,
-                                                   llvm::MDNode *Parent,
-                                                   bool Readonly) {
-  // Currently there is only one flag defined - the readonly flag.
-  llvm::Value *Flags = 0;
-  if (Readonly)
-    Flags = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), true);
-
-  // Set up the mdnode operand list.
-  llvm::Value *Ops[] = {
-    llvm::MDString::get(VMContext, NameStr),
-    Parent,
-    Flags
-  };
-
-  // Create the mdnode.
-  unsigned Len = llvm::array_lengthof(Ops) - !Flags;
-  return llvm::MDNode::get(VMContext, llvm::makeArrayRef(Ops, Len));
-}
-
 static bool TypeHasMayAlias(QualType QTy) {
   // Tagged types have declarations, and therefore may have attributes.
   if (const TagType *TTy = dyn_cast<TagType>(QTy))
@@ -137,7 +115,7 @@
     // "underlying types".
     default:
       return MetadataCache[Ty] =
-               getTBAAInfoForNamedType(BTy->getName(Features), getChar());
+        MDHelper.CreateTBAANode(BTy->getName(Features), getChar());
     }
   }
 
@@ -145,7 +123,7 @@
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.
   if (Ty->isPointerType())
-    return MetadataCache[Ty] = getTBAAInfoForNamedType("any pointer",
+    return MetadataCache[Ty] = MDHelper.CreateTBAANode("any pointer",
                                                        getChar());
 
   // Enum types are distinct types. In C++ they have "underlying types",
@@ -173,7 +151,7 @@
     llvm::raw_svector_ostream Out(OutName);
     MContext.mangleCXXRTTIName(QualType(ETy, 0), Out);
     Out.flush();
-    return MetadataCache[Ty] = getTBAAInfoForNamedType(OutName, getChar());
+    return MetadataCache[Ty] = MDHelper.CreateTBAANode(OutName, getChar());
   }
 
   // For now, handle any other kind of type conservatively.
@@ -181,5 +159,5 @@
 }
 
 llvm::MDNode *CodeGenTBAA::getTBAAInfoForVTablePtr() {
-  return getTBAAInfoForNamedType("vtable pointer", getRoot());
+  return MDHelper.CreateTBAANode("vtable pointer", getRoot());
 }