Search code examples
c++compiler-constructionllvmoperands

Source and Destination Operands - LLVM Instruction


I know that I can use the following code to loop through the operands of an instruction:

    unsigned i = 0;
    unsigned e = I ->getNumOperands();
    while(i != e) {
        Value *operand = I->getOperand(i);
        i++;
    }

but how do I differentiate between source operands and destination operands?


Solution

  • The destination is not an operand. The instruction represents the result.

    The instruction list returned by your loop will give you the arguments from left to right, but the instruction is the result.

    So, if the instruction is

    %X = add i32 %a, 2, I->getOperand(0) will return the Value* for %a, and I->getOperand(1) will return the Value* for i32

    However, the instruction (add) is the result ==> %X.