[C++ patch] Hookize output_vtable_inherit

Jan Hubicka jh@suse.cz
Mon Jul 28 22:44:00 GMT 2003


> On Sun, 2003-07-27 at 13:55, Jan Hubicka wrote:
> > > Jan Hubicka <jh@suse.cz> writes:
> > > 
> > > >> On Sat, 2003-06-21 at 12:06, Jan Hubicka wrote:
> > > >> > 
> > > >> > Hi,
> > > >> > this patch adds hooks to assemble_variable to deal with output_vtable_inherit
> > > >> > as discussed earlier.   I didn't find pleasant way to discover virtual tables
> > > >> > and vtts, so I simply look for them in the list.
> > > >> 
> > > >> That's no good; let's not turn what used to be a constant-time operation
> > > >> into a linear-time operation.  Add a mark bit if you need one.
> > > > OK, here is updated patch.  There does not appear to be language
> > > > specific decl flag but I can use generic tree flag.
> > > > Does this look better?
> > > >
> > > > (regtested/bootstrapped x86-64)
> > > >
> > > > Mon Jun 23 20:11:36 CEST 2003  Jan Hubicka  <jh@suse.cz>
> > > > 	* class.c (build_vtable): Make vtables.
> > > > 	* cp-tree.h (DECL_VTABLE_OR_VTT_P): New macro.
> > > > 	* decl2.c (output_vtable_inherit): Rename to ...
> > > > 	(prepare_assemble_variable): ... this one; change interface.
> > > > 	(maybe_emit_vtables): Do not call output_vtable_inherit.
> > > > 	* cp-lang.c (LANG_HOOKS_PREPARE_ASSEMBLE_VARIABLE): Define.
> > > > 	* cp-tree.h (prepare_assemble_variable): New.
> > > 
> > > This causes the assembler to barf because it expects the first
> > > argument of .vtable_inherit to be already defined, but now the
> > > directive is output before the definition.  See the selective4 and
> > > selective5 tests in the ld testsuite.
> > 
> > OK, then we have two choices, rename prepare_assmble_variable into
> > something else (what?) and call it afterwards or drop the feature as it
> > was claimed to be useless nowdays anyway.
> 
> Drop the feature.

It does not kill the prepare_assemble_variable hook yet.  I still do
have one use for it, but I will probably drop it anyway.

OK?

Honza
Tue Jul 29 00:36:28 CEST 2003  Jan Hubicka  <jh@suse.cz>
	* c-common.c (flag_vtable_gc): Kill.
	* c-common.g (flag_vtable_gc): Kill.
	* c-opts (c_common_handle_option): Kill.
	* c.opt (fvtable-gc): Kill.
	* final.c (final_scan_insn): Do not call assemble_vtable_entry.
	* output.h (assemble_vtable_entry, assemble_vtable_inherit): Kill.
	* varasm.c (assemble_vtable_entry, assemble_vtable_inherit): Kill.

	* class.c (build_vtable_entry_ref): Kill.
	(build_vtbl_ref_1): Do not call build_vtable_entry_ref.
	(build_vfn_ref): Do not call build_vtable_entry_ref.
	* cp-lang.c (LANG_HOOKS_PREPARE_ASSEMBLE_VARIABLE): Kill.
	* cp-tree.h (prepare_assemble_variable): Kill.
	* cp-decl.c (prepare_assemble_variable): Kill.

	* invoke.texi (-ftable-gc): Kill documentation.

	* vtgc1.c: Kill.
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.438
diff -c -3 -p -r1.438 c-common.c
*** c-common.c	24 Jul 2003 21:04:12 -0000	1.438
--- c-common.c	28 Jul 2003 22:37:36 -0000
*************** int flag_weak = 1;
*** 569,578 ****
  
  int flag_use_cxa_atexit = DEFAULT_USE_CXA_ATEXIT;
  
- /* Nonzero means output .vtable_{entry,inherit} for use in doing vtable gc.  */
- 
- int flag_vtable_gc;
- 
  /* Nonzero means make the default pedwarns warnings instead of errors.
     The value of this flag is ignored if -pedantic is specified.  */
  
--- 569,574 ----
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.194
diff -c -3 -p -r1.194 c-common.h
*** c-common.h	24 Jul 2003 20:48:05 -0000	1.194
--- c-common.h	28 Jul 2003 22:37:37 -0000
*************** extern int flag_weak;
*** 743,752 ****
  
  extern int flag_use_cxa_atexit;
  
