Blame SOURCES/gcc48-rh1468546.patch

13f101
2014-05-05  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
13f101
13f101
	* target.def: Add new target hook.
13f101
	* doc/tm.texi: Regenerate.
13f101
	* targhooks.h (default_keep_leaf_when_profiled): Add prototype.
13f101
	* targhooks.c (default_keep_leaf_when_profiled): New function.
13f101
13f101
2015-04-23  Anton Blanchard  <anton@samba.org>
13f101
13f101
	* config/rs6000/rs6000.c (rs6000_output_function_prologue): No
13f101
	need for -mprofile-kernel to save LR to stack.
13f101
13f101
2016-01-21  Anton Blanchard  <anton@samba.org>
13f101
	    Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
13f101
13f101
	PR target/63354
13f101
	* config/rs6000/linux64.h (TARGET_KEEP_LEAF_WHEN_PROFILED): New
13f101
	#define.
13f101
	* config/rs6000/rs6000.c (rs6000_keep_leaf_when_profiled): New
13f101
	function.
13f101
13f101
	* gcc.target/powerpc/pr63354.c:  New test.
13f101
13f101
--- gcc/doc/tm.texi
13f101
+++ gcc/doc/tm.texi
13f101
@@ -4953,6 +4953,10 @@ Define this macro if the code for function profiling should come before
13f101
 the function prologue.  Normally, the profiling code comes after.
13f101
 @end defmac
13f101
 
13f101
+@deftypefn {Target Hook} bool TARGET_KEEP_LEAF_WHEN_PROFILED (void)
13f101
+This target hook returns true if the target wants the leaf flag for the current function to stay true even if it calls mcount.  This might make sense for targets using the leaf flag only to determine whether a stack frame needs to be generated or not and for which the call to mcount is generated before the function prologue.
13f101
+@end deftypefn
13f101
+
13f101
 @node Tail Calls
13f101
 @subsection Permitting tail calls
13f101
 @cindex tail calls
13f101
--- gcc/doc/tm.texi.in
13f101
+++ gcc/doc/tm.texi.in
13f101
@@ -3963,6 +3963,8 @@ Define this macro if the code for function profiling should come before
13f101
 the function prologue.  Normally, the profiling code comes after.
13f101
 @end defmac
13f101
 
13f101
+@hook TARGET_KEEP_LEAF_WHEN_PROFILED
13f101
+
13f101
 @node Tail Calls
13f101
 @subsection Permitting tail calls
13f101
 @cindex tail calls
13f101
--- gcc/final.c
13f101
+++ gcc/final.c
13f101
@@ -4241,7 +4241,9 @@ leaf_function_p (void)
13f101
 {
13f101
   rtx insn;
13f101
 
13f101
-  if (crtl->profile || profile_arc_flag)
13f101
+  /* Some back-ends (e.g. s390) want leaf functions to stay leaf
13f101
+     functions even if they call mcount.  */
13f101
+  if (crtl->profile && !targetm.keep_leaf_when_profiled ())
13f101
     return 0;
13f101
 
13f101
   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
13f101
--- gcc/target.def
13f101
+++ gcc/target.def
13f101
@@ -2658,6 +2658,18 @@ The default version of this hook use the target macro\n\
13f101
  bool, (void),
13f101
  default_profile_before_prologue)
13f101
 
13f101
+/* Return true if a leaf function should stay leaf even with profiling
13f101
+   enabled.  */
13f101
+DEFHOOK
13f101
+(keep_leaf_when_profiled,
13f101
+ "This target hook returns true if the target wants the leaf flag for\
13f101
+ the current function to stay true even if it calls mcount.  This might\
13f101
+ make sense for targets using the leaf flag only to determine whether a\
13f101
+ stack frame needs to be generated or not and for which the call to\
13f101
+ mcount is generated before the function prologue.",
13f101
+ bool, (void),
13f101
+ default_keep_leaf_when_profiled)
13f101
+
13f101
 /* Modify and return the identifier of a DECL's external name,
13f101
    originally identified by ID, as required by the target,
13f101
    (eg, append @nn to windows32 stdcall function names).
13f101
--- gcc/targhooks.c
13f101
+++ gcc/targhooks.c
13f101
@@ -1447,6 +1447,15 @@ default_get_reg_raw_mode (int regno)
13f101
   return reg_raw_mode[regno];
13f101
 }
13f101
 
13f101
+/* Return true if a leaf function should stay leaf even with profiling
13f101
+   enabled.  */
13f101
+
13f101
+bool
13f101
+default_keep_leaf_when_profiled ()
13f101
+{
13f101
+  return false;
13f101
+}
13f101
+
13f101
 /* Return true if the state of option OPTION should be stored in PCH files
13f101
    and checked by default_pch_valid_p.  Store the option's current state
13f101
    in STATE if so.  */
