llvm.org GIT mirror llvm / ab67e70
Link NamedMDNodes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78696 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 11 years ago
5 changed file(s) with 42 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
228228 return new NamedMDNode(N, MDs, NumMDs, M);
229229 }
230230
231 static NamedMDNode *Create(const NamedMDNode *NMD, Module *M = 0);
232
231233 /// eraseFromParent - Drop all references and remove the node from parent
232234 /// module.
233235 void eraseFromParent();
537537 return false;
538538 }
539539
540 // Insert all of the named mdnoes in Src into the Dest module.
541 static void LinkNamedMDNodes(Module *Dest, Module *Src) {
542 for (Module::const_named_metadata_iterator I = Src->named_metadata_begin(),
543 E = Src->named_metadata_end(); I != E; ++I) {
544 const NamedMDNode *SrcNMD = I;
545 NamedMDNode *DestNMD = Dest->getNamedMetadata(SrcNMD->getName());
546 if (!DestNMD)
547 NamedMDNode::Create(SrcNMD, Dest);
548 else {
549 // Add Src elements into Dest node.
550 for (unsigned i = 0, e = SrcNMD->getNumElements(); i != e; ++i)
551 DestNMD->addElement(SrcNMD->getElement(i));
552 }
553 }
554 }
555
540556 // LinkGlobals - Loop through the global variables in the src module and merge
541557 // them into the dest module.
542558 static bool LinkGlobals(Module *Dest, const Module *Src,
13061322 AppendingVars.insert(std::make_pair(I->getName(), I));
13071323 }
13081324
1325 // Insert all of the named mdnoes in Src into the Dest module.
1326 LinkNamedMDNodes(Dest, Src);
1327
13091328 // Insert all of the globals in src into the Dest module... without linking
13101329 // initializers (which could refer to functions not yet mapped over).
13111330 if (LinkGlobals(Dest, Src, ValueMap, AppendingVars, ErrorMsg))
103103 dropAllReferences();
104104 getType()->getContext().pImpl->MDNodes.remove(this);
105105 }
106
106107 //===----------------------------------------------------------------------===//
107108 //NamedMDNode implementation
108109 //
122123 ParentModule->getNamedMDList().push_back(this);
123124 }
124125
126 NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) {
127 assert (NMD && "Invalid source NamedMDNode!");
128 SmallVector Elems;
129 for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i)
130 Elems.push_back(NMD->getElement(i));
131 return new NamedMDNode(NMD->getName().data(), Elems.data(), Elems.size(), M);
132 }
133
125134 /// eraseFromParent - Drop all references and remove the node from parent
126135 /// module.
127136 void NamedMDNode::eraseFromParent() {
0 ; RUN: llvm-as < %s > %t.bc
1 ; RUN: llvm-as < %p/linknamedmdnode2.ll > %t2.bc
2 ; RUN: llvm-link %t.bc %t2.bc | llvm-dis | grep "!llvm.stuff = !{!0, !1}"
3
4 !0 = metadata !{i32 42}
5 !llvm.stuff = !{!0}
0 ; This file is used by linknamedmdnode.ll, so it doesn't actually do anything itself
1 ;
2 ; RUN: true
3
4 !0 = metadata !{i32 41}
5 !llvm.stuff = !{!0}