[LLVMdev] Dependence analysis

Cody Yu hyu at cs.ucla.edu
Wed Jan 14 16:17:02 PST 2015


Hello,

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:

*int test(int a, int* out, int N)*
*{*
*    int sum = 0;*

*    for(i = 2; i < N; ++i)    {*
*        out[i] = a + i;*

*        sum += out[i - 2];    }*
*    return sum;*
*}*

I compiled this C code by using the following command:

*clang -fno-unroll-loops -emit-llvm -O2 -c -o test.bc test.c*

Then I run DependenceAnalysis pass:

*opt -basicaa -mem2reg -indvars -instcombine -instnamer -loop-simplify
-mergereturn -da -analyze test.bc > /dev/null*

and got this result:

*Printing analysis 'Dependence Analysis' for function 'test':*
*da analyze - none!*
*da analyze - consistent flow [2]!*
*da analyze - none!*

Actually this what I expect to got. However if I write a pass like this:

*TestPass.h*
*  virtual void getAnalysisUsage(AnalysisUsage &AU) const*
*  {*
*      AU.setPreservesAll();*
*      AU.addRequired<DependenceAnalysis>();*
*  }*

*TestPass.cpp*
*bool TestPass::runOnFunction(Function& F)*
*{*
*  llvmDependenceAnalysis = &(getAnalysis<DependenceAnalysis>(F));*

*   // The following code is copied from
DependenceAnalysis.cpp:dumpExampleDependence (157 - 182)*
*   for (inst_iterator SrcI = inst_begin(F), SrcE = inst_end(F); SrcI !=
SrcE; ++SrcI) {  ... SKIP... }*

*   return true; *
*}*

And I executed this pass by using the following command:

*opt -basicaa **-mem2reg -indvars -instcombine -instnamer -loop-simplify
-mergereturn** -load ./TestPass.so -test-pass test.bc > /dev/null*

at this time I got:

*da analyze - confused!*

*da analyze - confused!*
*da analyze - confused!*

Am I doing a wrong usage about this analysis?

Hao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150114/9e1842e1/attachment.html>


More information about the llvm-dev mailing list