且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在LLVM IR中,我要复制一组指令,然后通过LLVM传递将这些指令粘贴到IR中的另一个位置.这该怎么做?

更新时间:2023-11-10 23:47:34

假设您正在使用C ++ API,则只需固定引用.类似于以下内容:

Assuming you are using C++ API, you will just have to clone each instruction separately while fixing references between them. Something like the following:

llvm::ValueToValueMapTy vmap;

for (auto *inst: instructions_to_clone) {
  auto *new_inst = inst->clone();
  new_inst->insertBefore(insertion_pos);
  vmap[inst] = new_inst;
  llvm::RemapInstruction(new_inst, vmap,
                         RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
}