[LLVMdev] loop detection

Andrew Trick atrick at apple.com
Wed Jul 25 12:14:54 PDT 2012


On Jul 23, 2012, at 5:04 PM, Edvard Ghazaryan <edvard_gh at yahoo.com> wrote:

> 
> 
> Hello .
> 
> I'm trying to implement FunctionPass for detecting loops in llvm IR.
> How can I get <condition> for loop from llvm::Loop object.?
> Is there any example?

I'm not sure I understand the question. Here are some tips.

Loop::getLoopLatch() give you a canonical "latch" block if it exists. BasicBlock::getTerminator() gives you the branch. This is done throughout the code, so you can see the pattern.

Loop::getExitingBlocks() gives you all the branches that may leave the loop.

Or may want to do your own search for the "last" exit by following block predecessors from the loop header.

-Andy


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120725/c2cf1672/attachment.html>


More information about the llvm-dev mailing list