From patchwork Wed Oct 2 14:57:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 279760 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D33DC2C00BB for ; Thu, 3 Oct 2013 00:57:13 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=C28kAkeYMdnMPCkw+N/q2Mgxe5vYy21KAtY8EyJeEZvjgd RextqyC8Kf+6hrSqnCe2eHAl2kS7yVYxpppyRwkBvg4XA8a0jiP/4/r/jKEwXF/I wS7gdcndeA5ZFwENac/Wnld84cW7qVch2/I9McUJH3duyPSnoCH2x95EjGPew= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=QaZHK1uIxDfWSirklGOtjr8x2s0=; b=a9KuLOHoiQyzmddiZBOZ aUd5Ah7P/JuyTalMsqx4lEFKmxokr9JDiagXfwjTYHXZ7qvQ9PUq1rl9DnPvI+6d BqrkgMmPxLiO8CmW1KIY9b5wgjKZxklouYZUvi3vy/SfUcNeF6AYA3+Olu6IIywZ y4Hmnw1GwKbPfR/smUbitJ4= Received: (qmail 3284 invoked by alias); 2 Oct 2013 14:57:07 -0000 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 Received: (qmail 3269 invoked by uid 89); 2 Oct 2013 14:57:06 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Oct 2013 14:57:06 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r92Ev39c009248 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 Oct 2013 10:57:03 -0400 Received: from [10.10.51.176] (vpn-51-176.rdu2.redhat.com [10.10.51.176]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r92Ev1FV020034; Wed, 2 Oct 2013 10:57:02 -0400 Message-ID: <524C343D.5010105@redhat.com> Date: Wed, 02 Oct 2013 10:57:01 -0400 From: Andrew MacLeod User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8 MIME-Version: 1.0 To: gcc-patches , Richard Biener Subject: [patch] move phiopt, ssa-dce and ssa-dom prototypes. X-IsSubscribed: yes Handle a few more prototypes in tree-flow.h There were only 2 routines exported from tree-ssa-phiopts, and neither really belonged there. * I moved nonfreeing_call_p() to gimple.c since it is gimple dependent. blocks_in_phiopt_order() returns basic blocks in an order that guarantees any single predecessor is visited before its successor. After looking around, i think it really belongs in cfganal.c, so I moved it there... unless you can think of somewhere better. I also renamed it to be more generally descriptive: single_pred_before_succ_order... for lack of anything better. tree-ssa-dom.h needed to be created for a few prototypes. The only 2 exports from tree-ssa-dce.c were mark_virtual_operand_for_renaming and mark_virtual_phi_result_for_renaming. I moved them to tree-into-ssa.c which already has mark_virtual_operands_for_renaming (). Names are confusing a bit I find... and do we even need these routines? Aren't all virtual uses based off the one root variable? so isn't all that walking and SET_USE-ing a waste of time? Or is that still needed by the incremental bits? I never really paid attention to how that worked :-) Bootstrapped on x86_64-unknown-linux-gnu, and currently running regressions. Assuming it passes, OK? Andrew * tree-flow.h: Remove some prototypes. * tree-ssa-dce.c (mark_virtual_operand_for_renaming, mark_virtual_phi_result_for_renaming): Move to tree-into-ssa.c. * tree-into-ssa.c (mark_virtual_operand_for_renaming, mark_virtual_phi_result_for_renaming): Relocate here. * tree-into-ssa.h: Add prototypes. * tree-ssa-phiopt.c: (tree_ssa_phiopt_worker) Use single_pred_before_succ_order. (blocks_in_phiopt_order): Rename and move to cfganal.c. (nonfreeing_call_p) Move to gimple.c. * cfganal.c (single_pred_before_succ_order): Move and renamed from tree-ssa-phiopt.c. * basic-block.h (single_pred_before_succ_order): Add prototype. * gimple.c (nonfreeing_call_p): Relocate here. * gimple.h: Add prototype. * tree-ssa-ifcombine.c: Include tree-ssa-phiopt.h. * tree-ssa-dom.h: New file. Relocate prototypes here. * tree-ssa.h: Include tree-ssa-dom.h. Index: tree-flow.h =================================================================== *** tree-flow.h (revision 203113) --- tree-flow.h (working copy) *************** bool tree_node_can_be_shared (tree); *** 248,260 **** tree fold_const_aggregate_ref (tree); tree gimple_fold_stmt_to_constant (gimple, tree (*)(tree)); - /* In tree-ssa-dom.c */ - extern void dump_dominator_optimization_stats (FILE *); - extern void debug_dominator_optimization_stats (void); - int loop_depth_of_name (tree); - tree degenerate_phi_result (gimple); - bool simple_iv_increment_p (gimple); - /* In tree-ssa-copy.c */ extern void propagate_value (use_operand_p, tree); extern void propagate_tree_value (tree *, tree); --- 248,253 ---- *************** struct tree_niter_desc *** 309,318 **** enum tree_code cmp; }; - /* In tree-ssa-phiopt.c */ - bool empty_block_p (basic_block); - basic_block *blocks_in_phiopt_order (void); - bool nonfreeing_call_p (gimple); /* In tree-ssa-loop*.c */ --- 302,307 ---- *************** void tree_transform_and_unroll_loop (str *** 372,381 **** bool contains_abnormal_ssa_name_p (tree); bool stmt_dominates_stmt_p (gimple, gimple); - /* In tree-ssa-dce.c */ - void mark_virtual_operand_for_renaming (tree); - void mark_virtual_phi_result_for_renaming (gimple); - /* In tree-ssa-threadedge.c */ extern void threadedge_initialize_values (void); extern void threadedge_finalize_values (void); --- 361,366 ---- Index: tree-ssa-dce.c =================================================================== *** tree-ssa-dce.c (revision 203112) --- tree-ssa-dce.c (working copy) *************** propagate_necessity (bool aggressive) *** 907,954 **** } } - /* Replace all uses of NAME by underlying variable and mark it - for renaming. This assumes the defining statement of NAME is - going to be removed. */ - - void - mark_virtual_operand_for_renaming (tree name) - { - tree name_var = SSA_NAME_VAR (name); - bool used = false; - imm_use_iterator iter; - use_operand_p use_p; - gimple stmt; - - gcc_assert (VAR_DECL_IS_VIRTUAL_OPERAND (name_var)); - FOR_EACH_IMM_USE_STMT (stmt, iter, name) - { - FOR_EACH_IMM_USE_ON_STMT (use_p, iter) - SET_USE (use_p, name_var); - used = true; - } - if (used) - mark_virtual_operands_for_renaming (cfun); - } - - /* Replace all uses of the virtual PHI result by its underlying variable - and mark it for renaming. This assumes the PHI node is going to be - removed. */ - - void - mark_virtual_phi_result_for_renaming (gimple phi) - { - if (dump_file && (dump_flags & TDF_DETAILS)) - { - fprintf (dump_file, "Marking result for renaming : "); - print_gimple_stmt (dump_file, phi, 0, TDF_SLIM); - fprintf (dump_file, "\n"); - } - - mark_virtual_operand_for_renaming (gimple_phi_result (phi)); - } - - /* Remove dead PHI nodes from block BB. */ static bool --- 907,912 ---- Index: tree-into-ssa.c =================================================================== *** tree-into-ssa.c (revision 203113) --- tree-into-ssa.c (working copy) *************** mark_virtual_operands_for_renaming (stru *** 2869,2874 **** --- 2869,2914 ---- fn->gimple_df->rename_vops = 1; } + /* Replace all uses of NAME by underlying variable and mark it + for renaming. This assumes the defining statement of NAME is + going to be removed. */ + + void + mark_virtual_operand_for_renaming (tree name) + { + tree name_var = SSA_NAME_VAR (name); + bool used = false; + imm_use_iterator iter; + use_operand_p use_p; + gimple stmt; + + gcc_assert (VAR_DECL_IS_VIRTUAL_OPERAND (name_var)); + FOR_EACH_IMM_USE_STMT (stmt, iter, name) + { + FOR_EACH_IMM_USE_ON_STMT (use_p, iter) + SET_USE (use_p, name_var); + used = true; + } + if (used) + mark_virtual_operands_for_renaming (cfun); + } + + /* Replace all uses of the virtual PHI result by its underlying variable + and mark it for renaming. This assumes the PHI node is going to be + removed. */ + + void + mark_virtual_phi_result_for_renaming (gimple phi) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Marking result for renaming : "); + print_gimple_stmt (dump_file, phi, 0, TDF_SLIM); + fprintf (dump_file, "\n"); + } + + mark_virtual_operand_for_renaming (gimple_phi_result (phi)); + } /* Return true if there is any work to be done by update_ssa for function FN. */ Index: tree-into-ssa.h =================================================================== *** tree-into-ssa.h (revision 203113) --- tree-into-ssa.h (working copy) *************** extern void set_current_def (tree, tree) *** 25,30 **** --- 25,32 ---- void delete_update_ssa (void); tree create_new_def_for (tree, gimple, def_operand_p); void mark_virtual_operands_for_renaming (struct function *); + void mark_virtual_operand_for_renaming (tree); + void mark_virtual_phi_result_for_renaming (gimple); bool need_ssa_update_p (struct function *); bool name_registered_for_update_p (tree); void release_ssa_name_after_update_ssa (tree); Index: tree-ssa-phiopt.c =================================================================== *** tree-ssa-phiopt.c (revision 203112) --- tree-ssa-phiopt.c (working copy) *************** tree_ssa_phiopt_worker (bool do_store_el *** 308,314 **** This ensures that we collapse inner ifs before visiting the outer ones, and also that we do not try to visit a removed block. */ ! bb_order = blocks_in_phiopt_order (); n = n_basic_blocks - NUM_FIXED_BLOCKS; for (i = 0; i < n; i++) --- 308,314 ---- This ensures that we collapse inner ifs before visiting the outer ones, and also that we do not try to visit a removed block. */ ! bb_order = single_pred_before_succ_order (); n = n_basic_blocks - NUM_FIXED_BLOCKS; for (i = 0; i < n; i++) *************** tree_ssa_phiopt_worker (bool do_store_el *** 476,534 **** return 0; } - /* Returns the list of basic blocks in the function in an order that guarantees - that if a block X has just a single predecessor Y, then Y is after X in the - ordering. */ - - basic_block * - blocks_in_phiopt_order (void) - { - basic_block x, y; - basic_block *order = XNEWVEC (basic_block, n_basic_blocks); - unsigned n = n_basic_blocks - NUM_FIXED_BLOCKS; - unsigned np, i; - sbitmap visited = sbitmap_alloc (last_basic_block); - - #define MARK_VISITED(BB) (bitmap_set_bit (visited, (BB)->index)) - #define VISITED_P(BB) (bitmap_bit_p (visited, (BB)->index)) - - bitmap_clear (visited); - - MARK_VISITED (ENTRY_BLOCK_PTR); - FOR_EACH_BB (x) - { - if (VISITED_P (x)) - continue; - - /* Walk the predecessors of x as long as they have precisely one - predecessor and add them to the list, so that they get stored - after x. */ - for (y = x, np = 1; - single_pred_p (y) && !VISITED_P (single_pred (y)); - y = single_pred (y)) - np++; - for (y = x, i = n - np; - single_pred_p (y) && !VISITED_P (single_pred (y)); - y = single_pred (y), i++) - { - order[i] = y; - MARK_VISITED (y); - } - order[i] = y; - MARK_VISITED (y); - - gcc_assert (i == n - 1); - n -= np; - } - - sbitmap_free (visited); - gcc_assert (n == 0); - return order; - - #undef MARK_VISITED - #undef VISITED_P - } - /* Replace PHI node element whose edge is E in block BB with variable NEW. Remove the edge from COND_BLOCK which does not lead to BB (COND_BLOCK is known to have two edges, one of which must reach BB). */ --- 476,481 ---- *************** add_or_mark_expr (basic_block bb, tree e *** 1353,1380 **** } } - /* Return true when CALL is a call stmt that definitely doesn't - free any memory or makes it unavailable otherwise. */ - bool - nonfreeing_call_p (gimple call) - { - if (gimple_call_builtin_p (call, BUILT_IN_NORMAL) - && gimple_call_flags (call) & ECF_LEAF) - switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call))) - { - /* Just in case these become ECF_LEAF in the future. */ - case BUILT_IN_FREE: - case BUILT_IN_TM_FREE: - case BUILT_IN_REALLOC: - case BUILT_IN_STACK_RESTORE: - return false; - default: - return true; - } - - return false; - } - class nontrapping_dom_walker : public dom_walker { public: --- 1300,1305 ---- Index: cfganal.c =================================================================== *** cfganal.c (revision 203112) --- cfganal.c (working copy) *************** bitmap_union_of_preds (sbitmap dst, sbit *** 1465,1467 **** --- 1465,1520 ---- *r++ |= *p++; } } + + /* Returns the list of basic blocks in the function in an order that guarantees + that if a block X has just a single predecessor Y, then Y is after X in the + ordering. */ + + basic_block * + single_pred_before_succ_order (void) + { + basic_block x, y; + basic_block *order = XNEWVEC (basic_block, n_basic_blocks); + unsigned n = n_basic_blocks - NUM_FIXED_BLOCKS; + unsigned np, i; + sbitmap visited = sbitmap_alloc (last_basic_block); + + #define MARK_VISITED(BB) (bitmap_set_bit (visited, (BB)->index)) + #define VISITED_P(BB) (bitmap_bit_p (visited, (BB)->index)) + + bitmap_clear (visited); + + MARK_VISITED (ENTRY_BLOCK_PTR); + FOR_EACH_BB (x) + { + if (VISITED_P (x)) + continue; + + /* Walk the predecessors of x as long as they have precisely one + predecessor and add them to the list, so that they get stored + after x. */ + for (y = x, np = 1; + single_pred_p (y) && !VISITED_P (single_pred (y)); + y = single_pred (y)) + np++; + for (y = x, i = n - np; + single_pred_p (y) && !VISITED_P (single_pred (y)); + y = single_pred (y), i++) + { + order[i] = y; + MARK_VISITED (y); + } + order[i] = y; + MARK_VISITED (y); + + gcc_assert (i == n - 1); + n -= np; + } + + sbitmap_free (visited); + gcc_assert (n == 0); + return order; + + #undef MARK_VISITED + #undef VISITED_P + } Index: basic-block.h =================================================================== *** basic-block.h (revision 203112) --- basic-block.h (working copy) *************** extern int dfs_enumerate_from (basic_blo *** 803,808 **** --- 803,809 ---- basic_block *, int, const void *); extern void compute_dominance_frontiers (struct bitmap_head_def *); extern bitmap compute_idf (bitmap, struct bitmap_head_def *); + extern basic_block * single_pred_before_succ_order (void); /* In cfgrtl.c */ extern rtx block_label (basic_block); Index: gimple.c =================================================================== *** gimple.c (revision 203112) --- gimple.c (working copy) *************** gimple_can_coalesce_p (tree name1, tree *** 4418,4421 **** --- 4418,4444 ---- return false; } + + /* Return true when CALL is a call stmt that definitely doesn't + free any memory or makes it unavailable otherwise. */ + bool + nonfreeing_call_p (gimple call) + { + if (gimple_call_builtin_p (call, BUILT_IN_NORMAL) + && gimple_call_flags (call) & ECF_LEAF) + switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call))) + { + /* Just in case these become ECF_LEAF in the future. */ + case BUILT_IN_FREE: + case BUILT_IN_TM_FREE: + case BUILT_IN_REALLOC: + case BUILT_IN_STACK_RESTORE: + return false; + default: + return true; + } + + return false; + } + #include "gt-gimple.h" Index: gimple.h =================================================================== *** gimple.h (revision 203112) --- gimple.h (working copy) *************** extern tree gimple_boolify (tree); *** 1055,1060 **** --- 1055,1061 ---- extern gimple_predicate rhs_predicate_for (tree); extern tree canonicalize_cond_expr_cond (tree); extern void dump_decl_set (FILE *, bitmap); + extern bool nonfreeing_call_p (gimple); /* In omp-low.c. */ extern tree omp_reduction_init (tree, tree); Index: tree-ssa-ifcombine.c =================================================================== *** tree-ssa-ifcombine.c (revision 203112) --- tree-ssa-ifcombine.c (working copy) *************** tree_ssa_ifcombine (void) *** 624,630 **** bool cfg_changed = false; int i; ! bbs = blocks_in_phiopt_order (); calculate_dominance_info (CDI_DOMINATORS); for (i = 0; i < n_basic_blocks - NUM_FIXED_BLOCKS; ++i) --- 624,630 ---- bool cfg_changed = false; int i; ! bbs = single_pred_before_succ_order (); calculate_dominance_info (CDI_DOMINATORS); for (i = 0; i < n_basic_blocks - NUM_FIXED_BLOCKS; ++i) Index: tree-ssa-dom.h =================================================================== *** tree-ssa-dom.h (revision 0) --- tree-ssa-dom.h (working copy) *************** *** 0 **** --- 1,29 ---- + /* Header file for SSA dominator optimizations. + Copyright (C) 2013 Free Software Foundation, Inc. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3, or (at your option) any later + version. + + GCC is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING3. If not see + . */ + + #ifndef GCC_TREE_SSA_DOM_H + #define GCC_TREE_SSA_DOM_H + + extern void dump_dominator_optimization_stats (FILE *); + extern void debug_dominator_optimization_stats (void); + extern int loop_depth_of_name (tree); + extern bool simple_iv_increment_p (gimple); + extern tree degenerate_phi_result (gimple); + + #endif /* GCC_TREE_SSA_DOM_H */ Index: tree-ssa.h =================================================================== *** tree-ssa.h (revision 203112) --- tree-ssa.h (working copy) *************** along with GCC; see the file COPYING3. *** 26,31 **** --- 26,32 ---- #include "gimple-ssa.h" #include "ssa-iterators.h" #include "tree-ssanames.h" + #include "tree-ssa-dom.h" #include "tree-flow.h" /* Mapping for redirected edges. */