How can I identify a backedge from a BasicBlock in LLVM
I am writing an LLVM pass which analyzes and modifies the generated IR code. Is there a way to identify backedges, I mean to know if a successor of a BasicBlock is actually somewhere above it in path.
Yes, there is.
First, note that you need to distinguish between "every path to BB must pass through A", and "there is some path from A that might lead to BB".
I think that you're looking for the first situation - tell if the successor A of the basic block BB is a basic block that the execution must pass through to get to B.
When this situation happens, we say that "A dominates B". The interface to check for dominance is through the DominatorTree class (add in in the getAnalysisUsage function of your pass. See the writing an llvm pass for an example).