[LLVMdev] PROPOSAL : Introduce NamedMetadata

Dan Gohman gohman at apple.com
Mon Jul 27 16:08:18 PDT 2009


On Jul 27, 2009, at 3:05 PM, Devang Patel wrote:


> On Mon, Jul 27, 2009 at 1:13 PM, Dan Gohman<gohman at apple.com> wrote:
>
>>
>>
>> On Jul 27, 2009, at 10:10 AM, Devang Patel wrote:
>>
>>
>>
>>
>>
>>> 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.
>>>
>>
>>
>> So, the idea is that some Analysis can take an LLVM IR entity, mangle
>>
>> information about that entity into a string, and then use that string
>>
>> to look up the associated NamedMetadata?
>>
>
> No. I think, I used confusing example.
>
> The idea is to provide a way to have metadata that is not directly
> used by any LLVM IR entity. Here the metadata entity can itself use
> any other LLVM IR entity. For example
>
> ; ModuleID = 'blah.c'
>
> !1 = { i32 459008, metadata !"blah.c", "b", i32 4, i32 6 }
> !2 = { i32 458804, metadata !"blah.c", "a", i32 4, i32 6, i32 %a }
> a = global i32 42
>
> define void @foo() {
>  call void @llvm.dbg.declare(!1)
> }
>
> ---
>
> Here !1 and !2 encodes debug info for a local variable 'b' and global
> variable 'a' respectively. !1 is one of the llvm.dbg.declare argument
> so it is seen any LLVM IR walker. However, !2 is "invisible" here.
>
> The proposal is to introduce
>
> @llvm.dbg.gvs = ![ !2 ]

I talked with Devang about this and we came up with this syntax:

!llvm.dbg.gvs = { !2 }

which is nicely analogous with the syntax for named vs. unnamed values,
and with having NamedMetadata inherit directly from Value, rather than
from GlobalValue, since the only thing it needs is a name, not all
the other stuff from User + Constant + GlobalValue.

Dan




More information about the llvm-dev mailing list