【问题标题】:Usage of AllocaInst with example: LLVMAllocaInst 的用法与示例:LLVM
【发布时间】:2017-08-21 14:41:12
【问题描述】:

我是 LLVM 的新手,我想通过示例了解 AllocaInst 的正确用法。我尝试在线搜索,甚至 llvm 网页也没有正确的示例。 下面是我正在尝试执行的代码补丁。

string temp =(dyn_cast<ConstantInt>operand0))->getValue()).toString(10,true);
Type* A = IntegerType::getInt32Ty(F.getContext());
string name = "t"+to_string(++counter);
AllocaInst* variable = new AllocaInst(A,NULL,4,name,&*inst);

当我运行这个时,我会得到一个错误:

错误:没有匹配函数调用 'llvm::AllocaInst::AllocaInst(llvm::Type*&, NULL, int, std::string&, llvm::Instruction*)' AllocaInst* 变量 = 新 AllocaInst(A,NULL,4,name,&*inst);

我想知道如何在 AllcaInst 中提供地址位置。任何帮助将不胜感激。

【问题讨论】:

  • 您的 LLVM C++ 库版本是否与您使用的 C++ 标头同步?
  • “4”是干什么用的?
  • 这是数组大小。 LLVM C++ 和 C++ 标头同步

标签: c++ llvm llvm-clang llvm-ir


【解决方案1】:

您不能以这种方式初始化数组。您的代码的问题是数组大小。 AllocaInst 期望数组大小为 llvm::Value*,即大小必须存在于 IR 中。要获得常量 4,您必须使用 ConstantInt::get 在 IR 中创建一个常量整数值。 ConstantInt* 可以提供给 AllocaInst 构造函数。

【讨论】:

    猜你喜欢
    • 2022-07-21
    • 1970-01-01
    • 1970-01-01
    • 2020-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多