c – 替换LLVM指令的操作数

在下面的代码中,我尝试替换LLVM指令的操作数.但它不起作用,没有任何改变.不知道怎么解决这个问题?

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;
    }
}

解决方法:

您应该使用迭代器OI来替换它,而不是使用本地指针val.所以它应该是这样的.

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;
    }
}
上一篇:linux编译 llvm 7.1.0 + clang


下一篇:[ZZ] A Proposal For Compiling Direct3D HLSL With LLVM (Written by Michael Larabel )