This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++] Make vcall indices a vector
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Mark Mitchell <mark at codesourcery dot com>
- Date: Wed, 28 Jul 2004 09:54:17 +0100
- Subject: [C++] Make vcall indices a vector
- Organization: Codesourcery LLC
Hi,
this patch changes a class's vcall indices list into a vector of pairs.
If the vector is 75% full, this halves the memory used for that purpose.
I've introduced a tree_pair structure, I suspect it'll migrate to
tree.h at some point.
booted & tested on i686-pc-linux-gnu, installed.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2004-07-28 Nathan Sidwell <nathan@codesourcery.com>
* cp-tree.h (struct tree_pair_s): New.
(typedef tree_pair_p): New.
(DEF_VEC_O(tree_pair_s)): New.
(struct lang_type_class): Make vcall_indices a VEC(tree_pair_s).
(CLASSTYPE_VCALL_INDICES): Update documentation.
* class.c (get_vcall_index): Adjust.
(add_vcall_offset): Adjust.
Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.645
diff -c -3 -p -r1.645 class.c
*** cp/class.c 25 Jul 2004 22:52:14 -0000 1.645
--- cp/class.c 27 Jul 2004 15:31:20 -0000
*************** find_final_overrider (tree derived, tree
*** 1955,1971 ****
static tree
get_vcall_index (tree fn, tree type)
{
! tree v;
! for (v = CLASSTYPE_VCALL_INDICES (type); v; v = TREE_CHAIN (v))
! if ((DECL_DESTRUCTOR_P (fn) && DECL_DESTRUCTOR_P (TREE_PURPOSE (v)))
! || same_signature_p (fn, TREE_PURPOSE (v)))
! break;
/* There should always be an appropriate index. */
! my_friendly_assert (v, 20021103);
! return TREE_VALUE (v);
}
/* Update an entry in the vtable for BINFO, which is in the hierarchy
--- 1955,1973 ----
static tree
get_vcall_index (tree fn, tree type)
{
! VEC (tree_pair_s) *indices = CLASSTYPE_VCALL_INDICES (type);
! tree_pair_p p;
! unsigned ix;
! for (ix = 0; VEC_iterate (tree_pair_s, indices, ix, p); ix++)
! if ((DECL_DESTRUCTOR_P (fn) && DECL_DESTRUCTOR_P (p->purpose))
! || same_signature_p (fn, p->purpose))
! return p->value;
/* There should always be an appropriate index. */
! abort ();
! return NULL_TREE;
}
/* Update an entry in the vtable for BINFO, which is in the hierarchy
*************** add_vcall_offset (tree orig_fn, tree bin
*** 7682,7691 ****
the vtable for the most derived class, remember the vcall
offset. */
if (vid->binfo == TYPE_BINFO (vid->derived))
! CLASSTYPE_VCALL_INDICES (vid->derived)
! = tree_cons (orig_fn, vid->index,
! CLASSTYPE_VCALL_INDICES (vid->derived));
!
/* The next vcall offset will be found at a more negative
offset. */
vid->index = size_binop (MINUS_EXPR, vid->index,
--- 7684,7697 ----
the vtable for the most derived class, remember the vcall
offset. */
if (vid->binfo == TYPE_BINFO (vid->derived))
! {
! tree_pair_p elt = VEC_safe_push (tree_pair_s,
! CLASSTYPE_VCALL_INDICES (vid->derived),
! NULL);
! elt->purpose = orig_fn;
! elt->value = vid->index;
! }
!
/* The next vcall offset will be found at a more negative
offset. */
vid->index = size_binop (MINUS_EXPR, vid->index,
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.1024
diff -c -3 -p -r1.1024 cp-tree.h
*** cp/cp-tree.h 25 Jul 2004 22:52:15 -0000 1.1024
--- cp/cp-tree.h 27 Jul 2004 15:31:32 -0000
*************** enum languages { lang_c, lang_cplusplus,
*** 933,941 ****
!= NULL_TREE)
/* Gives the visibility specification for a class type. */
! #define CLASSTYPE_VISIBILITY(TYPE) DECL_VISIBILITY (TYPE_NAME (TYPE))
! #define CLASSTYPE_VISIBILITY_SPECIFIED(TYPE) DECL_VISIBILITY_SPECIFIED (TYPE_NAME (TYPE))
/* This is a few header flags for 'struct lang_type'. Actually,
all but the first are used only for lang_type_class; they
--- 933,950 ----
!= NULL_TREE)
/* Gives the visibility specification for a class type. */
! #define CLASSTYPE_VISIBILITY(TYPE) \
! DECL_VISIBILITY (TYPE_NAME (TYPE))
! #define CLASSTYPE_VISIBILITY_SPECIFIED(TYPE) \
! DECL_VISIBILITY_SPECIFIED (TYPE_NAME (TYPE))
+ typedef struct tree_pair_s GTY (())
+ {
+ tree purpose;
+ tree value;
+ } tree_pair_s;
+ typedef tree_pair_s *tree_pair_p;
+ DEF_VEC_O (tree_pair_s);
/* This is a few header flags for 'struct lang_type'. Actually,
all but the first are used only for lang_type_class; they
*************** struct lang_type_class GTY(())
*** 1020,1026 ****
unsigned dummy : 8;
tree primary_base;
! tree vcall_indices;
tree vtables;
tree typeinfo_var;
VEC (tree) *vbases;
--- 1029,1035 ----
unsigned dummy : 8;
tree primary_base;
! VEC (tree_pair_s) *vcall_indices;
tree vtables;
tree typeinfo_var;
VEC (tree) *vbases;
*************** struct lang_type GTY(())
*** 1432,1442 ****
/* Used by various search routines. */
#define IDENTIFIER_MARKED(NODE) TREE_LANG_FLAG_0 (NODE)
! /* A TREE_LIST of the vcall indices associated with the class NODE.
! The TREE_PURPOSE of each node is a FUNCTION_DECL for a virtual
! function. The TREE_VALUE is the index into the virtual table where
! the vcall offset for that function is stored, when NODE is a
! virtual base. */
#define CLASSTYPE_VCALL_INDICES(NODE) \
(LANG_TYPE_CLASS_CHECK (NODE)->vcall_indices)
--- 1441,1451 ----
/* Used by various search routines. */
#define IDENTIFIER_MARKED(NODE) TREE_LANG_FLAG_0 (NODE)
! /* A VEC(tree_pair_s) of the vcall indices associated with the class
! NODE. The PURPOSE of each element is a FUNCTION_DECL for a virtual
! function. The VALUE is the index into the virtual table where the
! vcall offset for that function is stored, when NODE is a virtual
! base. */
#define CLASSTYPE_VCALL_INDICES(NODE) \
(LANG_TYPE_CLASS_CHECK (NODE)->vcall_indices)