[llvm-dev] Should @llvm.used be a NamedMDNode?

Vedant Kumar via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 2 16:19:05 PST 2016


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


More information about the llvm-dev mailing list