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]

[C++ PATCH] Compare binfo types directly


Mark,
this patch replaces 'same_type_p (BINFO_TYPE (b), t)' with
'BINFO_TYPE (b) == t'. I know you've expressed reservations about omitting
same_type_p calls in this way, so I'm running this by you for comment
before committing.

This shows a .5% speed improvement on compiling the (preprocessed) qt
library on i686-pc-linux-gnu, so seems worth it. What this shows is that
same_type_p's performance is important (which we know).  I consider
BINFO_TYPE to be a special case as we know that it always points to the
TYPE_MAIN_VARIANT of a type, and thus same_type_p will only ever return
true when pointer comparison actually matches.  In grepping for opportunities
to appy this change, I noticed at least one place where we already do this.
We should pick one way of doing this and I think it should be the faster one.

booted & tested on i686-pc-linux-gnu.

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2004-10-11  Nathan Sidwell  <nathan@codesourcery.com>

	* class.c (build_base_path): Compare binfo types directly.
	(convert_to_base_statically, update_vtable_entry_for_fn,
	build_vtt_inits, dfs_build_secondary_vptr_vtt_inits,
	build_ctor_vtbl_group, accumulate_vtbl_inits,
	dfs_accumulate_vtbl_inits, build_vtbl_initializer,
	add_vcall_offset_vtbl_entries_1): Likewise.
	* init.c (expand_member_init): Likewise.
	* search.c (lookup_base_r, binfo_from_vbase): Likewise.

Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.682
diff -c -3 -p -r1.682 class.c
*** cp/class.c	8 Oct 2004 09:33:53 -0000	1.682
--- cp/class.c	8 Oct 2004 12:40:04 -0000
*************** build_base_path (enum tree_code code,
*** 259,269 ****
    if (want_pointer)
      probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
  
!   gcc_assert (code == MINUS_EXPR
! 	      ? same_type_p (BINFO_TYPE (binfo), probe)
! 	      : code == PLUS_EXPR
! 	      ? same_type_p (BINFO_TYPE (d_binfo), probe)
! 	      : false);
    
    if (binfo == d_binfo)
      /* Nothing to do.  */
--- 259,266 ----
    if (want_pointer)
      probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
  
!   gcc_assert ((code == MINUS_EXPR && BINFO_TYPE (binfo) == probe)
! 	      || (code == PLUS_EXPR && BINFO_TYPE (d_binfo) == probe));
    
    if (binfo == d_binfo)
      /* Nothing to do.  */
*************** convert_to_base (tree object, tree type,
*** 445,452 ****
    return build_base_path (PLUS_EXPR, object, binfo, /*nonnull=*/1);
  }
  
! /* EXPR is an expression with class type.  BASE is a base class (a
!    BINFO) of that class type.  Returns EXPR, converted to the BASE
     type.  This function assumes that EXPR is the most derived class;
     therefore virtual bases can be found at their static offsets.  */
  
--- 442,449 ----
    return build_base_path (PLUS_EXPR, object, binfo, /*nonnull=*/1);
  }
  
! /* EXPR is an expression with unqualified class type.  BASE is a base
!    binfo of that class type.  Returns EXPR, converted to the BASE
     type.  This function assumes that EXPR is the most derived class;
     therefore virtual bases can be found at their static offsets.  */
  
