Blame SOURCES/gcc48-aarch64-unwind-opt.patch

56d343
2014-08-08  Richard Henderson  <rth@redhat.com>
56d343
56d343
	* config/aarch64/aarch64.c (aarch64_save_or_restore_fprs): Add
56d343
	cfi_ops argument, for restore put REG_CFA_RESTORE notes into
56d343
	*cfi_ops rather than on individual insns.  Cleanup.
56d343
	(aarch64_save_or_restore_callee_save_registers): Likewise.
56d343
	(aarch64_expand_prologue): Adjust caller.
56d343
	(aarch64_expand_epilogue): Likewise.  Cleanup.  Emit queued cfi_ops
56d343
	on the stack restore insn.
56d343
56d343
--- gcc/config/aarch64/aarch64.c	2014-07-15 02:27:16.000000000 -0700
56d343
+++ gcc/config/aarch64/aarch64.c	2014-08-21 12:52:44.190455860 -0700
56d343
@@ -1603,24 +1603,23 @@ aarch64_register_saved_on_entry (int reg
56d343
 
56d343
 static void
56d343
 aarch64_save_or_restore_fprs (int start_offset, int increment,
56d343
-			      bool restore, rtx base_rtx)
56d343
-
56d343
+			      bool restore, rtx base_rtx, rtx *cfi_ops)
56d343
 {
56d343
   unsigned regno;
56d343
   unsigned regno2;
56d343
   rtx insn;
56d343
   rtx (*gen_mem_ref)(enum machine_mode, rtx) = (frame_pointer_needed)? gen_frame_mem : gen_rtx_MEM;
56d343
 
56d343
-
56d343
   for (regno = V0_REGNUM; regno <= V31_REGNUM; regno++)
56d343
     {
56d343
       if (aarch64_register_saved_on_entry (regno))
56d343
 	{
56d343
-	  rtx mem;
56d343
+	  rtx mem, reg1;
56d343
 	  mem = gen_mem_ref (DFmode,
56d343
 			     plus_constant (Pmode,
56d343
 					    base_rtx,
56d343
 					    start_offset));
56d343
+	  reg1 = gen_rtx_REG (DFmode, regno);
56d343
 
56d343
 	  for (regno2 = regno + 1;
56d343
 	       regno2 <= V31_REGNUM
56d343
@@ -1632,54 +1631,51 @@ aarch64_save_or_restore_fprs (int start_
56d343
 	  if (regno2 <= V31_REGNUM &&
56d343
 	      aarch64_register_saved_on_entry (regno2))
56d343
 	    {
56d343
-	      rtx mem2;
56d343
+	      rtx mem2, reg2;
56d343
 	      /* Next highest register to be saved.  */
56d343
 	      mem2 = gen_mem_ref (DFmode,
56d343
 				  plus_constant
56d343
 				  (Pmode,
56d343
 				   base_rtx,
56d343
 				   start_offset + increment));
56d343
+	      reg2 = gen_rtx_REG (DFmode, regno2);
56d343
+
56d343
 	      if (restore == false)
56d343
 		{
56d343
-		  insn = emit_insn
56d343
-		    ( gen_store_pairdf (mem, gen_rtx_REG (DFmode, regno),
56d343
-					mem2, gen_rtx_REG (DFmode, regno2)));
56d343
-
56d343
+		  insn = emit_insn (gen_store_pairdf (mem, reg1, mem2, reg2));
56d343
+		  /* The first part of a frame-related parallel insn
56d343
+		     is always assumed to be relevant to the frame
56d343
+		     calculations; subsequent parts, are only
56d343
+		     frame-related if explicitly marked.  */
56d343
+		  RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
56d343
+		  RTX_FRAME_RELATED_P (insn) = 1;
56d343
 		}
56d343
 	      else
56d343
 		{
56d343
-		  insn = emit_insn
56d343
-		    ( gen_load_pairdf (gen_rtx_REG (DFmode, regno), mem,
56d343
-				       gen_rtx_REG (DFmode, regno2), mem2));
56d343
-
56d343
-		  add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (DFmode, regno));
56d343
-		  add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (DFmode, regno2));
56d343
+		  emit_insn (gen_load_pairdf (reg1, mem, reg2, mem2));
56d343
+		  *cfi_ops = alloc_reg_note (REG_CFA_RESTORE, reg1, *cfi_ops);
56d343
+		  *cfi_ops = alloc_reg_note (REG_CFA_RESTORE, reg2, *cfi_ops);
56d343
 		}
56d343
 
56d343
-		  /* The first part of a frame-related parallel insn
56d343
-		     is always assumed to be relevant to the frame
56d343
-		     calculations; subsequent parts, are only
56d343
-		     frame-related if explicitly marked.  */
56d343
-	      RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0,
56d343
-					    1)) = 1;
56d343
 	      regno = regno2;
56d343
 	      start_offset += increment * 2;
56d343
 	    }
56d343
 	  else
56d343
 	    {
56d343
 	      if (restore == false)
56d343
-		insn = emit_move_insn (mem, gen_rtx_REG (DFmode, regno));
56d343
+		{
56d343
+		  insn = emit_move_insn (mem, reg1);
56d343
+		  RTX_FRAME_RELATED_P (insn) = 1;
56d343
+		}
56d343
 	      else
56d343
 		{
56d343
-		  insn = emit_move_insn (gen_rtx_REG (DFmode, regno), mem);
56d343
-		  add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (DImode, regno));
56d343
+		  emit_move_insn (reg1, mem);
56d343
+		  *cfi_ops = alloc_reg_note (REG_CFA_RESTORE, reg1, *cfi_ops);
56d343
 		}
56d343
 	      start_offset += increment;
56d343
 	    }
