Llvm Remove Terminator Instruction

走远了吗. 提交于 2019-12-11 20:46:51

问题


I want to remove an UnreachableInst since a previous transformation has made it reachable. However, calling eraseFromParent() gives me a malformed BasicBlock since the UnreachableInst is the terminator of its BasicBlock. How do I fix the BasicBlock to terminate at the instruction previous to the UnreachableInst?


回答1:


Every basic block must end with a terminator. I think that the most straightforward way to remove the unreachable instruction, then, is to replace it with another terminator - for example, a branch into the next basic block, a return instruction, etc.

Take a look at llvm::ReplaceInstWithInst in BasicBlockUtils.h for a convenient way to replace one instruction with another.



来源:https://stackoverflow.com/questions/18302465/llvm-remove-terminator-instruction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!