[llvm-dev] why LoopInfoWrapperPass can not detect all the canonical loops?

Mikhail Zolotukhin via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 3 17:56:52 PDT 2016


Hi Dong,

The LI provides iterator for top-level loops. In your test you have only one top-level loop, the other one is nested in it.

Here is what the loop structure looks like for your test:
$ opt -loops -analyze stencil.ll
Printing analysis 'Natural Loop Information' for function 'stencil':
Loop at depth 1 containing: %for.body<header>,%for.body8.lr.ph,%for.body8,%for.cond.cleanup7.loopexit,%for.cond.cleanup7<latch><exiting>
    Loop at depth 2 containing: %for.body8<header><latch><exiting>

There are a number of passes that walk through all loops in a function, you could look at them if you need an example. For example, loop-vectorizer does this:
SmallVector<Loop *, 8> Worklist;
for (Loop *L : *LI)
  addInnerLoop(*L, Worklist);
...

static void addInnerLoop(Loop &L, SmallVectorImpl<Loop *> &V) {
  if (L.empty())
    return V.push_back(&L);

  for (Loop *InnerL : L)
    addInnerLoop(*InnerL, V);
}

Hope this helps!

Michael


> On Aug 3, 2016, at 3:42 PM, Dong Chen via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> The original cl code contains 2 canonical loops (start from 0 with stride 1). But the analysis pass LoopInfoWrapperPass only detect one of them, anybody knows why?
> 
> The analysis pass LoopInfoWrapperPass is called from a function pass by the following statements:
> 
> LoopInfo& LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
> for(LoopInfo::iterator l = LI.begin(), lend = LI.end(); l != lend; ++l){
>     PHINode* phi = (*l)->getCanonicalInductionVariable();
> }
> <stencil.cl><stencil.ll>_______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160803/8dc5bdca/attachment.html>


More information about the llvm-dev mailing list