【发布时间】:2014-05-27 12:00:12
【问题描述】:
我有一些 LLVM 代码我想引用一个现有的变量。我将使用 JIT 并在我的流程中执行此代码,因此我希望该函数直接引用我现在拥有的变量。
例如,
int64_t begin, end;
auto&& con = g.module->getContext();
std::vector<llvm::Type*> types = { llvm::Type::getInt64PtrTy(con), llvm::Type::getInt64PtrTy(con) };
auto tramp = llvm::Function::Create(llvm::FunctionType::get(llvm::Type::getVoidTy(con), types, false), llvm::GlobalValue::LinkageTypes::ExternalLinkage, "", g.module.get());
auto bb = llvm::BasicBlock::Create(con, "entry", tramp);
auto builder = llvm::IRBuilder<>(bb);
auto call = builder.CreateCall(g.module->getFunction(failfunc->GetName()));
builder.CreateStore(builder.CreateExtractValue(call, { tupty->GetFieldIndex(1) }), &begin);
builder.CreateStore(builder.CreateExtractValue(call, { tupty->GetFieldIndex(2) }), &end);
builder.CreateRetVoid();
显然我不能在这里直接传递 &begin 和 &end 因为它们不是llvm::Values。但是如何创建一个直接指向它们的 LLVM 指针值,我可以将它们传递给CreateStore?
【问题讨论】: