[llvm-commits] [llvm] r78696 - in /llvm/trunk: include/llvm/Metadata.h lib/Linker/LinkModules.cpp lib/VMCore/Metadata.cpp test/Linker/linknamedmdnode.ll test/Linker/linknamedmdnode2.ll
Devang Patel
dpatel at apple.com
Tue Aug 11 11:01:24 PDT 2009
Author: dpatel
Date: Tue Aug 11 13:01:24 2009
New Revision: 78696
URL: http://llvm.org/viewvc/llvm-project?rev=78696&view=rev
Log:
Link NamedMDNodes.
Added:
llvm/trunk/test/Linker/linknamedmdnode.ll
llvm/trunk/test/Linker/linknamedmdnode2.ll
Modified:
llvm/trunk/include/llvm/Metadata.h
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/lib/VMCore/Metadata.cpp
Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=78696&r1=78695&r2=78696&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Tue Aug 11 13:01:24 2009
@@ -229,6 +229,8 @@
return new NamedMDNode(N, MDs, NumMDs, M);
}
+ static NamedMDNode *Create(const NamedMDNode *NMD, Module *M = 0);
+
/// eraseFromParent - Drop all references and remove the node from parent
/// module.
void eraseFromParent();
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=78696&r1=78695&r2=78696&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Tue Aug 11 13:01:24 2009
@@ -538,6 +538,22 @@
return false;
}
+// Insert all of the named mdnoes in Src into the Dest module.
+static void LinkNamedMDNodes(Module *Dest, Module *Src) {
+ for (Module::const_named_metadata_iterator I = Src->named_metadata_begin(),
+ E = Src->named_metadata_end(); I != E; ++I) {
+ const NamedMDNode *SrcNMD = I;
+ NamedMDNode *DestNMD = Dest->getNamedMetadata(SrcNMD->getName());
+ if (!DestNMD)
+ NamedMDNode::Create(SrcNMD, Dest);
+ else {
+ // Add Src elements into Dest node.
+ for (unsigned i = 0, e = SrcNMD->getNumElements(); i != e; ++i)
+ DestNMD->addElement(SrcNMD->getElement(i));
+ }
+ }
+}
+
// LinkGlobals - Loop through the global variables in the src module and merge
// them into the dest module.
static bool LinkGlobals(Module *Dest, const Module *Src,
@@ -1307,6 +1323,9 @@
AppendingVars.insert(std::make_pair(I->getName(), I));
}
+ // Insert all of the named mdnoes in Src into the Dest module.
+ LinkNamedMDNodes(Dest, Src);
+
// Insert all of the globals in src into the Dest module... without linking
// initializers (which could refer to functions not yet mapped over).
if (LinkGlobals(Dest, Src, ValueMap, AppendingVars, ErrorMsg))
Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=78696&r1=78695&r2=78696&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Tue Aug 11 13:01:24 2009
@@ -104,6 +104,7 @@
dropAllReferences();
getType()->getContext().pImpl->MDNodes.remove(this);
}
+
//===----------------------------------------------------------------------===//
//NamedMDNode implementation
//
@@ -123,6 +124,14 @@
ParentModule->getNamedMDList().push_back(this);
}
+NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) {
+ assert (NMD && "Invalid source NamedMDNode!");
+ SmallVector<MetadataBase *, 4> Elems;
+ for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i)
+ Elems.push_back(NMD->getElement(i));
+ return new NamedMDNode(NMD->getName().data(), Elems.data(), Elems.size(), M);
+}
+
/// eraseFromParent - Drop all references and remove the node from parent
/// module.
void NamedMDNode::eraseFromParent() {
Added: llvm/trunk/test/Linker/linknamedmdnode.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/linknamedmdnode.ll?rev=78696&view=auto
==============================================================================
--- llvm/trunk/test/Linker/linknamedmdnode.ll (added)
+++ llvm/trunk/test/Linker/linknamedmdnode.ll Tue Aug 11 13:01:24 2009
@@ -0,0 +1,6 @@
+; RUN: llvm-as < %s > %t.bc
+; RUN: llvm-as < %p/linknamedmdnode2.ll > %t2.bc
+; RUN: llvm-link %t.bc %t2.bc | llvm-dis | grep "!llvm.stuff = !{!0, !1}"
+
+!0 = metadata !{i32 42}
+!llvm.stuff = !{!0}
Added: llvm/trunk/test/Linker/linknamedmdnode2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/linknamedmdnode2.ll?rev=78696&view=auto
==============================================================================
--- llvm/trunk/test/Linker/linknamedmdnode2.ll (added)
+++ llvm/trunk/test/Linker/linknamedmdnode2.ll Tue Aug 11 13:01:24 2009
@@ -0,0 +1,6 @@
+; This file is used by linknamedmdnode.ll, so it doesn't actually do anything itself
+;
+; RUN: true
+
+!0 = metadata !{i32 41}
+!llvm.stuff = !{!0}
More information about the llvm-commits
mailing list