<div dir="ltr">Your Loop *L is from a different LoopInfo object than the one you're giving to ScalarEvolution. So your SE doesn't know your loop, and can't tell you anything about it.<div><br></div><div>Cheers,</div><div>Philip</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 28, 2018 at 2:26 PM benedikt steinmeier via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>Hi Sanjoy,</div><div><br></div><div>the LLVM IR is parsed with following expression:</div><div>.......<br></div><div>string file = "...."; <br>static LLVMContext cont;<br>SMDiagnostic diag;<br>unique_ptr<Module> module = parseIRFile(file, diag, cont);</div><div>.......</div><div><br></div><div>I mixed up the LLVM loop exit block with the loop exiting block in my analyses code. But after</div><div>resolving this issue, the exiting block is successfully determined:<br></div><div>......<br></div><div>BB1: ; preds = %BB3, %BB0<br> %3 = load i32, i32* %2, align 4<br> %4 = icmp slt i32 %3, 10<br> br i1 %4, label %BB2, label %BB4<br>.......</div><div><br></div><div>Nevertheless the loop exiting count can not be calculated with the ScalarEvolution class. I will try to</div><div>do the loop optimizations.<br></div><div><br></div><div>Many greetings<br></div><div>Benedikt<br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">Am Di., 27. Nov. 2018 um 22:25 Uhr schrieb Sanjoy Das <<a href="mailto:sanjoy@playingwithpointers.com" target="_blank">sanjoy@playingwithpointers.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Are you sure exitingblock is not null? This should probably be an<br>
assert in getExitCount itself.<br>
<br>
Other than that, SCEV normally expects that the loops have been<br>
canonicalized and some basic optimizations have been performed. How<br>
are you obtaining the IR you're passing to analysis?<br>
<br>
-- Sanjoy<br>
On Tue, Nov 27, 2018 at 1:14 PM benedikt steinmeier via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> I have problems to estimate the loop exit count of a simple loop with the ScalarEvolution class.<br>
><br>
> simple loop:<br>
> ......<br>
> int a = 0;<br>
> for(int i; i < 10; ++i){<br>
> a = a + 1;<br>
> };<br>
> ......<br>
><br>
> For the loop analyzation I use the ScalarEvolution class with the following initialization:<br>
> ......<br>
> void analysis(Function* func)<br>
> DominatorTree DT = DominatorTree();<br>
> DT.recalculate(*func);<br>
> DT.updateDFSNumbers();<br>
><br>
> LoopInfoBase<BasicBlock, Loop> LIB;<br>
> LIB.releaseMemory();<br>
> LIB.analyze(DT);<br>
><br>
> for(auto&bb :*func){<br>
> Loop * L = LIB.getLoopFor(&bb);<br>
> if(L != nullptr){<br>
> AssumptionCache AC = AssumptionCache(*bb.getParent());<br>
> Triple MT(llvm::sys::getDefaultTargetTriple());<br>
> TargetLibraryInfoImpl TLII(MT);<br>
> TargetLibraryInfoWrapperPass TLI = TargetLibraryInfoWrapperPass(TLII);<br>
><br>
> LoopInfo LI = LoopInfo(DT);<br>
> LI.analyze(DT);<br>
><br>
> ScalarEvolution SE = ScalarEvolution(*func, TLI.getTLI(),AC, DT, LI);<br>
> BasicBlock * exitingblock = L->getUniqueExitBlock();<br>
> const SCEV * exitingcount = SE.getExitCount (L,exitblock );<br>
> }<br>
> }<br>
> }<br>
> ......<br>
><br>
> Unfortunately I get this result by printing the SCEV exitingcount variable:<br>
> ***COULDNOTCOMPUTE***<br>
><br>
> It has been tested that the exitingblock of the loop was calculated successfully.<br>
> The LLVM IR is parsed and analysed without the usual pass framework. For this reason<br>
> the use of the getAnalysis<ScalarEvolution>() is not possible. The question is wether there<br>
> is something I`m doing wrong during the initialization of the ScalarEvolution class? Or is<br>
> the use of LLVM analysis classes without the passmanager framework not possible?<br>
><br>
> Best regards!<br>
> Benedikt<br>
><br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>