<div dir="ltr">Hello,<div><br></div><div><div>I am trying to use Dependence analysis to figure out some information form my benchmarks. However, I got different results by using LLVM analysis and my own pass. For example I have this case:</div><div><br></div><div><b><i>int test(int a, int* out, int N)</i></b></div><div><b><i>{</i></b></div><div><b><i>    int sum = 0;</i></b></div><div><b><i>    for(i = 2; i < N; ++i)<br>    {</i></b></div><div><b><i>        out[i] = a + i;</i></b></div><div><b><i>        sum += out[i - 2];<br>    }</i></b></div><div><b><i>    return sum;</i></b></div><div><b><i>}</i></b></div><div><br></div><div>I compiled this C code by using the following command:</div><div><br></div><div><b><i>clang -fno-unroll-loops -emit-llvm -O2 -c -o test.bc test.c</i></b><br></div><div><br></div><div>Then I run DependenceAnalysis pass:</div><div><br></div><div><b><i>opt -basicaa -mem2reg -indvars -instcombine -instnamer -loop-simplify -mergereturn -da -analyze test.bc > /dev/null</i></b></div><div><br></div><div>and got this result:</div><div><br></div><div><div><b><i>Printing analysis 'Dependence Analysis' for function 'test':</i></b></div><div><b><i>da analyze - none!</i></b></div><div><b><i>da analyze - consistent flow [2]!</i></b></div><div><b><i>da analyze - none!</i></b></div></div><div><br></div><div>Actually this what I expect to got. However if I write a pass like this:</div><div><br></div><div><b><i>TestPass.h</i></b></div><div><div><b><i>  virtual void getAnalysisUsage(AnalysisUsage &AU) const</i></b></div><div><b><i>  {</i></b></div><div><b><i>      AU.setPreservesAll();</i></b></div><div><b><i>      AU.addRequired<DependenceAnalysis>();</i></b></div><div><b><i>  }</i></b></div></div><div><br></div><div><b><i>TestPass.cpp</i></b></div><div><div><b><i>bool TestPass::runOnFunction(Function& F)</i></b></div><div><b><i>{</i></b></div><div><b><i>  llvmDependenceAnalysis = &(getAnalysis<DependenceAnalysis>(F));</i></b></div><div><b><i><br></i></b></div><div><b><i>   // The following code is copied from DependenceAnalysis.cpp:dumpExampleDependence (157 - 182)</i></b></div><div><b><i>   for (inst_iterator SrcI = inst_begin(F), SrcE = inst_end(F); SrcI != SrcE; ++SrcI) {  ... SKIP... }</i></b></div><div><b><i>  </i></b></div><div><b><i>   return true; </i></b></div><div><b><i>}</i></b></div></div><div><br></div><div>And I executed this pass by using the following command:</div><div><br></div><div><b><i>opt -basicaa </i></b><b><i>-mem2reg -indvars -instcombine -instnamer -loop-simplify -mergereturn</i></b><b><i> -load ./TestPass.so -test-pass test.bc > /dev/null</i></b></div><div><br></div><div>at this time I got:</div><div><br></div><div><div><b><i>da analyze - confused!</i></b></div><div><b><i>da analyze - confused!<br></i></b></div><div><b><i>da analyze - confused!</i></b><br></div></div><div><br></div><div>Am I doing a wrong usage about this analysis?</div><div><br></div><div>Hao</div><div><br></div>
</div></div>