我是 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);
当我运行它时,我会得到一个错误:
error:no matching function for call to 'llvm::AllocaInst::AllocaInst(llvm::Type*&, NULL, int, std::string&, llvm::Instruction*)' AllocaInst* variable = new AllocaInst(A,NULL,4,name,&*inst);
我想知道如何在 AllcaInst 中提供地址位置。任何帮助将不胜感激。
最佳答案
你不能用这种方式初始化一个数组。您的代码的问题是数组大小。 AllocaInst
期望数组大小有一个 llvm::Value*
,即,大小必须存在于 IR 中。要获得常量 4,您必须使用 ConstantInt::get
在 IR 中创建常量整数值。 ConstantInt*
可以提供给 AllocaInst 构造函数。
关于c++ - AllocaInst 的使用示例 : LLVM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45799933/