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?

☆樱花仙子☆ 提交于 2019-12-11 10:37:57

问题


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*

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/30732839/in-llvm-ir-how-can-i-print-the-name-of-a-unnamed-value-which-is-represented-as

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