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().getLoopInfo();
for(LoopInfo::iterator l = LI.begin(), lend = LI.end(); l != lend; ++l){
PHINode* phi = (*l)->getCanonicalInductionVariable();
}
stencil.cl (683 Bytes)
stencil.ll (5.15 KB)
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,%for.body8.lr.ph,%for.body8,%for.cond.cleanup7.loopexit,%for.cond.cleanup7
Loop at depth 2 containing: %for.body8
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