How to unroll loops in opposite loop nest order

I am trying to implement loop unrolling in a context, where lots of
constant propagation has taken place.
Unrolling an outer loop might make an inner loop have constant bounds,
therefore I want to process the loops
outside in, i.e. from parent loops to nested loops.
Unfortunately the standard loop pass manager performs loop passes inside
out, i.e. from nested loops to parent loops,
thereby missing optimization opportunities in my case.

I haven't found a way how to implement this on my own. I tried
implementing a function pass, where I could process the
loops outside in. Unfortunately I cannot use the UnrollLoop utility
function in this case, which crashes, when called with a
NULL LPPassManager object, despite opposite documentation.

Is there any way how to process loops outside in still using the
UnrollLoop function?

Martin

I noticed another case of referencing LPM without a null check and fixed it here r158007.

You’ll should be careful to check everything that’s currently disabled when LPM is missing: domtree update, ScalarEvolution update, SimplifyIndvar. If you need any of these things I suggest changing the interface.

Maybe it would work to pass in FunctionPass instead of LPM. In the one place we actually need an LPM (deleteLoopFromQueue), we could check FunctionPass’s type and cast. Maybe getAsPMDataManager()->getPassManagerType() == PMT_LoopPassManager?

-Andy

Hi Andy,

sorry, my mail wasn’t precise enough: I am trying to do this in a plugin, i.e. in a LLVM client. I try to do this without modifying
LLVM itself. In the meantime I have found a way to do it the way I need it. I only consider top-level loops in my LoopPass
and add the child loops again using LPPassManager::insertLoopIntoQueue. This seems to have the desired effect.

Martin