How do I create named metadata via the llvm-c api?

╄→гoц情女王★ 提交于 2019-12-22 07:58:40

问题


I want to add debug metadata to my generated llvm IR, which is created via the C API. However, I can't figure out how to create named metadata nodes (such as !llvm.dbg.cu), or even how to create metadata nodes with unique numbers (ie. !0, !1, etc.). Adding metadata operands to instructions looks pretty simple, but I cannot figure out how to create standalone metadata nodes.


回答1:


As at LLVM 3.0, there is no function exposed in the C API for creating or modifying named metadata. A new function (LLVMAddNamedMetadataOperand) was recently added to the API, after the 3.0 release.

If you're comfortable building LLVM from source, you can get this support from the trunk. See the Getting Started page on how to build LLVM. Otherwise you'll have to wait until LLVM 3.1 is released.

When the function is available, it'll be a simple matter of calling:

LLVMAddNamedMetadataOperand(module, "named_md_name", mdnode);

If there is no named metadata with the name "named_md_name", then one will be created. Otherwise the existing object will be updated.



来源:https://stackoverflow.com/questions/7998367/how-do-i-create-named-metadata-via-the-llvm-c-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!