[LLVMdev] [RFC] Separating Metadata from the Value hierarchy

Duncan P. N. Exon Smith dexonsmith at apple.com
Thu Nov 13 14:01:29 PST 2014


> On 2014-Nov-13, at 13:34, Philip Reames <listmail at philipreames.com> wrote:
> 
>> New syntax
>> ----------
>> 
>> Types only make sense when an operand can be an `llvm::Value`.  Let's
>> remove them where they don't make sense.
> Hm, how does this interact with range metadata?  Currently, the type of the values making up the range have to match the instruction they're attached to.  This seems like it could be a change in behaviour.  Thinking about it, it doesn't seem like a bad change, but it is a change.  Are there other cases like this?

I don't think there's any change there actually, just new syntax.  Range
metadata refers to `ConstantInt`s, which are `Value`s, which have `Type`s.

Eventually, I expect we'll build custom metadata types for constants that
eschew the `Value` hierarchy entirely, as Chris suggested here:

> I think that ValueAsMetadata is a great thing to have - it is essential to refer to global variables etc.  That said, I think that it will eventually be worthwhile to have metadata versions of integers and other common things to reduce memory.  This should come in a later pass of course.


The assembly syntax gets a little more verbose for values:

    define void @foo() {
      %val = i32 ...., !range !5
    }
    !5 = metadata !{value i32 0, value i32 8}

But we still have the `i32` type.

This is just like the first example...

>> 
>> I propose the following syntax for the above examples, using a new
>> keyword, `value`:
>> 
>>  1. Operands of `MDNode`.  Drop `metadata`, since metadata doesn't have
>>     types.  Use `value` to indicate a wrapped `llvm::Value`.
>> 
>>         !0 = !{!"string", !1, value i32* @global)

... here, with `value i32* @global`.

>> 
>>  2. Operands of `NamedMDNode`.  Drop `metadata`, since metadata doesn't
>>     have types.
>> 
>>         !named = !{!0, !1}
>> 
>>  3. Attachments to instructions.  No change!
>> 
>>         %inst = load i32* @global, !dbg !0
>> 
>>  4. Arguments to intrinsics.  Keep `metadata`, since here it's wrapped
>>     into an `llvm::Value` (which has a type).  Use `value` to indicate a
>>     metadata-wrapped value.
>> 
>>         call void @llvm.dbg(metadata value i32 %inst, metadata !0)
>> 
>>     Notice that the first argument doesn't use an `MDNode` anymore.
>> 





More information about the llvm-dev mailing list