- /* Nonzero means output .vtable_{entry,inherit} for use in doing vtable gc.  */
- 
- extern int flag_vtable_gc;
- 
  /* Nonzero means make the default pedwarns warnings instead of errors.
     The value of this flag is ignored if -pedantic is specified.  */
  
--- 743,748 ----
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.79
diff -c -3 -p -r1.79 c-opts.c
*** c-opts.c	22 Jul 2003 23:15:24 -0000	1.79
--- c-opts.c	28 Jul 2003 22:37:37 -0000
*************** c_common_handle_option (size_t scode, co
*** 892,901 ****
        max_tinst_depth = value;
        break;
  
-     case OPT_fvtable_gc:
-       flag_vtable_gc = value;
-       break;
- 
      case OPT_fuse_cxa_atexit:
        flag_use_cxa_atexit = value;
        break;
--- 892,897 ----
Index: c.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c.opt,v
retrieving revision 1.11
diff -c -3 -p -r1.11 c.opt
*** c.opt	17 Jul 2003 05:33:09 -0000	1.11
--- c.opt	28 Jul 2003 22:37:37 -0000
*************** fuse-cxa-atexit
*** 630,639 ****
  C++ ObjC++
  Use __cxa_atexit to register destructors
  
- fvtable-gc
- C++ ObjC++
- Discard unused virtual functions
- 
  fvtable-thunks
  C++ ObjC++
  Implement vtables using thunks
--- 630,635 ----
Index: final.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/final.c,v
retrieving revision 1.288
diff -c -3 -p -r1.288 final.c
*** final.c	22 Jul 2003 23:15:27 -0000	1.288
--- final.c	28 Jul 2003 22:37:38 -0000
*************** final_scan_insn (rtx insn, FILE *file, i
*** 2486,2494 ****
  
  	/* Emit information for vtable gc.  */
  	note = find_reg_note (insn, REG_VTABLE_REF, NULL_RTX);
- 	if (note)
- 	  assemble_vtable_entry (XEXP (XEXP (note, 0), 0),
- 				 INTVAL (XEXP (XEXP (note, 0), 1)));
  
  	current_output_insn = debug_insn = 0;
        }
--- 2486,2491 ----
Index: output.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/output.h,v
retrieving revision 1.130
diff -c -3 -p -r1.130 output.h
*** output.h	10 Jul 2003 11:38:17 -0000	1.130
--- output.h	28 Jul 2003 22:37:38 -0000
*************** extern void default_file_start (void);
*** 508,517 ****
  extern void file_end_indicate_exec_stack (void);
  extern bool default_valid_pointer_mode (enum machine_mode);
  
- /* Emit data for vtable gc for GNU binutils.  */
- extern void assemble_vtable_entry (rtx, HOST_WIDE_INT);
- extern void assemble_vtable_inherit (rtx, rtx);
- 
  extern int default_address_cost (rtx);
  
  #endif /* ! GCC_OUTPUT_H */
--- 508,513 ----
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.377
diff -c -3 -p -r1.377 varasm.c
*** varasm.c	27 Jul 2003 01:48:05 -0000	1.377
--- varasm.c	28 Jul 2003 22:37:39 -0000
*************** default_pe_asm_named_section (const char
*** 4657,4686 ****
      }
  }
  
- /* Used for vtable gc in GNU binutils.  Record that the pointer at OFFSET
-    from SYMBOL is used in all classes derived from SYMBOL.  */
- 
- void
- assemble_vtable_entry (rtx symbol, HOST_WIDE_INT offset)
- {
-   fputs ("\t.vtable_entry ", asm_out_file);
-   output_addr_const (asm_out_file, symbol);
-   fprintf (asm_out_file, ", " HOST_WIDE_INT_PRINT_DEC "\n", offset);
- }
- 
- /* Used for vtable gc in GNU binutils.  Record the class hierarchy by noting
-    that the vtable symbol CHILD is derived from the vtable symbol PARENT.  */
- 
- void
- assemble_vtable_inherit (rtx child, rtx parent)
- {
-   fputs ("\t.vtable_inherit ", asm_out_file);
-   output_addr_const (asm_out_file, child);
-   fputs (", ", asm_out_file);
-   output_addr_const (asm_out_file, parent);
-   fputc ('\n', asm_out_file);
- }
- 
  /* The lame default section selector.  */
  
  void
