From 0e361fbeb329cb0f8e56e2d7f1b8b70512d92875 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 11 Aug 2009 18:01:24 +0000 Subject: Link NamedMDNodes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78696 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/Linker/LinkModules.cpp') diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 3aec864..ca0bf73 100644 --- a/lib/Linker/LinkModules.cpp +++ b/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)) -- cgit v1.1