How to remove a successor from a terminator instruction in LLVM

For the base unit, I want to change the conditional jump to the unconditional jump. Therefore, if the base unit had two successors, I want to remove an edge to one of the successors. I want the base unit to go directly to one of the successors. How can i do this?

To illustrate my point, I want to change

A / \ / \ BC 

to

  A \ \ C 
+4
source share
1 answer

I think the easiest way is to simply create a new unconditional branch instruction, and then replace it with the old one. So something like:

 #include "llvm/Transforms/Utils/BasicBlockUtils.h" BranchInst* Old = ... BranchInst* New = BranchInst::Create(Old->getSuccessor(X)); ReplaceInstWithInst(Old, New); 

Where X is 0 or 1, depending on whether you want a β€œtrue” branch or a β€œfalse” branch.

+6
source

Source: https://habr.com/ru/post/1445037/


All Articles