summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Linker/LinkModules.cpp19
-rw-r--r--llvm/lib/VMCore/Metadata.cpp9
2 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 3aec864c2d0..ca0bf73002b 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -538,6 +538,22 @@ static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
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 @@ Linker::LinkModules(Module *Dest, Module *Src, std::string *ErrorMsg) {
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))
diff --git a/llvm/lib/VMCore/Metadata.cpp b/llvm/lib/VMCore/Metadata.cpp
index 3a61d0eefb7..4762a105550 100644
--- a/llvm/lib/VMCore/Metadata.cpp
+++ b/llvm/lib/VMCore/Metadata.cpp
@@ -104,6 +104,7 @@ MDNode::~MDNode() {
dropAllReferences();
getType()->getContext().pImpl->MDNodes.remove(this);
}
+
//===----------------------------------------------------------------------===//
//NamedMDNode implementation
//
@@ -123,6 +124,14 @@ NamedMDNode::NamedMDNode(const Twine &N, MetadataBase*const* MDs,
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() {
OpenPOWER on IntegriCloud