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

There are 1 answers

0
Ismail Badawi On BEST ANSWER

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.