13f101
--- gcc/targhooks.h
13f101
+++ gcc/targhooks.h
13f101
@@ -188,6 +188,7 @@ extern section * default_function_sectio
13f101
 					  bool startup, bool exit);
13f101
 extern enum machine_mode default_dwarf_frame_reg_mode (int);
13f101
 extern enum machine_mode default_get_reg_raw_mode(int);
13f101
+extern bool default_keep_leaf_when_profiled ();
13f101
 
13f101
 extern void *default_get_pch_validity (size_t *);
13f101
 extern const char *default_pch_valid_p (const void *, size_t);
13f101
--- gcc/config/rs6000/rs6000.c
13f101
+++ gcc/config/rs6000/rs6000.c
13f101
@@ -24433,7 +24433,6 @@ rs6000_output_function_prologue (FILE *file,
13f101
       gcc_assert (!TARGET_32BIT);
13f101
 
13f101
       asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
13f101
-      asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
13f101
 
13f101
       /* In the ELFv2 ABI we have no compiler stack word.  It must be
13f101
 	 the resposibility of _mcount to preserve the static chain
13f101
--- gcc/config/rs6000/linux64.h
13f101
+++ gcc/config/rs6000/linux64.h
13f101
@@ -59,6 +59,9 @@ extern int dot_symbols;
13f101
 
13f101
 #define TARGET_PROFILE_KERNEL profile_kernel
13f101
 
13f101
+#undef TARGET_KEEP_LEAF_WHEN_PROFILED
13f101
+#define TARGET_KEEP_LEAF_WHEN_PROFILED rs6000_keep_leaf_when_profiled
13f101
+
13f101
 #define TARGET_USES_LINUX64_OPT 1
13f101
 #ifdef HAVE_LD_LARGE_TOC
13f101
 #undef TARGET_CMODEL
13f101
--- gcc/config/rs6000/rs6000.c
13f101
+++ gcc/config/rs6000/rs6000.c
13f101
@@ -26237,6 +26237,14 @@ rs6000_output_function_prologue (FILE *file,
13f101
   rs6000_pic_labelno++;
13f101
 }
13f101
 
13f101
+/* -mprofile-kernel code calls mcount before the function prolog,
13f101
+   so a profiled leaf function should stay a leaf function.  */
13f101
+static bool
13f101
+rs6000_keep_leaf_when_profiled ()
13f101
+{
13f101
+  return TARGET_PROFILE_KERNEL;
13f101
+}
13f101
+
13f101
 /* Non-zero if vmx regs are restored before the frame pop, zero if
13f101
    we restore after the pop when possible.  */
13f101
 #define ALWAYS_RESTORE_ALTIVEC_BEFORE_POP 0
13f101
--- /dev/null
13f101
+++ gcc/testsuite/gcc.target/powerpc/pr63354.c
13f101
@@ -0,0 +1,12 @@
13f101
+/* Verify that we don't stack a frame for leaf functions when using
13f101
+   -pg -mprofile-kernel.  */
13f101
+
13f101
+/* { dg-do compile { target { powerpc64*-*-* } } } */
13f101
+/* { dg-options "-O2 -pg -mprofile-kernel" } */
13f101
+/* { dg-require-effective-target lp64 } */
13f101
+/* { dg-final { scan-assembler-not "mtlr" } } */
13f101
+
13f101
+int foo(void)
13f101
+{
13f101
+  return 1;
13f101
+}