I am writing an optimization for my compiler and I use LLVM IR as my Intermediate Language. I have parsed the input file and converted it to LLVM IR. During optimization, I need to retrieve the operands of the instructions. I am able to find getOpCode() in the Instruction class, but unable to retrieve the operand list. How do I go about that?
I am writing an optimization for my compiler and I use LLVM IR as
Share
There are lots of operand accessors, usually provided by the class
llvm::User, whose doxygen page is: http://llvm.org/doxygen/classllvm_1_1User.html There’sgetNumOperands()andgetOperand(unsigned int), as well as iterator-style accessorsop_begin()andop_end().For example, given Instruction
%X = add i32 %a, 2,I->getOperand(0)will return theValue*for%a, andI->getOperand(1)will return theValue*fori32 2(castable to ConstantInt).