*************** convert_to_base_statically (tree expr, t
*** 456,462 ****
    tree expr_type;
  
    expr_type = TREE_TYPE (expr);
!   if (!same_type_p (expr_type, BINFO_TYPE (base)))
      {
        tree pointer_type;
  
--- 453,459 ----
    tree expr_type;
  
    expr_type = TREE_TYPE (expr);
!   if (expr_type != BINFO_TYPE (base))
      {
        tree pointer_type;
  
*************** update_vtable_entry_for_fn (tree t, tree
*** 2062,2069 ****
      {
        /* If we find the final overrider, then we can stop
  	 walking.  */
!       if (same_type_p (BINFO_TYPE (b), 
! 		       BINFO_TYPE (TREE_VALUE (overrider))))
  	break;
  
        /* If we find a virtual base, and we haven't yet found the
--- 2059,2065 ----
      {
        /* If we find the final overrider, then we can stop
  	 walking.  */
!       if (BINFO_TYPE (b) == BINFO_TYPE (TREE_VALUE (overrider)))
  	break;
  
        /* If we find a virtual base, and we haven't yet found the
*************** build_vtt_inits (tree binfo, tree t, tre
*** 6697,6703 ****
    tree init;
    tree secondary_vptrs;
    secondary_vptr_vtt_init_data data;
!   int top_level_p = same_type_p (TREE_TYPE (binfo), t);
  
    /* We only need VTTs for subobjects with virtual bases.  */
    if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
--- 6693,6699 ----
    tree init;
    tree secondary_vptrs;
    secondary_vptr_vtt_init_data data;
!   int top_level_p = BINFO_TYPE (binfo) == t;
  
    /* We only need VTTs for subobjects with virtual bases.  */
    if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
*************** dfs_build_secondary_vptr_vtt_inits (tree
*** 6783,6789 ****
  
    /* We're only interested in proper subobjects of the type being
       constructed.  */
!   if (same_type_p (BINFO_TYPE (binfo), data->type_being_constructed))
      return NULL_TREE;
  
    /* We're only interested in bases with virtual bases or reachable
--- 6779,6785 ----
  
    /* We're only interested in proper subobjects of the type being
       constructed.  */
!   if (BINFO_TYPE (binfo) == data->type_being_constructed)
      return NULL_TREE;
  
    /* We're only interested in bases with virtual bases or reachable
*************** build_ctor_vtbl_group (tree binfo, tree 
*** 6869,6875 ****
    if (IDENTIFIER_GLOBAL_VALUE (id))
      return;
  
!   gcc_assert (!same_type_p (BINFO_TYPE (binfo), t));
    /* Build a version of VTBL (with the wrong type) for use in
       constructing the addresses of secondary vtables in the
       construction vtable group.  */
--- 6865,6871 ----
    if (IDENTIFIER_GLOBAL_VALUE (id))
      return;
  
!   gcc_assert (BINFO_TYPE (binfo) != t);
    /* Build a version of VTBL (with the wrong type) for use in
       constructing the addresses of secondary vtables in the
       construction vtable group.  */
*************** accumulate_vtbl_inits (tree binfo,
*** 6925,6933 ****
  {
    int i;
    tree base_binfo;
!   int ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
  
!   gcc_assert (same_type_p (BINFO_TYPE (binfo), BINFO_TYPE (orig_binfo)));
  
    /* If it doesn't have a vptr, we don't do anything.  */
    if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
--- 6921,6929 ----
  {
    int i;
    tree base_binfo;
!   int ctor_vtbl_p = BINFO_TYPE (rtti_binfo) != t;
  
!   gcc_assert (BINFO_TYPE (binfo) == BINFO_TYPE (orig_binfo));
  
    /* If it doesn't have a vptr, we don't do anything.  */
    if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
*************** dfs_accumulate_vtbl_inits (tree binfo,
*** 6975,6981 ****
  {
    tree inits = NULL_TREE;
    tree vtbl = NULL_TREE;
!   int ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
  
    if (ctor_vtbl_p
        && BINFO_VIRTUAL_P (orig_binfo) && BINFO_PRIMARY_P (orig_binfo))
--- 6971,6977 ----
  {
    tree inits = NULL_TREE;
    tree vtbl = NULL_TREE;
!   int ctor_vtbl_p = BINFO_TYPE (rtti_binfo) != t;
  
    if (ctor_vtbl_p
        && BINFO_VIRTUAL_P (orig_binfo) && BINFO_PRIMARY_P (orig_binfo))
*************** build_vtbl_initializer (tree binfo,
*** 7110,7116 ****
    vid.rtti_binfo = rtti_binfo;
    vid.last_init = &vid.inits;
    vid.primary_vtbl_p = (binfo == TYPE_BINFO (t));
!   vid.ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
    vid.generate_vcall_entries = true;
    /* The first vbase or vcall offset is at index -3 in the vtable.  */
    vid.index = ssize_int(-3 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
--- 7106,7112 ----
    vid.rtti_binfo = rtti_binfo;
    vid.last_init = &vid.inits;
    vid.primary_vtbl_p = (binfo == TYPE_BINFO (t));
!   vid.ctor_vtbl_p = BINFO_TYPE (rtti_binfo) != t;
    vid.generate_vcall_entries = true;
    /* The first vbase or vcall offset is at index -3 in the vtable.  */
    vid.index = ssize_int(-3 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
*************** add_vcall_offset_vtbl_entries_1 (tree bi
*** 7523,7529 ****
  	  /* When processing BINFO, we only want to generate vcall slots for
  	     function slots introduced in BINFO.  So don't try to generate
  	     one if the function isn't even defined in BINFO.  */
! 	  if (!same_type_p (DECL_CONTEXT (orig_fn), BINFO_TYPE (binfo)))
  	    continue;
  
  	  add_vcall_offset (orig_fn, binfo, vid);
--- 7519,7525 ----
  	  /* When processing BINFO, we only want to generate vcall slots for
  	     function slots introduced in BINFO.  So don't try to generate
  	     one if the function isn't even defined in BINFO.  */
! 	  if (DECL_CONTEXT (orig_fn) != BINFO_TYPE (binfo))
  	    continue;
  
  	  add_vcall_offset (orig_fn, binfo, vid);
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.398
diff -c -3 -p -r1.398 init.c
*** cp/init.c	8 Oct 2004 09:33:54 -0000	1.398
--- cp/init.c	8 Oct 2004 12:40:22 -0000
*************** expand_member_init (tree name)
*** 979,985 ****
  
        /* Look for a direct base.  */
        for (i = 0; BINFO_BASE_ITERATE (class_binfo, i, direct_binfo); ++i)
! 	if (same_type_p (basetype, BINFO_TYPE (direct_binfo)))
  	  break;
  
        /* Look for a virtual base -- unless the direct base is itself
--- 979,985 ----
  
        /* Look for a direct base.  */
        for (i = 0; BINFO_BASE_ITERATE (class_binfo, i, direct_binfo); ++i)
! 	if (basetype == BINFO_TYPE (direct_binfo))
  	  break;
  
        /* Look for a virtual base -- unless the direct base is itself
Index: cp/search.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/search.c,v
retrieving revision 1.326
diff -c -3 -p -r1.326 search.c
*** cp/search.c	8 Oct 2004 09:33:55 -0000	1.326
--- cp/search.c	8 Oct 2004 12:40:32 -0000
*************** lookup_base_r (tree binfo, tree base, ba
*** 90,96 ****
    tree base_binfo;
    base_kind found = bk_not_base;
    
!   if (same_type_p (BINFO_TYPE (binfo), base))
      {
        /* We have found a base. Check against what we have found
           already.  */
--- 99,105 ----
    tree base_binfo;
    base_kind found = bk_not_base;
    
!   if (BINFO_TYPE (binfo) == base)
      {
        /* We have found a base. Check against what we have found
           already.  */
*************** binfo_from_vbase (tree binfo)
*** 2346,2352 ****
  tree
  binfo_via_virtual (tree binfo, tree limit)
  {
!   for (; binfo && (!limit || !same_type_p (BINFO_TYPE (binfo), limit));
         binfo = BINFO_INHERITANCE_CHAIN (binfo))
      {
        if (BINFO_VIRTUAL_P (binfo))
--- 2415,2421 ----
  tree
  binfo_via_virtual (tree binfo, tree limit)
  {
!   for (; binfo && BINFO_TYPE (binfo) != limit;
         binfo = BINFO_INHERITANCE_CHAIN (binfo))
      {
        if (BINFO_VIRTUAL_P (binfo))

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