This patch adds a new command-line flag "-fshrink-wrap-separate", a status flag "shrink_wrapped_separate", hooks for abstracting the target concerns, and documentation for all those.
2016-06-07 Segher Boessenkool <seg...@kernel.crashing.org> * common.opt (-fshrink-wrap-separate): New flag. * doc/invoke.texi: Document it. * doc/tm.texi.in (Shrink-wrapping separate concerns): 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_concerns, concerns_for_bb, disqualify_concerns, emit_prologue_concerns, emit_epilogue_concerns, set_handled_concerns): New hooks. --- gcc/common.opt | 4 ++++ gcc/doc/invoke.texi | 11 ++++++++++- gcc/doc/tm.texi | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/doc/tm.texi.in | 29 +++++++++++++++++++++++++++ gcc/emit-rtl.h | 4 ++++ gcc/target.def | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 156 insertions(+), 1 deletion(-) diff --git a/gcc/common.opt b/gcc/common.opt index 2bb576c..b00f538 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2153,6 +2153,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 e3a2399..21df5c5 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -394,7 +394,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 @@ -6263,6 +6264,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 @@ -7180,6 +7182,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 b318615..c326599 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 concerns:: * Stack Smashing Protection:: * Miscellaneous Register Hooks:: @end menu @@ -4852,6 +4853,58 @@ 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 concerns +@subsection Shrink-wrapping separate concerns +@cindex shrink-wrapping separate concerns + +The prologue does a lot of separate things: save callee-saved registers, +do whatever needs to be done to be able to call things (save the return +address, align the stack, whatever; different for each target), set up a +stack frame, do whatever needs to be done for the static chain (if anything), +set up registers for PIC, etc. Using the following hooks those concerns +can be shrink-wrapped separately, so that the initialization (and possibly +teardown) for those concerns is not done on execution paths where it is +unnecessary. + +What exactly those concerns are is up to the target code; the generic +code treats them abstractly. + +@deftypefn {Target Hook} sbitmap TARGET_SHRINK_WRAP_GET_SEPARATE_CONCERNS (void) +This hook should return an @code{sbitmap} with the bits set for those +concerns 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_CONCERNS_FOR_BB (basic_block) +This hook should return an @code{sbitmap} with the bits set for those +concerns that the @code{basic_block} needs set up, does set up, or does +otherwise touch. +@end deftypefn + +@deftypefn {Target Hook} void TARGET_SHRINK_WRAP_DISQUALIFY_CONCERNS (sbitmap @var{concerns}, edge @var{e}, sbitmap @var{edge_concerns}, bool @var{is_prologue}) +This hook should clear the bits in the @var{concerns} bitmap for those +concerns in @var{edge_concerns} 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_CONCERNS (sbitmap) +Emit prologue insns for the concerns indicated by the parameter. +@end deftypefn + +@deftypefn {Target Hook} void TARGET_SHRINK_WRAP_EMIT_EPILOGUE_CONCERNS (sbitmap) +Emit epilogue insns for the concerns indicated by the parameter. +@end deftypefn + +@deftypefn {Target Hook} void TARGET_SHRINK_WRAP_SET_HANDLED_CONCERNS (sbitmap) +Mark the concerns in the parameter as handled, so that the @code{prologue} +and @code{epilogue} named patterns know to ignore those concerns. Don't +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 1e8423c..05bb50a 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 concerns:: * Stack Smashing Protection:: * Miscellaneous Register Hooks:: @end menu @@ -3789,6 +3790,34 @@ the function prologue. Normally, the profiling code comes after. @hook TARGET_WARN_FUNC_RETURN +@node Shrink-wrapping separate concerns +@subsection Shrink-wrapping separate concerns +@cindex shrink-wrapping separate concerns + +The prologue does a lot of separate things: save callee-saved registers, +do whatever needs to be done to be able to call things (save the return +address, align the stack, whatever; different for each target), set up a +stack frame, do whatever needs to be done for the static chain (if anything), +set up registers for PIC, etc. Using the following hooks those concerns +can be shrink-wrapped separately, so that the initialization (and possibly +teardown) for those concerns is not done on execution paths where it is +unnecessary. + +What exactly those concerns are is up to the target code; the generic +code treats them abstractly. + +@hook TARGET_SHRINK_WRAP_GET_SEPARATE_CONCERNS + +@hook TARGET_SHRINK_WRAP_CONCERNS_FOR_BB + +@hook TARGET_SHRINK_WRAP_DISQUALIFY_CONCERNS + +@hook TARGET_SHRINK_WRAP_EMIT_PROLOGUE_CONCERNS + +@hook TARGET_SHRINK_WRAP_EMIT_EPILOGUE_CONCERNS + +@hook TARGET_SHRINK_WRAP_SET_HANDLED_CONCERNS + @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 39dfce9..279e580 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 concerns 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 a4df363..0c57cbf 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -5742,6 +5742,62 @@ 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_concerns, + "This hook should return an @code{sbitmap} with the bits set for those\n\ +concerns 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 +(concerns_for_bb, + "This hook should return an @code{sbitmap} with the bits set for those\n\ +concerns that the @code{basic_block} needs set up, does set up, or does\n\ +otherwise touch.", + sbitmap, (basic_block), + NULL) + +DEFHOOK +(disqualify_concerns, + "This hook should clear the bits in the @var{concerns} bitmap for those\n\ +concerns in @var{edge_concerns} 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 concerns, edge e, sbitmap edge_concerns, bool is_prologue), + NULL) + +DEFHOOK +(emit_prologue_concerns, + "Emit prologue insns for the concerns indicated by the parameter.", + void, (sbitmap), + NULL) + +DEFHOOK +(emit_epilogue_concerns, + "Emit epilogue insns for the concerns indicated by the parameter.", + void, (sbitmap), + NULL) + +DEFHOOK +(set_handled_concerns, + "Mark the concerns in the parameter as handled, so that the @code{prologue}\n\ +and @code{epilogue} named patterns know to ignore those concerns. Don't\n\ +hang on to the @code{sbitmap}, it 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, -- 1.9.3