]>
Commit | Line | Data |
---|---|---|
31236dcd | 1 | /* Perform optimizations on tree structure. |
75a70cf9 | 2 | Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008 |
d29afff0 | 3 | Free Software Foundation, Inc. |
31236dcd | 4 | Written by Mark Michell (mark@codesourcery.com). |
5 | ||
6f0d25a6 | 6 | This file is part of GCC. |
31236dcd | 7 | |
6f0d25a6 | 8 | GCC is free software; you can redistribute it and/or modify it |
b278476e | 9 | under the terms of the GNU General Public License as published by |
aa139c3f | 10 | the Free Software Foundation; either version 3, or (at your option) |
b278476e | 11 | any later version. |
12 | ||
6f0d25a6 | 13 | GCC is distributed in the hope that it will be useful, but |
b278476e | 14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | General Public License for more details. | |
4d26ca8c | 17 | |
b278476e | 18 | You should have received a copy of the GNU General Public License |
aa139c3f | 19 | along with GCC; see the file COPYING3. If not see |
20 | <http://www.gnu.org/licenses/>. */ | |
31236dcd | 21 | |
22 | #include "config.h" | |
23 | #include "system.h" | |
805e22b2 | 24 | #include "coretypes.h" |
25 | #include "tm.h" | |
31236dcd | 26 | #include "tree.h" |
27 | #include "cp-tree.h" | |
28 | #include "rtl.h" | |
29 | #include "insn-config.h" | |
6cb10b66 | 30 | #include "input.h" |
31236dcd | 31 | #include "integrate.h" |
4d26ca8c | 32 | #include "toplev.h" |
31236dcd | 33 | #include "varray.h" |
1f1fa73c | 34 | #include "params.h" |
a846710f | 35 | #include "hashtab.h" |
853b7640 | 36 | #include "target.h" |
c37d72e9 | 37 | #include "debug.h" |
1e3b023c | 38 | #include "tree-inline.h" |
4ee9c684 | 39 | #include "flags.h" |
40 | #include "langhooks.h" | |
41 | #include "diagnostic.h" | |
42 | #include "tree-dump.h" | |
75a70cf9 | 43 | #include "gimple.h" |
31236dcd | 44 | |
31236dcd | 45 | /* Prototypes. */ |
46 | ||
ff64eef0 | 47 | static void update_cloned_parm (tree, tree, bool); |
cd25c883 | 48 | |
b8792625 | 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 | ||
54 | static void | |
ff64eef0 | 55 | update_cloned_parm (tree parm, tree cloned_parm, bool first) |
b8792625 | 56 | { |
57 | DECL_ABSTRACT_ORIGIN (cloned_parm) = parm; | |
b00bfd31 | 58 | |
47cd6605 | 59 | /* We may have taken its address. */ |
b00bfd31 | 60 | TREE_ADDRESSABLE (cloned_parm) = TREE_ADDRESSABLE (parm); |
61 | ||
47cd6605 | 62 | /* The definition might have different constness. */ |
b00bfd31 | 63 | TREE_READONLY (cloned_parm) = TREE_READONLY (parm); |
9031d10b | 64 | |
ff64eef0 | 65 | TREE_USED (cloned_parm) = !first || TREE_USED (parm); |
9031d10b | 66 | |
47cd6605 | 67 | /* The name may have changed from the declaration. */ |
b8792625 | 68 | DECL_NAME (cloned_parm) = DECL_NAME (parm); |
346064d9 | 69 | DECL_SOURCE_LOCATION (cloned_parm) = DECL_SOURCE_LOCATION (parm); |
39908afa | 70 | TREE_TYPE (cloned_parm) = TREE_TYPE (parm); |
b58456b5 | 71 | |
72 | DECL_GIMPLE_REG_P (cloned_parm) = DECL_GIMPLE_REG_P (parm); | |
b8792625 | 73 | } |
74 | ||
75a70cf9 | 75 | |
76 | /* FN is a function in High GIMPLE form that has a complete body and no | |
77 | CFG. CLONE is a function whose body is to be set to a copy of FN, | |
78 | mapping argument declarations according to the ARG_MAP splay_tree. */ | |
32020b10 | 79 | |
80 | static void | |
81 | clone_body (tree clone, tree fn, void *arg_map) | |
82 | { | |
83 | copy_body_data id; | |
75a70cf9 | 84 | gimple_seq new_body; |
85 | ||
86 | /* FN must already be in GIMPLE form. */ | |
87 | gcc_assert (gimple_body (fn)); | |
32020b10 | 88 | |
75a70cf9 | 89 | /* Clone the body, as if we were making an inline call. But, remap |
90 | the parameters in the callee to the parameters of caller. */ | |
32020b10 | 91 | memset (&id, 0, sizeof (id)); |
92 | id.src_fn = fn; | |
93 | id.dst_fn = clone; | |
94 | id.src_cfun = DECL_STRUCT_FUNCTION (fn); | |
75a70cf9 | 95 | id.decl_map = (struct pointer_map_t *) arg_map; |
32020b10 | 96 | |
97 | id.copy_decl = copy_decl_no_change; | |
98 | id.transform_call_graph_edges = CB_CGE_DUPLICATE; | |
99 | id.transform_new_cfg = true; | |
100 | id.transform_return_to_modify = false; | |
75a70cf9 | 101 | id.transform_lang_insert_block = NULL; |
32020b10 | 102 | |
103 | /* We're not inside any EH region. */ | |
104 | id.eh_region = -1; | |
105 | ||
106 | /* Actually copy the body. */ | |
75a70cf9 | 107 | new_body = remap_gimple_seq (gimple_body (fn), &id); |
108 | gimple_set_body (clone, new_body); | |
32020b10 | 109 | } |
110 | ||
e55cba4c | 111 | /* FN is a function that has a complete body. Clone the body as |
3160db1d | 112 | necessary. Returns nonzero if there's no longer any need to |
e55cba4c | 113 | process the main body. */ |
114 | ||
805e22b2 | 115 | bool |
116 | maybe_clone_body (tree fn) | |
e55cba4c | 117 | { |
e55cba4c | 118 | tree clone; |
ff64eef0 | 119 | bool first = true; |
e55cba4c | 120 | |
e55cba4c | 121 | /* We only clone constructors and destructors. */ |
122 | if (!DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn) | |
123 | && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn)) | |
124 | return 0; | |
125 | ||
8f80e66d | 126 | /* Emit the DWARF1 abstract instance. */ |
c37d72e9 | 127 | (*debug_hooks->deferred_inline_function) (fn); |
8f80e66d | 128 | |
e55cba4c | 129 | /* We know that any clones immediately follow FN in the TYPE_METHODS |
130 | list. */ | |
93c149df | 131 | push_to_top_level (); |
caa6fdce | 132 | FOR_EACH_CLONE (clone, fn) |
e55cba4c | 133 | { |
134 | tree parm; | |
135 | tree clone_parm; | |
136 | int parmno; | |
e3022db7 | 137 | struct pointer_map_t *decl_map; |
e55cba4c | 138 | |
139 | /* Update CLONE's source position information to match FN's. */ | |
346064d9 | 140 | DECL_SOURCE_LOCATION (clone) = DECL_SOURCE_LOCATION (fn); |
d3981643 | 141 | DECL_DECLARED_INLINE_P (clone) = DECL_DECLARED_INLINE_P (fn); |
0ce25b06 | 142 | DECL_COMDAT (clone) = DECL_COMDAT (fn); |
143 | DECL_WEAK (clone) = DECL_WEAK (fn); | |
ecd88073 | 144 | |
145 | /* We don't copy the comdat group from fn to clone because the assembler | |
146 | name of fn was corrupted by write_mangled_name by adding *INTERNAL* | |
147 | to it. By doing so, it also corrupted the comdat group. */ | |
148 | if (DECL_ONE_ONLY (fn)) | |
149 | DECL_COMDAT_GROUP (clone) = cxx_comdat_group (clone); | |
0ce25b06 | 150 | DECL_SECTION_NAME (clone) = DECL_SECTION_NAME (fn); |
f753592a | 151 | DECL_USE_TEMPLATE (clone) = DECL_USE_TEMPLATE (fn); |
152 | DECL_EXTERNAL (clone) = DECL_EXTERNAL (fn); | |
153 | DECL_INTERFACE_KNOWN (clone) = DECL_INTERFACE_KNOWN (fn); | |
154 | DECL_NOT_REALLY_EXTERN (clone) = DECL_NOT_REALLY_EXTERN (fn); | |
3418ec43 | 155 | TREE_PUBLIC (clone) = TREE_PUBLIC (fn); |
9c40570a | 156 | DECL_VISIBILITY (clone) = DECL_VISIBILITY (fn); |
b212f378 | 157 | DECL_VISIBILITY_SPECIFIED (clone) = DECL_VISIBILITY_SPECIFIED (fn); |
578887bb | 158 | DECL_DLLIMPORT_P (clone) = DECL_DLLIMPORT_P (fn); |
e55cba4c | 159 | |
47cd6605 | 160 | /* Adjust the parameter names and locations. */ |
17d36341 | 161 | parm = DECL_ARGUMENTS (fn); |
162 | clone_parm = DECL_ARGUMENTS (clone); | |
4cb90235 | 163 | /* Update the `this' parameter, which is always first. */ |
ff64eef0 | 164 | update_cloned_parm (parm, clone_parm, first); |
4cb90235 | 165 | parm = TREE_CHAIN (parm); |
166 | clone_parm = TREE_CHAIN (clone_parm); | |
17d36341 | 167 | if (DECL_HAS_IN_CHARGE_PARM_P (fn)) |
168 | parm = TREE_CHAIN (parm); | |
169 | if (DECL_HAS_VTT_PARM_P (fn)) | |
170 | parm = TREE_CHAIN (parm); | |
171 | if (DECL_HAS_VTT_PARM_P (clone)) | |
172 | clone_parm = TREE_CHAIN (clone_parm); | |
173 | for (; parm; | |
174 | parm = TREE_CHAIN (parm), clone_parm = TREE_CHAIN (clone_parm)) | |
0767cba9 | 175 | /* Update this parameter. */ |
ff64eef0 | 176 | update_cloned_parm (parm, clone_parm, first); |
17d36341 | 177 | |
e55cba4c | 178 | /* Start processing the function. */ |
3046c0a3 | 179 | start_preparsed_function (clone, NULL_TREE, SF_PRE_PARSED); |
e55cba4c | 180 | |
e55cba4c | 181 | /* Remap the parameters. */ |
e3022db7 | 182 | decl_map = pointer_map_create (); |
e55cba4c | 183 | for (parmno = 0, |
184 | parm = DECL_ARGUMENTS (fn), | |
185 | clone_parm = DECL_ARGUMENTS (clone); | |
186 | parm; | |
187 | ++parmno, | |
188 | parm = TREE_CHAIN (parm)) | |
189 | { | |
190 | /* Map the in-charge parameter to an appropriate constant. */ | |
191 | if (DECL_HAS_IN_CHARGE_PARM_P (fn) && parmno == 1) | |
192 | { | |
193 | tree in_charge; | |
f04596da | 194 | in_charge = in_charge_arg_for_name (DECL_NAME (clone)); |
e3022db7 | 195 | *pointer_map_insert (decl_map, parm) = in_charge; |
dcbeb3ef | 196 | } |
197 | else if (DECL_ARTIFICIAL (parm) | |
198 | && DECL_NAME (parm) == vtt_parm_identifier) | |
199 | { | |
0ce25b06 | 200 | /* For a subobject constructor or destructor, the next |
201 | argument is the VTT parameter. Remap the VTT_PARM | |
202 | from the CLONE to this parameter. */ | |
dcbeb3ef | 203 | if (DECL_HAS_VTT_PARM_P (clone)) |
0ce25b06 | 204 | { |
8f80e66d | 205 | DECL_ABSTRACT_ORIGIN (clone_parm) = parm; |
e3022db7 | 206 | *pointer_map_insert (decl_map, parm) = clone_parm; |
0ce25b06 | 207 | clone_parm = TREE_CHAIN (clone_parm); |
208 | } | |
209 | /* Otherwise, map the VTT parameter to `NULL'. */ | |
dcbeb3ef | 210 | else |
e3022db7 | 211 | *pointer_map_insert (decl_map, parm) = null_pointer_node; |
e55cba4c | 212 | } |
213 | /* Map other parameters to their equivalents in the cloned | |
214 | function. */ | |
215 | else | |
216 | { | |
e3022db7 | 217 | *pointer_map_insert (decl_map, parm) = clone_parm; |
e55cba4c | 218 | clone_parm = TREE_CHAIN (clone_parm); |
219 | } | |
220 | } | |
221 | ||
853b7640 | 222 | if (targetm.cxx.cdtor_returns_this ()) |
223 | { | |
224 | parm = DECL_RESULT (fn); | |
225 | clone_parm = DECL_RESULT (clone); | |
e3022db7 | 226 | *pointer_map_insert (decl_map, parm) = clone_parm; |
853b7640 | 227 | } |
1e3b023c | 228 | /* Clone the body. */ |
229 | clone_body (clone, fn, decl_map); | |
e55cba4c | 230 | |
231 | /* Clean up. */ | |
e3022db7 | 232 | pointer_map_destroy (decl_map); |
e55cba4c | 233 | |
95cedffb | 234 | /* The clone can throw iff the original function can throw. */ |
235 | cp_function_chain->can_throw = !TREE_NOTHROW (fn); | |
236 | ||
e55cba4c | 237 | /* Now, expand this function into RTL, if appropriate. */ |
8f80e66d | 238 | finish_function (0); |
239 | BLOCK_ABSTRACT_ORIGIN (DECL_INITIAL (clone)) = DECL_INITIAL (fn); | |
75a70cf9 | 240 | DECL_SAVED_TREE (clone) = NULL; |
6cb758f0 | 241 | expand_or_defer_fn (clone); |
ff64eef0 | 242 | first = false; |
e55cba4c | 243 | } |
93c149df | 244 | pop_from_top_level (); |
4d26ca8c | 245 | |
e55cba4c | 246 | /* We don't need to process the original function any further. */ |
247 | return 1; | |
248 | } |