[LLVMdev] LoopInfo of a basic block
Devang Patel
dpatel at apple.com
Mon Feb 28 14:43:02 PST 2011
On Feb 28, 2011, at 2:35 PM, Naznin Fauzia wrote:
> Hi all,
>
> How Can I get the Loops around an Instruction?
>
> I know I can get the basic block of an instruction using inst.getParent() which returns a BasicBlock*. Now I want to use the getLoopFor(BasicBlock) method of the class LoopInfo.
> But I dont know how to get the LoopInfo.
>
> BasicBlock* bb = inst.getParent();
>
> (... what should I add here?)
>
> Loop* innerloop = LI -> getLoopFor(bb):
>
Two steps:
1) In your pass's getAnalysisUsage(), request LoopInfo.
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<LoopInfo>();
}
2) In your runOnLoop() method get the analysis.
LoopPass *LI = &getAnalysis<LoopInfo>();
Now, you can do LI->getLoopFor(...)
-
Devang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110228/8c8e884f/attachment.html>
More information about the llvm-dev
mailing list