Vedant Kumar via llvm-dev
2016-Mar-03 00:19 UTC
[llvm-dev] Should @llvm.used be a NamedMDNode?
Hi, Should @llvm.used be a NamedMDNode instead of a GlobalVariable? I think this would make it easier to mark globals as used. The current method involves (1) copying the existing elements of @llvm.used into a container, (2) erasing @llvm.used, (3) appending the new global to the container, (4) re-creating @llvm.used (thereby polluting the ConstantArray cache?), and (5) calling LLVMUsed->setSection("llvm.metadata"). See InstrProfiling::emitUses. If we use NamedMDNode, this could be as simple as: auto *LLVMUsed = M->getOrInsertNamedMetadata("llvm.used"); LLVMUsed->addOperand(ConstantAsMetadata::get(C)); I took a cursory look around and it doesn't seem like we really depend on @llvm.used being a GlobalVariable. Am I wrong about this? Other thoughts? thanks vedant
Vedant Kumar via llvm-dev
2016-Mar-03 00:23 UTC
[llvm-dev] Should @llvm.used be a NamedMDNode?
> On Mar 2, 2016, at 4:19 PM, Vedant Kumar <vsk at apple.com> wrote: > > Hi, > > Should @llvm.used be a NamedMDNode instead of a GlobalVariable? > > I think this would make it easier to mark globals as used. The current method > involves (1) copying the existing elements of @llvm.used into a container, (2) > erasing @llvm.used, (3) appending the new global to the container, (4) > re-creating @llvm.used (thereby polluting the ConstantArray cache?), and (5) > calling LLVMUsed->setSection("llvm.metadata"). See InstrProfiling::emitUses. > > If we use NamedMDNode, this could be as simple as: > > auto *LLVMUsed = M->getOrInsertNamedMetadata("llvm.used"); > LLVMUsed->addOperand(ConstantAsMetadata::get(C));Actually, the ConstantAsMetadata would have to be wrapped in an MDTuple, because Metadata doesn't inherit from MDNode. The point still stands. vedant> > I took a cursory look around and it doesn't seem like we really depend on > @llvm.used being a GlobalVariable. > > Am I wrong about this? Other thoughts? > > thanks > vedant
Chris Lattner via llvm-dev
2016-Mar-03 04:29 UTC
[llvm-dev] Should @llvm.used be a NamedMDNode?
> On Mar 2, 2016, at 4:19 PM, Vedant Kumar via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Hi, > > Should @llvm.used be a NamedMDNode instead of a GlobalVariable? > > I think this would make it easier to mark globals as used. The current method > involves (1) copying the existing elements of @llvm.used into a container, (2) > erasing @llvm.used, (3) appending the new global to the container, (4) > re-creating @llvm.used (thereby polluting the ConstantArray cache?), and (5) > calling LLVMUsed->setSection("llvm.metadata"). See InstrProfiling::emitUses. > > If we use NamedMDNode, this could be as simple as: > > auto *LLVMUsed = M->getOrInsertNamedMetadata("llvm.used"); > LLVMUsed->addOperand(ConstantAsMetadata::get(C)); > > I took a cursory look around and it doesn't seem like we really depend on > @llvm.used being a GlobalVariable. > > Am I wrong about this? Other thoughts?I’m not sure that this will work. One of the reasons that it is a global variable is that we *want* the global variable to show up in the uselist for the “used” value (and thus appear to be used in an “unknown” way and treated conservatively). Metadata aren’t typically in the use list for a value. -Chris