简体   繁体   English

如何用值替换指令?

[英]How do I replace an instruction with a value?

I'm writing in C++. 我正在用C ++编写。 Say I have 说我有

define void @ha(i32) #0 {
  %2 = add nsw i32 %0, 1
  %3 = sub nsw i32 %2, 1
  ret void
}

I'd like to replace 我想更换

%3 = sub nsw i32 %2, 1

with

%3 = %0

I've tried 我试过了

inst_iter->replaceAllUsesWith(val);
inst_iter->eraseFromParent();

and ReplaceInstWithValue(inst_iter->getParent()->getInstList(), inst_iter, val); 和ReplaceInstWithValue(inst_iter-> getParent()-> getInstList(),inst_iter,val);

The first understandably does not work, as it does not have another reference; 可以理解的是,第一个没有用,因为它没有其他参考。 for the second one, it just deletes the instruction. 对于第二个,它只是删除指令。 I couldn't find an appropriate function either (and I haven't included IRBuilder). 我也找不到合适的函数(并且我还没有包含IRBuilder)。 Any help is appreciated, thank you! 任何帮助表示赞赏,谢谢!

The function you want is replaceAllUsesWith() . 您想要的函数是replaceAllUsesWith() Find your sub and replace all uses of that instruction with. 找到您的sub并替换为该指令的所有用法。 Done. 完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM