【发布时间】:2016-02-16 19:45:33
【问题描述】:
我想写一些代码,给定一个 LLVM 函数 F,在同一个模块中创建一个精确的副本(以便以后可以在保留原始副本的同时对副本进行操作)。我想用 CloneFunctionInto 方法做到这一点。
我当前的尝试涉及尝试将每个(新 arg,旧 arg)对插入 VMap。以前我尝试过插入一个未初始化的 VMap 并将这对反过来。令人印象深刻的是,所有 3 个都导致了完全相同的错误消息:
断言 `VMap.count(&I) && "No mapping from source argument specified!"' 失败。
//F and S are defined higher up in the code
FunctionType *FType = F->getFunctionType();
Function *new_F = cast<Function>(M->getOrInsertFunction(S,FType));
std::vector<Type*> ArgTypes;
ValueToValueMapTy VMap;
Function::arg_iterator old_args = F->arg_begin();
for (Function::arg_iterator new_args = new_F->arg_begin(), new_args_end = new_F->arg_end();new_args != new_args_end; new_args++) {
std::pair<Value*,Value*> pair(&*new_args,&*old_args);
VMap.insert(pair);
if (VMap.count(&*new_args)>0) {
errs().write_escaped("Mapping added") << '\n';
}
old_args++;
}
SmallVector<ReturnInst*, 8> Returns;
CloneFunctionInto(new_F, F, VMap, false, Returns, "_new", 0, 0);
在使用中,“添加映射”消息的打印次数正确(即每个参数打印一次),所以我真的不确定错误在哪里。
【问题讨论】:
标签: llvm compiler-optimization llvm-c++-api