Replacing the operand of an LLVM instruction

c++, compiler-construction, llvm

Solution

You should use the iterator `OI` to replace it, instead of the local pointer `val`. So it should be like this.

for (OI = insn->op_begin(), OE = insn->op_end(); OI != OE; ++OI)
{
    Value *val = *OI;
    iter = mapClonedAndOrg.find( val );

    if( iter != mapClonedAndOrg.end( ) )
    {
        *OI = (Value*)iter->second.PN;
    }
}

Problem

In the following code, I try to replace operand(s) of an LLVM instructions. However it doesn't work and nothing is changed. Any idea how to solve this? ``` for (OI = insn->op_begin(), OE = insn->op_end(); OI != OE; ++OI) { Value *val = *OI; iter = mapClonedAndOrg.find( val ); if( iter != mapClonedAndOrg.end( ) ) { // Here I try to replace the operand, to no effect! val = (Value*)iter->second.PN; } } ```

Original source