[LLVMdev] get LPPassManager to use it in llvm::CloneLoop

Eli Friedman eli.friedman at gmail.com
Mon May 9 07:48:29 PDT 2011


On Mon, May 9, 2011 at 1:06 AM, Jimborean Alexandra
<xinfinity_a at yahoo.com> wrote:
> Hi,
>
> I try to write a FunctionPass that, among other tasks, has to clone some
> loops from the current function.
> How can I obtain the LPPassManager in order to use the CloneLoop function.
> In a LoopPass this is a parameter for the runOnLoop, but how can I obtain it
> in a FunctionPass?
> I tried simply by creating a new instance :
>
>         ValueMap<const Value *, Value* > VMap;
>         LoopInfo *LI = &getAnalysis<LoopInfo>();
>         LPPassManager *LPM = new llvm::LPPassManager(1);
>
>         Loop* nL = llvm::CloneLoop(L, LPM, LI, VMap, this);
>
> but it segfaults in CloneLoop when trying LPM->insertLoop(..).

CloneLoop isn't fundamentally dependent on a LPPassManager, but it
looks like you have to pass one in at the moment; you might need to
mess with the implementation of llvm::CloneLoop (in CloneLoop.cpp) a
bit so that passing in null for the LPM argument works correctly.

> Does the CloneLoop function include both loops in the CFG and re-create the
> use map between the clones?
> Also does it update the phi nodes to use either the original or the cloned
> values?

CloneLoop essentially puts in a copy of the loop, and doesn't mess
with anything outside of the loop.  You have to fix up everything else
to fit together properly yourself.  Note that the "LCSSA" pass helps a
lot here, but I don't recall if requiring it from a FunctionPass works
properly.

-Eli




More information about the llvm-dev mailing list