diff mbox

[ARM] Remove uses of leaf_function_p

Message ID AM5PR0802MB2610BCCACCF1F32737C0D02983830@AM5PR0802MB2610.eurprd08.prod.outlook.com
State New
Headers show

Commit Message

Wilco Dijkstra Dec. 5, 2016, 2:52 p.m. UTC
Using leaf_function_p in a backend is dangerous as it incorrectly returns
false if it is called while in a sequence (for example during prolog/epilog
generation).  Replace all uses with crtl->is_leaf as this is now initialized
early enough in ira.c.  This typically causes no code generation differences
unless there was a bug due to leaf_function_p returning the wrong value.

Bootstrap OK.

ChangeLog:
2016-12-05  Wilco Dijkstra  <wdijkstr@arm.com>

        * gcc/config/arm/arm.h (TARGET_BACKTRACE): Use crtl->is_leaf.
        * gcc/config/arm/arm.c (arm_option_check_internal): Improve comment.
        (thumb_force_lr_save): Use crtl->is_leaf.
        (arm_get_frame_offsets): Remove comment.  Use crtl->is_leaf.
        (thumb_far_jump_used_p): Remove comment.
        (arm_frame_pointer_required): Use crtl->is_leaf.
--
diff mbox

Patch

diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index c8d74623814884fbdbcaa7cb4546f7319dbbaac4..0c50d2d67d1ad33778e9a5507de1839de2457af7 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -126,7 +126,7 @@  extern void (*arm_lang_output_object_attributes_hook)(void);
 #define TARGET_IWMMXT_ABI (TARGET_32BIT && arm_abi == ARM_ABI_IWMMXT)
 #define TARGET_ARM                      (! TARGET_THUMB)
 #define TARGET_EITHER			1 /* (TARGET_ARM | TARGET_THUMB) */
-#define TARGET_BACKTRACE	        (leaf_function_p () \
+#define TARGET_BACKTRACE	        (crtl->is_leaf \
 				         ? TARGET_TPCS_LEAF_FRAME \
 				         : TARGET_TPCS_FRAME)
 #define TARGET_AAPCS_BASED \
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 29dcefd23762ba861b458b8860eb4b4856a9cb02..c1088bf98335acfc4041c68f73c9bfe1cf0c1436 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -2798,8 +2798,7 @@  arm_option_check_internal (struct gcc_options *opts)
   if (TARGET_ARM_P (flags) && !ARM_FSET_HAS_CPU1 (insn_flags, FL_NOTM))
     error ("target CPU does not support ARM mode");
 
-  /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done
-     from here where no function is being compiled currently.  */
+  /* TARGET_BACKTRACE cannot be used here as crtl->is_leaf is not set yet.  */
   if ((TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) && TARGET_ARM_P (flags))
     warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb");
 
@@ -19631,7 +19630,7 @@  static bool
 thumb_force_lr_save (void)
 {
   return !cfun->machine->lr_save_eliminated
-	 && (!leaf_function_p ()
+	 && (!crtl->is_leaf
 	     || thumb_far_jump_used_p ()
 	     || df_regs_ever_live_p (LR_REGNUM));
 }
@@ -19736,7 +19735,6 @@  arm_get_frame_offsets (void)
 {
   struct arm_stack_offsets *offsets;
   unsigned long func_type;
-  int leaf;
   int saved;
   int core_saved;
   HOST_WIDE_INT frame_size;
@@ -19744,16 +19742,6 @@  arm_get_frame_offsets (void)
 
   offsets = &cfun->machine->stack_offsets;
 
-  /* We need to know if we are a leaf function.  Unfortunately, it
-     is possible to be called after start_sequence has been called,
-     which causes get_insns to return the insns for the sequence,
-     not the function, which will cause leaf_function_p to return
-     the incorrect result.
-
-     to know about leaf functions once reload has completed, and the
-     frame size cannot be changed after that time, so we can safely
-     use the cached value.  */
-
   if (reload_completed)
     return offsets;
 
@@ -19761,8 +19749,6 @@  arm_get_frame_offsets (void)
      into an offset once we have determined the size of preceding data.  */
   frame_size = ROUND_UP_WORD (get_frame_size ());
 
-  leaf = leaf_function_p ();
-
   /* Space for variadic functions.  */
   offsets->saved_args = crtl->args.pretend_args_size;
 
@@ -19816,7 +19802,7 @@  arm_get_frame_offsets (void)
 
   /* A leaf function does not need any stack alignment if it has nothing
      on the stack.  */
-  if (leaf && frame_size == 0
+  if (crtl->is_leaf && frame_size == 0
       /* However if it calls alloca(), we have a dynamically allocated
 	 block of BIGGEST_ALIGNMENT on stack, so still do stack alignment.  */
       && ! cfun->calls_alloca)
@@ -23107,9 +23093,6 @@  thumb_far_jump_used_p (void)
   bool far_jump = false;
   unsigned int func_size = 0;
 
-  /* This test is only important for leaf functions.  */
-  /* assert (!leaf_function_p ()); */
-
   /* If we have already decided that far jumps may be used,
      do not bother checking again, and always return true even if
      it turns out that they are not being used.  Once we have made
@@ -26484,7 +26467,7 @@  arm_frame_pointer_required (void)
     return true;
 
   /* The frame pointer is required for non-leaf APCS frames.  */
-  if (TARGET_ARM && TARGET_APCS_FRAME && !leaf_function_p ())
+  if (TARGET_ARM && TARGET_APCS_FRAME && !crtl->is_leaf)
     return true;
 
   /* If we are probing the stack in the prologue, we will have a faulting