How to detect whether we're inside of a loop??

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Wed Apr 9 07:55:00 GMT 2003


 > From: Jan Hubicka <hubicka@ucw.cz>
 > 
 > > I was interested in experimenting with heuristics which might expand a
 > > builtin depending on whether at the point of expansion we're in a loop
 > > or not.  E.g. It might make sense to expand something which might
 > > create slightly larger code only if we think it's likely that it'll be
 > > executed a number of times.  I'm guessing that being inside a loop is
 > > one way to increase that probability.  Thus I was curious if there's a
 > > way to detect this.  So my questions are:
 > > 
 > > 1.  Can we detect this?  (C'mon there's gotta be a way.)
 > 
 > I guess cfun->stmt->x_nesting_depth is what you are looking for.
 > Honza

Not quite.  Following your lead I read through stmt.c a bit and if I
understand it correctly, x_nesting_depth records all scopes not just
loops.  E.g. if-then, switches, etc.  Luckily, I quickly found
x_loop_stack which does exactly what I want.  So thanks for putting me
in the right ballpark.

		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu



More information about the Gcc mailing list