diff options
author | Jan Hubicka <jh@suse.cz> | 2010-08-21 11:46:15 +0200 |
---|---|---|
committer | Jan Hubicka <hubicka@gcc.gnu.org> | 2010-08-21 09:46:15 +0000 |
commit | 508e475706c3560a86b08446e1bb764773b93ed9 (patch) | |
tree | dd592015baf43a7ac0105edb4a35dc0cecd6d50f /gcc/cgraph.c | |
parent | f1395d4a6e0ea98b1fa3b72d40f02fcba9801500 (diff) | |
download | gcc-508e475706c3560a86b08446e1bb764773b93ed9.zip gcc-508e475706c3560a86b08446e1bb764773b93ed9.tar.gz gcc-508e475706c3560a86b08446e1bb764773b93ed9.tar.bz2 |
re PR middle-end/45307 (Stores expanding to no RTL not removed by tree optimizers, Empty ctors/dtors not eliminated)
PR c++/45307
PR c++/17736
* cgraph.h (cgraph_only_called_directly_p,
cgraph_can_remove_if_no_direct_calls_and_refs_p): Handle
static cdtors.
* cgraphunit.c (cgraph_decide_is_function_needed): Static cdtors
are not needed.
(cgraph_finalize_function): Static cdtors are reachable.
(cgraph_mark_functions_to_output): Use cgraph_only_called_directly_p.
* gcc.dg/ipa/ctor-empty-1.c: Add testcase.
* g++.dg/tree-ssa/empty-2.C: Check that constructor got optimized out.
From-SVN: r163439
Diffstat (limited to 'gcc/cgraph.c')
-rw-r--r-- | gcc/cgraph.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/cgraph.c b/gcc/cgraph.c index 32ad190..470fb5a 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -2709,6 +2709,33 @@ cgraph_edge_cannot_lead_to_return (struct cgraph_edge *e) return cgraph_node_cannot_return (e->callee); } +/* Return true when function NODE can be removed from callgraph + if all direct calls are eliminated. */ + +bool +cgraph_can_remove_if_no_direct_calls_and_refs_p (struct cgraph_node *node) +{ + /* When function is needed, we can not remove it. */ + if (node->needed || node->reachable_from_other_partition) + return false; + /* Only COMDAT functions can be removed if externally visible. */ + if (node->local.externally_visible + && (!DECL_COMDAT (node->decl) || node->local.used_from_object_file)) + return false; + /* Constructors and destructors are executed by the runtime, however + we can get rid of all pure constructors and destructors. */ + if (DECL_STATIC_CONSTRUCTOR (node->decl) + || DECL_STATIC_DESTRUCTOR (node->decl)) + { + int flags = flags_from_decl_or_type (node->decl); + if (!optimize + || !(flags & (ECF_CONST | ECF_PURE)) + || (flags & ECF_LOOPING_CONST_OR_PURE)) + return false; + } + return true; +} + /* Return true when function NODE can be excpected to be removed from program when direct calls in this compilation unit are removed. |