[cfe-commits] r154767 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenTBAA.cpp lib/CodeGen/CodeGenTBAA.h test/CodeGen/may-alias.c test/CodeGen/tbaa-for-vptr.cpp

Duncan Sands baldrick at free.fr
Sun Apr 15 11:04:54 PDT 2012


Author: baldrick
Date: Sun Apr 15 13:04:54 2012
New Revision: 154767

URL: http://llvm.org/viewvc/llvm-project?rev=154767&view=rev
Log:
Use MDBuilder to help with metadata creation.

Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
    cfe/trunk/lib/CodeGen/CodeGenTBAA.h
    cfe/trunk/test/CodeGen/may-alias.c
    cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=154767&r1=154766&r2=154767&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sun Apr 15 13:04:54 2012
@@ -24,6 +24,7 @@
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/Intrinsics.h"
 #include "llvm/LLVMContext.h"
+#include "llvm/Support/MDBuilder.h"
 #include "llvm/Target/TargetData.h"
 using namespace clang;
 using namespace CodeGen;
@@ -908,16 +909,8 @@
     }
   }
 
-  if (End == Min)
-    return NULL;
-
-  llvm::Value *LowAndHigh[2];
-  LowAndHigh[0] = llvm::ConstantInt::get(LTy, Min);
-  LowAndHigh[1] = llvm::ConstantInt::get(LTy, End);
-
-  llvm::LLVMContext &C = getLLVMContext();
-  llvm::MDNode *Range = llvm::MDNode::get(C, LowAndHigh);
-  return Range;
+  llvm::MDBuilder MDHelper(getLLVMContext());
+  return MDHelper.CreateRange(Min, End);
 }
 
 llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,

Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=154767&r1=154766&r2=154767&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Sun Apr 15 13:04:54 2012
@@ -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());
 }

Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.h?rev=154767&r1=154766&r2=154767&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.h Sun Apr 15 13:04:54 2012
@@ -17,6 +17,7 @@
 
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/Support/MDBuilder.h"
 
 namespace llvm {
   class LLVMContext;
@@ -41,6 +42,9 @@
   const LangOptions &Features;
   MangleContext &MContext;
 
+  // MDHelper - Helper for creating metadata.
+  llvm::MDBuilder MDHelper;
+
   /// MetadataCache - This maps clang::Types to llvm::MDNodes describing them.
   llvm::DenseMap<const Type *, llvm::MDNode *> MetadataCache;
 
@@ -55,10 +59,6 @@
   /// considered to be equivalent to it.
   llvm::MDNode *getChar();
 
-  llvm::MDNode *getTBAAInfoForNamedType(StringRef NameStr,
-                                        llvm::MDNode *Parent,
-                                        bool Readonly = false);
-
 public:
   CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext &VMContext,
               const LangOptions &Features,

Modified: cfe/trunk/test/CodeGen/may-alias.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/may-alias.c?rev=154767&r1=154766&r2=154767&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/may-alias.c (original)
+++ cfe/trunk/test/CodeGen/may-alias.c Sun Apr 15 13:04:54 2012
@@ -26,5 +26,5 @@
 
 // CHECK: !0 = metadata !{metadata !"any pointer", metadata !1}
 // CHECK: !1 = metadata !{metadata !"omnipotent char", metadata !2}
-// CHECK: !2 = metadata !{metadata !"Simple C/C++ TBAA", null}
+// CHECK: !2 = metadata !{metadata !"Simple C/C++ TBAA"}
 // CHECK: !3 = metadata !{metadata !"int", metadata !1}

Modified: cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp?rev=154767&r1=154766&r2=154767&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp (original)
+++ cfe/trunk/test/CodeGen/tbaa-for-vptr.cpp Sun Apr 15 13:04:54 2012
@@ -16,4 +16,4 @@
 // CHECK: %{{.*}} = load {{.*}} !tbaa !0
 // CHECK: store {{.*}} !tbaa !0
 // CHECK: !0 = metadata !{metadata !"vtable pointer", metadata !1}
-// CHECK: !1 = metadata !{metadata !"Simple C/C++ TBAA", null}
+// CHECK: !1 = metadata !{metadata !"Simple C/C++ TBAA"}





More information about the cfe-commits mailing list