[LLVMdev] LLVM Instruction*->getOperand() not working properly for ICMP

Krzysztof Parzyszek kparzysz at codeaurora.org
Fri Jan 11 06:33:58 PST 2013

On 1/11/2013 5:50 AM, Alexandru Ionut Diaconescu wrote:
> Hi Óscar,
> But if I do "I1->getOperand(0)->getOperand(0)" I get " ‘class
> llvm::Value’ has no member named ‘getOperand’ ". getOperand() I think
> it's only defined for Instruction class. Do you know any equivalent
> method for Value?

Value is a base superclass, from which a lot of other classes are 
derived.  Among the derived classes are User and Instruction (which 
itself is derived from User).  If I remember correctly, the class User 
adds "getOperand".  In your case, the simplest thing to do would be to 
down-cast the Value to Instruction, and if the cast returns non-zero, 
then you have a valur of type Instruction, for which you can use 
getOperand.  For example:

   Value *V = ...
   if (Instruction *In = dyn_cast<Instruction>(V)) {
     // Now have Instruction, can use getOperand:
     ... = In->getOperand(i);


Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation

More information about the llvm-dev mailing list