On 7/19/21 12:20 AM, Kewen.Lin wrote:
Hi,

This patch follows Martin's suggestion here[1], to support
range-based for loops for traversing loops, analogously to
the patch for vec[2].

Bootstrapped and regtested on powerpc64le-linux-gnu P9,
x86_64-redhat-linux and aarch64-linux-gnu, also
bootstrapped on ppc64le P9 with bootstrap-O3 config.

Any comments are appreciated.

Thanks for this nice cleanup!  Just a few suggestions:

I would recommend against introducing new macros unless they
offer a significant advantage over alternatives (for the two
macros the patch adds I don't think they do).

If improving const-correctness is one of our a goals
the loops_list iterator type would need to a corresponding
const_iterator type, and const overloads of the begin()
and end() member functions.

Rather than introducing more instances of the loop_p typedef
I'd suggest to use loop *.  It has at least two advantages:
it's clearer (it's obvious it refers to a pointer), and lends
itself more readily to making code const-correct by declaring
the control variable const: for (const class loop *loop: ...)
while avoiding the mistake of using const loop_p loop to
declare a pointer to a const loop.

Martin


BR,
Kewen

[1] https://gcc.gnu.org/pipermail/gcc-patches/2021-June/573424.html
[2] https://gcc.gnu.org/pipermail/gcc-patches/2021-June/572315.html
-----
gcc/ChangeLog:

        * cfgloop.h (class loop_iterator): Rename to ...
        (class loops_list): ... this.
        (loop_iterator::next): Rename to ...
        (loops_list::iterator::fill_curr_loop): ... this and adjust.
        (loop_iterator::loop_iterator): Rename to ...
        (loops_list::loops_list): ... this and adjust.
        (FOR_EACH_LOOP): Rename to ...
        (ALL_LOOPS): ... this.
        (FOR_EACH_LOOP_FN): Rename to ...
        (ALL_LOOPS_FN): this.
        (loops_list::iterator): New class.
        (loops_list::begin): New function.
        (loops_list::end): Likewise.
        * cfgloop.c (flow_loops_dump): Adjust FOR_EACH_LOOP* with ALL_LOOPS*.
        (sort_sibling_loops): Likewise.
        (disambiguate_loops_with_multiple_latches): Likewise.
        (verify_loop_structure): Likewise.
        * cfgloopmanip.c (create_preheaders): Likewise.
        (force_single_succ_latches): Likewise.
        * config/aarch64/falkor-tag-collision-avoidance.c
        (execute_tag_collision_avoidance): Likewise.
        * config/mn10300/mn10300.c (mn10300_scan_for_setlb_lcc): Likewise.
        * config/s390/s390.c (s390_adjust_loops): Likewise.
        * doc/loop.texi: Likewise.
        * gimple-loop-interchange.cc (pass_linterchange::execute): Likewise.
        * gimple-loop-jam.c (tree_loop_unroll_and_jam): Likewise.
        * gimple-loop-versioning.cc (loop_versioning::analyze_blocks): Likewise.
        (loop_versioning::make_versioning_decisions): Likewise.
        * gimple-ssa-split-paths.c (split_paths): Likewise.
        * graphite-isl-ast-to-gimple.c (graphite_regenerate_ast_isl): Likewise.
        * graphite.c (canonicalize_loop_form): Likewise.
        (graphite_transform_loops): Likewise.
        * ipa-fnsummary.c (analyze_function_body): Likewise.
        * ipa-pure-const.c (analyze_function): Likewise.
        * loop-doloop.c (doloop_optimize_loops): Likewise.
        * loop-init.c (loop_optimizer_finalize): Likewise.
        (fix_loop_structure): Likewise.
        * loop-invariant.c (calculate_loop_reg_pressure): Likewise.
        (move_loop_invariants): Likewise.
        * loop-unroll.c (decide_unrolling): Likewise.
        (unroll_loops): Likewise.
        * modulo-sched.c (sms_schedule): Likewise.
        * predict.c (predict_loops): Likewise.
        (pass_profile::execute): Likewise.
        * profile.c (branch_prob): Likewise.
        * sel-sched-ir.c (sel_finish_pipelining): Likewise.
        (sel_find_rgns): Likewise.
        * tree-cfg.c (replace_loop_annotate): Likewise.
        (replace_uses_by): Likewise.
        (move_sese_region_to_fn): Likewise.
        * tree-if-conv.c (pass_if_conversion::execute): Likewise.
        * tree-loop-distribution.c (loop_distribution::execute): Likewise.
        * tree-parloops.c (parallelize_loops): Likewise.
        * tree-predcom.c (tree_predictive_commoning): Likewise.
        * tree-scalar-evolution.c (scev_initialize): Likewise.
        (scev_reset): Likewise.
        * tree-ssa-dce.c (find_obviously_necessary_stmts): Likewise.
        * tree-ssa-live.c (remove_unused_locals): Likewise.
        * tree-ssa-loop-ch.c (ch_base::copy_headers): Likewise.
        * tree-ssa-loop-im.c (analyze_memory_references): Likewise.
        (tree_ssa_lim_initialize): Likewise.
        * tree-ssa-loop-ivcanon.c (canonicalize_induction_variables): Likewise.
        * tree-ssa-loop-ivopts.c (tree_ssa_iv_optimize): Likewise.
        * tree-ssa-loop-manip.c (get_loops_exits): Likewise.
        * tree-ssa-loop-niter.c (estimate_numbers_of_iterations): Likewise.
        (free_numbers_of_iterations_estimates): Likewise.
        * tree-ssa-loop-prefetch.c (tree_ssa_prefetch_arrays): Likewise.
        * tree-ssa-loop-split.c (tree_ssa_split_loops): Likewise.
        * tree-ssa-loop-unswitch.c (tree_ssa_unswitch_loops): Likewise.
        * tree-ssa-loop.c (gate_oacc_kernels): Likewise.
        (pass_scev_cprop::execute): Likewise.
        * tree-ssa-propagate.c (clean_up_loop_closed_phi): Likewise.
        * tree-ssa-sccvn.c (do_rpo_vn): Likewise.
        * tree-ssa-threadupdate.c
        (jump_thread_path_registry::thread_through_all_blocks): Likewise.
        * tree-vectorizer.c (vectorize_loops): Likewise.
        * tree-vrp.c (vrp_asserts::find_assert_locations): Likewise.


Reply via email to