Blame SOURCES/gcc48-rh1468546.patch

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