Cristianno Martins
2012-Apr-26 15:52 UTC
[LLVMdev] Detect if a basicblock is part of a loop
Hi Rinaldini, In order to find information about loops inside a given function you should use something like "LoopInfo *LI = P->getAnalysis<LoopInfo>()", remembering to add "AU.addRequired<LoopInfo>();" to your getAnalysisUsage method. If the function you are interested to is not located in the module being compiled (if you created it as an auxiliary function, for example), you could create this information by simply creating a DominatorTreeBase of your function and using it to calculate the LoopInfo, as below: DominatorTreeBase<BasicBlock> *DTB; DTB = new DominatorTreeBase<BasicBlock>(false); DTB->recalculate(*AuxFunction); LoopInfoBase<BasicBlock, Loop> LIB; LIB.Calculate(*DTB); Cheers, -- Cristianno Martins PhD Student of Computer Science University of Campinas cmartins at ic.unicamp.br On Thursday, 26 de April de 2012 at 11:57, Hal Finkel wrote:> Rinaldini, > > What exactly did you run? Specifically, you may be missing some > analysis passes that are necessary for LoopInfo to have the loop > information you desire. > > -Hal > > On Thu, 26 Apr 2012 14:02:04 +0000 > Rinaldini Julien <julien.rinaldini at heig-vd.ch (mailto:julien.rinaldini at heig-vd.ch)> wrote: > > > Hi, > > > > I'm trying to detect if a basicblock is part of a loop or not. > > > > I tried the llvm::LoopInfo like that > > (http://llvm.org/docs/doxygen/html/classllvm_1_1LoopInfo.html#a4abca289c73cd09487e05d11d9f7d877): > > > > LoopInfo *loop = new LoopInfo(); > > bool isLoop = loop->getLoopFor(myBB); // getLoopFor - Return the > > inner most loop that BB lives in. If a basic block is in no loop (for > > example the entry node), null is returned. See doxygen > > > > But getLoopFor() always return me NULL even if my basicblock is > > inside a for loop... I tried this: > > http://comments.gmane.org/gmane.comp.compilers.llvm.devel/38490 but > > it didn't work too :( > > > > Any advice? > > Thx > > > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > > > > > -- > Hal Finkel > Postdoctoral Appointee > Leadership Computing Facility > Argonne National Laboratory > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120426/45f5dfbe/attachment.html>
Arnaud ALLARD DE GRANDMAISON
2012-Apr-26 20:21 UTC
[LLVMdev] Detect if a basicblock is part of a loop
Hi, Depending on what have run before your pass, the loop may have been unrolled or simplified if the computation inside the loop is too simple. Cheers, -- Arnaud de Grandmaison ________________________________________ From: llvmdev-bounces at cs.uiuc.edu [llvmdev-bounces at cs.uiuc.edu] On Behalf Of Cristianno Martins [cristiannomartins at gmail.com] Sent: Thursday, April 26, 2012 5:52 PM To: Hal Finkel Cc: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] Detect if a basicblock is part of a loop Hi Rinaldini, In order to find information about loops inside a given function you should use something like "LoopInfo *LI = P->getAnalysis<LoopInfo>()", remembering to add "AU.addRequired<LoopInfo>();" to your getAnalysisUsage method. If the function you are interested to is not located in the module being compiled (if you created it as an auxiliary function, for example), you could create this information by simply creating a DominatorTreeBase of your function and using it to calculate the LoopInfo, as below: DominatorTreeBase<BasicBlock> *DTB; DTB = new DominatorTreeBase<BasicBlock>(false); DTB->recalculate(*AuxFunction); LoopInfoBase<BasicBlock, Loop> LIB; LIB.Calculate(*DTB); Cheers, -- Cristianno Martins PhD Student of Computer Science University of Campinas cmartins at ic.unicamp.br On Thursday, 26 de April de 2012 at 11:57, Hal Finkel wrote: Rinaldini, What exactly did you run? Specifically, you may be missing some analysis passes that are necessary for LoopInfo to have the loop information you desire. -Hal On Thu, 26 Apr 2012 14:02:04 +0000 Rinaldini Julien <julien.rinaldini at heig-vd.ch<mailto:julien.rinaldini at heig-vd.ch>> wrote: Hi, I'm trying to detect if a basicblock is part of a loop or not. I tried the llvm::LoopInfo like that (http://llvm.org/docs/doxygen/html/classllvm_1_1LoopInfo.html#a4abca289c73cd09487e05d11d9f7d877): LoopInfo *loop = new LoopInfo(); bool isLoop = loop->getLoopFor(myBB); // getLoopFor - Return the inner most loop that BB lives in. If a basic block is in no loop (for example the entry node), null is returned. See doxygen But getLoopFor() always return me NULL even if my basicblock is inside a for loop... I tried this: http://comments.gmane.org/gmane.comp.compilers.llvm.devel/38490 but it didn't work too :( Any advice? Thx _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc..edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev -- Hal Finkel Postdoctoral Appointee Leadership Computing Facility Argonne National Laboratory _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Rinaldini Julien
2012-Apr-27 12:09 UTC
[LLVMdev] RE : Detect if a basicblock is part of a loop
Thx all for the quick answers...> De : llvmdev-bounces at cs.uiuc.edu [llvmdev-bounces at cs.uiuc.edu] de la part de Arnaud ALLARD DE GRANDMAISON [arnaud.allarddegrandmaison at parrot.com] > > Hi, > > Depending on what have run before your pass, the loop may have been unrolled or simplified if the computation inside the loop is too simple. > > Cheers, > -- > Arnaud de GrandmaisonJust as I said to Hal, nothing else than: $ clang -emit-llvm -S -o main.ll main.c $ ../build/Release/bin/opt -load ../build/Release/lib/LLVMobfuscationTest.so -flattening -S main.ll -o main.opt.ll> From: llvmdev-bounces at cs.uiuc.edu [llvmdev-bounces at cs.uiuc.edu] On Behalf Of Cristianno Martins [cristiannomartins at gmail.com]> Hi Rinaldini, > > In order to find information about loops inside a given function you should use something like "LoopInfo *LI = P->getAnalysis<LoopInfo>()", remembering to add "AU.addRequired<LoopInfo>();" to your getAnalysisUsage method. > > If the function you are interested to is not located in the module being compiled (if you created it as an auxiliary function, for example), you could create this information by simply creating a DominatorTreeBase of your function and using it to calculate the LoopInfo, as below: > DominatorTreeBase<BasicBlock> *DTB; > DTB = new DominatorTreeBase<BasicBlock>(false); > DTB->recalculate(*AuxFunction); > > LoopInfoBase<BasicBlock, Loop> LIB; > LIB.Calculate(*DTB); > > Cheers,> -- > Cristianno Martins > PhD Student of Computer Science > University of Campinas > cmartins at ic.unicamp.brThx, I'll try that... I guess I missed the Dominator step last time> On Thursday, 26 de April de 2012 at 11:57, Hal Finkel wrote: > > Rinaldini, > > What exactly did you run? Specifically, you may be missing some > analysis passes that are necessary for LoopInfo to have the loop > information you desire. > > -HalI'm running opt with my lib on a ir code emmitted by clang: $ clang -emit-llvm -S -o main.ll main.c and opt: $ ../build/Release/bin/opt -load ../build/Release/lib/LLVMobfuscationTest.so -flattening -S main.ll -o main.opt.ll No others optimization applied...
Possibly Parallel Threads
- [LLVMdev] Detect if a basicblock is part of a loop
- [LLVMdev] Detect if a basicblock is part of a loop
- [LLVMdev] RE : Detect if a basicblock is part of a loop
- [LLVMdev] Detect if a basicblock is part of a loop
- [LLVMdev] RE : Detect if a basicblock is part of a loop