Bug Summary

File:build/gcc/cgraphclones.c
Warning:line 841, column 6
Value stored to 'edge' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name cgraphclones.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model static -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/gcc -resource-dir /usr/lib64/clang/13.0.0 -D IN_GCC -D HAVE_CONFIG_H -I . -I . -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/. -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libcpp/include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libcody -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libdecnumber -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libdecnumber/bid -I ../libdecnumber -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libbacktrace -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11 -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11/x86_64-suse-linux -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11/backward -internal-isystem /usr/lib64/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-narrowing -Wwrite-strings -Wno-error=format-diag -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fdeprecated-macro -fdebug-compilation-dir=/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/gcc -ferror-limit 19 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=plist-html -analyzer-config silence-checkers=core.NullDereference -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/clang-static-analyzer/2021-11-20-133755-20252-1/report-xlDb53.plist -x c++ /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c
1/* Callgraph clones
2 Copyright (C) 2003-2021 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21/* This module provide facilities for cloning functions. I.e. creating
22 new functions based on existing functions with simple modifications,
23 such as replacement of parameters.
24
25 To allow whole program optimization without actual presence of function
26 bodies, an additional infrastructure is provided for so-called virtual
27 clones
28
29 A virtual clone in the callgraph is a function that has no
30 associated body, just a description of how to create its body based
31 on a different function (which itself may be a virtual clone).
32
33 The description of function modifications includes adjustments to
34 the function's signature (which allows, for example, removing or
35 adding function arguments), substitutions to perform on the
36 function body, and, for inlined functions, a pointer to the
37 function that it will be inlined into.
38
39 It is also possible to redirect any edge of the callgraph from a
40 function to its virtual clone. This implies updating of the call
41 site to adjust for the new function signature.
42
43 Most of the transformations performed by inter-procedural
44 optimizations can be represented via virtual clones. For
45 instance, a constant propagation pass can produce a virtual clone
46 of the function which replaces one of its arguments by a
47 constant. The inliner can represent its decisions by producing a
48 clone of a function whose body will be later integrated into
49 a given function.
50
51 Using virtual clones, the program can be easily updated
52 during the Execute stage, solving most of pass interactions
53 problems that would otherwise occur during Transform.
54
55 Virtual clones are later materialized in the LTRANS stage and
56 turned into real functions. Passes executed after the virtual
57 clone were introduced also perform their Transform stage
58 on new functions, so for a pass there is no significant
59 difference between operating on a real function or a virtual
60 clone introduced before its Execute stage.
61
62 Optimization passes then work on virtual clones introduced before
63 their Execute stage as if they were real functions. The
64 only difference is that clones are not visible during the
65 Generate Summary stage. */
66
67#include "config.h"
68#include "system.h"
69#include "coretypes.h"
70#include "backend.h"
71#include "target.h"
72#include "rtl.h"
73#include "tree.h"
74#include "gimple.h"
75#include "stringpool.h"
76#include "cgraph.h"
77#include "lto-streamer.h"
78#include "tree-eh.h"
79#include "tree-cfg.h"
80#include "tree-inline.h"
81#include "dumpfile.h"
82#include "gimple-pretty-print.h"
83#include "alloc-pool.h"
84#include "symbol-summary.h"
85#include "tree-vrp.h"
86#include "ipa-prop.h"
87#include "ipa-fnsummary.h"
88#include "symtab-thunks.h"
89#include "symtab-clones.h"
90
91/* Create clone of edge in the node N represented by CALL_EXPR
92 the callgraph. */
93
94cgraph_edge *
95cgraph_edge::clone (cgraph_node *n, gcall *call_stmt, unsigned stmt_uid,
96 profile_count num, profile_count den,
97 bool update_original)
98{
99 cgraph_edge *new_edge;
100 profile_count::adjust_for_ipa_scaling (&num, &den);
101 profile_count prof_count = count.apply_scale (num, den);
102
103 if (indirect_unknown_callee)
104 {
105 tree decl;
106
107 if (call_stmt && (decl = gimple_call_fndecl (call_stmt))
108 /* When the call is speculative, we need to resolve it
109 via cgraph_resolve_speculation and not here. */
110 && !speculative)
111 {
112 cgraph_node *callee = cgraph_node::get (decl);
113 gcc_checking_assert (callee)((void)(!(callee) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 113, __FUNCTION__), 0 : 0))
;
114 new_edge = n->create_edge (callee, call_stmt, prof_count, true);
115 }
116 else
117 {
118 new_edge = n->create_indirect_edge (call_stmt,
119 indirect_info->ecf_flags,
120 prof_count, true);
121 *new_edge->indirect_info = *indirect_info;
122 }
123 }
124 else
125 {
126 new_edge = n->create_edge (callee, call_stmt, prof_count, true);
127 if (indirect_info)
128 {
129 new_edge->indirect_info
130 = ggc_cleared_alloc<cgraph_indirect_call_info> ();
131 *new_edge->indirect_info = *indirect_info;
132 }
133 }
134
135 new_edge->inline_failed = inline_failed;
136 new_edge->indirect_inlining_edge = indirect_inlining_edge;
137 if (!call_stmt)
138 new_edge->lto_stmt_uid = stmt_uid;
139 new_edge->speculative_id = speculative_id;
140 /* Clone flags that depend on call_stmt availability manually. */
141 new_edge->can_throw_external = can_throw_external;
142 new_edge->call_stmt_cannot_inline_p = call_stmt_cannot_inline_p;
143 new_edge->speculative = speculative;
144 new_edge->in_polymorphic_cdtor = in_polymorphic_cdtor;
145
146 /* Update IPA profile. Local profiles need no updating in original. */
147 if (update_original)
148 count = count.combine_with_ipa_count_within (count.ipa ()
149 - new_edge->count.ipa (),
150 caller->count);
151 symtab->call_edge_duplication_hooks (this, new_edge);
152 return new_edge;
153}
154
155/* Set flags of NEW_NODE and its decl. NEW_NODE is a newly created private
156 clone or its thunk. */
157
158static void
159set_new_clone_decl_and_node_flags (cgraph_node *new_node)
160{
161 DECL_EXTERNAL (new_node->decl)((contains_struct_check ((new_node->decl), (TS_DECL_COMMON
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 161, __FUNCTION__))->decl_common.decl_flag_1)
= 0;
162 TREE_PUBLIC (new_node->decl)((new_node->decl)->base.public_flag) = 0;
163 DECL_COMDAT (new_node->decl)((contains_struct_check ((new_node->decl), (TS_DECL_WITH_VIS
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 163, __FUNCTION__))->decl_with_vis.comdat_flag)
= 0;
164 DECL_WEAK (new_node->decl)((contains_struct_check ((new_node->decl), (TS_DECL_WITH_VIS
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 164, __FUNCTION__))->decl_with_vis.weak_flag)
= 0;
165 DECL_VIRTUAL_P (new_node->decl)((contains_struct_check ((new_node->decl), (TS_DECL_COMMON
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 165, __FUNCTION__))->decl_common.virtual_flag)
= 0;
166 DECL_STATIC_CONSTRUCTOR (new_node->decl)((tree_check ((new_node->decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 166, __FUNCTION__, (FUNCTION_DECL)))->function_decl.static_ctor_flag
)
= 0;
167 DECL_STATIC_DESTRUCTOR (new_node->decl)((tree_check ((new_node->decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 167, __FUNCTION__, (FUNCTION_DECL)))->function_decl.static_dtor_flag
)
= 0;
168 DECL_SET_IS_OPERATOR_NEW (new_node->decl, 0)set_function_decl_type ((tree_check ((new_node->decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 168, __FUNCTION__, (FUNCTION_DECL))), OPERATOR_NEW, 0)
;
169 DECL_SET_IS_OPERATOR_DELETE (new_node->decl, 0)set_function_decl_type ((tree_check ((new_node->decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 169, __FUNCTION__, (FUNCTION_DECL))), OPERATOR_DELETE, 0)
;
170 DECL_IS_REPLACEABLE_OPERATOR (new_node->decl)((tree_check ((new_node->decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 170, __FUNCTION__, (FUNCTION_DECL)))->function_decl.replaceable_operator
)
= 0;
171
172 new_node->externally_visible = 0;
173 new_node->local = 1;
174 new_node->lowered = true;
175 new_node->semantic_interposition = 0;
176}
177
178/* Duplicate thunk THUNK if necessary but make it to refer to NODE.
179 ARGS_TO_SKIP, if non-NULL, determines which parameters should be omitted.
180 Function can return NODE if no thunk is necessary, which can happen when
181 thunk is this_adjusting but we are removing this parameter. */
182
183static cgraph_node *
184duplicate_thunk_for_node (cgraph_node *thunk, cgraph_node *node)
185{
186 cgraph_node *new_thunk, *thunk_of;
187 thunk_of = thunk->callees->callee->ultimate_alias_target ();
188
189 if (thunk_of->thunk)
190 node = duplicate_thunk_for_node (thunk_of, node);
191
192 if (!DECL_ARGUMENTS (thunk->decl)((tree_check ((thunk->decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 192, __FUNCTION__, (FUNCTION_DECL)))->function_decl.arguments
)
)
193 thunk->get_untransformed_body ();
194
195 thunk_info *i = thunk_info::get (thunk);
196 cgraph_edge *cs;
197 for (cs = node->callers; cs; cs = cs->next_caller)
198 if (cs->caller->thunk)
199 {
200 thunk_info *i2 = thunk_info::get (cs->caller);
201 if (*i2 == *i)
202 return cs->caller;
203 }
204
205 tree new_decl;
206 clone_info *info = clone_info::get (node);
207 if (info && info->param_adjustments)
208 {
209 /* We do not need to duplicate this_adjusting thunks if we have removed
210 this. */
211 if (i->this_adjusting
212 && !info->param_adjustments->first_param_intact_p ())
213 return node;
214
215 new_decl = copy_node (thunk->decl);
216 ipa_param_body_adjustments body_adj (info->param_adjustments,
217 new_decl);
218 body_adj.modify_formal_parameters ();
219 }
220 else
221 new_decl = copy_node (thunk->decl);
222
223 gcc_checking_assert (!DECL_STRUCT_FUNCTION (new_decl))((void)(!(!((tree_check ((new_decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 223, __FUNCTION__, (FUNCTION_DECL)))->function_decl.f)) ?
fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 223, __FUNCTION__), 0 : 0))
;
224 gcc_checking_assert (!DECL_INITIAL (new_decl))((void)(!(!((contains_struct_check ((new_decl), (TS_DECL_COMMON
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 224, __FUNCTION__))->decl_common.initial)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 224, __FUNCTION__), 0 : 0))
;
225 gcc_checking_assert (!DECL_RESULT (new_decl))((void)(!(!((tree_check ((new_decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 225, __FUNCTION__, (FUNCTION_DECL)))->decl_non_common.result
)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 225, __FUNCTION__), 0 : 0))
;
226 gcc_checking_assert (!DECL_RTL_SET_P (new_decl))((void)(!(!(((tree_contains_struct[(((enum tree_code) (new_decl
)->base.code))][(TS_DECL_WRTL)])) && (contains_struct_check
((new_decl), (TS_DECL_WRTL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 226, __FUNCTION__))->decl_with_rtl.rtl != nullptr)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 226, __FUNCTION__), 0 : 0))
;
227
228 DECL_NAME (new_decl)((contains_struct_check ((new_decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 228, __FUNCTION__))->decl_minimal.name)
= clone_function_name_numbered (thunk->decl,
229 "artificial_thunk");
230 SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl))overwrite_decl_assembler_name (new_decl, ((contains_struct_check
((new_decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 230, __FUNCTION__))->decl_minimal.name))
;
231
232 /* We need to force DECL_IGNORED_P because the new thunk is created after
233 early debug was run. */
234 DECL_IGNORED_P (new_decl)((contains_struct_check ((new_decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 234, __FUNCTION__))->decl_common.ignored_flag)
= 1;
235
236 new_thunk = cgraph_node::create (new_decl);
237 set_new_clone_decl_and_node_flags (new_thunk);
238 new_thunk->definition = true;
239 new_thunk->can_change_signature = node->can_change_signature;
240 new_thunk->thunk = thunk->thunk;
241 new_thunk->unique_name = in_lto_pglobal_options.x_in_lto_p;
242 new_thunk->former_clone_of = thunk->decl;
243 if (info && info->param_adjustments)
244 clone_info::get_create (new_thunk)->param_adjustments
245 = info->param_adjustments;
246 new_thunk->unit_id = thunk->unit_id;
247 new_thunk->merged_comdat = thunk->merged_comdat;
248 new_thunk->merged_extern_inline = thunk->merged_extern_inline;
249
250 cgraph_edge *e = new_thunk->create_edge (node, NULLnullptr, new_thunk->count);
251 symtab->call_edge_duplication_hooks (thunk->callees, e);
252 symtab->call_cgraph_duplication_hooks (thunk, new_thunk);
253 return new_thunk;
254}
255
256/* If E does not lead to a thunk, simply redirect it to N. Otherwise create
257 one or more equivalent thunks for N and redirect E to the first in the
258 chain. Note that it is then necessary to call
259 n->expand_all_artificial_thunks once all callers are redirected. */
260
261void
262cgraph_edge::redirect_callee_duplicating_thunks (cgraph_node *n)
263{
264 cgraph_node *orig_to = callee->ultimate_alias_target ();
265 if (orig_to->thunk)
266 n = duplicate_thunk_for_node (orig_to, n);
267
268 redirect_callee (n);
269}
270
271/* Call expand_thunk on all callers that are thunks and if analyze those nodes
272 that were expanded. */
273
274void
275cgraph_node::expand_all_artificial_thunks ()
276{
277 cgraph_edge *e;
278 for (e = callers; e;)
279 if (e->caller->thunk)
280 {
281 cgraph_node *thunk = e->caller;
282
283 e = e->next_caller;
284 if (expand_thunk (thunk, false, false))
285 {
286 thunk->thunk = false;
287 thunk->analyze ();
288 ipa_analyze_node (thunk);
289 inline_analyze_function (thunk);
290 }
291 thunk->expand_all_artificial_thunks ();
292 }
293 else
294 e = e->next_caller;
295}
296
297void
298dump_callgraph_transformation (const cgraph_node *original,
299 const cgraph_node *clone,
300 const char *suffix)
301{
302 if (symtab->ipa_clones_dump_file)
303 {
304 fprintf (symtab->ipa_clones_dump_file,
305 "Callgraph clone;%s;%d;%s;%d;%d;%s;%d;%s;%d;%d;%s\n",
306 original->asm_name (), original->order,
307 DECL_SOURCE_FILE (original->decl)((expand_location (((contains_struct_check ((original->decl
), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 307, __FUNCTION__))->decl_minimal.locus))).file)
,
308 DECL_SOURCE_LINE (original->decl)((expand_location (((contains_struct_check ((original->decl
), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 308, __FUNCTION__))->decl_minimal.locus))).line)
,
309 DECL_SOURCE_COLUMN (original->decl)((expand_location (((contains_struct_check ((original->decl
), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 309, __FUNCTION__))->decl_minimal.locus))).column)
, clone->asm_name (),
310 clone->order, DECL_SOURCE_FILE (clone->decl)((expand_location (((contains_struct_check ((clone->decl),
(TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 310, __FUNCTION__))->decl_minimal.locus))).file)
,
311 DECL_SOURCE_LINE (clone->decl)((expand_location (((contains_struct_check ((clone->decl),
(TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 311, __FUNCTION__))->decl_minimal.locus))).line)
, DECL_SOURCE_COLUMN (clone->decl)((expand_location (((contains_struct_check ((clone->decl),
(TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 311, __FUNCTION__))->decl_minimal.locus))).column)
,
312 suffix);
313
314 symtab->cloned_nodes.add (original);
315 symtab->cloned_nodes.add (clone);
316 }
317}
318
319/* Turn profile of N to local profile. */
320
321static void
322localize_profile (cgraph_node *n)
323{
324 n->count = n->count.guessed_local ();
325 for (cgraph_edge *e = n->callees; e; e=e->next_callee)
326 {
327 e->count = e->count.guessed_local ();
328 if (!e->inline_failed)
329 localize_profile (e->callee);
330 }
331 for (cgraph_edge *e = n->indirect_calls; e; e=e->next_callee)
332 e->count = e->count.guessed_local ();
333}
334
335/* Create node representing clone of N executed COUNT times. Decrease
336 the execution counts from original node too.
337 The new clone will have decl set to DECL that may or may not be the same
338 as decl of N.
339
340 When UPDATE_ORIGINAL is true, the counts are subtracted from the original
341 function's profile to reflect the fact that part of execution is handled
342 by node.
343 When CALL_DUPLICATION_HOOK is true, the ipa passes are acknowledged about
344 the new clone. Otherwise the caller is responsible for doing so later.
345
346 If the new node is being inlined into another one, NEW_INLINED_TO should be
347 the outline function the new one is (even indirectly) inlined to. All hooks
348 will see this in node's inlined_to, when invoked. Can be NULL if the
349 node is not inlined.
350
351 If PARAM_ADJUSTMENTS is non-NULL, the parameter manipulation information
352 will be overwritten by the new structure. Otherwise the new node will
353 share parameter manipulation information with the original node. */
354
355cgraph_node *
356cgraph_node::create_clone (tree new_decl, profile_count prof_count,
357 bool update_original,
358 vec<cgraph_edge *> redirect_callers,
359 bool call_duplication_hook,
360 cgraph_node *new_inlined_to,
361 ipa_param_adjustments *param_adjustments,
362 const char *suffix)
363{
364 cgraph_node *new_node = symtab->create_empty ();
365 cgraph_edge *e;
366 unsigned i;
367 profile_count old_count = count;
368 bool nonzero = count.ipa ().nonzero_p ();
369
370 if (new_inlined_to)
371 dump_callgraph_transformation (this, new_inlined_to, "inlining to");
372
373 /* When inlining we scale precisely to prof_count, when cloning we can
374 preserve local profile. */
375 if (!new_inlined_to)
376 prof_count = count.combine_with_ipa_count (prof_count);
377 new_node->count = prof_count;
378
379 /* Update IPA profile. Local profiles need no updating in original. */
380 if (update_original)
381 {
382 if (inlined_to)
383 count = count.combine_with_ipa_count_within (count.ipa ()
384 - prof_count.ipa (),
385 inlined_to->count);
386 else
387 count = count.combine_with_ipa_count (count.ipa () - prof_count.ipa ());
388 }
389 new_node->decl = new_decl;
390 new_node->register_symbol ();
391 new_node->lto_file_data = lto_file_data;
392 new_node->analyzed = analyzed;
393 new_node->definition = definition;
394 new_node->versionable = versionable;
395 new_node->can_change_signature = can_change_signature;
396 new_node->redefined_extern_inline = redefined_extern_inline;
397 new_node->tm_may_enter_irr = tm_may_enter_irr;
398 new_node->externally_visible = false;
399 new_node->no_reorder = no_reorder;
400 new_node->local = true;
401 new_node->inlined_to = new_inlined_to;
402 new_node->rtl = rtl;
403 new_node->frequency = frequency;
404 new_node->tp_first_run = tp_first_run;
405 new_node->tm_clone = tm_clone;
406 new_node->icf_merged = icf_merged;
407 new_node->thunk = thunk;
408 new_node->unit_id = unit_id;
409 new_node->merged_comdat = merged_comdat;
410 new_node->merged_extern_inline = merged_extern_inline;
411 clone_info *info = clone_info::get (this);
412
413 if (param_adjustments)
414 clone_info::get_create (new_node)->param_adjustments = param_adjustments;
415 else if (info && info->param_adjustments)
416 clone_info::get_create (new_node)->param_adjustments
417 = info->param_adjustments;
418 new_node->split_part = split_part;
419
420 FOR_EACH_VEC_ELT (redirect_callers, i, e)for (i = 0; (redirect_callers).iterate ((i), &(e)); ++(i)
)
421 {
422 /* Redirect calls to the old version node to point to its new
423 version. The only exception is when the edge was proved to
424 be unreachable during the cloning procedure. */
425 if (!e->callee
426 || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
427 e->redirect_callee_duplicating_thunks (new_node);
428 }
429 new_node->expand_all_artificial_thunks ();
430
431 for (e = callees;e; e=e->next_callee)
432 e->clone (new_node, e->call_stmt, e->lto_stmt_uid, new_node->count, old_count,
433 update_original);
434
435 for (e = indirect_calls; e; e = e->next_callee)
436 e->clone (new_node, e->call_stmt, e->lto_stmt_uid,
437 new_node->count, old_count, update_original);
438 new_node->clone_references (this);
439
440 new_node->next_sibling_clone = clones;
441 if (clones)
442 clones->prev_sibling_clone = new_node;
443 clones = new_node;
444 new_node->clone_of = this;
445
446 if (call_duplication_hook)
447 symtab->call_cgraph_duplication_hooks (this, new_node);
448 /* With partial train run we do not want to assume that original's
449 count is zero whenever we redurect all executed edges to clone.
450 Simply drop profile to local one in this case. */
451 if (update_original
452 && opt_for_fn (decl, flag_profile_partial_training)(opts_for_fn (decl)->x_flag_profile_partial_training)
453 && nonzero
454 && count.ipa_p ()
455 && !count.ipa ().nonzero_p ()
456 && !inlined_to)
457 localize_profile (this);
458
459 if (!new_inlined_to)
460 dump_callgraph_transformation (this, new_node, suffix);
461
462 return new_node;
463}
464
465static GTY(()) hash_map<const char *, unsigned> *clone_fn_ids;
466
467/* Return a new assembler name for a clone of decl named NAME. Apart
468 from the string SUFFIX, the new name will end with a unique (for
469 each NAME) unspecified number. If clone numbering is not needed
470 then the two argument clone_function_name should be used instead.
471 Should not be called directly except for by
472 lto-partition.c:privatize_symbol_name_1. */
473
474tree
475clone_function_name_numbered (const char *name, const char *suffix)
476{
477 /* Initialize the function->counter mapping the first time it's
478 needed. */
479 if (!clone_fn_ids)
480 clone_fn_ids = hash_map<const char *, unsigned int>::create_ggc (64);
481 unsigned int &suffix_counter = clone_fn_ids->get_or_insert (
482 IDENTIFIER_POINTER (get_identifier (name))((const char *) (tree_check (((__builtin_constant_p (name) ? get_identifier_with_length
((name), strlen (name)) : get_identifier (name))), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 482, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
483 return clone_function_name (name, suffix, suffix_counter++);
484}
485
486/* Return a new assembler name for a clone of DECL. Apart from string
487 SUFFIX, the new name will end with a unique (for each DECL
488 assembler name) unspecified number. If clone numbering is not
489 needed then the two argument clone_function_name should be used
490 instead. */
491
492tree
493clone_function_name_numbered (tree decl, const char *suffix)
494{
495 tree name = DECL_ASSEMBLER_NAME (decl)decl_assembler_name (decl);
496 return clone_function_name_numbered (IDENTIFIER_POINTER (name)((const char *) (tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 496, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
,
497 suffix);
498}
499
500/* Return a new assembler name for a clone of decl named NAME. Apart
501 from the string SUFFIX, the new name will end with the specified
502 NUMBER. If clone numbering is not needed then the two argument
503 clone_function_name should be used instead. */
504
505tree
506clone_function_name (const char *name, const char *suffix,
507 unsigned long number)
508{
509 size_t len = strlen (name);
510 char *tmp_name, *prefix;
511
512 prefix = XALLOCAVEC (char, len + strlen (suffix) + 2)((char *) __builtin_alloca(sizeof (char) * (len + strlen (suffix
) + 2)))
;
513 memcpy (prefix, name, len);
514 strcpy (prefix + len + 1, suffix);
515 prefix[len] = symbol_table::symbol_suffix_separator ();
516 ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix, number)do { const char *const name_ = (prefix); char *const output_ =
(tmp_name) = (char *) __builtin_alloca(strlen (name_) + 32);
sprintf (output_, "%s.%lu", name_, (unsigned long)(number));
} while (0)
;
517 return get_identifier (tmp_name)(__builtin_constant_p (tmp_name) ? get_identifier_with_length
((tmp_name), strlen (tmp_name)) : get_identifier (tmp_name))
;
518}
519
520/* Return a new assembler name for a clone of DECL. Apart from the
521 string SUFFIX, the new name will end with the specified NUMBER. If
522 clone numbering is not needed then the two argument
523 clone_function_name should be used instead. */
524
525tree
526clone_function_name (tree decl, const char *suffix,
527 unsigned long number)
528{
529 return clone_function_name (
530 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))((const char *) (tree_check ((decl_assembler_name (decl)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 530, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
, suffix, number);
531}
532
533/* Return a new assembler name ending with the string SUFFIX for a
534 clone of DECL. */
535
536tree
537clone_function_name (tree decl, const char *suffix)
538{
539 tree identifier = DECL_ASSEMBLER_NAME (decl)decl_assembler_name (decl);
540 /* For consistency this needs to behave the same way as
541 ASM_FORMAT_PRIVATE_NAME does, but without the final number
542 suffix. */
543 char *separator = XALLOCAVEC (char, 2)((char *) __builtin_alloca(sizeof (char) * (2)));
544 separator[0] = symbol_table::symbol_suffix_separator ();
545 separator[1] = 0;
546#if defined (NO_DOT_IN_LABEL) && defined (NO_DOLLAR_IN_LABEL)
547 const char *prefix = "__";
548#else
549 const char *prefix = "";
550#endif
551 char *result = ACONCAT ((prefix,(libiberty_concat_ptr = (char *) __builtin_alloca(concat_length
(prefix, ((const char *) (tree_check ((identifier), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 552, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
), separator, suffix, (char*)0) + 1), concat_copy2 (prefix, (
(const char *) (tree_check ((identifier), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 552, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
), separator, suffix, (char*)0))
552 IDENTIFIER_POINTER (identifier),(libiberty_concat_ptr = (char *) __builtin_alloca(concat_length
(prefix, ((const char *) (tree_check ((identifier), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 552, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
), separator, suffix, (char*)0) + 1), concat_copy2 (prefix, (
(const char *) (tree_check ((identifier), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 552, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
), separator, suffix, (char*)0))
553 separator,(libiberty_concat_ptr = (char *) __builtin_alloca(concat_length
(prefix, ((const char *) (tree_check ((identifier), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 552, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
), separator, suffix, (char*)0) + 1), concat_copy2 (prefix, (
(const char *) (tree_check ((identifier), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 552, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
), separator, suffix, (char*)0))
554 suffix,(libiberty_concat_ptr = (char *) __builtin_alloca(concat_length
(prefix, ((const char *) (tree_check ((identifier), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 552, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
), separator, suffix, (char*)0) + 1), concat_copy2 (prefix, (
(const char *) (tree_check ((identifier), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 552, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
), separator, suffix, (char*)0))
555 (char*)0))(libiberty_concat_ptr = (char *) __builtin_alloca(concat_length
(prefix, ((const char *) (tree_check ((identifier), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 552, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
), separator, suffix, (char*)0) + 1), concat_copy2 (prefix, (
(const char *) (tree_check ((identifier), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 552, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
), separator, suffix, (char*)0))
;
556 return get_identifier (result)(__builtin_constant_p (result) ? get_identifier_with_length (
(result), strlen (result)) : get_identifier (result))
;
557}
558
559
560/* Create callgraph node clone with new declaration. The actual body will be
561 copied later at compilation stage. The name of the new clone will be
562 constructed from the name of the original node, SUFFIX and NUM_SUFFIX.
563
564 TODO: after merging in ipa-sra use function call notes instead of args_to_skip
565 bitmap interface.
566 */
567cgraph_node *
568cgraph_node::create_virtual_clone (const vec<cgraph_edge *> &redirect_callers,
569 vec<ipa_replace_map *, va_gc> *tree_map,
570 ipa_param_adjustments *param_adjustments,
571 const char * suffix, unsigned num_suffix)
572{
573 tree old_decl = decl;
574 cgraph_node *new_node = NULLnullptr;
575 tree new_decl;
576 size_t len, i;
577 ipa_replace_map *map;
578 char *name;
579
580 gcc_checking_assert (versionable)((void)(!(versionable) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 580, __FUNCTION__), 0 : 0))
;
581 /* TODO: It would be nice if we could recognize that param_adjustments do not
582 actually perform any changes, but at the moment let's require it simply
583 does not exist. */
584 gcc_assert (can_change_signature || !param_adjustments)((void)(!(can_change_signature || !param_adjustments) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 584, __FUNCTION__), 0 : 0))
;
585
586 /* Make a new FUNCTION_DECL tree node */
587 if (!param_adjustments)
588 new_decl = copy_node (old_decl);
589 else
590 new_decl = param_adjustments->adjust_decl (old_decl);
591
592 /* These pointers represent function body and will be populated only when clone
593 is materialized. */
594 gcc_assert (new_decl != old_decl)((void)(!(new_decl != old_decl) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 594, __FUNCTION__), 0 : 0))
;
595 DECL_STRUCT_FUNCTION (new_decl)((tree_check ((new_decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 595, __FUNCTION__, (FUNCTION_DECL)))->function_decl.f)
= NULLnullptr;
596 DECL_ARGUMENTS (new_decl)((tree_check ((new_decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 596, __FUNCTION__, (FUNCTION_DECL)))->function_decl.arguments
)
= NULLnullptr;
597 DECL_INITIAL (new_decl)((contains_struct_check ((new_decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 597, __FUNCTION__))->decl_common.initial)
= NULLnullptr;
598 DECL_RESULT (new_decl)((tree_check ((new_decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 598, __FUNCTION__, (FUNCTION_DECL)))->decl_non_common.result
)
= NULLnullptr;
599 /* We cannot do DECL_RESULT (new_decl) = NULL; here because of LTO partitioning
600 sometimes storing only clone decl instead of original. */
601
602 /* Generate a new name for the new version. */
603 len = IDENTIFIER_LENGTH (DECL_NAME (old_decl))((tree_check ((((contains_struct_check ((old_decl), (TS_DECL_MINIMAL
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 603, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 603, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.len
)
;
604 name = XALLOCAVEC (char, len + strlen (suffix) + 2)((char *) __builtin_alloca(sizeof (char) * (len + strlen (suffix
) + 2)))
;
605 memcpy (name, IDENTIFIER_POINTER (DECL_NAME (old_decl))((const char *) (tree_check ((((contains_struct_check ((old_decl
), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 605, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 605, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
, len);
606 strcpy (name + len + 1, suffix);
607 name[len] = '.';
608 DECL_NAME (new_decl)((contains_struct_check ((new_decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 608, __FUNCTION__))->decl_minimal.name)
= get_identifier (name)(__builtin_constant_p (name) ? get_identifier_with_length ((name
), strlen (name)) : get_identifier (name))
;
609 SET_DECL_ASSEMBLER_NAME (new_decl,overwrite_decl_assembler_name (new_decl, clone_function_name (
old_decl, suffix, num_suffix))
610 clone_function_name (old_decl, suffix, num_suffix))overwrite_decl_assembler_name (new_decl, clone_function_name (
old_decl, suffix, num_suffix))
;
611 SET_DECL_RTL (new_decl, NULL)set_decl_rtl (new_decl, nullptr);
612
613 new_node = create_clone (new_decl, count, false,
614 redirect_callers, false, NULLnullptr, param_adjustments,
615 suffix);
616
617 /* Update the properties.
618 Make clone visible only within this translation unit. Make sure
619 that is not weak also.
620 ??? We cannot use COMDAT linkage because there is no
621 ABI support for this. */
622 set_new_clone_decl_and_node_flags (new_node);
623 new_node->ipcp_clone = ipcp_clone;
624 if (tree_map)
625 clone_info::get_create (new_node)->tree_map = tree_map;
626 if (!implicit_section)
627 new_node->set_section (*this);
628
629 /* Clones of global symbols or symbols with unique names are unique. */
630 if ((TREE_PUBLIC (old_decl)((old_decl)->base.public_flag)
631 && !DECL_EXTERNAL (old_decl)((contains_struct_check ((old_decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 631, __FUNCTION__))->decl_common.decl_flag_1)
632 && !DECL_WEAK (old_decl)((contains_struct_check ((old_decl), (TS_DECL_WITH_VIS), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 632, __FUNCTION__))->decl_with_vis.weak_flag)
633 && !DECL_COMDAT (old_decl)((contains_struct_check ((old_decl), (TS_DECL_WITH_VIS), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 633, __FUNCTION__))->decl_with_vis.comdat_flag)
)
634 || in_lto_pglobal_options.x_in_lto_p)
635 new_node->unique_name = true;
636 FOR_EACH_VEC_SAFE_ELT (tree_map, i, map)for (i = 0; vec_safe_iterate ((tree_map), (i), &(map)); ++
(i))
637 {
638 tree repl = map->new_tree;
639 if (map->force_load_ref)
640 {
641 gcc_assert (TREE_CODE (repl) == ADDR_EXPR)((void)(!(((enum tree_code) (repl)->base.code) == ADDR_EXPR
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 641, __FUNCTION__), 0 : 0))
;
642 repl = get_base_address (TREE_OPERAND (repl, 0)(*((const_cast<tree*> (tree_operand_check ((repl), (0),
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 642, __FUNCTION__)))))
);
643 }
644 new_node->maybe_create_reference (repl, NULLnullptr);
645 }
646
647 if (ipa_transforms_to_apply.exists ())
648 new_node->ipa_transforms_to_apply
649 = ipa_transforms_to_apply.copy ();
650
651 symtab->call_cgraph_duplication_hooks (this, new_node);
652
653 return new_node;
654}
655
656/* callgraph node being removed from symbol table; see if its entry can be
657 replaced by other inline clone.
658 INFO is clone info to attach to the new root. */
659cgraph_node *
660cgraph_node::find_replacement (clone_info *info)
661{
662 cgraph_node *next_inline_clone, *replacement;
663
664 for (next_inline_clone = clones;
665 next_inline_clone
666 && next_inline_clone->decl != decl;
667 next_inline_clone = next_inline_clone->next_sibling_clone)
668 ;
669
670 /* If there is inline clone of the node being removed, we need
671 to put it into the position of removed node and reorganize all
672 other clones to be based on it. */
673 if (next_inline_clone)
674 {
675 cgraph_node *n;
676 cgraph_node *new_clones;
677
678 replacement = next_inline_clone;
679
680 /* Unlink inline clone from the list of clones of removed node. */
681 if (next_inline_clone->next_sibling_clone)
682 next_inline_clone->next_sibling_clone->prev_sibling_clone
683 = next_inline_clone->prev_sibling_clone;
684 if (next_inline_clone->prev_sibling_clone)
685 {
686 gcc_assert (clones != next_inline_clone)((void)(!(clones != next_inline_clone) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 686, __FUNCTION__), 0 : 0))
;
687 next_inline_clone->prev_sibling_clone->next_sibling_clone
688 = next_inline_clone->next_sibling_clone;
689 }
690 else
691 {
692 gcc_assert (clones == next_inline_clone)((void)(!(clones == next_inline_clone) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 692, __FUNCTION__), 0 : 0))
;
693 clones = next_inline_clone->next_sibling_clone;
694 }
695
696 new_clones = clones;
697 clones = NULLnullptr;
698
699 /* Copy clone info. */
700 if (info)
701 *clone_info::get_create (next_inline_clone) = *info;
702
703 /* Now place it into clone tree at same level at NODE. */
704 next_inline_clone->clone_of = clone_of;
705 next_inline_clone->prev_sibling_clone = NULLnullptr;
706 next_inline_clone->next_sibling_clone = NULLnullptr;
707 if (clone_of)
708 {
709 if (clone_of->clones)
710 clone_of->clones->prev_sibling_clone = next_inline_clone;
711 next_inline_clone->next_sibling_clone = clone_of->clones;
712 clone_of->clones = next_inline_clone;
713 }
714
715 /* Merge the clone list. */
716 if (new_clones)
717 {
718 if (!next_inline_clone->clones)
719 next_inline_clone->clones = new_clones;
720 else
721 {
722 n = next_inline_clone->clones;
723 while (n->next_sibling_clone)
724 n = n->next_sibling_clone;
725 n->next_sibling_clone = new_clones;
726 new_clones->prev_sibling_clone = n;
727 }
728 }
729
730 /* Update clone_of pointers. */
731 n = new_clones;
732 while (n)
733 {
734 n->clone_of = next_inline_clone;
735 n = n->next_sibling_clone;
736 }
737
738 /* Update order in order to be able to find a LTO section
739 with function body. */
740 replacement->order = order;
741
742 return replacement;
743 }
744 else
745 return NULLnullptr;
746}
747
748/* Like cgraph_set_call_stmt but walk the clone tree and update all
749 clones sharing the same function body.
750 When WHOLE_SPECULATIVE_EDGES is true, all three components of
751 speculative edge gets updated. Otherwise we update only direct
752 call. */
753
754void
755cgraph_node::set_call_stmt_including_clones (gimple *old_stmt,
756 gcall *new_stmt,
757 bool update_speculative)
758{
759 cgraph_node *node;
760 cgraph_edge *master_edge = get_edge (old_stmt);
761
762 if (master_edge)
763 cgraph_edge::set_call_stmt (master_edge, new_stmt, update_speculative);
764
765 node = clones;
766 if (node)
767 while (node != this)
768 {
769 cgraph_edge *edge = node->get_edge (old_stmt);
770 if (edge)
771 {
772 edge = cgraph_edge::set_call_stmt (edge, new_stmt,
773 update_speculative);
774 /* If UPDATE_SPECULATIVE is false, it means that we are turning
775 speculative call into a real code sequence. Update the
776 callgraph edges. */
777 if (edge->speculative && !update_speculative)
778 {
779 cgraph_edge *indirect = edge->speculative_call_indirect_edge ();
780
781 for (cgraph_edge *next, *direct
782 = edge->first_speculative_call_target ();
783 direct;
784 direct = next)
785 {
786 next = direct->next_speculative_call_target ();
787 direct->speculative_call_target_ref ()->speculative = false;
788 direct->speculative = false;
789 }
790 indirect->speculative = false;
791 }
792 }
793 if (node->clones)
794 node = node->clones;
795 else if (node->next_sibling_clone)
796 node = node->next_sibling_clone;
797 else
798 {
799 while (node != this && !node->next_sibling_clone)
800 node = node->clone_of;
801 if (node != this)
802 node = node->next_sibling_clone;
803 }
804 }
805}
806
807/* Like cgraph_create_edge walk the clone tree and update all clones sharing
808 same function body. If clones already have edge for OLD_STMT; only
809 update the edge same way as cgraph_set_call_stmt_including_clones does.
810
811 TODO: COUNT and LOOP_DEPTH should be properly distributed based on relative
812 frequencies of the clones. */
813
814void
815cgraph_node::create_edge_including_clones (cgraph_node *callee,
816 gimple *old_stmt, gcall *stmt,
817 profile_count count,
818 cgraph_inline_failed_t reason)
819{
820 cgraph_node *node;
821
822 if (!get_edge (stmt))
823 {
824 cgraph_edge *edge = create_edge (callee, stmt, count);
825 edge->inline_failed = reason;
826 }
827
828 node = clones;
829 if (node)
830 while (node != this)
831 /* Thunk clones do not get updated while copying inline function body. */
832 if (!node->thunk)
833 {
834 cgraph_edge *edge = node->get_edge (old_stmt);
835
836 /* It is possible that clones already contain the edge while
837 master didn't. Either we promoted indirect call into direct
838 call in the clone or we are processing clones of unreachable
839 master where edges has been removed. */
840 if (edge)
841 edge = cgraph_edge::set_call_stmt (edge, stmt);
Value stored to 'edge' is never read
842 else if (! node->get_edge (stmt))
843 {
844 edge = node->create_edge (callee, stmt, count);
845 edge->inline_failed = reason;
846 }
847
848 if (node->clones)
849 node = node->clones;
850 else if (node->next_sibling_clone)
851 node = node->next_sibling_clone;
852 else
853 {
854 while (node != this && !node->next_sibling_clone)
855 node = node->clone_of;
856 if (node != this)
857 node = node->next_sibling_clone;
858 }
859 }
860}
861
862/* Remove the node from cgraph and all inline clones inlined into it.
863 Skip however removal of FORBIDDEN_NODE and return true if it needs to be
864 removed. This allows to call the function from outer loop walking clone
865 tree. */
866
867bool
868cgraph_node::remove_symbol_and_inline_clones (cgraph_node *forbidden_node)
869{
870 cgraph_edge *e, *next;
871 bool found = false;
872
873 if (this == forbidden_node)
874 {
875 cgraph_edge::remove (callers);
876 return true;
877 }
878 for (e = callees; e; e = next)
879 {
880 next = e->next_callee;
881 if (!e->inline_failed)
882 found |= e->callee->remove_symbol_and_inline_clones (forbidden_node);
883 }
884 remove ();
885 return found;
886}
887
888/* The edges representing the callers of the NEW_VERSION node were
889 fixed by cgraph_function_versioning (), now the call_expr in their
890 respective tree code should be updated to call the NEW_VERSION. */
891
892static void
893update_call_expr (cgraph_node *new_version)
894{
895 cgraph_edge *e;
896
897 gcc_assert (new_version)((void)(!(new_version) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 897, __FUNCTION__), 0 : 0))
;
898
899 /* Update the call expr on the edges to call the new version. */
900 for (e = new_version->callers; e; e = e->next_caller)
901 {
902 function *inner_function = DECL_STRUCT_FUNCTION (e->caller->decl)((tree_check ((e->caller->decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 902, __FUNCTION__, (FUNCTION_DECL)))->function_decl.f)
;
903 gimple_call_set_fndecl (e->call_stmt, new_version->decl);
904 maybe_clean_eh_stmt_fn (inner_function, e->call_stmt);
905 }
906}
907
908
909/* Create a new cgraph node which is the new version of
910 callgraph node. REDIRECT_CALLERS holds the callers
911 edges which should be redirected to point to
912 NEW_VERSION. ALL the callees edges of the node
913 are cloned to the new version node. Return the new
914 version node.
915
916 If non-NULL BLOCK_TO_COPY determine what basic blocks
917 was copied to prevent duplications of calls that are dead
918 in the clone. */
919
920cgraph_node *
921cgraph_node::create_version_clone (tree new_decl,
922 vec<cgraph_edge *> redirect_callers,
923 bitmap bbs_to_copy,
924 const char *suffix)
925 {
926 cgraph_node *new_version;
927 cgraph_edge *e;
928 unsigned i;
929
930 new_version = cgraph_node::create (new_decl);
931
932 new_version->analyzed = analyzed;
933 new_version->definition = definition;
934 new_version->local = local;
935 new_version->externally_visible = false;
936 new_version->no_reorder = no_reorder;
937 new_version->local = new_version->definition;
938 new_version->inlined_to = inlined_to;
939 new_version->rtl = rtl;
940 new_version->count = count;
941 new_version->unit_id = unit_id;
942 new_version->merged_comdat = merged_comdat;
943 new_version->merged_extern_inline = merged_extern_inline;
944
945 for (e = callees; e; e=e->next_callee)
946 if (!bbs_to_copy
947 || bitmap_bit_p (bbs_to_copy, gimple_bb (e->call_stmt)->index))
948 e->clone (new_version, e->call_stmt,
949 e->lto_stmt_uid, count, count,
950 true);
951 for (e = indirect_calls; e; e=e->next_callee)
952 if (!bbs_to_copy
953 || bitmap_bit_p (bbs_to_copy, gimple_bb (e->call_stmt)->index))
954 e->clone (new_version, e->call_stmt,
955 e->lto_stmt_uid, count, count,
956 true);
957 FOR_EACH_VEC_ELT (redirect_callers, i, e)for (i = 0; (redirect_callers).iterate ((i), &(e)); ++(i)
)
958 {
959 /* Redirect calls to the old version node to point to its new
960 version. */
961 e->redirect_callee (new_version);
962 }
963
964 dump_callgraph_transformation (this, new_version, suffix);
965
966 return new_version;
967 }
968
969/* Perform function versioning.
970 Function versioning includes copying of the tree and
971 a callgraph update (creating a new cgraph node and updating
972 its callees and callers).
973
974 REDIRECT_CALLERS varray includes the edges to be redirected
975 to the new version.
976
977 TREE_MAP is a mapping of tree nodes we want to replace with
978 new ones (according to results of prior analysis).
979
980 If non-NULL ARGS_TO_SKIP determine function parameters to remove
981 from new version.
982 If SKIP_RETURN is true, the new version will return void.
983 If non-NULL BLOCK_TO_COPY determine what basic blocks to copy.
984 If non_NULL NEW_ENTRY determine new entry BB of the clone.
985
986 If TARGET_ATTRIBUTES is non-null, when creating a new declaration,
987 add the attributes to DECL_ATTRIBUTES. And call valid_attribute_p
988 that will promote value of the attribute DECL_FUNCTION_SPECIFIC_TARGET
989 of the declaration.
990
991 If VERSION_DECL is set true, use clone_function_name_numbered for the
992 function clone. Otherwise, use clone_function_name.
993
994 Return the new version's cgraph node. */
995
996cgraph_node *
997cgraph_node::create_version_clone_with_body
998 (vec<cgraph_edge *> redirect_callers,
999 vec<ipa_replace_map *, va_gc> *tree_map,
1000 ipa_param_adjustments *param_adjustments,
1001 bitmap bbs_to_copy, basic_block new_entry_block, const char *suffix,
1002 tree target_attributes, bool version_decl)
1003{
1004 tree old_decl = decl;
1005 cgraph_node *new_version_node = NULLnullptr;
1006 tree new_decl;
1007
1008 if (!tree_versionable_function_p (old_decl))
1009 return NULLnullptr;
1010
1011 /* TODO: Restore an assert that we do not change signature if
1012 can_change_signature is false. We cannot just check that
1013 param_adjustments is NULL because unfortunately ipa-split removes return
1014 values from such functions. */
1015
1016 /* Make a new FUNCTION_DECL tree node for the new version. */
1017 if (param_adjustments)
1018 new_decl = param_adjustments->adjust_decl (old_decl);
1019 else
1020 new_decl = copy_node (old_decl);
1021
1022 /* Generate a new name for the new version. */
1023 tree fnname = (version_decl ? clone_function_name_numbered (old_decl, suffix)
1024 : clone_function_name (old_decl, suffix));
1025 DECL_NAME (new_decl)((contains_struct_check ((new_decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1025, __FUNCTION__))->decl_minimal.name)
= fnname;
1026 SET_DECL_ASSEMBLER_NAME (new_decl, fnname)overwrite_decl_assembler_name (new_decl, fnname);
1027 SET_DECL_RTL (new_decl, NULL)set_decl_rtl (new_decl, nullptr);
1028
1029 DECL_VIRTUAL_P (new_decl)((contains_struct_check ((new_decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1029, __FUNCTION__))->decl_common.virtual_flag)
= 0;
1030
1031 if (target_attributes)
1032 {
1033 DECL_ATTRIBUTES (new_decl)((contains_struct_check ((new_decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1033, __FUNCTION__))->decl_common.attributes)
= target_attributes;
1034
1035 location_t saved_loc = input_location;
1036 tree v = TREE_VALUE (target_attributes)((tree_check ((target_attributes), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1036, __FUNCTION__, (TREE_LIST)))->list.value)
;
1037 input_location = DECL_SOURCE_LOCATION (new_decl)((contains_struct_check ((new_decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1037, __FUNCTION__))->decl_minimal.locus)
;
1038 bool r = targetm.target_option.valid_attribute_p (new_decl, NULLnullptr, v, 1);
1039 input_location = saved_loc;
1040 if (!r)
1041 return NULLnullptr;
1042 }
1043
1044 /* When the old decl was a con-/destructor make sure the clone isn't. */
1045 DECL_STATIC_CONSTRUCTOR (new_decl)((tree_check ((new_decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1045, __FUNCTION__, (FUNCTION_DECL)))->function_decl.static_ctor_flag
)
= 0;
1046 DECL_STATIC_DESTRUCTOR (new_decl)((tree_check ((new_decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1046, __FUNCTION__, (FUNCTION_DECL)))->function_decl.static_dtor_flag
)
= 0;
1047 DECL_SET_IS_OPERATOR_NEW (new_decl, 0)set_function_decl_type ((tree_check ((new_decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1047, __FUNCTION__, (FUNCTION_DECL))), OPERATOR_NEW, 0)
;
1048 DECL_SET_IS_OPERATOR_DELETE (new_decl, 0)set_function_decl_type ((tree_check ((new_decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1048, __FUNCTION__, (FUNCTION_DECL))), OPERATOR_DELETE, 0)
;
1049 DECL_IS_REPLACEABLE_OPERATOR (new_decl)((tree_check ((new_decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1049, __FUNCTION__, (FUNCTION_DECL)))->function_decl.replaceable_operator
)
= 0;
1050
1051 /* Create the new version's call-graph node.
1052 and update the edges of the new node. */
1053 new_version_node = create_version_clone (new_decl, redirect_callers,
1054 bbs_to_copy, suffix);
1055
1056 if (ipa_transforms_to_apply.exists ())
1057 new_version_node->ipa_transforms_to_apply
1058 = ipa_transforms_to_apply.copy ();
1059 /* Copy the OLD_VERSION_NODE function tree to the new version. */
1060 tree_function_versioning (old_decl, new_decl, tree_map, param_adjustments,
1061 false, bbs_to_copy, new_entry_block);
1062
1063 /* Update the new version's properties.
1064 Make The new version visible only within this translation unit. Make sure
1065 that is not weak also.
1066 ??? We cannot use COMDAT linkage because there is no
1067 ABI support for this. */
1068 new_version_node->make_decl_local ();
1069 DECL_VIRTUAL_P (new_version_node->decl)((contains_struct_check ((new_version_node->decl), (TS_DECL_COMMON
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1069, __FUNCTION__))->decl_common.virtual_flag)
= 0;
1070 new_version_node->externally_visible = 0;
1071 new_version_node->local = 1;
1072 new_version_node->lowered = true;
1073 if (!implicit_section)
1074 new_version_node->set_section (*this);
1075 /* Clones of global symbols or symbols with unique names are unique. */
1076 if ((TREE_PUBLIC (old_decl)((old_decl)->base.public_flag)
1077 && !DECL_EXTERNAL (old_decl)((contains_struct_check ((old_decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1077, __FUNCTION__))->decl_common.decl_flag_1)
1078 && !DECL_WEAK (old_decl)((contains_struct_check ((old_decl), (TS_DECL_WITH_VIS), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1078, __FUNCTION__))->decl_with_vis.weak_flag)
1079 && !DECL_COMDAT (old_decl)((contains_struct_check ((old_decl), (TS_DECL_WITH_VIS), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/cgraphclones.c"
, 1079, __FUNCTION__))->decl_with_vis.comdat_flag)
)
1080 || in_lto_pglobal_options.x_in_lto_p)
1081 new_version_node->unique_name = true;
1082
1083 /* Update the call_expr on the edges to call the new version node. */
1084 update_call_expr (new_version_node);
1085
1086 symtab->call_cgraph_insertion_hooks (new_version_node);
1087 return new_version_node;
1088}
1089
1090/* Remove the node from the tree of virtual and inline clones and make it a
1091 standalone node - not a clone any more. */
1092
1093void cgraph_node::remove_from_clone_tree ()
1094{
1095 if (next_sibling_clone)
1096 next_sibling_clone->prev_sibling_clone = prev_sibling_clone;
1097 if (prev_sibling_clone)
1098 prev_sibling_clone->next_sibling_clone = next_sibling_clone;
1099 else
1100 clone_of->clones = next_sibling_clone;
1101 next_sibling_clone = NULLnullptr;
1102 prev_sibling_clone = NULLnullptr;
1103 clone_of = NULLnullptr;
1104}
1105
1106/* Given virtual clone, turn it into actual clone. */
1107
1108void
1109cgraph_node::materialize_clone ()
1110{
1111 clone_info *info = clone_info::get (this);
1112 clone_of->get_untransformed_body ();
1113 former_clone_of = clone_of->decl;
1114 if (clone_of->former_clone_of)
1115 former_clone_of = clone_of->former_clone_of;
1116 if (symtab->dump_file)
1117 {
1118 fprintf (symtab->dump_file, "cloning %s to %s\n",
1119 clone_of->dump_name (),
1120 dump_name ());
1121 if (info && info->tree_map)
1122 {
1123 fprintf (symtab->dump_file, " replace map:");
1124 for (unsigned int i = 0;
1125 i < vec_safe_length (info->tree_map);
1126 i++)
1127 {
1128 ipa_replace_map *replace_info;
1129 replace_info = (*info->tree_map)[i];
1130 fprintf (symtab->dump_file, "%s %i -> ",
1131 i ? "," : "", replace_info->parm_num);
1132 print_generic_expr (symtab->dump_file,
1133 replace_info->new_tree);
1134 }
1135 fprintf (symtab->dump_file, "\n");
1136 }
1137 if (info && info->param_adjustments)
1138 info->param_adjustments->dump (symtab->dump_file);
1139 }
1140 clear_stmts_in_references ();
1141 /* Copy the OLD_VERSION_NODE function tree to the new version. */
1142 tree_function_versioning (clone_of->decl, decl,
1143 info ? info->tree_map : NULLnullptr,
1144 info ? info->param_adjustments : NULLnullptr,
1145 true, NULLnullptr, NULLnullptr);
1146 if (symtab->dump_file)
1147 {
1148 dump_function_to_file (clone_of->decl, symtab->dump_file,
1149 dump_flags);
1150 dump_function_to_file (decl, symtab->dump_file, dump_flags);
1151 }
1152
1153 cgraph_node *this_clone_of = clone_of;
1154 /* Function is no longer clone. */
1155 remove_from_clone_tree ();
1156 if (!this_clone_of->analyzed && !this_clone_of->clones)
1157 this_clone_of->release_body ();
1158}
1159
1160#include "gt-cgraphclones.h"