LLVM 中的 CallInst::Create() return 是什么?

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

正在考虑

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

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

例如,在下面的代码中,

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

CallInst *ptr 是 return 值。抽象地讲,ptr是否意味着

  1. 一个整数值 return由 int foo(int) 编辑;
  2. 或CALL指令

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

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

为了说明,请看这个 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 'value'.

inst 被 return 编辑为 writeln 的参数表达式的计算。