On Mon, 2012-12-03 at 12:19 +0100, Richard Biener wrote: > On Mon, Dec 3, 2012 at 11:05 AM, Alexey Kravets <mr.kayr...@gmail.com> wrote: > > Hello, > > I am looking for a way to implement source annotation (or something > > similar) for a for loops. Basically, I need some mechanism to mark > > certain for loops in the source code for the GIMPLE optimization > > passes (for C/C++ only currently). > > For example something like this: > > > > int i; > > __attribute__((marked)) // Not compilable by GCC. > > for (i =0; i < 100; i++) { > > foo (i); > > } > > > > or > > > > int i; > > > > #pragma marked // Can be compiled, but require additional GIMPLE tree nodes. > > for (i =0; i < 100; i++) { > > foo (i); > > } > > > > > > As far as I know, for loops are lowered to jumps by C front-end and > > natural loops are detected later, so there is no strait way of passing > > such information. > > OpenMP pragmas provides such functionality, but require additional > > GIMPLE nodes to be defined and carried through all optimization > > passes, > > which I would prefer to avoid (if possible). So, is there any strait > > way to implement this? > > A natural way would be to attach such information to the on-the side > loop structure tree (cfgloop.h, struct loop). Unfortunately it is build > quite late, so at the moment you'd have to use a combination of > GIMPLE nodes and later transitioning it to loop struct annotations. > There is, of course, no reason to not at some point in the future > let frontends populate the initial loop tree and keep that up-to-date.
I don't know if this gives you what you need, but an approach that occurred to me is to mark the iterator variable with a custom attribute: int i __attribute__((iterator_for_one_of_the_interesting_loops)); for (i =0; i < 100; i++) { foo (i); } Perhaps you could use that to detect the loops of interest: the initialization, the comparison, and the increment? Hope this is helpful Dave