我是 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);
当我运行它时,我会得到一个错误:
我想知道如何在AllcaInst中提供地址位置。任何帮助,将不胜感激。
最佳答案
您不能以这种方式初始化数组。您的代码的问题是数组的大小。 AllocaInst
需要数组大小的llvm::Value*
,即该大小必须存在于IR中。要获得常数4,您必须使用ConstantInt::get
在IR中创建常数整数值。可以将ConstantInt*
提供给AllocaInst构造函数。