From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17167 invoked by alias); 12 Oct 2011 06:51:13 -0000 Received: (qmail 17157 invoked by uid 22791); 12 Oct 2011 06:51:12 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 12 Oct 2011 06:50:54 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=EU1-MAIL.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1RDseT-0001ag-W9 from Maxim_Kuvyrkov@mentor.com for gcc-patches@gcc.gnu.org; Tue, 11 Oct 2011 23:50:54 -0700 Received: from [127.0.0.1] ([172.16.63.104]) by EU1-MAIL.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.1830); Wed, 12 Oct 2011 07:50:52 +0100 From: Maxim Kuvyrkov Content-Type: multipart/mixed; boundary="Apple-Mail=_92CF55F1-0E9C-44C0-8BFA-7187BFB39818" Subject: [PATCH] Add capability to run several iterations of early optimizations Date: Wed, 12 Oct 2011 08:14:00 -0000 Message-Id: To: GCC Patches Mime-Version: 1.0 (Apple Message framework v1244.3) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-10/txt/msg00959.txt.bz2 --Apple-Mail=_92CF55F1-0E9C-44C0-8BFA-7187BFB39818 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Content-length: 1496 The following patch adds new knob to make GCC perform several iterations of= early optimizations and inlining. This is for dont-care-about-compile-time-optimize-all-you-can scenarios. P= erforming several iterations of optimizations does significantly improve co= de speed on a certain proprietary source base. Some hand-tuning of the par= ameter value is required to get optimum performance. Another good use for = this option is for search and ad-hoc analysis of cases where GCC misses opt= imization opportunities. With the default setting of '1', nothing is changed from the current status= quo. The patch was bootstrapped and regtested with 3 iterations set by default o= n i686-linux-gnu. The only failures in regression testsuite were due to la= tent bugs in handling of EH information, which are being discussed in a dif= ferent thread. Performance impact on the standard benchmarks is not conclusive, there are = improvements in SPEC2000 of up to 4% and regressions down to -2%, see [*]. = SPEC2006 benchmarks will take another day or two to complete and I will up= date the spreadsheet then. The benchmarks were run on a Core2 system for a= ll combinations of {-m32/-m64}{-O2/-O3}. Effect on compilation time is fairly predictable, about 10% compile time in= crease with 3 iterations. OK for trunk? [*] https://docs.google.com/spreadsheet/ccc?key=3D0AvK0Y-Pgj7bNdFBQMEJ6d3la= eFdvdk9lQ1p0LUFkVFE&hl=3Den_US Thank you, -- Maxim Kuvyrkov CodeSourcery / Mentor Graphics --Apple-Mail=_92CF55F1-0E9C-44C0-8BFA-7187BFB39818 Content-Disposition: attachment; filename=fsf-gcc-iter-eipa.ChangeLog Content-Type: application/octet-stream; name="fsf-gcc-iter-eipa.ChangeLog" Content-Transfer-Encoding: 7bit Content-length: 429 2011-10-11 Maxim Kuvyrkov Add scheduling of several iterations of early IPA passes. * doc/invoke.texi (eipa-iterations): Document new parameter. * params.def (PARAM_EIPA_ITERATIONS): Define. * passes.c (init_optimization_passes): Schedule several iterations of pass_all_early_optimizations. * toplev.c (general_init, toplev_main): Move init_optimizations_passes after processing of arguments. --Apple-Mail=_92CF55F1-0E9C-44C0-8BFA-7187BFB39818 Content-Disposition: attachment; filename=fsf-gcc-iter-eipa.patch Content-Type: application/octet-stream; name="fsf-gcc-iter-eipa.patch" Content-Transfer-Encoding: 7bit Content-length: 4741 commit a54b6cb0160d5413499e08a87da3a35eb6e29652 Author: Maxim Kuvyrkov Date: Sat Oct 1 01:09:50 2011 -0700 Add iterative optimization passes diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index c92c6b2..1ebaf35 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -9060,6 +9060,12 @@ the parameter is reserved exclusively for debug insns created by @option{-fvar-tracking-assignments}, but debug insns may get (non-overlapping) uids above it if the reserved range is exhausted. +@item eipa-iterations +The pass scheduler will execute @option{eipa-iterations} iterations of +early optimization passes before running interprocedural analysis. +Running several iterations of optimization passes allows the compiler +to provide thoroughly optimized code to the interprocedural analysis. + @item ipa-sra-ptr-growth-factor IPA-SRA will replace a pointer to an aggregate with one or more new parameters only when their cumulative size is less or equal to diff --git a/gcc/params.def b/gcc/params.def index 5e49c48..9609919 100644 --- a/gcc/params.def +++ b/gcc/params.def @@ -861,6 +861,11 @@ DEFPARAM (PARAM_MIN_NONDEBUG_INSN_UID, "The minimum UID to be used for a nondebug insn", 0, 1, 0) +DEFPARAM (PARAM_EIPA_ITERATIONS, + "eipa-iterations", + "Number of iterations of early optimizations before IPA analysis", + 1, 1, 0) + DEFPARAM (PARAM_IPA_SRA_PTR_GROWTH_FACTOR, "ipa-sra-ptr-growth-factor", "Maximum allowed growth of size of new parameters ipa-sra replaces " diff --git a/gcc/passes.c b/gcc/passes.c index 887007f..dcc3297 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -1191,6 +1191,7 @@ init_optimization_passes (void) NEXT_PASS (pass_early_local_passes); { struct opt_pass **p = &pass_early_local_passes.pass.sub; + int i; NEXT_PASS (pass_fixup_cfg); NEXT_PASS (pass_init_datastructures); NEXT_PASS (pass_expand_omp); @@ -1199,12 +1200,29 @@ init_optimization_passes (void) NEXT_PASS (pass_build_ssa); NEXT_PASS (pass_lower_vector); NEXT_PASS (pass_early_warn_uninitialized); - NEXT_PASS (pass_rebuild_cgraph_edges); - NEXT_PASS (pass_inline_parameters); - NEXT_PASS (pass_early_inline); - NEXT_PASS (pass_all_early_optimizations); + + /* Schedule PARAM_EIPA_ITERATIONS iterations of early optimizations. + We run these passes at least once as pass_all_early_optimizations. */ + gcc_assert (PARAM_VALUE (PARAM_EIPA_ITERATIONS) >= 1); + for (i = 0; i < PARAM_VALUE (PARAM_EIPA_ITERATIONS); ++i) { - struct opt_pass **p = &pass_all_early_optimizations.pass.sub; + struct opt_pass **q; + + NEXT_PASS (pass_rebuild_cgraph_edges); + NEXT_PASS (pass_inline_parameters); + NEXT_PASS (pass_early_inline); + + { + struct opt_pass **r; + r = p; + NEXT_PASS (pass_all_early_optimizations); + /* (*R) is the pointer to the newly allocated instance of + pass_all_early_optimizations. */ + q = &(*r)->next; + /* Push to sub-pass. */ + p = &(*r)->sub; + } + NEXT_PASS (pass_remove_cgraph_callee_edges); NEXT_PASS (pass_rename_ssa_copies); NEXT_PASS (pass_ccp); @@ -1222,13 +1240,19 @@ init_optimization_passes (void) NEXT_PASS (pass_early_ipa_sra); NEXT_PASS (pass_tail_recursion); NEXT_PASS (pass_convert_switch); - NEXT_PASS (pass_cleanup_eh); - NEXT_PASS (pass_profile); - NEXT_PASS (pass_local_pure_const); + NEXT_PASS (pass_cleanup_eh); + if (i == PARAM_VALUE (PARAM_EIPA_ITERATIONS) - 1) + /* Schedule pass_profile only for the last iteration. + This pass assumes that it is run only once. */ + NEXT_PASS (pass_profile); + NEXT_PASS (pass_local_pure_const); /* Split functions creates parts that are not run through early optimizations again. It is thus good idea to do this late. */ - NEXT_PASS (pass_split_functions); + NEXT_PASS (pass_split_functions); + + /* Pop from sub-pass. */ + p = q; } NEXT_PASS (pass_release_ssa_names); NEXT_PASS (pass_rebuild_cgraph_edges); diff --git a/gcc/toplev.c b/gcc/toplev.c index ab6b5a4..a0ad17d 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -1224,7 +1224,6 @@ general_init (const char *argv0) /* This must be done after global_init_params but before argument processing. */ init_ggc_heuristics(); - init_optimization_passes (); statistics_early_init (); finish_params (); } @@ -1984,6 +1983,8 @@ toplev_main (int argc, char **argv) save_decoded_options, save_decoded_options_count, UNKNOWN_LOCATION, global_dc); + init_optimization_passes (); + handle_common_deferred_options (); init_local_tick (); --Apple-Mail=_92CF55F1-0E9C-44C0-8BFA-7187BFB39818--