56d343
-	  RTX_FRAME_RELATED_P (insn) = 1;
56d343
 	}
56d343
     }
56d343
-
56d343
 }
56d343
 
56d343
 
56d343
@@ -1687,13 +1683,14 @@ aarch64_save_or_restore_fprs (int start_
56d343
    restore's have to happen.  */
56d343
 static void
56d343
 aarch64_save_or_restore_callee_save_registers (HOST_WIDE_INT offset,
56d343
-					    bool restore)
56d343
+					       bool restore, rtx *cfi_ops)
56d343
 {
56d343
   rtx insn;
56d343
   rtx base_rtx = stack_pointer_rtx;
56d343
   HOST_WIDE_INT start_offset = offset;
56d343
   HOST_WIDE_INT increment = UNITS_PER_WORD;
56d343
-  rtx (*gen_mem_ref)(enum machine_mode, rtx) = (frame_pointer_needed)? gen_frame_mem : gen_rtx_MEM;
56d343
+  rtx (*gen_mem_ref)(enum machine_mode, rtx)
56d343
+    = (frame_pointer_needed)? gen_frame_mem : gen_rtx_MEM;
56d343
   unsigned limit = (frame_pointer_needed)? R28_REGNUM: R30_REGNUM;
56d343
   unsigned regno;
56d343
   unsigned regno2;
56d343
@@ -1702,11 +1699,13 @@ aarch64_save_or_restore_callee_save_regi
56d343
     {
56d343
       if (aarch64_register_saved_on_entry (regno))
56d343
 	{
56d343
-	  rtx mem;
56d343
+	  rtx mem, reg1;
56d343
+
56d343
 	  mem = gen_mem_ref (Pmode,
56d343
 			     plus_constant (Pmode,
56d343
 					    base_rtx,
56d343
 					    start_offset));
56d343
+	  reg1 = gen_rtx_REG (DImode, regno);
56d343
 
56d343
 	  for (regno2 = regno + 1;
56d343
 	       regno2 <= limit
56d343
@@ -1718,56 +1717,54 @@ aarch64_save_or_restore_callee_save_regi
56d343
 	  if (regno2 <= limit &&
56d343
 	      aarch64_register_saved_on_entry (regno2))
56d343
 	    {
56d343
-	      rtx mem2;
56d343
+	      rtx mem2, reg2;
56d343
 	      /* Next highest register to be saved.  */
56d343
 	      mem2 = gen_mem_ref (Pmode,
56d343
 				  plus_constant
56d343
 				  (Pmode,
56d343
 				   base_rtx,
56d343
 				   start_offset + increment));
56d343
+	      reg2 = gen_rtx_REG (DImode, regno2);
56d343
+
56d343
 	      if (restore == false)
56d343
 		{
56d343
-		  insn = emit_insn
56d343
-		    ( gen_store_pairdi (mem, gen_rtx_REG (DImode, regno),
56d343
-					mem2, gen_rtx_REG (DImode, regno2)));
56d343
-
56d343
+		  insn = emit_insn (gen_store_pairdi (mem, reg1, mem2, reg2));
56d343
+		  /* The first part of a frame-related parallel insn
56d343
+		     is always assumed to be relevant to the frame
56d343
+		     calculations; subsequent parts, are only
56d343
+		     frame-related if explicitly marked.  */
56d343
+		  RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
56d343
+	  	  RTX_FRAME_RELATED_P (insn) = 1;
56d343
 		}
56d343
 	      else
56d343
 		{
56d343
-		  insn = emit_insn
56d343
-		    ( gen_load_pairdi (gen_rtx_REG (DImode, regno), mem,
56d343
-				     gen_rtx_REG (DImode, regno2), mem2));
56d343
-
56d343
-		  add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (DImode, regno));
56d343
-		  add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (DImode, regno2));
56d343
+		  emit_insn (gen_load_pairdi (reg1, mem, reg2, mem2));
56d343
+		  *cfi_ops = alloc_reg_note (REG_CFA_RESTORE, reg1, *cfi_ops);
56d343
+		  *cfi_ops = alloc_reg_note (REG_CFA_RESTORE, reg2, *cfi_ops);
56d343
 		}
56d343
 
56d343
-		  /* The first part of a frame-related parallel insn
56d343
-		     is always assumed to be relevant to the frame
56d343
-		     calculations; subsequent parts, are only
56d343
-		     frame-related if explicitly marked.  */
56d343
-	      RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0,
56d343
-					    1)) = 1;
56d343
 	      regno = regno2;
56d343
 	      start_offset += increment * 2;
56d343
 	    }
