For a LLVM IR instruction like %cmp7 = icmp eq i32 %6 %7
I want to get all three register/symbol names (i.e. %cmp %6 and %7
)
Now I can get string %cmp
by command pi->getName()
where pi is Instruction pointer. But when I try to get oprand names I got empty string by typing pi->getOperand(0)->getName()
.
I tried isa<Instruction>(pi->getOperand(0))
to check whether this is an instruction and it returned true but pi->getOperand(0)->hasName()
returned false. Things make me feeling strange is that why both pi
and pi->getOperand(0)
are instructions but only pi
has name?
Is there any thoughts I can get operand name (string %6
and %7
here)by using API?
LLVM version I'm using is 3.4.2
Names are optional for LLVM instructions, and indeed the two operands of your icmp
instruction in this case don't have a name, hence the empty string.
When you print an LLVM module to an .ll file then the writer allocates a %<num>
name for each instruction to make it human-readable, but this is only something the writer does during printing, that string does not exist in the actual module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With