Value* to Instruction*/LoadInst* casting [closed]

柔情痞子 提交于 2019-12-23 04:37:14

问题


Can you please tell me if it is possible in LLVM to cast a Value* to an Instruction*/LoadInst* if for example isa<LoadInst>(MyValue) is true? In my particular piece of code:

Value* V1 = icmpInstrArray[i]->getOperand(0);
Value* V2 = icmpInstrArray[i]->getOperand(1);
if (isa<LoadInst>(V1) || isa<LoadInst>(V2)){
...
if(isa<LoadInst>(icmpInstrArray[i]->getOperand(0)))
    LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0));
        Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION ERROR

Further, I just need to make C100->getName() and I will get the loaded variable.

The compilation error is : error: ‘LD100’ was not declared in this scope.

I don't think that I can use cast like that. Can you tell me a method to obtain the loaded variable from a Load instruction correspondent to my ICMP instructions? Or better how I can extract the Load instruction from icmpInstrArray[i]->getOperand(0)?


回答1:


You are missing the braces around the if-statement. Your code is currently equal to this:

if(isa<LoadInst>(icmpInstrArray[i]->getOperand(0))) {
    LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0));
}
Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION ERROR

LD100 is not defined outside the if-statements scope. This would work:

if(isa<LoadInst>(icmpInstrArray[i]->getOperand(0))) {
    LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0));
    Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION ERROR
}


来源:https://stackoverflow.com/questions/14560027/value-to-instruction-loadinst-casting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!