now that libsystem no longer uses SmallVector, we can move
[oota-llvm.git] / lib / VMCore / Metadata.cpp
index 3e24eaed60cb247431986797d2ee1a54eac676b0..ac91a40e10db2bb08251fa8f866e3ef52ced441d 100644 (file)
@@ -42,20 +42,22 @@ MDString *MDString::get(LLVMContext &Context, const char *Str) {
   StringMapEntry<MDString *> &Entry = 
     pImpl->MDStringCache.GetOrCreateValue(Str ? StringRef(Str) : StringRef());
   MDString *&S = Entry.getValue();
-  if (!S) new MDString(Context, Entry.getKey());
+  if (!S) S = new MDString(Context, Entry.getKey());
   return S;
 }
 
 //===----------------------------------------------------------------------===//
 // MDNode implementation.
 //
-MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals)
+MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals,
+               Function *LocalFunc)
   : 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 = LocalFunc;
 }
 
 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;
@@ -218,7 +223,7 @@ public:
   /// addMD - Attach the metadata of given kind to an Instruction.
   void addMD(unsigned Kind, MDNode *Node, Instruction *Inst);
   
-  /// removeMD - Remove metadata of given kind attached with an instuction.
+  /// removeMD - Remove metadata of given kind attached with an instruction.
   void removeMD(unsigned Kind, Instruction *Inst);
   
   /// removeAllMetadata - Remove all metadata attached with an instruction.
@@ -289,7 +294,7 @@ void MetadataContextImpl::addMD(unsigned MDKind, MDNode *Node,
   Info.push_back(std::make_pair(MDKind, Node));
 }
 
-/// removeMD - Remove metadata of given kind attached with an instuction.
+/// removeMD - Remove metadata of given kind attached with an instruction.
 void MetadataContextImpl::removeMD(unsigned Kind, Instruction *Inst) {
   MDStoreTy::iterator I = MetadataStore.find(Inst);
   if (I == MetadataStore.end())
@@ -442,7 +447,7 @@ void MetadataContext::addMD(unsigned Kind, MDNode *Node, Instruction *Inst) {
   pImpl->addMD(Kind, Node, Inst);
 }
 
-/// removeMD - Remove metadata of given kind attached with an instuction.
+/// removeMD - Remove metadata of given kind attached with an instruction.
 void MetadataContext::removeMD(unsigned Kind, Instruction *Inst) {
   pImpl->removeMD(Kind, Inst);
 }