Iterating over loops with LoopInfoWrapperPass in LLVM

968 Views Asked by At

I am using the LoopInfoWrapperPass to generate Loopinfo, but then I am not able to use Loopinfo to iterate over the loops in my function.

Here is the code. I get a build error while using the 'make' command:

#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "iostream"
#include "llvm/Pass.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"

using namespace llvm;

namespace {
    struct SkeletonPass : public FunctionPass {
        static char ID;
        SkeletonPass() : FunctionPass(ID) {}

        void getAnalysisUsage(AnalysisUsage &AU) const override {
            AU.setPreservesCFG();
            AU.addRequired<LoopInfoWrapperPass>();
        }

        virtual bool runOnFunction(Function &F) {
            LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
            for(LoopInfo::iterator i = LI.begin(), e=LI.end(); i != e; ++i) {
                // Some code here
            }
            return false;
        }
    }
}

I am getting a stray error '\342' in the program at the line with the for loop. What is the problem?

1

There are 1 best solutions below

1
On

Have you copy-pasted the for loop line? This might be causing the issue. If so, delete and add back the letter that is causing the issue.