如何使用C ++ API将元数据附加到LLVM IR? [英] How to attach metadata to LLVM IR using the C++ API?

查看:99
本文介绍了如何使用C ++ API将元数据附加到LLVM IR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以指出使用C ++ API将元数据附加到llvm-ir的具体示例吗?

Can anyone point me to a concrete example of attaching metadata to llvm-ir using the c++ api?

我已阅读此页面 http://llvm.org/docs/SourceLevelDebugging.html.

谢谢

推荐答案

以上答案不太正确(或不完整).您还可以仅使用MDNode :: get(...)在模块级别创建元数据,该MDNode :: get(...)会使用上下文和值数组来从中创建元数据.命名的元数据非常重要,您仅应将其用作顶级元数据值的锚点.

The above answer is not quite correct (or complete). You can also create metadata at the module level with just MDNode::get(...) which takes a context and an array of values to create metadata from. Named metadata is very heavyweight and you should only use it as an anchor for top level metadata values.

要附加到指令,您确实想在指令上使用setMetadata调用来设置任何特定的元数据,但是,您需要确保使用正确的上下文-否则,您可能会覆盖其他元数据.

For attaching to instructions you do want to use the setMetadata call on the Instruction to set any particular metadata, however, you'll want to make sure you're using the correct context - otherwise you could overwrite other metadata.

这篇关于如何使用C ++ API将元数据附加到LLVM IR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