In LLVM IR, how can I print the name of a unnamed

2019-08-09 09:36发布

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条回答
Viruses.
2楼-- · 2019-08-09 10:19

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.

查看更多
登录 后发表回答