56d343
 	  else
56d343
 	    {
56d343
 	      if (restore == false)
56d343
-		insn = emit_move_insn (mem, gen_rtx_REG (DImode, regno));
56d343
+		{
56d343
+		  insn = emit_move_insn (mem, reg1);
56d343
+	  	  RTX_FRAME_RELATED_P (insn) = 1;
56d343
+		}
56d343
 	      else
56d343
 		{
56d343
-		  insn = emit_move_insn (gen_rtx_REG (DImode, regno), mem);
56d343
-		  add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (DImode, regno));
56d343
+		  emit_move_insn (reg1, mem);
56d343
+		  *cfi_ops = alloc_reg_note (REG_CFA_RESTORE, reg1, *cfi_ops);
56d343
 		}
56d343
 	      start_offset += increment;
56d343
 	    }
56d343
-	  RTX_FRAME_RELATED_P (insn) = 1;
56d343
 	}
56d343
     }
56d343
 
56d343
-  aarch64_save_or_restore_fprs (start_offset, increment, restore, base_rtx);
56d343
-
56d343
+  aarch64_save_or_restore_fprs (start_offset, increment, restore,
56d343
+				base_rtx, cfi_ops);
56d343
 }
56d343
 
56d343
 /* AArch64 stack frames generated by this compiler look like:
56d343
@@ -1966,7 +1963,7 @@ aarch64_expand_prologue (void)
56d343
 	}
56d343
 
56d343
       aarch64_save_or_restore_callee_save_registers
56d343
-	(fp_offset + cfun->machine->frame.hardfp_offset, 0);
56d343
+	(fp_offset + cfun->machine->frame.hardfp_offset, 0, NULL);
56d343
     }
56d343
 
56d343
   /* when offset >= 512,
56d343
@@ -1991,6 +1988,7 @@ aarch64_expand_epilogue (bool for_sibcal
56d343
   HOST_WIDE_INT fp_offset;
56d343
   rtx insn;
56d343
   rtx cfa_reg;
56d343
+  rtx cfi_ops = NULL;
56d343
 
56d343
   aarch64_layout_frame ();
56d343
   original_frame_size = get_frame_size () + cfun->machine->saved_varargs_size;
56d343
@@ -2035,15 +2033,17 @@ aarch64_expand_epilogue (bool for_sibcal
56d343
       insn = emit_insn (gen_add3_insn (stack_pointer_rtx,
56d343
 				       hard_frame_pointer_rtx,
56d343
 				       GEN_INT (- fp_offset)));
56d343
+      /* CFA should be calculated from the value of SP from now on.  */
56d343
+      add_reg_note (insn, REG_CFA_ADJUST_CFA,
56d343
+		    gen_rtx_SET (VOIDmode, stack_pointer_rtx,
56d343
+				 plus_constant (Pmode, hard_frame_pointer_rtx,
56d343
+						-fp_offset)));
56d343
       RTX_FRAME_RELATED_P (insn) = 1;
56d343
-      /* As SP is set to (FP - fp_offset), according to the rules in
56d343
-	 dwarf2cfi.c:dwarf2out_frame_debug_expr, CFA should be calculated
56d343
-	 from the value of SP from now on.  */
56d343
       cfa_reg = stack_pointer_rtx;
56d343
     }
56d343
 
56d343
   aarch64_save_or_restore_callee_save_registers
56d343
-    (fp_offset + cfun->machine->frame.hardfp_offset, 1);
56d343
+    (fp_offset + cfun->machine->frame.hardfp_offset, 1, &cfi_ops);
56d343
 
