[llvm-dev] Should @llvm.used be a NamedMDNode?
Chris Lattner via llvm-dev
llvm-dev at lists.llvm.org
Wed Mar 2 20:29:51 PST 2016
> 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
More information about the llvm-dev
mailing list