--- 4657,4662 ----
Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.557
diff -c -3 -p -r1.557 class.c
*** cp/class.c	24 Jul 2003 23:33:25 -0000	1.557
--- cp/class.c	28 Jul 2003 22:37:43 -0000
*************** static void add_implicitly_declared_memb
*** 130,136 ****
  static tree fixed_type_or_null (tree, int *, int *);
  static tree resolve_address_of_overloaded_function (tree, tree, int,
  							  int, int, tree);
- static tree build_vtable_entry_ref (tree, tree, tree);
  static tree build_vtbl_ref_1 (tree, tree);
  static tree build_vtbl_initializer (tree, tree, tree, tree, int *);
  static int count_fields (tree);
--- 130,135 ----
*************** convert_to_base_statically (tree expr, t
*** 419,450 ****
  }
  
  
- /* Virtual function things.  */
- 
- static tree
- build_vtable_entry_ref (tree array_ref, tree instance, tree idx)
- {
-   tree i, i2, vtable, first_fn, basetype;
- 
-   basetype = non_reference (TREE_TYPE (instance));
- 
-   vtable = get_vtbl_decl_for_binfo (TYPE_BINFO (basetype));
-   first_fn = TYPE_BINFO_VTABLE (basetype);
- 
-   i = fold (build_array_ref (first_fn, idx));
-   i = fold (build_c_cast (ptrdiff_type_node,
- 			  build_unary_op (ADDR_EXPR, i, 0)));
-   i2 = fold (build_array_ref (vtable, build_int_2 (0,0)));
-   i2 = fold (build_c_cast (ptrdiff_type_node,
- 			   build_unary_op (ADDR_EXPR, i2, 0)));
-   i = fold (cp_build_binary_op (MINUS_EXPR, i, i2));
- 
-   if (TREE_CODE (i) != INTEGER_CST)
-     abort ();
- 
-   return build (VTABLE_REF, TREE_TYPE (array_ref), array_ref, vtable, i);
- }
- 
  /* Given an object INSTANCE, return an expression which yields the
     vtable element corresponding to INDEX.  There are many special
     cases for INSTANCE which we take care of here, mainly to avoid
--- 418,423 ----
*************** build_vtbl_ref (tree instance, tree idx)
*** 488,496 ****
  {
    tree aref = build_vtbl_ref_1 (instance, idx);
  
-   if (flag_vtable_gc)
-     aref = build_vtable_entry_ref (aref, instance, idx);
- 
    return aref;
  }
  
--- 461,466 ----
*************** build_vfn_ref (tree instance, tree idx)
*** 507,515 ****
    if (TARGET_VTABLE_USES_DESCRIPTORS)
      aref = build1 (NOP_EXPR, TREE_TYPE (aref),
  		   build_unary_op (ADDR_EXPR, aref, /*noconvert=*/1));
- 
-   if (flag_vtable_gc)
-     aref = build_vtable_entry_ref (aref, instance, idx);
  
    return aref;
  }
--- 477,482 ----
Index: cp/cp-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-lang.c,v
retrieving revision 1.57
diff -c -3 -p -r1.57 cp-lang.c
*** cp/cp-lang.c	22 Jul 2003 23:30:13 -0000	1.57
--- cp/cp-lang.c	28 Jul 2003 22:37:43 -0000
*************** static bool cp_var_mod_type_p (tree);
*** 153,161 ****
  #undef LANG_HOOKS_EXPR_SIZE
  #define LANG_HOOKS_EXPR_SIZE cp_expr_size
  
- #undef LANG_HOOKS_PREPARE_ASSEMBLE_VARIABLE 
- #define LANG_HOOKS_PREPARE_ASSEMBLE_VARIABLE prepare_assemble_variable
- 
  #undef LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION
  #define LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION expand_body
  #undef LANG_HOOKS_CALLGRAPH_LOWER_FUNCTION
