Implement module-independent data retrieval operations for LLVMNamedMDNodeRef #995
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'd like to expand the LLVM C API, more specifically the Modules/NamedMDNode API as it has a rather interesting way to retrieve data owned by a
LLVMNamedMDNodeRef
In the C++ API, all the data associated with a
llvm::NamedMDNode
is owned by the node itself so it would only make sense to pull said data from the node itself. For unknown? reasons [1], the C API requires the owning module of aLLVMNamedMDNodeRef
to retrieve the data. Looking closer at the implementation we can tell that we shouldn't need the module to retrieve parts of this data.The functions I have added in this patch have the same functionality as the ones present in the C API. The only difference is that we don't need to provide a module to look up a LLVMNamedMDNodeRef inside of, instead we provide the instance returned by
LLVMGetNamedMetadata
orLLVMGetOrInsertNamedMetadata
.[1]: I imagine it was designed this way because in the C++ API,
llvm::NamedMDNode
s may be detached and not associated with a Module so providing the owning module was the natural choice, but this is not possible to do through the C API alone which means we can do better.