Embedded Metadata phase2
From LLVM
Now that we have value handles, we can consider how to store metadata which keeps references to non-Constant Values.
Proposed steps:
- Create a new
metadatatype distinct from{}. Make metadata use it exclusively and check it like the parser currently does forvoid. - An MDNode may take any number of WeakVHs. These may reference any global or instruction in the function where they're used.
- we need to be able to serialize WeakVHs. Constants are easy, but an MDNode could also reference values inside different functions. I propose a syntax of "
@functionname/%tmp". - the WeakVH will follow the value through RAUW. To maintain MDNode uniqueness, we'll need to check whether this node is now equivalent to one that already exists and RAUW ourselves. This suggests that users of metadata will want to keep a WeakVH themselves.
- on deletion, we remove the value from the MDNode. Consider this use case:
@llvm.noalias = metadata { i8* @f/%x, i8* @f/%y, i8* @f/%z }- when we discover that
@f/%zis only computed in a dead basic block, it is deleted and the metadata becomes: @llvm.noalias = metadata { i8* @f/%x, i8* @f/%y }- In the event that what you really wanted was to delete the metadata entirely, just add an initial "size" entry that indicates how many entries are supposed to be there. If it doesn't match, you know the data is no longer valid.
- we need to be able to serialize WeakVHs. Constants are easy, but an MDNode could also reference values inside different functions. I propose a syntax of "

