From patchwork Mon Aug 13 10:32:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 176902 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id B757C2C0088 for ; Mon, 13 Aug 2012 20:33:36 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1345458817; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=HRInQWA Nw0QIUOxwK13ZALeHz64=; b=G/6BJQKXfvaXG5quG5e8eDbA5a6h694G75D0qqt Rx2JeO/OtgwmiGYJR3xQDrX/QZvLam6W4IlxPOXa6MtA23Oa4RX+s/JCi2hvakA3 kJBnkXdqc3YZkAABxtqhJhHr9EZUM8WB+BNBuvwFnF+USTHjLAWZ7yNRgLZMzUH8 5ztA= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Yu2BWhXvyjtSXiNZ+DoDcRaWZYLVfZY9SQPoAPEkUoORwGOXFq5uHTowPpNPVL H4OEgF6ERD8v83xuN6/zdWX26xEtuivfjWNZ2a0kL9eRUZaniWQ9xoT9UXeWS5PF DDx3xgoRiNu+r0pfOHqceHGqBJGWs40SuwnU7xIw4Df/g=; Received: (qmail 14224 invoked by alias); 13 Aug 2012 10:33:32 -0000 Received: (qmail 14206 invoked by uid 22791); 13 Aug 2012 10:33:31 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=AWL, BAYES_00, FROM_12LTRDOM, KHOP_RCVD_UNTRUST, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, TW_CP 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; Mon, 13 Aug 2012 10:33:17 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1T0rxU-0005dC-BZ from Bernd_Schmidt@mentor.com for gcc-patches@gcc.gnu.org; Mon, 13 Aug 2012 03:33:16 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 13 Aug 2012 03:33:16 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Mon, 13 Aug 2012 11:33:14 +0100 Message-ID: <5028D7D4.3090209@codesourcery.com> Date: Mon, 13 Aug 2012 12:32:52 +0200 From: Bernd Schmidt User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.6esrpre) Gecko/20120730 Thunderbird/10.0.6 MIME-Version: 1.0 To: GCC Patches Subject: Scheduler: Save state at the end of a block Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This is a small patch for sched-rgn that attempts to save DFA state at the end of a basic block and re-use it in successor blocks. This was a customer-requested optimization; I've not seen it make much of a difference in any macro benchmarks. Bootstrapped and tested on x86_64-linux and also tested on c6x-elf. OK? Bernd * sched-int.h (schedule_block): Adjust declaration. * sched-rgn.c (bb_state_array, bb_state): New static variables. (sched_rgn_init): Initialize them. (sched_rgn_free): Free them. (schedule_region): Save scheduling state for future blocks, and pass such state to schedule_block. * params.def (PARAM_SCHED_STATE_EDGE_PROB_CUTOFF): New. * doc/invoke.texi (--param): Document it. * haifa-sched.c (schedule_block): New arg init_state. Use it to initialize state if nonnull. All callers changed. Call advance_one_cycle after scheduling. Index: gcc/sched-ebb.c =================================================================== --- gcc/sched-ebb.c (revision 189284) +++ gcc/sched-ebb.c (working copy) @@ -544,7 +544,7 @@ schedule_ebb (rtx head, rtx tail, bool m /* Make ready list big enough to hold all the instructions from the ebb. */ sched_extend_ready_list (rgn_n_insns); - success = schedule_block (&target_bb); + success = schedule_block (&target_bb, NULL); gcc_assert (success || modulo_scheduling); /* Free ready list. */ Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 189284) +++ gcc/doc/invoke.texi (working copy) @@ -9101,6 +9101,11 @@ The minimal probability of speculation s speculative insns are scheduled. The default value is 40. +@item sched-spec-state-edge-prob-cutoff +The minimum probability an edge must have for the scheduler to save its +state across it. +The default value is 10. + @item sched-mem-true-dep-cost Minimal distance (in CPU cycles) between store and load targeting same memory locations. The default value is 1. Index: gcc/haifa-sched.c =================================================================== --- gcc/haifa-sched.c (revision 189284) +++ gcc/haifa-sched.c (working copy) @@ -5542,7 +5542,7 @@ verify_shadows (void) region. */ bool -schedule_block (basic_block *target_bb) +schedule_block (basic_block *target_bb, state_t init_state) { int i; bool success = modulo_ii == 0; @@ -5573,7 +5573,10 @@ schedule_block (basic_block *target_bb) if (sched_verbose) dump_new_block_header (0, *target_bb, head, tail); - state_reset (curr_state); + if (init_state == NULL) + state_reset (curr_state); + else + memcpy (curr_state, init_state, dfa_state_size); /* Clear the ready list. */ ready.first = ready.veclen - 1; @@ -6029,7 +6032,9 @@ schedule_block (basic_block *target_bb) } if (ls.modulo_epilogue) success = true; + end_schedule: + advance_one_cycle (); if (modulo_ii > 0) { /* Once again, debug insn suckiness: they can be on the ready list Index: gcc/sched-int.h =================================================================== --- gcc/sched-int.h (revision 189284) +++ gcc/sched-int.h (working copy) @@ -1291,7 +1291,7 @@ extern int dep_cost (dep_t); extern int set_priorities (rtx, rtx); extern void sched_setup_bb_reg_pressure_info (basic_block, rtx); -extern bool schedule_block (basic_block *); +extern bool schedule_block (basic_block *, state_t); extern int cycle_issued_insns; extern int issue_rate; Index: gcc/sched-rgn.c =================================================================== --- gcc/sched-rgn.c (revision 189284) +++ gcc/sched-rgn.c (working copy) @@ -125,6 +125,9 @@ int current_blocks; static basic_block *bblst_table; static int bblst_size, bblst_last; +static char *bb_state_array; +static state_t *bb_state; + /* Target info declarations. The block currently being scheduled is referred to as the "target" block, @@ -2974,9 +2977,21 @@ schedule_region (int rgn) curr_bb = first_bb; if (dbg_cnt (sched_block)) { - schedule_block (&curr_bb); + edge f; + + schedule_block (&curr_bb, bb_state[first_bb->index]); gcc_assert (EBB_FIRST_BB (bb) == first_bb); sched_rgn_n_insns += sched_n_insns; + f = find_fallthru_edge (last_bb->succs); + if (f && f->probability * 100 / REG_BR_PROB_BASE >= + PARAM_VALUE (PARAM_SCHED_STATE_EDGE_PROB_CUTOFF)) + { + memcpy (bb_state[f->dest->index], curr_state, + dfa_state_size); + if (sched_verbose >= 5) + fprintf (sched_dump, "saving state for edge %d->%d\n", + f->src->index, f->dest->index); + } } else { @@ -3009,6 +3024,8 @@ schedule_region (int rgn) void sched_rgn_init (bool single_blocks_p) { + int i; + min_spec_prob = ((PARAM_VALUE (PARAM_MIN_SPEC_PROB) * REG_BR_PROB_BASE) / 100); @@ -3020,6 +3037,23 @@ sched_rgn_init (bool single_blocks_p) CONTAINING_RGN (ENTRY_BLOCK) = -1; CONTAINING_RGN (EXIT_BLOCK) = -1; + if (!sel_sched_p ()) + { + bb_state_array = (char *) xmalloc (last_basic_block * dfa_state_size); + bb_state = XNEWVEC (state_t, last_basic_block); + for (i = 0; i < last_basic_block; i++) + { + bb_state[i] = (state_t) (bb_state_array + i * dfa_state_size); + + state_reset (bb_state[i]); + } + } + else + { + bb_state_array = NULL; + bb_state = NULL; + } + /* Compute regions for scheduling. */ if (single_blocks_p || n_basic_blocks == NUM_FIXED_BLOCKS + 1 @@ -3056,6 +3090,9 @@ sched_rgn_init (bool single_blocks_p) void sched_rgn_finish (void) { + free (bb_state_array); + free (bb_state); + /* Reposition the prologue and epilogue notes in case we moved the prologue/epilogue insns. */ if (reload_completed) Index: gcc/params.def =================================================================== --- gcc/params.def (revision 189284) +++ gcc/params.def (working copy) @@ -611,6 +611,11 @@ DEFPARAM(PARAM_SCHED_SPEC_PROB_CUTOFF, "The minimal probability of speculation success (in percents), so that speculative insn will be scheduled.", 40, 0, 100) +DEFPARAM(PARAM_SCHED_STATE_EDGE_PROB_CUTOFF, + "sched-state-edge-prob-cutoff", + "The minimum probability an edge must have for the scheduler to save its state across it.", + 10, 0, 100) + DEFPARAM(PARAM_SELSCHED_MAX_LOOKAHEAD, "selsched-max-lookahead", "The maximum size of the lookahead window of selective scheduling",