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

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