mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-10-31 08:16:47 +00:00 
			
		
		
		
	Link NamedMDNodes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78696 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		| @@ -229,6 +229,8 @@ public: | |||||||
|     return new NamedMDNode(N, MDs, NumMDs, M); |     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 |   /// eraseFromParent - Drop all references and remove the node from parent | ||||||
|   /// module. |   /// module. | ||||||
|   void eraseFromParent(); |   void eraseFromParent(); | ||||||
|   | |||||||
| @@ -538,6 +538,22 @@ static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src, | |||||||
|   return false; |   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 | // LinkGlobals - Loop through the global variables in the src module and merge | ||||||
| // them into the dest module. | // them into the dest module. | ||||||
| static bool LinkGlobals(Module *Dest, const Module *Src, | 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)); |       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 |   // Insert all of the globals in src into the Dest module... without linking | ||||||
|   // initializers (which could refer to functions not yet mapped over). |   // initializers (which could refer to functions not yet mapped over). | ||||||
|   if (LinkGlobals(Dest, Src, ValueMap, AppendingVars, ErrorMsg)) |   if (LinkGlobals(Dest, Src, ValueMap, AppendingVars, ErrorMsg)) | ||||||
|   | |||||||
| @@ -104,6 +104,7 @@ MDNode::~MDNode() { | |||||||
|   dropAllReferences(); |   dropAllReferences(); | ||||||
|   getType()->getContext().pImpl->MDNodes.remove(this); |   getType()->getContext().pImpl->MDNodes.remove(this); | ||||||
| } | } | ||||||
|  |  | ||||||
| //===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||||
| //NamedMDNode implementation | //NamedMDNode implementation | ||||||
| // | // | ||||||
| @@ -123,6 +124,14 @@ NamedMDNode::NamedMDNode(const Twine &N, MetadataBase*const* MDs, | |||||||
|     ParentModule->getNamedMDList().push_back(this); |     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 | /// eraseFromParent - Drop all references and remove the node from parent | ||||||
| /// module. | /// module. | ||||||
| void NamedMDNode::eraseFromParent() { | void NamedMDNode::eraseFromParent() { | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								test/Linker/linknamedmdnode.ll
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								test/Linker/linknamedmdnode.ll
									
									
									
									
									
										Normal file
									
								
							| @@ -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} | ||||||
							
								
								
									
										6
									
								
								test/Linker/linknamedmdnode2.ll
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								test/Linker/linknamedmdnode2.ll
									
									
									
									
									
										Normal file
									
								
							| @@ -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} | ||||||
		Reference in New Issue
	
	Block a user