On Wed, 2019-10-30 at 10:27 +0100, Richard Biener wrote: > > Hmm, not sure - I'd like to write > > for (gimple *use_stmt : imm_stmt_uses (SSAVAR)) > for (use_operand_p use_p : <need to refer to the iterator object > from > above>) > ... > > I don't see how that's possible. It would need to be "awkward" like > > for (auto it : imm_stmt_uses (SSAVAR)) > { > gimple *use_stmt = *it; > for (use_operand_p use_p : it) > ... > } > > so the first loops iteration object are the actual iterator and you'd > have to do extra indirection to get at the actual stmt you iterated > to. > > So I'd extend C++ (hah) to allow > > for (gimple *use_stmt : imm_stmt_uses (SSAVAR)) > for (use_operand_p use_p : auto) > ... > > where 'auto' magically selects the next iterator object in scope > [that matches]. > > ;)
Have you applied for a patent yet? :D How about this one? for (gimple* use_stmt : imm_stmt_uses (SSAVAR)) for (use_operand_p use_p : imm_uses_on_stmt (*use_stmt)) ... where helper function "imm_uses_on_stmt" returns a range object that offers a begin and end function and its own iterator type. Another concept that could be interesting are filter iterators. We used a simplistic re-implementation (c++03) to avoid dragging in boost when working on AMS https://github.com/erikvarga/gcc/blob/master/gcc/filter_iterator.h Example uses are https://github.com/erikvarga/gcc/blob/master/gcc/ams.h#L845 https://github.com/erikvarga/gcc/blob/master/gcc/ams.cc#L3715 I think there are also some places in RTL where filter iterators could be used, e.g. "iterate over all MEMs in an RTL" could be made to look something like that: for (auto&& i : filter_rtl (my_rtl_obj, MEM_P)) ... Anyway, maybe it can plant some ideas. Cheers, Oleg