Hi everyone, Are there any functions to identify the initiation,condition and iteration part of the loop? Example: for(i=0;i<10;i++) { a[i]+=1; } I want to know the name of the variable used in the loop(i) , the initiation(i=0), condition(i<10) and the iteration(i++) part of the loop. Thank you:) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120116/551dbd63/attachment.html>
On Mon, Jan 16, 2012 at 06:51:34AM -0500, Adarsh HV wrote:> Hi everyone, > Are there any functions to identify the initiation,condition and iteration > part of the loop? > Example: for(i=0;i<10;i++) > { > a[i]+=1; > } > I want to know the name of the variable used in the loop(i) , the > initiation(i=0), condition(i<10) and the iteration(i++) part of the loop. > Thank you:)Perhaps it's easier to use clang to achieve your goal? Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj
Hi Adarsh,> On Mon, Jan 16, 2012 at 06:51:34AM -0500, Adarsh HV wrote: >> Hi everyone, >> Are there any functions to identify the initiation,condition and iteration >> part of the loop? >> Example: for(i=0;i<10;i++) >> { >> a[i]+=1; >> } >> I want to know the name of the variable used in the loop(i) , the >> initiation(i=0), condition(i<10) and the iteration(i++) part of the loop. >> Thank you:)this is what LLVM's scalar evolution infrastructure is for. Ciao, Duncan.
On 01/16/2012 12:51 PM, Adarsh HV wrote:> Hi everyone, > Are there any functions to identify the initiation,condition and > iteration part of the loop? > Example: for(i=0;i<10;i++) > { > a[i]+=1; > } > I want to know the name of the variable used in the loop(i) , the > initiation(i=0), condition(i<10) and the iteration(i++) part of the loop. > Thank you:)Hi Adarsh, the main question is where to do this analysis. You have two options 1. Do it in clang As pointed out by chenwj, you can do this in clang. This will basically be a pattern matching approach or, if more advanced, some source code based induction variable recognition. Working on clang has the advantage that your results directly relate to the C code. However, performing advanced induction variable analysis on C code is more difficult. I am not sure, if there already exists an induction variable analysis. 2. Do it in LLVM Here you would work on LLVM-IR and use the LoopInfo and the ScalarEvolution analysis. These analysis perform advanced induction variable recognition and will give you good results for a wider range of code (including while loops, goto, pointer arithmetic). However, it will be hard to relate the results to the original C code. You can try to use debugging information, but I doubt this will work in all cases. Cheers Tobi