benedikt steinmeier via llvm-dev
2018-Nov-27 21:14 UTC
[llvm-dev] ScalarEvolution class returns no valid loop exit count
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181127/c2fe6cdb/attachment.html>
Sanjoy Das via llvm-dev
2018-Nov-27 21:25 UTC
[llvm-dev] ScalarEvolution class returns no valid loop exit count
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
benedikt steinmeier via llvm-dev
2018-Nov-28 13:26 UTC
[llvm-dev] ScalarEvolution class returns no valid loop exit count
Hi Sanjoy, the LLVM IR is parsed with following expression: ....... string file = "...."; static LLVMContext cont; SMDiagnostic diag; unique_ptr<Module> module = parseIRFile(file, diag, cont); ....... I mixed up the LLVM loop exit block with the loop exiting block in my analyses code. But after resolving this issue, the exiting block is successfully determined: ...... BB1: ; preds = %BB3, %BB0 %3 = load i32, i32* %2, align 4 %4 = icmp slt i32 %3, 10 br i1 %4, label %BB2, label %BB4 ....... Nevertheless the loop exiting count can not be calculated with the ScalarEvolution class. I will try to do the loop optimizations. Many greetings Benedikt Am Di., 27. Nov. 2018 um 22:25 Uhr schrieb Sanjoy Das < sanjoy at playingwithpointers.com>:> 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181128/badabcbf/attachment.html>