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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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).