diff mbox

[3/9] Introduce emit_status::ensure_regno_capacity

Message ID 1478898935-46932-4-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm Nov. 11, 2016, 9:15 p.m. UTC
Link to earlier version of the patch:
  https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00278.html

gcc/ChangeLog:
	* emit-rtl.c (gen_reg_rtx): Move regno_pointer_align and
	regno_reg_rtx resizing logic to...
	(emit_status::ensure_regno_capacity): ...this new method.
	(init_emit): Allocate regno_reg_rtx using ggc_cleared_vec_alloc
	rather than ggc_vec_alloc.
	* function.h (emit_status::ensure_regno_capacity): New method.
---
 gcc/emit-rtl.c | 45 ++++++++++++++++++++++++++-------------------
 gcc/function.h |  2 ++
 2 files changed, 28 insertions(+), 19 deletions(-)

Comments

Bernd Schmidt Nov. 14, 2016, 2:17 p.m. UTC | #1
On 11/11/2016 10:15 PM, David Malcolm wrote:
> Link to earlier version of the patch:
>   https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00278.html

Isn't this the same one?


Bernd
David Malcolm Nov. 14, 2016, 2:30 p.m. UTC | #2
On Mon, 2016-11-14 at 15:17 +0100, Bernd Schmidt wrote:
> On 11/11/2016 10:15 PM, David Malcolm wrote:
> > Link to earlier version of the patch:
> >   https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00278.html
> 
> Isn't this the same one?
> 
It is; sorry.  The rest of the patch kit has changed greatly since the
last version; I wanted to post that before the close of stage 1.

I'll work on integrating your earlier comments into the patch today.

Dave
Jeff Law Nov. 23, 2016, 8:12 p.m. UTC | #3
On 11/11/2016 02:15 PM, David Malcolm wrote:
> Link to earlier version of the patch:
>   https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00278.html
>
> gcc/ChangeLog:
> 	* emit-rtl.c (gen_reg_rtx): Move regno_pointer_align and
> 	regno_reg_rtx resizing logic to...
> 	(emit_status::ensure_regno_capacity): ...this new method.
> 	(init_emit): Allocate regno_reg_rtx using ggc_cleared_vec_alloc
> 	rather than ggc_vec_alloc.
> 	* function.h (emit_status::ensure_regno_capacity): New method.
OK.
jeff
diff mbox

Patch

diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index e995899..50cd388 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -1057,29 +1057,35 @@  gen_reg_rtx (machine_mode mode)
   /* Do not call gen_reg_rtx with uninitialized crtl.  */
   gcc_assert (crtl->emit.regno_pointer_align_length);
 
-  /* Make sure regno_pointer_align, and regno_reg_rtx are large
-     enough to have an element for this pseudo reg number.  */
+  int cur_size = crtl->emit.regno_pointer_align_length;
+  if (reg_rtx_no == cur_size)
+    crtl->emit.ensure_regno_capacity (cur_size * 2);
 
-  if (reg_rtx_no == crtl->emit.regno_pointer_align_length)
-    {
-      int old_size = crtl->emit.regno_pointer_align_length;
-      char *tmp;
-      rtx *new1;
+  val = gen_raw_REG (mode, reg_rtx_no);
+  regno_reg_rtx[reg_rtx_no++] = val;
+  return val;
+}
+
+/* Make sure m_regno_pointer_align, and regno_reg_rtx are large
+   enough to have elements in the range 0 <= idx < NEW_SIZE.  */
+
+void
+emit_status::ensure_regno_capacity (int new_size)
+{
+  if (new_size < regno_pointer_align_length)
+    return;
 
-      tmp = XRESIZEVEC (char, crtl->emit.regno_pointer_align, old_size * 2);
-      memset (tmp + old_size, 0, old_size);
-      crtl->emit.regno_pointer_align = (unsigned char *) tmp;
+  int old_size = regno_pointer_align_length;
 
-      new1 = GGC_RESIZEVEC (rtx, regno_reg_rtx, old_size * 2);
-      memset (new1 + old_size, 0, old_size * sizeof (rtx));
-      regno_reg_rtx = new1;
+  char *tmp = XRESIZEVEC (char, regno_pointer_align, new_size);
+  memset (tmp + old_size, 0, new_size - old_size);
+  regno_pointer_align = (unsigned char *) tmp;
 
-      crtl->emit.regno_pointer_align_length = old_size * 2;
-    }
+  rtx *new1 = GGC_RESIZEVEC (rtx, regno_reg_rtx, new_size);
+  memset (new1 + old_size, 0, (new_size - old_size) * sizeof (rtx));
+  regno_reg_rtx = new1;
 
-  val = gen_raw_REG (mode, reg_rtx_no);
-  regno_reg_rtx[reg_rtx_no++] = val;
-  return val;
+  crtl->emit.regno_pointer_align_length = new_size;
 }
 
 /* Return TRUE if REG is a PARM_DECL, FALSE otherwise.  */
@@ -5667,7 +5673,8 @@  init_emit (void)
   crtl->emit.regno_pointer_align
     = XCNEWVEC (unsigned char, crtl->emit.regno_pointer_align_length);
 
-  regno_reg_rtx = ggc_vec_alloc<rtx> (crtl->emit.regno_pointer_align_length);
+  regno_reg_rtx =
+    ggc_cleared_vec_alloc<rtx> (crtl->emit.regno_pointer_align_length);
 
   /* Put copies of all the hard registers into regno_reg_rtx.  */
   memcpy (regno_reg_rtx,
diff --git a/gcc/function.h b/gcc/function.h
index e854c7f..9fe479c 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -34,6 +34,8 @@  struct GTY(()) sequence_stack {
 };
 
 struct GTY(()) emit_status {
+  void ensure_regno_capacity (int new_size);
+
   /* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function.
      After rtl generation, it is 1 plus the largest register number used.  */
   int x_reg_rtx_no;