[C++ patch] Hookize output_vtable_inherit

Jan Hubicka hubicka@ucw.cz
Sat Jun 21 19:21:00 GMT 2003


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.

Bootstrapped/regtested i386 togehter with previous patch. OK?
Honza

Sat Jun 21 19:19:23 CEST 2003  Jan Hubicka  <jh@suse.cz>
	* 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.

	* langhooks-def.h (LANG_HOOKS_PREPARE_ASSEMBLE_VARIABLE): New macro.
	* langhooks.h (lang_hooks_for_decls): Add prepare_assemble_variable.
	* varasm.c (assemble_variable): Call prepare_assemble_variable.
Index: decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.630
diff -c -3 -p -r1.630 decl2.c
*** decl2.c	20 Jun 2003 00:48:40 -0000	1.630
--- decl2.c	21 Jun 2003 17:57:38 -0000
*************** static void add_using_namespace (tree, t
*** 66,72 ****
  static cxx_binding *ambiguous_decl (tree, cxx_binding *, cxx_binding *, int);
  static tree build_anon_union_vars (tree);
  static bool acceptable_java_type (tree);
- static void output_vtable_inherit (tree);
  static tree start_objects (int, int);
  static void finish_objects (int, int, tree);
  static tree merge_functions (tree, tree);
--- 66,71 ----
*************** import_export_class (tree ctype)
*** 1604,1614 ****
  /* We need to describe to the assembler the relationship between
     a vtable and the vtable of the parent class.  */
  
! static void
! output_vtable_inherit (tree vars)
  {
    tree parent;
    rtx child_rtx, parent_rtx;
  
    child_rtx = XEXP (DECL_RTL (vars), 0);	  /* strip the mem ref  */
  
--- 1608,1638 ----
  /* 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;
+   tree vtbl;
+ 
+   if (!flag_vtable_gc)
+     return;
+   /* Recognize virtual tables.  
+      Both VTTs and vtables are array types with context set to the parent
+      class.  */
+   if (TREE_CODE (TREE_TYPE (vars)) != ARRAY_TYPE
+       || !DECL_CONTEXT (vars)
+       || !CLASS_TYPE_P (DECL_CONTEXT (vars)))
+     return;
+   /* Look trought the list of VTTs and vtables of the class to see whether
+      we are seeing one.  */
+   for (vtbl = CLASSTYPE_VTABLES (DECL_CONTEXT (vars));
+        vtbl; vtbl = TREE_CHAIN (vtbl))
+     if (vtbl == vars)
+       break;
+ 
+   if (!vtbl)
+     return;
  
    child_rtx = XEXP (DECL_RTL (vars), 0);	  /* strip the mem ref  */
  
*************** maybe_emit_vtables (tree ctype)
*** 1706,1714 ****
  
        rest_of_decl_compilation (vtbl, NULL, 1, 1);
  
-       if (flag_vtable_gc)
- 	output_vtable_inherit (vtbl);
- 
        /* Because we're only doing syntax-checking, we'll never end up
  	 actually marking the variable as written.  */
        if (flag_syntax_only)
--- 1730,1735 ----
Index: langhooks-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks-def.h,v
retrieving revision 1.50
diff -c -3 -p -r1.50 langhooks-def.h
*** langhooks-def.h	11 Jun 2003 22:21:07 -0000	1.50
--- langhooks-def.h	21 Jun 2003 17:50:48 -0000
*************** int lhd_tree_dump_type_quals			PARAMS ((
*** 221,226 ****
--- 221,227 ----
  #define LANG_HOOKS_GETDECLS	getdecls
  #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL lhd_warn_unused_global_decl
  #define LANG_HOOKS_WRITE_GLOBALS write_global_declarations
+ #define LANG_HOOKS_PREPARE_ASSEMBLE_VARIABLE NULL
  #define LANG_HOOKS_DECL_OK_FOR_SIBCALL	lhd_decl_ok_for_sibcall
  
  #define LANG_HOOKS_DECLS { \
*************** int lhd_tree_dump_type_quals			PARAMS ((
*** 233,238 ****
--- 234,240 ----
    LANG_HOOKS_GETDECLS, \
    LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL, \
    LANG_HOOKS_WRITE_GLOBALS, \
+   LANG_HOOKS_PREPARE_ASSEMBLE_VARIABLE, \
    LANG_HOOKS_DECL_OK_FOR_SIBCALL, \
  }
  
Index: langhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.h,v
retrieving revision 1.58
diff -c -3 -p -r1.58 langhooks.h
*** langhooks.h	11 Jun 2003 22:21:07 -0000	1.58
--- langhooks.h	21 Jun 2003 17:50:48 -0000
*************** struct lang_hooks_for_decls
*** 181,186 ****
--- 181,189 ----
       of compilation */
    void (*final_write_globals) PARAMS ((void));
  
+   /* Do necessary preparations before assemble_variable can proceed.  */
+   void (*prepare_assemble_variable) PARAMS ((tree));
+ 
    /* True if this decl may be called via a sibcall.  */
    bool (*ok_for_sibcall) PARAMS ((tree));
  };
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.362
diff -c -3 -p -r1.362 varasm.c
*** varasm.c	19 Jun 2003 21:47:01 -0000	1.362
--- varasm.c	21 Jun 2003 17:50:49 -0000
*************** assemble_variable (decl, top_level, at_e
*** 1409,1414 ****
--- 1409,1417 ----
    int reloc = 0;
    rtx decl_rtl;
  
+   if (lang_hooks.decls.prepare_assemble_variable)
+     (*lang_hooks.decls.prepare_assemble_variable) (decl);
+ 
    last_assemble_variable_decl = 0;
  
    /* Normally no need to say anything here for external references,
Index: cp/cp-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-lang.c,v
retrieving revision 1.50
diff -c -3 -p -r1.50 cp-lang.c
*** cp/cp-lang.c	7 Jun 2003 11:10:43 -0000	1.50
--- cp/cp-lang.c	21 Jun 2003 17:50:49 -0000
*************** static bool cp_var_mod_type_p (tree);
*** 145,150 ****
--- 145,153 ----
  #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_MAKE_TYPE
  #define LANG_HOOKS_MAKE_TYPE cxx_make_type
  #undef LANG_HOOKS_TYPE_FOR_MODE
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.858
diff -c -3 -p -r1.858 cp-tree.h
*** cp/cp-tree.h	20 Jun 2003 02:40:33 -0000	1.858
--- cp/cp-tree.h	21 Jun 2003 17:50:49 -0000
*************** extern tree build_artificial_parm (tree,
*** 3794,3799 ****
--- 3794,3800 ----
  extern tree get_guard (tree);
  extern tree get_guard_cond (tree);
  extern tree set_guard (tree);
+ extern void prepare_assemble_variable (tree);
  
  extern void cp_error_at		(const char *msgid, ...);
  extern void cp_warning_at	(const char *msgid, ...);



More information about the Gcc-patches mailing list