56d343
   /* Restore the frame pointer and lr if the frame pointer is needed.  */
56d343
   if (offset > 0)
56d343
@@ -2051,6 +2051,8 @@ aarch64_expand_epilogue (bool for_sibcal
56d343
       if (frame_pointer_needed)
56d343
 	{
56d343
 	  rtx mem_fp, mem_lr;
56d343
+	  rtx reg_fp = hard_frame_pointer_rtx;
56d343
+	  rtx reg_lr = gen_rtx_REG (DImode, LR_REGNUM);
56d343
 
56d343
 	  if (fp_offset)
56d343
 	    {
56d343
@@ -2063,52 +2065,36 @@ aarch64_expand_epilogue (bool for_sibcal
56d343
 						     stack_pointer_rtx,
56d343
 						     fp_offset
56d343
 						     + UNITS_PER_WORD));
56d343
-	      insn = emit_insn (gen_load_pairdi (hard_frame_pointer_rtx,
56d343
-						 mem_fp,
56d343
-						 gen_rtx_REG (DImode,
56d343
-							      LR_REGNUM),
56d343
-						 mem_lr));
56d343
+	      emit_insn (gen_load_pairdi (reg_fp, mem_fp, reg_lr, mem_lr));
56d343
+
56d343
+	      insn = emit_insn (gen_add2_insn (stack_pointer_rtx,
56d343
+					       GEN_INT (offset)));
56d343
 	    }
56d343
 	  else
56d343
 	    {
56d343
 	      insn = emit_insn (gen_loadwb_pairdi_di
56d343
-				(stack_pointer_rtx,
56d343
-				 stack_pointer_rtx,
56d343
-				 hard_frame_pointer_rtx,
56d343
-				 gen_rtx_REG (DImode, LR_REGNUM),
56d343
-				 GEN_INT (offset),
56d343
+				(stack_pointer_rtx, stack_pointer_rtx,
56d343
+				 reg_fp, reg_lr, GEN_INT (offset),
56d343
 				 GEN_INT (GET_MODE_SIZE (DImode) + offset)));
56d343
-	      RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 2)) = 1;
56d343
-	      add_reg_note (insn, REG_CFA_ADJUST_CFA,
56d343
-			    (gen_rtx_SET (Pmode, stack_pointer_rtx,
56d343
-					  plus_constant (Pmode, cfa_reg,
56d343
-							 offset))));
56d343
-	    }
56d343
-
56d343
-	  /* The first part of a frame-related parallel insn
56d343
-	     is always assumed to be relevant to the frame
56d343
-	     calculations; subsequent parts, are only
56d343
-	     frame-related if explicitly marked.  */
56d343
-	  RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
56d343
-	  RTX_FRAME_RELATED_P (insn) = 1;
56d343
-	  add_reg_note (insn, REG_CFA_RESTORE, hard_frame_pointer_rtx);
56d343
-	  add_reg_note (insn, REG_CFA_RESTORE,
56d343
-			gen_rtx_REG (DImode, LR_REGNUM));
56d343
-
56d343
-	  if (fp_offset)
56d343
-	    {
56d343
-	      insn = emit_insn (gen_add2_insn (stack_pointer_rtx,
56d343
-					       GEN_INT (offset)));
56d343
-	      RTX_FRAME_RELATED_P (insn) = 1;
56d343
 	    }
56d343
+	  cfi_ops = alloc_reg_note (REG_CFA_RESTORE, reg_fp, cfi_ops);
56d343
+	  cfi_ops = alloc_reg_note (REG_CFA_RESTORE, reg_lr, cfi_ops);
56d343
 	}
56d343
       else
56d343
 	{
56d343
 	  insn = emit_insn (gen_add2_insn (stack_pointer_rtx,
56d343
 					   GEN_INT (offset)));
56d343
-	  RTX_FRAME_RELATED_P (insn) = 1;
56d343
 	}
56d343
+      cfi_ops = alloc_reg_note (REG_CFA_ADJUST_CFA,
56d343
+				gen_rtx_SET (VOIDmode, stack_pointer_rtx,
56d343
+					     plus_constant (Pmode, cfa_reg,
56d343
+							    offset)),
56d343
+				cfi_ops);
56d343
+      REG_NOTES (insn) = cfi_ops;
56d343
+      RTX_FRAME_RELATED_P (insn) = 1;
56d343
     }
56d343
+  else
56d343
+    gcc_assert (cfi_ops == NULL);
56d343
 
56d343
   /* Stack adjustment for exception handler.  */
56d343
   if (crtl->calls_eh_return)