[LLVMdev] inserting blocks into a Function

Sameer D. Sahasrabuddhe sameerds at it.iitb.ac.in
Wed Apr 27 22:26:47 PDT 2005

Recently wrote a pass that inserts a preheader for a loop that doesn't
have one. When I tried to run it, I ran into a problem that became
obvious in hindsight - the PHINodes need to be updated in places where
the incoming control-edge has changed. Is there anything else that can
be affected when a block is inserted into the CFG?

Also, planning to write a helper function which will take care of such
issues. The general signature is:

void reconnectBlocks(BasicBlock *newBlock, BasicBlock *insertBefore
                    , std::vector<BasicBlock*> &preds
                    , bool createBr = true)

The std::vector "preds" is used to provide a list of preds for
insertBefore, which will be reconnected to newBlock. For cases where
all the preds will be reconnected, the function can be overloaded with
this argument removed.

The bool createBr is used to indicate whether an unconditional branch
should be inserted from newBlock to insertBefore.

Does such a thing already exist?
If not, would people be interested in having such a function, or is
this an overkill?
Where in the LLVM sources should it end up?
Am I missing anything, that needs to be included, or that makes it
futile to write such a generalised function?

Research Scholar, KReSIT, IIT Bombay

More information about the llvm-dev mailing list