[llvm-dev] Obtaining bounds of loops

Philip Reames via llvm-dev llvm-dev at lists.llvm.org
Mon Feb 22 10:58:20 PST 2021


JFYI, the infrastructure on Loop itself is very very limited. Honestly, 
it probably shouldn't exist at all.

ScalarEvolution exists to analyze loops.  In particular, it can compute 
symbolic execute counts for a much much broader family of loops.

Without knowing your use case, I can't say for sure, but I suspect you 
want to be using ScalarEvolution.

Philip

On 2/22/21 8:48 AM, bodhisatwa via llvm-dev wrote:
> Hi,
>
> I am trying to test out the getBounds() method from LoopInfo. However, 
> the method doesn't seem to obtain the bounds of simple loops like -
>
>        for (int j = 0; j < 10; j ++)
>            B[j] = 6;
>
>        int i = 10, j = 2,
>
>        while ( i != j)
>              j++;
>
>  My code snippet in the function pass is as follows (which gives the 
> output as "No value for loop bounds" for all the loops):
>
>       LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
>
>       for (auto loop = LI.begin(), e = LI.end(); loop != e; ++loop )
>       {
>           ScalarEvolution *SE = 
> &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
>           auto b = (*loop)->getBounds(*SE);
>
>           if (!b.hasValue())
>                {
>                   errs() << "No value for loop bounds\n";
>                }
>       }
>
>  Is there something that I am missing here?
>
>
>  Thanks,
>  Bodhi
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list