This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] function.[ch]: Use VEC instead of VARRAY.


Hi,

Attached is a patch to use VEC instead of VARRAY.

All these three instances of VEC are lazily allocated, so we don't
need init_function_once any more.  I went ahead and removed that
function.

I simplified record_insns quite a bit.  The original code scans INSNS
twice.  With this patch, the code scans INSNS once using
VEC_safe_push.

Tested on i686-pc-linux-gnu.  I will wait for 24 hours just in case
before I check in this patch.

Kazu Hirata

2005-05-26  Kazu Hirata  <kazu@cs.umass.edu>

	* function.c (prologue, epilogue): Change their types to
	VEC(int,gc)*.
	(init_function_for_compilation, record_insns, contains,
	prologue_epilogue_contains, sibcall_epilogue_contains,
	reposition_prologue_and_epilogue_notes): Use VEC instead of
	VARRAY.  (init_function_once): Remove.
	* function.h: Remove the prototype for init_function_once.
	* toplev.c (backend_init): Don't call init_function_once.

Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.622
diff -u -d -p -r1.622 function.c
--- function.c	12 May 2005 23:52:37 -0000	1.622
+++ function.c	21 May 2005 03:17:32 -0000
@@ -121,13 +121,16 @@ struct machine_function * (*init_machine
 /* The currently compiled function.  */
 struct function *cfun = 0;
 
+DEF_VEC_P(int);
+DEF_VEC_ALLOC_P(int,gc);
+
 /* These arrays record the INSN_UIDs of the prologue and epilogue insns.  */
-static GTY(()) varray_type prologue;
-static GTY(()) varray_type epilogue;
+static GTY(()) VEC(int,gc) *prologue;
+static GTY(()) VEC(int,gc) *epilogue;
 
 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue
    in this function.  */
-static GTY(()) varray_type sibcall_epilogue;
+static GTY(()) VEC(int,gc) *sibcall_epilogue;
 
 /* In order to evaluate some expressions, such as function calls returning
    structures in memory, we need to temporarily allocate stack locations.
@@ -198,8 +201,8 @@ static tree *get_block_vector (tree, int
 extern tree debug_find_var_in_block_tree (tree, tree);
 /* We always define `record_insns' even if it's not used so that we
    can always export `prologue_epilogue_contains'.  */
-static void record_insns (rtx, varray_type *) ATTRIBUTE_UNUSED;
-static int contains (rtx, varray_type);
+static void record_insns (rtx, VEC(int,gc) **) ATTRIBUTE_UNUSED;
+static int contains (rtx, VEC(int,gc) **);
 #ifdef HAVE_return
 static void emit_return_into_block (basic_block, rtx);
 #endif
@@ -3862,9 +3865,9 @@ init_function_for_compilation (void)
   reg_renumber = 0;
 
   /* No prologue/epilogue insns yet.  */
-  VARRAY_GROW (prologue, 0);
-  VARRAY_GROW (epilogue, 0);
-  VARRAY_GROW (sibcall_epilogue, 0);
+  VEC_truncate (int, prologue, 0);
+  VEC_truncate (int, epilogue, 0);
+  VEC_truncate (int, sibcall_epilogue, 0);
 }
 
 void
