Is there any way to update llvm metadata?

For example, I need to change the baseType of a DIDerivedType metadata through my pass:

!147 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !148, size: 64)

What functions can be used to do this? It would be best if there were code cases.

I am not sure if you want to update an existing node, as this may impact other users of the node.

You should be able to create a new DIDerivedType node with updated data. Unused metadata nodes will be cleaned up automatically.

See LLVM: llvm::DIBuilder Class Reference for a helper to build metadata.

Thanks for your reply. I originally wanted to directly update the metadata information of the existing node, but I couldn’t find the relevant function. Now I intend to extract the information in metadata into the JSON object, and then update the type information in JSON.