khaled hamidouche
2010-Apr-21 14:31 UTC
[LLVMdev] determining the number of iteration of a loop
Hello I'm wandring to know how many times a block is executed inside a loop ? knowing that I can't use getSmallConstantTripCount() because the number is unkown "for (i=0;i<N;i++) for example" I'm using a Function pass for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { if (Loop *L = LI->getLoopFor(BB)) { if (L->getHeader() == BB) { the code of the loop (the header) } else{the code of the block inside the loop} else the code of a basicblock (outside a loop) How can I get the variable N (even only the name of this variable !!) ??? I mean I want to get "the loop will be executed "%N" times" Thank you so much K.H -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100421/59c92f33/attachment.html>
Trevor Harmon
2010-Apr-21 21:28 UTC
[LLVMdev] determining the number of iteration of a loop
On Apr 21, 2010, at 7:31 AM, khaled hamidouche wrote:> I'm wandring to know how many times a block is executed inside a > loop ? > knowing that I can't use getSmallConstantTripCount() because the > number is unkown "for (i=0;i<N;i++) for example"In general, the number of iterations is undecidable. For example: int main(char **argv, int N) { for (int i = 0; i < N; i++) { std::cout << "arg: " << argv[i] << std::endl; } return 0; } If you are parsing code whose iterations can be determined, please post it. Trevor
Eugene Toder
2010-Apr-21 21:48 UTC
[LLVMdev] determining the number of iteration of a loop
In your example the the number of iterations is known -- it is N. It is not known at compile time, but it's known at run-time before you enter the loop. So you can do transforms like if( N < threshold ) copy of loop optimized for small iterations count; else copy of loop optimized for large iterations count; But you are right, in general, the number of iterations in unknown. I think Khaled is interested in a large number of cases when it is known, either as a constant or value. Eugene On Wed, Apr 21, 2010 at 10:28 PM, Trevor Harmon <Trevor.W.Harmon at nasa.gov> wrote:> On Apr 21, 2010, at 7:31 AM, khaled hamidouche wrote: > >> I'm wandring to know how many times a block is executed inside a >> loop ? >> knowing that I can't use getSmallConstantTripCount() because the >> number is unkown "for (i=0;i<N;i++) for example" > > In general, the number of iterations is undecidable. For example: > > int main(char **argv, int N) { > for (int i = 0; i < N; i++) { > std::cout << "arg: " << argv[i] << std::endl; > } > return 0; > } > > If you are parsing code whose iterations can be determined, please > post it. > > Trevor > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Seemingly Similar Threads
- [LLVMdev] determining the number of iteration of a loop
- [LLVMdev] iterate over loops inside the runOnFunction
- [LLVMdev] determining the number of iteration of a loop
- [LLVMdev] Problem with the installation of llvm gcc
- [LLVMdev] Problem with the installation of llvm gcc