问题
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