@@ -4446,28 +4449,12 @@ get_arg_pointer_save_area (struct functi
    (a list of one or more insns).  */
 
 static void
-record_insns (rtx insns, varray_type *vecp)
+record_insns (rtx insns, VEC(int,gc) **vecp)
 {
-  int i, len;
   rtx tmp;
 
-  tmp = insns;
-  len = 0;
-  while (tmp != NULL_RTX)
-    {
-      len++;
-      tmp = NEXT_INSN (tmp);
-    }
-
-  i = VARRAY_SIZE (*vecp);
-  VARRAY_GROW (*vecp, i + len);
-  tmp = insns;
-  while (tmp != NULL_RTX)
-    {
-      VARRAY_INT (*vecp, i) = INSN_UID (tmp);
-      i++;
-      tmp = NEXT_INSN (tmp);
-    }
+  for (tmp = insns; tmp != NULL_RTX; tmp = NEXT_INSN (tmp))
+    VEC_safe_push (int, gc, *vecp, INSN_UID (tmp));
 }
 
 /* Set the locator of the insn chain starting at INSN to LOC.  */
@@ -4486,7 +4473,7 @@ set_insn_locators (rtx insn, int loc)
    be running after reorg, SEQUENCE rtl is possible.  */
 
 static int
-contains (rtx insn, varray_type vec)
+contains (rtx insn, VEC(int,gc) **vec)
 {
   int i, j;
 
@@ -4495,15 +4482,16 @@ contains (rtx insn, varray_type vec)
     {
       int count = 0;
       for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
-	for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
-	  if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == VARRAY_INT (vec, j))
+	for (j = VEC_length (int, *vec) - 1; j >= 0; --j)
+	  if (INSN_UID (XVECEXP (PATTERN (insn), 0, i))
+	      == VEC_index (int, *vec, j))
 	    count++;
       return count;
     }
   else
     {
-      for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
-	if (INSN_UID (insn) == VARRAY_INT (vec, j))
+      for (j = VEC_length (int, *vec) - 1; j >= 0; --j)
+	if (INSN_UID (insn) == VEC_index (int, *vec, j))
 	  return 1;
     }
   return 0;
@@ -4512,9 +4500,9 @@ contains (rtx insn, varray_type vec)
 int
 prologue_epilogue_contains (rtx insn)
 {
-  if (contains (insn, prologue))
+  if (contains (insn, &prologue))
     return 1;
-  if (contains (insn, epilogue))
+  if (contains (insn, &epilogue))
     return 1;
   return 0;
 }
@@ -4523,7 +4511,7 @@ int
 sibcall_epilogue_contains (rtx insn)
 {
   if (sibcall_epilogue)
-    return contains (insn, sibcall_epilogue);
+    return contains (insn, &sibcall_epilogue);
   return 0;
 }
 
@@ -5262,7 +5250,7 @@ reposition_prologue_and_epilogue_notes (
   rtx insn, last, note;
   int len;
 
-  if ((len = VARRAY_SIZE (prologue)) > 0)
+  if ((len = VEC_length (int, prologue)) > 0)
     {
       last = 0, note = 0;
 
@@ -5276,7 +5264,7 @@ reposition_prologue_and_epilogue_notes (
 	      if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
 		note = insn;
 	    }
-	  else if (contains (insn, prologue))
+	  else if (contains (insn, &prologue))
 	    {
 	      last = insn;
 	      if (--len == 0)
@@ -5303,7 +5291,7 @@ reposition_prologue_and_epilogue_notes (
 	}
     }
 
-  if ((len = VARRAY_SIZE (epilogue)) > 0)
+  if ((len = VEC_length (int, epilogue)) > 0)
     {
       last = 0, note = 0;
 
@@ -5317,7 +5305,7 @@ reposition_prologue_and_epilogue_notes (
 	      if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
 		note = insn;
 	    }
-	  else if (contains (insn, epilogue))
+	  else if (contains (insn, &epilogue))
 	    {
 	      last = insn;
 	      if (--len == 0)
@@ -5344,16 +5332,6 @@ reposition_prologue_and_epilogue_notes (
 #endif /* HAVE_prologue or HAVE_epilogue */
 }
 
-/* Called once, at initialization, to initialize function.c.  */
-
-void
-init_function_once (void)
-{
-  VARRAY_INT_INIT (prologue, 0, "prologue");
-  VARRAY_INT_INIT (epilogue, 0, "epilogue");
-  VARRAY_INT_INIT (sibcall_epilogue, 0, "sibcall_epilogue");
-}
-
 /* Resets insn_block_boundaries array.  */
 
 void
Index: function.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.h,v
retrieving revision 1.152
diff -u -d -p -r1.152 function.h
--- function.h	17 May 2005 16:56:23 -0000	1.152
+++ function.h	21 May 2005 03:17:33 -0000
@@ -556,9 +556,6 @@ extern void instantiate_virtual_regs (vo
 /* Returns the name of the current function.  */
 extern const char *current_function_name (void);
 
-/* Called once, at initialization, to initialize function.c.  */
-extern void init_function_once (void);
-
 extern void do_warn_unused_parameter (tree);
 
 extern bool pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.954
diff -u -d -p -r1.954 toplev.c
--- toplev.c	3 May 2005 17:55:38 -0000	1.954
+++ toplev.c	21 May 2005 03:17:35 -0000
@@ -1987,7 +1987,6 @@ backend_init (void)
   init_alias_once ();
   init_loop ();
   init_reload ();
-  init_function_once ();
   init_varasm_once ();
 
   /* The following initialization functions need to generate rtl, so


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]