[patch] Use VEC instead of VARRAY for ib_boundaries_block. (Needs a review)

Kazu Hirata kazu@codesourcery.com
Wed Jan 11 04:45:00 GMT 2006


Hi,

Attached is a patch to use VEC instead of VARRAY for
ib_boundaries_block.

The hunks for function.[ch] do the VEC-to-VARRAY conversion.  Note
that gengtype wants to see a type declaration before that type is used
to declare a variable.  It turns out that when gengtype scans
function.h before tree.h, so it does not what to do with VEC(tree,gc)*
yet.  To solve this problem, I changed the order of GTFILES in
Makefile.in.  Specifically, I put function.h immediately after tree.h.

Also, since function.h uses VEC(tree,gc)* with this patch applied,
function.h needs to include tree.h.

This in turn causes cselib.c to indirectly include
libcpp/include/symtab.h, which does

  typedef struct ht hash_table;

Unfortunately, cselib.c does not like that because it does

  static htab_t hash_table;

So I renamed hash_table in cselib.c to cselib_hash_table throughout
the file.

Tested on x86_pc-linux-gnu.  OK to apply?

Kazu Hirata

2006-01-11  Kazu Hirata  <kazu@codesourcery.com>

	* Makefile.in (GTFILES): Move function.h after tree.h.
	* cselib.c (hash_table): Rename to cselib_hash_table.
	(cselib_clear_table, discard_useless_values,
	remove_useless_values, cselib_lookup_mem, cselib_lookup,
	cselib_init, cselib_finish): Adjust uses of hash_table.
	* function.c (reset_block_changes, record_block_change,
	check_block_change, free_block_changes): Adjust uses of
	ib_boundaries_block.
	* function.h (function): Change the type of
	ib_boundaries_block to VEC(tree,gc)*.
	* tree-inline.c (copy_cfg_body): Use NULL instead of
	(varray_type) 0.

Index: Makefile.in
===================================================================
--- Makefile.in	(revision 109449)
+++ Makefile.in	(working copy)
@@ -2784,8 +2784,8 @@ insn-preds.o : insn-preds.c $(CONFIG_H) 
 GTFILES = $(srcdir)/input.h $(srcdir)/coretypes.h \
   $(CPP_ID_DATA_H) $(host_xm_file_list) \
   $(tm_file_list) $(HASHTAB_H) $(SPLAY_TREE_H) $(srcdir)/bitmap.h \
-  $(srcdir)/coverage.c $(srcdir)/function.h $(srcdir)/rtl.h \
-  $(srcdir)/optabs.h $(srcdir)/tree.h $(srcdir)/libfuncs.h $(SYMTAB_H) \
+  $(srcdir)/coverage.c $(srcdir)/rtl.h \
+  $(srcdir)/optabs.h $(srcdir)/tree.h $(srcdir)/function.h $(srcdir)/libfuncs.h $(SYMTAB_H) \
   $(srcdir)/real.h $(srcdir)/varray.h $(srcdir)/insn-addr.h $(srcdir)/hwint.h \
   $(srcdir)/ipa-reference.h $(srcdir)/output.h \
   $(srcdir)/cselib.h $(srcdir)/basic-block.h  $(srcdir)/cgraph.h \
Index: cselib.c
===================================================================
--- cselib.c	(revision 109449)
+++ cselib.c	(working copy)
@@ -74,7 +74,7 @@ static void cselib_record_sets (rtx);
      the locations of the entries with the rtx we are looking up.  */
 
 /* A table that enables us to look up elts by their value.  */
-static htab_t hash_table;
+static htab_t cselib_hash_table;
 
 /* This is a global so we don't have to pass this through every function.
    It is used in new_elt_loc_list to set SETTING_INSN.  */
@@ -212,7 +212,7 @@ cselib_clear_table (void)
 
   n_used_regs = 0;
 
-  htab_empty (hash_table);
+  htab_empty (cselib_hash_table);
 
   n_useless_values = 0;
 
@@ -332,7 +332,7 @@ discard_useless_values (void **x, void *
   if (v->locs == 0)
     {
       CSELIB_VAL_PTR (v->u.val_rtx) = NULL;
-      htab_clear_slot (hash_table, x);
+      htab_clear_slot (cselib_hash_table, x);
       unchain_one_value (v);
       n_useless_values--;
     }
@@ -352,7 +352,7 @@ remove_useless_values (void)
   do
     {
       values_became_useless = 0;
-      htab_traverse (hash_table, discard_useless_locs, 0);
+      htab_traverse (cselib_hash_table, discard_useless_locs, 0);
     }
   while (values_became_useless);
 
@@ -367,7 +367,7 @@ remove_useless_values (void)
       }
   *p = &dummy_val;
 
-  htab_traverse (hash_table, discard_useless_values, 0);
+  htab_traverse (cselib_hash_table, discard_useless_values, 0);
 
   gcc_assert (!n_useless_values);
 }
@@ -803,7 +803,7 @@ cselib_lookup_mem (rtx x, int create)
 
   mem_elt = new_cselib_val (++next_unknown_value, mode);
   add_mem_for_addr (addr, mem_elt, x);
-  slot = htab_find_slot_with_hash (hash_table, wrap_constant (mode, x),
+  slot = htab_find_slot_with_hash (cselib_hash_table, wrap_constant (mode, x),
 				   mem_elt->value, INSERT);
   *slot = mem_elt;
   return mem_elt;
@@ -954,7 +954,7 @@ cselib_lookup (rtx x, enum machine_mode 
 	  REG_VALUES (i) = new_elt_list (REG_VALUES (i), NULL);
 	}
       REG_VALUES (i)->next = new_elt_list (REG_VALUES (i)->next, e);
-      slot = htab_find_slot_with_hash (hash_table, x, e->value, INSERT);
+      slot = htab_find_slot_with_hash (cselib_hash_table, x, e->value, INSERT);
       *slot = e;
       return e;
     }
