0

does anybody know how to iterate over the basic of Loops of functions in module pass.I was trying :

bool runOnModule(Module &M) override
{
    for(Module::iterator f = M.begin(), fend = M.end(); f != fend; ++f)
    {
            LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
            for(Loop *L : LI)
            {
                for(BasicBlock *BB : L->getBlocks())
                {
                    dbgs() << "basicb name: "<< BB->getName() <<"\n";
                }
            }
     }
     return true;
}

and it always gives the error

opt: /home/anurag/polly/llvm/include/llvm/PassAnalysisSupport.h:235:    AnalysisType& llvm::Pass::getAnalysisID(llvm::AnalysisID) const [with AnalysisType = llvm::LoopInfoWrapperPass; llvm::AnalysisID = const void*]: Assertion `ResultPass && "getAnalysis*() called on an analysis that was not " "'required' by pass!"' failed.
3
  • Have you added the LoopInfoWrapperPass to your getAnalysisUsage() routine? Commented Oct 24, 2017 at 12:29
  • yes i have added. Commented Oct 28, 2017 at 15:30
  • @Brian I tried like:void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<LoopInfoWrapperPass>(); } Commented Oct 29, 2017 at 5:30

1 Answer 1

0

There are two updates needed for this code. The first was also noted in this question, that when requesting the loop info from a module pass, you need to specify the function (adding the iterator access):

LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>(*f).getLoopInfo();

The second issue is that some functions in the module are "empty", declarations without definitions. Adding a check for the size should skip those and avoiding any issues with trying to find loops in empty functions.

if ((*f).size() == 0) continue;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.