--- 153,158 ----
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.892
diff -c -3 -p -r1.892 cp-tree.h
*** cp/cp-tree.h	28 Jul 2003 11:06:27 -0000	1.892
--- cp/cp-tree.h	28 Jul 2003 22:37:45 -0000
*************** extern tree build_artificial_parm (tree,
*** 3826,3832 ****
  extern tree get_guard (tree);
  extern tree get_guard_cond (tree);
  extern tree set_guard (tree);
- extern void prepare_assemble_variable (tree);
  extern void lower_function (tree);
  
  /* XXX Not i18n clean.  */
--- 3826,3831 ----
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.650
diff -c -3 -p -r1.650 decl2.c
*** cp/decl2.c	28 Jul 2003 21:59:30 -0000	1.650
--- cp/decl2.c	28 Jul 2003 22:37:45 -0000
*************** import_export_class (tree ctype)
*** 1626,1661 ****
        CLASSTYPE_INTERFACE_ONLY (ctype) = (import_export < 0);
      }
  }
-     
- /* We need to describe to the assembler the relationship between
-    a vtable and the vtable of the parent class.  */
- 
- void
- prepare_assemble_variable (tree vars)
- {
-   tree parent;
-   rtx child_rtx, parent_rtx;
- 
-   if (!flag_vtable_gc || TREE_CODE (vars) != VAR_DECL
-       || !DECL_VTABLE_OR_VTT_P (vars))
-     return;
- 
-   child_rtx = XEXP (DECL_RTL (vars), 0);	  /* strip the mem ref  */
- 
-   parent = binfo_for_vtable (vars);
- 
-   if (parent == TYPE_BINFO (DECL_CONTEXT (vars)))
-     parent_rtx = const0_rtx;
-   else if (parent)
-     {
-       parent = get_vtbl_decl_for_binfo (TYPE_BINFO (BINFO_TYPE (parent)));
-       parent_rtx = XEXP (DECL_RTL (parent), 0);  /* strip the mem ref  */
-     }
-   else
-     abort ();
- 
-   assemble_vtable_inherit (child_rtx, parent_rtx);
- }
  
  /* If necessary, write out the vtables for the dynamic class CTYPE.
     Returns true if any vtables were emitted.  */
--- 1626,1631 ----
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.323
diff -c -3 -p -r1.323 invoke.texi
*** doc/invoke.texi	24 Jul 2003 12:14:06 -0000	1.323
--- doc/invoke.texi	28 Jul 2003 22:37:49 -0000
*************** in the following sections.
*** 183,189 ****
  -fno-nonansi-builtins  -fno-operator-names @gol
  -fno-optional-diags  -fpermissive @gol
  -frepo  -fno-rtti  -fstats  -ftemplate-depth-@var{n} @gol
! -fuse-cxa-atexit  -fvtable-gc  -fno-weak  -nostdinc++ @gol
  -fno-default-inline  -Wabi  -Wctor-dtor-privacy @gol
  -Wnon-virtual-dtor  -Wreorder @gol
  -Weffc++  -Wno-deprecated @gol
--- 183,189 ----
  -fno-nonansi-builtins  -fno-operator-names @gol
  -fno-optional-diags  -fpermissive @gol
  -frepo  -fno-rtti  -fstats  -ftemplate-depth-@var{n} @gol
! -fuse-cxa-atexit  -fno-weak  -nostdinc++ @gol
  -fno-default-inline  -Wabi  -Wctor-dtor-privacy @gol
  -Wnon-virtual-dtor  -Wreorder @gol
  -Weffc++  -Wno-deprecated @gol
*************** Register destructors for objects with st
*** 1454,1470 ****
  This option is required for fully standards-compliant handling of static
  destructors, but will only work if your C library supports
  @code{__cxa_atexit}.
- 
- @item -fvtable-gc
- @opindex fvtable-gc
- Emit special relocations for vtables and virtual function references
- so that the linker can identify unused virtual functions and zero out
- vtable slots that refer to them.  This is most useful with
- @option{-ffunction-sections} and @option{-Wl,--gc-sections}, in order to
- also discard the functions themselves.
- 
- This optimization requires GNU as and GNU ld.  Not all systems support
- this option.  @option{-Wl,--gc-sections} is ignored without @option{-static}.
  
  @item -fno-weak
  @opindex fno-weak
