[LLVMdev] PROPOSAL : Introduce NamedMetadata

Devang Patel devang.patel at gmail.com
Mon Jul 27 10:10:07 PDT 2009


In LLVM IR metadata is used to attach auxiliary information with
various IR constructs. Currently metadata information is represented
using MDNode and MDString. The metadata can refer to LLVM values but
these references are not counted as regular "uses" of these values
because metadata is maintained 'on the side'. This ensures that the
optimizer is not influenced by auxiliary information. For example,

!1 = { i32 42 }

define void @foo() {
  %x = call i8 @llvm.something(metadata !1)
 }


See http://nondot.org/~sabre/LLVMNotes/EmbeddedMetadata.txt for more
information.

This metadata support is not useful if the auxiliary information is
not referenced by any LLVM IR entity.  This is a limiting factor. The
proposed solution is to introduced NamedMetadata. The NamedMetadata is
derived from GlobalValue. The NamedMetadata is an array of metadata
nodes and metadata strings.

	@class.42 = ![ !5, !11, !2 ] ; NamedMetadata

	!5 = metadata !"int"
	!11 = metadata !"class.21 pointer"
	!2 = metadata ! {I32 8 } ; size


The NamedMetadata element list contains MDString and MDNodes only. The
NamedMetadata is always implicitly typed as metadata. LLVM bitcode
reader and writer will keep track of NamedMetadata in a Module. A
module can use metadata that is not listed in any NamedMetadata value.
 A module can have multiple NamedMetadata values. NamedMetadata
implicitly uses AppendingLinkage. A  NamedMetadata value has zero
uses.

The NamedMetadata can be used to describe Front End specific types for
the optimizer's use. Another potential use is to encode debug
information for a global variable.  I do not intend to make @llvm.used
a NamedMetadata value.

-
Devang



More information about the llvm-dev mailing list