LLVM gets the operand and lvalue value of the instruction

For the LLVM IR instruction, for example %cmp7 = icmp eq i32 %6 %7, I want to get all three case / character names (i.e. %cmp %6 and %7)

Now I can get the line with the %cmpcommand pi->getName(), where pi is the instruction pointer. But when I try to get the oprand names, I got an empty string by typing pi->getOperand(0)->getName().

I tried to isa<Instruction>(pi->getOperand(0))check if this is an instruction, and it returned true, but pi->getOperand(0)->hasName()returns false. Things make me feel weird, why the two piand pi->getOperand(0)are instructions, but only pihas a name?

Are there any thoughts, I can get the name of the operand (the string %6and %7here) using the API?

The LLVM version I'm using is 3.4.2

+4
source share
1 answer

Names are optional for LLVM instructions, and in fact the two operands of your command icmpin this case do not have a name, therefore, an empty string.

When you print the LLVM module into a .ll file, the writer allocates a name %<num>for each command to make it accessible to the person, but this is only what the writer does during printing, this line does not exist in the actual module.

+5
source

Source: https://habr.com/ru/post/1546164/


All Articles