From patchwork Fri Sep 23 08:21:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 673956 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sgRDb2Y4Cz9sBg for ; Fri, 23 Sep 2016 18:22:23 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=QrYZ3kJI; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; q=dns; s=default; b=ECN9yQn6EoKdVaR7D3f /n7IhOQRcHoRclSx9dsPQNeQBwvg0A+TUJQJzJYIUkSMrHKuo8AGeMtlSOAHY+ky hZYjZRh6solgVfITr+z2faiIPS/6qgp9+xEzVboeZ3W+OH79YUrBZm1tbrk4OhVE OQO9+Dlc8uzJbtIhsFfjFiRY= 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:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; s=default; bh=VJWj+i+FpaAIxmdGpQNHE5jzE 8M=; b=QrYZ3kJIBqjxgCvbz8coLfVmF25H+RS7alB0uhOZMOH1x9AfFY/yQfUda ElAO4YPiGCDHTd/9ksCunzPDj2ChET+h6XBPbVScaIKMS/PU7//UxkAsQ/o3BN7P rqkOLtSjvjXVOIDv7X6fwB6snz6pA79tY4/Ktwu/RShnMisaME= Received: (qmail 127311 invoked by alias); 23 Sep 2016 08:22:14 -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 127293 invoked by uid 89); 23 Sep 2016 08:22:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Protection, basic_block, U*segher, D*crashing.org X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 23 Sep 2016 08:22:03 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id AE7401C043A; Fri, 23 Sep 2016 08:22:01 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: law@redhat.com, dje.gcc@gmail.com, Segher Boessenkool Subject: [PATCH 1/5] separate shrink-wrap: New command-line flag, status flag, hooks, and doc Date: Fri, 23 Sep 2016 08:21:10 +0000 Message-Id: <65d50574d86ab36c76adeee684a863e5b1a1a975.1474616087.git.segher@kernel.crashing.org> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes This patch adds a new command-line flag "-fshrink-wrap-separate", a status flag "shrink_wrapped_separate", hooks for abstracting the target components, and documentation for all those. 2016-09-23 Segher Boessenkool * common.opt (-fshrink-wrap-separate): New flag. * doc/invoke.texi: Document it. * doc/tm.texi.in (Shrink-wrapping separate components): New subsection. * doc/tm.texi: Regenerate. * emit-rtl.h (struct rtl_data): New field shrink_wrapped_separate. * target.def (shrink_wrap): New hook vector. (get_separate_components, components_for_bb, disqualify_components, emit_prologue_components, emit_epilogue_components, set_handled_components): New hooks. --- gcc/common.opt | 4 ++++ gcc/doc/invoke.texi | 11 +++++++++- gcc/doc/tm.texi | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/doc/tm.texi.in | 38 ++++++++++++++++++++++++++++++++ gcc/emit-rtl.h | 4 ++++ gcc/target.def | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 176 insertions(+), 1 deletion(-) diff --git a/gcc/common.opt b/gcc/common.opt index fa1c036..1a38d12 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2189,6 +2189,10 @@ Common Report Var(flag_shrink_wrap) Optimization Emit function prologues only before parts of the function that need it, rather than at the top of the function. +fshrink-wrap-separate +Common Report Var(flag_shrink_wrap_separate) Init(1) Optimization +Shrink-wrap parts of the prologue and epilogue separately. + fsignaling-nans Common Report Var(flag_signaling_nans) Optimization SetByCombined Disable optimizations observable by IEEE signaling NaNs. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 8eb5eff..464b737 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -397,7 +397,8 @@ Objective-C and Objective-C++ Dialects}. -fschedule-insns -fschedule-insns2 -fsection-anchors @gol -fselective-scheduling -fselective-scheduling2 @gol -fsel-sched-pipelining -fsel-sched-pipelining-outer-loops @gol --fsemantic-interposition -fshrink-wrap -fsignaling-nans @gol +-fsemantic-interposition -fshrink-wrap -fshrink-wrap-separate @gol +-fsignaling-nans @gol -fsingle-precision-constant -fsplit-ivs-in-unroller @gol -fsplit-paths @gol -fsplit-wide-types -fssa-backprop -fssa-phiopt @gol @@ -6396,6 +6397,7 @@ compilation time. -fmove-loop-invariants @gol -freorder-blocks @gol -fshrink-wrap @gol +-fshrink-wrap-separate @gol -fsplit-wide-types @gol -fssa-backprop @gol -fssa-phiopt @gol @@ -7306,6 +7308,13 @@ Emit function prologues only before parts of the function that need it, rather than at the top of the function. This flag is enabled by default at @option{-O} and higher. +@item -fshrink-wrap-separate +@opindex fshrink-wrap-separate +Shrink-wrap separate parts of the prologue and epilogue separately, so that +those parts are only executed when needed. +This option is on by default, but has no effect unless @option{-fshrink-wrap} +is also turned on. + @item -fcaller-saves @opindex fcaller-saves Enable allocation of values to registers that are clobbered by diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index ced6274..c439695 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -2924,6 +2924,7 @@ This describes the stack layout and calling conventions. * Function Entry:: * Profiling:: * Tail Calls:: +* Shrink-wrapping separate components:: * Stack Smashing Protection:: * Miscellaneous Register Hooks:: @end menu @@ -4853,6 +4854,68 @@ This hook should add additional registers that are computed by the prologue to t True if a function's return statements should be checked for matching the function's return type. This includes checking for falling off the end of a non-void function. Return false if no such check should be made. @end deftypefn +@node Shrink-wrapping separate components +@subsection Shrink-wrapping separate components +@cindex shrink-wrapping separate components + +The prologue may perform a variety of target dependent tasks such as +saving callee-saved registers, saving the return address, aligning the +stack, creating a stack frame, initializing the PIC register, setting +up the static chain, etc. + +On some targets some of these tasks may be independent of others and +thus may be shrink-wrapped separately. These independent tasks are +referred to as components and are handled generically by the target +independent parts of GCC. + +Using the following hooks those prologue or epilogue components can be +shrink-wrapped separately, so that the initialization (and possibly +teardown) those components do is not done as frequently on execution +paths where this would unnecessary. + +What exactly those components are is up to the target code; the generic +code treats them abstractly, as a bit in an @code{sbitmap}. These +@code{sbitmap}s are allocated by the @code{shrink_wrap.get_separate_components} +and @code{shrink_wrap.components_for_bb} hooks, and deallocated by the +generic code. + +@deftypefn {Target Hook} sbitmap TARGET_SHRINK_WRAP_GET_SEPARATE_COMPONENTS (void) +This hook should return an @code{sbitmap} with the bits set for those +components that can be separately shrink-wrapped in the current function. +Return @code{NULL} if the current function should not get any separate +shrink-wrapping. +Don't define this hook if it would always return @code{NULL}. +If it is defined, the other hooks in this group have to be defined as well. +@end deftypefn + +@deftypefn {Target Hook} sbitmap TARGET_SHRINK_WRAP_COMPONENTS_FOR_BB (basic_block) +This hook should return an @code{sbitmap} with the bits set for those +components where either the prologue component has to be executed before +the @code{basic_block}, or the epilogue component after it, or both. +@end deftypefn + +@deftypefn {Target Hook} void TARGET_SHRINK_WRAP_DISQUALIFY_COMPONENTS (sbitmap @var{components}, edge @var{e}, sbitmap @var{edge_components}, bool @var{is_prologue}) +This hook should clear the bits in the @var{components} bitmap for those +components in @var{edge_components} that the target cannot handle on edge +@var{e}, where @var{is_prologue} says if this is for a prologue or an +epilogue instead. +@end deftypefn + +@deftypefn {Target Hook} void TARGET_SHRINK_WRAP_EMIT_PROLOGUE_COMPONENTS (sbitmap) +Emit prologue insns for the components indicated by the parameter. +@end deftypefn + +@deftypefn {Target Hook} void TARGET_SHRINK_WRAP_EMIT_EPILOGUE_COMPONENTS (sbitmap) +Emit epilogue insns for the components indicated by the parameter. +@end deftypefn + +@deftypefn {Target Hook} void TARGET_SHRINK_WRAP_SET_HANDLED_COMPONENTS (sbitmap) +Mark the components in the parameter as handled, so that the +@code{prologue} and @code{epilogue} named patterns know to ignore those +components. The target code should not hang on to the @code{sbitmap}, it +will be deleted after this call. +@end deftypefn + @node Stack Smashing Protection @subsection Stack smashing protection @cindex stack smashing protection diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index a5714d1..84164bf 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -2530,6 +2530,7 @@ This describes the stack layout and calling conventions. * Function Entry:: * Profiling:: * Tail Calls:: +* Shrink-wrapping separate components:: * Stack Smashing Protection:: * Miscellaneous Register Hooks:: @end menu @@ -3775,6 +3776,43 @@ the function prologue. Normally, the profiling code comes after. @hook TARGET_WARN_FUNC_RETURN +@node Shrink-wrapping separate components +@subsection Shrink-wrapping separate components +@cindex shrink-wrapping separate components + +The prologue may perform a variety of target dependent tasks such as +saving callee-saved registers, saving the return address, aligning the +stack, creating a stack frame, initializing the PIC register, setting +up the static chain, etc. + +On some targets some of these tasks may be independent of others and +thus may be shrink-wrapped separately. These independent tasks are +referred to as components and are handled generically by the target +independent parts of GCC. + +Using the following hooks those prologue or epilogue components can be +shrink-wrapped separately, so that the initialization (and possibly +teardown) those components do is not done as frequently on execution +paths where this would unnecessary. + +What exactly those components are is up to the target code; the generic +code treats them abstractly, as a bit in an @code{sbitmap}. These +@code{sbitmap}s are allocated by the @code{shrink_wrap.get_separate_components} +and @code{shrink_wrap.components_for_bb} hooks, and deallocated by the +generic code. + +@hook TARGET_SHRINK_WRAP_GET_SEPARATE_COMPONENTS + +@hook TARGET_SHRINK_WRAP_COMPONENTS_FOR_BB + +@hook TARGET_SHRINK_WRAP_DISQUALIFY_COMPONENTS + +@hook TARGET_SHRINK_WRAP_EMIT_PROLOGUE_COMPONENTS + +@hook TARGET_SHRINK_WRAP_EMIT_EPILOGUE_COMPONENTS + +@hook TARGET_SHRINK_WRAP_SET_HANDLED_COMPONENTS + @node Stack Smashing Protection @subsection Stack smashing protection @cindex stack smashing protection diff --git a/gcc/emit-rtl.h b/gcc/emit-rtl.h index 52c72b1..0a242b1 100644 --- a/gcc/emit-rtl.h +++ b/gcc/emit-rtl.h @@ -254,6 +254,10 @@ struct GTY(()) rtl_data { /* True if we performed shrink-wrapping for the current function. */ bool shrink_wrapped; + /* True if we performed shrink-wrapping for separate components for + the current function. */ + bool shrink_wrapped_separate; + /* Nonzero if function being compiled doesn't modify the stack pointer (ignoring the prologue and epilogue). This is only valid after pass_stack_ptr_mod has run. */ diff --git a/gcc/target.def b/gcc/target.def index 0e10d6f..c357d65 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -5792,6 +5792,63 @@ DEFHOOK bool, (tree), hook_bool_tree_true) +#undef HOOK_PREFIX +#define HOOK_PREFIX "TARGET_SHRINK_WRAP_" +HOOK_VECTOR (TARGET_SHRINK_WRAP_HOOKS, shrink_wrap) + +DEFHOOK +(get_separate_components, + "This hook should return an @code{sbitmap} with the bits set for those\n\ +components that can be separately shrink-wrapped in the current function.\n\ +Return @code{NULL} if the current function should not get any separate\n\ +shrink-wrapping.\n\ +Don't define this hook if it would always return @code{NULL}.\n\ +If it is defined, the other hooks in this group have to be defined as well.", + sbitmap, (void), + NULL) + +DEFHOOK +(components_for_bb, + "This hook should return an @code{sbitmap} with the bits set for those\n\ +components where either the prologue component has to be executed before\n\ +the @code{basic_block}, or the epilogue component after it, or both.", + sbitmap, (basic_block), + NULL) + +DEFHOOK +(disqualify_components, + "This hook should clear the bits in the @var{components} bitmap for those\n\ +components in @var{edge_components} that the target cannot handle on edge\n\ +@var{e}, where @var{is_prologue} says if this is for a prologue or an\n\ +epilogue instead.", + void, (sbitmap components, edge e, sbitmap edge_components, bool is_prologue), + NULL) + +DEFHOOK +(emit_prologue_components, + "Emit prologue insns for the components indicated by the parameter.", + void, (sbitmap), + NULL) + +DEFHOOK +(emit_epilogue_components, + "Emit epilogue insns for the components indicated by the parameter.", + void, (sbitmap), + NULL) + +DEFHOOK +(set_handled_components, + "Mark the components in the parameter as handled, so that the\n\ +@code{prologue} and @code{epilogue} named patterns know to ignore those\n\ +components. The target code should not hang on to the @code{sbitmap}, it\n\ +will be deleted after this call.", + void, (sbitmap), + NULL) + +HOOK_VECTOR_END (shrink_wrap) +#undef HOOK_PREFIX +#define HOOK_PREFIX "TARGET_" + /* Determine the type of unwind info to emit for debugging. */ DEFHOOK (debug_unwind_info,