CallInst::Create() 在 LLVM 中返回什么

What does CallInst::Create() return in LLVM?

本文关键字:返回 什么 LLVM Create CallInst      更新时间:2023-10-16

正在考虑

static CallInst *Create(Value *Func,
                      ArrayRef<Value *> Args,
                      const Twine &NameStr = "",
                      Instruction *InsertBefore = 0)
这个函数

,我想知道这个函数的返回值是什么意思。

例如,在下面的代码中,

int foo(int a);
...
Function *foo_ptr = ~~;//say, foo is refered through getOrInsertFunction()
CallInst *ptr = CallInst::Create(foo_ptr, .../* properly set */);

CallInst *ptr 是返回值。抽象地说,ptr是否意味着

  1. 由 int foo(int( 返回的整数值;
  2. 或呼叫指令

我以为数字 2 是答案,但看着一些代码开始感到困惑。

1 和 2 都是"true"。它返回调用指令,当我们执行代码时,其"值"将是函数的返回值。

为了说明这一点,请以这个小的Pascal程序为例:

program p;
function f: integer;
begin
   f := 42;
end; { f }
begin
   writeln(f);
end.

这转化为这个LLVM-IR:

; ModuleID = 'TheModule'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%text = type { i32, i8*, i32, i32 }
@input = global %text zeroinitializer, align 8
@output = global %text zeroinitializer, align 8
@UnitIniList = constant [1 x i8*] zeroinitializer
define i32 @P.f() #0 {
entry:
  %f = alloca i32, align 4
  store i32 42, i32* %f
  %0 = load i32, i32* %f
  ret i32 %0
}
define void @__PascalMain() #0 {
entry:
  %calltmp = call i32 @P.f()
  call void @__write_int(%text* @output, i32 %calltmp, i32 0)
  call void @__write_nl(%text* @output)
  ret void
}
declare void @__write_int(%text*, i32, i32)
declare void @__write_nl(%text*)
attributes #0 = { "no-frame-pointer-elim"="true" }

call i32 @P.f()由以下人员生成:

inst = builder.CreateCall(calleF, argsV, "calltmp");

inst的内容是%calltmp = call i32 @P.f()的——这是一个CallInst"价值"。

并且inst返回到表达式的计算中,以便参数writeln