【问题标题】:What does CallInst::Create() return in LLVM?CallInst::Create() 在 LLVM 中返回什么?
【发布时间】:2016-02-12 07:07:12
【问题描述】:

考虑

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. 或CALL指令

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

【问题讨论】:

    标签: c++ llvm instrumentation


    【解决方案1】:

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

    举个例子,用这个小帕斯卡程序:

    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 参数的表达式的评估。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-14
      • 1970-01-01
      • 2016-12-08
      • 1970-01-01
      • 2021-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多