Insert all (including single predecessor) phi nodes

Hi,

I’m trying to implement superblock analysis as an LLVM pass. In my code, a basic block is sometimes cloned and inserted into a neighboring position in the cfg, with the same successors as the original basic block. The frequently executed edge will have one predecessor, and all other predecessor edges go to the cloned block. If there are phi nodes in the successors, they are appropriately updated by adding one more entry and mapping the instructions from the old basic block to the cloned block using the map returned by CloneBasicBlock.

However, if there are no phi nodes in the successors because they only had one predecessor, then one needs to be inserted for any values that are used in those successor blocks, since they may now come from either the cloned block or the original block.

I’m having difficulty figuring out how to iterate over a basic block, determine which operands come from previous basic blocks and then inserting a phi node for them. If there is a way to do a pass to insert phi nodes even in the case of only one predecessor, I think my pass will then find and update them correctly.

Is there a better approach to this? Is there a simple way to do the aforementioned “insert all phi nodes” pass?

Thanks,
Tarun