Question about using LoopAccessLegacyAnalysis

Hi LLVM community,

I am writing a custom pass for analyzing the dependence information for the memory access within a loop. I found “LoopAccessLegacyAnalysis” class useful, however I m not able to obtain information from that pass. Here is what I did to get the information:

// require pass
virtual void getAnalysisUsage(AnalysisUsage &AU) const
    {
         AU.addRequired<LoopInfoWrapperPass>();
         AU.addRequired<LoopAccessLegacyAnalysis>();
         AU.setPreservesAll();
    }

// processing
virtual bool runOnFunction(Function &F) {
         LoopInfo &li = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
         LoopAccessLegacyAnalysis &lala = getAnalysis<LoopAccessLegacyAnalysis>();

         for(LoopInfo::iterator lp = li.begin(); lp != li.end(); lp++)
         {
             Loop *loop = *lp;
             const LoopAccessInfo &lai = lala.getInfo(loop);
        
        // need help here
        // I can’t get any information from the LoopAccessInfo instance.
        errs()<<lai.getNumLoads(); // return 0
    }
}

// register
static RegisterPass<SkeletonPass> X("test", "test for using the existing pass",
                                    “false",
                                    “false”);

I must be missing something important. Any response would be greatly appreciated!

Thanks,
Kewen

Best regards,
Kewen

Have you check LoopAccessLegacyAnalysis::runOnFunction ran as you expect? Besides, I am not sure if LoopAccessLegacyAnalysis::runOnFunction does anything useful, have you check that, too?

Hi Wei-Ren,

Thanks for your reply.

I use --debug-pass=Structure and it says Loop access analysis pass is executed before my pass. The interesting part is when I use -mem2reg and -loop-rotate it returns dependence information. I have no idea how to explain that. I would be great if one could help me with it. Thanks in advance.

Best,

Kewen