hameeza ahmed via llvm-dev
2019-Jan-11 06:28 UTC
[llvm-dev] LLVM Pass to count reachable BB
Hello, I have code containing conditions and loops. Hence some BB execution are determined at run time depending on condition. Now I want to count only those BB that are always executed irrespective of condition result means reachable. and their execution is evident at compile time. How to do this? Please help Thank You Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190111/2770dc15/attachment.html>
Brian M. Rzycki via llvm-dev
2019-Jan-11 16:11 UTC
[llvm-dev] LLVM Pass to count reachable BB
Hello Hameeza, If you have access to the dominator analysis (and the data is up-to-date) you can query if each block is dominated by the entry block of a function. I used this method to locate (and avoid) unreachable blocks at the beginning of the JumpThreading pass: https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/Scalar/JumpThreading.cpp#L362 // JumpThreading must not processes blocks unreachable from entry. It's a // waste of compute time and can potentially lead to hangs. SmallPtrSet<BasicBlock *, 16> Unreachable; assert(DTU && "DTU isn't passed into JumpThreading before using it."); assert(DTU->hasDomTree() && "JumpThreading relies on DomTree to proceed."); DominatorTree &DT = DTU->getDomTree(); for (auto &BB : F) if (!DT.isReachableFromEntry(&BB)) Unreachable.insert(&BB); And later in the main for loop below (line 378): if (Unreachable.count(&BB)) continue; On Fri, Jan 11, 2019 at 12:29 AM hameeza ahmed via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hello, > I have code containing conditions and loops. Hence some BB execution are > determined at run time depending on condition. Now I want to count only > those BB that are always executed irrespective of condition result means > reachable. and their execution is evident at compile time. > > How to do this? > > Please help > > Thank You > Regards > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190111/163f8422/attachment.html>
Krzysztof Parzyszek via llvm-dev
2019-Jan-11 18:00 UTC
[llvm-dev] LLVM Pass to count reachable BB
On 1/11/2019 12:28 AM, hameeza ahmed via llvm-dev wrote:> Hello, > I have code containing conditions and loops. Hence some BB execution are > determined at run time depending on condition. Now I want to count only > those BB that are always executed irrespective of condition result means > reachable. and their execution is evident at compile time. > > How to do this?You can find the set of all dominators of the exit block. Would that give you what you want? -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
hameeza ahmed via llvm-dev
2019-Jan-13 13:11 UTC
[llvm-dev] LLVM Pass to count reachable BB
Thank You.. I want to implement following algorithm in LLVM pass.. 1. Scan BB of CFG 2. If BB is not 1st entry block then 3. If BB.predecessor block has instruction "conditional br" then 4. dont print BB 5. else 6. print BB Please help me...How to implement this algorithm in LLVM pass? Thank You Regards On Fri, Jan 11, 2019 at 9:12 PM Brian M. Rzycki <brzycki at gmail.com> wrote:> Hello Hameeza, > > If you have access to the dominator analysis (and the data is up-to-date) > you can query if each block is dominated by the entry block of a function. > I used this method to locate (and avoid) unreachable blocks at the > beginning of the JumpThreading pass: > > > https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/Scalar/JumpThreading.cpp#L362 > > // JumpThreading must not processes blocks unreachable from entry. It's a > // waste of compute time and can potentially lead to hangs. > SmallPtrSet<BasicBlock *, 16> Unreachable; > assert(DTU && "DTU isn't passed into JumpThreading before using it."); > assert(DTU->hasDomTree() && "JumpThreading relies on DomTree to proceed."); > DominatorTree &DT = DTU->getDomTree(); > for (auto &BB : F) > if (!DT.isReachableFromEntry(&BB)) > Unreachable.insert(&BB); > > And later in the main for loop below (line 378): > if (Unreachable.count(&BB)) > continue; > > On Fri, Jan 11, 2019 at 12:29 AM hameeza ahmed via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hello, >> I have code containing conditions and loops. Hence some BB execution are >> determined at run time depending on condition. Now I want to count only >> those BB that are always executed irrespective of condition result means >> reachable. and their execution is evident at compile time. >> >> How to do this? >> >> Please help >> >> Thank You >> Regards >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190113/5b079614/attachment.html>