Commit 7be82279 by Jan Hubicka Committed by Jan Hubicka

semantics.c (expand_or_defer_fn): Do not call c_record_cdtor_fn.

	* semantics.c (expand_or_defer_fn): Do not call c_record_cdtor_fn.
	* decl2.c (start_objects): ctors and dtors are no longer public.
	(cp_write_global_declarations): Do not call c_build_cdtor_fns.

	* cgraphunit.c: Include gt-cgraphunit.h
	(static_ctors, static_dtors): New static vars.
	(record_cdtor_fn, build_cdtor, cgraph_build_cdtor_fns): New functions,
	based on implementation in c-common.c
	(cgraph_finalize_function): Call record_cdtor_fn.
	(cgraph_optimize): Call cgraph_build_cdtor_fns.
	* decl.c (finish_function): Do not call c_record_cdtor_fn.
	(c_write_global_declarations): Do not call c_build_cdtor_fns.
	* c-common.c (static_ctors, static_dtors, c_record_cdtor_fn,
	build_cdtor, c_build_cdtor_fns): Remove.
	* c-common.h (static_ctors, static_dtors, c_record_cdtor_fn,
	c_build_cdtor_fns): Remove prototype.

From-SVN: r124618
parent 2a5fce6d
2007-05-11 Jan Hubicka <jh@suse.cz>
* cgraphunit.c: Include gt-cgraphunit.h
(static_ctors, static_dtors): New static vars.
(record_cdtor_fn, build_cdtor, cgraph_build_cdtor_fns): New functions,
based on implementation in c-common.c
(cgraph_finalize_function): Call record_cdtor_fn.
(cgraph_optimize): Call cgraph_build_cdtor_fns.
* decl.c (finish_function): Do not call c_record_cdtor_fn.
(c_write_global_declarations): Do not call c_build_cdtor_fns.
* c-common.c (static_ctors, static_dtors, c_record_cdtor_fn,
build_cdtor, c_build_cdtor_fns): Remove.
* c-common.h (static_ctors, static_dtors, c_record_cdtor_fn,
c_build_cdtor_fns): Remove prototype.
2007-05-11 Paolo Carlini <pcarlini@suse.de> 2007-05-11 Paolo Carlini <pcarlini@suse.de>
PR other/31852 PR other/31852
......
...@@ -2370,7 +2370,8 @@ cgraphunit.o : cgraphunit.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ ...@@ -2370,7 +2370,8 @@ cgraphunit.o : cgraphunit.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) langhooks.h $(TREE_INLINE_H) toplev.h $(FLAGS_H) $(GGC_H) \ $(TREE_H) langhooks.h $(TREE_INLINE_H) toplev.h $(FLAGS_H) $(GGC_H) \
$(TARGET_H) $(CGRAPH_H) intl.h pointer-set.h $(FUNCTION_H) $(TREE_GIMPLE_H) \ $(TARGET_H) $(CGRAPH_H) intl.h pointer-set.h $(FUNCTION_H) $(TREE_GIMPLE_H) \
$(TREE_FLOW_H) tree-pass.h $(C_COMMON_H) debug.h $(DIAGNOSTIC_H) \ $(TREE_FLOW_H) tree-pass.h $(C_COMMON_H) debug.h $(DIAGNOSTIC_H) \
$(FIBHEAP_H) output.h $(PARAMS_H) $(RTL_H) $(TIMEVAR_H) ipa-prop.h $(FIBHEAP_H) output.h $(PARAMS_H) $(RTL_H) $(TIMEVAR_H) ipa-prop.h \
gt-cgraphunit.h
cgraphbuild.o : cgraphbuild.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ cgraphbuild.o : cgraphbuild.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) langhooks.h $(CGRAPH_H) intl.h pointer-set.h $(TREE_GIMPLE_H) \ $(TREE_H) langhooks.h $(CGRAPH_H) intl.h pointer-set.h $(TREE_GIMPLE_H) \
$(TREE_FLOW_H) tree-pass.h $(TREE_FLOW_H) tree-pass.h
...@@ -2965,7 +2966,7 @@ GTFILES = $(srcdir)/input.h $(srcdir)/coretypes.h \ ...@@ -2965,7 +2966,7 @@ GTFILES = $(srcdir)/input.h $(srcdir)/coretypes.h \
$(srcdir)/ipa-reference.c $(srcdir)/tree-ssa-structalias.h \ $(srcdir)/ipa-reference.c $(srcdir)/tree-ssa-structalias.h \
$(srcdir)/tree-ssa-structalias.c \ $(srcdir)/tree-ssa-structalias.c \
$(srcdir)/omp-low.c $(srcdir)/varpool.c \ $(srcdir)/omp-low.c $(srcdir)/varpool.c \
$(srcdir)/targhooks.c $(out_file) $(srcdir)/passes.c \ $(srcdir)/targhooks.c $(out_file) $(srcdir)/passes.c $(srcdir)/cgraphunit.c \
@all_gtfiles@ @all_gtfiles@
GTFILES_H = $(subst /,-, $(subst $(srcdir)/,gt-, $(subst .c,.h, \ GTFILES_H = $(subst /,-, $(subst $(srcdir)/,gt-, $(subst .c,.h, \
......
...@@ -670,11 +670,6 @@ const struct attribute_spec c_common_format_attribute_table[] = ...@@ -670,11 +670,6 @@ const struct attribute_spec c_common_format_attribute_table[] =
{ NULL, 0, 0, false, false, false, NULL } { NULL, 0, 0, false, false, false, NULL }
}; };
/* Functions called automatically at the beginning and end of execution. */
tree static_ctors;
tree static_dtors;
/* Push current bindings for the function name VAR_DECLS. */ /* Push current bindings for the function name VAR_DECLS. */
void void
...@@ -6994,61 +6989,6 @@ warn_for_unused_label (tree label) ...@@ -6994,61 +6989,6 @@ warn_for_unused_label (tree label)
} }
} }
/* If FNDECL is a static constructor or destructor, add it to the list
of functions to be called by the file scope initialization
function. */
void
c_record_cdtor_fn (tree fndecl)
{
if (targetm.have_ctors_dtors)
return;
if (DECL_STATIC_CONSTRUCTOR (fndecl))
static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
if (DECL_STATIC_DESTRUCTOR (fndecl))
static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
}
/* Synthesize a function which calls all the global ctors or global
dtors in this file. This is only used for targets which do not
support .ctors/.dtors sections. FIXME: Migrate into cgraph. */
static void
build_cdtor (int method_type, tree cdtors)
{
tree body = 0;
if (!cdtors)
return;
for (; cdtors; cdtors = TREE_CHAIN (cdtors))
append_to_statement_list (build_function_call (TREE_VALUE (cdtors), 0),
&body);
cgraph_build_static_cdtor (method_type, body, DEFAULT_INIT_PRIORITY);
}
/* Generate functions to call static constructors and destructors
for targets that do not support .ctors/.dtors sections. These
functions have magic names which are detected by collect2. */
void
c_build_cdtor_fns (void)
{
if (!targetm.have_ctors_dtors)
{
build_cdtor ('I', static_ctors);
static_ctors = NULL_TREE;
build_cdtor ('D', static_dtors);
static_dtors = NULL_TREE;
}
else
{
gcc_assert (!static_ctors);
gcc_assert (!static_dtors);
}
}
#ifndef TARGET_HAS_TARGETCM #ifndef TARGET_HAS_TARGETCM
struct gcc_targetcm targetcm = TARGETCM_INITIALIZER; struct gcc_targetcm targetcm = TARGETCM_INITIALIZER;
#endif #endif
......
...@@ -1005,11 +1005,4 @@ extern tree c_omp_remap_decl (tree, bool); ...@@ -1005,11 +1005,4 @@ extern tree c_omp_remap_decl (tree, bool);
#define GCC_DIAG_STYLE __gcc_cdiag__ #define GCC_DIAG_STYLE __gcc_cdiag__
#endif #endif
/* Functions called automatically at the beginning and end of execution. */
extern GTY (()) tree static_ctors;
extern GTY (()) tree static_dtors;
extern void c_record_cdtor_fn (tree);
extern void c_build_cdtor_fns (void);
#endif /* ! GCC_C_COMMON_H */ #endif /* ! GCC_C_COMMON_H */
...@@ -6799,10 +6799,6 @@ finish_function (void) ...@@ -6799,10 +6799,6 @@ finish_function (void)
info for the epilogue. */ info for the epilogue. */
cfun->function_end_locus = input_location; cfun->function_end_locus = input_location;
/* Keep track of functions declared with the "constructor" and
"destructor" attribute. */
c_record_cdtor_fn (fndecl);
/* Finalize the ELF visibility for the function. */ /* Finalize the ELF visibility for the function. */
c_determine_visibility (fndecl); c_determine_visibility (fndecl);
...@@ -7923,10 +7919,6 @@ c_write_global_declarations (void) ...@@ -7923,10 +7919,6 @@ c_write_global_declarations (void)
c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t))); c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
c_write_global_declarations_1 (BLOCK_VARS (ext_block)); c_write_global_declarations_1 (BLOCK_VARS (ext_block));
/* Call functions declared with the "constructor" or "destructor"
attribute. */
c_build_cdtor_fns ();
/* We're done parsing; proceed to optimize and emit assembly. /* We're done parsing; proceed to optimize and emit assembly.
FIXME: shouldn't be the front end's responsibility to call this. */ FIXME: shouldn't be the front end's responsibility to call this. */
cgraph_optimize (); cgraph_optimize ();
......
...@@ -168,6 +168,75 @@ static void cgraph_output_pending_asms (void); ...@@ -168,6 +168,75 @@ static void cgraph_output_pending_asms (void);
static FILE *cgraph_dump_file; static FILE *cgraph_dump_file;
static GTY (()) tree static_ctors;
static GTY (()) tree static_dtors;
/* When target does not have ctors and dtors, we call all constructor
and destructor by special initialization/destruction functio
recognized by collect2.
When we are going to build this function, collect all constructors and
destructors and turn them into normal functions. */
static void
record_cdtor_fn (tree fndecl)
{
if (targetm.have_ctors_dtors)
return;
if (DECL_STATIC_CONSTRUCTOR (fndecl))
{
static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
DECL_STATIC_CONSTRUCTOR (fndecl) = 0;
cgraph_mark_reachable_node (cgraph_node (fndecl));
}
if (DECL_STATIC_DESTRUCTOR (fndecl))
{
static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
DECL_STATIC_DESTRUCTOR (fndecl) = 0;
cgraph_mark_reachable_node (cgraph_node (fndecl));
}
}
/* Synthesize a function which calls all the global ctors or global
dtors in this file. This is only used for targets which do not
support .ctors/.dtors sections. */
static void
build_cdtor (int method_type, tree cdtors)
{
tree body = 0;
if (!cdtors)
return;
for (; cdtors; cdtors = TREE_CHAIN (cdtors))
append_to_statement_list (build_function_call_expr (TREE_VALUE (cdtors), 0),
&body);
cgraph_build_static_cdtor (method_type, body, DEFAULT_INIT_PRIORITY);
}
/* Generate functions to call static constructors and destructors
for targets that do not support .ctors/.dtors sections. These
functions have magic names which are detected by collect2. */
static void
cgraph_build_cdtor_fns (void)
{
if (!targetm.have_ctors_dtors)
{
build_cdtor ('I', static_ctors);
static_ctors = NULL_TREE;
build_cdtor ('D', static_dtors);
static_dtors = NULL_TREE;
}
else
{
gcc_assert (!static_ctors);
gcc_assert (!static_dtors);
}
}
/* Determine if function DECL is needed. That is, visible to something /* Determine if function DECL is needed. That is, visible to something
either outside this translation unit, something magic in the system either outside this translation unit, something magic in the system
configury, or (if not doing unit-at-a-time) to something we havn't configury, or (if not doing unit-at-a-time) to something we havn't
...@@ -458,6 +527,7 @@ cgraph_finalize_function (tree decl, bool nested) ...@@ -458,6 +527,7 @@ cgraph_finalize_function (tree decl, bool nested)
node->decl = decl; node->decl = decl;
node->local.finalized = true; node->local.finalized = true;
node->lowered = DECL_STRUCT_FUNCTION (decl)->cfg != NULL; node->lowered = DECL_STRUCT_FUNCTION (decl)->cfg != NULL;
record_cdtor_fn (node->decl);
if (node->nested) if (node->nested)
lower_nested_functions (decl); lower_nested_functions (decl);
gcc_assert (!node->nested); gcc_assert (!node->nested);
...@@ -1222,6 +1292,10 @@ cgraph_optimize (void) ...@@ -1222,6 +1292,10 @@ cgraph_optimize (void)
#ifdef ENABLE_CHECKING #ifdef ENABLE_CHECKING
verify_cgraph (); verify_cgraph ();
#endif #endif
/* Call functions declared with the "constructor" or "destructor"
attribute. */
cgraph_build_cdtor_fns ();
if (!flag_unit_at_a_time) if (!flag_unit_at_a_time)
{ {
cgraph_assemble_pending_functions (); cgraph_assemble_pending_functions ();
...@@ -1572,3 +1646,5 @@ save_inline_function_body (struct cgraph_node *node) ...@@ -1572,3 +1646,5 @@ save_inline_function_body (struct cgraph_node *node)
#endif #endif
return first_clone; return first_clone;
} }
#include "gt-cgraphunit.h"
2007-05-11 Jan Hubicka <jh@suse.cz>
* semantics.c (expand_or_defer_fn): Do not call c_record_cdtor_fn.
* decl2.c (start_objects): ctors and dtors are no longer public.
(cp_write_global_declarations): Do not call c_build_cdtor_fns.
2007-05-07 Andrew Pinski <andrew_pinski@playstation.sony.com> 2007-05-07 Andrew Pinski <andrew_pinski@playstation.sony.com>
* typeck.c (build_unary_op): Remove code that used to * typeck.c (build_unary_op): Remove code that used to
......
...@@ -2333,9 +2333,7 @@ start_objects (int method_type, int initp) ...@@ -2333,9 +2333,7 @@ start_objects (int method_type, int initp)
void_list_node)); void_list_node));
start_preparsed_function (fndecl, /*attrs=*/NULL_TREE, SF_PRE_PARSED); start_preparsed_function (fndecl, /*attrs=*/NULL_TREE, SF_PRE_PARSED);
/* It can be a static function as long as collect2 does not have TREE_PUBLIC (current_function_decl) = 0;
to scan the object file to find its ctor/dtor routine. */
TREE_PUBLIC (current_function_decl) = ! targetm.have_ctors_dtors;
/* Mark this declaration as used to avoid spurious warnings. */ /* Mark this declaration as used to avoid spurious warnings. */
TREE_USED (current_function_decl) = 1; TREE_USED (current_function_decl) = 1;
...@@ -3299,8 +3297,6 @@ cp_write_global_declarations (void) ...@@ -3299,8 +3297,6 @@ cp_write_global_declarations (void)
if (priority_info_map) if (priority_info_map)
splay_tree_delete (priority_info_map); splay_tree_delete (priority_info_map);
c_build_cdtor_fns ();
/* Generate any missing aliases. */ /* Generate any missing aliases. */
maybe_apply_pending_pragma_weaks (); maybe_apply_pending_pragma_weaks ();
......
...@@ -3188,10 +3188,6 @@ expand_or_defer_fn (tree fn) ...@@ -3188,10 +3188,6 @@ expand_or_defer_fn (tree fn)
return; return;
} }
/* Keep track of functions declared with the "constructor" and
"destructor" attribute. */
c_record_cdtor_fn (fn);
/* We make a decision about linkage for these functions at the end /* We make a decision about linkage for these functions at the end
of the compilation. Until that point, we do not want the back of the compilation. Until that point, we do not want the back
end to output them -- but we do want it to see the bodies of end to output them -- but we do want it to see the bodies of
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment