MDNodes that refer to an instruction are local to a function; in that case, explicitl...
authorVictor Hernandez <vhernandez@apple.com>
Wed, 16 Dec 2009 02:52:09 +0000 (02:52 +0000)
committerVictor Hernandez <vhernandez@apple.com>
Wed, 16 Dec 2009 02:52:09 +0000 (02:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91497 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Metadata.h
lib/VMCore/Metadata.cpp

index c7f2b445ee8e7cc759fd9bc6390f54681261af65..320944bf244eb2b807c7b9e481245e5829994fd8 100644 (file)
@@ -111,13 +111,16 @@ class MDNode : public MetadataBase, public FoldingSetNode {
 
   ElementVH *Node;
   unsigned NodeSize;
+  Function *LocalFunction;
 
 protected:
-  explicit MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals);
+  explicit MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals,
+                  Function *LocalFunction = NULL);
 public:
   // Constructors and destructors.
   static MDNode *get(LLVMContext &Context, 
-                     Value *const *Vals, unsigned NumVals);
+                     Value *const *Vals, unsigned NumVals,
+                     Function *LocalFunction = NULL);
 
   /// ~MDNode - Destroy MDNode.
   ~MDNode();
@@ -130,6 +133,9 @@ public:
 
   /// getNumElements - Return number of MDNode elements.
   unsigned getNumElements() const { return NodeSize; }
+  
+  /// isFunctionLocal - Return whether MDNode is local to a function.
+  bool isFunctionLocal() const { return LocalFunction; }
 
   /// Profile - calculate a unique identifier for this MDNode to collapse
   /// duplicates
index b80b6bfebc436e224b61290a18a6da34821d942f..713661680cfb3b166885ecdd2dbfb8f703487107 100644 (file)
@@ -49,13 +49,15 @@ MDString *MDString::get(LLVMContext &Context, const char *Str) {
 //===----------------------------------------------------------------------===//
 // MDNode implementation.
 //
-MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals)
+MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals,
+               Function *LocalFunction)
   : MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) {
   NodeSize = NumVals;
   Node = new ElementVH[NodeSize];
   ElementVH *Ptr = Node;
   for (unsigned i = 0; i != NumVals; ++i) 
     *Ptr++ = ElementVH(Vals[i], this);
+  LocalFunction = LocalFunction;
 }
 
 void MDNode::Profile(FoldingSetNodeID &ID) const {
@@ -63,17 +65,20 @@ void MDNode::Profile(FoldingSetNodeID &ID) const {
     ID.AddPointer(getElement(i));
 }
 
-MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
+MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals,
+                    Function *LocalFunction) {
   LLVMContextImpl *pImpl = Context.pImpl;
   FoldingSetNodeID ID;
   for (unsigned i = 0; i != NumVals; ++i)
     ID.AddPointer(Vals[i]);
+  if (LocalFunction)
+    ID.AddPointer(LocalFunction);
 
   void *InsertPoint;
   MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
   if (!N) {
     // InsertPoint will have been set by the FindNodeOrInsertPos call.
-    N = new MDNode(Context, Vals, NumVals);
+    N = new MDNode(Context, Vals, NumVals, LocalFunction);
     pImpl->MDNodeSet.InsertNode(N, InsertPoint);
   }
   return N;