From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 397833850432 for ; Fri, 23 Jul 2021 16:10:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 397833850432 Received: by mail-qk1-x730.google.com with SMTP id 184so1879012qkh.1 for ; Fri, 23 Jul 2021 09:10:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eOuzZQ50FM62w0ma5ZCtmPYd+7YTBM4NJ6ZkgjWn5C4=; b=Np2JKwU9ljiYdsfQoJKxz3/TcVdRK/cnO0iZo2ZA0gCyFhZHwNg16vz1mleCUpVsze nS1WKRuk6jQsBGWG0eDlu/vGCovOyagKJQv7y11MNzY6Z7pm+r+FXUTR4Tzv5CepLdiM jUMxolmVscpX3z3SK2s+exJdDJ4pj/flGXuwvANQ2DDdZdj1Z7kuBZ21POFKO5sLyRxt hQEXWUqSCEizmBJt1dsXETfOToed7fJpRlSiD50YaQ3iGS2HlneD0vkrS1BOZl/plEtt Lv5z9EL/YHJ62njzvf3OtG9dN7/OHmiqi6w3qjbHby8dwgla1H9+isixJ5GpwDhs3Ghy GxEg== X-Gm-Message-State: AOAM532beWrQLYYeKS390mc2mCsVu2MxuG9ho+BUbq1xo5/H7df0XOIa ymXibP6cY3IfZYKGhS0ZHqo= X-Google-Smtp-Source: ABdhPJzC32Q5qo7vM4DMYzeBlmmDY5wfrTw6WXDuyvSZEA0Dcs+XnUYHfvk2rZwHjAC1/JIg0ob7Ug== X-Received: by 2002:a37:b0a:: with SMTP id 10mr5270342qkl.291.1627056641773; Fri, 23 Jul 2021 09:10:41 -0700 (PDT) Received: from [192.168.0.41] (75-166-102-22.hlrn.qwest.net. [75.166.102.22]) by smtp.gmail.com with ESMTPSA id k14sm11961518qtm.18.2021.07.23.09.10.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Jul 2021 09:10:41 -0700 (PDT) Subject: Re: [PATCH v3] Use range-based for loops for traversing loops To: "Kewen.Lin" , GCC Patches Cc: Jakub Jelinek , Jonathan Wakely , Segher Boessenkool , Richard Sandiford , Bill Schmidt , tbsaunde@tbsaunde.org, Richard Biener References: <0a8b77ba-1d54-1eff-b54d-d2cb1e769e09@linux.ibm.com> <79a93b1f-6417-234c-a785-fdc598dfb92c@linux.ibm.com> From: Martin Sebor Message-ID: Date: Fri, 23 Jul 2021 10:10:39 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <79a93b1f-6417-234c-a785-fdc598dfb92c@linux.ibm.com> Content-Type: text/plain; charset=gbk; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jul 2021 16:10:43 -0000 On 7/23/21 2:35 AM, Kewen.Lin wrote: > Hi, > > Comparing to v2, this v3 removed the new CTOR with struct loops *loops > as Richi clarified. I'd like to support it in a separated follow up > patch by extending the existing CTOR with an optional argument loop_p > root. Looks very nice (and quite a bit work)! Thanks again! Not to make even more work for you, but it occurred to me that the declaration of the loop control variable could be simplified by the use of auto like so: for (auto loop: loops_list (cfun, ...)) I spotted what looks to me like a few minor typos in the docs diff: diff --git a/gcc/doc/loop.texi b/gcc/doc/loop.texi index a135656ed01..27697b08728 100644 --- a/gcc/doc/loop.texi +++ b/gcc/doc/loop.texi @@ -79,14 +79,14 @@ and its subloops in the numbering. The index of a loop never changes. The entries of the @code{larray} field should not be accessed directly. The function @code{get_loop} returns the loop description for a loop with -the given index. @code{number_of_loops} function returns number of -loops in the function. To traverse all loops, use @code{FOR_EACH_LOOP} -macro. The @code{flags} argument of the macro is used to determine -the direction of traversal and the set of loops visited. Each loop is -guaranteed to be visited exactly once, regardless of the changes to the -loop tree, and the loops may be removed during the traversal. The newly -created loops are never traversed, if they need to be visited, this -must be done separately after their creation. +the given index. @code{number_of_loops} function returns number of loops +in the function. To traverse all loops, use range-based for loop with Missing article: use a range-based for loop +class @code{loop_list} instance. The @code{flags} argument of the macro Is that loop_list or loops_list? IIUC, it's also not a macro anymore, right? The flags argument is passed to the loop_list ctor, no? Martin > > Bootstrapped and regtested again on powerpc64le-linux-gnu P9, > x86_64-redhat-linux and aarch64-linux-gnu, also > bootstrapped again on ppc64le P9 with bootstrap-O3 config. > > Is it ok for trunk? > > BR, > Kewen > ----- > gcc/ChangeLog: > > * cfgloop.h (as_const): New function. > (class loop_iterator): Rename to ... > (class loops_list): ... this. > (loop_iterator::next): Rename to ... > (loops_list::Iter::fill_curr_loop): ... this and adjust. > (loop_iterator::loop_iterator): Rename to ... > (loops_list::loops_list): ... this and adjust. > (loops_list::Iter): New class. > (loops_list::iterator): New type. > (loops_list::const_iterator): New type. > (loops_list::begin): New function. > (loops_list::end): Likewise. > (loops_list::begin const): Likewise. > (loops_list::end const): Likewise. > (FOR_EACH_LOOP): Remove. > (FOR_EACH_LOOP_FN): Remove. > * cfgloop.c (flow_loops_dump): Adjust FOR_EACH_LOOP* with range-based > for loop with loops_list instance. > (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. >