值* 到指令*/LoadInst* 转换

Ale*_*lex 1 llvm

你能告诉我是否可以在 LLVM 中将 a 转换Value*Instruction*/LoadInst*if 例如isa<LoadInst>(MyValue)为 true 吗?在我的特定代码中:

\n\n
Value* V1 = icmpInstrArray[i]->getOperand(0);\nValue* V2 = icmpInstrArray[i]->getOperand(1);\nif (isa<LoadInst>(V1) || isa<LoadInst>(V2)){\n...\nif(isa<LoadInst>(icmpInstrArray[i]->getOperand(0)))\n    LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0));\n        Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION ERROR\n
Run Code Online (Sandbox Code Playgroud)\n\n

此外,我只需要做C100->getName()即可获得加载的变量。

\n\n

编译错误是:error: \xe2\x80\x98LD100\xe2\x80\x99 was not declared in this scope.

\n\n

我不认为我可以那样使用强制转换。你能告诉我一种从与我的ICMP指令相对应的Load指令中获取加载变量的方法吗?或者更好的是我如何从中提取加载指令icmpInstrArray[i]->getOperand(0)

\n

Nik*_*s R 5

您缺少 if 语句周围的大括号。您的代码当前等于:

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

LD100未在 if 语句范围之外定义。这会起作用:

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