LLVM IR:获取调用点的 return 值

LLVM IR: get the return value of the callsite

这是一个关于分析 LLVM IR 的快速问题。所以基本上我正在尝试获取 LLVM IR 函数调用语句的 return 值,如下所示:

%47  =   call i256 @test(i256 %46)

我想获得访问权限 %47

这是我用来访问参数的代码。

      else if (funcName.contains("test")) {
        Value *op = CI->getOperand(0);
        if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(op))
          // get the first function parameter
          op = GEP->getPointerOperand();
      }

非常令人惊讶的发现是我在文档中找不到类似 "get return value" 的东西:http://llvm.org/doxygen/classllvm_1_1CallInst.html

任何人都可以在这里阐明一些问题吗?非常感谢。

CIcall指令)它的return值。它具有继承 Value.

的类型

如果你想做 1 + %47,举个例子,你可以像这样进行加法:Value * Add = BinaryOperation::Create(Instruction::Add, CI, ConstantInt::get(i256, 1), ...); 加法指令反过来就是它的结果,Add->getType() == i256因为它是两个类型都为 i256.

的值的总和

作为不同的答案,如果您需要“return 值”名称的字符串,您可以在 Instruction 对象上使用 inst.getName()inst.getNameOrAsOperand(),这是从 Value class.

派生的