]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/optimize.c
basic-block.h (reorder_block_def): Rename to reorder_block_def_p.
[thirdparty/gcc.git] / gcc / cp / optimize.c
CommitLineData
46e8c075 1/* Perform optimizations on tree structure.
3c2426b9
KH
2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004
3 Free Software Foundation, Inc.
46e8c075
MM
4 Written by Mark Michell (mark@codesourcery.com).
5
f5adbb8d 6This file is part of GCC.
46e8c075 7
f5adbb8d 8GCC is free software; you can redistribute it and/or modify it
06ceef4e
RK
9under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2, or (at your option)
11any later version.
12
f5adbb8d 13GCC is distributed in the hope that it will be useful, but
06ceef4e
RK
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
9c96f3f8 17
06ceef4e 18You should have received a copy of the GNU General Public License
f5adbb8d 19along with GCC; see the file COPYING. If not, write to the Free
06ceef4e
RK
20Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2102111-1307, USA. */
46e8c075
MM
22
23#include "config.h"
24#include "system.h"
4977bab6
ZW
25#include "coretypes.h"
26#include "tm.h"
46e8c075
MM
27#include "tree.h"
28#include "cp-tree.h"
29#include "rtl.h"
30#include "insn-config.h"
574a0ef5 31#include "input.h"
46e8c075 32#include "integrate.h"
9c96f3f8 33#include "toplev.h"
46e8c075 34#include "varray.h"
b850de4f 35#include "params.h"
11fe225a 36#include "hashtab.h"
2b85879e 37#include "debug.h"
25af8512 38#include "tree-inline.h"
6de9cd9a
DN
39#include "flags.h"
40#include "langhooks.h"
41#include "diagnostic.h"
42#include "tree-dump.h"
eadf906f 43#include "tree-gimple.h"
46e8c075 44
46e8c075
MM
45/* Prototypes. */
46
4977bab6 47static void update_cloned_parm (tree, tree);
95fabfd3 48
d60e5448
MM
49/* CLONED_PARM is a copy of CLONE, generated for a cloned constructor
50 or destructor. Update it to ensure that the source-position for
51 the cloned parameter matches that for the original, and that the
52 debugging generation code will be able to find the original PARM. */
53
54static void
4977bab6 55update_cloned_parm (tree parm, tree cloned_parm)
d60e5448
MM
56{
57 DECL_ABSTRACT_ORIGIN (cloned_parm) = parm;
d30a825a 58
c6002625 59 /* We may have taken its address. */
d30a825a
NS
60 TREE_ADDRESSABLE (cloned_parm) = TREE_ADDRESSABLE (parm);
61
c6002625 62 /* The definition might have different constness. */
d30a825a
NS
63 TREE_READONLY (cloned_parm) = TREE_READONLY (parm);
64
65 TREE_USED (cloned_parm) = TREE_USED (parm);
d60e5448 66
c6002625 67 /* The name may have changed from the declaration. */
d60e5448 68 DECL_NAME (cloned_parm) = DECL_NAME (parm);
f31686a3 69 DECL_SOURCE_LOCATION (cloned_parm) = DECL_SOURCE_LOCATION (parm);
d60e5448
MM
70}
71
db9b2174 72/* FN is a function that has a complete body. Clone the body as
838dfd8a 73 necessary. Returns nonzero if there's no longer any need to
db9b2174
MM
74 process the main body. */
75
4977bab6
ZW
76bool
77maybe_clone_body (tree fn)
db9b2174 78{
db9b2174
MM
79 tree clone;
80
db9b2174
MM
81 /* We only clone constructors and destructors. */
82 if (!DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
83 && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn))
84 return 0;
85
5daf7c0a 86 /* Emit the DWARF1 abstract instance. */
2b85879e 87 (*debug_hooks->deferred_inline_function) (fn);
5daf7c0a 88
db9b2174
MM
89 /* We know that any clones immediately follow FN in the TYPE_METHODS
90 list. */
f44b0c8e 91 push_to_top_level ();
db9b2174
MM
92 for (clone = TREE_CHAIN (fn);
93 clone && DECL_CLONED_FUNCTION_P (clone);
85b22f78 94 clone = TREE_CHAIN (clone))
db9b2174
MM
95 {
96 tree parm;
97 tree clone_parm;
98 int parmno;
25af8512 99 splay_tree decl_map;
db9b2174
MM
100
101 /* Update CLONE's source position information to match FN's. */
f31686a3 102 DECL_SOURCE_LOCATION (clone) = DECL_SOURCE_LOCATION (fn);
99389463 103 DECL_INLINE (clone) = DECL_INLINE (fn);
79065db2 104 DECL_DECLARED_INLINE_P (clone) = DECL_DECLARED_INLINE_P (fn);
3ec6bad3
MM
105 DECL_COMDAT (clone) = DECL_COMDAT (fn);
106 DECL_WEAK (clone) = DECL_WEAK (fn);
107 DECL_ONE_ONLY (clone) = DECL_ONE_ONLY (fn);
108 DECL_SECTION_NAME (clone) = DECL_SECTION_NAME (fn);
459c43ad
MM
109 DECL_USE_TEMPLATE (clone) = DECL_USE_TEMPLATE (fn);
110 DECL_EXTERNAL (clone) = DECL_EXTERNAL (fn);
111 DECL_INTERFACE_KNOWN (clone) = DECL_INTERFACE_KNOWN (fn);
112 DECL_NOT_REALLY_EXTERN (clone) = DECL_NOT_REALLY_EXTERN (fn);
b96ada87 113 TREE_PUBLIC (clone) = TREE_PUBLIC (fn);
968b41a1 114 DECL_VISIBILITY (clone) = DECL_VISIBILITY (fn);
db9b2174 115
c6002625 116 /* Adjust the parameter names and locations. */
02a1a68c
NS
117 parm = DECL_ARGUMENTS (fn);
118 clone_parm = DECL_ARGUMENTS (clone);
4a90862e 119 /* Update the `this' parameter, which is always first. */
d60e5448 120 update_cloned_parm (parm, clone_parm);
4a90862e
JM
121 parm = TREE_CHAIN (parm);
122 clone_parm = TREE_CHAIN (clone_parm);
02a1a68c
NS
123 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
124 parm = TREE_CHAIN (parm);
125 if (DECL_HAS_VTT_PARM_P (fn))
126 parm = TREE_CHAIN (parm);
127 if (DECL_HAS_VTT_PARM_P (clone))
128 clone_parm = TREE_CHAIN (clone_parm);
129 for (; parm;
130 parm = TREE_CHAIN (parm), clone_parm = TREE_CHAIN (clone_parm))
85b22f78
NS
131 /* Update this parameter. */
132 update_cloned_parm (parm, clone_parm);
02a1a68c 133
db9b2174 134 /* Start processing the function. */
058b15c1 135 start_preparsed_function (clone, NULL_TREE, SF_PRE_PARSED);
db9b2174 136
db9b2174 137 /* Remap the parameters. */
25af8512 138 decl_map = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
db9b2174
MM
139 for (parmno = 0,
140 parm = DECL_ARGUMENTS (fn),
141 clone_parm = DECL_ARGUMENTS (clone);
142 parm;
143 ++parmno,
144 parm = TREE_CHAIN (parm))
145 {
146 /* Map the in-charge parameter to an appropriate constant. */
147 if (DECL_HAS_IN_CHARGE_PARM_P (fn) && parmno == 1)
148 {
149 tree in_charge;
298d6f60 150 in_charge = in_charge_arg_for_name (DECL_NAME (clone));
25af8512 151 splay_tree_insert (decl_map,
db9b2174 152 (splay_tree_key) parm,
3ec6bad3 153 (splay_tree_value) in_charge);
e0fff4b3
JM
154 }
155 else if (DECL_ARTIFICIAL (parm)
156 && DECL_NAME (parm) == vtt_parm_identifier)
157 {
3ec6bad3
MM
158 /* For a subobject constructor or destructor, the next
159 argument is the VTT parameter. Remap the VTT_PARM
160 from the CLONE to this parameter. */
e0fff4b3 161 if (DECL_HAS_VTT_PARM_P (clone))
3ec6bad3 162 {
5daf7c0a 163 DECL_ABSTRACT_ORIGIN (clone_parm) = parm;
25af8512 164 splay_tree_insert (decl_map,
e0fff4b3 165 (splay_tree_key) parm,
3ec6bad3 166 (splay_tree_value) clone_parm);
3ec6bad3
MM
167 clone_parm = TREE_CHAIN (clone_parm);
168 }
169 /* Otherwise, map the VTT parameter to `NULL'. */
e0fff4b3 170 else
3ec6bad3 171 {
25af8512 172 splay_tree_insert (decl_map,
e0fff4b3 173 (splay_tree_key) parm,
3ec6bad3 174 (splay_tree_value) null_pointer_node);
3ec6bad3 175 }
db9b2174
MM
176 }
177 /* Map other parameters to their equivalents in the cloned
178 function. */
179 else
180 {
25af8512 181 splay_tree_insert (decl_map,
db9b2174
MM
182 (splay_tree_key) parm,
183 (splay_tree_value) clone_parm);
184 clone_parm = TREE_CHAIN (clone_parm);
185 }
186 }
187
25af8512
AO
188 /* Clone the body. */
189 clone_body (clone, fn, decl_map);
db9b2174
MM
190
191 /* Clean up. */
25af8512 192 splay_tree_delete (decl_map);
db9b2174 193
b2dd096b
MM
194 /* The clone can throw iff the original function can throw. */
195 cp_function_chain->can_throw = !TREE_NOTHROW (fn);
196
db9b2174 197 /* Now, expand this function into RTL, if appropriate. */
5daf7c0a
JM
198 finish_function (0);
199 BLOCK_ABSTRACT_ORIGIN (DECL_INITIAL (clone)) = DECL_INITIAL (fn);
8cd2462c 200 expand_or_defer_fn (clone);
db9b2174 201 }
f44b0c8e 202 pop_from_top_level ();
9c96f3f8 203
db9b2174
MM
204 /* We don't need to process the original function any further. */
205 return 1;
206}