[LLVMdev] LLVM Instruction*->getOperand() not working properly for ICMP
ofv at wanadoo.es
Fri Jan 11 03:07:52 PST 2013
Alexandru Ionut Diaconescu <alexandruionutdiaconescu at gmail.com> writes:
> But I have another problem: Do you know how can I iterate through a Value*?
> For instance, I have :
> Instruction *I1; // I take only I1 that are ICmp
> errs()<<"\n "<<*I1->getOperand(0)<<" \n";
> // %3 = load i32* %c, align 4
> As expected. Now I want to get %c from the previous to use "%c" in
> comparisons. I tried :
> for (llvm::Value::use_iterator VI=(*I1->getOperand(0)).use_begin(),
> VE=(*I1->getOperand(0)).use_end(); VI != VE ; ++VI)
> errs()<<"\n "<<**VI<<" \n";
> // %cmp3 = icmp ne i32 %3, 0
> Not as expected. It is printing the I1 instruction.
> Do you know how I can get %c from the "load instruction"?
In this case, you get %c starting from I1 this way:
because "%3 = load i32* %c, align 4" (or %3, for short) is the first
operand of I1, and %c is the first operand of %3.
Please note that some Instructions are Values too. This is the case for
the Instruction `load'.
More information about the llvm-dev