--- 1454,1459 ----
Index: testsuite/g++.dg/opt/vtgc1.C
===================================================================
RCS file: testsuite/g++.dg/opt/vtgc1.C
diff -N testsuite/g++.dg/opt/vtgc1.C
*** testsuite/g++.dg/opt/vtgc1.C	1 Mar 2002 02:39:38 -0000	1.2
--- /dev/null	1 Jan 1970 00:00:00 -0000
***************
*** 1,136 ****
- // { dg-do compile }
- // { dg-options "-fvtable-gc" }
- // Origin: Hans-Peter Nilsson <hp@bitrange.com>
- 
- class Base0
- {
- public:
-   Base0(); virtual ~Base0();
-   virtual void f1();
-   virtual void f2();
- private:
-   int a_value;
- };
- 
- class Base1 : public Base0
- {
- public:
-   Base1(); virtual ~Base1();
-   virtual void f1(), f2();
-   virtual void f3();
- };
- 
- class Base2 : public Base1
- {
- public:
-   Base2(); virtual ~Base2();
-   virtual void f1(), f2();
-   virtual void f4();
- };
- 
- class VbasedA : virtual public Base2
- {
- public:
-   VbasedA(); virtual ~VbasedA();
-   virtual void f1(), f2(), f3();
-   virtual void f6();
- };
- 
- class Side0
- {
- public:
-   Side0(); virtual ~Side0();
-   virtual void x1();
-   virtual void xx();
- private:
-   int ryan;
- };
- 
- class Multisv0 : public Side0, virtual public Base2
- {
- public:
-   Multisv0(); virtual ~Multisv0();
-   virtual void f1(), f2();
-   virtual void f3();
-   virtual void f6();
-   virtual void xx();
- };
- 
- class Multivs1 : public Base2, virtual public Side0
- {
- public:
-   Multivs1(); virtual ~Multivs1(); virtual void f1(); virtual void fx2();
-   virtual void fx4(), fx5();
-   virtual void f6();
-   virtual void xx();
- };
- 
- class Multiss2 : public Base2, public Side0
- {
- public:
-   Multiss2(); virtual ~Multiss2(); virtual void f1(); virtual void fx2();
-   virtual void fx4();
-   virtual void f6();
-   virtual void xx();
- };
- 
- class Multivv3 : virtual public Base2, virtual public Side0
- {
- public:
-   Multivv3(); virtual ~Multivv3(); virtual void f1(); virtual void fx2();
-   virtual void fx4(), fx5();
-   virtual void f6();
-   virtual void xx();
- };
- 
- Base0::Base0() {}
- Base0::~Base0() {}
- Base1::Base1() {}
- Base1::~Base1() {}
- Base2::Base2() {}
- Base2::~Base2() {}
- VbasedA::VbasedA() {}
- VbasedA::~VbasedA() {}
- Multisv0::Multisv0() {}
- Multisv0::~Multisv0() {}
- Multivs1::Multivs1() {}
- Multivs1::~Multivs1() {}
- Multiss2::Multiss2() {}
- Multiss2::~Multiss2() {}
- Multivv3::Multivv3() {}
- Multivv3::~Multivv3() {}
- Side0::Side0() {}
- Side0::~Side0() {}
- 
- extern void x (VbasedA *);
- extern void x2 (Multisv0 *);
- extern void x3 (Multivs1 *);
- extern void x4 (Multiss2 *);
- extern void x5 (Multivv3 *);
- void y () { VbasedA ii; x(&ii);}
- void y2 () { Multisv0 ii; x2(&ii);}
- void y3 () { Multivs1 ii; x3(&ii);}
- void y4 () { Multiss2 ii; x4(&ii);}
- void y5 () { Multivv3 ii; x5(&ii);}
- void x (VbasedA *ii) { ii->f2();}
- void x2 (Multisv0 *ii) { ii->f2();}
- void x3 (Multivs1 *ii) { ii->f2();}
- void x4 (Multiss2 *ii) { ii->f2();}
- void x5 (Multivv3 *ii) { ii->f2();}
- 
- // Use .* because of ia64's convention of marking symbols with "#", which
- // makes it through the c++filt.
- 
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*vtable for Multivv3.*0" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*VTT for Multivv3.*0" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*vtable for Multiss2.*vtable for Base2" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*vtable for Multivs1.*vtable for Base2" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*VTT for Multivs1.*vtable for Base2" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*vtable for Multisv0.*vtable for Side0" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*VTT for Multisv0.*vtable for Side0" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*vtable for Side0.*0" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*vtable for VbasedA.*0" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*VTT for VbasedA.*0" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*vtable for Base2.*vtable for Base1" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*vtable for Base1.*vtable for Base0" } }
- // { dg-final { scan-assembler-dem "\.vtable_inherit\[ \t\]*vtable for Base0.*0" } }
--- 0 ----



More information about the Gcc-patches mailing list