[LLVMdev] Insert all (including single predecessor) phi nodes

Tarun Pondicherry tpondich at stanford.edu
Sun May 27 22:41:00 PDT 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120528/37a662e0/attachment.html>


More information about the llvm-dev mailing list