@@ -967,7 +967,7 @@ cselib_lookup (rtx x, enum machine_mode 
   if (! hashval)
     return 0;
 
-  slot = htab_find_slot_with_hash (hash_table, wrap_constant (mode, x),
+  slot = htab_find_slot_with_hash (cselib_hash_table, wrap_constant (mode, x),
 				   hashval, create ? INSERT : NO_INSERT);
   if (slot == 0)
     return 0;
@@ -1476,7 +1476,7 @@ cselib_init (bool record_memory)
     }
   used_regs = xmalloc (sizeof (*used_regs) * cselib_nregs);
   n_used_regs = 0;
-  hash_table = htab_create (31, get_value_hash, entry_and_rtx_equal_p, NULL);
+  cselib_hash_table = htab_create (31, get_value_hash, entry_and_rtx_equal_p, NULL);
   cselib_current_insn_in_libcall = false;
 }
 
@@ -1490,10 +1490,10 @@ cselib_finish (void)
   free_alloc_pool (cselib_val_pool);
   free_alloc_pool (value_pool);
   cselib_clear_table ();
-  htab_delete (hash_table);
+  htab_delete (cselib_hash_table);
   free (used_regs);
   used_regs = 0;
-  hash_table = 0;
+  cselib_hash_table = 0;
   n_useless_values = 0;
   next_unknown_value = 0;
 }
Index: function.c
===================================================================
--- function.c	(revision 109449)
+++ function.c	(working copy)
@@ -5499,8 +5499,8 @@ reposition_prologue_and_epilogue_notes (
 void
 reset_block_changes (void)
 {
-  VARRAY_TREE_INIT (cfun->ib_boundaries_block, 100, "ib_boundaries_block");
-  VARRAY_PUSH_TREE (cfun->ib_boundaries_block, NULL_TREE);
+  cfun->ib_boundaries_block = VEC_alloc (tree, gc, 100);
+  VEC_quick_push (tree, cfun->ib_boundaries_block, NULL_TREE);
 }
 
 /* Record the boundary for BLOCK.  */
@@ -5516,13 +5516,12 @@ record_block_change (tree block)
   if(!cfun->ib_boundaries_block)
     return;
 
-  last_block = VARRAY_TOP_TREE (cfun->ib_boundaries_block);
-  VARRAY_POP (cfun->ib_boundaries_block);
+  last_block = VEC_pop (tree, cfun->ib_boundaries_block);
   n = get_max_uid ();
-  for (i = VARRAY_ACTIVE_SIZE (cfun->ib_boundaries_block); i < n; i++)
-    VARRAY_PUSH_TREE (cfun->ib_boundaries_block, last_block);
+  for (i = VEC_length (tree, cfun->ib_boundaries_block); i < n; i++)
+    VEC_safe_push (tree, gc, cfun->ib_boundaries_block, last_block);
 
-  VARRAY_PUSH_TREE (cfun->ib_boundaries_block, block);
+  VEC_safe_push (tree, gc, cfun->ib_boundaries_block, block);
 }
 
 /* Finishes record of boundaries.  */
@@ -5537,17 +5536,17 @@ check_block_change (rtx insn, tree *bloc
 {
   unsigned uid = INSN_UID (insn);
 
-  if (uid >= VARRAY_ACTIVE_SIZE (cfun->ib_boundaries_block))
+  if (uid >= VEC_length (tree, cfun->ib_boundaries_block))
     return;
 
-  *block = VARRAY_TREE (cfun->ib_boundaries_block, uid);
+  *block = VEC_index (tree, cfun->ib_boundaries_block, uid);
 }
 
 /* Releases the ib_boundaries_block records.  */
 void
 free_block_changes (void)
 {
-  cfun->ib_boundaries_block = NULL;
+  VEC_free (tree, gc, cfun->ib_boundaries_block);
 }
 
 /* Returns the name of the current function.  */
Index: function.h
===================================================================
--- function.h	(revision 109449)
+++ function.h	(working copy)
@@ -22,6 +22,8 @@ Software Foundation, 51 Franklin Street,
 #ifndef GCC_FUNCTION_H
 #define GCC_FUNCTION_H
 
+#include "tree.h"
+
 struct var_refs_queue GTY(())
 {
   rtx modified;
@@ -351,7 +353,7 @@ struct function GTY(())
   location_t function_end_locus;
 
   /* Array mapping insn uids to blocks.  */
-  struct varray_head_tag *ib_boundaries_block;
+  VEC(tree,gc) *ib_boundaries_block;
 
   /* The variables unexpanded so far.  */
   tree unexpanded_var_list;
Index: tree-inline.c
===================================================================
--- tree-inline.c	(revision 109449)
+++ tree-inline.c	(working copy)
@@ -966,7 +966,7 @@ copy_cfg_body (inline_data * id, gcov_ty
       *new_cfun = *DECL_STRUCT_FUNCTION (callee_fndecl);
       new_cfun->cfg = NULL;
       new_cfun->decl = new_fndecl = copy_node (callee_fndecl);
-      new_cfun->ib_boundaries_block = (varray_type) 0;
+      new_cfun->ib_boundaries_block = NULL;
       DECL_STRUCT_FUNCTION (new_fndecl) = new_cfun;
       push_cfun (new_cfun);
       init_empty_tree_cfg ();



More information about the Gcc-patches mailing list