<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><font face="Arial" style="font-size: 14px;" class="">Hi LLVM-ers,</font><div class=""><font face="Arial" style="font-size: 14px;" class=""><br class=""></font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""> (1) I tried to use the following command line to get the iteration distance of a loop-carried dependence of a simple program : </font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""> </font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""> <span class="Apple-tab-span" style="white-space:pre"> </span> command line: opt -basicaa -da -analyze dis_test.ll</font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""><br class=""></font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""> program: <span class="Apple-tab-span" style="white-space:pre"> </span>for ( int i=0; j < n; ++i ) {</font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""> <span class="Apple-tab-span" style="white-space:pre"> </span> b[i] = b[i-2] + 3;</font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> }</font></div><div class=""><font face="Arial" class=""><span style="font-size: 14px;" class=""> results: da analyze — none!</span></font></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span> da analyze — consistent anti [-2] (This is what I expected!!)</span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span> da analyze — none!</span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""> </span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""> (2) However, when I tried to use the C++ API to do the same thing, the distance result is null.</span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""><br class=""></span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""> My pass: </span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""><br class=""></span></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span><span style="font-size: 14px;" class=""><font face="Arial" class="">class IterationDistance : public DependenceAnalysis { </font></span></div><div class=""><span style="font-size: 14px;" class=""><font face="Arial" class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>...</font></span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""> <span class="Apple-tab-span" style="white-space:pre"> </span> void getAnalysisUsage(AnalysisUsage &AU) const { </span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span> AU.setPreservesAll(); </span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span> AU.addRequired<AliasAnalysis>();
<span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> AU.addRequired<LoopInfo>(); </span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span> AU.addRequired<ScalarEvolution>();
<span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> </span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""> AU.addRequired<DependenceAnalysis>();</span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>}</span></div><div class=""><span style="font-family: Arial; font-size: 14px;" class=""> ...</span></div><div class=""><span style="font-size: 14px;" class=""><font face="Arial" class=""><span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span></font></span><font face="Arial" class=""><span style="font-size: 14px;" class="">DependenceAnalysis *DA = &(getAnalysis<DependenceAnalysis>());</span></font></div><div class=""><font face="Arial" class=""><span style="font-size: 14px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>auto D = DA->depends(Src, Des, true);</span></font></div><div class=""><font face="Arial" class=""><span style="font-size: 14px;" class=""><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>if (D->isAnti()) {</div><div class=""> unsigned Levels = D->getLevels();</div><div class=""> errs() << "levels = " << Levels << "\n";</div><div class=""> char Direction;</div><div class=""> for (unsigned II = 1; II <= Levels; ++II) {</div><div class=""> ...</div><div class=""><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>const SCEV *Distance = D->getDistance(II);</div><div class=""> const SCEVConstant *SCEVConst = dyn_cast_or_null<SCEVConstant>(Distance);</div></div><div class=""> ...</div></span></font></div><div class=""><div class=""><font face="Arial" style="font-size: 14px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""><br class=""></font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""> Results: levels = 0;</font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""> Distance is null.</font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""><br class=""></font></div><div class=""><font face="Arial" class=""><span style="font-size: 14px;" class=""> (3) My guess is that the "levels = 0” which makes the Distance cannot be got. Can anyone help me with this? </span></font></div><div class=""><font face="Arial" style="font-size: 14px;" class=""><br class=""></font></div><div class=""><font face="Arial" style="font-size: 14px;" class="">Thanks!</font></div><div class=""><font face="Arial" style="font-size: 14px;" class="">Shvo</font></div></div></body></html>