在LLVM IR中,我要复制一组指令,然后通过LLVM传递将这些指令粘贴到IR中的另一个位置.这该怎么做? [英] In LLVM IR, I want to copy a set of Instructions and paste those instructions to another place in IR through LLVM pass. How to do this?

查看:206
本文介绍了在LLVM IR中,我要复制一组指令,然后通过LLVM传递将这些指令粘贴到IR中的另一个位置.这该怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将这组指令从一个部分复制并粘贴到IR中的另一部分

I want to copy these set of instructions from one part and paste to that in another part in IR

  %0 = load i32, i32* @x, align 4
  %1 = load i32, i32* @y, align 4
  %add = add nsw i32 %0, %1
  %2 = load i32, i32* @n, align 4
  %cmp = icmp slt i32 %add, %2
  %conv = zext i1 %cmp to i32

推荐答案

假设您正在使用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);
}

这篇关于在LLVM IR中,我要复制一组指令,然后通过LLVM传递将这些指令粘贴到IR中的另一个位置.这该怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