[llvm-dev] ScalarEvolution class returns no valid loop exit count

Sanjoy Das via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 27 13:25:10 PST 2018


Are you sure exitingblock is not null?  This should probably be an
assert in getExitCount itself.

Other than that, SCEV normally expects that the loops have been
canonicalized and some basic optimizations have been performed.  How
are you obtaining the IR you're passing to analysis?

-- Sanjoy
On Tue, Nov 27, 2018 at 1:14 PM benedikt steinmeier via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
>
> Hi,
>
> I have problems to estimate the loop exit count of a simple loop with the ScalarEvolution class.
>
> simple loop:
> ......
>     int a = 0;
>     for(int i; i < 10; ++i){
>         a = a + 1;
>     };
> ......
>
> For the loop analyzation I use the ScalarEvolution class with the following initialization:
> ......
> void analysis(Function* func)
>     DominatorTree DT = DominatorTree();
>     DT.recalculate(*func);
>     DT.updateDFSNumbers();
>
>     LoopInfoBase<BasicBlock, Loop> LIB;
>     LIB.releaseMemory();
>     LIB.analyze(DT);
>
>     for(auto&bb :*func){
>         Loop * L = LIB.getLoopFor(&bb);
>         if(L != nullptr){
>             AssumptionCache AC = AssumptionCache(*bb.getParent());
>             Triple MT(llvm::sys::getDefaultTargetTriple());
>             TargetLibraryInfoImpl TLII(MT);
>             TargetLibraryInfoWrapperPass TLI = TargetLibraryInfoWrapperPass(TLII);
>
>             LoopInfo LI = LoopInfo(DT);
>             LI.analyze(DT);
>
>             ScalarEvolution SE = ScalarEvolution(*func, TLI.getTLI(),AC, DT, LI);
>             BasicBlock * exitingblock = L->getUniqueExitBlock();
>             const SCEV * exitingcount = SE.getExitCount (L,exitblock );
>         }
>     }
> }
> ......
>
> Unfortunately I get this result by printing the SCEV exitingcount variable:
> ***COULDNOTCOMPUTE***
>
> It has been tested that the exitingblock of the loop was calculated successfully.
> The LLVM IR is parsed and analysed without the usual pass framework. For this reason
> the use of the getAnalysis<ScalarEvolution>() is not possible. The question is wether there
> is something I`m doing wrong during the initialization of the ScalarEvolution class? Or is
> the use of LLVM analysis classes without the passmanager framework not possible?
>
> Best regards!
> Benedikt
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list