在LLVM IR中,如何打印一个未命名的值的名称,它用前缀(如%2)表示为无符号数值? [英] In LLVM IR, how can I print the name of a unnamed value which is represented as an unsigned numeric value with their prefix such as %2?

查看:647
本文介绍了在LLVM IR中,如何打印一个未命名的值的名称,它用前缀(如%2)表示为无符号数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印出LLVM IR(为实践)编写的指令,我有一个BitCastInst像这样:
%0 = bitcast [32xi32] *%reg到i8 * / code>

I want to print out the instructions written in LLVM IR( for practice ) and I have a BitCastInst like this: %0 = bitcast [32xi32]* %reg to i8*

如何打印左值的名称,即未命名的值%0 在这种情况下?

How can I print its name of left value which is a unnamed value %0 in this case?

推荐答案

这些名称并不真正存在于IR的内存中表示,只是使用指针引用其他值。计算名称,并将其添加到正在写出的文本形式。这是有意义的,因为转换不断地操作IR,并且每当一个指令被插入某处时,必须去更新所有的名称是昂贵的。

Those names don't really exist in the in-memory representation of the IR -- there, values just refer to other values using pointers. The names are computed and added to the textual form as it's being written out. This makes sense since transforms are constantly manipulating the IR and it would be expensive to have to go and update all the names whenever an instruction is inserted somewhere.

你可以看看 AsmWriter 的来源验证此 - 增加的数字由 SlotTracker 这里这里是打印出一条指令行在IR中的代码,使用名称如果它存在或插槽号,如果不是

You can look at the source for the AsmWriter to verify this -- the incrementing numbers are assigned by the SlotTracker here, and here's the code that that prints out an instruction line in the IR, using the name if it's present or the slot number if not.

这篇关于在LLVM IR中,如何打印一个未命名的值的名称,它用前缀(如%2)表示为无符号数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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