| 1 |
/* Tree inlining. |
| 2 |
Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Alexandre Oliva <[email protected]> |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 7 |
GCC is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3, or (at your option) |
| 10 |
any later version. |
| 11 |
|
| 12 |
GCC is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with GCC; see the file COPYING3. If not see |
| 19 |
<http://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
#include "system.h" |
| 23 |
#include "coretypes.h" |
| 24 |
#include "backend.h" |
| 25 |
#include "target.h" |
| 26 |
#include "rtl.h" |
| 27 |
#include "tree.h" |
| 28 |
#include "gimple.h" |
| 29 |
#include "cfghooks.h" |
| 30 |
#include "tree-pass.h" |
| 31 |
#include "ssa.h" |
| 32 |
#include "cgraph.h" |
| 33 |
#include "tree-pretty-print.h" |
| 34 |
#include "diagnostic-core.h" |
| 35 |
#include "gimple-predict.h" |
| 36 |
#include "fold-const.h" |
| 37 |
#include "stor-layout.h" |
| 38 |
#include "calls.h" |
| 39 |
#include "tree-inline.h" |
| 40 |
#include "langhooks.h" |
| 41 |
#include "cfganal.h" |
| 42 |
#include "tree-iterator.h" |
| 43 |
#include "intl.h" |
| 44 |
#include "gimple-iterator.h" |
| 45 |
#include "gimple-fold.h" |
| 46 |
#include "tree-eh.h" |
| 47 |
#include "gimplify.h" |
| 48 |
#include "gimplify-me.h" |
| 49 |
#include "gimple-walk.h" |
| 50 |
#include "tree-cfg.h" |
| 51 |
#include "tree-into-ssa.h" |
| 52 |
#include "tree-dfa.h" |
| 53 |
#include "tree-ssa.h" |
| 54 |
#include "except.h" |
| 55 |
#include "debug.h" |
| 56 |
#include "value-prof.h" |
| 57 |
#include "cfgloop.h" |
| 58 |
#include "builtins.h" |
| 59 |
#include "stringpool.h" |
| 60 |
#include "attribs.h" |
| 61 |
#include "sreal.h" |
| 62 |
#include "tree-cfgcleanup.h" |
| 63 |
#include "tree-ssa-live.h" |
| 64 |
#include "alloc-pool.h" |
| 65 |
#include "symbol-summary.h" |
| 66 |
#include "symtab-thunks.h" |
| 67 |
#include "symtab-clones.h" |
| 68 |
#include "asan.h" |
| 69 |
|
| 70 |
/* I'm not real happy about this, but we need to handle gimple and |
| 71 |
non-gimple trees. */ |
| 72 |
|
| 73 |
/* Inlining, Cloning, Versioning, Parallelization |
| 74 |
|
| 75 |
Inlining: a function body is duplicated, but the PARM_DECLs are |
| 76 |
remapped into VAR_DECLs, and non-void RETURN_EXPRs become |
| 77 |
MODIFY_EXPRs that store to a dedicated returned-value variable. |
| 78 |
The duplicated eh_region info of the copy will later be appended |
| 79 |
to the info for the caller; the eh_region info in copied throwing |
| 80 |
statements and RESX statements are adjusted accordingly. |
| 81 |
|
| 82 |
Cloning: (only in C++) We have one body for a con/de/structor, and |
| 83 |
multiple function decls, each with a unique parameter list. |
| 84 |
Duplicate the body, using the given splay tree; some parameters |
| 85 |
will become constants (like 0 or 1). |
| 86 |
|
| 87 |
Versioning: a function body is duplicated and the result is a new |
| 88 |
function rather than into blocks of an existing function as with |
| 89 |
inlining. Some parameters will become constants. |
| 90 |
|
| 91 |
Parallelization: a region of a function is duplicated resulting in |
| 92 |
a new function. Variables may be replaced with complex expressions |
| 93 |
to enable shared variable semantics. |
| 94 |
|
| 95 |
All of these will simultaneously lookup any callgraph edges. If |
| 96 |
we're going to inline the duplicated function body, and the given |
| 97 |
function has some cloned callgraph nodes (one for each place this |
| 98 |
function will be inlined) those callgraph edges will be duplicated. |
| 99 |
If we're cloning the body, those callgraph edges will be |
| 100 |
updated to point into the new body. (Note that the original |
| 101 |
callgraph node and edge list will not be altered.) |
| 102 |
|
| 103 |
See the CALL_EXPR handling case in copy_tree_body_r (). */ |
| 104 |
|
| 105 |
/* To Do: |
| 106 |
|
| 107 |
o In order to make inlining-on-trees work, we pessimized |
| 108 |
function-local static constants. In particular, they are now |
| 109 |
always output, even when not addressed. Fix this by treating |
| 110 |
function-local static constants just like global static |
| 111 |
constants; the back-end already knows not to output them if they |
| 112 |
are not needed. |
| 113 |
|
| 114 |
o Provide heuristics to clamp inlining of recursive template |
| 115 |
calls? */ |
| 116 |
|
| 117 |
|
| 118 |
/* Weights that estimate_num_insns uses to estimate the size of the |
| 119 |
produced code. */ |
| 120 |
|
| 121 |
eni_weights eni_size_weights; |
| 122 |
|
| 123 |
/* Weights that estimate_num_insns uses to estimate the time necessary |
| 124 |
to execute the produced code. */ |
| 125 |
|
| 126 |
eni_weights eni_time_weights; |
| 127 |
|
| 128 |
/* Prototypes. */ |
| 129 |
|
| 130 |
static tree declare_return_variable (copy_body_data *, tree, tree, |
| 131 |
basic_block); |
| 132 |
static void remap_block (tree *, copy_body_data *); |
| 133 |
static void copy_bind_expr (tree *, int *, copy_body_data *); |
| 134 |
static void declare_inline_vars (tree, tree); |
| 135 |
static void remap_save_expr (tree *, hash_map<tree, tree> *, int *); |
| 136 |
static void prepend_lexical_block (tree current_block, tree new_block); |
| 137 |
static tree copy_result_decl_to_var (tree, copy_body_data *); |
| 138 |
static tree copy_decl_maybe_to_var (tree, copy_body_data *); |
| 139 |
static gimple_seq remap_gimple_stmt (gimple *, copy_body_data *); |
| 140 |
static void insert_init_stmt (copy_body_data *, basic_block, gimple *); |
| 141 |
|
| 142 |
/* Insert a tree->tree mapping for ID. Despite the name suggests |
| 143 |
that the trees should be variables, it is used for more than that. */ |
| 144 |
|
| 145 |
void |
| 146 |
insert_decl_map (copy_body_data *id, tree key, tree value) |
| 147 |
{ |
| 148 |
id->decl_map->put (key, value); |
| 149 |
|
| 150 |
/* Always insert an identity map as well. If we see this same new |
| 151 |
node again, we won't want to duplicate it a second time. */ |
| 152 |
if (key != value && value) |
| 153 |
id->decl_map->put (value, value); |
| 154 |
} |
| 155 |
|
| 156 |
/* If nonzero, we're remapping the contents of inlined debug |
| 157 |
statements. If negative, an error has occurred, such as a |
| 158 |
reference to a variable that isn't available in the inlined |
| 159 |
context. */ |
| 160 |
static int processing_debug_stmt = 0; |
| 161 |
|
| 162 |
/* Construct new SSA name for old NAME. ID is the inline context. */ |
| 163 |
|
| 164 |
static tree |
| 165 |
remap_ssa_name (tree name, copy_body_data *id) |
| 166 |
{ |
| 167 |
tree new_tree, var; |
| 168 |
tree *n; |
| 169 |
|
| 170 |
gcc_assert (TREE_CODE (name) == SSA_NAME); |
| 171 |
|
| 172 |
n = id->decl_map->get (name); |
| 173 |
if (n) |
| 174 |
{ |
| 175 |
/* When we perform edge redirection as part of CFG copy, IPA-SRA can |
| 176 |
remove an unused LHS from a call statement. Such LHS can however |
| 177 |
still appear in debug statements, but their value is lost in this |
| 178 |
function and we do not want to map them. */ |
| 179 |
if (id->killed_new_ssa_names |
| 180 |
&& id->killed_new_ssa_names->contains (*n)) |
| 181 |
{ |
| 182 |
gcc_assert (processing_debug_stmt); |
| 183 |
processing_debug_stmt = -1; |
| 184 |
return name; |
| 185 |
} |
| 186 |
|
| 187 |
return unshare_expr (*n); |
| 188 |
} |
| 189 |
|
| 190 |
if (processing_debug_stmt) |
| 191 |
{ |
| 192 |
if (SSA_NAME_IS_DEFAULT_DEF (name) |
| 193 |
&& TREE_CODE (SSA_NAME_VAR (name)) == PARM_DECL |
| 194 |
&& id->entry_bb == NULL |
| 195 |
&& single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (cfun))) |
| 196 |
{ |
| 197 |
gimple *def_temp; |
| 198 |
gimple_stmt_iterator gsi; |
| 199 |
tree val = SSA_NAME_VAR (name); |
| 200 |
|
| 201 |
n = id->decl_map->get (val); |
| 202 |
if (n != NULL) |
| 203 |
val = *n; |
| 204 |
if (TREE_CODE (val) != PARM_DECL |
| 205 |
&& !(VAR_P (val) && DECL_ABSTRACT_ORIGIN (val))) |
| 206 |
{ |
| 207 |
processing_debug_stmt = -1; |
| 208 |
return name; |
| 209 |
} |
| 210 |
n = id->decl_map->get (val); |
| 211 |
if (n && TREE_CODE (*n) == DEBUG_EXPR_DECL) |
| 212 |
return *n; |
| 213 |
tree vexpr = build_debug_expr_decl (TREE_TYPE (name)); |
| 214 |
/* FIXME: Is setting the mode really necessary? */ |
| 215 |
SET_DECL_MODE (vexpr, DECL_MODE (SSA_NAME_VAR (name))); |
| 216 |
def_temp = gimple_build_debug_source_bind (vexpr, val, NULL); |
| 217 |
gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun))); |
| 218 |
gsi_insert_before (&gsi, def_temp, GSI_SAME_STMT); |
| 219 |
insert_decl_map (id, val, vexpr); |
| 220 |
return vexpr; |
| 221 |
} |
| 222 |
|
| 223 |
processing_debug_stmt = -1; |
| 224 |
return name; |
| 225 |
} |
| 226 |
|
| 227 |
/* Remap anonymous SSA names or SSA names of anonymous decls. */ |
| 228 |
var = SSA_NAME_VAR (name); |
| 229 |
if (!var |
| 230 |
|| (!SSA_NAME_IS_DEFAULT_DEF (name) |
| 231 |
&& VAR_P (var) |
| 232 |
&& !VAR_DECL_IS_VIRTUAL_OPERAND (var) |
| 233 |
&& DECL_ARTIFICIAL (var) |
| 234 |
&& DECL_IGNORED_P (var) |
| 235 |
&& !DECL_NAME (var))) |
| 236 |
{ |
| 237 |
struct ptr_info_def *pi; |
| 238 |
new_tree = make_ssa_name (remap_type (TREE_TYPE (name), id)); |
| 239 |
if (!var && SSA_NAME_IDENTIFIER (name)) |
| 240 |
SET_SSA_NAME_VAR_OR_IDENTIFIER (new_tree, SSA_NAME_IDENTIFIER (name)); |
| 241 |
insert_decl_map (id, name, new_tree); |
| 242 |
SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree) |
| 243 |
= SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name); |
| 244 |
/* At least IPA points-to info can be directly transferred. */ |
| 245 |
if (id->src_cfun->gimple_df |
| 246 |
&& id->src_cfun->gimple_df->ipa_pta |
| 247 |
&& POINTER_TYPE_P (TREE_TYPE (name)) |
| 248 |
&& (pi = SSA_NAME_PTR_INFO (name)) |
| 249 |
&& !pi->pt.anything) |
| 250 |
{ |
| 251 |
struct ptr_info_def *new_pi = get_ptr_info (new_tree); |
| 252 |
new_pi->pt = pi->pt; |
| 253 |
} |
| 254 |
/* So can range-info. */ |
| 255 |
if (!POINTER_TYPE_P (TREE_TYPE (name)) |
| 256 |
&& SSA_NAME_RANGE_INFO (name)) |
| 257 |
duplicate_ssa_name_range_info (new_tree, name); |
| 258 |
return new_tree; |
| 259 |
} |
| 260 |
|
| 261 |
/* Do not set DEF_STMT yet as statement is not copied yet. We do that |
| 262 |
in copy_bb. */ |
| 263 |
new_tree = remap_decl (var, id); |
| 264 |
|
| 265 |
/* We might've substituted constant or another SSA_NAME for |
| 266 |
the variable. |
| 267 |
|
| 268 |
Replace the SSA name representing RESULT_DECL by variable during |
| 269 |
inlining: this saves us from need to introduce PHI node in a case |
| 270 |
return value is just partly initialized. */ |
| 271 |
if ((VAR_P (new_tree) || TREE_CODE (new_tree) == PARM_DECL) |
| 272 |
&& (!SSA_NAME_VAR (name) |
| 273 |
|| TREE_CODE (SSA_NAME_VAR (name)) != RESULT_DECL |
| 274 |
|| !id->transform_return_to_modify)) |
| 275 |
{ |
| 276 |
struct ptr_info_def *pi; |
| 277 |
new_tree = make_ssa_name (new_tree); |
| 278 |
insert_decl_map (id, name, new_tree); |
| 279 |
SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree) |
| 280 |
= SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name); |
| 281 |
/* At least IPA points-to info can be directly transferred. */ |
| 282 |
if (id->src_cfun->gimple_df |
| 283 |
&& id->src_cfun->gimple_df->ipa_pta |
| 284 |
&& POINTER_TYPE_P (TREE_TYPE (name)) |
| 285 |
&& (pi = SSA_NAME_PTR_INFO (name)) |
| 286 |
&& !pi->pt.anything) |
| 287 |
{ |
| 288 |
struct ptr_info_def *new_pi = get_ptr_info (new_tree); |
| 289 |
new_pi->pt = pi->pt; |
| 290 |
} |
| 291 |
/* So can range-info. */ |
| 292 |
if (!POINTER_TYPE_P (TREE_TYPE (name)) |
| 293 |
&& SSA_NAME_RANGE_INFO (name)) |
| 294 |
duplicate_ssa_name_range_info (new_tree, name); |
| 295 |
if (SSA_NAME_IS_DEFAULT_DEF (name)) |
| 296 |
{ |
| 297 |
/* By inlining function having uninitialized variable, we might |
| 298 |
extend the lifetime (variable might get reused). This cause |
| 299 |
ICE in the case we end up extending lifetime of SSA name across |
| 300 |
abnormal edge, but also increase register pressure. |
| 301 |
|
| 302 |
We simply initialize all uninitialized vars by 0 except |
| 303 |
for case we are inlining to very first BB. We can avoid |
| 304 |
this for all BBs that are not inside strongly connected |
| 305 |
regions of the CFG, but this is expensive to test. */ |
| 306 |
if (id->entry_bb |
| 307 |
&& SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name) |
| 308 |
&& (!SSA_NAME_VAR (name) |
| 309 |
|| TREE_CODE (SSA_NAME_VAR (name)) != PARM_DECL) |
| 310 |
&& (id->entry_bb != EDGE_SUCC (ENTRY_BLOCK_PTR_FOR_FN (cfun), |
| 311 |
0)->dest |
| 312 |
|| EDGE_COUNT (id->entry_bb->preds) != 1)) |
| 313 |
{ |
| 314 |
gimple_stmt_iterator gsi = gsi_last_bb (id->entry_bb); |
| 315 |
gimple *init_stmt; |
| 316 |
tree zero = build_zero_cst (TREE_TYPE (new_tree)); |
| 317 |
|
| 318 |
init_stmt = gimple_build_assign (new_tree, zero); |
| 319 |
gsi_insert_after (&gsi, init_stmt, GSI_NEW_STMT); |
| 320 |
SSA_NAME_IS_DEFAULT_DEF (new_tree) = 0; |
| 321 |
} |
| 322 |
else |
| 323 |
{ |
| 324 |
SSA_NAME_DEF_STMT (new_tree) = gimple_build_nop (); |
| 325 |
set_ssa_default_def (cfun, SSA_NAME_VAR (new_tree), new_tree); |
| 326 |
} |
| 327 |
} |
| 328 |
} |
| 329 |
else |
| 330 |
insert_decl_map (id, name, new_tree); |
| 331 |
return new_tree; |
| 332 |
} |
| 333 |
|
| 334 |
/* Remap DECL during the copying of the BLOCK tree for the function. */ |
| 335 |
|
| 336 |
tree |
| 337 |
remap_decl (tree decl, copy_body_data *id) |
| 338 |
{ |
| 339 |
tree *n; |
| 340 |
|
| 341 |
/* We only remap local variables in the current function. */ |
| 342 |
|
| 343 |
/* See if we have remapped this declaration. */ |
| 344 |
|
| 345 |
n = id->decl_map->get (decl); |
| 346 |
|
| 347 |
if (!n && processing_debug_stmt) |
| 348 |
{ |
| 349 |
processing_debug_stmt = -1; |
| 350 |
return decl; |
| 351 |
} |
| 352 |
|
| 353 |
/* When remapping a type within copy_gimple_seq_and_replace_locals, all |
| 354 |
necessary DECLs have already been remapped and we do not want to duplicate |
| 355 |
a decl coming from outside of the sequence we are copying. */ |
| 356 |
if (!n |
| 357 |
&& id->prevent_decl_creation_for_types |
| 358 |
&& id->remapping_type_depth > 0 |
| 359 |
&& (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)) |
| 360 |
return decl; |
| 361 |
|
| 362 |
/* If we didn't already have an equivalent for this declaration, create one |
| 363 |
now. */ |
| 364 |
if (!n) |
| 365 |
{ |
| 366 |
/* Make a copy of the variable or label. */ |
| 367 |
tree t = id->copy_decl (decl, id); |
| 368 |
|
| 369 |
/* Remember it, so that if we encounter this local entity again |
| 370 |
we can reuse this copy. Do this early because remap_type may |
| 371 |
need this decl for TYPE_STUB_DECL. */ |
| 372 |
insert_decl_map (id, decl, t); |
| 373 |
|
| 374 |
if (!DECL_P (t) || t == decl) |
| 375 |
return t; |
| 376 |
|
| 377 |
/* Remap types, if necessary. */ |
| 378 |
TREE_TYPE (t) = remap_type (TREE_TYPE (t), id); |
| 379 |
if (TREE_CODE (t) == TYPE_DECL) |
| 380 |
{ |
| 381 |
DECL_ORIGINAL_TYPE (t) = remap_type (DECL_ORIGINAL_TYPE (t), id); |
| 382 |
|
| 383 |
/* Preserve the invariant that DECL_ORIGINAL_TYPE != TREE_TYPE, |
| 384 |
which is enforced in gen_typedef_die when DECL_ABSTRACT_ORIGIN |
| 385 |
is not set on the TYPE_DECL, for example in LTO mode. */ |
| 386 |
if (DECL_ORIGINAL_TYPE (t) == TREE_TYPE (t)) |
| 387 |
{ |
| 388 |
tree x = build_variant_type_copy (TREE_TYPE (t)); |
| 389 |
TYPE_STUB_DECL (x) = TYPE_STUB_DECL (TREE_TYPE (t)); |
| 390 |
TYPE_NAME (x) = TYPE_NAME (TREE_TYPE (t)); |
| 391 |
DECL_ORIGINAL_TYPE (t) = x; |
| 392 |
} |
| 393 |
} |
| 394 |
|
| 395 |
/* Remap sizes as necessary. */ |
| 396 |
walk_tree (&DECL_SIZE (t), copy_tree_body_r, id, NULL); |
| 397 |
walk_tree (&DECL_SIZE_UNIT (t), copy_tree_body_r, id, NULL); |
| 398 |
|
| 399 |
/* If fields, do likewise for offset and qualifier. */ |
| 400 |
if (TREE_CODE (t) == FIELD_DECL) |
| 401 |
{ |
| 402 |
walk_tree (&DECL_FIELD_OFFSET (t), copy_tree_body_r, id, NULL); |
| 403 |
if (TREE_CODE (DECL_CONTEXT (t)) == QUAL_UNION_TYPE) |
| 404 |
walk_tree (&DECL_QUALIFIER (t), copy_tree_body_r, id, NULL); |
| 405 |
} |
| 406 |
|
| 407 |
return t; |
| 408 |
} |
| 409 |
|
| 410 |
if (id->do_not_unshare) |
| 411 |
return *n; |
| 412 |
else |
| 413 |
return unshare_expr (*n); |
| 414 |
} |
| 415 |
|
| 416 |
static tree |
| 417 |
remap_type_1 (tree type, copy_body_data *id) |
| 418 |
{ |
| 419 |
tree new_tree, t; |
| 420 |
|
| 421 |
/* We do need a copy. build and register it now. If this is a pointer or |
| 422 |
reference type, remap the designated type and make a new pointer or |
| 423 |
reference type. */ |
| 424 |
if (TREE_CODE (type) == POINTER_TYPE) |
| 425 |
{ |
| 426 |
new_tree = build_pointer_type_for_mode (remap_type (TREE_TYPE (type), id), |
| 427 |
TYPE_MODE (type), |
| 428 |
TYPE_REF_CAN_ALIAS_ALL (type)); |
| 429 |
if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type)) |
| 430 |
new_tree = build_type_attribute_qual_variant (new_tree, |
| 431 |
TYPE_ATTRIBUTES (type), |
| 432 |
TYPE_QUALS (type)); |
| 433 |
insert_decl_map (id, type, new_tree); |
| 434 |
return new_tree; |
| 435 |
} |
| 436 |
else if (TREE_CODE (type) == REFERENCE_TYPE) |
| 437 |
{ |
| 438 |
new_tree = build_reference_type_for_mode (remap_type (TREE_TYPE (type), id), |
| 439 |
TYPE_MODE (type), |
| 440 |
TYPE_REF_CAN_ALIAS_ALL (type)); |
| 441 |
if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type)) |
| 442 |
new_tree = build_type_attribute_qual_variant (new_tree, |
| 443 |
TYPE_ATTRIBUTES (type), |
| 444 |
TYPE_QUALS (type)); |
| 445 |
insert_decl_map (id, type, new_tree); |
| 446 |
return new_tree; |
| 447 |
} |
| 448 |
else |
| 449 |
new_tree = copy_node (type); |
| 450 |
|
| 451 |
insert_decl_map (id, type, new_tree); |
| 452 |
|
| 453 |
/* This is a new type, not a copy of an old type. Need to reassociate |
| 454 |
variants. We can handle everything except the main variant lazily. */ |
| 455 |
t = TYPE_MAIN_VARIANT (type); |
| 456 |
if (type != t) |
| 457 |
{ |
| 458 |
t = remap_type (t, id); |
| 459 |
TYPE_MAIN_VARIANT (new_tree) = t; |
| 460 |
TYPE_NEXT_VARIANT (new_tree) = TYPE_NEXT_VARIANT (t); |
| 461 |
TYPE_NEXT_VARIANT (t) = new_tree; |
| 462 |
} |
| 463 |
else |
| 464 |
{ |
| 465 |
TYPE_MAIN_VARIANT (new_tree) = new_tree; |
| 466 |
TYPE_NEXT_VARIANT (new_tree) = NULL; |
| 467 |
} |
| 468 |
|
| 469 |
if (TYPE_STUB_DECL (type)) |
| 470 |
TYPE_STUB_DECL (new_tree) = remap_decl (TYPE_STUB_DECL (type), id); |
| 471 |
|
| 472 |
/* Lazily create pointer and reference types. */ |
| 473 |
TYPE_POINTER_TO (new_tree) = NULL; |
| 474 |
TYPE_REFERENCE_TO (new_tree) = NULL; |
| 475 |
|
| 476 |
/* Copy all types that may contain references to local variables; be sure to |
| 477 |
preserve sharing in between type and its main variant when possible. */ |
| 478 |
switch (TREE_CODE (new_tree)) |
| 479 |
{ |
| 480 |
case INTEGER_TYPE: |
| 481 |
case REAL_TYPE: |
| 482 |
case FIXED_POINT_TYPE: |
| 483 |
case ENUMERAL_TYPE: |
| 484 |
case BOOLEAN_TYPE: |
| 485 |
if (TYPE_MAIN_VARIANT (new_tree) != new_tree) |
| 486 |
{ |
| 487 |
gcc_checking_assert (TYPE_MIN_VALUE (type) == TYPE_MIN_VALUE (TYPE_MAIN_VARIANT (type))); |
| 488 |
gcc_checking_assert (TYPE_MAX_VALUE (type) == TYPE_MAX_VALUE (TYPE_MAIN_VARIANT (type))); |
| 489 |
|
| 490 |
TYPE_MIN_VALUE (new_tree) = TYPE_MIN_VALUE (TYPE_MAIN_VARIANT (new_tree)); |
| 491 |
TYPE_MAX_VALUE (new_tree) = TYPE_MAX_VALUE (TYPE_MAIN_VARIANT (new_tree)); |
| 492 |
} |
| 493 |
else |
| 494 |
{ |
| 495 |
t = TYPE_MIN_VALUE (new_tree); |
| 496 |
if (t && TREE_CODE (t) != INTEGER_CST) |
| 497 |
walk_tree (&TYPE_MIN_VALUE (new_tree), copy_tree_body_r, id, NULL); |
| 498 |
|
| 499 |
t = TYPE_MAX_VALUE (new_tree); |
| 500 |
if (t && TREE_CODE (t) != INTEGER_CST) |
| 501 |
walk_tree (&TYPE_MAX_VALUE (new_tree), copy_tree_body_r, id, NULL); |
| 502 |
} |
| 503 |
return new_tree; |
| 504 |
|
| 505 |
case FUNCTION_TYPE: |
| 506 |
if (TYPE_MAIN_VARIANT (new_tree) != new_tree |
| 507 |
&& TREE_TYPE (type) == TREE_TYPE (TYPE_MAIN_VARIANT (type))) |
| 508 |
TREE_TYPE (new_tree) = TREE_TYPE (TYPE_MAIN_VARIANT (new_tree)); |
| 509 |
else |
| 510 |
TREE_TYPE (new_tree) = remap_type (TREE_TYPE (new_tree), id); |
| 511 |
if (TYPE_MAIN_VARIANT (new_tree) != new_tree |
| 512 |
&& TYPE_ARG_TYPES (type) == TYPE_ARG_TYPES (TYPE_MAIN_VARIANT (type))) |
| 513 |
TYPE_ARG_TYPES (new_tree) = TYPE_ARG_TYPES (TYPE_MAIN_VARIANT (new_tree)); |
| 514 |
else |
| 515 |
walk_tree (&TYPE_ARG_TYPES (new_tree), copy_tree_body_r, id, NULL); |
| 516 |
return new_tree; |
| 517 |
|
| 518 |
case ARRAY_TYPE: |
| 519 |
if (TYPE_MAIN_VARIANT (new_tree) != new_tree |
| 520 |
&& TREE_TYPE (type) == TREE_TYPE (TYPE_MAIN_VARIANT (type))) |
| 521 |
TREE_TYPE (new_tree) = TREE_TYPE (TYPE_MAIN_VARIANT (new_tree)); |
| 522 |
else |
| 523 |
TREE_TYPE (new_tree) = remap_type (TREE_TYPE (new_tree), id); |
| 524 |
|
| 525 |
if (TYPE_MAIN_VARIANT (new_tree) != new_tree) |
| 526 |
{ |
| 527 |
gcc_checking_assert (TYPE_DOMAIN (type) |
| 528 |
== TYPE_DOMAIN (TYPE_MAIN_VARIANT (type))); |
| 529 |
TYPE_DOMAIN (new_tree) = TYPE_DOMAIN (TYPE_MAIN_VARIANT (new_tree)); |
| 530 |
} |
| 531 |
else |
| 532 |
{ |
| 533 |
TYPE_DOMAIN (new_tree) = remap_type (TYPE_DOMAIN (new_tree), id); |
| 534 |
/* For array bounds where we have decided not to copy over the bounds |
| 535 |
variable which isn't used in OpenMP/OpenACC region, change them to |
| 536 |
an uninitialized VAR_DECL temporary. */ |
| 537 |
if (id->adjust_array_error_bounds |
| 538 |
&& TYPE_DOMAIN (new_tree) |
| 539 |
&& TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) == error_mark_node |
| 540 |
&& TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node) |
| 541 |
{ |
| 542 |
tree v = create_tmp_var (TREE_TYPE (TYPE_DOMAIN (new_tree))); |
| 543 |
DECL_ATTRIBUTES (v) |
| 544 |
= tree_cons (get_identifier ("omp dummy var"), NULL_TREE, |
| 545 |
DECL_ATTRIBUTES (v)); |
| 546 |
TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) = v; |
| 547 |
} |
| 548 |
} |
| 549 |
break; |
| 550 |
|
| 551 |
case RECORD_TYPE: |
| 552 |
case UNION_TYPE: |
| 553 |
case QUAL_UNION_TYPE: |
| 554 |
if (TYPE_MAIN_VARIANT (type) != type |
| 555 |
&& TYPE_FIELDS (type) == TYPE_FIELDS (TYPE_MAIN_VARIANT (type))) |
| 556 |
TYPE_FIELDS (new_tree) = TYPE_FIELDS (TYPE_MAIN_VARIANT (new_tree)); |
| 557 |
else |
| 558 |
{ |
| 559 |
tree f, nf = NULL; |
| 560 |
|
| 561 |
for (f = TYPE_FIELDS (new_tree); f ; f = DECL_CHAIN (f)) |
| 562 |
{ |
| 563 |
t = remap_decl (f, id); |
| 564 |
DECL_CONTEXT (t) = new_tree; |
| 565 |
DECL_CHAIN (t) = nf; |
| 566 |
nf = t; |
| 567 |
} |
| 568 |
TYPE_FIELDS (new_tree) = nreverse (nf); |
| 569 |
} |
| 570 |
break; |
| 571 |
|
| 572 |
case OFFSET_TYPE: |
| 573 |
default: |
| 574 |
/* Shouldn't have been thought variable sized. */ |
| 575 |
gcc_unreachable (); |
| 576 |
} |
| 577 |
|
| 578 |
/* All variants of type share the same size, so use the already remaped data. */ |
| 579 |
if (TYPE_MAIN_VARIANT (new_tree) != new_tree) |
| 580 |
{ |
| 581 |
tree s = TYPE_SIZE (type); |
| 582 |
tree mvs = TYPE_SIZE (TYPE_MAIN_VARIANT (type)); |
| 583 |
tree su = TYPE_SIZE_UNIT (type); |
| 584 |
tree mvsu = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type)); |
| 585 |
gcc_checking_assert ((TREE_CODE (s) == PLACEHOLDER_EXPR |
| 586 |
&& (TREE_CODE (mvs) == PLACEHOLDER_EXPR)) |
| 587 |
|| s == mvs); |
| 588 |
gcc_checking_assert ((TREE_CODE (su) == PLACEHOLDER_EXPR |
| 589 |
&& (TREE_CODE (mvsu) == PLACEHOLDER_EXPR)) |
| 590 |
|| su == mvsu); |
| 591 |
TYPE_SIZE (new_tree) = TYPE_SIZE (TYPE_MAIN_VARIANT (new_tree)); |
| 592 |
TYPE_SIZE_UNIT (new_tree) = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (new_tree)); |
| 593 |
} |
| 594 |
else |
| 595 |
{ |
| 596 |
walk_tree (&TYPE_SIZE (new_tree), copy_tree_body_r, id, NULL); |
| 597 |
walk_tree (&TYPE_SIZE_UNIT (new_tree), copy_tree_body_r, id, NULL); |
| 598 |
} |
| 599 |
|
| 600 |
return new_tree; |
| 601 |
} |
| 602 |
|
| 603 |
/* Helper function for remap_type_2, called through walk_tree. */ |
| 604 |
|
| 605 |
static tree |
| 606 |
remap_type_3 (tree *tp, int *walk_subtrees, void *data) |
| 607 |
{ |
| 608 |
copy_body_data *id = (copy_body_data *) data; |
| 609 |
|
| 610 |
if (TYPE_P (*tp)) |
| 611 |
*walk_subtrees = 0; |
| 612 |
|
| 613 |
else if (DECL_P (*tp) && remap_decl (*tp, id) != *tp) |
| 614 |
return *tp; |
| 615 |
|
| 616 |
return NULL_TREE; |
| 617 |
} |
| 618 |
|
| 619 |
/* Return true if TYPE needs to be remapped because remap_decl on any |
| 620 |
needed embedded decl returns something other than that decl. */ |
| 621 |
|
| 622 |
static bool |
| 623 |
remap_type_2 (tree type, copy_body_data *id) |
| 624 |
{ |
| 625 |
tree t; |
| 626 |
|
| 627 |
#define RETURN_TRUE_IF_VAR(T) \ |
| 628 |
do \ |
| 629 |
{ \ |
| 630 |
tree _t = (T); \ |
| 631 |
if (_t) \ |
| 632 |
{ \ |
| 633 |
if (DECL_P (_t) && remap_decl (_t, id) != _t) \ |
| 634 |
return true; \ |
| 635 |
if (!TYPE_SIZES_GIMPLIFIED (type) \ |
| 636 |
&& walk_tree (&_t, remap_type_3, id, NULL)) \ |
| 637 |
return true; \ |
| 638 |
} \ |
| 639 |
} \ |
| 640 |
while (0) |
| 641 |
|
| 642 |
switch (TREE_CODE (type)) |
| 643 |
{ |
| 644 |
case POINTER_TYPE: |
| 645 |
case REFERENCE_TYPE: |
| 646 |
case FUNCTION_TYPE: |
| 647 |
case METHOD_TYPE: |
| 648 |
return remap_type_2 (TREE_TYPE (type), id); |
| 649 |
|
| 650 |
case INTEGER_TYPE: |
| 651 |
case REAL_TYPE: |
| 652 |
case FIXED_POINT_TYPE: |
| 653 |
case ENUMERAL_TYPE: |
| 654 |
case BOOLEAN_TYPE: |
| 655 |
RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type)); |
| 656 |
RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type)); |
| 657 |
return false; |
| 658 |
|
| 659 |
case ARRAY_TYPE: |
| 660 |
if (remap_type_2 (TREE_TYPE (type), id) |
| 661 |
|| (TYPE_DOMAIN (type) && remap_type_2 (TYPE_DOMAIN (type), id))) |
| 662 |
return true; |
| 663 |
break; |
| 664 |
|
| 665 |
case RECORD_TYPE: |
| 666 |
case UNION_TYPE: |
| 667 |
case QUAL_UNION_TYPE: |
| 668 |
for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t)) |
| 669 |
if (TREE_CODE (t) == FIELD_DECL) |
| 670 |
{ |
| 671 |
RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t)); |
| 672 |
RETURN_TRUE_IF_VAR (DECL_SIZE (t)); |
| 673 |
RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t)); |
| 674 |
if (TREE_CODE (type) == QUAL_UNION_TYPE) |
| 675 |
RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t)); |
| 676 |
} |
| 677 |
break; |
| 678 |
|
| 679 |
default: |
| 680 |
return false; |
| 681 |
} |
| 682 |
|
| 683 |
RETURN_TRUE_IF_VAR (TYPE_SIZE (type)); |
| 684 |
RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type)); |
| 685 |
return false; |
| 686 |
#undef RETURN_TRUE_IF_VAR |
| 687 |
} |
| 688 |
|
| 689 |
tree |
| 690 |
remap_type (tree type, copy_body_data *id) |
| 691 |
{ |
| 692 |
tree *node; |
| 693 |
tree tmp; |
| 694 |
|
| 695 |
if (type == NULL) |
| 696 |
return type; |
| 697 |
|
| 698 |
/* See if we have remapped this type. */ |
| 699 |
node = id->decl_map->get (type); |
| 700 |
if (node) |
| 701 |
return *node; |
| 702 |
|
| 703 |
/* The type only needs remapping if it's variably modified. */ |
| 704 |
if (! variably_modified_type_p (type, id->src_fn) |
| 705 |
/* Don't remap if copy_decl method doesn't always return a new |
| 706 |
decl and for all embedded decls returns the passed in decl. */ |
| 707 |
|| (id->dont_remap_vla_if_no_change && !remap_type_2 (type, id))) |
| 708 |
{ |
| 709 |
insert_decl_map (id, type, type); |
| 710 |
return type; |
| 711 |
} |
| 712 |
|
| 713 |
id->remapping_type_depth++; |
| 714 |
tmp = remap_type_1 (type, id); |
| 715 |
id->remapping_type_depth--; |
| 716 |
|
| 717 |
return tmp; |
| 718 |
} |
| 719 |
|
| 720 |
/* Decide if DECL can be put into BLOCK_NONLOCAL_VARs. */ |
| 721 |
|
| 722 |
static bool |
| 723 |
can_be_nonlocal (tree decl, copy_body_data *id) |
| 724 |
{ |
| 725 |
/* We cannot duplicate function decls. */ |
| 726 |
if (TREE_CODE (decl) == FUNCTION_DECL) |
| 727 |
return true; |
| 728 |
|
| 729 |
/* Local static vars must be non-local or we get multiple declaration |
| 730 |
problems. */ |
| 731 |
if (VAR_P (decl) && !auto_var_in_fn_p (decl, id->src_fn)) |
| 732 |
return true; |
| 733 |
|
| 734 |
return false; |
| 735 |
} |
| 736 |
|
| 737 |
static tree |
| 738 |
remap_decls (tree decls, vec<tree, va_gc> **nonlocalized_list, |
| 739 |
copy_body_data *id) |
| 740 |
{ |
| 741 |
tree old_var; |
| 742 |
tree new_decls = NULL_TREE; |
| 743 |
|
| 744 |
/* Remap its variables. */ |
| 745 |
for (old_var = decls; old_var; old_var = DECL_CHAIN (old_var)) |
| 746 |
{ |
| 747 |
tree new_var; |
| 748 |
|
| 749 |
if (can_be_nonlocal (old_var, id)) |
| 750 |
{ |
| 751 |
/* We need to add this variable to the local decls as otherwise |
| 752 |
nothing else will do so. */ |
| 753 |
if (VAR_P (old_var) && ! DECL_EXTERNAL (old_var) && cfun) |
| 754 |
add_local_decl (cfun, old_var); |
| 755 |
if ((!optimize || debug_info_level > DINFO_LEVEL_TERSE) |
| 756 |
&& !DECL_IGNORED_P (old_var) |
| 757 |
&& nonlocalized_list) |
| 758 |
vec_safe_push (*nonlocalized_list, old_var); |
| 759 |
continue; |
| 760 |
} |
| 761 |
|
| 762 |
/* Remap the variable. */ |
| 763 |
new_var = remap_decl (old_var, id); |
| 764 |
|
| 765 |
/* If we didn't remap this variable, we can't mess with its |
| 766 |
TREE_CHAIN. If we remapped this variable to the return slot, it's |
| 767 |
already declared somewhere else, so don't declare it here. */ |
| 768 |
|
| 769 |
if (new_var == old_var || new_var == id->retvar) |
| 770 |
; |
| 771 |
else if (!new_var) |
| 772 |
{ |
| 773 |
if ((!optimize || debug_info_level > DINFO_LEVEL_TERSE) |
| 774 |
&& !DECL_IGNORED_P (old_var) |
| 775 |
&& nonlocalized_list) |
| 776 |
vec_safe_push (*nonlocalized_list, old_var); |
| 777 |
} |
| 778 |
else |
| 779 |
{ |
| 780 |
gcc_assert (DECL_P (new_var)); |
| 781 |
DECL_CHAIN (new_var) = new_decls; |
| 782 |
new_decls = new_var; |
| 783 |
|
| 784 |
/* Also copy value-expressions. */ |
| 785 |
if (VAR_P (new_var) && DECL_HAS_VALUE_EXPR_P (new_var)) |
| 786 |
{ |
| 787 |
tree tem = DECL_VALUE_EXPR (new_var); |
| 788 |
bool old_regimplify = id->regimplify; |
| 789 |
id->remapping_type_depth++; |
| 790 |
walk_tree (&tem, copy_tree_body_r, id, NULL); |
| 791 |
id->remapping_type_depth--; |
| 792 |
id->regimplify = old_regimplify; |
| 793 |
SET_DECL_VALUE_EXPR (new_var, tem); |
| 794 |
} |
| 795 |
} |
| 796 |
} |
| 797 |
|
| 798 |
return nreverse (new_decls); |
| 799 |
} |
| 800 |
|
| 801 |
/* Copy the BLOCK to contain remapped versions of the variables |
| 802 |
therein. And hook the new block into the block-tree. */ |
| 803 |
|
| 804 |
static void |
| 805 |
remap_block (tree *block, copy_body_data *id) |
| 806 |
{ |
| 807 |
tree old_block; |
| 808 |
tree new_block; |
| 809 |
|
| 810 |
/* Make the new block. */ |
| 811 |
old_block = *block; |
| 812 |
new_block = make_node (BLOCK); |
| 813 |
TREE_USED (new_block) = TREE_USED (old_block); |
| 814 |
BLOCK_ABSTRACT_ORIGIN (new_block) = BLOCK_ORIGIN (old_block); |
| 815 |
BLOCK_SOURCE_LOCATION (new_block) = BLOCK_SOURCE_LOCATION (old_block); |
| 816 |
BLOCK_NONLOCALIZED_VARS (new_block) |
| 817 |
= vec_safe_copy (BLOCK_NONLOCALIZED_VARS (old_block)); |
| 818 |
*block = new_block; |
| 819 |
|
| 820 |
/* Remap its variables. */ |
| 821 |
BLOCK_VARS (new_block) = remap_decls (BLOCK_VARS (old_block), |
| 822 |
&BLOCK_NONLOCALIZED_VARS (new_block), |
| 823 |
id); |
| 824 |
|
| 825 |
/* Remember the remapped block. */ |
| 826 |
insert_decl_map (id, old_block, new_block); |
| 827 |
} |
| 828 |
|
| 829 |
/* Copy the whole block tree and root it in id->block. */ |
| 830 |
|
| 831 |
static tree |
| 832 |
remap_blocks (tree block, copy_body_data *id) |
| 833 |
{ |
| 834 |
tree t; |
| 835 |
tree new_tree = block; |
| 836 |
|
| 837 |
if (!block) |
| 838 |
return NULL; |
| 839 |
|
| 840 |
remap_block (&new_tree, id); |
| 841 |
gcc_assert (new_tree != block); |
| 842 |
for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t)) |
| 843 |
prepend_lexical_block (new_tree, remap_blocks (t, id)); |
| 844 |
/* Blocks are in arbitrary order, but make things slightly prettier and do |
| 845 |
not swap order when producing a copy. */ |
| 846 |
BLOCK_SUBBLOCKS (new_tree) = blocks_nreverse (BLOCK_SUBBLOCKS (new_tree)); |
| 847 |
return new_tree; |
| 848 |
} |
| 849 |
|
| 850 |
/* Remap the block tree rooted at BLOCK to nothing. */ |
| 851 |
|
| 852 |
static void |
| 853 |
remap_blocks_to_null (tree block, copy_body_data *id) |
| 854 |
{ |
| 855 |
tree t; |
| 856 |
insert_decl_map (id, block, NULL_TREE); |
| 857 |
for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t)) |
| 858 |
remap_blocks_to_null (t, id); |
| 859 |
} |
| 860 |
|
| 861 |
/* Remap the location info pointed to by LOCUS. */ |
| 862 |
|
| 863 |
static location_t |
| 864 |
remap_location (location_t locus, copy_body_data *id) |
| 865 |
{ |
| 866 |
if (LOCATION_BLOCK (locus)) |
| 867 |
{ |
| 868 |
tree *n = id->decl_map->get (LOCATION_BLOCK (locus)); |
| 869 |
gcc_assert (n); |
| 870 |
if (*n) |
| 871 |
return set_block (locus, *n); |
| 872 |
} |
| 873 |
|
| 874 |
locus = LOCATION_LOCUS (locus); |
| 875 |
|
| 876 |
if (locus != UNKNOWN_LOCATION && id->block) |
| 877 |
return set_block (locus, id->block); |
| 878 |
|
| 879 |
return locus; |
| 880 |
} |
| 881 |
|
| 882 |
static void |
| 883 |
copy_statement_list (tree *tp) |
| 884 |
{ |
| 885 |
tree_stmt_iterator oi, ni; |
| 886 |
tree new_tree; |
| 887 |
|
| 888 |
new_tree = alloc_stmt_list (); |
| 889 |
ni = tsi_start (new_tree); |
| 890 |
oi = tsi_start (*tp); |
| 891 |
TREE_TYPE (new_tree) = TREE_TYPE (*tp); |
| 892 |
*tp = new_tree; |
| 893 |
|
| 894 |
for (; !tsi_end_p (oi); tsi_next (&oi)) |
| 895 |
{ |
| 896 |
tree stmt = tsi_stmt (oi); |
| 897 |
if (TREE_CODE (stmt) == STATEMENT_LIST) |
| 898 |
/* This copy is not redundant; tsi_link_after will smash this |
| 899 |
STATEMENT_LIST into the end of the one we're building, and we |
| 900 |
don't want to do that with the original. */ |
| 901 |
copy_statement_list (&stmt); |
| 902 |
tsi_link_after (&ni, stmt, TSI_CONTINUE_LINKING); |
| 903 |
} |
| 904 |
} |
| 905 |
|
| 906 |
static void |
| 907 |
copy_bind_expr (tree *tp, int *walk_subtrees, copy_body_data *id) |
| 908 |
{ |
| 909 |
tree block = BIND_EXPR_BLOCK (*tp); |
| 910 |
/* Copy (and replace) the statement. */ |
| 911 |
copy_tree_r (tp, walk_subtrees, NULL); |
| 912 |
if (block) |
| 913 |
{ |
| 914 |
remap_block (&block, id); |
| 915 |
BIND_EXPR_BLOCK (*tp) = block; |
| 916 |
} |
| 917 |
|
| 918 |
if (BIND_EXPR_VARS (*tp)) |
| 919 |
/* This will remap a lot of the same decls again, but this should be |
| 920 |
harmless. */ |
| 921 |
BIND_EXPR_VARS (*tp) = remap_decls (BIND_EXPR_VARS (*tp), NULL, id); |
| 922 |
} |
| 923 |
|
| 924 |
|
| 925 |
/* Create a new gimple_seq by remapping all the statements in BODY |
| 926 |
using the inlining information in ID. */ |
| 927 |
|
| 928 |
static gimple_seq |
| 929 |
remap_gimple_seq (gimple_seq body, copy_body_data *id) |
| 930 |
{ |
| 931 |
gimple_stmt_iterator si; |
| 932 |
gimple_seq new_body = NULL; |
| 933 |
|
| 934 |
for (si = gsi_start (body); !gsi_end_p (si); gsi_next (&si)) |
| 935 |
{ |
| 936 |
gimple_seq new_stmts = remap_gimple_stmt (gsi_stmt (si), id); |
| 937 |
gimple_seq_add_seq (&new_body, new_stmts); |
| 938 |
} |
| 939 |
|
| 940 |
return new_body; |
| 941 |
} |
| 942 |
|
| 943 |
|
| 944 |
/* Copy a GIMPLE_BIND statement STMT, remapping all the symbols in its |
| 945 |
block using the mapping information in ID. */ |
| 946 |
|
| 947 |
static gimple * |
| 948 |
copy_gimple_bind (gbind *stmt, copy_body_data *id) |
| 949 |
{ |
| 950 |
gimple *new_bind; |
| 951 |
tree new_block, new_vars; |
| 952 |
gimple_seq body, new_body; |
| 953 |
|
| 954 |
/* Copy the statement. Note that we purposely don't use copy_stmt |
| 955 |
here because we need to remap statements as we copy. */ |
| 956 |
body = gimple_bind_body (stmt); |
| 957 |
new_body = remap_gimple_seq (body, id); |
| 958 |
|
| 959 |
new_block = gimple_bind_block (stmt); |
| 960 |
if (new_block) |
| 961 |
remap_block (&new_block, id); |
| 962 |
|
| 963 |
/* This will remap a lot of the same decls again, but this should be |
| 964 |
harmless. */ |
| 965 |
new_vars = gimple_bind_vars (stmt); |
| 966 |
if (new_vars) |
| 967 |
new_vars = remap_decls (new_vars, NULL, id); |
| 968 |
|
| 969 |
new_bind = gimple_build_bind (new_vars, new_body, new_block); |
| 970 |
|
| 971 |
return new_bind; |
| 972 |
} |
| 973 |
|
| 974 |
/* Return true if DECL is a parameter or a SSA_NAME for a parameter. */ |
| 975 |
|
| 976 |
static bool |
| 977 |
is_parm (tree decl) |
| 978 |
{ |
| 979 |
if (TREE_CODE (decl) == SSA_NAME) |
| 980 |
{ |
| 981 |
decl = SSA_NAME_VAR (decl); |
| 982 |
if (!decl) |
| 983 |
return false; |
| 984 |
} |
| 985 |
|
| 986 |
return (TREE_CODE (decl) == PARM_DECL); |
| 987 |
} |
| 988 |
|
| 989 |
/* Remap the dependence CLIQUE from the source to the destination function |
| 990 |
as specified in ID. */ |
| 991 |
|
| 992 |
static unsigned short |
| 993 |
remap_dependence_clique (copy_body_data *id, unsigned short clique) |
| 994 |
{ |
| 995 |
if (clique == 0 || processing_debug_stmt) |
| 996 |
return 0; |
| 997 |
if (!id->dependence_map) |
| 998 |
id->dependence_map = new hash_map<dependence_hash, unsigned short>; |
| 999 |
bool existed; |
| 1000 |
unsigned short &newc = id->dependence_map->get_or_insert (clique, &existed); |
| 1001 |
if (!existed) |
| 1002 |
{ |
| 1003 |
/* Clique 1 is reserved for local ones set by PTA. */ |
| 1004 |
if (cfun->last_clique == 0) |
| 1005 |
cfun->last_clique = 1; |
| 1006 |
newc = get_new_clique (cfun); |
| 1007 |
} |
| 1008 |
return newc; |
| 1009 |
} |
| 1010 |
|
| 1011 |
/* Remap the GIMPLE operand pointed to by *TP. DATA is really a |
| 1012 |
'struct walk_stmt_info *'. DATA->INFO is a 'copy_body_data *'. |
| 1013 |
WALK_SUBTREES is used to indicate walk_gimple_op whether to keep |
| 1014 |
recursing into the children nodes of *TP. */ |
| 1015 |
|
| 1016 |
static tree |
| 1017 |
remap_gimple_op_r (tree *tp, int *walk_subtrees, void *data) |
| 1018 |
{ |
| 1019 |
struct walk_stmt_info *wi_p = (struct walk_stmt_info *) data; |
| 1020 |
copy_body_data *id = (copy_body_data *) wi_p->info; |
| 1021 |
tree fn = id->src_fn; |
| 1022 |
|
| 1023 |
/* For recursive invocations this is no longer the LHS itself. */ |
| 1024 |
bool is_lhs = wi_p->is_lhs; |
| 1025 |
wi_p->is_lhs = false; |
| 1026 |
|
| 1027 |
if (TREE_CODE (*tp) == SSA_NAME) |
| 1028 |
{ |
| 1029 |
*tp = remap_ssa_name (*tp, id); |
| 1030 |
*walk_subtrees = 0; |
| 1031 |
if (is_lhs) |
| 1032 |
SSA_NAME_DEF_STMT (*tp) = wi_p->stmt; |
| 1033 |
return NULL; |
| 1034 |
} |
| 1035 |
else if (auto_var_in_fn_p (*tp, fn)) |
| 1036 |
{ |
| 1037 |
/* Local variables and labels need to be replaced by equivalent |
| 1038 |
variables. We don't want to copy static variables; there's |
| 1039 |
only one of those, no matter how many times we inline the |
| 1040 |
containing function. Similarly for globals from an outer |
| 1041 |
function. */ |
| 1042 |
tree new_decl; |
| 1043 |
|
| 1044 |
/* Remap the declaration. */ |
| 1045 |
new_decl = remap_decl (*tp, id); |
| 1046 |
gcc_assert (new_decl); |
| 1047 |
/* Replace this variable with the copy. */ |
| 1048 |
STRIP_TYPE_NOPS (new_decl); |
| 1049 |
/* ??? The C++ frontend uses void * pointer zero to initialize |
| 1050 |
any other type. This confuses the middle-end type verification. |
| 1051 |
As cloned bodies do not go through gimplification again the fixup |
| 1052 |
there doesn't trigger. */ |
| 1053 |
if (TREE_CODE (new_decl) == INTEGER_CST |
| 1054 |
&& !useless_type_conversion_p (TREE_TYPE (*tp), TREE_TYPE (new_decl))) |
| 1055 |
new_decl = fold_convert (TREE_TYPE (*tp), new_decl); |
| 1056 |
*tp = new_decl; |
| 1057 |
*walk_subtrees = 0; |
| 1058 |
} |
| 1059 |
else if (TREE_CODE (*tp) == STATEMENT_LIST) |
| 1060 |
gcc_unreachable (); |
| 1061 |
else if (TREE_CODE (*tp) == SAVE_EXPR) |
| 1062 |
gcc_unreachable (); |
| 1063 |
else if (TREE_CODE (*tp) == LABEL_DECL |
| 1064 |
&& (!DECL_CONTEXT (*tp) |
| 1065 |
|| decl_function_context (*tp) == id->src_fn)) |
| 1066 |
/* These may need to be remapped for EH handling. */ |
| 1067 |
*tp = remap_decl (*tp, id); |
| 1068 |
else if (TREE_CODE (*tp) == FIELD_DECL) |
| 1069 |
{ |
| 1070 |
/* If the enclosing record type is variably_modified_type_p, the field |
| 1071 |
has already been remapped. Otherwise, it need not be. */ |
| 1072 |
tree *n = id->decl_map->get (*tp); |
| 1073 |
if (n) |
| 1074 |
*tp = *n; |
| 1075 |
*walk_subtrees = 0; |
| 1076 |
} |
| 1077 |
else if (TYPE_P (*tp)) |
| 1078 |
/* Types may need remapping as well. */ |
| 1079 |
*tp = remap_type (*tp, id); |
| 1080 |
else if (CONSTANT_CLASS_P (*tp)) |
| 1081 |
{ |
| 1082 |
/* If this is a constant, we have to copy the node iff the type |
| 1083 |
will be remapped. copy_tree_r will not copy a constant. */ |
| 1084 |
tree new_type = remap_type (TREE_TYPE (*tp), id); |
| 1085 |
|
| 1086 |
if (new_type == TREE_TYPE (*tp)) |
| 1087 |
*walk_subtrees = 0; |
| 1088 |
|
| 1089 |
else if (TREE_CODE (*tp) == INTEGER_CST) |
| 1090 |
*tp = wide_int_to_tree (new_type, wi::to_wide (*tp)); |
| 1091 |
else |
| 1092 |
{ |
| 1093 |
*tp = copy_node (*tp); |
| 1094 |
TREE_TYPE (*tp) = new_type; |
| 1095 |
} |
| 1096 |
} |
| 1097 |
else |
| 1098 |
{ |
| 1099 |
/* Otherwise, just copy the node. Note that copy_tree_r already |
| 1100 |
knows not to copy VAR_DECLs, etc., so this is safe. */ |
| 1101 |
|
| 1102 |
if (TREE_CODE (*tp) == MEM_REF && !id->do_not_fold) |
| 1103 |
{ |
| 1104 |
/* We need to re-canonicalize MEM_REFs from inline substitutions |
| 1105 |
that can happen when a pointer argument is an ADDR_EXPR. |
| 1106 |
Recurse here manually to allow that. */ |
| 1107 |
tree ptr = TREE_OPERAND (*tp, 0); |
| 1108 |
tree type = remap_type (TREE_TYPE (*tp), id); |
| 1109 |
tree old = *tp; |
| 1110 |
walk_tree (&ptr, remap_gimple_op_r, data, NULL); |
| 1111 |
*tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1)); |
| 1112 |
TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); |
| 1113 |
TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old); |
| 1114 |
copy_warning (*tp, old); |
| 1115 |
if (MR_DEPENDENCE_CLIQUE (old) != 0) |
| 1116 |
{ |
| 1117 |
MR_DEPENDENCE_CLIQUE (*tp) |
| 1118 |
= remap_dependence_clique (id, MR_DEPENDENCE_CLIQUE (old)); |
| 1119 |
MR_DEPENDENCE_BASE (*tp) = MR_DEPENDENCE_BASE (old); |
| 1120 |
} |
| 1121 |
/* We cannot propagate the TREE_THIS_NOTRAP flag if we have |
| 1122 |
remapped a parameter as the property might be valid only |
| 1123 |
for the parameter itself. */ |
| 1124 |
if (TREE_THIS_NOTRAP (old) |
| 1125 |
&& (!is_parm (TREE_OPERAND (old, 0)) |
| 1126 |
|| (!id->transform_parameter && is_parm (ptr)))) |
| 1127 |
TREE_THIS_NOTRAP (*tp) = 1; |
| 1128 |
REF_REVERSE_STORAGE_ORDER (*tp) = REF_REVERSE_STORAGE_ORDER (old); |
| 1129 |
*walk_subtrees = 0; |
| 1130 |
return NULL; |
| 1131 |
} |
| 1132 |
|
| 1133 |
/* Here is the "usual case". Copy this tree node, and then |
| 1134 |
tweak some special cases. */ |
| 1135 |
copy_tree_r (tp, walk_subtrees, NULL); |
| 1136 |
|
| 1137 |
if (TREE_CODE (*tp) != OMP_CLAUSE) |
| 1138 |
TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id); |
| 1139 |
|
| 1140 |
if (TREE_CODE (*tp) == TARGET_EXPR && TREE_OPERAND (*tp, 3)) |
| 1141 |
{ |
| 1142 |
/* The copied TARGET_EXPR has never been expanded, even if the |
| 1143 |
original node was expanded already. */ |
| 1144 |
TREE_OPERAND (*tp, 1) = TREE_OPERAND (*tp, 3); |
| 1145 |
TREE_OPERAND (*tp, 3) = NULL_TREE; |
| 1146 |
} |
| 1147 |
else if (TREE_CODE (*tp) == ADDR_EXPR) |
| 1148 |
{ |
| 1149 |
/* Variable substitution need not be simple. In particular, |
| 1150 |
the MEM_REF substitution above. Make sure that |
| 1151 |
TREE_CONSTANT and friends are up-to-date. */ |
| 1152 |
int invariant = is_gimple_min_invariant (*tp); |
| 1153 |
walk_tree (&TREE_OPERAND (*tp, 0), remap_gimple_op_r, data, NULL); |
| 1154 |
recompute_tree_invariant_for_addr_expr (*tp); |
| 1155 |
|
| 1156 |
/* If this used to be invariant, but is not any longer, |
| 1157 |
then regimplification is probably needed. */ |
| 1158 |
if (invariant && !is_gimple_min_invariant (*tp)) |
| 1159 |
id->regimplify = true; |
| 1160 |
|
| 1161 |
*walk_subtrees = 0; |
| 1162 |
} |
| 1163 |
else if (TREE_CODE (*tp) == OMP_NEXT_VARIANT) |
| 1164 |
{ |
| 1165 |
/* Neither operand is interesting, and walking the selector |
| 1166 |
causes problems because it's not an expression. */ |
| 1167 |
gcc_assert (TREE_CODE (TREE_OPERAND (*tp, 0)) == INTEGER_CST); |
| 1168 |
*walk_subtrees = 0; |
| 1169 |
} |
| 1170 |
} |
| 1171 |
|
| 1172 |
/* Update the TREE_BLOCK for the cloned expr. */ |
| 1173 |
if (EXPR_P (*tp)) |
| 1174 |
{ |
| 1175 |
tree new_block = id->remapping_type_depth == 0 ? id->block : NULL; |
| 1176 |
tree old_block = TREE_BLOCK (*tp); |
| 1177 |
if (old_block) |
| 1178 |
{ |
| 1179 |
tree *n; |
| 1180 |
n = id->decl_map->get (TREE_BLOCK (*tp)); |
| 1181 |
if (n) |
| 1182 |
new_block = *n; |
| 1183 |
} |
| 1184 |
TREE_SET_BLOCK (*tp, new_block); |
| 1185 |
} |
| 1186 |
|
| 1187 |
/* Keep iterating. */ |
| 1188 |
return NULL_TREE; |
| 1189 |
} |
| 1190 |
|
| 1191 |
|
| 1192 |
/* Called from copy_body_id via walk_tree. DATA is really a |
| 1193 |
`copy_body_data *'. */ |
| 1194 |
|
| 1195 |
tree |
| 1196 |
copy_tree_body_r (tree *tp, int *walk_subtrees, void *data) |
| 1197 |
{ |
| 1198 |
copy_body_data *id = (copy_body_data *) data; |
| 1199 |
tree fn = id->src_fn; |
| 1200 |
tree new_block; |
| 1201 |
|
| 1202 |
/* Begin by recognizing trees that we'll completely rewrite for the |
| 1203 |
inlining context. Our output for these trees is completely |
| 1204 |
different from out input (e.g. RETURN_EXPR is deleted, and morphs |
| 1205 |
into an edge). Further down, we'll handle trees that get |
| 1206 |
duplicated and/or tweaked. */ |
| 1207 |
|
| 1208 |
/* When requested, RETURN_EXPRs should be transformed to just the |
| 1209 |
contained MODIFY_EXPR. The branch semantics of the return will |
| 1210 |
be handled elsewhere by manipulating the CFG rather than a statement. */ |
| 1211 |
if (TREE_CODE (*tp) == RETURN_EXPR && id->transform_return_to_modify) |
| 1212 |
{ |
| 1213 |
tree assignment = TREE_OPERAND (*tp, 0); |
| 1214 |
|
| 1215 |
/* If we're returning something, just turn that into an |
| 1216 |
assignment into the equivalent of the original RESULT_DECL. |
| 1217 |
If the "assignment" is just the result decl, the result |
| 1218 |
decl has already been set (e.g. a recent "foo (&result_decl, |
| 1219 |
...)"); just toss the entire RETURN_EXPR. */ |
| 1220 |
if (assignment && TREE_CODE (assignment) == MODIFY_EXPR) |
| 1221 |
{ |
| 1222 |
/* Replace the RETURN_EXPR with (a copy of) the |
| 1223 |
MODIFY_EXPR hanging underneath. */ |
| 1224 |
*tp = copy_node (assignment); |
| 1225 |
} |
| 1226 |
else /* Else the RETURN_EXPR returns no value. */ |
| 1227 |
{ |
| 1228 |
*tp = NULL; |
| 1229 |
return (tree) (void *)1; |
| 1230 |
} |
| 1231 |
} |
| 1232 |
else if (TREE_CODE (*tp) == SSA_NAME) |
| 1233 |
{ |
| 1234 |
*tp = remap_ssa_name (*tp, id); |
| 1235 |
*walk_subtrees = 0; |
| 1236 |
return NULL; |
| 1237 |
} |
| 1238 |
|
| 1239 |
/* Local variables and labels need to be replaced by equivalent |
| 1240 |
variables. We don't want to copy static variables; there's only |
| 1241 |
one of those, no matter how many times we inline the containing |
| 1242 |
function. Similarly for globals from an outer function. */ |
| 1243 |
else if (auto_var_in_fn_p (*tp, fn)) |
| 1244 |
{ |
| 1245 |
tree new_decl; |
| 1246 |
|
| 1247 |
/* Remap the declaration. */ |
| 1248 |
new_decl = remap_decl (*tp, id); |
| 1249 |
gcc_assert (new_decl); |
| 1250 |
/* Replace this variable with the copy. */ |
| 1251 |
STRIP_TYPE_NOPS (new_decl); |
| 1252 |
*tp = new_decl; |
| 1253 |
*walk_subtrees = 0; |
| 1254 |
} |
| 1255 |
else if (TREE_CODE (*tp) == STATEMENT_LIST) |
| 1256 |
copy_statement_list (tp); |
| 1257 |
else if (TREE_CODE (*tp) == SAVE_EXPR |
| 1258 |
|| TREE_CODE (*tp) == TARGET_EXPR) |
| 1259 |
remap_save_expr (tp, id->decl_map, walk_subtrees); |
| 1260 |
else if (TREE_CODE (*tp) == LABEL_DECL |
| 1261 |
&& (! DECL_CONTEXT (*tp) |
| 1262 |
|| decl_function_context (*tp) == id->src_fn)) |
| 1263 |
/* These may need to be remapped for EH handling. */ |
| 1264 |
*tp = remap_decl (*tp, id); |
| 1265 |
else if (TREE_CODE (*tp) == BIND_EXPR) |
| 1266 |
copy_bind_expr (tp, walk_subtrees, id); |
| 1267 |
/* Types may need remapping as well. */ |
| 1268 |
else if (TYPE_P (*tp)) |
| 1269 |
*tp = remap_type (*tp, id); |
| 1270 |
|
| 1271 |
/* If this is a constant, we have to copy the node iff the type will be |
| 1272 |
remapped. copy_tree_r will not copy a constant. */ |
| 1273 |
else if (CONSTANT_CLASS_P (*tp)) |
| 1274 |
{ |
| 1275 |
tree new_type = remap_type (TREE_TYPE (*tp), id); |
| 1276 |
|
| 1277 |
if (new_type == TREE_TYPE (*tp)) |
| 1278 |
*walk_subtrees = 0; |
| 1279 |
|
| 1280 |
else if (TREE_CODE (*tp) == INTEGER_CST) |
| 1281 |
*tp = wide_int_to_tree (new_type, wi::to_wide (*tp)); |
| 1282 |
else |
| 1283 |
{ |
| 1284 |
*tp = copy_node (*tp); |
| 1285 |
TREE_TYPE (*tp) = new_type; |
| 1286 |
} |
| 1287 |
} |
| 1288 |
|
| 1289 |
/* Otherwise, just copy the node. Note that copy_tree_r already |
| 1290 |
knows not to copy VAR_DECLs, etc., so this is safe. */ |
| 1291 |
else |
| 1292 |
{ |
| 1293 |
/* Here we handle trees that are not completely rewritten. |
| 1294 |
First we detect some inlining-induced bogosities for |
| 1295 |
discarding. */ |
| 1296 |
if (TREE_CODE (*tp) == MODIFY_EXPR |
| 1297 |
&& TREE_OPERAND (*tp, 0) == TREE_OPERAND (*tp, 1) |
| 1298 |
&& (auto_var_in_fn_p (TREE_OPERAND (*tp, 0), fn))) |
| 1299 |
{ |
| 1300 |
/* Some assignments VAR = VAR; don't generate any rtl code |
| 1301 |
and thus don't count as variable modification. Avoid |
| 1302 |
keeping bogosities like 0 = 0. */ |
| 1303 |
tree decl = TREE_OPERAND (*tp, 0), value; |
| 1304 |
tree *n; |
| 1305 |
|
| 1306 |
n = id->decl_map->get (decl); |
| 1307 |
if (n) |
| 1308 |
{ |
| 1309 |
value = *n; |
| 1310 |
STRIP_TYPE_NOPS (value); |
| 1311 |
if (TREE_CONSTANT (value) || TREE_READONLY (value)) |
| 1312 |
{ |
| 1313 |
*tp = build_empty_stmt (EXPR_LOCATION (*tp)); |
| 1314 |
return copy_tree_body_r (tp, walk_subtrees, data); |
| 1315 |
} |
| 1316 |
} |
| 1317 |
} |
| 1318 |
else if (INDIRECT_REF_P (*tp)) |
| 1319 |
{ |
| 1320 |
/* Get rid of *& from inline substitutions that can happen when a |
| 1321 |
pointer argument is an ADDR_EXPR. */ |
| 1322 |
tree decl = TREE_OPERAND (*tp, 0); |
| 1323 |
tree *n = id->decl_map->get (decl); |
| 1324 |
if (n) |
| 1325 |
{ |
| 1326 |
/* If we happen to get an ADDR_EXPR in n->value, strip |
| 1327 |
it manually here as we'll eventually get ADDR_EXPRs |
| 1328 |
which lie about their types pointed to. In this case |
| 1329 |
build_fold_indirect_ref wouldn't strip the INDIRECT_REF, |
| 1330 |
but we absolutely rely on that. As fold_indirect_ref |
| 1331 |
does other useful transformations, try that first, though. */ |
| 1332 |
tree type = TREE_TYPE (*tp); |
| 1333 |
tree ptr = id->do_not_unshare ? *n : unshare_expr (*n); |
| 1334 |
tree old = *tp; |
| 1335 |
*tp = id->do_not_fold ? NULL : gimple_fold_indirect_ref (ptr); |
| 1336 |
if (! *tp) |
| 1337 |
{ |
| 1338 |
type = remap_type (type, id); |
| 1339 |
if (TREE_CODE (ptr) == ADDR_EXPR && !id->do_not_fold) |
| 1340 |
{ |
| 1341 |
*tp |
| 1342 |
= fold_indirect_ref_1 (EXPR_LOCATION (ptr), type, ptr); |
| 1343 |
/* ??? We should either assert here or build |
| 1344 |
a VIEW_CONVERT_EXPR instead of blindly leaking |
| 1345 |
incompatible types to our IL. */ |
| 1346 |
if (! *tp) |
| 1347 |
*tp = TREE_OPERAND (ptr, 0); |
| 1348 |
} |
| 1349 |
else |
| 1350 |
{ |
| 1351 |
*tp = build1 (INDIRECT_REF, type, ptr); |
| 1352 |
TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); |
| 1353 |
TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old); |
| 1354 |
TREE_READONLY (*tp) = TREE_READONLY (old); |
| 1355 |
/* We cannot propagate the TREE_THIS_NOTRAP flag if we |
| 1356 |
have remapped a parameter as the property might be |
| 1357 |
valid only for the parameter itself. */ |
| 1358 |
if (TREE_THIS_NOTRAP (old) |
| 1359 |
&& (!is_parm (TREE_OPERAND (old, 0)) |
| 1360 |
|| (!id->transform_parameter && is_parm (ptr)))) |
| 1361 |
TREE_THIS_NOTRAP (*tp) = 1; |
| 1362 |
} |
| 1363 |
} |
| 1364 |
*walk_subtrees = 0; |
| 1365 |
return NULL; |
| 1366 |
} |
| 1367 |
} |
| 1368 |
else if (TREE_CODE (*tp) == MEM_REF && !id->do_not_fold) |
| 1369 |
{ |
| 1370 |
/* We need to re-canonicalize MEM_REFs from inline substitutions |
| 1371 |
that can happen when a pointer argument is an ADDR_EXPR. |
| 1372 |
Recurse here manually to allow that. */ |
| 1373 |
tree ptr = TREE_OPERAND (*tp, 0); |
| 1374 |
tree type = remap_type (TREE_TYPE (*tp), id); |
| 1375 |
tree old = *tp; |
| 1376 |
walk_tree (&ptr, copy_tree_body_r, data, NULL); |
| 1377 |
*tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1)); |
| 1378 |
TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); |
| 1379 |
TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old); |
| 1380 |
copy_warning (*tp, old); |
| 1381 |
if (MR_DEPENDENCE_CLIQUE (old) != 0) |
| 1382 |
{ |
| 1383 |
MR_DEPENDENCE_CLIQUE (*tp) |
| 1384 |
= remap_dependence_clique (id, MR_DEPENDENCE_CLIQUE (old)); |
| 1385 |
MR_DEPENDENCE_BASE (*tp) = MR_DEPENDENCE_BASE (old); |
| 1386 |
} |
| 1387 |
/* We cannot propagate the TREE_THIS_NOTRAP flag if we have |
| 1388 |
remapped a parameter as the property might be valid only |
| 1389 |
for the parameter itself. */ |
| 1390 |
if (TREE_THIS_NOTRAP (old) |
| 1391 |
&& (!is_parm (TREE_OPERAND (old, 0)) |
| 1392 |
|| (!id->transform_parameter && is_parm (ptr)))) |
| 1393 |
TREE_THIS_NOTRAP (*tp) = 1; |
| 1394 |
REF_REVERSE_STORAGE_ORDER (*tp) = REF_REVERSE_STORAGE_ORDER (old); |
| 1395 |
*walk_subtrees = 0; |
| 1396 |
return NULL; |
| 1397 |
} |
| 1398 |
|
| 1399 |
/* Here is the "usual case". Copy this tree node, and then |
| 1400 |
tweak some special cases. */ |
| 1401 |
copy_tree_r (tp, walk_subtrees, NULL); |
| 1402 |
|
| 1403 |
/* If EXPR has block defined, map it to newly constructed block. |
| 1404 |
When inlining we want EXPRs without block appear in the block |
| 1405 |
of function call if we are not remapping a type. */ |
| 1406 |
if (EXPR_P (*tp)) |
| 1407 |
{ |
| 1408 |
new_block = id->remapping_type_depth == 0 ? id->block : NULL; |
| 1409 |
if (TREE_BLOCK (*tp)) |
| 1410 |
{ |
| 1411 |
tree *n; |
| 1412 |
n = id->decl_map->get (TREE_BLOCK (*tp)); |
| 1413 |
if (n) |
| 1414 |
new_block = *n; |
| 1415 |
} |
| 1416 |
TREE_SET_BLOCK (*tp, new_block); |
| 1417 |
} |
| 1418 |
|
| 1419 |
if (TREE_CODE (*tp) != OMP_CLAUSE) |
| 1420 |
TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id); |
| 1421 |
|
| 1422 |
/* The copied TARGET_EXPR has never been expanded, even if the |
| 1423 |
original node was expanded already. */ |
| 1424 |
if (TREE_CODE (*tp) == TARGET_EXPR && TREE_OPERAND (*tp, 3)) |
| 1425 |
{ |
| 1426 |
TREE_OPERAND (*tp, 1) = TREE_OPERAND (*tp, 3); |
| 1427 |
TREE_OPERAND (*tp, 3) = NULL_TREE; |
| 1428 |
} |
| 1429 |
|
| 1430 |
/* Variable substitution need not be simple. In particular, the |
| 1431 |
INDIRECT_REF substitution above. Make sure that TREE_CONSTANT |
| 1432 |
and friends are up-to-date. */ |
| 1433 |
else if (TREE_CODE (*tp) == ADDR_EXPR) |
| 1434 |
{ |
| 1435 |
int invariant = is_gimple_min_invariant (*tp); |
| 1436 |
walk_tree (&TREE_OPERAND (*tp, 0), copy_tree_body_r, id, NULL); |
| 1437 |
|
| 1438 |
/* Handle the case where we substituted an INDIRECT_REF |
| 1439 |
into the operand of the ADDR_EXPR. */ |
| 1440 |
if (INDIRECT_REF_P (TREE_OPERAND (*tp, 0)) |
| 1441 |
&& !id->do_not_fold) |
| 1442 |
{ |
| 1443 |
tree t = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0); |
| 1444 |
if (TREE_TYPE (t) != TREE_TYPE (*tp)) |
| 1445 |
t = fold_convert (remap_type (TREE_TYPE (*tp), id), t); |
| 1446 |
*tp = t; |
| 1447 |
} |
| 1448 |
else |
| 1449 |
recompute_tree_invariant_for_addr_expr (*tp); |
| 1450 |
|
| 1451 |
/* If this used to be invariant, but is not any longer, |
| 1452 |
then regimplification is probably needed. */ |
| 1453 |
if (invariant && !is_gimple_min_invariant (*tp)) |
| 1454 |
id->regimplify = true; |
| 1455 |
|
| 1456 |
*walk_subtrees = 0; |
| 1457 |
} |
| 1458 |
else if (TREE_CODE (*tp) == OMP_CLAUSE |
| 1459 |
&& (OMP_CLAUSE_CODE (*tp) == OMP_CLAUSE_AFFINITY |
| 1460 |
|| OMP_CLAUSE_CODE (*tp) == OMP_CLAUSE_DEPEND)) |
| 1461 |
{ |
| 1462 |
tree t = OMP_CLAUSE_DECL (*tp); |
| 1463 |
if (t |
| 1464 |
&& TREE_CODE (t) == TREE_LIST |
| 1465 |
&& TREE_PURPOSE (t) |
| 1466 |
&& TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) |
| 1467 |
{ |
| 1468 |
*walk_subtrees = 0; |
| 1469 |
OMP_CLAUSE_DECL (*tp) = copy_node (t); |
| 1470 |
t = OMP_CLAUSE_DECL (*tp); |
| 1471 |
TREE_PURPOSE (t) = copy_node (TREE_PURPOSE (t)); |
| 1472 |
for (int i = 0; i <= 4; i++) |
| 1473 |
walk_tree (&TREE_VEC_ELT (TREE_PURPOSE (t), i), |
| 1474 |
copy_tree_body_r, id, NULL); |
| 1475 |
if (TREE_VEC_ELT (TREE_PURPOSE (t), 5)) |
| 1476 |
remap_block (&TREE_VEC_ELT (TREE_PURPOSE (t), 5), id); |
| 1477 |
walk_tree (&TREE_VALUE (t), copy_tree_body_r, id, NULL); |
| 1478 |
} |
| 1479 |
} |
| 1480 |
} |
| 1481 |
|
| 1482 |
/* Keep iterating. */ |
| 1483 |
return NULL_TREE; |
| 1484 |
} |
| 1485 |
|
| 1486 |
/* Helper for remap_gimple_stmt. Given an EH region number for the |
| 1487 |
source function, map that to the duplicate EH region number in |
| 1488 |
the destination function. */ |
| 1489 |
|
| 1490 |
static int |
| 1491 |
remap_eh_region_nr (int old_nr, copy_body_data *id) |
| 1492 |
{ |
| 1493 |
eh_region old_r, new_r; |
| 1494 |
|
| 1495 |
old_r = get_eh_region_from_number_fn (id->src_cfun, old_nr); |
| 1496 |
new_r = static_cast<eh_region> (*id->eh_map->get (old_r)); |
| 1497 |
|
| 1498 |
return new_r->index; |
| 1499 |
} |
| 1500 |
|
| 1501 |
/* Similar, but operate on INTEGER_CSTs. */ |
| 1502 |
|
| 1503 |
static tree |
| 1504 |
remap_eh_region_tree_nr (tree old_t_nr, copy_body_data *id) |
| 1505 |
{ |
| 1506 |
int old_nr, new_nr; |
| 1507 |
|
| 1508 |
old_nr = tree_to_shwi (old_t_nr); |
| 1509 |
new_nr = remap_eh_region_nr (old_nr, id); |
| 1510 |
|
| 1511 |
return build_int_cst (integer_type_node, new_nr); |
| 1512 |
} |
| 1513 |
|
| 1514 |
/* Helper for copy_bb. Remap statement STMT using the inlining |
| 1515 |
information in ID. Return the new statement copy. */ |
| 1516 |
|
| 1517 |
static gimple_seq |
| 1518 |
remap_gimple_stmt (gimple *stmt, copy_body_data *id) |
| 1519 |
{ |
| 1520 |
gimple *copy = NULL; |
| 1521 |
struct walk_stmt_info wi; |
| 1522 |
bool skip_first = false; |
| 1523 |
gimple_seq stmts = NULL; |
| 1524 |
|
| 1525 |
if (is_gimple_debug (stmt) |
| 1526 |
&& (gimple_debug_nonbind_marker_p (stmt) |
| 1527 |
? !DECL_STRUCT_FUNCTION (id->dst_fn)->debug_nonbind_markers |
| 1528 |
: !opt_for_fn (id->dst_fn, flag_var_tracking_assignments))) |
| 1529 |
return NULL; |
| 1530 |
|
| 1531 |
if (!is_gimple_debug (stmt) |
| 1532 |
&& id->param_body_adjs |
| 1533 |
&& id->param_body_adjs->m_dead_stmts.contains (stmt)) |
| 1534 |
{ |
| 1535 |
tree *dval = id->param_body_adjs->m_dead_stmt_debug_equiv.get (stmt); |
| 1536 |
if (!dval) |
| 1537 |
return NULL; |
| 1538 |
|
| 1539 |
gcc_assert (is_gimple_assign (stmt)); |
| 1540 |
tree lhs = gimple_assign_lhs (stmt); |
| 1541 |
tree *dvar = id->param_body_adjs->m_dead_ssa_debug_equiv.get (lhs); |
| 1542 |
gdebug *bind = gimple_build_debug_bind (*dvar, *dval, stmt); |
| 1543 |
if (id->reset_location) |
| 1544 |
gimple_set_location (bind, input_location); |
| 1545 |
id->debug_stmts.safe_push (bind); |
| 1546 |
gimple_seq_add_stmt_without_update (&stmts, bind); |
| 1547 |
return stmts; |
| 1548 |
} |
| 1549 |
|
| 1550 |
/* Begin by recognizing trees that we'll completely rewrite for the |
| 1551 |
inlining context. Our output for these trees is completely |
| 1552 |
different from our input (e.g. RETURN_EXPR is deleted and morphs |
| 1553 |
into an edge). Further down, we'll handle trees that get |
| 1554 |
duplicated and/or tweaked. */ |
| 1555 |
|
| 1556 |
/* When requested, GIMPLE_RETURN should be transformed to just the |
| 1557 |
contained GIMPLE_ASSIGN. The branch semantics of the return will |
| 1558 |
be handled elsewhere by manipulating the CFG rather than the |
| 1559 |
statement. */ |
| 1560 |
if (gimple_code (stmt) == GIMPLE_RETURN && id->transform_return_to_modify) |
| 1561 |
{ |
| 1562 |
tree retval = gimple_return_retval (as_a <greturn *> (stmt)); |
| 1563 |
|
| 1564 |
/* If we're returning something, just turn that into an |
| 1565 |
assignment to the equivalent of the original RESULT_DECL. |
| 1566 |
If RETVAL is just the result decl, the result decl has |
| 1567 |
already been set (e.g. a recent "foo (&result_decl, ...)"); |
| 1568 |
just toss the entire GIMPLE_RETURN. Likewise for when the |
| 1569 |
call doesn't want the return value. */ |
| 1570 |
if (retval |
| 1571 |
&& (TREE_CODE (retval) != RESULT_DECL |
| 1572 |
&& (!id->call_stmt |
| 1573 |
|| gimple_call_lhs (id->call_stmt) != NULL_TREE) |
| 1574 |
&& (TREE_CODE (retval) != SSA_NAME |
| 1575 |
|| ! SSA_NAME_VAR (retval) |
| 1576 |
|| TREE_CODE (SSA_NAME_VAR (retval)) != RESULT_DECL))) |
| 1577 |
{ |
| 1578 |
copy = gimple_build_assign (id->do_not_unshare |
| 1579 |
? id->retvar : unshare_expr (id->retvar), |
| 1580 |
retval); |
| 1581 |
/* id->retvar is already substituted. Skip it on later remapping. */ |
| 1582 |
skip_first = true; |
| 1583 |
} |
| 1584 |
else |
| 1585 |
return NULL; |
| 1586 |
} |
| 1587 |
else if (gimple_has_substatements (stmt)) |
| 1588 |
{ |
| 1589 |
gimple_seq s1, s2; |
| 1590 |
|
| 1591 |
/* When cloning bodies from the C++ front end, we will be handed bodies |
| 1592 |
in High GIMPLE form. Handle here all the High GIMPLE statements that |
| 1593 |
have embedded statements. */ |
| 1594 |
switch (gimple_code (stmt)) |
| 1595 |
{ |
| 1596 |
case GIMPLE_BIND: |
| 1597 |
copy = copy_gimple_bind (as_a <gbind *> (stmt), id); |
| 1598 |
break; |
| 1599 |
|
| 1600 |
case GIMPLE_CATCH: |
| 1601 |
{ |
| 1602 |
gcatch *catch_stmt = as_a <gcatch *> (stmt); |
| 1603 |
s1 = remap_gimple_seq (gimple_catch_handler (catch_stmt), id); |
| 1604 |
copy = gimple_build_catch (gimple_catch_types (catch_stmt), s1); |
| 1605 |
} |
| 1606 |
break; |
| 1607 |
|
| 1608 |
case GIMPLE_EH_FILTER: |
| 1609 |
s1 = remap_gimple_seq (gimple_eh_filter_failure (stmt), id); |
| 1610 |
copy = gimple_build_eh_filter (gimple_eh_filter_types (stmt), s1); |
| 1611 |
break; |
| 1612 |
|
| 1613 |
case GIMPLE_TRY: |
| 1614 |
s1 = remap_gimple_seq (gimple_try_eval (stmt), id); |
| 1615 |
s2 = remap_gimple_seq (gimple_try_cleanup (stmt), id); |
| 1616 |
copy = gimple_build_try (s1, s2, gimple_try_kind (stmt)); |
| 1617 |
break; |
| 1618 |
|
| 1619 |
case GIMPLE_WITH_CLEANUP_EXPR: |
| 1620 |
s1 = remap_gimple_seq (gimple_wce_cleanup (stmt), id); |
| 1621 |
copy = gimple_build_wce (s1); |
| 1622 |
break; |
| 1623 |
|
| 1624 |
case GIMPLE_OMP_PARALLEL: |
| 1625 |
{ |
| 1626 |
gomp_parallel *omp_par_stmt = as_a <gomp_parallel *> (stmt); |
| 1627 |
s1 = remap_gimple_seq (gimple_omp_body (omp_par_stmt), id); |
| 1628 |
copy = gimple_build_omp_parallel |
| 1629 |
(s1, |
| 1630 |
gimple_omp_parallel_clauses (omp_par_stmt), |
| 1631 |
gimple_omp_parallel_child_fn (omp_par_stmt), |
| 1632 |
gimple_omp_parallel_data_arg (omp_par_stmt)); |
| 1633 |
} |
| 1634 |
break; |
| 1635 |
|
| 1636 |
case GIMPLE_OMP_TASK: |
| 1637 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1638 |
copy = gimple_build_omp_task |
| 1639 |
(s1, |
| 1640 |
gimple_omp_task_clauses (stmt), |
| 1641 |
gimple_omp_task_child_fn (stmt), |
| 1642 |
gimple_omp_task_data_arg (stmt), |
| 1643 |
gimple_omp_task_copy_fn (stmt), |
| 1644 |
gimple_omp_task_arg_size (stmt), |
| 1645 |
gimple_omp_task_arg_align (stmt)); |
| 1646 |
break; |
| 1647 |
|
| 1648 |
case GIMPLE_OMP_FOR: |
| 1649 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1650 |
s2 = remap_gimple_seq (gimple_omp_for_pre_body (stmt), id); |
| 1651 |
copy = gimple_build_omp_for (s1, gimple_omp_for_kind (stmt), |
| 1652 |
gimple_omp_for_clauses (stmt), |
| 1653 |
gimple_omp_for_collapse (stmt), s2); |
| 1654 |
{ |
| 1655 |
size_t i; |
| 1656 |
for (i = 0; i < gimple_omp_for_collapse (stmt); i++) |
| 1657 |
{ |
| 1658 |
gimple_omp_for_set_index (copy, i, |
| 1659 |
gimple_omp_for_index (stmt, i)); |
| 1660 |
gimple_omp_for_set_initial (copy, i, |
| 1661 |
gimple_omp_for_initial (stmt, i)); |
| 1662 |
gimple_omp_for_set_final (copy, i, |
| 1663 |
gimple_omp_for_final (stmt, i)); |
| 1664 |
gimple_omp_for_set_incr (copy, i, |
| 1665 |
gimple_omp_for_incr (stmt, i)); |
| 1666 |
gimple_omp_for_set_cond (copy, i, |
| 1667 |
gimple_omp_for_cond (stmt, i)); |
| 1668 |
} |
| 1669 |
} |
| 1670 |
break; |
| 1671 |
|
| 1672 |
case GIMPLE_OMP_MASTER: |
| 1673 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1674 |
copy = gimple_build_omp_master (s1); |
| 1675 |
break; |
| 1676 |
|
| 1677 |
case GIMPLE_OMP_MASKED: |
| 1678 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1679 |
copy = gimple_build_omp_masked |
| 1680 |
(s1, gimple_omp_masked_clauses (stmt)); |
| 1681 |
break; |
| 1682 |
|
| 1683 |
case GIMPLE_OMP_SCOPE: |
| 1684 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1685 |
copy = gimple_build_omp_scope |
| 1686 |
(s1, gimple_omp_scope_clauses (stmt)); |
| 1687 |
break; |
| 1688 |
|
| 1689 |
case GIMPLE_OMP_DISPATCH: |
| 1690 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1691 |
copy = gimple_build_omp_dispatch (s1, |
| 1692 |
gimple_omp_dispatch_clauses (stmt)); |
| 1693 |
break; |
| 1694 |
|
| 1695 |
case GIMPLE_OMP_TASKGROUP: |
| 1696 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1697 |
copy = gimple_build_omp_taskgroup |
| 1698 |
(s1, gimple_omp_taskgroup_clauses (stmt)); |
| 1699 |
break; |
| 1700 |
|
| 1701 |
case GIMPLE_OMP_ORDERED: |
| 1702 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1703 |
copy = gimple_build_omp_ordered |
| 1704 |
(s1, |
| 1705 |
gimple_omp_ordered_clauses (as_a <gomp_ordered *> (stmt))); |
| 1706 |
break; |
| 1707 |
|
| 1708 |
case GIMPLE_OMP_SCAN: |
| 1709 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1710 |
copy = gimple_build_omp_scan |
| 1711 |
(s1, gimple_omp_scan_clauses (as_a <gomp_scan *> (stmt))); |
| 1712 |
break; |
| 1713 |
|
| 1714 |
case GIMPLE_OMP_SECTION: |
| 1715 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1716 |
copy = gimple_build_omp_section (s1); |
| 1717 |
break; |
| 1718 |
|
| 1719 |
case GIMPLE_OMP_SECTIONS: |
| 1720 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1721 |
copy = gimple_build_omp_sections |
| 1722 |
(s1, gimple_omp_sections_clauses (stmt)); |
| 1723 |
break; |
| 1724 |
|
| 1725 |
case GIMPLE_OMP_STRUCTURED_BLOCK: |
| 1726 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1727 |
copy = gimple_build_omp_structured_block (s1); |
| 1728 |
break; |
| 1729 |
|
| 1730 |
case GIMPLE_OMP_SINGLE: |
| 1731 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1732 |
copy = gimple_build_omp_single |
| 1733 |
(s1, gimple_omp_single_clauses (stmt)); |
| 1734 |
break; |
| 1735 |
|
| 1736 |
case GIMPLE_OMP_TARGET: |
| 1737 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1738 |
copy = gimple_build_omp_target |
| 1739 |
(s1, gimple_omp_target_kind (stmt), |
| 1740 |
gimple_omp_target_clauses (stmt)); |
| 1741 |
break; |
| 1742 |
|
| 1743 |
case GIMPLE_OMP_TEAMS: |
| 1744 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1745 |
copy = gimple_build_omp_teams |
| 1746 |
(s1, gimple_omp_teams_clauses (stmt)); |
| 1747 |
break; |
| 1748 |
|
| 1749 |
case GIMPLE_OMP_CRITICAL: |
| 1750 |
s1 = remap_gimple_seq (gimple_omp_body (stmt), id); |
| 1751 |
copy = gimple_build_omp_critical (s1, |
| 1752 |
gimple_omp_critical_name |
| 1753 |
(as_a <gomp_critical *> (stmt)), |
| 1754 |
gimple_omp_critical_clauses |
| 1755 |
(as_a <gomp_critical *> (stmt))); |
| 1756 |
break; |
| 1757 |
|
| 1758 |
case GIMPLE_ASSUME: |
| 1759 |
s1 = remap_gimple_seq (gimple_assume_body (stmt), id); |
| 1760 |
copy = gimple_build_assume (gimple_assume_guard (stmt), s1); |
| 1761 |
break; |
| 1762 |
|
| 1763 |
case GIMPLE_TRANSACTION: |
| 1764 |
{ |
| 1765 |
gtransaction *old_trans_stmt = as_a <gtransaction *> (stmt); |
| 1766 |
gtransaction *new_trans_stmt; |
| 1767 |
s1 = remap_gimple_seq (gimple_transaction_body (old_trans_stmt), |
| 1768 |
id); |
| 1769 |
copy = new_trans_stmt = gimple_build_transaction (s1); |
| 1770 |
gimple_transaction_set_subcode (new_trans_stmt, |
| 1771 |
gimple_transaction_subcode (old_trans_stmt)); |
| 1772 |
gimple_transaction_set_label_norm (new_trans_stmt, |
| 1773 |
gimple_transaction_label_norm (old_trans_stmt)); |
| 1774 |
gimple_transaction_set_label_uninst (new_trans_stmt, |
| 1775 |
gimple_transaction_label_uninst (old_trans_stmt)); |
| 1776 |
gimple_transaction_set_label_over (new_trans_stmt, |
| 1777 |
gimple_transaction_label_over (old_trans_stmt)); |
| 1778 |
} |
| 1779 |
break; |
| 1780 |
|
| 1781 |
default: |
| 1782 |
gcc_unreachable (); |
| 1783 |
} |
| 1784 |
} |
| 1785 |
else |
| 1786 |
{ |
| 1787 |
if (gimple_assign_single_p (stmt) |
| 1788 |
&& gimple_assign_lhs (stmt) == gimple_assign_rhs1 (stmt) |
| 1789 |
&& auto_var_in_fn_p (gimple_assign_lhs (stmt), id->src_fn)) |
| 1790 |
{ |
| 1791 |
/* Here we handle statements that are not completely rewritten. |
| 1792 |
First we detect some inlining-induced bogosities for |
| 1793 |
discarding. */ |
| 1794 |
|
| 1795 |
/* Some assignments VAR = VAR; don't generate any rtl code |
| 1796 |
and thus don't count as variable modification. Avoid |
| 1797 |
keeping bogosities like 0 = 0. */ |
| 1798 |
tree decl = gimple_assign_lhs (stmt), value; |
| 1799 |
tree *n; |
| 1800 |
|
| 1801 |
n = id->decl_map->get (decl); |
| 1802 |
if (n) |
| 1803 |
{ |
| 1804 |
value = *n; |
| 1805 |
STRIP_TYPE_NOPS (value); |
| 1806 |
if (TREE_CONSTANT (value) || TREE_READONLY (value)) |
| 1807 |
return NULL; |
| 1808 |
} |
| 1809 |
} |
| 1810 |
|
| 1811 |
/* For *ptr_N ={v} {CLOBBER}, if ptr_N is SSA_NAME defined |
| 1812 |
in a block that we aren't copying during tree_function_versioning, |
| 1813 |
just drop the clobber stmt. */ |
| 1814 |
if (id->blocks_to_copy && gimple_clobber_p (stmt)) |
| 1815 |
{ |
| 1816 |
tree lhs = gimple_assign_lhs (stmt); |
| 1817 |
if (TREE_CODE (lhs) == MEM_REF |
| 1818 |
&& TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME) |
| 1819 |
{ |
| 1820 |
gimple *def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (lhs, 0)); |
| 1821 |
if (gimple_bb (def_stmt) |
| 1822 |
&& !bitmap_bit_p (id->blocks_to_copy, |
| 1823 |
gimple_bb (def_stmt)->index)) |
| 1824 |
return NULL; |
| 1825 |
} |
| 1826 |
} |
| 1827 |
|
| 1828 |
/* We do not allow CLOBBERs of handled components. In case |
| 1829 |
returned value is stored via such handled component, remove |
| 1830 |
the clobber so stmt verifier is happy. */ |
| 1831 |
if (gimple_clobber_p (stmt) |
| 1832 |
&& TREE_CODE (gimple_assign_lhs (stmt)) == RESULT_DECL) |
| 1833 |
{ |
| 1834 |
tree remapped = remap_decl (gimple_assign_lhs (stmt), id); |
| 1835 |
if (!DECL_P (remapped) |
| 1836 |
&& TREE_CODE (remapped) != MEM_REF) |
| 1837 |
return NULL; |
| 1838 |
} |
| 1839 |
|
| 1840 |
if (gimple_debug_bind_p (stmt)) |
| 1841 |
{ |
| 1842 |
tree var = gimple_debug_bind_get_var (stmt); |
| 1843 |
tree value = gimple_debug_bind_get_value (stmt); |
| 1844 |
if (id->param_body_adjs |
| 1845 |
&& id->param_body_adjs->m_dead_stmts.contains (stmt)) |
| 1846 |
{ |
| 1847 |
value = unshare_expr_without_location (value); |
| 1848 |
id->param_body_adjs->remap_with_debug_expressions (&value); |
| 1849 |
} |
| 1850 |
|
| 1851 |
gdebug *copy = gimple_build_debug_bind (var, value, stmt); |
| 1852 |
if (id->reset_location) |
| 1853 |
gimple_set_location (copy, input_location); |
| 1854 |
id->debug_stmts.safe_push (copy); |
| 1855 |
gimple_seq_add_stmt_without_update (&stmts, copy); |
| 1856 |
return stmts; |
| 1857 |
} |
| 1858 |
if (gimple_debug_source_bind_p (stmt)) |
| 1859 |
{ |
| 1860 |
gdebug *copy = gimple_build_debug_source_bind |
| 1861 |
(gimple_debug_source_bind_get_var (stmt), |
| 1862 |
gimple_debug_source_bind_get_value (stmt), |
| 1863 |
stmt); |
| 1864 |
if (id->reset_location) |
| 1865 |
gimple_set_location (copy, input_location); |
| 1866 |
id->debug_stmts.safe_push (copy); |
| 1867 |
gimple_seq_add_stmt_without_update (&stmts, copy); |
| 1868 |
return stmts; |
| 1869 |
} |
| 1870 |
if (gimple_debug_nonbind_marker_p (stmt)) |
| 1871 |
{ |
| 1872 |
/* If the inlined function has too many debug markers, |
| 1873 |
don't copy them. */ |
| 1874 |
if (id->src_cfun->debug_marker_count |
| 1875 |
> param_max_debug_marker_count |
| 1876 |
|| id->reset_location) |
| 1877 |
return stmts; |
| 1878 |
|
| 1879 |
gdebug *copy = as_a <gdebug *> (gimple_copy (stmt)); |
| 1880 |
id->debug_stmts.safe_push (copy); |
| 1881 |
gimple_seq_add_stmt_without_update (&stmts, copy); |
| 1882 |
return stmts; |
| 1883 |
} |
| 1884 |
|
| 1885 |
/* Create a new deep copy of the statement. */ |
| 1886 |
copy = gimple_copy (stmt); |
| 1887 |
|
| 1888 |
/* Clear flags that need revisiting. */ |
| 1889 |
if (gcall *call_stmt = dyn_cast <gcall *> (copy)) |
| 1890 |
{ |
| 1891 |
if (gimple_call_tail_p (call_stmt)) |
| 1892 |
gimple_call_set_tail (call_stmt, false); |
| 1893 |
if (gimple_call_from_thunk_p (call_stmt)) |
| 1894 |
gimple_call_set_from_thunk (call_stmt, false); |
| 1895 |
/* Silently clear musttail flag when inlining a function |
| 1896 |
with must tail call from a non-musttail call. The inlining |
| 1897 |
removes one frame so acts like musttail's intent, and we |
| 1898 |
can be inlining a function with musttail calls in the middle |
| 1899 |
of caller where musttail will always error. */ |
| 1900 |
if (gimple_call_must_tail_p (call_stmt) |
| 1901 |
&& id->call_stmt |
| 1902 |
&& !gimple_call_must_tail_p (id->call_stmt)) |
| 1903 |
gimple_call_set_must_tail (call_stmt, false); |
| 1904 |
if (gimple_call_internal_p (call_stmt)) |
| 1905 |
switch (gimple_call_internal_fn (call_stmt)) |
| 1906 |
{ |
| 1907 |
case IFN_GOMP_SIMD_LANE: |
| 1908 |
case IFN_GOMP_SIMD_VF: |
| 1909 |
case IFN_GOMP_SIMD_LAST_LANE: |
| 1910 |
case IFN_GOMP_SIMD_ORDERED_START: |
| 1911 |
case IFN_GOMP_SIMD_ORDERED_END: |
| 1912 |
DECL_STRUCT_FUNCTION (id->dst_fn)->has_simduid_loops = true; |
| 1913 |
break; |
| 1914 |
default: |
| 1915 |
break; |
| 1916 |
} |
| 1917 |
} |
| 1918 |
|
| 1919 |
/* Remap the region numbers for __builtin_eh_{pointer,filter}, |
| 1920 |
RESX and EH_DISPATCH. */ |
| 1921 |
if (id->eh_map) |
| 1922 |
switch (gimple_code (copy)) |
| 1923 |
{ |
| 1924 |
case GIMPLE_CALL: |
| 1925 |
{ |
| 1926 |
tree r, fndecl = gimple_call_fndecl (copy); |
| 1927 |
if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)) |
| 1928 |
switch (DECL_FUNCTION_CODE (fndecl)) |
| 1929 |
{ |
| 1930 |
case BUILT_IN_EH_COPY_VALUES: |
| 1931 |
r = gimple_call_arg (copy, 1); |
| 1932 |
r = remap_eh_region_tree_nr (r, id); |
| 1933 |
gimple_call_set_arg (copy, 1, r); |
| 1934 |
/* FALLTHRU */ |
| 1935 |
|
| 1936 |
case BUILT_IN_EH_POINTER: |
| 1937 |
case BUILT_IN_EH_FILTER: |
| 1938 |
r = gimple_call_arg (copy, 0); |
| 1939 |
r = remap_eh_region_tree_nr (r, id); |
| 1940 |
gimple_call_set_arg (copy, 0, r); |
| 1941 |
break; |
| 1942 |
|
| 1943 |
default: |
| 1944 |
break; |
| 1945 |
} |
| 1946 |
|
| 1947 |
/* Reset alias info if we didn't apply measures to |
| 1948 |
keep it valid over inlining by setting DECL_PT_UID. */ |
| 1949 |
if (!id->src_cfun->gimple_df |
| 1950 |
|| !id->src_cfun->gimple_df->ipa_pta) |
| 1951 |
gimple_call_reset_alias_info (as_a <gcall *> (copy)); |
| 1952 |
} |
| 1953 |
break; |
| 1954 |
|
| 1955 |
case GIMPLE_RESX: |
| 1956 |
{ |
| 1957 |
gresx *resx_stmt = as_a <gresx *> (copy); |
| 1958 |
int r = gimple_resx_region (resx_stmt); |
| 1959 |
r = remap_eh_region_nr (r, id); |
| 1960 |
gimple_resx_set_region (resx_stmt, r); |
| 1961 |
} |
| 1962 |
break; |
| 1963 |
|
| 1964 |
case GIMPLE_EH_DISPATCH: |
| 1965 |
{ |
| 1966 |
geh_dispatch *eh_dispatch = as_a <geh_dispatch *> (copy); |
| 1967 |
int r = gimple_eh_dispatch_region (eh_dispatch); |
| 1968 |
r = remap_eh_region_nr (r, id); |
| 1969 |
gimple_eh_dispatch_set_region (eh_dispatch, r); |
| 1970 |
} |
| 1971 |
break; |
| 1972 |
|
| 1973 |
default: |
| 1974 |
break; |
| 1975 |
} |
| 1976 |
} |
| 1977 |
|
| 1978 |
/* If STMT has a block defined, map it to the newly constructed block. */ |
| 1979 |
if (tree block = gimple_block (copy)) |
| 1980 |
{ |
| 1981 |
tree *n; |
| 1982 |
n = id->decl_map->get (block); |
| 1983 |
gcc_assert (n); |
| 1984 |
gimple_set_block (copy, *n); |
| 1985 |
} |
| 1986 |
if (id->param_body_adjs) |
| 1987 |
{ |
| 1988 |
gimple_seq extra_stmts = NULL; |
| 1989 |
id->param_body_adjs->modify_gimple_stmt (©, &extra_stmts, stmt); |
| 1990 |
if (!gimple_seq_empty_p (extra_stmts)) |
| 1991 |
{ |
| 1992 |
memset (&wi, 0, sizeof (wi)); |
| 1993 |
wi.info = id; |
| 1994 |
for (gimple_stmt_iterator egsi = gsi_start (extra_stmts); |
| 1995 |
!gsi_end_p (egsi); |
| 1996 |
gsi_next (&egsi)) |
| 1997 |
walk_gimple_op (gsi_stmt (egsi), remap_gimple_op_r, &wi); |
| 1998 |
gimple_seq_add_seq_without_update (&stmts, extra_stmts); |
| 1999 |
} |
| 2000 |
} |
| 2001 |
|
| 2002 |
if (id->reset_location) |
| 2003 |
gimple_set_location (copy, input_location); |
| 2004 |
|
| 2005 |
/* Debug statements ought to be rebuilt and not copied. */ |
| 2006 |
gcc_checking_assert (!is_gimple_debug (copy)); |
| 2007 |
|
| 2008 |
/* Remap all the operands in COPY. */ |
| 2009 |
memset (&wi, 0, sizeof (wi)); |
| 2010 |
wi.info = id; |
| 2011 |
if (skip_first) |
| 2012 |
walk_tree (gimple_op_ptr (copy, 1), remap_gimple_op_r, &wi, NULL); |
| 2013 |
else |
| 2014 |
walk_gimple_op (copy, remap_gimple_op_r, &wi); |
| 2015 |
|
| 2016 |
/* Clear the copied virtual operands. We are not remapping them here |
| 2017 |
but are going to recreate them from scratch. */ |
| 2018 |
if (gimple_has_mem_ops (copy)) |
| 2019 |
{ |
| 2020 |
gimple_set_vdef (copy, NULL_TREE); |
| 2021 |
gimple_set_vuse (copy, NULL_TREE); |
| 2022 |
} |
| 2023 |
|
| 2024 |
if (cfun->can_throw_non_call_exceptions) |
| 2025 |
{ |
| 2026 |
/* When inlining a function which does not have non-call exceptions |
| 2027 |
enabled into a function that has (which only happens with |
| 2028 |
always-inline) we have to fixup stmts that cannot throw. */ |
| 2029 |
if (gcond *cond = dyn_cast <gcond *> (copy)) |
| 2030 |
if (gimple_could_trap_p (cond)) |
| 2031 |
{ |
| 2032 |
gassign *cmp |
| 2033 |
= gimple_build_assign (make_ssa_name (boolean_type_node), |
| 2034 |
gimple_cond_code (cond), |
| 2035 |
gimple_cond_lhs (cond), |
| 2036 |
gimple_cond_rhs (cond)); |
| 2037 |
gimple_seq_add_stmt_without_update (&stmts, cmp); |
| 2038 |
gimple_cond_set_code (cond, NE_EXPR); |
| 2039 |
gimple_cond_set_lhs (cond, gimple_assign_lhs (cmp)); |
| 2040 |
gimple_cond_set_rhs (cond, boolean_false_node); |
| 2041 |
} |
| 2042 |
} |
| 2043 |
|
| 2044 |
gimple_seq_add_stmt_without_update (&stmts, copy); |
| 2045 |
return stmts; |
| 2046 |
} |
| 2047 |
|
| 2048 |
|
| 2049 |
/* Copy basic block, scale profile accordingly. Edges will be taken care of |
| 2050 |
later */ |
| 2051 |
|
| 2052 |
static basic_block |
| 2053 |
copy_bb (copy_body_data *id, basic_block bb, |
| 2054 |
profile_count num, profile_count den) |
| 2055 |
{ |
| 2056 |
gimple_stmt_iterator gsi, copy_gsi, seq_gsi; |
| 2057 |
basic_block copy_basic_block; |
| 2058 |
tree decl; |
| 2059 |
basic_block prev; |
| 2060 |
|
| 2061 |
profile_count::adjust_for_ipa_scaling (&num, &den); |
| 2062 |
|
| 2063 |
/* Search for previous copied basic block. */ |
| 2064 |
prev = bb->prev_bb; |
| 2065 |
while (!prev->aux) |
| 2066 |
prev = prev->prev_bb; |
| 2067 |
|
| 2068 |
/* create_basic_block() will append every new block to |
| 2069 |
basic_block_info automatically. */ |
| 2070 |
copy_basic_block = create_basic_block (NULL, (basic_block) prev->aux); |
| 2071 |
copy_basic_block->count = bb->count.apply_scale (num, den); |
| 2072 |
|
| 2073 |
copy_gsi = gsi_start_bb (copy_basic_block); |
| 2074 |
|
| 2075 |
unsigned min_cond_uid = 0; |
| 2076 |
if (id->src_cfun->cond_uids) |
| 2077 |
{ |
| 2078 |
if (!cfun->cond_uids) |
| 2079 |
cfun->cond_uids = new hash_map <gcond*, unsigned> (); |
| 2080 |
|
| 2081 |
for (auto itr : *id->src_cfun->cond_uids) |
| 2082 |
if (itr.second >= min_cond_uid) |
| 2083 |
min_cond_uid = itr.second + 1; |
| 2084 |
} |
| 2085 |
|
| 2086 |
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
| 2087 |
{ |
| 2088 |
gimple_seq stmts; |
| 2089 |
gimple *stmt = gsi_stmt (gsi); |
| 2090 |
gimple *orig_stmt = stmt; |
| 2091 |
gimple_stmt_iterator stmts_gsi; |
| 2092 |
bool stmt_added = false; |
| 2093 |
|
| 2094 |
id->regimplify = false; |
| 2095 |
stmts = remap_gimple_stmt (stmt, id); |
| 2096 |
|
| 2097 |
if (gimple_seq_empty_p (stmts)) |
| 2098 |
continue; |
| 2099 |
|
| 2100 |
seq_gsi = copy_gsi; |
| 2101 |
|
| 2102 |
for (stmts_gsi = gsi_start (stmts); |
| 2103 |
!gsi_end_p (stmts_gsi); ) |
| 2104 |
{ |
| 2105 |
stmt = gsi_stmt (stmts_gsi); |
| 2106 |
|
| 2107 |
/* Advance iterator now before stmt is moved to seq_gsi. */ |
| 2108 |
gsi_next (&stmts_gsi); |
| 2109 |
|
| 2110 |
if (gimple_nop_p (stmt)) |
| 2111 |
continue; |
| 2112 |
|
| 2113 |
/* If -fcondition-coverage is used, register the inlined conditions |
| 2114 |
in the cond->expression mapping of the caller. The expression tag |
| 2115 |
is shifted conditions from the two bodies are not mixed. */ |
| 2116 |
if (id->src_cfun->cond_uids && is_a <gcond*> (stmt)) |
| 2117 |
{ |
| 2118 |
gcond *orig_cond = as_a <gcond*> (orig_stmt); |
| 2119 |
gcond *cond = as_a <gcond*> (stmt); |
| 2120 |
unsigned *v = id->src_cfun->cond_uids->get (orig_cond); |
| 2121 |
if (v) |
| 2122 |
cfun->cond_uids->put (cond, *v + min_cond_uid); |
| 2123 |
} |
| 2124 |
|
| 2125 |
gimple_duplicate_stmt_histograms (cfun, stmt, id->src_cfun, |
| 2126 |
orig_stmt); |
| 2127 |
|
| 2128 |
gsi_insert_after (&seq_gsi, stmt, GSI_NEW_STMT); |
| 2129 |
|
| 2130 |
if (id->regimplify) |
| 2131 |
gimple_regimplify_operands (stmt, &seq_gsi); |
| 2132 |
|
| 2133 |
stmt_added = true; |
| 2134 |
} |
| 2135 |
|
| 2136 |
if (!stmt_added) |
| 2137 |
continue; |
| 2138 |
|
| 2139 |
/* If copy_basic_block has been empty at the start of this iteration, |
| 2140 |
call gsi_start_bb again to get at the newly added statements. */ |
| 2141 |
if (gsi_end_p (copy_gsi)) |
| 2142 |
copy_gsi = gsi_start_bb (copy_basic_block); |
| 2143 |
else |
| 2144 |
gsi_next (©_gsi); |
| 2145 |
|
| 2146 |
/* Process the new statement. The call to gimple_regimplify_operands |
| 2147 |
possibly turned the statement into multiple statements, we |
| 2148 |
need to process all of them. */ |
| 2149 |
do |
| 2150 |
{ |
| 2151 |
tree fn; |
| 2152 |
gcall *call_stmt; |
| 2153 |
|
| 2154 |
stmt = gsi_stmt (copy_gsi); |
| 2155 |
call_stmt = dyn_cast <gcall *> (stmt); |
| 2156 |
if (call_stmt |
| 2157 |
&& gimple_call_va_arg_pack_p (call_stmt) |
| 2158 |
&& id->call_stmt |
| 2159 |
&& ! gimple_call_va_arg_pack_p (id->call_stmt)) |
| 2160 |
{ |
| 2161 |
/* __builtin_va_arg_pack () should be replaced by |
| 2162 |
all arguments corresponding to ... in the caller. */ |
| 2163 |
tree p; |
| 2164 |
gcall *new_call; |
| 2165 |
vec<tree> argarray; |
| 2166 |
size_t nargs_caller = gimple_call_num_args (id->call_stmt); |
| 2167 |
size_t nargs = nargs_caller; |
| 2168 |
|
| 2169 |
for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p)) |
| 2170 |
{ |
| 2171 |
/* Avoid crashing on invalid IL that doesn't have a |
| 2172 |
varargs function or that passes not enough arguments. */ |
| 2173 |
if (nargs == 0) |
| 2174 |
break; |
| 2175 |
nargs--; |
| 2176 |
} |
| 2177 |
|
| 2178 |
/* Create the new array of arguments. */ |
| 2179 |
size_t nargs_callee = gimple_call_num_args (call_stmt); |
| 2180 |
size_t n = nargs + nargs_callee; |
| 2181 |
argarray.create (n); |
| 2182 |
argarray.safe_grow_cleared (n, true); |
| 2183 |
|
| 2184 |
/* Copy all the arguments before '...' */ |
| 2185 |
if (nargs_callee) |
| 2186 |
memcpy (argarray.address (), |
| 2187 |
gimple_call_arg_ptr (call_stmt, 0), |
| 2188 |
nargs_callee * sizeof (tree)); |
| 2189 |
|
| 2190 |
/* Append the arguments passed in '...' */ |
| 2191 |
if (nargs) |
| 2192 |
memcpy (argarray.address () + nargs_callee, |
| 2193 |
gimple_call_arg_ptr (id->call_stmt, 0) |
| 2194 |
+ (nargs_caller - nargs), nargs * sizeof (tree)); |
| 2195 |
|
| 2196 |
new_call = gimple_build_call_vec (gimple_call_fn (call_stmt), |
| 2197 |
argarray); |
| 2198 |
|
| 2199 |
argarray.release (); |
| 2200 |
|
| 2201 |
/* Copy all GIMPLE_CALL flags, location and block, except |
| 2202 |
GF_CALL_VA_ARG_PACK. */ |
| 2203 |
gimple_call_copy_flags (new_call, call_stmt); |
| 2204 |
gimple_call_set_va_arg_pack (new_call, false); |
| 2205 |
gimple_call_set_fntype (new_call, gimple_call_fntype (call_stmt)); |
| 2206 |
/* location includes block. */ |
| 2207 |
gimple_set_location (new_call, gimple_location (stmt)); |
| 2208 |
gimple_call_set_lhs (new_call, gimple_call_lhs (call_stmt)); |
| 2209 |
|
| 2210 |
gsi_replace (©_gsi, new_call, false); |
| 2211 |
stmt = new_call; |
| 2212 |
} |
| 2213 |
else if (call_stmt |
| 2214 |
&& id->call_stmt |
| 2215 |
&& (decl = gimple_call_fndecl (stmt)) |
| 2216 |
&& fndecl_built_in_p (decl, BUILT_IN_VA_ARG_PACK_LEN)) |
| 2217 |
{ |
| 2218 |
/* __builtin_va_arg_pack_len () should be replaced by |
| 2219 |
the number of anonymous arguments. */ |
| 2220 |
size_t nargs = gimple_call_num_args (id->call_stmt); |
| 2221 |
tree count, p; |
| 2222 |
gimple *new_stmt; |
| 2223 |
|
| 2224 |
for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p)) |
| 2225 |
nargs--; |
| 2226 |
|
| 2227 |
if (!gimple_call_lhs (stmt)) |
| 2228 |
{ |
| 2229 |
/* Drop unused calls. */ |
| 2230 |
gsi_remove (©_gsi, false); |
| 2231 |
continue; |
| 2232 |
} |
| 2233 |
else if (!gimple_call_va_arg_pack_p (id->call_stmt)) |
| 2234 |
{ |
| 2235 |
count = build_int_cst (integer_type_node, nargs); |
| 2236 |
new_stmt = gimple_build_assign (gimple_call_lhs (stmt), count); |
| 2237 |
gsi_replace (©_gsi, new_stmt, false); |
| 2238 |
stmt = new_stmt; |
| 2239 |
} |
| 2240 |
else if (nargs != 0) |
| 2241 |
{ |
| 2242 |
tree newlhs = create_tmp_reg_or_ssa_name (integer_type_node); |
| 2243 |
count = build_int_cst (integer_type_node, nargs); |
| 2244 |
new_stmt = gimple_build_assign (gimple_call_lhs (stmt), |
| 2245 |
PLUS_EXPR, newlhs, count); |
| 2246 |
gimple_call_set_lhs (stmt, newlhs); |
| 2247 |
gsi_insert_after (©_gsi, new_stmt, GSI_NEW_STMT); |
| 2248 |
} |
| 2249 |
} |
| 2250 |
else if (call_stmt |
| 2251 |
&& id->call_stmt |
| 2252 |
&& gimple_call_internal_p (stmt)) |
| 2253 |
switch (gimple_call_internal_fn (stmt)) |
| 2254 |
{ |
| 2255 |
case IFN_TSAN_FUNC_EXIT: |
| 2256 |
/* Drop .TSAN_FUNC_EXIT () internal calls during inlining. */ |
| 2257 |
gsi_remove (©_gsi, false); |
| 2258 |
continue; |
| 2259 |
case IFN_ASAN_MARK: |
| 2260 |
/* Drop .ASAN_MARK internal calls during inlining into |
| 2261 |
no_sanitize functions. */ |
| 2262 |
if (!sanitize_flags_p (SANITIZE_ADDRESS, id->dst_fn) |
| 2263 |
&& !sanitize_flags_p (SANITIZE_HWADDRESS, id->dst_fn)) |
| 2264 |
{ |
| 2265 |
gsi_remove (©_gsi, false); |
| 2266 |
continue; |
| 2267 |
} |
| 2268 |
break; |
| 2269 |
default: |
| 2270 |
break; |
| 2271 |
} |
| 2272 |
|
| 2273 |
/* Statements produced by inlining can be unfolded, especially |
| 2274 |
when we constant propagated some operands. We can't fold |
| 2275 |
them right now for two reasons: |
| 2276 |
1) folding require SSA_NAME_DEF_STMTs to be correct |
| 2277 |
2) we can't change function calls to builtins. |
| 2278 |
So we just mark statement for later folding. We mark |
| 2279 |
all new statements, instead just statements that has changed |
| 2280 |
by some nontrivial substitution so even statements made |
| 2281 |
foldable indirectly are updated. If this turns out to be |
| 2282 |
expensive, copy_body can be told to watch for nontrivial |
| 2283 |
changes. */ |
| 2284 |
if (id->statements_to_fold) |
| 2285 |
id->statements_to_fold->add (stmt); |
| 2286 |
|
| 2287 |
/* We're duplicating a CALL_EXPR. Find any corresponding |
| 2288 |
callgraph edges and update or duplicate them. */ |
| 2289 |
if (gcall *call_stmt = dyn_cast <gcall *> (stmt)) |
| 2290 |
{ |
| 2291 |
struct cgraph_edge *edge; |
| 2292 |
|
| 2293 |
switch (id->transform_call_graph_edges) |
| 2294 |
{ |
| 2295 |
case CB_CGE_DUPLICATE: |
| 2296 |
edge = id->src_node->get_edge (orig_stmt); |
| 2297 |
if (edge) |
| 2298 |
{ |
| 2299 |
struct cgraph_edge *old_edge = edge; |
| 2300 |
|
| 2301 |
/* A speculative call is consist of multiple |
| 2302 |
edges - indirect edge and one or more direct edges |
| 2303 |
Duplicate the whole thing and distribute frequencies |
| 2304 |
accordingly. */ |
| 2305 |
if (edge->speculative) |
| 2306 |
{ |
| 2307 |
int n = 0; |
| 2308 |
profile_count direct_cnt |
| 2309 |
= profile_count::zero (); |
| 2310 |
|
| 2311 |
/* First figure out the distribution of counts |
| 2312 |
so we can re-scale BB profile accordingly. */ |
| 2313 |
for (cgraph_edge *e = old_edge; e; |
| 2314 |
e = e->next_speculative_call_target ()) |
| 2315 |
direct_cnt = direct_cnt + e->count; |
| 2316 |
|
| 2317 |
cgraph_edge *indirect |
| 2318 |
= old_edge->speculative_call_indirect_edge (); |
| 2319 |
profile_count indir_cnt = indirect->count; |
| 2320 |
|
| 2321 |
/* Next iterate all direct edges, clone it and its |
| 2322 |
corresponding reference and update profile. */ |
| 2323 |
for (cgraph_edge *e = old_edge; |
| 2324 |
e; |
| 2325 |
e = e->next_speculative_call_target ()) |
| 2326 |
{ |
| 2327 |
profile_count cnt = e->count; |
| 2328 |
|
| 2329 |
id->dst_node->clone_reference |
| 2330 |
(e->speculative_call_target_ref (), stmt); |
| 2331 |
edge = e->clone (id->dst_node, call_stmt, |
| 2332 |
gimple_uid (stmt), num, den, |
| 2333 |
true); |
| 2334 |
profile_probability prob |
| 2335 |
= cnt.probability_in (direct_cnt |
| 2336 |
+ indir_cnt); |
| 2337 |
edge->count |
| 2338 |
= copy_basic_block->count.apply_probability |
| 2339 |
(prob); |
| 2340 |
n++; |
| 2341 |
} |
| 2342 |
gcc_checking_assert |
| 2343 |
(indirect->num_speculative_call_targets_p () |
| 2344 |
== n); |
| 2345 |
|
| 2346 |
/* Duplicate the indirect edge after all direct edges |
| 2347 |
cloned. */ |
| 2348 |
indirect = indirect->clone (id->dst_node, call_stmt, |
| 2349 |
gimple_uid (stmt), |
| 2350 |
num, den, |
| 2351 |
true); |
| 2352 |
|
| 2353 |
profile_probability prob |
| 2354 |
= indir_cnt.probability_in (direct_cnt |
| 2355 |
+ indir_cnt); |
| 2356 |
indirect->count |
| 2357 |
= copy_basic_block->count.apply_probability (prob); |
| 2358 |
} |
| 2359 |
else |
| 2360 |
{ |
| 2361 |
edge = edge->clone (id->dst_node, call_stmt, |
| 2362 |
gimple_uid (stmt), |
| 2363 |
num, den, |
| 2364 |
true); |
| 2365 |
edge->count = copy_basic_block->count; |
| 2366 |
} |
| 2367 |
} |
| 2368 |
break; |
| 2369 |
|
| 2370 |
case CB_CGE_MOVE_CLONES: |
| 2371 |
id->dst_node->set_call_stmt_including_clones (orig_stmt, |
| 2372 |
call_stmt); |
| 2373 |
edge = id->dst_node->get_edge (stmt); |
| 2374 |
break; |
| 2375 |
|
| 2376 |
case CB_CGE_MOVE: |
| 2377 |
edge = id->dst_node->get_edge (orig_stmt); |
| 2378 |
if (edge) |
| 2379 |
edge = cgraph_edge::set_call_stmt (edge, call_stmt); |
| 2380 |
break; |
| 2381 |
|
| 2382 |
default: |
| 2383 |
gcc_unreachable (); |
| 2384 |
} |
| 2385 |
|
| 2386 |
/* Constant propagation on argument done during inlining |
| 2387 |
may create new direct call. Produce an edge for it. */ |
| 2388 |
if ((!edge |
| 2389 |
|| (edge->indirect_inlining_edge |
| 2390 |
&& id->transform_call_graph_edges == CB_CGE_MOVE_CLONES)) |
| 2391 |
&& id->dst_node->definition |
| 2392 |
&& (fn = gimple_call_fndecl (stmt)) != NULL) |
| 2393 |
{ |
| 2394 |
struct cgraph_node *dest = cgraph_node::get_create (fn); |
| 2395 |
|
| 2396 |
/* We have missing edge in the callgraph. This can happen |
| 2397 |
when previous inlining turned an indirect call into a |
| 2398 |
direct call by constant propagating arguments or we are |
| 2399 |
producing dead clone (for further cloning). In all |
| 2400 |
other cases we hit a bug (incorrect node sharing is the |
| 2401 |
most common reason for missing edges). */ |
| 2402 |
gcc_assert (!dest->definition |
| 2403 |
|| dest->address_taken |
| 2404 |
|| !id->src_node->definition |
| 2405 |
|| !id->dst_node->definition); |
| 2406 |
if (id->transform_call_graph_edges == CB_CGE_MOVE_CLONES) |
| 2407 |
id->dst_node->create_edge_including_clones |
| 2408 |
(dest, orig_stmt, call_stmt, bb->count, |
| 2409 |
CIF_ORIGINALLY_INDIRECT_CALL); |
| 2410 |
else |
| 2411 |
id->dst_node->create_edge (dest, call_stmt, |
| 2412 |
bb->count)->inline_failed |
| 2413 |
= CIF_ORIGINALLY_INDIRECT_CALL; |
| 2414 |
if (dump_file) |
| 2415 |
{ |
| 2416 |
fprintf (dump_file, "Created new direct edge to %s\n", |
| 2417 |
dest->dump_name ()); |
| 2418 |
} |
| 2419 |
} |
| 2420 |
|
| 2421 |
notice_special_calls (as_a <gcall *> (stmt)); |
| 2422 |
} |
| 2423 |
|
| 2424 |
maybe_duplicate_eh_stmt_fn (cfun, stmt, id->src_cfun, orig_stmt, |
| 2425 |
id->eh_map, id->eh_lp_nr); |
| 2426 |
|
| 2427 |
gsi_next (©_gsi); |
| 2428 |
} |
| 2429 |
while (!gsi_end_p (copy_gsi)); |
| 2430 |
|
| 2431 |
copy_gsi = gsi_last_bb (copy_basic_block); |
| 2432 |
} |
| 2433 |
|
| 2434 |
return copy_basic_block; |
| 2435 |
} |
| 2436 |
|
| 2437 |
/* Inserting Single Entry Multiple Exit region in SSA form into code in SSA |
| 2438 |
form is quite easy, since dominator relationship for old basic blocks does |
| 2439 |
not change. |
| 2440 |
|
| 2441 |
There is however exception where inlining might change dominator relation |
| 2442 |
across EH edges from basic block within inlined functions destinating |
| 2443 |
to landing pads in function we inline into. |
| 2444 |
|
| 2445 |
The function fills in PHI_RESULTs of such PHI nodes if they refer |
| 2446 |
to gimple regs. Otherwise, the function mark PHI_RESULT of such |
| 2447 |
PHI nodes for renaming. For non-gimple regs, renaming is safe: the |
| 2448 |
EH edges are abnormal and SSA_NAME_OCCURS_IN_ABNORMAL_PHI must be |
| 2449 |
set, and this means that there will be no overlapping live ranges |
| 2450 |
for the underlying symbol. |
| 2451 |
|
| 2452 |
This might change in future if we allow redirecting of EH edges and |
| 2453 |
we might want to change way build CFG pre-inlining to include |
| 2454 |
all the possible edges then. */ |
| 2455 |
static void |
| 2456 |
update_ssa_across_abnormal_edges (basic_block bb, basic_block ret_bb, |
| 2457 |
bool can_throw, bool nonlocal_goto) |
| 2458 |
{ |
| 2459 |
edge e; |
| 2460 |
edge_iterator ei; |
| 2461 |
|
| 2462 |
FOR_EACH_EDGE (e, ei, bb->succs) |
| 2463 |
if (!e->dest->aux |
| 2464 |
|| ((basic_block)e->dest->aux)->index == ENTRY_BLOCK) |
| 2465 |
{ |
| 2466 |
gphi *phi; |
| 2467 |
gphi_iterator si; |
| 2468 |
|
| 2469 |
if (!nonlocal_goto) |
| 2470 |
gcc_assert (e->flags & EDGE_EH); |
| 2471 |
|
| 2472 |
if (!can_throw) |
| 2473 |
gcc_assert (!(e->flags & EDGE_EH)); |
| 2474 |
|
| 2475 |
for (si = gsi_start_phis (e->dest); !gsi_end_p (si); gsi_next (&si)) |
| 2476 |
{ |
| 2477 |
edge re; |
| 2478 |
|
| 2479 |
phi = si.phi (); |
| 2480 |
|
| 2481 |
/* For abnormal goto/call edges the receiver can be the |
| 2482 |
ENTRY_BLOCK. Do not assert this cannot happen. */ |
| 2483 |
|
| 2484 |
gcc_assert ((e->flags & EDGE_EH) |
| 2485 |
|| SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (phi))); |
| 2486 |
|
| 2487 |
re = find_edge (ret_bb, e->dest); |
| 2488 |
gcc_checking_assert (re); |
| 2489 |
gcc_assert ((re->flags & (EDGE_EH | EDGE_ABNORMAL)) |
| 2490 |
== (e->flags & (EDGE_EH | EDGE_ABNORMAL))); |
| 2491 |
|
| 2492 |
SET_USE (PHI_ARG_DEF_PTR_FROM_EDGE (phi, e), |
| 2493 |
USE_FROM_PTR (PHI_ARG_DEF_PTR_FROM_EDGE (phi, re))); |
| 2494 |
} |
| 2495 |
} |
| 2496 |
} |
| 2497 |
|
| 2498 |
/* Insert clobbers for automatic variables of inlined ID->src_fn |
| 2499 |
function at the start of basic block ID->eh_landing_pad_dest. */ |
| 2500 |
|
| 2501 |
static void |
| 2502 |
add_clobbers_to_eh_landing_pad (copy_body_data *id) |
| 2503 |
{ |
| 2504 |
tree var; |
| 2505 |
basic_block bb = id->eh_landing_pad_dest; |
| 2506 |
live_vars_map *vars = NULL; |
| 2507 |
unsigned int cnt = 0; |
| 2508 |
unsigned int i; |
| 2509 |
FOR_EACH_VEC_SAFE_ELT (id->src_cfun->local_decls, i, var) |
| 2510 |
if (VAR_P (var) |
| 2511 |
&& !DECL_HARD_REGISTER (var) |
| 2512 |
&& !TREE_THIS_VOLATILE (var) |
| 2513 |
&& !DECL_HAS_VALUE_EXPR_P (var) |
| 2514 |
&& !is_gimple_reg (var) |
| 2515 |
&& auto_var_in_fn_p (var, id->src_fn) |
| 2516 |
&& !lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var))) |
| 2517 |
{ |
| 2518 |
tree *t = id->decl_map->get (var); |
| 2519 |
if (!t) |
| 2520 |
continue; |
| 2521 |
tree new_var = *t; |
| 2522 |
if (VAR_P (new_var) |
| 2523 |
&& !DECL_HARD_REGISTER (new_var) |
| 2524 |
&& !TREE_THIS_VOLATILE (new_var) |
| 2525 |
&& !DECL_HAS_VALUE_EXPR_P (new_var) |
| 2526 |
&& !is_gimple_reg (new_var) |
| 2527 |
&& auto_var_in_fn_p (new_var, id->dst_fn)) |
| 2528 |
{ |
| 2529 |
if (vars == NULL) |
| 2530 |
vars = new live_vars_map; |
| 2531 |
vars->put (DECL_UID (var), cnt++); |
| 2532 |
} |
| 2533 |
} |
| 2534 |
if (vars == NULL) |
| 2535 |
return; |
| 2536 |
|
| 2537 |
vec<bitmap_head> live = compute_live_vars (id->src_cfun, vars); |
| 2538 |
FOR_EACH_VEC_SAFE_ELT (id->src_cfun->local_decls, i, var) |
| 2539 |
if (VAR_P (var)) |
| 2540 |
{ |
| 2541 |
edge e; |
| 2542 |
edge_iterator ei; |
| 2543 |
bool needed = false; |
| 2544 |
unsigned int *v = vars->get (DECL_UID (var)); |
| 2545 |
if (v == NULL) |
| 2546 |
continue; |
| 2547 |
FOR_EACH_EDGE (e, ei, bb->preds) |
| 2548 |
if ((e->flags & EDGE_EH) != 0 |
| 2549 |
&& e->src->index >= id->add_clobbers_to_eh_landing_pads) |
| 2550 |
{ |
| 2551 |
basic_block src_bb = (basic_block) e->src->aux; |
| 2552 |
|
| 2553 |
if (bitmap_bit_p (&live[src_bb->index], *v)) |
| 2554 |
{ |
| 2555 |
needed = true; |
| 2556 |
break; |
| 2557 |
} |
| 2558 |
} |
| 2559 |
if (needed) |
| 2560 |
{ |
| 2561 |
tree new_var = *id->decl_map->get (var); |
| 2562 |
gimple_stmt_iterator gsi = gsi_after_labels (bb); |
| 2563 |
tree clobber = build_clobber (TREE_TYPE (new_var)); |
| 2564 |
gimple *clobber_stmt = gimple_build_assign (new_var, clobber); |
| 2565 |
gsi_insert_before (&gsi, clobber_stmt, GSI_NEW_STMT); |
| 2566 |
} |
| 2567 |
} |
| 2568 |
destroy_live_vars (live); |
| 2569 |
delete vars; |
| 2570 |
} |
| 2571 |
|
| 2572 |
/* Copy edges from BB into its copy constructed earlier, scale profile |
| 2573 |
accordingly. Edges will be taken care of later. Assume aux |
| 2574 |
pointers to point to the copies of each BB. Return true if any |
| 2575 |
debug stmts are left after a statement that must end the basic block. */ |
| 2576 |
|
| 2577 |
static bool |
| 2578 |
copy_edges_for_bb (basic_block bb, profile_count num, profile_count den, |
| 2579 |
basic_block ret_bb, basic_block abnormal_goto_dest, |
| 2580 |
copy_body_data *id) |
| 2581 |
{ |
| 2582 |
basic_block new_bb = (basic_block) bb->aux; |
| 2583 |
edge_iterator ei; |
| 2584 |
edge old_edge; |
| 2585 |
gimple_stmt_iterator si; |
| 2586 |
bool need_debug_cleanup = false; |
| 2587 |
|
| 2588 |
/* Use the indices from the original blocks to create edges for the |
| 2589 |
new ones. */ |
| 2590 |
FOR_EACH_EDGE (old_edge, ei, bb->succs) |
| 2591 |
if (!(old_edge->flags & EDGE_EH)) |
| 2592 |
{ |
| 2593 |
edge new_edge; |
| 2594 |
int flags = old_edge->flags; |
| 2595 |
location_t locus = old_edge->goto_locus; |
| 2596 |
|
| 2597 |
/* Return edges do get a FALLTHRU flag when they get inlined. */ |
| 2598 |
if (old_edge->dest->index == EXIT_BLOCK |
| 2599 |
&& !(flags & (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE|EDGE_FAKE)) |
| 2600 |
&& old_edge->dest->aux != EXIT_BLOCK_PTR_FOR_FN (cfun)) |
| 2601 |
flags |= EDGE_FALLTHRU; |
| 2602 |
|
| 2603 |
new_edge |
| 2604 |
= make_edge (new_bb, (basic_block) old_edge->dest->aux, flags); |
| 2605 |
new_edge->probability = old_edge->probability; |
| 2606 |
if (!id->reset_location) |
| 2607 |
new_edge->goto_locus = remap_location (locus, id); |
| 2608 |
} |
| 2609 |
|
| 2610 |
if (bb->index == ENTRY_BLOCK || bb->index == EXIT_BLOCK) |
| 2611 |
return false; |
| 2612 |
|
| 2613 |
/* When doing function splitting, we must decrease count of the return block |
| 2614 |
which was previously reachable by block we did not copy. */ |
| 2615 |
if (single_succ_p (bb) && single_succ_edge (bb)->dest->index == EXIT_BLOCK) |
| 2616 |
FOR_EACH_EDGE (old_edge, ei, bb->preds) |
| 2617 |
if (old_edge->src->index != ENTRY_BLOCK |
| 2618 |
&& !old_edge->src->aux) |
| 2619 |
new_bb->count -= old_edge->count ().apply_scale (num, den); |
| 2620 |
|
| 2621 |
/* Walk stmts from end to start so that splitting will adjust the BB |
| 2622 |
pointer for each stmt at most once, even when we split the block |
| 2623 |
multiple times. */ |
| 2624 |
bool seen_nondebug = false; |
| 2625 |
for (si = gsi_last_bb (new_bb); !gsi_end_p (si);) |
| 2626 |
{ |
| 2627 |
bool can_throw, nonlocal_goto; |
| 2628 |
gimple *copy_stmt = gsi_stmt (si); |
| 2629 |
|
| 2630 |
/* Do this before the possible split_block. */ |
| 2631 |
gsi_prev (&si); |
| 2632 |
|
| 2633 |
/* If this tree could throw an exception, there are two |
| 2634 |
cases where we need to add abnormal edge(s): the |
| 2635 |
tree wasn't in a region and there is a "current |
| 2636 |
region" in the caller; or the original tree had |
| 2637 |
EH edges. In both cases split the block after the tree, |
| 2638 |
and add abnormal edge(s) as needed; we need both |
| 2639 |
those from the callee and the caller. |
| 2640 |
We check whether the copy can throw, because the const |
| 2641 |
propagation can change an INDIRECT_REF which throws |
| 2642 |
into a COMPONENT_REF which doesn't. If the copy |
| 2643 |
can throw, the original could also throw. */ |
| 2644 |
can_throw = stmt_can_throw_internal (cfun, copy_stmt); |
| 2645 |
nonlocal_goto |
| 2646 |
= (stmt_can_make_abnormal_goto (copy_stmt) |
| 2647 |
&& !computed_goto_p (copy_stmt)); |
| 2648 |
|
| 2649 |
if (can_throw || nonlocal_goto) |
| 2650 |
{ |
| 2651 |
/* If there's only debug insns after copy_stmt don't split |
| 2652 |
the block but instead mark the block for cleanup. */ |
| 2653 |
if (!seen_nondebug) |
| 2654 |
need_debug_cleanup = true; |
| 2655 |
else |
| 2656 |
{ |
| 2657 |
/* Note that bb's predecessor edges aren't necessarily |
| 2658 |
right at this point; split_block doesn't care. */ |
| 2659 |
edge e = split_block (new_bb, copy_stmt); |
| 2660 |
e->dest->aux = new_bb->aux; |
| 2661 |
seen_nondebug = false; |
| 2662 |
} |
| 2663 |
} |
| 2664 |
|
| 2665 |
if (!is_gimple_debug (copy_stmt)) |
| 2666 |
seen_nondebug = true; |
| 2667 |
|
| 2668 |
bool update_probs = false; |
| 2669 |
|
| 2670 |
if (gimple_code (copy_stmt) == GIMPLE_EH_DISPATCH) |
| 2671 |
{ |
| 2672 |
make_eh_dispatch_edges (as_a <geh_dispatch *> (copy_stmt)); |
| 2673 |
update_probs = true; |
| 2674 |
} |
| 2675 |
else if (can_throw) |
| 2676 |
{ |
| 2677 |
make_eh_edge (copy_stmt); |
| 2678 |
update_probs = true; |
| 2679 |
} |
| 2680 |
|
| 2681 |
/* EH edges may not match old edges. Copy as much as possible. */ |
| 2682 |
if (update_probs) |
| 2683 |
{ |
| 2684 |
edge e; |
| 2685 |
edge_iterator ei; |
| 2686 |
basic_block copy_stmt_bb = gimple_bb (copy_stmt); |
| 2687 |
|
| 2688 |
FOR_EACH_EDGE (old_edge, ei, bb->succs) |
| 2689 |
if ((old_edge->flags & EDGE_EH) |
| 2690 |
&& (e = find_edge (copy_stmt_bb, |
| 2691 |
(basic_block) old_edge->dest->aux)) |
| 2692 |
&& (e->flags & EDGE_EH)) |
| 2693 |
e->probability = old_edge->probability; |
| 2694 |
|
| 2695 |
FOR_EACH_EDGE (e, ei, copy_stmt_bb->succs) |
| 2696 |
if (e->flags & EDGE_EH) |
| 2697 |
{ |
| 2698 |
if (!e->probability.initialized_p ()) |
| 2699 |
e->probability = profile_probability::never (); |
| 2700 |
if (e->dest->index < id->add_clobbers_to_eh_landing_pads) |
| 2701 |
{ |
| 2702 |
if (id->eh_landing_pad_dest == NULL) |
| 2703 |
id->eh_landing_pad_dest = e->dest; |
| 2704 |
else |
| 2705 |
gcc_assert (id->eh_landing_pad_dest == e->dest); |
| 2706 |
} |
| 2707 |
} |
| 2708 |
} |
| 2709 |
|
| 2710 |
|
| 2711 |
/* If the call we inline cannot make abnormal goto do not add |
| 2712 |
additional abnormal edges but only retain those already present |
| 2713 |
in the original function body. */ |
| 2714 |
if (abnormal_goto_dest == NULL) |
| 2715 |
nonlocal_goto = false; |
| 2716 |
if (nonlocal_goto) |
| 2717 |
{ |
| 2718 |
basic_block copy_stmt_bb = gimple_bb (copy_stmt); |
| 2719 |
|
| 2720 |
if (get_abnormal_succ_dispatcher (copy_stmt_bb)) |
| 2721 |
nonlocal_goto = false; |
| 2722 |
/* ABNORMAL_DISPATCHER (1) is for longjmp/setjmp or nonlocal gotos |
| 2723 |
in OpenMP regions which aren't allowed to be left abnormally. |
| 2724 |
So, no need to add abnormal edge in that case. */ |
| 2725 |
else if (is_gimple_call (copy_stmt) |
| 2726 |
&& gimple_call_internal_p (copy_stmt) |
| 2727 |
&& (gimple_call_internal_fn (copy_stmt) |
| 2728 |
== IFN_ABNORMAL_DISPATCHER) |
| 2729 |
&& gimple_call_arg (copy_stmt, 0) == boolean_true_node) |
| 2730 |
nonlocal_goto = false; |
| 2731 |
else |
| 2732 |
{ |
| 2733 |
make_single_succ_edge (copy_stmt_bb, abnormal_goto_dest, |
| 2734 |
EDGE_ABNORMAL); |
| 2735 |
gimple_call_set_ctrl_altering (copy_stmt, true); |
| 2736 |
if (is_a <gcall *> (copy_stmt) |
| 2737 |
&& (gimple_call_flags (copy_stmt) & ECF_NORETURN)) |
| 2738 |
fixup_noreturn_call (copy_stmt); |
| 2739 |
} |
| 2740 |
} |
| 2741 |
|
| 2742 |
if ((can_throw || nonlocal_goto) |
| 2743 |
&& gimple_in_ssa_p (cfun)) |
| 2744 |
update_ssa_across_abnormal_edges (gimple_bb (copy_stmt), ret_bb, |
| 2745 |
can_throw, nonlocal_goto); |
| 2746 |
} |
| 2747 |
return need_debug_cleanup; |
| 2748 |
} |
| 2749 |
|
| 2750 |
/* Copy the PHIs. All blocks and edges are copied, some blocks |
| 2751 |
was possibly split and new outgoing EH edges inserted. |
| 2752 |
BB points to the block of original function and AUX pointers links |
| 2753 |
the original and newly copied blocks. */ |
| 2754 |
|
| 2755 |
static void |
| 2756 |
copy_phis_for_bb (basic_block bb, copy_body_data *id) |
| 2757 |
{ |
| 2758 |
basic_block const new_bb = (basic_block) bb->aux; |
| 2759 |
edge_iterator ei; |
| 2760 |
gphi *phi; |
| 2761 |
gphi_iterator si; |
| 2762 |
edge new_edge; |
| 2763 |
bool inserted = false; |
| 2764 |
|
| 2765 |
for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si)) |
| 2766 |
{ |
| 2767 |
tree res, new_res; |
| 2768 |
gphi *new_phi; |
| 2769 |
|
| 2770 |
phi = si.phi (); |
| 2771 |
res = PHI_RESULT (phi); |
| 2772 |
new_res = res; |
| 2773 |
if (!virtual_operand_p (res) |
| 2774 |
&& (!id->param_body_adjs |
| 2775 |
|| !id->param_body_adjs->m_dead_stmts.contains (phi))) |
| 2776 |
{ |
| 2777 |
walk_tree (&new_res, copy_tree_body_r, id, NULL); |
| 2778 |
if (EDGE_COUNT (new_bb->preds) == 0) |
| 2779 |
{ |
| 2780 |
/* Technically we'd want a SSA_DEFAULT_DEF here... */ |
| 2781 |
SSA_NAME_DEF_STMT (new_res) = gimple_build_nop (); |
| 2782 |
} |
| 2783 |
else |
| 2784 |
{ |
| 2785 |
new_phi = create_phi_node (new_res, new_bb); |
| 2786 |
FOR_EACH_EDGE (new_edge, ei, new_bb->preds) |
| 2787 |
{ |
| 2788 |
edge old_edge = find_edge ((basic_block) new_edge->src->aux, |
| 2789 |
bb); |
| 2790 |
tree arg; |
| 2791 |
tree new_arg; |
| 2792 |
edge_iterator ei2; |
| 2793 |
location_t locus; |
| 2794 |
|
| 2795 |
/* When doing partial cloning, we allow PHIs on the entry |
| 2796 |
block as long as all the arguments are the same. |
| 2797 |
Find any input edge to see argument to copy. */ |
| 2798 |
if (!old_edge) |
| 2799 |
FOR_EACH_EDGE (old_edge, ei2, bb->preds) |
| 2800 |
if (!old_edge->src->aux) |
| 2801 |
break; |
| 2802 |
|
| 2803 |
arg = PHI_ARG_DEF_FROM_EDGE (phi, old_edge); |
| 2804 |
new_arg = arg; |
| 2805 |
walk_tree (&new_arg, copy_tree_body_r, id, NULL); |
| 2806 |
gcc_assert (new_arg); |
| 2807 |
/* With return slot optimization we can end up with |
| 2808 |
non-gimple (foo *)&this->m, fix that here. */ |
| 2809 |
if (TREE_CODE (new_arg) != SSA_NAME |
| 2810 |
&& TREE_CODE (new_arg) != FUNCTION_DECL |
| 2811 |
&& !is_gimple_val (new_arg)) |
| 2812 |
{ |
| 2813 |
gimple_seq stmts = NULL; |
| 2814 |
new_arg = force_gimple_operand (new_arg, &stmts, true, |
| 2815 |
NULL); |
| 2816 |
gsi_insert_seq_on_edge (new_edge, stmts); |
| 2817 |
inserted = true; |
| 2818 |
} |
| 2819 |
locus = gimple_phi_arg_location_from_edge (phi, old_edge); |
| 2820 |
if (id->reset_location) |
| 2821 |
locus = input_location; |
| 2822 |
else |
| 2823 |
locus = remap_location (locus, id); |
| 2824 |
add_phi_arg (new_phi, new_arg, new_edge, locus); |
| 2825 |
} |
| 2826 |
} |
| 2827 |
} |
| 2828 |
} |
| 2829 |
|
| 2830 |
/* Commit the delayed edge insertions. */ |
| 2831 |
if (inserted) |
| 2832 |
FOR_EACH_EDGE (new_edge, ei, new_bb->preds) |
| 2833 |
gsi_commit_one_edge_insert (new_edge, NULL); |
| 2834 |
} |
| 2835 |
|
| 2836 |
|
| 2837 |
/* Wrapper for remap_decl so it can be used as a callback. */ |
| 2838 |
|
| 2839 |
static tree |
| 2840 |
remap_decl_1 (tree decl, void *data) |
| 2841 |
{ |
| 2842 |
return remap_decl (decl, (copy_body_data *) data); |
| 2843 |
} |
| 2844 |
|
| 2845 |
/* Build struct function and associated datastructures for the new clone |
| 2846 |
NEW_FNDECL to be build. CALLEE_FNDECL is the original. Function changes |
| 2847 |
the cfun to the function of new_fndecl (and current_function_decl too). */ |
| 2848 |
|
| 2849 |
static void |
| 2850 |
initialize_cfun (tree new_fndecl, tree callee_fndecl, profile_count count) |
| 2851 |
{ |
| 2852 |
struct function *src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl); |
| 2853 |
|
| 2854 |
/* Register specific tree functions. */ |
| 2855 |
gimple_register_cfg_hooks (); |
| 2856 |
|
| 2857 |
/* Get clean struct function. */ |
| 2858 |
push_struct_function (new_fndecl, true); |
| 2859 |
targetm.target_option.relayout_function (new_fndecl); |
| 2860 |
|
| 2861 |
/* We will rebuild these, so just sanity check that they are empty. */ |
| 2862 |
gcc_assert (VALUE_HISTOGRAMS (cfun) == NULL); |
| 2863 |
gcc_assert (cfun->local_decls == NULL); |
| 2864 |
gcc_assert (cfun->cfg == NULL); |
| 2865 |
gcc_assert (cfun->decl == new_fndecl); |
| 2866 |
|
| 2867 |
/* Copy items we preserve during cloning. */ |
| 2868 |
cfun->static_chain_decl = src_cfun->static_chain_decl; |
| 2869 |
cfun->nonlocal_goto_save_area = src_cfun->nonlocal_goto_save_area; |
| 2870 |
cfun->function_end_locus = src_cfun->function_end_locus; |
| 2871 |
cfun->curr_properties = src_cfun->curr_properties; |
| 2872 |
cfun->last_verified = src_cfun->last_verified; |
| 2873 |
cfun->va_list_gpr_size = src_cfun->va_list_gpr_size; |
| 2874 |
cfun->va_list_fpr_size = src_cfun->va_list_fpr_size; |
| 2875 |
cfun->has_nonlocal_label = src_cfun->has_nonlocal_label; |
| 2876 |
cfun->calls_eh_return = src_cfun->calls_eh_return; |
| 2877 |
cfun->stdarg = src_cfun->stdarg; |
| 2878 |
cfun->after_inlining = src_cfun->after_inlining; |
| 2879 |
cfun->can_throw_non_call_exceptions |
| 2880 |
= src_cfun->can_throw_non_call_exceptions; |
| 2881 |
cfun->can_delete_dead_exceptions = src_cfun->can_delete_dead_exceptions; |
| 2882 |
cfun->returns_struct = src_cfun->returns_struct; |
| 2883 |
cfun->returns_pcc_struct = src_cfun->returns_pcc_struct; |
| 2884 |
|
| 2885 |
init_empty_tree_cfg (); |
| 2886 |
|
| 2887 |
profile_status_for_fn (cfun) = profile_status_for_fn (src_cfun); |
| 2888 |
cfun->cfg->full_profile = src_cfun->cfg->full_profile; |
| 2889 |
|
| 2890 |
profile_count num = count; |
| 2891 |
profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count; |
| 2892 |
profile_count::adjust_for_ipa_scaling (&num, &den); |
| 2893 |
|
| 2894 |
ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = |
| 2895 |
ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (count, |
| 2896 |
ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count); |
| 2897 |
EXIT_BLOCK_PTR_FOR_FN (cfun)->count = |
| 2898 |
EXIT_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (count, |
| 2899 |
ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count); |
| 2900 |
if (src_cfun->eh) |
| 2901 |
init_eh_for_function (); |
| 2902 |
|
| 2903 |
if (src_cfun->gimple_df) |
| 2904 |
{ |
| 2905 |
init_tree_ssa (cfun); |
| 2906 |
cfun->gimple_df->in_ssa_p = src_cfun->gimple_df->in_ssa_p; |
| 2907 |
if (cfun->gimple_df->in_ssa_p) |
| 2908 |
init_ssa_operands (cfun); |
| 2909 |
} |
| 2910 |
} |
| 2911 |
|
| 2912 |
/* Helper function for copy_cfg_body. Move debug stmts from the end |
| 2913 |
of NEW_BB to the beginning of successor basic blocks when needed. If the |
| 2914 |
successor has multiple predecessors, reset them, otherwise keep |
| 2915 |
their value. */ |
| 2916 |
|
| 2917 |
static void |
| 2918 |
maybe_move_debug_stmts_to_successors (copy_body_data *id, basic_block new_bb) |
| 2919 |
{ |
| 2920 |
edge e; |
| 2921 |
edge_iterator ei; |
| 2922 |
gimple_stmt_iterator si = gsi_last_nondebug_bb (new_bb); |
| 2923 |
|
| 2924 |
if (gsi_end_p (si) |
| 2925 |
|| gsi_one_before_end_p (si) |
| 2926 |
|| !(stmt_can_throw_internal (cfun, gsi_stmt (si)) |
| 2927 |
|| stmt_can_make_abnormal_goto (gsi_stmt (si)))) |
| 2928 |
return; |
| 2929 |
|
| 2930 |
FOR_EACH_EDGE (e, ei, new_bb->succs) |
| 2931 |
{ |
| 2932 |
gimple_stmt_iterator ssi = gsi_last_bb (new_bb); |
| 2933 |
gimple_stmt_iterator dsi = gsi_after_labels (e->dest); |
| 2934 |
while (is_gimple_debug (gsi_stmt (ssi))) |
| 2935 |
{ |
| 2936 |
gimple *stmt = gsi_stmt (ssi); |
| 2937 |
gdebug *new_stmt; |
| 2938 |
tree var; |
| 2939 |
tree value; |
| 2940 |
|
| 2941 |
/* For the last edge move the debug stmts instead of copying |
| 2942 |
them. */ |
| 2943 |
if (ei_one_before_end_p (ei)) |
| 2944 |
{ |
| 2945 |
si = ssi; |
| 2946 |
gsi_prev (&ssi); |
| 2947 |
if (!single_pred_p (e->dest) && gimple_debug_bind_p (stmt)) |
| 2948 |
{ |
| 2949 |
gimple_debug_bind_reset_value (stmt); |
| 2950 |
gimple_set_location (stmt, UNKNOWN_LOCATION); |
| 2951 |
} |
| 2952 |
gsi_remove (&si, false); |
| 2953 |
gsi_insert_before (&dsi, stmt, GSI_NEW_STMT); |
| 2954 |
continue; |
| 2955 |
} |
| 2956 |
|
| 2957 |
if (gimple_debug_bind_p (stmt)) |
| 2958 |
{ |
| 2959 |
var = gimple_debug_bind_get_var (stmt); |
| 2960 |
if (single_pred_p (e->dest)) |
| 2961 |
{ |
| 2962 |
value = gimple_debug_bind_get_value (stmt); |
| 2963 |
value = unshare_expr (value); |
| 2964 |
new_stmt = gimple_build_debug_bind (var, value, stmt); |
| 2965 |
} |
| 2966 |
else |
| 2967 |
new_stmt = gimple_build_debug_bind (var, NULL_TREE, NULL); |
| 2968 |
} |
| 2969 |
else if (gimple_debug_source_bind_p (stmt)) |
| 2970 |
{ |
| 2971 |
var = gimple_debug_source_bind_get_var (stmt); |
| 2972 |
value = gimple_debug_source_bind_get_value (stmt); |
| 2973 |
new_stmt = gimple_build_debug_source_bind (var, value, stmt); |
| 2974 |
} |
| 2975 |
else if (gimple_debug_nonbind_marker_p (stmt)) |
| 2976 |
new_stmt = as_a <gdebug *> (gimple_copy (stmt)); |
| 2977 |
else |
| 2978 |
gcc_unreachable (); |
| 2979 |
gsi_insert_before (&dsi, new_stmt, GSI_NEW_STMT); |
| 2980 |
id->debug_stmts.safe_push (new_stmt); |
| 2981 |
gsi_prev (&ssi); |
| 2982 |
} |
| 2983 |
} |
| 2984 |
} |
| 2985 |
|
| 2986 |
/* Make a copy of the sub-loops of SRC_PARENT and place them |
| 2987 |
as siblings of DEST_PARENT. */ |
| 2988 |
|
| 2989 |
static void |
| 2990 |
copy_loops (copy_body_data *id, |
| 2991 |
class loop *dest_parent, class loop *src_parent) |
| 2992 |
{ |
| 2993 |
class loop *src_loop = src_parent->inner; |
| 2994 |
while (src_loop) |
| 2995 |
{ |
| 2996 |
if (!id->blocks_to_copy |
| 2997 |
|| bitmap_bit_p (id->blocks_to_copy, src_loop->header->index)) |
| 2998 |
{ |
| 2999 |
class loop *dest_loop = alloc_loop (); |
| 3000 |
|
| 3001 |
/* Assign the new loop its header and latch and associate |
| 3002 |
those with the new loop. */ |
| 3003 |
dest_loop->header = (basic_block)src_loop->header->aux; |
| 3004 |
dest_loop->header->loop_father = dest_loop; |
| 3005 |
if (src_loop->latch != NULL) |
| 3006 |
{ |
| 3007 |
dest_loop->latch = (basic_block)src_loop->latch->aux; |
| 3008 |
dest_loop->latch->loop_father = dest_loop; |
| 3009 |
} |
| 3010 |
|
| 3011 |
/* Copy loop meta-data. */ |
| 3012 |
copy_loop_info (src_loop, dest_loop); |
| 3013 |
if (dest_loop->unroll) |
| 3014 |
cfun->has_unroll = true; |
| 3015 |
if (dest_loop->force_vectorize) |
| 3016 |
cfun->has_force_vectorize_loops = true; |
| 3017 |
if (id->src_cfun->last_clique != 0) |
| 3018 |
dest_loop->owned_clique |
| 3019 |
= remap_dependence_clique (id, |
| 3020 |
src_loop->owned_clique |
| 3021 |
? src_loop->owned_clique : 1); |
| 3022 |
|
| 3023 |
/* Finally place it into the loop array and the loop tree. */ |
| 3024 |
place_new_loop (cfun, dest_loop); |
| 3025 |
flow_loop_tree_node_add (dest_parent, dest_loop); |
| 3026 |
|
| 3027 |
if (src_loop->simduid) |
| 3028 |
{ |
| 3029 |
dest_loop->simduid = remap_decl (src_loop->simduid, id); |
| 3030 |
cfun->has_simduid_loops = true; |
| 3031 |
} |
| 3032 |
|
| 3033 |
/* Recurse. */ |
| 3034 |
copy_loops (id, dest_loop, src_loop); |
| 3035 |
} |
| 3036 |
src_loop = src_loop->next; |
| 3037 |
} |
| 3038 |
} |
| 3039 |
|
| 3040 |
/* Call redirect_call_stmt_to_callee on all calls in BB. */ |
| 3041 |
|
| 3042 |
void |
| 3043 |
redirect_all_calls (copy_body_data * id, basic_block bb) |
| 3044 |
{ |
| 3045 |
gimple_stmt_iterator si; |
| 3046 |
gimple *last = last_nondebug_stmt (bb); |
| 3047 |
for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) |
| 3048 |
{ |
| 3049 |
gimple *stmt = gsi_stmt (si); |
| 3050 |
if (is_gimple_call (stmt)) |
| 3051 |
{ |
| 3052 |
struct cgraph_edge *edge = id->dst_node->get_edge (stmt); |
| 3053 |
if (edge) |
| 3054 |
{ |
| 3055 |
if (!id->killed_new_ssa_names) |
| 3056 |
id->killed_new_ssa_names = new hash_set<tree> (16); |
| 3057 |
cgraph_edge::redirect_call_stmt_to_callee (edge, |
| 3058 |
id->killed_new_ssa_names); |
| 3059 |
|
| 3060 |
if (stmt == last && id->call_stmt && maybe_clean_eh_stmt (stmt)) |
| 3061 |
gimple_purge_dead_eh_edges (bb); |
| 3062 |
} |
| 3063 |
} |
| 3064 |
} |
| 3065 |
} |
| 3066 |
|
| 3067 |
/* Make a copy of the body of FN so that it can be inserted inline in |
| 3068 |
another function. Walks FN via CFG, returns new fndecl. */ |
| 3069 |
|
| 3070 |
static tree |
| 3071 |
copy_cfg_body (copy_body_data * id, |
| 3072 |
basic_block entry_block_map, basic_block exit_block_map, |
| 3073 |
basic_block new_entry) |
| 3074 |
{ |
| 3075 |
tree callee_fndecl = id->src_fn; |
| 3076 |
/* Original cfun for the callee, doesn't change. */ |
| 3077 |
struct function *src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl); |
| 3078 |
struct function *cfun_to_copy; |
| 3079 |
basic_block bb; |
| 3080 |
tree new_fndecl = NULL; |
| 3081 |
bool need_debug_cleanup = false; |
| 3082 |
int last; |
| 3083 |
profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count; |
| 3084 |
profile_count num = entry_block_map->count; |
| 3085 |
|
| 3086 |
cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl); |
| 3087 |
|
| 3088 |
/* Register specific tree functions. */ |
| 3089 |
gimple_register_cfg_hooks (); |
| 3090 |
|
| 3091 |
/* If we are inlining just region of the function, make sure to connect |
| 3092 |
new entry to ENTRY_BLOCK_PTR_FOR_FN (cfun). Since new entry can be |
| 3093 |
part of loop, we must compute frequency and probability of |
| 3094 |
ENTRY_BLOCK_PTR_FOR_FN (cfun) based on the frequencies and |
| 3095 |
probabilities of edges incoming from nonduplicated region. */ |
| 3096 |
if (new_entry) |
| 3097 |
{ |
| 3098 |
edge e; |
| 3099 |
edge_iterator ei; |
| 3100 |
den = profile_count::zero (); |
| 3101 |
|
| 3102 |
FOR_EACH_EDGE (e, ei, new_entry->preds) |
| 3103 |
if (!e->src->aux) |
| 3104 |
den += e->count (); |
| 3105 |
ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = den; |
| 3106 |
} |
| 3107 |
|
| 3108 |
profile_count::adjust_for_ipa_scaling (&num, &den); |
| 3109 |
|
| 3110 |
/* Must have a CFG here at this point. */ |
| 3111 |
gcc_assert (ENTRY_BLOCK_PTR_FOR_FN |
| 3112 |
(DECL_STRUCT_FUNCTION (callee_fndecl))); |
| 3113 |
|
| 3114 |
|
| 3115 |
ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = entry_block_map; |
| 3116 |
EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = exit_block_map; |
| 3117 |
entry_block_map->aux = ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy); |
| 3118 |
exit_block_map->aux = EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy); |
| 3119 |
|
| 3120 |
/* Duplicate any exception-handling regions. */ |
| 3121 |
if (cfun->eh) |
| 3122 |
id->eh_map = duplicate_eh_regions (cfun_to_copy, NULL, id->eh_lp_nr, |
| 3123 |
remap_decl_1, id); |
| 3124 |
|
| 3125 |
/* Use aux pointers to map the original blocks to copy. */ |
| 3126 |
FOR_EACH_BB_FN (bb, cfun_to_copy) |
| 3127 |
if (!id->blocks_to_copy || bitmap_bit_p (id->blocks_to_copy, bb->index)) |
| 3128 |
{ |
| 3129 |
basic_block new_bb = copy_bb (id, bb, num, den); |
| 3130 |
bb->aux = new_bb; |
| 3131 |
new_bb->aux = bb; |
| 3132 |
new_bb->loop_father = entry_block_map->loop_father; |
| 3133 |
} |
| 3134 |
|
| 3135 |
last = last_basic_block_for_fn (cfun); |
| 3136 |
|
| 3137 |
/* Now that we've duplicated the blocks, duplicate their edges. */ |
| 3138 |
basic_block abnormal_goto_dest = NULL; |
| 3139 |
if (id->call_stmt |
| 3140 |
&& stmt_can_make_abnormal_goto (id->call_stmt)) |
| 3141 |
{ |
| 3142 |
gimple_stmt_iterator gsi = gsi_for_stmt (id->call_stmt); |
| 3143 |
|
| 3144 |
bb = gimple_bb (id->call_stmt); |
| 3145 |
gsi_next (&gsi); |
| 3146 |
if (gsi_end_p (gsi)) |
| 3147 |
abnormal_goto_dest = get_abnormal_succ_dispatcher (bb); |
| 3148 |
} |
| 3149 |
FOR_ALL_BB_FN (bb, cfun_to_copy) |
| 3150 |
if (!id->blocks_to_copy |
| 3151 |
|| (bb->index > 0 && bitmap_bit_p (id->blocks_to_copy, bb->index))) |
| 3152 |
need_debug_cleanup |= copy_edges_for_bb (bb, num, den, exit_block_map, |
| 3153 |
abnormal_goto_dest, id); |
| 3154 |
|
| 3155 |
if (id->eh_landing_pad_dest) |
| 3156 |
{ |
| 3157 |
add_clobbers_to_eh_landing_pad (id); |
| 3158 |
id->eh_landing_pad_dest = NULL; |
| 3159 |
} |
| 3160 |
|
| 3161 |
if (new_entry) |
| 3162 |
{ |
| 3163 |
edge e = make_edge (entry_block_map, (basic_block)new_entry->aux, |
| 3164 |
EDGE_FALLTHRU); |
| 3165 |
e->probability = profile_probability::always (); |
| 3166 |
} |
| 3167 |
|
| 3168 |
/* Duplicate the loop tree, if available and wanted. */ |
| 3169 |
if (loops_for_fn (src_cfun) != NULL |
| 3170 |
&& current_loops != NULL) |
| 3171 |
{ |
| 3172 |
copy_loops (id, entry_block_map->loop_father, |
| 3173 |
get_loop (src_cfun, 0)); |
| 3174 |
/* Defer to cfgcleanup to update loop-father fields of basic-blocks. */ |
| 3175 |
loops_state_set (LOOPS_NEED_FIXUP); |
| 3176 |
} |
| 3177 |
|
| 3178 |
/* If the loop tree in the source function needed fixup, mark the |
| 3179 |
destination loop tree for fixup, too. */ |
| 3180 |
if (loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP) |
| 3181 |
loops_state_set (LOOPS_NEED_FIXUP); |
| 3182 |
|
| 3183 |
if (gimple_in_ssa_p (cfun)) |
| 3184 |
FOR_ALL_BB_FN (bb, cfun_to_copy) |
| 3185 |
if (!id->blocks_to_copy |
| 3186 |
|| (bb->index > 0 && bitmap_bit_p (id->blocks_to_copy, bb->index))) |
| 3187 |
copy_phis_for_bb (bb, id); |
| 3188 |
|
| 3189 |
FOR_ALL_BB_FN (bb, cfun_to_copy) |
| 3190 |
if (bb->aux) |
| 3191 |
{ |
| 3192 |
if (need_debug_cleanup |
| 3193 |
&& bb->index != ENTRY_BLOCK |
| 3194 |
&& bb->index != EXIT_BLOCK) |
| 3195 |
maybe_move_debug_stmts_to_successors (id, (basic_block) bb->aux); |
| 3196 |
/* Update call edge destinations. This cannot be done before loop |
| 3197 |
info is updated, because we may split basic blocks. */ |
| 3198 |
if (id->transform_call_graph_edges == CB_CGE_DUPLICATE |
| 3199 |
&& bb->index != ENTRY_BLOCK |
| 3200 |
&& bb->index != EXIT_BLOCK) |
| 3201 |
redirect_all_calls (id, (basic_block)bb->aux); |
| 3202 |
((basic_block)bb->aux)->aux = NULL; |
| 3203 |
bb->aux = NULL; |
| 3204 |
} |
| 3205 |
|
| 3206 |
/* Zero out AUX fields of newly created block during EH edge |
| 3207 |
insertion. */ |
| 3208 |
for (; last < last_basic_block_for_fn (cfun); last++) |
| 3209 |
{ |
| 3210 |
if (need_debug_cleanup) |
| 3211 |
maybe_move_debug_stmts_to_successors (id, |
| 3212 |
BASIC_BLOCK_FOR_FN (cfun, last)); |
| 3213 |
BASIC_BLOCK_FOR_FN (cfun, last)->aux = NULL; |
| 3214 |
/* Update call edge destinations. This cannot be done before loop |
| 3215 |
info is updated, because we may split basic blocks. */ |
| 3216 |
if (id->transform_call_graph_edges == CB_CGE_DUPLICATE) |
| 3217 |
redirect_all_calls (id, BASIC_BLOCK_FOR_FN (cfun, last)); |
| 3218 |
} |
| 3219 |
entry_block_map->aux = NULL; |
| 3220 |
exit_block_map->aux = NULL; |
| 3221 |
|
| 3222 |
if (id->eh_map) |
| 3223 |
{ |
| 3224 |
delete id->eh_map; |
| 3225 |
id->eh_map = NULL; |
| 3226 |
} |
| 3227 |
if (id->dependence_map) |
| 3228 |
{ |
| 3229 |
delete id->dependence_map; |
| 3230 |
id->dependence_map = NULL; |
| 3231 |
} |
| 3232 |
|
| 3233 |
return new_fndecl; |
| 3234 |
} |
| 3235 |
|
| 3236 |
/* Copy the debug STMT using ID. We deal with these statements in a |
| 3237 |
special way: if any variable in their VALUE expression wasn't |
| 3238 |
remapped yet, we won't remap it, because that would get decl uids |
| 3239 |
out of sync, causing codegen differences between -g and -g0. If |
| 3240 |
this arises, we drop the VALUE expression altogether. */ |
| 3241 |
|
| 3242 |
static void |
| 3243 |
copy_debug_stmt (gdebug *stmt, copy_body_data *id) |
| 3244 |
{ |
| 3245 |
tree t, *n; |
| 3246 |
struct walk_stmt_info wi; |
| 3247 |
|
| 3248 |
if (tree block = gimple_block (stmt)) |
| 3249 |
{ |
| 3250 |
n = id->decl_map->get (block); |
| 3251 |
gimple_set_block (stmt, n ? *n : id->block); |
| 3252 |
} |
| 3253 |
|
| 3254 |
if (gimple_debug_nonbind_marker_p (stmt)) |
| 3255 |
{ |
| 3256 |
if (id->call_stmt && !gimple_block (stmt)) |
| 3257 |
{ |
| 3258 |
gimple_stmt_iterator gsi = gsi_for_stmt (stmt); |
| 3259 |
gsi_remove (&gsi, true); |
| 3260 |
} |
| 3261 |
return; |
| 3262 |
} |
| 3263 |
|
| 3264 |
/* Remap all the operands in COPY. */ |
| 3265 |
memset (&wi, 0, sizeof (wi)); |
| 3266 |
wi.info = id; |
| 3267 |
|
| 3268 |
processing_debug_stmt = 1; |
| 3269 |
|
| 3270 |
if (gimple_debug_source_bind_p (stmt)) |
| 3271 |
t = gimple_debug_source_bind_get_var (stmt); |
| 3272 |
else if (gimple_debug_bind_p (stmt)) |
| 3273 |
t = gimple_debug_bind_get_var (stmt); |
| 3274 |
else |
| 3275 |
gcc_unreachable (); |
| 3276 |
|
| 3277 |
if (TREE_CODE (t) == PARM_DECL |
| 3278 |
&& id->debug_map |
| 3279 |
&& (n = id->debug_map->get (t))) |
| 3280 |
{ |
| 3281 |
gcc_assert (VAR_P (*n)); |
| 3282 |
t = *n; |
| 3283 |
} |
| 3284 |
else if (VAR_P (t) && !is_global_var (t) && !id->decl_map->get (t)) |
| 3285 |
/* T is a non-localized variable. */; |
| 3286 |
else |
| 3287 |
walk_tree (&t, remap_gimple_op_r, &wi, NULL); |
| 3288 |
|
| 3289 |
if (gimple_debug_bind_p (stmt)) |
| 3290 |
{ |
| 3291 |
gimple_debug_bind_set_var (stmt, t); |
| 3292 |
|
| 3293 |
if (gimple_debug_bind_has_value_p (stmt)) |
| 3294 |
walk_tree (gimple_debug_bind_get_value_ptr (stmt), |
| 3295 |
remap_gimple_op_r, &wi, NULL); |
| 3296 |
|
| 3297 |
/* Punt if any decl couldn't be remapped. */ |
| 3298 |
if (processing_debug_stmt < 0) |
| 3299 |
gimple_debug_bind_reset_value (stmt); |
| 3300 |
} |
| 3301 |
else if (gimple_debug_source_bind_p (stmt)) |
| 3302 |
{ |
| 3303 |
gimple_debug_source_bind_set_var (stmt, t); |
| 3304 |
/* When inlining and source bind refers to one of the optimized |
| 3305 |
away parameters, change the source bind into normal debug bind |
| 3306 |
referring to the corresponding DEBUG_EXPR_DECL that should have |
| 3307 |
been bound before the call stmt. */ |
| 3308 |
t = gimple_debug_source_bind_get_value (stmt); |
| 3309 |
if (t != NULL_TREE |
| 3310 |
&& TREE_CODE (t) == PARM_DECL |
| 3311 |
&& id->call_stmt) |
| 3312 |
{ |
| 3313 |
vec<tree, va_gc> **debug_args = decl_debug_args_lookup (id->src_fn); |
| 3314 |
unsigned int i; |
| 3315 |
if (debug_args != NULL) |
| 3316 |
{ |
| 3317 |
for (i = 0; i < vec_safe_length (*debug_args); i += 2) |
| 3318 |
if ((**debug_args)[i] == DECL_ORIGIN (t) |
| 3319 |
&& TREE_CODE ((**debug_args)[i + 1]) == DEBUG_EXPR_DECL) |
| 3320 |
{ |
| 3321 |
t = (**debug_args)[i + 1]; |
| 3322 |
stmt->subcode = GIMPLE_DEBUG_BIND; |
| 3323 |
gimple_debug_bind_set_value (stmt, t); |
| 3324 |
break; |
| 3325 |
} |
| 3326 |
} |
| 3327 |
} |
| 3328 |
if (gimple_debug_source_bind_p (stmt)) |
| 3329 |
walk_tree (gimple_debug_source_bind_get_value_ptr (stmt), |
| 3330 |
remap_gimple_op_r, &wi, NULL); |
| 3331 |
} |
| 3332 |
|
| 3333 |
processing_debug_stmt = 0; |
| 3334 |
|
| 3335 |
update_stmt (stmt); |
| 3336 |
} |
| 3337 |
|
| 3338 |
/* Process deferred debug stmts. In order to give values better odds |
| 3339 |
of being successfully remapped, we delay the processing of debug |
| 3340 |
stmts until all other stmts that might require remapping are |
| 3341 |
processed. */ |
| 3342 |
|
| 3343 |
static void |
| 3344 |
copy_debug_stmts (copy_body_data *id) |
| 3345 |
{ |
| 3346 |
if (!id->debug_stmts.exists ()) |
| 3347 |
return; |
| 3348 |
|
| 3349 |
for (gdebug *stmt : id->debug_stmts) |
| 3350 |
/* But avoid re-processing debug stmts that have been elided. */ |
| 3351 |
if (gimple_bb (stmt)) |
| 3352 |
copy_debug_stmt (stmt, id); |
| 3353 |
|
| 3354 |
id->debug_stmts.release (); |
| 3355 |
} |
| 3356 |
|
| 3357 |
/* Make a copy of the body of SRC_FN so that it can be inserted inline in |
| 3358 |
another function. */ |
| 3359 |
|
| 3360 |
static tree |
| 3361 |
copy_tree_body (copy_body_data *id) |
| 3362 |
{ |
| 3363 |
tree fndecl = id->src_fn; |
| 3364 |
tree body = DECL_SAVED_TREE (fndecl); |
| 3365 |
|
| 3366 |
walk_tree (&body, copy_tree_body_r, id, NULL); |
| 3367 |
|
| 3368 |
return body; |
| 3369 |
} |
| 3370 |
|
| 3371 |
/* Make a copy of the body of FN so that it can be inserted inline in |
| 3372 |
another function. */ |
| 3373 |
|
| 3374 |
static tree |
| 3375 |
copy_body (copy_body_data *id, |
| 3376 |
basic_block entry_block_map, basic_block exit_block_map, |
| 3377 |
basic_block new_entry) |
| 3378 |
{ |
| 3379 |
tree fndecl = id->src_fn; |
| 3380 |
tree body; |
| 3381 |
|
| 3382 |
/* If this body has a CFG, walk CFG and copy. */ |
| 3383 |
gcc_assert (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (fndecl))); |
| 3384 |
body = copy_cfg_body (id, entry_block_map, exit_block_map, |
| 3385 |
new_entry); |
| 3386 |
copy_debug_stmts (id); |
| 3387 |
if (id->killed_new_ssa_names) |
| 3388 |
{ |
| 3389 |
ipa_release_ssas_in_hash (id->killed_new_ssa_names); |
| 3390 |
delete id->killed_new_ssa_names; |
| 3391 |
id->killed_new_ssa_names = NULL; |
| 3392 |
} |
| 3393 |
|
| 3394 |
return body; |
| 3395 |
} |
| 3396 |
|
| 3397 |
/* Return true if VALUE is an ADDR_EXPR of an automatic variable |
| 3398 |
defined in function FN, or of a data member thereof. */ |
| 3399 |
|
| 3400 |
static bool |
| 3401 |
self_inlining_addr_expr (tree value, tree fn) |
| 3402 |
{ |
| 3403 |
tree var; |
| 3404 |
|
| 3405 |
if (TREE_CODE (value) != ADDR_EXPR) |
| 3406 |
return false; |
| 3407 |
|
| 3408 |
var = get_base_address (TREE_OPERAND (value, 0)); |
| 3409 |
|
| 3410 |
return var && auto_var_in_fn_p (var, fn); |
| 3411 |
} |
| 3412 |
|
| 3413 |
/* Append to BB a debug annotation that binds VAR to VALUE, inheriting |
| 3414 |
lexical block and line number information from base_stmt, if given, |
| 3415 |
or from the last stmt of the block otherwise. */ |
| 3416 |
|
| 3417 |
static gimple * |
| 3418 |
insert_init_debug_bind (copy_body_data *id, |
| 3419 |
basic_block bb, tree var, tree value, |
| 3420 |
gimple *base_stmt) |
| 3421 |
{ |
| 3422 |
gimple *note; |
| 3423 |
gimple_stmt_iterator gsi; |
| 3424 |
tree tracked_var; |
| 3425 |
|
| 3426 |
if (!gimple_in_ssa_p (id->src_cfun)) |
| 3427 |
return NULL; |
| 3428 |
|
| 3429 |
if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments)) |
| 3430 |
return NULL; |
| 3431 |
|
| 3432 |
tracked_var = target_for_debug_bind (var); |
| 3433 |
if (!tracked_var) |
| 3434 |
return NULL; |
| 3435 |
|
| 3436 |
if (bb) |
| 3437 |
{ |
| 3438 |
gsi = gsi_last_bb (bb); |
| 3439 |
if (!base_stmt && !gsi_end_p (gsi)) |
| 3440 |
base_stmt = gsi_stmt (gsi); |
| 3441 |
} |
| 3442 |
|
| 3443 |
note = gimple_build_debug_bind (tracked_var, |
| 3444 |
value == error_mark_node |
| 3445 |
? NULL_TREE : unshare_expr (value), |
| 3446 |
base_stmt); |
| 3447 |
|
| 3448 |
if (bb) |
| 3449 |
{ |
| 3450 |
if (!gsi_end_p (gsi)) |
| 3451 |
gsi_insert_after (&gsi, note, GSI_SAME_STMT); |
| 3452 |
else |
| 3453 |
gsi_insert_before (&gsi, note, GSI_SAME_STMT); |
| 3454 |
} |
| 3455 |
|
| 3456 |
return note; |
| 3457 |
} |
| 3458 |
|
| 3459 |
static void |
| 3460 |
insert_init_stmt (copy_body_data *id, basic_block bb, gimple *init_stmt) |
| 3461 |
{ |
| 3462 |
/* If VAR represents a zero-sized variable, it's possible that the |
| 3463 |
assignment statement may result in no gimple statements. */ |
| 3464 |
if (init_stmt) |
| 3465 |
{ |
| 3466 |
gimple_stmt_iterator si = gsi_last_bb (bb); |
| 3467 |
|
| 3468 |
/* We can end up with init statements that store to a non-register |
| 3469 |
from a rhs with a conversion. Handle that here by forcing the |
| 3470 |
rhs into a temporary. gimple_regimplify_operands is not |
| 3471 |
prepared to do this for us. */ |
| 3472 |
if (!is_gimple_debug (init_stmt) |
| 3473 |
&& !is_gimple_reg (gimple_assign_lhs (init_stmt)) |
| 3474 |
&& is_gimple_reg_type (TREE_TYPE (gimple_assign_lhs (init_stmt))) |
| 3475 |
&& gimple_assign_rhs_class (init_stmt) == GIMPLE_UNARY_RHS) |
| 3476 |
{ |
| 3477 |
tree rhs = build1 (gimple_assign_rhs_code (init_stmt), |
| 3478 |
TREE_TYPE (gimple_assign_lhs (init_stmt)), |
| 3479 |
gimple_assign_rhs1 (init_stmt)); |
| 3480 |
rhs = force_gimple_operand_gsi (&si, rhs, true, NULL_TREE, false, |
| 3481 |
GSI_NEW_STMT); |
| 3482 |
gimple_assign_set_rhs_code (init_stmt, TREE_CODE (rhs)); |
| 3483 |
gimple_assign_set_rhs1 (init_stmt, rhs); |
| 3484 |
} |
| 3485 |
gsi_insert_after (&si, init_stmt, GSI_NEW_STMT); |
| 3486 |
if (!is_gimple_debug (init_stmt)) |
| 3487 |
{ |
| 3488 |
gimple_regimplify_operands (init_stmt, &si); |
| 3489 |
|
| 3490 |
tree def = gimple_assign_lhs (init_stmt); |
| 3491 |
insert_init_debug_bind (id, bb, def, def, init_stmt); |
| 3492 |
} |
| 3493 |
} |
| 3494 |
} |
| 3495 |
|
| 3496 |
/* Deal with mismatched formal/actual parameters, in a rather brute-force way |
| 3497 |
if need be (which should only be necessary for invalid programs). Attempt |
| 3498 |
to convert VAL to TYPE and return the result if it is possible, just return |
| 3499 |
a zero constant of the given type if it fails. */ |
| 3500 |
|
| 3501 |
tree |
| 3502 |
force_value_to_type (tree type, tree value) |
| 3503 |
{ |
| 3504 |
/* If we can match up types by promotion/demotion do so. */ |
| 3505 |
if (fold_convertible_p (type, value)) |
| 3506 |
return fold_convert (type, value); |
| 3507 |
|
| 3508 |
/* ??? For valid programs we should not end up here. |
| 3509 |
Still if we end up with truly mismatched types here, fall back |
| 3510 |
to using a VIEW_CONVERT_EXPR or a literal zero to not leak invalid |
| 3511 |
GIMPLE to the following passes. */ |
| 3512 |
if (TREE_CODE (value) == WITH_SIZE_EXPR) |
| 3513 |
return error_mark_node; |
| 3514 |
else if (!is_gimple_reg_type (TREE_TYPE (value)) |
| 3515 |
|| TYPE_SIZE (type) == TYPE_SIZE (TREE_TYPE (value))) |
| 3516 |
return fold_build1 (VIEW_CONVERT_EXPR, type, value); |
| 3517 |
else |
| 3518 |
return build_zero_cst (type); |
| 3519 |
} |
| 3520 |
|
| 3521 |
/* Initialize parameter P with VALUE. If needed, produce init statement |
| 3522 |
at the end of BB. When BB is NULL, we return init statement to be |
| 3523 |
output later. */ |
| 3524 |
static gimple * |
| 3525 |
setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn, |
| 3526 |
basic_block bb, tree *vars) |
| 3527 |
{ |
| 3528 |
gimple *init_stmt = NULL; |
| 3529 |
tree var; |
| 3530 |
tree def = (gimple_in_ssa_p (cfun) |
| 3531 |
? ssa_default_def (id->src_cfun, p) : NULL); |
| 3532 |
|
| 3533 |
/* Make an equivalent VAR_DECL. Note that we must NOT remap the type |
| 3534 |
here since the type of this decl must be visible to the calling |
| 3535 |
function. */ |
| 3536 |
var = copy_decl_to_var (p, id); |
| 3537 |
|
| 3538 |
/* Declare this new variable. */ |
| 3539 |
DECL_CHAIN (var) = *vars; |
| 3540 |
*vars = var; |
| 3541 |
|
| 3542 |
/* Make gimplifier happy about this variable. */ |
| 3543 |
DECL_SEEN_IN_BIND_EXPR_P (var) = 1; |
| 3544 |
|
| 3545 |
/* If the parameter is never assigned to, has no SSA_NAMEs created, |
| 3546 |
we would not need to create a new variable here at all, if it |
| 3547 |
weren't for debug info. Still, we can just use the argument |
| 3548 |
value. */ |
| 3549 |
if (TREE_READONLY (p) |
| 3550 |
&& !TREE_ADDRESSABLE (p) |
| 3551 |
&& value |
| 3552 |
&& !TREE_SIDE_EFFECTS (value) |
| 3553 |
&& !def) |
| 3554 |
{ |
| 3555 |
/* We may produce non-gimple trees by adding NOPs or introduce invalid |
| 3556 |
sharing when the value is not constant or DECL. And we need to make |
| 3557 |
sure that it cannot be modified from another path in the callee. */ |
| 3558 |
if (((is_gimple_min_invariant (value) |
| 3559 |
/* When the parameter is used in a context that forces it to |
| 3560 |
not be a GIMPLE register avoid substituting something that |
| 3561 |
is not a decl there. */ |
| 3562 |
&& ! DECL_NOT_GIMPLE_REG_P (p)) |
| 3563 |
|| (DECL_P (value) && TREE_READONLY (value)) |
| 3564 |
|| (auto_var_in_fn_p (value, id->dst_fn) |
| 3565 |
&& !TREE_ADDRESSABLE (value))) |
| 3566 |
&& useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE (value)) |
| 3567 |
/* We have to be very careful about ADDR_EXPR. Make sure |
| 3568 |
the base variable isn't a local variable of the inlined |
| 3569 |
function, e.g., when doing recursive inlining, direct or |
| 3570 |
mutually-recursive or whatever, which is why we don't |
| 3571 |
just test whether fn == current_function_decl. */ |
| 3572 |
&& ! self_inlining_addr_expr (value, fn)) |
| 3573 |
{ |
| 3574 |
insert_decl_map (id, p, value); |
| 3575 |
if (!id->debug_map) |
| 3576 |
id->debug_map = new hash_map<tree, tree>; |
| 3577 |
id->debug_map->put (p, var); |
| 3578 |
return insert_init_debug_bind (id, bb, var, value, NULL); |
| 3579 |
} |
| 3580 |
} |
| 3581 |
|
| 3582 |
/* Register the VAR_DECL as the equivalent for the PARM_DECL; |
| 3583 |
that way, when the PARM_DECL is encountered, it will be |
| 3584 |
automatically replaced by the VAR_DECL. */ |
| 3585 |
insert_decl_map (id, p, var); |
| 3586 |
|
| 3587 |
/* Even if P was TREE_READONLY, the new VAR should not be. In the original |
| 3588 |
code, we would have constructed a temporary, and then the function body |
| 3589 |
would have never changed the value of P. However, now, we will be |
| 3590 |
constructing VAR directly. Therefore, it must not be TREE_READONLY. */ |
| 3591 |
TREE_READONLY (var) = 0; |
| 3592 |
|
| 3593 |
tree rhs = value; |
| 3594 |
if (value |
| 3595 |
&& value != error_mark_node |
| 3596 |
&& !useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE (value))) |
| 3597 |
rhs = force_value_to_type (TREE_TYPE (p), value); |
| 3598 |
|
| 3599 |
/* If there is no setup required and we are in SSA, take the easy route |
| 3600 |
replacing all SSA names representing the function parameter by the |
| 3601 |
SSA name passed to function. |
| 3602 |
|
| 3603 |
We need to construct map for the variable anyway as it might be used |
| 3604 |
in different SSA names when parameter is set in function. |
| 3605 |
|
| 3606 |
Do replacement at -O0 for const arguments replaced by constant. |
| 3607 |
This is important for builtin_constant_p and other construct requiring |
| 3608 |
constant argument to be visible in inlined function body. */ |
| 3609 |
if (gimple_in_ssa_p (cfun) && rhs && def && is_gimple_reg (p) |
| 3610 |
&& (optimize |
| 3611 |
|| (TREE_READONLY (p) |
| 3612 |
&& is_gimple_min_invariant (rhs))) |
| 3613 |
&& (TREE_CODE (rhs) == SSA_NAME |
| 3614 |
|| is_gimple_min_invariant (rhs)) |
| 3615 |
&& !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def)) |
| 3616 |
{ |
| 3617 |
insert_decl_map (id, def, rhs); |
| 3618 |
return insert_init_debug_bind (id, bb, var, rhs, NULL); |
| 3619 |
} |
| 3620 |
|
| 3621 |
/* If the value of argument is never used, don't care about initializing |
| 3622 |
it. */ |
| 3623 |
if (optimize && gimple_in_ssa_p (cfun) && !def && is_gimple_reg (p)) |
| 3624 |
{ |
| 3625 |
/* When there's a gross type mismatch between the passed value |
| 3626 |
and the declared argument type drop it on the floor and do |
| 3627 |
not bother to insert a debug bind. */ |
| 3628 |
if (value && !is_gimple_reg_type (TREE_TYPE (value))) |
| 3629 |
return NULL; |
| 3630 |
return insert_init_debug_bind (id, bb, var, rhs, NULL); |
| 3631 |
} |
| 3632 |
|
| 3633 |
/* Initialize this VAR_DECL from the equivalent argument. Convert |
| 3634 |
the argument to the proper type in case it was promoted. */ |
| 3635 |
if (value) |
| 3636 |
{ |
| 3637 |
if (rhs == error_mark_node) |
| 3638 |
{ |
| 3639 |
insert_decl_map (id, p, var); |
| 3640 |
return insert_init_debug_bind (id, bb, var, rhs, NULL); |
| 3641 |
} |
| 3642 |
|
| 3643 |
STRIP_USELESS_TYPE_CONVERSION (rhs); |
| 3644 |
|
| 3645 |
/* If we are in SSA form properly remap the default definition. */ |
| 3646 |
if (gimple_in_ssa_p (cfun) && is_gimple_reg (p)) |
| 3647 |
{ |
| 3648 |
if (def) |
| 3649 |
{ |
| 3650 |
def = remap_ssa_name (def, id); |
| 3651 |
init_stmt = gimple_build_assign (def, rhs); |
| 3652 |
SSA_NAME_IS_DEFAULT_DEF (def) = 0; |
| 3653 |
set_ssa_default_def (cfun, var, NULL); |
| 3654 |
} |
| 3655 |
} |
| 3656 |
else if (!is_empty_type (TREE_TYPE (var))) |
| 3657 |
init_stmt = gimple_build_assign (var, rhs); |
| 3658 |
|
| 3659 |
if (bb && init_stmt) |
| 3660 |
insert_init_stmt (id, bb, init_stmt); |
| 3661 |
} |
| 3662 |
return init_stmt; |
| 3663 |
} |
| 3664 |
|
| 3665 |
/* Generate code to initialize the parameters of the function at the |
| 3666 |
top of the stack in ID from the GIMPLE_CALL STMT. */ |
| 3667 |
|
| 3668 |
static void |
| 3669 |
initialize_inlined_parameters (copy_body_data *id, gimple *stmt, |
| 3670 |
tree fn, basic_block bb) |
| 3671 |
{ |
| 3672 |
tree parms; |
| 3673 |
size_t i; |
| 3674 |
tree p; |
| 3675 |
tree vars = NULL_TREE; |
| 3676 |
tree static_chain = gimple_call_chain (stmt); |
| 3677 |
|
| 3678 |
/* Figure out what the parameters are. */ |
| 3679 |
parms = DECL_ARGUMENTS (fn); |
| 3680 |
|
| 3681 |
/* Loop through the parameter declarations, replacing each with an |
| 3682 |
equivalent VAR_DECL, appropriately initialized. */ |
| 3683 |
for (p = parms, i = 0; p; p = DECL_CHAIN (p), i++) |
| 3684 |
{ |
| 3685 |
tree val; |
| 3686 |
val = i < gimple_call_num_args (stmt) ? gimple_call_arg (stmt, i) : NULL; |
| 3687 |
setup_one_parameter (id, p, val, fn, bb, &vars); |
| 3688 |
} |
| 3689 |
/* After remapping parameters remap their types. This has to be done |
| 3690 |
in a second loop over all parameters to appropriately remap |
| 3691 |
variable sized arrays when the size is specified in a |
| 3692 |
parameter following the array. */ |
| 3693 |
for (p = parms, i = 0; p; p = DECL_CHAIN (p), i++) |
| 3694 |
{ |
| 3695 |
tree *varp = id->decl_map->get (p); |
| 3696 |
if (varp && VAR_P (*varp)) |
| 3697 |
{ |
| 3698 |
tree def = (gimple_in_ssa_p (cfun) && is_gimple_reg (p) |
| 3699 |
? ssa_default_def (id->src_cfun, p) : NULL); |
| 3700 |
tree var = *varp; |
| 3701 |
TREE_TYPE (var) = remap_type (TREE_TYPE (var), id); |
| 3702 |
/* Also remap the default definition if it was remapped |
| 3703 |
to the default definition of the parameter replacement |
| 3704 |
by the parameter setup. */ |
| 3705 |
if (def) |
| 3706 |
{ |
| 3707 |
tree *defp = id->decl_map->get (def); |
| 3708 |
if (defp |
| 3709 |
&& TREE_CODE (*defp) == SSA_NAME |
| 3710 |
&& SSA_NAME_VAR (*defp) == var) |
| 3711 |
TREE_TYPE (*defp) = TREE_TYPE (var); |
| 3712 |
} |
| 3713 |
/* When not optimizing and the parameter is unused, assign to |
| 3714 |
a dummy SSA name. Do this after remapping the type above. */ |
| 3715 |
else if (!optimize |
| 3716 |
&& is_gimple_reg (p) |
| 3717 |
&& i < gimple_call_num_args (stmt)) |
| 3718 |
{ |
| 3719 |
tree val = gimple_call_arg (stmt, i); |
| 3720 |
if (val != error_mark_node) |
| 3721 |
{ |
| 3722 |
if (!useless_type_conversion_p (TREE_TYPE (p), |
| 3723 |
TREE_TYPE (val))) |
| 3724 |
val = force_value_to_type (TREE_TYPE (p), val); |
| 3725 |
def = make_ssa_name (var); |
| 3726 |
gimple *init_stmt = gimple_build_assign (def, val); |
| 3727 |
insert_init_stmt (id, bb, init_stmt); |
| 3728 |
} |
| 3729 |
} |
| 3730 |
} |
| 3731 |
} |
| 3732 |
|
| 3733 |
/* Initialize the static chain. */ |
| 3734 |
p = DECL_STRUCT_FUNCTION (fn)->static_chain_decl; |
| 3735 |
gcc_assert (fn != current_function_decl); |
| 3736 |
if (p) |
| 3737 |
{ |
| 3738 |
/* No static chain? Seems like a bug in tree-nested.cc. */ |
| 3739 |
gcc_assert (static_chain); |
| 3740 |
|
| 3741 |
setup_one_parameter (id, p, static_chain, fn, bb, &vars); |
| 3742 |
} |
| 3743 |
|
| 3744 |
/* Reverse so the variables appear in the correct order in DWARF |
| 3745 |
debug info. */ |
| 3746 |
vars = nreverse (vars); |
| 3747 |
|
| 3748 |
declare_inline_vars (id->block, vars); |
| 3749 |
} |
| 3750 |
|
| 3751 |
|
| 3752 |
/* Declare a return variable to replace the RESULT_DECL for the |
| 3753 |
function we are calling. An appropriate DECL_STMT is returned. |
| 3754 |
The USE_STMT is filled to contain a use of the declaration to |
| 3755 |
indicate the return value of the function. |
| 3756 |
|
| 3757 |
RETURN_SLOT, if non-null is place where to store the result. It |
| 3758 |
is set only for CALL_EXPR_RETURN_SLOT_OPT. MODIFY_DEST, if non-null, |
| 3759 |
was the LHS of the MODIFY_EXPR to which this call is the RHS. |
| 3760 |
|
| 3761 |
The return value is a (possibly null) value that holds the result |
| 3762 |
as seen by the caller. */ |
| 3763 |
|
| 3764 |
static tree |
| 3765 |
declare_return_variable (copy_body_data *id, tree return_slot, tree modify_dest, |
| 3766 |
basic_block entry_bb) |
| 3767 |
{ |
| 3768 |
tree callee = id->src_fn; |
| 3769 |
tree result = DECL_RESULT (callee); |
| 3770 |
tree callee_type = TREE_TYPE (result); |
| 3771 |
tree caller_type; |
| 3772 |
tree var, use; |
| 3773 |
|
| 3774 |
/* Handle type-mismatches in the function declaration return type |
| 3775 |
vs. the call expression. */ |
| 3776 |
if (modify_dest) |
| 3777 |
caller_type = TREE_TYPE (modify_dest); |
| 3778 |
else if (return_slot) |
| 3779 |
caller_type = TREE_TYPE (return_slot); |
| 3780 |
else /* No LHS on the call. */ |
| 3781 |
caller_type = TREE_TYPE (TREE_TYPE (callee)); |
| 3782 |
|
| 3783 |
/* We don't need to do anything for functions that don't return anything. */ |
| 3784 |
if (VOID_TYPE_P (callee_type)) |
| 3785 |
return NULL_TREE; |
| 3786 |
|
| 3787 |
/* If there was a return slot, then the return value is the |
| 3788 |
dereferenced address of that object. */ |
| 3789 |
if (return_slot) |
| 3790 |
{ |
| 3791 |
/* The front end shouldn't have used both return_slot and |
| 3792 |
a modify expression. */ |
| 3793 |
gcc_assert (!modify_dest); |
| 3794 |
if (DECL_BY_REFERENCE (result)) |
| 3795 |
{ |
| 3796 |
tree return_slot_addr = build_fold_addr_expr (return_slot); |
| 3797 |
STRIP_USELESS_TYPE_CONVERSION (return_slot_addr); |
| 3798 |
|
| 3799 |
/* We are going to construct *&return_slot and we can't do that |
| 3800 |
for variables believed to be not addressable. |
| 3801 |
|
| 3802 |
FIXME: This check possibly can match, because values returned |
| 3803 |
via return slot optimization are not believed to have address |
| 3804 |
taken by alias analysis. */ |
| 3805 |
gcc_assert (TREE_CODE (return_slot) != SSA_NAME); |
| 3806 |
var = return_slot_addr; |
| 3807 |
mark_addressable (return_slot); |
| 3808 |
} |
| 3809 |
else |
| 3810 |
{ |
| 3811 |
var = return_slot; |
| 3812 |
gcc_assert (TREE_CODE (var) != SSA_NAME); |
| 3813 |
if (TREE_ADDRESSABLE (result)) |
| 3814 |
mark_addressable (var); |
| 3815 |
} |
| 3816 |
if (DECL_NOT_GIMPLE_REG_P (result) |
| 3817 |
&& DECL_P (var)) |
| 3818 |
DECL_NOT_GIMPLE_REG_P (var) = 1; |
| 3819 |
|
| 3820 |
if (!useless_type_conversion_p (callee_type, caller_type)) |
| 3821 |
var = build1 (VIEW_CONVERT_EXPR, callee_type, var); |
| 3822 |
|
| 3823 |
use = NULL; |
| 3824 |
goto done; |
| 3825 |
} |
| 3826 |
|
| 3827 |
/* All types requiring non-trivial constructors should have been handled. */ |
| 3828 |
gcc_assert (!TREE_ADDRESSABLE (callee_type)); |
| 3829 |
|
| 3830 |
/* Attempt to avoid creating a new temporary variable. */ |
| 3831 |
if (modify_dest |
| 3832 |
&& TREE_CODE (modify_dest) != SSA_NAME) |
| 3833 |
{ |
| 3834 |
bool use_it = false; |
| 3835 |
|
| 3836 |
/* We can't use MODIFY_DEST if there's type promotion involved. */ |
| 3837 |
if (!useless_type_conversion_p (callee_type, caller_type)) |
| 3838 |
use_it = false; |
| 3839 |
|
| 3840 |
/* ??? If we're assigning to a variable sized type, then we must |
| 3841 |
reuse the destination variable, because we've no good way to |
| 3842 |
create variable sized temporaries at this point. */ |
| 3843 |
else if (!poly_int_tree_p (TYPE_SIZE_UNIT (caller_type))) |
| 3844 |
use_it = true; |
| 3845 |
|
| 3846 |
/* If the callee cannot possibly modify MODIFY_DEST, then we can |
| 3847 |
reuse it as the result of the call directly. Don't do this if |
| 3848 |
it would promote MODIFY_DEST to addressable. */ |
| 3849 |
else if (TREE_ADDRESSABLE (result)) |
| 3850 |
use_it = false; |
| 3851 |
else |
| 3852 |
{ |
| 3853 |
tree base_m = get_base_address (modify_dest); |
| 3854 |
|
| 3855 |
/* If the base isn't a decl, then it's a pointer, and we don't |
| 3856 |
know where that's going to go. */ |
| 3857 |
if (!DECL_P (base_m)) |
| 3858 |
use_it = false; |
| 3859 |
else if (is_global_var (base_m)) |
| 3860 |
use_it = false; |
| 3861 |
else if (DECL_NOT_GIMPLE_REG_P (result) |
| 3862 |
&& !DECL_NOT_GIMPLE_REG_P (base_m)) |
| 3863 |
use_it = false; |
| 3864 |
else if (!TREE_ADDRESSABLE (base_m)) |
| 3865 |
use_it = true; |
| 3866 |
} |
| 3867 |
|
| 3868 |
if (use_it) |
| 3869 |
{ |
| 3870 |
var = modify_dest; |
| 3871 |
use = NULL; |
| 3872 |
goto done; |
| 3873 |
} |
| 3874 |
} |
| 3875 |
|
| 3876 |
gcc_assert (poly_int_tree_p (TYPE_SIZE_UNIT (callee_type))); |
| 3877 |
|
| 3878 |
var = copy_result_decl_to_var (result, id); |
| 3879 |
DECL_SEEN_IN_BIND_EXPR_P (var) = 1; |
| 3880 |
|
| 3881 |
/* Do not have the rest of GCC warn about this variable as it should |
| 3882 |
not be visible to the user. */ |
| 3883 |
suppress_warning (var /* OPT_Wuninitialized? */); |
| 3884 |
|
| 3885 |
declare_inline_vars (id->block, var); |
| 3886 |
|
| 3887 |
/* Build the use expr. If the return type of the function was |
| 3888 |
promoted, convert it back to the expected type. */ |
| 3889 |
use = var; |
| 3890 |
if (!useless_type_conversion_p (caller_type, TREE_TYPE (var))) |
| 3891 |
{ |
| 3892 |
/* If we can match up types by promotion/demotion do so. */ |
| 3893 |
if (fold_convertible_p (caller_type, var)) |
| 3894 |
use = fold_convert (caller_type, var); |
| 3895 |
else |
| 3896 |
{ |
| 3897 |
/* ??? For valid programs we should not end up here. |
| 3898 |
Still if we end up with truly mismatched types here, fall back |
| 3899 |
to using a MEM_REF to not leak invalid GIMPLE to the following |
| 3900 |
passes. */ |
| 3901 |
/* Prevent var from being written into SSA form. */ |
| 3902 |
if (is_gimple_reg_type (TREE_TYPE (var))) |
| 3903 |
DECL_NOT_GIMPLE_REG_P (var) = true; |
| 3904 |
use = fold_build2 (MEM_REF, caller_type, |
| 3905 |
build_fold_addr_expr (var), |
| 3906 |
build_int_cst (ptr_type_node, 0)); |
| 3907 |
} |
| 3908 |
} |
| 3909 |
|
| 3910 |
STRIP_USELESS_TYPE_CONVERSION (use); |
| 3911 |
|
| 3912 |
if (DECL_BY_REFERENCE (result)) |
| 3913 |
{ |
| 3914 |
TREE_ADDRESSABLE (var) = 1; |
| 3915 |
var = build_fold_addr_expr (var); |
| 3916 |
} |
| 3917 |
|
| 3918 |
done: |
| 3919 |
/* Register the VAR_DECL as the equivalent for the RESULT_DECL; that |
| 3920 |
way, when the RESULT_DECL is encountered, it will be |
| 3921 |
automatically replaced by the VAR_DECL. |
| 3922 |
|
| 3923 |
When returning by reference, ensure that RESULT_DECL remaps to |
| 3924 |
gimple_val. */ |
| 3925 |
if (DECL_BY_REFERENCE (result) |
| 3926 |
&& !is_gimple_val (var)) |
| 3927 |
{ |
| 3928 |
tree temp = create_tmp_var (TREE_TYPE (result), "retvalptr"); |
| 3929 |
insert_decl_map (id, result, temp); |
| 3930 |
/* When RESULT_DECL is in SSA form, we need to remap and initialize |
| 3931 |
it's default_def SSA_NAME. */ |
| 3932 |
if (gimple_in_ssa_p (id->src_cfun) |
| 3933 |
&& is_gimple_reg (result)) |
| 3934 |
if (tree default_def = ssa_default_def (id->src_cfun, result)) |
| 3935 |
{ |
| 3936 |
temp = make_ssa_name (temp); |
| 3937 |
insert_decl_map (id, default_def, temp); |
| 3938 |
} |
| 3939 |
insert_init_stmt (id, entry_bb, gimple_build_assign (temp, var)); |
| 3940 |
} |
| 3941 |
else |
| 3942 |
insert_decl_map (id, result, var); |
| 3943 |
|
| 3944 |
/* Remember this so we can ignore it in remap_decls. */ |
| 3945 |
id->retvar = var; |
| 3946 |
return use; |
| 3947 |
} |
| 3948 |
|
| 3949 |
/* Determine if the function can be copied. If so return NULL. If |
| 3950 |
not return a string describng the reason for failure. */ |
| 3951 |
|
| 3952 |
const char * |
| 3953 |
copy_forbidden (struct function *fun) |
| 3954 |
{ |
| 3955 |
const char *reason = fun->cannot_be_copied_reason; |
| 3956 |
|
| 3957 |
/* Only examine the function once. */ |
| 3958 |
if (fun->cannot_be_copied_set) |
| 3959 |
return reason; |
| 3960 |
|
| 3961 |
/* We cannot copy a function that receives a non-local goto |
| 3962 |
because we cannot remap the destination label used in the |
| 3963 |
function that is performing the non-local goto. */ |
| 3964 |
/* ??? Actually, this should be possible, if we work at it. |
| 3965 |
No doubt there's just a handful of places that simply |
| 3966 |
assume it doesn't happen and don't substitute properly. */ |
| 3967 |
if (fun->has_nonlocal_label) |
| 3968 |
{ |
| 3969 |
reason = G_("function %q+F can never be copied " |
| 3970 |
"because it receives a non-local goto"); |
| 3971 |
goto fail; |
| 3972 |
} |
| 3973 |
|
| 3974 |
if (fun->has_forced_label_in_static) |
| 3975 |
{ |
| 3976 |
reason = G_("function %q+F can never be copied because it saves " |
| 3977 |
"address of local label in a static variable"); |
| 3978 |
goto fail; |
| 3979 |
} |
| 3980 |
|
| 3981 |
fail: |
| 3982 |
fun->cannot_be_copied_reason = reason; |
| 3983 |
fun->cannot_be_copied_set = true; |
| 3984 |
return reason; |
| 3985 |
} |
| 3986 |
|
| 3987 |
|
| 3988 |
static const char *inline_forbidden_reason; |
| 3989 |
|
| 3990 |
/* A callback for walk_gimple_seq to handle statements. Returns non-null |
| 3991 |
iff a function cannot be inlined. Also sets the reason why. */ |
| 3992 |
|
| 3993 |
static tree |
| 3994 |
inline_forbidden_p_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p, |
| 3995 |
struct walk_stmt_info *wip) |
| 3996 |
{ |
| 3997 |
tree fn = (tree) wip->info; |
| 3998 |
tree t; |
| 3999 |
gimple *stmt = gsi_stmt (*gsi); |
| 4000 |
|
| 4001 |
switch (gimple_code (stmt)) |
| 4002 |
{ |
| 4003 |
case GIMPLE_CALL: |
| 4004 |
/* Refuse to inline alloca call unless user explicitly forced so as |
| 4005 |
this may change program's memory overhead drastically when the |
| 4006 |
function using alloca is called in loop. In GCC present in |
| 4007 |
SPEC2000 inlining into schedule_block cause it to require 2GB of |
| 4008 |
RAM instead of 256MB. Don't do so for alloca calls emitted for |
| 4009 |
VLA objects as those can't cause unbounded growth (they're always |
| 4010 |
wrapped inside stack_save/stack_restore regions. */ |
| 4011 |
if (gimple_maybe_alloca_call_p (stmt) |
| 4012 |
&& !gimple_call_alloca_for_var_p (as_a <gcall *> (stmt)) |
| 4013 |
&& !lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn))) |
| 4014 |
{ |
| 4015 |
inline_forbidden_reason |
| 4016 |
= G_("function %q+F can never be inlined because it uses " |
| 4017 |
"alloca (override using the always_inline attribute)"); |
| 4018 |
*handled_ops_p = true; |
| 4019 |
return fn; |
| 4020 |
} |
| 4021 |
|
| 4022 |
t = gimple_call_fndecl (stmt); |
| 4023 |
if (t == NULL_TREE) |
| 4024 |
break; |
| 4025 |
|
| 4026 |
/* We cannot inline functions that call setjmp. */ |
| 4027 |
if (setjmp_call_p (t)) |
| 4028 |
{ |
| 4029 |
inline_forbidden_reason |
| 4030 |
= G_("function %q+F can never be inlined because it uses setjmp"); |
| 4031 |
*handled_ops_p = true; |
| 4032 |
return t; |
| 4033 |
} |
| 4034 |
|
| 4035 |
if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL) |
| 4036 |
switch (DECL_FUNCTION_CODE (t)) |
| 4037 |
{ |
| 4038 |
/* We cannot inline functions that take a variable number of |
| 4039 |
arguments. */ |
| 4040 |
case BUILT_IN_VA_START: |
| 4041 |
case BUILT_IN_NEXT_ARG: |
| 4042 |
case BUILT_IN_VA_END: |
| 4043 |
inline_forbidden_reason |
| 4044 |
= G_("function %q+F can never be inlined because it " |
| 4045 |
"uses variable argument lists"); |
| 4046 |
*handled_ops_p = true; |
| 4047 |
return t; |
| 4048 |
|
| 4049 |
case BUILT_IN_LONGJMP: |
| 4050 |
/* We can't inline functions that call __builtin_longjmp at |
| 4051 |
all. The non-local goto machinery really requires the |
| 4052 |
destination be in a different function. If we allow the |
| 4053 |
function calling __builtin_longjmp to be inlined into the |
| 4054 |
function calling __builtin_setjmp, Things will Go Awry. */ |
| 4055 |
inline_forbidden_reason |
| 4056 |
= G_("function %q+F can never be inlined because " |
| 4057 |
"it uses setjmp-longjmp exception handling"); |
| 4058 |
*handled_ops_p = true; |
| 4059 |
return t; |
| 4060 |
|
| 4061 |
case BUILT_IN_NONLOCAL_GOTO: |
| 4062 |
/* Similarly. */ |
| 4063 |
inline_forbidden_reason |
| 4064 |
= G_("function %q+F can never be inlined because " |
| 4065 |
"it uses non-local goto"); |
| 4066 |
*handled_ops_p = true; |
| 4067 |
return t; |
| 4068 |
|
| 4069 |
case BUILT_IN_RETURN: |
| 4070 |
case BUILT_IN_APPLY_ARGS: |
| 4071 |
/* If a __builtin_apply_args caller would be inlined, |
| 4072 |
it would be saving arguments of the function it has |
| 4073 |
been inlined into. Similarly __builtin_return would |
| 4074 |
return from the function the inline has been inlined into. */ |
| 4075 |
inline_forbidden_reason |
| 4076 |
= G_("function %q+F can never be inlined because " |
| 4077 |
"it uses %<__builtin_return%> or %<__builtin_apply_args%>"); |
| 4078 |
*handled_ops_p = true; |
| 4079 |
return t; |
| 4080 |
|
| 4081 |
default: |
| 4082 |
break; |
| 4083 |
} |
| 4084 |
break; |
| 4085 |
|
| 4086 |
case GIMPLE_GOTO: |
| 4087 |
t = gimple_goto_dest (stmt); |
| 4088 |
|
| 4089 |
/* We will not inline a function which uses computed goto. The |
| 4090 |
addresses of its local labels, which may be tucked into |
| 4091 |
global storage, are of course not constant across |
| 4092 |
instantiations, which causes unexpected behavior. */ |
| 4093 |
if (TREE_CODE (t) != LABEL_DECL) |
| 4094 |
{ |
| 4095 |
inline_forbidden_reason |
| 4096 |
= G_("function %q+F can never be inlined " |
| 4097 |
"because it contains a computed goto"); |
| 4098 |
*handled_ops_p = true; |
| 4099 |
return t; |
| 4100 |
} |
| 4101 |
break; |
| 4102 |
|
| 4103 |
default: |
| 4104 |
break; |
| 4105 |
} |
| 4106 |
|
| 4107 |
*handled_ops_p = false; |
| 4108 |
return NULL_TREE; |
| 4109 |
} |
| 4110 |
|
| 4111 |
/* Return true if FNDECL is a function that cannot be inlined into |
| 4112 |
another one. */ |
| 4113 |
|
| 4114 |
static bool |
| 4115 |
inline_forbidden_p (tree fndecl) |
| 4116 |
{ |
| 4117 |
struct function *fun = DECL_STRUCT_FUNCTION (fndecl); |
| 4118 |
struct walk_stmt_info wi; |
| 4119 |
basic_block bb; |
| 4120 |
bool forbidden_p = false; |
| 4121 |
|
| 4122 |
/* First check for shared reasons not to copy the code. */ |
| 4123 |
inline_forbidden_reason = copy_forbidden (fun); |
| 4124 |
if (inline_forbidden_reason != NULL) |
| 4125 |
return true; |
| 4126 |
|
| 4127 |
/* Next, walk the statements of the function looking for |
| 4128 |
constraucts we can't handle, or are non-optimal for inlining. */ |
| 4129 |
hash_set<tree> visited_nodes; |
| 4130 |
memset (&wi, 0, sizeof (wi)); |
| 4131 |
wi.info = (void *) fndecl; |
| 4132 |
wi.pset = &visited_nodes; |
| 4133 |
|
| 4134 |
/* We cannot inline a function with a variable-sized parameter because we |
| 4135 |
cannot materialize a temporary of such a type in the caller if need be. |
| 4136 |
Note that the return case is not symmetrical because we can guarantee |
| 4137 |
that a temporary is not needed by means of CALL_EXPR_RETURN_SLOT_OPT. */ |
| 4138 |
for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm)) |
| 4139 |
if (!poly_int_tree_p (DECL_SIZE (parm))) |
| 4140 |
{ |
| 4141 |
inline_forbidden_reason |
| 4142 |
= G_("function %q+F can never be inlined because " |
| 4143 |
"it has a VLA argument"); |
| 4144 |
return true; |
| 4145 |
} |
| 4146 |
|
| 4147 |
FOR_EACH_BB_FN (bb, fun) |
| 4148 |
{ |
| 4149 |
gimple *ret; |
| 4150 |
gimple_seq seq = bb_seq (bb); |
| 4151 |
ret = walk_gimple_seq (seq, inline_forbidden_p_stmt, NULL, &wi); |
| 4152 |
forbidden_p = (ret != NULL); |
| 4153 |
if (forbidden_p) |
| 4154 |
break; |
| 4155 |
} |
| 4156 |
|
| 4157 |
return forbidden_p; |
| 4158 |
} |
| 4159 |
|
| 4160 |
/* Return false if the function FNDECL cannot be inlined on account of its |
| 4161 |
attributes, true otherwise. */ |
| 4162 |
static bool |
| 4163 |
function_attribute_inlinable_p (const_tree fndecl) |
| 4164 |
{ |
| 4165 |
for (auto scoped_attributes : targetm.attribute_table) |
| 4166 |
{ |
| 4167 |
const_tree a; |
| 4168 |
|
| 4169 |
for (a = DECL_ATTRIBUTES (fndecl); a; a = TREE_CHAIN (a)) |
| 4170 |
{ |
| 4171 |
const_tree name = get_attribute_name (a); |
| 4172 |
|
| 4173 |
for (const attribute_spec &attribute : scoped_attributes->attributes) |
| 4174 |
if (is_attribute_p (attribute.name, name)) |
| 4175 |
return targetm.function_attribute_inlinable_p (fndecl); |
| 4176 |
} |
| 4177 |
} |
| 4178 |
|
| 4179 |
return true; |
| 4180 |
} |
| 4181 |
|
| 4182 |
/* Returns nonzero if FN is a function that does not have any |
| 4183 |
fundamental inline blocking properties. */ |
| 4184 |
|
| 4185 |
bool |
| 4186 |
tree_inlinable_function_p (tree fn) |
| 4187 |
{ |
| 4188 |
bool inlinable = true; |
| 4189 |
bool do_warning; |
| 4190 |
tree always_inline; |
| 4191 |
|
| 4192 |
/* If we've already decided this function shouldn't be inlined, |
| 4193 |
there's no need to check again. */ |
| 4194 |
if (DECL_UNINLINABLE (fn)) |
| 4195 |
return false; |
| 4196 |
|
| 4197 |
/* We only warn for functions declared `inline' by the user. */ |
| 4198 |
do_warning = (opt_for_fn (fn, warn_inline) |
| 4199 |
&& DECL_DECLARED_INLINE_P (fn) |
| 4200 |
&& !DECL_NO_INLINE_WARNING_P (fn) |
| 4201 |
&& !DECL_IN_SYSTEM_HEADER (fn)); |
| 4202 |
|
| 4203 |
always_inline = lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)); |
| 4204 |
|
| 4205 |
if (flag_no_inline |
| 4206 |
&& always_inline == NULL) |
| 4207 |
{ |
| 4208 |
if (do_warning) |
| 4209 |
warning (OPT_Winline, "function %q+F can never be inlined because it " |
| 4210 |
"is suppressed using %<-fno-inline%>", fn); |
| 4211 |
inlinable = false; |
| 4212 |
} |
| 4213 |
|
| 4214 |
else if (!function_attribute_inlinable_p (fn)) |
| 4215 |
{ |
| 4216 |
if (do_warning) |
| 4217 |
warning (OPT_Winline, "function %q+F can never be inlined because it " |
| 4218 |
"uses attributes conflicting with inlining", fn); |
| 4219 |
inlinable = false; |
| 4220 |
} |
| 4221 |
|
| 4222 |
else if (inline_forbidden_p (fn)) |
| 4223 |
{ |
| 4224 |
/* See if we should warn about uninlinable functions. Previously, |
| 4225 |
some of these warnings would be issued while trying to expand |
| 4226 |
the function inline, but that would cause multiple warnings |
| 4227 |
about functions that would for example call alloca. But since |
| 4228 |
this a property of the function, just one warning is enough. |
| 4229 |
As a bonus we can now give more details about the reason why a |
| 4230 |
function is not inlinable. */ |
| 4231 |
if (always_inline) |
| 4232 |
error (inline_forbidden_reason, fn); |
| 4233 |
else if (do_warning) |
| 4234 |
warning (OPT_Winline, inline_forbidden_reason, fn); |
| 4235 |
|
| 4236 |
inlinable = false; |
| 4237 |
} |
| 4238 |
|
| 4239 |
/* Squirrel away the result so that we don't have to check again. */ |
| 4240 |
DECL_UNINLINABLE (fn) = !inlinable; |
| 4241 |
|
| 4242 |
return inlinable; |
| 4243 |
} |
| 4244 |
|
| 4245 |
/* Estimate the cost of a memory move of type TYPE. Use machine dependent |
| 4246 |
word size and take possible memcpy call into account and return |
| 4247 |
cost based on whether optimizing for size or speed according to SPEED_P. */ |
| 4248 |
|
| 4249 |
int |
| 4250 |
estimate_move_cost (tree type, bool ARG_UNUSED (speed_p)) |
| 4251 |
{ |
| 4252 |
HOST_WIDE_INT size; |
| 4253 |
|
| 4254 |
gcc_assert (!VOID_TYPE_P (type)); |
| 4255 |
|
| 4256 |
if (VECTOR_TYPE_P (type)) |
| 4257 |
{ |
| 4258 |
scalar_mode inner = SCALAR_TYPE_MODE (TREE_TYPE (type)); |
| 4259 |
machine_mode simd = targetm.vectorize.preferred_simd_mode (inner); |
| 4260 |
int orig_mode_size |
| 4261 |
= estimated_poly_value (GET_MODE_SIZE (TYPE_MODE (type))); |
| 4262 |
int simd_mode_size = estimated_poly_value (GET_MODE_SIZE (simd)); |
| 4263 |
return ((orig_mode_size + simd_mode_size - 1) |
| 4264 |
/ simd_mode_size); |
| 4265 |
} |
| 4266 |
|
| 4267 |
size = int_size_in_bytes (type); |
| 4268 |
|
| 4269 |
if (size < 0 || size > MOVE_MAX_PIECES * MOVE_RATIO (speed_p)) |
| 4270 |
/* Cost of a memcpy call, 3 arguments and the call. */ |
| 4271 |
return 4; |
| 4272 |
else |
| 4273 |
return ((size + MOVE_MAX_PIECES - 1) / MOVE_MAX_PIECES); |
| 4274 |
} |
| 4275 |
|
| 4276 |
/* Returns cost of operation CODE, according to WEIGHTS */ |
| 4277 |
|
| 4278 |
static int |
| 4279 |
estimate_operator_cost (enum tree_code code, eni_weights *weights, |
| 4280 |
tree op1 ATTRIBUTE_UNUSED, tree op2) |
| 4281 |
{ |
| 4282 |
switch (code) |
| 4283 |
{ |
| 4284 |
/* These are "free" conversions, or their presumed cost |
| 4285 |
is folded into other operations. */ |
| 4286 |
case RANGE_EXPR: |
| 4287 |
CASE_CONVERT: |
| 4288 |
case COMPLEX_EXPR: |
| 4289 |
case PAREN_EXPR: |
| 4290 |
case VIEW_CONVERT_EXPR: |
| 4291 |
return 0; |
| 4292 |
|
| 4293 |
/* Assign cost of 1 to usual operations. |
| 4294 |
??? We may consider mapping RTL costs to this. */ |
| 4295 |
case COND_EXPR: |
| 4296 |
case VEC_COND_EXPR: |
| 4297 |
case VEC_PERM_EXPR: |
| 4298 |
|
| 4299 |
case PLUS_EXPR: |
| 4300 |
case POINTER_PLUS_EXPR: |
| 4301 |
case POINTER_DIFF_EXPR: |
| 4302 |
case MINUS_EXPR: |
| 4303 |
case MULT_EXPR: |
| 4304 |
case MULT_HIGHPART_EXPR: |
| 4305 |
|
| 4306 |
case ADDR_SPACE_CONVERT_EXPR: |
| 4307 |
case FIXED_CONVERT_EXPR: |
| 4308 |
case FIX_TRUNC_EXPR: |
| 4309 |
|
| 4310 |
case NEGATE_EXPR: |
| 4311 |
case FLOAT_EXPR: |
| 4312 |
case MIN_EXPR: |
| 4313 |
case MAX_EXPR: |
| 4314 |
case ABS_EXPR: |
| 4315 |
case ABSU_EXPR: |
| 4316 |
|
| 4317 |
case LSHIFT_EXPR: |
| 4318 |
case RSHIFT_EXPR: |
| 4319 |
case LROTATE_EXPR: |
| 4320 |
case RROTATE_EXPR: |
| 4321 |
|
| 4322 |
case BIT_IOR_EXPR: |
| 4323 |
case BIT_XOR_EXPR: |
| 4324 |
case BIT_AND_EXPR: |
| 4325 |
case BIT_NOT_EXPR: |
| 4326 |
|
| 4327 |
case TRUTH_ANDIF_EXPR: |
| 4328 |
case TRUTH_ORIF_EXPR: |
| 4329 |
case TRUTH_AND_EXPR: |
| 4330 |
case TRUTH_OR_EXPR: |
| 4331 |
case TRUTH_XOR_EXPR: |
| 4332 |
case TRUTH_NOT_EXPR: |
| 4333 |
|
| 4334 |
case LT_EXPR: |
| 4335 |
case LE_EXPR: |
| 4336 |
case GT_EXPR: |
| 4337 |
case GE_EXPR: |
| 4338 |
case EQ_EXPR: |
| 4339 |
case NE_EXPR: |
| 4340 |
case ORDERED_EXPR: |
| 4341 |
case UNORDERED_EXPR: |
| 4342 |
|
| 4343 |
case UNLT_EXPR: |
| 4344 |
case UNLE_EXPR: |
| 4345 |
case UNGT_EXPR: |
| 4346 |
case UNGE_EXPR: |
| 4347 |
case UNEQ_EXPR: |
| 4348 |
case LTGT_EXPR: |
| 4349 |
|
| 4350 |
case CONJ_EXPR: |
| 4351 |
|
| 4352 |
case PREDECREMENT_EXPR: |
| 4353 |
case PREINCREMENT_EXPR: |
| 4354 |
case POSTDECREMENT_EXPR: |
| 4355 |
case POSTINCREMENT_EXPR: |
| 4356 |
|
| 4357 |
case REALIGN_LOAD_EXPR: |
| 4358 |
|
| 4359 |
case WIDEN_SUM_EXPR: |
| 4360 |
case WIDEN_MULT_EXPR: |
| 4361 |
case DOT_PROD_EXPR: |
| 4362 |
case SAD_EXPR: |
| 4363 |
case WIDEN_MULT_PLUS_EXPR: |
| 4364 |
case WIDEN_MULT_MINUS_EXPR: |
| 4365 |
case WIDEN_LSHIFT_EXPR: |
| 4366 |
|
| 4367 |
case VEC_WIDEN_MULT_HI_EXPR: |
| 4368 |
case VEC_WIDEN_MULT_LO_EXPR: |
| 4369 |
case VEC_WIDEN_MULT_EVEN_EXPR: |
| 4370 |
case VEC_WIDEN_MULT_ODD_EXPR: |
| 4371 |
case VEC_UNPACK_HI_EXPR: |
| 4372 |
case VEC_UNPACK_LO_EXPR: |
| 4373 |
case VEC_UNPACK_FLOAT_HI_EXPR: |
| 4374 |
case VEC_UNPACK_FLOAT_LO_EXPR: |
| 4375 |
case VEC_UNPACK_FIX_TRUNC_HI_EXPR: |
| 4376 |
case VEC_UNPACK_FIX_TRUNC_LO_EXPR: |
| 4377 |
case VEC_PACK_TRUNC_EXPR: |
| 4378 |
case VEC_PACK_SAT_EXPR: |
| 4379 |
case VEC_PACK_FIX_TRUNC_EXPR: |
| 4380 |
case VEC_PACK_FLOAT_EXPR: |
| 4381 |
case VEC_WIDEN_LSHIFT_HI_EXPR: |
| 4382 |
case VEC_WIDEN_LSHIFT_LO_EXPR: |
| 4383 |
case VEC_DUPLICATE_EXPR: |
| 4384 |
case VEC_SERIES_EXPR: |
| 4385 |
|
| 4386 |
return 1; |
| 4387 |
|
| 4388 |
/* Few special cases of expensive operations. This is useful |
| 4389 |
to avoid inlining on functions having too many of these. */ |
| 4390 |
case TRUNC_DIV_EXPR: |
| 4391 |
case CEIL_DIV_EXPR: |
| 4392 |
case FLOOR_DIV_EXPR: |
| 4393 |
case ROUND_DIV_EXPR: |
| 4394 |
case EXACT_DIV_EXPR: |
| 4395 |
case TRUNC_MOD_EXPR: |
| 4396 |
case CEIL_MOD_EXPR: |
| 4397 |
case FLOOR_MOD_EXPR: |
| 4398 |
case ROUND_MOD_EXPR: |
| 4399 |
case RDIV_EXPR: |
| 4400 |
if (TREE_CODE (op2) != INTEGER_CST) |
| 4401 |
return weights->div_mod_cost; |
| 4402 |
return 1; |
| 4403 |
|
| 4404 |
/* Bit-field insertion needs several shift and mask operations. */ |
| 4405 |
case BIT_INSERT_EXPR: |
| 4406 |
return 3; |
| 4407 |
|
| 4408 |
default: |
| 4409 |
/* We expect a copy assignment with no operator. */ |
| 4410 |
gcc_assert (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS); |
| 4411 |
return 0; |
| 4412 |
} |
| 4413 |
} |
| 4414 |
|
| 4415 |
|
| 4416 |
/* Estimate number of instructions that will be created by expanding |
| 4417 |
the statements in the statement sequence STMTS. |
| 4418 |
WEIGHTS contains weights attributed to various constructs. */ |
| 4419 |
|
| 4420 |
int |
| 4421 |
estimate_num_insns_seq (gimple_seq stmts, eni_weights *weights) |
| 4422 |
{ |
| 4423 |
int cost; |
| 4424 |
gimple_stmt_iterator gsi; |
| 4425 |
|
| 4426 |
cost = 0; |
| 4427 |
for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi)) |
| 4428 |
cost += estimate_num_insns (gsi_stmt (gsi), weights); |
| 4429 |
|
| 4430 |
return cost; |
| 4431 |
} |
| 4432 |
|
| 4433 |
|
| 4434 |
/* Estimate number of instructions that will be created by expanding STMT. |
| 4435 |
WEIGHTS contains weights attributed to various constructs. */ |
| 4436 |
|
| 4437 |
int |
| 4438 |
estimate_num_insns (gimple *stmt, eni_weights *weights) |
| 4439 |
{ |
| 4440 |
unsigned cost, i; |
| 4441 |
enum gimple_code code = gimple_code (stmt); |
| 4442 |
tree lhs; |
| 4443 |
tree rhs; |
| 4444 |
|
| 4445 |
switch (code) |
| 4446 |
{ |
| 4447 |
case GIMPLE_ASSIGN: |
| 4448 |
/* Try to estimate the cost of assignments. We have three cases to |
| 4449 |
deal with: |
| 4450 |
1) Simple assignments to registers; |
| 4451 |
2) Stores to things that must live in memory. This includes |
| 4452 |
"normal" stores to scalars, but also assignments of large |
| 4453 |
structures, or constructors of big arrays; |
| 4454 |
|
| 4455 |
Let us look at the first two cases, assuming we have "a = b + C": |
| 4456 |
<GIMPLE_ASSIGN <var_decl "a"> |
| 4457 |
<plus_expr <var_decl "b"> <constant C>> |
| 4458 |
If "a" is a GIMPLE register, the assignment to it is free on almost |
| 4459 |
any target, because "a" usually ends up in a real register. Hence |
| 4460 |
the only cost of this expression comes from the PLUS_EXPR, and we |
| 4461 |
can ignore the GIMPLE_ASSIGN. |
| 4462 |
If "a" is not a GIMPLE register, the assignment to "a" will most |
| 4463 |
likely be a real store, so the cost of the GIMPLE_ASSIGN is the cost |
| 4464 |
of moving something into "a", which we compute using the function |
| 4465 |
estimate_move_cost. */ |
| 4466 |
if (gimple_clobber_p (stmt)) |
| 4467 |
return 0; /* ={v} {CLOBBER} stmt expands to nothing. */ |
| 4468 |
|
| 4469 |
lhs = gimple_assign_lhs (stmt); |
| 4470 |
rhs = gimple_assign_rhs1 (stmt); |
| 4471 |
|
| 4472 |
cost = 0; |
| 4473 |
|
| 4474 |
/* Account for the cost of moving to / from memory. */ |
| 4475 |
if (gimple_store_p (stmt)) |
| 4476 |
cost += estimate_move_cost (TREE_TYPE (lhs), weights->time_based); |
| 4477 |
if (gimple_assign_load_p (stmt)) |
| 4478 |
cost += estimate_move_cost (TREE_TYPE (rhs), weights->time_based); |
| 4479 |
|
| 4480 |
cost += estimate_operator_cost (gimple_assign_rhs_code (stmt), weights, |
| 4481 |
gimple_assign_rhs1 (stmt), |
| 4482 |
get_gimple_rhs_class (gimple_assign_rhs_code (stmt)) |
| 4483 |
== GIMPLE_BINARY_RHS |
| 4484 |
? gimple_assign_rhs2 (stmt) : NULL); |
| 4485 |
break; |
| 4486 |
|
| 4487 |
case GIMPLE_COND: |
| 4488 |
cost = 1 + estimate_operator_cost (gimple_cond_code (stmt), weights, |
| 4489 |
gimple_op (stmt, 0), |
| 4490 |
gimple_op (stmt, 1)); |
| 4491 |
break; |
| 4492 |
|
| 4493 |
case GIMPLE_SWITCH: |
| 4494 |
{ |
| 4495 |
gswitch *switch_stmt = as_a <gswitch *> (stmt); |
| 4496 |
/* Take into account cost of the switch + guess 2 conditional jumps for |
| 4497 |
each case label. |
| 4498 |
|
| 4499 |
TODO: once the switch expansion logic is sufficiently separated, we can |
| 4500 |
do better job on estimating cost of the switch. */ |
| 4501 |
if (weights->time_based) |
| 4502 |
cost = floor_log2 (gimple_switch_num_labels (switch_stmt)) * 2; |
| 4503 |
else |
| 4504 |
cost = gimple_switch_num_labels (switch_stmt) * 2; |
| 4505 |
} |
| 4506 |
break; |
| 4507 |
|
| 4508 |
case GIMPLE_CALL: |
| 4509 |
{ |
| 4510 |
tree decl; |
| 4511 |
|
| 4512 |
if (gimple_call_internal_p (stmt)) |
| 4513 |
return 0; |
| 4514 |
else if ((decl = gimple_call_fndecl (stmt)) |
| 4515 |
&& fndecl_built_in_p (decl)) |
| 4516 |
{ |
| 4517 |
/* Do not special case builtins where we see the body. |
| 4518 |
This just confuse inliner. */ |
| 4519 |
struct cgraph_node *node; |
| 4520 |
if ((node = cgraph_node::get (decl)) |
| 4521 |
&& node->definition) |
| 4522 |
; |
| 4523 |
/* For buitins that are likely expanded to nothing or |
| 4524 |
inlined do not account operand costs. */ |
| 4525 |
else if (is_simple_builtin (decl)) |
| 4526 |
return 0; |
| 4527 |
else if (is_inexpensive_builtin (decl)) |
| 4528 |
return weights->target_builtin_call_cost; |
| 4529 |
else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) |
| 4530 |
{ |
| 4531 |
/* We canonicalize x * x to pow (x, 2.0) with -ffast-math, so |
| 4532 |
specialize the cheap expansion we do here. |
| 4533 |
??? This asks for a more general solution. */ |
| 4534 |
switch (DECL_FUNCTION_CODE (decl)) |
| 4535 |
{ |
| 4536 |
case BUILT_IN_POW: |
| 4537 |
case BUILT_IN_POWF: |
| 4538 |
case BUILT_IN_POWL: |
| 4539 |
if (TREE_CODE (gimple_call_arg (stmt, 1)) == REAL_CST |
| 4540 |
&& (real_equal |
| 4541 |
(&TREE_REAL_CST (gimple_call_arg (stmt, 1)), |
| 4542 |
&dconst2))) |
| 4543 |
return estimate_operator_cost |
| 4544 |
(MULT_EXPR, weights, gimple_call_arg (stmt, 0), |
| 4545 |
gimple_call_arg (stmt, 0)); |
| 4546 |
break; |
| 4547 |
|
| 4548 |
default: |
| 4549 |
break; |
| 4550 |
} |
| 4551 |
} |
| 4552 |
} |
| 4553 |
|
| 4554 |
cost = decl ? weights->call_cost : weights->indirect_call_cost; |
| 4555 |
if (gimple_call_lhs (stmt)) |
| 4556 |
cost += estimate_move_cost (TREE_TYPE (gimple_call_lhs (stmt)), |
| 4557 |
weights->time_based); |
| 4558 |
for (i = 0; i < gimple_call_num_args (stmt); i++) |
| 4559 |
{ |
| 4560 |
tree arg = gimple_call_arg (stmt, i); |
| 4561 |
cost += estimate_move_cost (TREE_TYPE (arg), |
| 4562 |
weights->time_based); |
| 4563 |
} |
| 4564 |
break; |
| 4565 |
} |
| 4566 |
|
| 4567 |
case GIMPLE_RETURN: |
| 4568 |
return weights->return_cost; |
| 4569 |
|
| 4570 |
case GIMPLE_GOTO: |
| 4571 |
case GIMPLE_LABEL: |
| 4572 |
case GIMPLE_NOP: |
| 4573 |
case GIMPLE_PHI: |
| 4574 |
case GIMPLE_PREDICT: |
| 4575 |
case GIMPLE_DEBUG: |
| 4576 |
return 0; |
| 4577 |
|
| 4578 |
case GIMPLE_ASM: |
| 4579 |
{ |
| 4580 |
int count = asm_str_count (gimple_asm_string (as_a <gasm *> (stmt))); |
| 4581 |
/* 1000 means infinity. This avoids overflows later |
| 4582 |
with very long asm statements. */ |
| 4583 |
if (count > 1000) |
| 4584 |
count = 1000; |
| 4585 |
/* If this asm is asm inline, count anything as minimum size. */ |
| 4586 |
if (gimple_asm_inline_p (as_a <gasm *> (stmt))) |
| 4587 |
count = MIN (1, count); |
| 4588 |
return MAX (1, count); |
| 4589 |
} |
| 4590 |
|
| 4591 |
case GIMPLE_RESX: |
| 4592 |
/* This is either going to be an external function call with one |
| 4593 |
argument, or two register copy statements plus a goto. */ |
| 4594 |
return 2; |
| 4595 |
|
| 4596 |
case GIMPLE_EH_DISPATCH: |
| 4597 |
/* ??? This is going to turn into a switch statement. Ideally |
| 4598 |
we'd have a look at the eh region and estimate the number of |
| 4599 |
edges involved. */ |
| 4600 |
return 10; |
| 4601 |
|
| 4602 |
case GIMPLE_BIND: |
| 4603 |
return estimate_num_insns_seq ( |
| 4604 |
gimple_bind_body (as_a <gbind *> (stmt)), |
| 4605 |
weights); |
| 4606 |
|
| 4607 |
case GIMPLE_EH_FILTER: |
| 4608 |
return estimate_num_insns_seq (gimple_eh_filter_failure (stmt), weights); |
| 4609 |
|
| 4610 |
case GIMPLE_CATCH: |
| 4611 |
return estimate_num_insns_seq (gimple_catch_handler ( |
| 4612 |
as_a <gcatch *> (stmt)), |
| 4613 |
weights); |
| 4614 |
|
| 4615 |
case GIMPLE_TRY: |
| 4616 |
return (estimate_num_insns_seq (gimple_try_eval (stmt), weights) |
| 4617 |
+ estimate_num_insns_seq (gimple_try_cleanup (stmt), weights)); |
| 4618 |
|
| 4619 |
/* OMP directives are generally very expensive. */ |
| 4620 |
|
| 4621 |
case GIMPLE_OMP_RETURN: |
| 4622 |
case GIMPLE_OMP_SECTIONS_SWITCH: |
| 4623 |
case GIMPLE_OMP_ATOMIC_STORE: |
| 4624 |
case GIMPLE_OMP_CONTINUE: |
| 4625 |
/* ...except these, which are cheap. */ |
| 4626 |
return 0; |
| 4627 |
|
| 4628 |
case GIMPLE_OMP_ATOMIC_LOAD: |
| 4629 |
return weights->omp_cost; |
| 4630 |
|
| 4631 |
case GIMPLE_OMP_FOR: |
| 4632 |
return (weights->omp_cost |
| 4633 |
+ estimate_num_insns_seq (gimple_omp_body (stmt), weights) |
| 4634 |
+ estimate_num_insns_seq (gimple_omp_for_pre_body (stmt), weights)); |
| 4635 |
|
| 4636 |
case GIMPLE_OMP_PARALLEL: |
| 4637 |
case GIMPLE_OMP_TASK: |
| 4638 |
case GIMPLE_OMP_CRITICAL: |
| 4639 |
case GIMPLE_OMP_MASTER: |
| 4640 |
case GIMPLE_OMP_MASKED: |
| 4641 |
case GIMPLE_OMP_SCOPE: |
| 4642 |
case GIMPLE_OMP_DISPATCH: |
| 4643 |
case GIMPLE_OMP_TASKGROUP: |
| 4644 |
case GIMPLE_OMP_ORDERED: |
| 4645 |
case GIMPLE_OMP_SCAN: |
| 4646 |
case GIMPLE_OMP_SECTION: |
| 4647 |
case GIMPLE_OMP_SECTIONS: |
| 4648 |
case GIMPLE_OMP_STRUCTURED_BLOCK: |
| 4649 |
case GIMPLE_OMP_SINGLE: |
| 4650 |
case GIMPLE_OMP_TARGET: |
| 4651 |
case GIMPLE_OMP_TEAMS: |
| 4652 |
return (weights->omp_cost |
| 4653 |
+ estimate_num_insns_seq (gimple_omp_body (stmt), weights)); |
| 4654 |
|
| 4655 |
case GIMPLE_TRANSACTION: |
| 4656 |
return (weights->tm_cost |
| 4657 |
+ estimate_num_insns_seq (gimple_transaction_body ( |
| 4658 |
as_a <gtransaction *> (stmt)), |
| 4659 |
weights)); |
| 4660 |
|
| 4661 |
default: |
| 4662 |
gcc_unreachable (); |
| 4663 |
} |
| 4664 |
|
| 4665 |
return cost; |
| 4666 |
} |
| 4667 |
|
| 4668 |
/* Estimate number of instructions that will be created by expanding |
| 4669 |
function FNDECL. WEIGHTS contains weights attributed to various |
| 4670 |
constructs. */ |
| 4671 |
|
| 4672 |
int |
| 4673 |
estimate_num_insns_fn (tree fndecl, eni_weights *weights) |
| 4674 |
{ |
| 4675 |
struct function *my_function = DECL_STRUCT_FUNCTION (fndecl); |
| 4676 |
gimple_stmt_iterator bsi; |
| 4677 |
basic_block bb; |
| 4678 |
int n = 0; |
| 4679 |
|
| 4680 |
gcc_assert (my_function && my_function->cfg); |
| 4681 |
FOR_EACH_BB_FN (bb, my_function) |
| 4682 |
{ |
| 4683 |
for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi)) |
| 4684 |
n += estimate_num_insns (gsi_stmt (bsi), weights); |
| 4685 |
} |
| 4686 |
|
| 4687 |
return n; |
| 4688 |
} |
| 4689 |
|
| 4690 |
|
| 4691 |
/* Initializes weights used by estimate_num_insns. */ |
| 4692 |
|
| 4693 |
void |
| 4694 |
init_inline_once (void) |
| 4695 |
{ |
| 4696 |
eni_size_weights.call_cost = 1; |
| 4697 |
eni_size_weights.indirect_call_cost = 3; |
| 4698 |
eni_size_weights.target_builtin_call_cost = 1; |
| 4699 |
eni_size_weights.div_mod_cost = 1; |
| 4700 |
eni_size_weights.omp_cost = 40; |
| 4701 |
eni_size_weights.tm_cost = 10; |
| 4702 |
eni_size_weights.time_based = false; |
| 4703 |
eni_size_weights.return_cost = 1; |
| 4704 |
|
| 4705 |
/* Estimating time for call is difficult, since we have no idea what the |
| 4706 |
called function does. In the current uses of eni_time_weights, |
| 4707 |
underestimating the cost does less harm than overestimating it, so |
| 4708 |
we choose a rather small value here. */ |
| 4709 |
eni_time_weights.call_cost = 10; |
| 4710 |
eni_time_weights.indirect_call_cost = 15; |
| 4711 |
eni_time_weights.target_builtin_call_cost = 1; |
| 4712 |
eni_time_weights.div_mod_cost = 10; |
| 4713 |
eni_time_weights.omp_cost = 40; |
| 4714 |
eni_time_weights.tm_cost = 40; |
| 4715 |
eni_time_weights.time_based = true; |
| 4716 |
eni_time_weights.return_cost = 2; |
| 4717 |
} |
| 4718 |
|
| 4719 |
|
| 4720 |
/* Install new lexical TREE_BLOCK underneath 'current_block'. */ |
| 4721 |
|
| 4722 |
static void |
| 4723 |
prepend_lexical_block (tree current_block, tree new_block) |
| 4724 |
{ |
| 4725 |
BLOCK_CHAIN (new_block) = BLOCK_SUBBLOCKS (current_block); |
| 4726 |
BLOCK_SUBBLOCKS (current_block) = new_block; |
| 4727 |
BLOCK_SUPERCONTEXT (new_block) = current_block; |
| 4728 |
} |
| 4729 |
|
| 4730 |
/* Add local variables from CALLEE to CALLER. */ |
| 4731 |
|
| 4732 |
static inline void |
| 4733 |
add_local_variables (struct function *callee, struct function *caller, |
| 4734 |
copy_body_data *id) |
| 4735 |
{ |
| 4736 |
tree var; |
| 4737 |
unsigned ix; |
| 4738 |
|
| 4739 |
FOR_EACH_LOCAL_DECL (callee, ix, var) |
| 4740 |
if (!can_be_nonlocal (var, id)) |
| 4741 |
{ |
| 4742 |
tree new_var = remap_decl (var, id); |
| 4743 |
|
| 4744 |
/* Remap debug-expressions. */ |
| 4745 |
if (VAR_P (new_var) |
| 4746 |
&& DECL_HAS_DEBUG_EXPR_P (var) |
| 4747 |
&& new_var != var) |
| 4748 |
{ |
| 4749 |
tree tem = DECL_DEBUG_EXPR (var); |
| 4750 |
bool old_regimplify = id->regimplify; |
| 4751 |
id->remapping_type_depth++; |
| 4752 |
walk_tree (&tem, copy_tree_body_r, id, NULL); |
| 4753 |
id->remapping_type_depth--; |
| 4754 |
id->regimplify = old_regimplify; |
| 4755 |
SET_DECL_DEBUG_EXPR (new_var, tem); |
| 4756 |
DECL_HAS_DEBUG_EXPR_P (new_var) = 1; |
| 4757 |
} |
| 4758 |
add_local_decl (caller, new_var); |
| 4759 |
} |
| 4760 |
} |
| 4761 |
|
| 4762 |
/* Add to BINDINGS a debug stmt resetting SRCVAR if inlining might |
| 4763 |
have brought in or introduced any debug stmts for SRCVAR. */ |
| 4764 |
|
| 4765 |
static inline void |
| 4766 |
reset_debug_binding (copy_body_data *id, tree srcvar, gimple_seq *bindings) |
| 4767 |
{ |
| 4768 |
tree *remappedvarp = id->decl_map->get (srcvar); |
| 4769 |
|
| 4770 |
if (!remappedvarp) |
| 4771 |
return; |
| 4772 |
|
| 4773 |
if (!VAR_P (*remappedvarp)) |
| 4774 |
return; |
| 4775 |
|
| 4776 |
if (*remappedvarp == id->retvar) |
| 4777 |
return; |
| 4778 |
|
| 4779 |
tree tvar = target_for_debug_bind (*remappedvarp); |
| 4780 |
if (!tvar) |
| 4781 |
return; |
| 4782 |
|
| 4783 |
gdebug *stmt = gimple_build_debug_bind (tvar, NULL_TREE, |
| 4784 |
id->call_stmt); |
| 4785 |
gimple_seq_add_stmt (bindings, stmt); |
| 4786 |
} |
| 4787 |
|
| 4788 |
/* For each inlined variable for which we may have debug bind stmts, |
| 4789 |
add before GSI a final debug stmt resetting it, marking the end of |
| 4790 |
its life, so that var-tracking knows it doesn't have to compute |
| 4791 |
further locations for it. */ |
| 4792 |
|
| 4793 |
static inline void |
| 4794 |
reset_debug_bindings (copy_body_data *id, gimple_stmt_iterator gsi) |
| 4795 |
{ |
| 4796 |
tree var; |
| 4797 |
unsigned ix; |
| 4798 |
gimple_seq bindings = NULL; |
| 4799 |
|
| 4800 |
if (!gimple_in_ssa_p (id->src_cfun)) |
| 4801 |
return; |
| 4802 |
|
| 4803 |
if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments)) |
| 4804 |
return; |
| 4805 |
|
| 4806 |
for (var = DECL_ARGUMENTS (id->src_fn); |
| 4807 |
var; var = DECL_CHAIN (var)) |
| 4808 |
reset_debug_binding (id, var, &bindings); |
| 4809 |
|
| 4810 |
FOR_EACH_LOCAL_DECL (id->src_cfun, ix, var) |
| 4811 |
reset_debug_binding (id, var, &bindings); |
| 4812 |
|
| 4813 |
gsi_insert_seq_before_without_update (&gsi, bindings, GSI_SAME_STMT); |
| 4814 |
} |
| 4815 |
|
| 4816 |
/* If STMT is a GIMPLE_CALL, replace it with its inline expansion. */ |
| 4817 |
|
| 4818 |
static bool |
| 4819 |
expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id, |
| 4820 |
bitmap to_purge) |
| 4821 |
{ |
| 4822 |
tree use_retvar; |
| 4823 |
tree fn; |
| 4824 |
hash_map<tree, tree> *dst; |
| 4825 |
hash_map<tree, tree> *st = NULL; |
| 4826 |
tree return_slot; |
| 4827 |
tree modify_dest; |
| 4828 |
struct cgraph_edge *cg_edge; |
| 4829 |
cgraph_inline_failed_t reason; |
| 4830 |
basic_block return_block; |
| 4831 |
edge e; |
| 4832 |
gimple_stmt_iterator gsi, stmt_gsi; |
| 4833 |
bool successfully_inlined = false; |
| 4834 |
bool purge_dead_abnormal_edges; |
| 4835 |
gcall *call_stmt; |
| 4836 |
unsigned int prop_mask, src_properties; |
| 4837 |
struct function *dst_cfun; |
| 4838 |
tree simduid; |
| 4839 |
use_operand_p use; |
| 4840 |
gimple *simtenter_stmt = NULL; |
| 4841 |
vec<tree> *simtvars_save; |
| 4842 |
tree save_stack = NULL_TREE; |
| 4843 |
|
| 4844 |
/* The gimplifier uses input_location in too many places, such as |
| 4845 |
internal_get_tmp_var (). */ |
| 4846 |
location_t saved_location = input_location; |
| 4847 |
input_location = gimple_location (stmt); |
| 4848 |
|
| 4849 |
/* From here on, we're only interested in CALL_EXPRs. */ |
| 4850 |
call_stmt = dyn_cast <gcall *> (stmt); |
| 4851 |
if (!call_stmt) |
| 4852 |
goto egress; |
| 4853 |
|
| 4854 |
cg_edge = id->dst_node->get_edge (stmt); |
| 4855 |
gcc_checking_assert (cg_edge); |
| 4856 |
/* First, see if we can figure out what function is being called. |
| 4857 |
If we cannot, then there is no hope of inlining the function. */ |
| 4858 |
if (cg_edge->indirect_unknown_callee) |
| 4859 |
goto egress; |
| 4860 |
fn = cg_edge->callee->decl; |
| 4861 |
gcc_checking_assert (fn); |
| 4862 |
|
| 4863 |
/* If FN is a declaration of a function in a nested scope that was |
| 4864 |
globally declared inline, we don't set its DECL_INITIAL. |
| 4865 |
However, we can't blindly follow DECL_ABSTRACT_ORIGIN because the |
| 4866 |
C++ front-end uses it for cdtors to refer to their internal |
| 4867 |
declarations, that are not real functions. Fortunately those |
| 4868 |
don't have trees to be saved, so we can tell by checking their |
| 4869 |
gimple_body. */ |
| 4870 |
if (!DECL_INITIAL (fn) |
| 4871 |
&& DECL_ABSTRACT_ORIGIN (fn) |
| 4872 |
&& gimple_has_body_p (DECL_ABSTRACT_ORIGIN (fn))) |
| 4873 |
fn = DECL_ABSTRACT_ORIGIN (fn); |
| 4874 |
|
| 4875 |
/* Don't try to inline functions that are not well-suited to inlining. */ |
| 4876 |
if (cg_edge->inline_failed) |
| 4877 |
{ |
| 4878 |
reason = cg_edge->inline_failed; |
| 4879 |
/* If this call was originally indirect, we do not want to emit any |
| 4880 |
inlining related warnings or sorry messages because there are no |
| 4881 |
guarantees regarding those. */ |
| 4882 |
if (cg_edge->indirect_inlining_edge) |
| 4883 |
goto egress; |
| 4884 |
|
| 4885 |
if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) |
| 4886 |
/* For extern inline functions that get redefined we always |
| 4887 |
silently ignored always_inline flag. Better behavior would |
| 4888 |
be to be able to keep both bodies and use extern inline body |
| 4889 |
for inlining, but we can't do that because frontends overwrite |
| 4890 |
the body. */ |
| 4891 |
&& !cg_edge->callee->redefined_extern_inline |
| 4892 |
/* During early inline pass, report only when optimization is |
| 4893 |
not turned on. */ |
| 4894 |
&& (symtab->global_info_ready |
| 4895 |
|| !optimize |
| 4896 |
|| cgraph_inline_failed_type (reason) == CIF_FINAL_ERROR) |
| 4897 |
/* PR 20090218-1_0.c. Body can be provided by another module. */ |
| 4898 |
&& (reason != CIF_BODY_NOT_AVAILABLE || !flag_generate_lto)) |
| 4899 |
{ |
| 4900 |
error ("inlining failed in call to %<always_inline%> %q+F: %s", fn, |
| 4901 |
cgraph_inline_failed_string (reason)); |
| 4902 |
if (gimple_location (stmt) != UNKNOWN_LOCATION) |
| 4903 |
inform (gimple_location (stmt), "called from here"); |
| 4904 |
else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION) |
| 4905 |
inform (DECL_SOURCE_LOCATION (cfun->decl), |
| 4906 |
"called from this function"); |
| 4907 |
} |
| 4908 |
else if (opt_for_fn (fn, warn_inline) |
| 4909 |
&& DECL_DECLARED_INLINE_P (fn) |
| 4910 |
&& !DECL_NO_INLINE_WARNING_P (fn) |
| 4911 |
&& !DECL_IN_SYSTEM_HEADER (fn) |
| 4912 |
&& reason != CIF_UNSPECIFIED |
| 4913 |
&& !lookup_attribute ("noinline", DECL_ATTRIBUTES (fn)) |
| 4914 |
/* Do not warn about not inlined recursive calls. */ |
| 4915 |
&& !cg_edge->recursive_p () |
| 4916 |
/* Avoid warnings during early inline pass. */ |
| 4917 |
&& symtab->global_info_ready) |
| 4918 |
{ |
| 4919 |
auto_diagnostic_group d; |
| 4920 |
if (warning (OPT_Winline, "inlining failed in call to %q+F: %s", |
| 4921 |
fn, _(cgraph_inline_failed_string (reason)))) |
| 4922 |
{ |
| 4923 |
if (gimple_location (stmt) != UNKNOWN_LOCATION) |
| 4924 |
inform (gimple_location (stmt), "called from here"); |
| 4925 |
else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION) |
| 4926 |
inform (DECL_SOURCE_LOCATION (cfun->decl), |
| 4927 |
"called from this function"); |
| 4928 |
} |
| 4929 |
} |
| 4930 |
goto egress; |
| 4931 |
} |
| 4932 |
id->src_node = cg_edge->callee; |
| 4933 |
|
| 4934 |
/* If callee is thunk, all we need is to adjust the THIS pointer |
| 4935 |
and redirect to function being thunked. */ |
| 4936 |
if (id->src_node->thunk) |
| 4937 |
{ |
| 4938 |
cgraph_edge *edge; |
| 4939 |
tree virtual_offset = NULL; |
| 4940 |
profile_count count = cg_edge->count; |
| 4941 |
tree op; |
| 4942 |
gimple_stmt_iterator iter = gsi_for_stmt (stmt); |
| 4943 |
thunk_info *info = thunk_info::get (id->src_node); |
| 4944 |
|
| 4945 |
cgraph_edge::remove (cg_edge); |
| 4946 |
edge = id->src_node->callees->clone (id->dst_node, call_stmt, |
| 4947 |
gimple_uid (stmt), |
| 4948 |
profile_count::one (), |
| 4949 |
profile_count::one (), |
| 4950 |
true); |
| 4951 |
edge->count = count; |
| 4952 |
if (info->virtual_offset_p) |
| 4953 |
virtual_offset = size_int (info->virtual_value); |
| 4954 |
op = create_tmp_reg_fn (cfun, TREE_TYPE (gimple_call_arg (stmt, 0)), |
| 4955 |
NULL); |
| 4956 |
gsi_insert_before (&iter, gimple_build_assign (op, |
| 4957 |
gimple_call_arg (stmt, 0)), |
| 4958 |
GSI_NEW_STMT); |
| 4959 |
gcc_assert (info->this_adjusting); |
| 4960 |
op = thunk_adjust (&iter, op, 1, info->fixed_offset, |
| 4961 |
virtual_offset, info->indirect_offset); |
| 4962 |
|
| 4963 |
gimple_call_set_arg (stmt, 0, op); |
| 4964 |
gimple_call_set_fndecl (stmt, edge->callee->decl); |
| 4965 |
update_stmt (stmt); |
| 4966 |
id->src_node->remove (); |
| 4967 |
successfully_inlined = expand_call_inline (bb, stmt, id, to_purge); |
| 4968 |
maybe_remove_unused_call_args (cfun, stmt); |
| 4969 |
/* This used to return true even though we do fail to inline in |
| 4970 |
some cases. See PR98525. */ |
| 4971 |
goto egress; |
| 4972 |
} |
| 4973 |
fn = cg_edge->callee->decl; |
| 4974 |
cg_edge->callee->get_untransformed_body (); |
| 4975 |
|
| 4976 |
if (flag_checking && cg_edge->callee->decl != id->dst_node->decl) |
| 4977 |
cg_edge->callee->verify (); |
| 4978 |
|
| 4979 |
/* We will be inlining this callee. */ |
| 4980 |
id->eh_lp_nr = lookup_stmt_eh_lp (stmt); |
| 4981 |
|
| 4982 |
/* Update the callers EH personality. */ |
| 4983 |
if (DECL_FUNCTION_PERSONALITY (fn)) |
| 4984 |
DECL_FUNCTION_PERSONALITY (cg_edge->caller->decl) |
| 4985 |
= DECL_FUNCTION_PERSONALITY (fn); |
| 4986 |
|
| 4987 |
/* Split the block before the GIMPLE_CALL. */ |
| 4988 |
stmt_gsi = gsi_for_stmt (stmt); |
| 4989 |
gsi_prev (&stmt_gsi); |
| 4990 |
e = split_block (bb, gsi_end_p (stmt_gsi) ? NULL : gsi_stmt (stmt_gsi)); |
| 4991 |
bb = e->src; |
| 4992 |
return_block = e->dest; |
| 4993 |
remove_edge (e); |
| 4994 |
|
| 4995 |
/* If the GIMPLE_CALL was in the last statement of BB, it may have |
| 4996 |
been the source of abnormal edges. In this case, schedule |
| 4997 |
the removal of dead abnormal edges. */ |
| 4998 |
gsi = gsi_start_bb (return_block); |
| 4999 |
gsi_next (&gsi); |
| 5000 |
purge_dead_abnormal_edges = gsi_end_p (gsi); |
| 5001 |
|
| 5002 |
stmt_gsi = gsi_start_bb (return_block); |
| 5003 |
|
| 5004 |
/* Build a block containing code to initialize the arguments, the |
| 5005 |
actual inline expansion of the body, and a label for the return |
| 5006 |
statements within the function to jump to. The type of the |
| 5007 |
statement expression is the return type of the function call. |
| 5008 |
??? If the call does not have an associated block then we will |
| 5009 |
remap all callee blocks to NULL, effectively dropping most of |
| 5010 |
its debug information. This should only happen for calls to |
| 5011 |
artificial decls inserted by the compiler itself. We need to |
| 5012 |
either link the inlined blocks into the caller block tree or |
| 5013 |
not refer to them in any way to not break GC for locations. */ |
| 5014 |
if (tree block = gimple_block (stmt)) |
| 5015 |
{ |
| 5016 |
/* We do want to assign a not UNKNOWN_LOCATION BLOCK_SOURCE_LOCATION |
| 5017 |
to make inlined_function_outer_scope_p return true on this BLOCK. */ |
| 5018 |
location_t loc = LOCATION_LOCUS (gimple_location (stmt)); |
| 5019 |
if (loc == UNKNOWN_LOCATION) |
| 5020 |
loc = LOCATION_LOCUS (DECL_SOURCE_LOCATION (fn)); |
| 5021 |
if (loc == UNKNOWN_LOCATION) |
| 5022 |
loc = BUILTINS_LOCATION; |
| 5023 |
id->block = make_node (BLOCK); |
| 5024 |
BLOCK_ABSTRACT_ORIGIN (id->block) = DECL_ORIGIN (fn); |
| 5025 |
BLOCK_SOURCE_LOCATION (id->block) = loc; |
| 5026 |
prepend_lexical_block (block, id->block); |
| 5027 |
} |
| 5028 |
|
| 5029 |
/* Local declarations will be replaced by their equivalents in this map. */ |
| 5030 |
st = id->decl_map; |
| 5031 |
id->decl_map = new hash_map<tree, tree>; |
| 5032 |
dst = id->debug_map; |
| 5033 |
id->debug_map = NULL; |
| 5034 |
if (flag_stack_reuse != SR_NONE) |
| 5035 |
id->add_clobbers_to_eh_landing_pads = last_basic_block_for_fn (cfun); |
| 5036 |
|
| 5037 |
/* Record the function we are about to inline. */ |
| 5038 |
id->src_fn = fn; |
| 5039 |
id->src_cfun = DECL_STRUCT_FUNCTION (fn); |
| 5040 |
id->reset_location = DECL_IGNORED_P (fn); |
| 5041 |
id->call_stmt = call_stmt; |
| 5042 |
cfun->cfg->full_profile &= id->src_cfun->cfg->full_profile; |
| 5043 |
|
| 5044 |
/* When inlining into an OpenMP SIMD-on-SIMT loop, arrange for new automatic |
| 5045 |
variables to be added to IFN_GOMP_SIMT_ENTER argument list. */ |
| 5046 |
dst_cfun = DECL_STRUCT_FUNCTION (id->dst_fn); |
| 5047 |
simtvars_save = id->dst_simt_vars; |
| 5048 |
if (!(dst_cfun->curr_properties & PROP_gimple_lomp_dev) |
| 5049 |
&& (simduid = bb->loop_father->simduid) != NULL_TREE |
| 5050 |
&& (simduid = ssa_default_def (dst_cfun, simduid)) != NULL_TREE |
| 5051 |
&& single_imm_use (simduid, &use, &simtenter_stmt) |
| 5052 |
&& is_gimple_call (simtenter_stmt) |
| 5053 |
&& gimple_call_internal_p (simtenter_stmt, IFN_GOMP_SIMT_ENTER)) |
| 5054 |
vec_alloc (id->dst_simt_vars, 0); |
| 5055 |
else |
| 5056 |
id->dst_simt_vars = NULL; |
| 5057 |
|
| 5058 |
if (profile_status_for_fn (id->src_cfun) == PROFILE_ABSENT) |
| 5059 |
profile_status_for_fn (dst_cfun) = PROFILE_ABSENT; |
| 5060 |
|
| 5061 |
/* If the src function contains an IFN_VA_ARG, then so will the dst |
| 5062 |
function after inlining. Likewise for IFN_GOMP_USE_SIMT. */ |
| 5063 |
prop_mask = PROP_gimple_lva | PROP_gimple_lomp_dev; |
| 5064 |
src_properties = id->src_cfun->curr_properties & prop_mask; |
| 5065 |
if (src_properties != prop_mask) |
| 5066 |
dst_cfun->curr_properties &= src_properties | ~prop_mask; |
| 5067 |
dst_cfun->calls_eh_return |= id->src_cfun->calls_eh_return; |
| 5068 |
id->dst_node->has_omp_variant_constructs |
| 5069 |
|= id->src_node->has_omp_variant_constructs; |
| 5070 |
|
| 5071 |
gcc_assert (!id->src_cfun->after_inlining); |
| 5072 |
|
| 5073 |
id->entry_bb = bb; |
| 5074 |
if (lookup_attribute ("cold", DECL_ATTRIBUTES (fn))) |
| 5075 |
{ |
| 5076 |
gimple_stmt_iterator si = gsi_last_bb (bb); |
| 5077 |
gsi_insert_after (&si, gimple_build_predict (PRED_COLD_FUNCTION, |
| 5078 |
NOT_TAKEN), |
| 5079 |
GSI_NEW_STMT); |
| 5080 |
} |
| 5081 |
initialize_inlined_parameters (id, stmt, fn, bb); |
| 5082 |
if (debug_nonbind_markers_p && debug_inline_points && id->block |
| 5083 |
&& inlined_function_outer_scope_p (id->block)) |
| 5084 |
{ |
| 5085 |
gimple_stmt_iterator si = gsi_last_bb (bb); |
| 5086 |
gsi_insert_after (&si, gimple_build_debug_inline_entry |
| 5087 |
(id->block, DECL_SOURCE_LOCATION (id->src_fn)), |
| 5088 |
GSI_NEW_STMT); |
| 5089 |
} |
| 5090 |
|
| 5091 |
/* If function to be inlined calls alloca, wrap the inlined function |
| 5092 |
in between save_stack = __builtin_stack_save (); and |
| 5093 |
__builtin_stack_restore (save_stack); calls. */ |
| 5094 |
if (id->src_cfun->calls_alloca && !gimple_call_noreturn_p (stmt)) |
| 5095 |
/* Don't do this for VLA allocations though, just for user alloca |
| 5096 |
calls. */ |
| 5097 |
for (struct cgraph_edge *e = id->src_node->callees; e; e = e->next_callee) |
| 5098 |
if (gimple_maybe_alloca_call_p (e->call_stmt) |
| 5099 |
&& !gimple_call_alloca_for_var_p (e->call_stmt)) |
| 5100 |
{ |
| 5101 |
tree fn = builtin_decl_implicit (BUILT_IN_STACK_SAVE); |
| 5102 |
gcall *call = gimple_build_call (fn, 0); |
| 5103 |
save_stack = make_ssa_name (ptr_type_node); |
| 5104 |
gimple_call_set_lhs (call, save_stack); |
| 5105 |
gimple_stmt_iterator si = gsi_last_bb (bb); |
| 5106 |
gsi_insert_after (&si, call, GSI_NEW_STMT); |
| 5107 |
struct cgraph_node *dest = cgraph_node::get_create (fn); |
| 5108 |
id->dst_node->create_edge (dest, call, bb->count)->inline_failed |
| 5109 |
= CIF_BODY_NOT_AVAILABLE; |
| 5110 |
break; |
| 5111 |
} |
| 5112 |
|
| 5113 |
if (DECL_INITIAL (fn)) |
| 5114 |
{ |
| 5115 |
if (gimple_block (stmt)) |
| 5116 |
{ |
| 5117 |
tree *var; |
| 5118 |
|
| 5119 |
prepend_lexical_block (id->block, |
| 5120 |
remap_blocks (DECL_INITIAL (fn), id)); |
| 5121 |
gcc_checking_assert (BLOCK_SUBBLOCKS (id->block) |
| 5122 |
&& (BLOCK_CHAIN (BLOCK_SUBBLOCKS (id->block)) |
| 5123 |
== NULL_TREE)); |
| 5124 |
/* Move vars for PARM_DECLs from DECL_INITIAL block to id->block, |
| 5125 |
otherwise for DWARF DW_TAG_formal_parameter will not be children of |
| 5126 |
DW_TAG_inlined_subroutine, but of a DW_TAG_lexical_block |
| 5127 |
under it. The parameters can be then evaluated in the debugger, |
| 5128 |
but don't show in backtraces. */ |
| 5129 |
for (var = &BLOCK_VARS (BLOCK_SUBBLOCKS (id->block)); *var; ) |
| 5130 |
if (TREE_CODE (DECL_ORIGIN (*var)) == PARM_DECL) |
| 5131 |
{ |
| 5132 |
tree v = *var; |
| 5133 |
*var = TREE_CHAIN (v); |
| 5134 |
TREE_CHAIN (v) = BLOCK_VARS (id->block); |
| 5135 |
BLOCK_VARS (id->block) = v; |
| 5136 |
} |
| 5137 |
else |
| 5138 |
var = &TREE_CHAIN (*var); |
| 5139 |
} |
| 5140 |
else |
| 5141 |
remap_blocks_to_null (DECL_INITIAL (fn), id); |
| 5142 |
} |
| 5143 |
|
| 5144 |
/* Return statements in the function body will be replaced by jumps |
| 5145 |
to the RET_LABEL. */ |
| 5146 |
gcc_assert (DECL_INITIAL (fn)); |
| 5147 |
gcc_assert (TREE_CODE (DECL_INITIAL (fn)) == BLOCK); |
| 5148 |
|
| 5149 |
/* Find the LHS to which the result of this call is assigned. */ |
| 5150 |
return_slot = NULL; |
| 5151 |
if (gimple_call_lhs (stmt)) |
| 5152 |
{ |
| 5153 |
modify_dest = gimple_call_lhs (stmt); |
| 5154 |
|
| 5155 |
/* The function which we are inlining might not return a value, |
| 5156 |
in which case we should issue a warning that the function |
| 5157 |
does not return a value. In that case the optimizers will |
| 5158 |
see that the variable to which the value is assigned was not |
| 5159 |
initialized. We do not want to issue a warning about that |
| 5160 |
uninitialized variable. */ |
| 5161 |
if (DECL_P (modify_dest)) |
| 5162 |
suppress_warning (modify_dest, OPT_Wuninitialized); |
| 5163 |
|
| 5164 |
/* If we have a return slot, we can assign it the result directly, |
| 5165 |
except in the case where it is a global variable that is only |
| 5166 |
written to because, the callee being permitted to read or take |
| 5167 |
the address of its DECL_RESULT, this could invalidate the flag |
| 5168 |
on the global variable; instead we preventively remove the store, |
| 5169 |
which would have happened later if the call was not inlined. */ |
| 5170 |
if (gimple_call_return_slot_opt_p (call_stmt)) |
| 5171 |
{ |
| 5172 |
tree base = get_base_address (modify_dest); |
| 5173 |
|
| 5174 |
if (VAR_P (base) |
| 5175 |
&& (TREE_STATIC (base) || DECL_EXTERNAL (base)) |
| 5176 |
&& varpool_node::get (base)->writeonly) |
| 5177 |
return_slot = NULL; |
| 5178 |
else |
| 5179 |
return_slot = modify_dest; |
| 5180 |
|
| 5181 |
modify_dest = NULL; |
| 5182 |
} |
| 5183 |
} |
| 5184 |
else |
| 5185 |
modify_dest = NULL; |
| 5186 |
|
| 5187 |
/* If we are inlining a call to the C++ operator new, we don't want |
| 5188 |
to use type based alias analysis on the return value. Otherwise |
| 5189 |
we may get confused if the compiler sees that the inlined new |
| 5190 |
function returns a pointer which was just deleted. See bug |
| 5191 |
33407. */ |
| 5192 |
if (DECL_IS_OPERATOR_NEW_P (fn)) |
| 5193 |
{ |
| 5194 |
return_slot = NULL; |
| 5195 |
modify_dest = NULL; |
| 5196 |
} |
| 5197 |
|
| 5198 |
/* Declare the return variable for the function. */ |
| 5199 |
use_retvar = declare_return_variable (id, return_slot, modify_dest, bb); |
| 5200 |
|
| 5201 |
/* Add local vars in this inlined callee to caller. */ |
| 5202 |
add_local_variables (id->src_cfun, cfun, id); |
| 5203 |
|
| 5204 |
if (dump_enabled_p ()) |
| 5205 |
{ |
| 5206 |
char buf[128]; |
| 5207 |
snprintf (buf, sizeof(buf), "%4.2f", |
| 5208 |
cg_edge->sreal_frequency ().to_double ()); |
| 5209 |
dump_printf_loc (MSG_NOTE | MSG_PRIORITY_INTERNALS, |
| 5210 |
call_stmt, |
| 5211 |
"Inlining %C to %C with frequency %s\n", |
| 5212 |
id->src_node, id->dst_node, buf); |
| 5213 |
if (dump_file && (dump_flags & TDF_DETAILS)) |
| 5214 |
{ |
| 5215 |
id->src_node->dump (dump_file); |
| 5216 |
id->dst_node->dump (dump_file); |
| 5217 |
} |
| 5218 |
} |
| 5219 |
|
| 5220 |
/* This is it. Duplicate the callee body. Assume callee is |
| 5221 |
pre-gimplified. Note that we must not alter the caller |
| 5222 |
function in any way before this point, as this CALL_EXPR may be |
| 5223 |
a self-referential call; if we're calling ourselves, we need to |
| 5224 |
duplicate our body before altering anything. */ |
| 5225 |
copy_body (id, bb, return_block, NULL); |
| 5226 |
|
| 5227 |
reset_debug_bindings (id, stmt_gsi); |
| 5228 |
|
| 5229 |
if (flag_stack_reuse != SR_NONE) |
| 5230 |
for (tree p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p)) |
| 5231 |
if (!TREE_THIS_VOLATILE (p)) |
| 5232 |
{ |
| 5233 |
/* The value associated with P is a local temporary only if |
| 5234 |
there is no value associated with P in the debug map. */ |
| 5235 |
tree *varp = id->decl_map->get (p); |
| 5236 |
if (varp |
| 5237 |
&& VAR_P (*varp) |
| 5238 |
&& !is_gimple_reg (*varp) |
| 5239 |
&& !(id->debug_map && id->debug_map->get (p))) |
| 5240 |
{ |
| 5241 |
tree clobber = build_clobber (TREE_TYPE (*varp), |
| 5242 |
CLOBBER_STORAGE_END); |
| 5243 |
gimple *clobber_stmt; |
| 5244 |
clobber_stmt = gimple_build_assign (*varp, clobber); |
| 5245 |
gimple_set_location (clobber_stmt, gimple_location (stmt)); |
| 5246 |
gsi_insert_before (&stmt_gsi, clobber_stmt, GSI_SAME_STMT); |
| 5247 |
} |
| 5248 |
} |
| 5249 |
|
| 5250 |
if (save_stack) |
| 5251 |
{ |
| 5252 |
tree fn = builtin_decl_implicit (BUILT_IN_STACK_RESTORE); |
| 5253 |
gcall *call = gimple_build_call (fn, 1, save_stack); |
| 5254 |
gsi_insert_before (&stmt_gsi, call, GSI_SAME_STMT); |
| 5255 |
struct cgraph_node *dest = cgraph_node::get_create (fn); |
| 5256 |
id->dst_node->create_edge (dest, call, |
| 5257 |
return_block->count)->inline_failed |
| 5258 |
= CIF_BODY_NOT_AVAILABLE; |
| 5259 |
} |
| 5260 |
|
| 5261 |
/* Reset the escaped solution. */ |
| 5262 |
if (cfun->gimple_df) |
| 5263 |
{ |
| 5264 |
pt_solution_reset (&cfun->gimple_df->escaped); |
| 5265 |
pt_solution_reset (&cfun->gimple_df->escaped_return); |
| 5266 |
} |
| 5267 |
|
| 5268 |
/* Add new automatic variables to IFN_GOMP_SIMT_ENTER arguments. */ |
| 5269 |
if (id->dst_simt_vars && id->dst_simt_vars->length () > 0) |
| 5270 |
{ |
| 5271 |
size_t nargs = gimple_call_num_args (simtenter_stmt); |
| 5272 |
vec<tree> *vars = id->dst_simt_vars; |
| 5273 |
auto_vec<tree> newargs (nargs + vars->length ()); |
| 5274 |
for (size_t i = 0; i < nargs; i++) |
| 5275 |
newargs.quick_push (gimple_call_arg (simtenter_stmt, i)); |
| 5276 |
for (tree *pvar = vars->begin (); pvar != vars->end (); pvar++) |
| 5277 |
{ |
| 5278 |
tree ptrtype = build_pointer_type (TREE_TYPE (*pvar)); |
| 5279 |
newargs.quick_push (build1 (ADDR_EXPR, ptrtype, *pvar)); |
| 5280 |
} |
| 5281 |
gcall *g = gimple_build_call_internal_vec (IFN_GOMP_SIMT_ENTER, newargs); |
| 5282 |
gimple_call_set_lhs (g, gimple_call_lhs (simtenter_stmt)); |
| 5283 |
gimple_stmt_iterator gsi = gsi_for_stmt (simtenter_stmt); |
| 5284 |
gsi_replace (&gsi, g, false); |
| 5285 |
} |
| 5286 |
vec_free (id->dst_simt_vars); |
| 5287 |
id->dst_simt_vars = simtvars_save; |
| 5288 |
|
| 5289 |
/* Clean up. */ |
| 5290 |
if (id->debug_map) |
| 5291 |
{ |
| 5292 |
delete id->debug_map; |
| 5293 |
id->debug_map = dst; |
| 5294 |
} |
| 5295 |
delete id->decl_map; |
| 5296 |
id->decl_map = st; |
| 5297 |
|
| 5298 |
/* Unlink the calls virtual operands before replacing it. */ |
| 5299 |
unlink_stmt_vdef (stmt); |
| 5300 |
if (gimple_vdef (stmt) |
| 5301 |
&& TREE_CODE (gimple_vdef (stmt)) == SSA_NAME) |
| 5302 |
release_ssa_name (gimple_vdef (stmt)); |
| 5303 |
|
| 5304 |
/* If the inlined function returns a result that we care about, |
| 5305 |
substitute the GIMPLE_CALL with an assignment of the return |
| 5306 |
variable to the LHS of the call. That is, if STMT was |
| 5307 |
'a = foo (...)', substitute the call with 'a = USE_RETVAR'. */ |
| 5308 |
if (use_retvar && gimple_call_lhs (stmt)) |
| 5309 |
{ |
| 5310 |
gimple *old_stmt = stmt; |
| 5311 |
tree lhs = gimple_call_lhs (stmt); |
| 5312 |
if (!is_gimple_reg (lhs) |
| 5313 |
&& !is_gimple_reg (use_retvar) |
| 5314 |
&& is_gimple_reg_type (TREE_TYPE (lhs))) |
| 5315 |
{ |
| 5316 |
/* If both lhs and use_retvar aren't gimple regs, yet have |
| 5317 |
gimple reg type, copy through a temporary SSA_NAME. */ |
| 5318 |
gimple *g = gimple_build_assign (make_ssa_name (TREE_TYPE (lhs)), |
| 5319 |
use_retvar); |
| 5320 |
gimple_set_location (g, gimple_location (old_stmt)); |
| 5321 |
gsi_insert_before (&stmt_gsi, g, GSI_SAME_STMT); |
| 5322 |
use_retvar = gimple_assign_lhs (g); |
| 5323 |
} |
| 5324 |
stmt = gimple_build_assign (lhs, use_retvar); |
| 5325 |
gimple_set_location (stmt, gimple_location (old_stmt)); |
| 5326 |
gsi_replace (&stmt_gsi, stmt, false); |
| 5327 |
maybe_clean_or_replace_eh_stmt (old_stmt, stmt); |
| 5328 |
/* Append a clobber for id->retvar if easily possible. */ |
| 5329 |
if (flag_stack_reuse != SR_NONE |
| 5330 |
&& id->retvar |
| 5331 |
&& VAR_P (id->retvar) |
| 5332 |
&& id->retvar != return_slot |
| 5333 |
&& id->retvar != modify_dest |
| 5334 |
&& !TREE_THIS_VOLATILE (id->retvar) |
| 5335 |
&& !is_gimple_reg (id->retvar) |
| 5336 |
&& !stmt_ends_bb_p (stmt)) |
| 5337 |
{ |
| 5338 |
tree clobber = build_clobber (TREE_TYPE (id->retvar), |
| 5339 |
CLOBBER_STORAGE_END); |
| 5340 |
gimple *clobber_stmt; |
| 5341 |
clobber_stmt = gimple_build_assign (id->retvar, clobber); |
| 5342 |
gimple_set_location (clobber_stmt, gimple_location (old_stmt)); |
| 5343 |
gsi_insert_after (&stmt_gsi, clobber_stmt, GSI_SAME_STMT); |
| 5344 |
} |
| 5345 |
} |
| 5346 |
else |
| 5347 |
{ |
| 5348 |
/* Handle the case of inlining a function with no return |
| 5349 |
statement, which causes the return value to become undefined. */ |
| 5350 |
if (gimple_call_lhs (stmt) |
| 5351 |
&& TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME) |
| 5352 |
{ |
| 5353 |
tree name = gimple_call_lhs (stmt); |
| 5354 |
tree var = SSA_NAME_VAR (name); |
| 5355 |
tree def = var ? ssa_default_def (cfun, var) : NULL; |
| 5356 |
|
| 5357 |
if (def) |
| 5358 |
{ |
| 5359 |
/* If the variable is used undefined, make this name |
| 5360 |
undefined via a move. */ |
| 5361 |
stmt = gimple_build_assign (gimple_call_lhs (stmt), def); |
| 5362 |
gsi_replace (&stmt_gsi, stmt, true); |
| 5363 |
} |
| 5364 |
else |
| 5365 |
{ |
| 5366 |
if (!var) |
| 5367 |
{ |
| 5368 |
var = create_tmp_reg_fn (cfun, TREE_TYPE (name), NULL); |
| 5369 |
SET_SSA_NAME_VAR_OR_IDENTIFIER (name, var); |
| 5370 |
} |
| 5371 |
/* Otherwise make this variable undefined. */ |
| 5372 |
gsi_remove (&stmt_gsi, true); |
| 5373 |
set_ssa_default_def (cfun, var, name); |
| 5374 |
SSA_NAME_DEF_STMT (name) = gimple_build_nop (); |
| 5375 |
} |
| 5376 |
} |
| 5377 |
/* Replace with a clobber for id->retvar. */ |
| 5378 |
else if (flag_stack_reuse != SR_NONE |
| 5379 |
&& id->retvar |
| 5380 |
&& VAR_P (id->retvar) |
| 5381 |
&& id->retvar != return_slot |
| 5382 |
&& id->retvar != modify_dest |
| 5383 |
&& !TREE_THIS_VOLATILE (id->retvar) |
| 5384 |
&& !is_gimple_reg (id->retvar)) |
| 5385 |
{ |
| 5386 |
tree clobber = build_clobber (TREE_TYPE (id->retvar)); |
| 5387 |
gimple *clobber_stmt; |
| 5388 |
clobber_stmt = gimple_build_assign (id->retvar, clobber); |
| 5389 |
gimple_set_location (clobber_stmt, gimple_location (stmt)); |
| 5390 |
gsi_replace (&stmt_gsi, clobber_stmt, false); |
| 5391 |
maybe_clean_or_replace_eh_stmt (stmt, clobber_stmt); |
| 5392 |
} |
| 5393 |
else |
| 5394 |
gsi_remove (&stmt_gsi, true); |
| 5395 |
} |
| 5396 |
|
| 5397 |
if (purge_dead_abnormal_edges) |
| 5398 |
bitmap_set_bit (to_purge, return_block->index); |
| 5399 |
|
| 5400 |
/* If the value of the new expression is ignored, that's OK. We |
| 5401 |
don't warn about this for CALL_EXPRs, so we shouldn't warn about |
| 5402 |
the equivalent inlined version either. */ |
| 5403 |
if (is_gimple_assign (stmt)) |
| 5404 |
{ |
| 5405 |
gcc_assert (gimple_assign_single_p (stmt) |
| 5406 |
|| CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))); |
| 5407 |
TREE_USED (gimple_assign_rhs1 (stmt)) = 1; |
| 5408 |
} |
| 5409 |
|
| 5410 |
id->add_clobbers_to_eh_landing_pads = 0; |
| 5411 |
|
| 5412 |
/* Output the inlining info for this abstract function, since it has been |
| 5413 |
inlined. If we don't do this now, we can lose the information about the |
| 5414 |
variables in the function when the blocks get blown away as soon as we |
| 5415 |
remove the cgraph node. */ |
| 5416 |
if (gimple_block (stmt)) |
| 5417 |
(*debug_hooks->outlining_inline_function) (fn); |
| 5418 |
|
| 5419 |
/* Update callgraph if needed. */ |
| 5420 |
cg_edge->callee->remove (); |
| 5421 |
|
| 5422 |
id->block = NULL_TREE; |
| 5423 |
id->retvar = NULL_TREE; |
| 5424 |
successfully_inlined = true; |
| 5425 |
|
| 5426 |
egress: |
| 5427 |
input_location = saved_location; |
| 5428 |
return successfully_inlined; |
| 5429 |
} |
| 5430 |
|
| 5431 |
/* Expand call statements reachable from STMT_P. |
| 5432 |
We can only have CALL_EXPRs as the "toplevel" tree code or nested |
| 5433 |
in a MODIFY_EXPR. */ |
| 5434 |
|
| 5435 |
static bool |
| 5436 |
gimple_expand_calls_inline (basic_block bb, copy_body_data *id, |
| 5437 |
bitmap to_purge) |
| 5438 |
{ |
| 5439 |
gimple_stmt_iterator gsi; |
| 5440 |
bool inlined = false; |
| 5441 |
|
| 5442 |
for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);) |
| 5443 |
{ |
| 5444 |
gimple *stmt = gsi_stmt (gsi); |
| 5445 |
gsi_prev (&gsi); |
| 5446 |
|
| 5447 |
if (is_gimple_call (stmt) |
| 5448 |
&& !gimple_call_internal_p (stmt)) |
| 5449 |
inlined |= expand_call_inline (bb, stmt, id, to_purge); |
| 5450 |
} |
| 5451 |
|
| 5452 |
return inlined; |
| 5453 |
} |
| 5454 |
|
| 5455 |
|
| 5456 |
/* Walk all basic blocks created after FIRST and try to fold every statement |
| 5457 |
in the STATEMENTS pointer set. */ |
| 5458 |
|
| 5459 |
static void |
| 5460 |
fold_marked_statements (int first, hash_set<gimple *> *statements) |
| 5461 |
{ |
| 5462 |
auto_bitmap to_purge; |
| 5463 |
auto_bitmap to_purge_abnormal; |
| 5464 |
|
| 5465 |
auto_vec<edge, 20> stack (n_basic_blocks_for_fn (cfun) + 2); |
| 5466 |
auto_sbitmap visited (last_basic_block_for_fn (cfun)); |
| 5467 |
bitmap_clear (visited); |
| 5468 |
|
| 5469 |
stack.quick_push (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun))); |
| 5470 |
while (!stack.is_empty ()) |
| 5471 |
{ |
| 5472 |
/* Look at the edge on the top of the stack. */ |
| 5473 |
edge e = stack.pop (); |
| 5474 |
basic_block dest = e->dest; |
| 5475 |
|
| 5476 |
if (dest == EXIT_BLOCK_PTR_FOR_FN (cfun) |
| 5477 |
|| bitmap_bit_p (visited, dest->index)) |
| 5478 |
continue; |
| 5479 |
|
| 5480 |
bitmap_set_bit (visited, dest->index); |
| 5481 |
|
| 5482 |
if (dest->index >= first) |
| 5483 |
for (gimple_stmt_iterator gsi = gsi_start_bb (dest); |
| 5484 |
!gsi_end_p (gsi); gsi_next (&gsi)) |
| 5485 |
{ |
| 5486 |
if (!statements->contains (gsi_stmt (gsi))) |
| 5487 |
continue; |
| 5488 |
|
| 5489 |
gimple *old_stmt = gsi_stmt (gsi); |
| 5490 |
bool can_make_abnormal_goto = false; |
| 5491 |
tree old_decl = NULL_TREE; |
| 5492 |
|
| 5493 |
if (is_gimple_call (old_stmt)) |
| 5494 |
{ |
| 5495 |
old_decl = gimple_call_fndecl (old_stmt); |
| 5496 |
if (stmt_can_make_abnormal_goto (old_stmt)) |
| 5497 |
can_make_abnormal_goto = true; |
| 5498 |
} |
| 5499 |
|
| 5500 |
if (old_decl && fndecl_built_in_p (old_decl)) |
| 5501 |
{ |
| 5502 |
/* Folding builtins can create multiple instructions, |
| 5503 |
we need to look at all of them. */ |
| 5504 |
gimple_stmt_iterator i2 = gsi; |
| 5505 |
gsi_prev (&i2); |
| 5506 |
if (fold_stmt (&gsi)) |
| 5507 |
{ |
| 5508 |
gimple *new_stmt; |
| 5509 |
/* If a builtin at the end of a bb folded into nothing, |
| 5510 |
the following loop won't work. */ |
| 5511 |
if (gsi_end_p (gsi)) |
| 5512 |
{ |
| 5513 |
cgraph_update_edges_for_call_stmt (old_stmt, |
| 5514 |
old_decl, NULL); |
| 5515 |
if (can_make_abnormal_goto) |
| 5516 |
bitmap_set_bit (to_purge_abnormal, dest->index); |
| 5517 |
break; |
| 5518 |
} |
| 5519 |
if (gsi_end_p (i2)) |
| 5520 |
i2 = gsi_start_bb (dest); |
| 5521 |
else |
| 5522 |
gsi_next (&i2); |
| 5523 |
while (1) |
| 5524 |
{ |
| 5525 |
new_stmt = gsi_stmt (i2); |
| 5526 |
update_stmt (new_stmt); |
| 5527 |
cgraph_update_edges_for_call_stmt (old_stmt, old_decl, |
| 5528 |
new_stmt); |
| 5529 |
|
| 5530 |
if (new_stmt == gsi_stmt (gsi)) |
| 5531 |
{ |
| 5532 |
/* It is okay to check only for the very last |
| 5533 |
of these statements. If it is a throwing |
| 5534 |
statement nothing will change. If it isn't |
| 5535 |
this can remove EH edges. If that weren't |
| 5536 |
correct then because some intermediate stmts |
| 5537 |
throw, but not the last one. That would mean |
| 5538 |
we'd have to split the block, which we can't |
| 5539 |
here and we'd loose anyway. And as builtins |
| 5540 |
probably never throw, this all |
| 5541 |
is mood anyway. */ |
| 5542 |
if (maybe_clean_or_replace_eh_stmt (old_stmt, |
| 5543 |
new_stmt)) |
| 5544 |
bitmap_set_bit (to_purge, dest->index); |
| 5545 |
if (can_make_abnormal_goto |
| 5546 |
&& !stmt_can_make_abnormal_goto (new_stmt)) |
| 5547 |
bitmap_set_bit (to_purge_abnormal, dest->index); |
| 5548 |
break; |
| 5549 |
} |
| 5550 |
gsi_next (&i2); |
| 5551 |
} |
| 5552 |
} |
| 5553 |
} |
| 5554 |
else if (fold_stmt (&gsi)) |
| 5555 |
{ |
| 5556 |
/* Re-read the statement from GSI as fold_stmt() may |
| 5557 |
have changed it. */ |
| 5558 |
gimple *new_stmt = gsi_stmt (gsi); |
| 5559 |
update_stmt (new_stmt); |
| 5560 |
|
| 5561 |
if (is_gimple_call (old_stmt) |
| 5562 |
|| is_gimple_call (new_stmt)) |
| 5563 |
cgraph_update_edges_for_call_stmt (old_stmt, old_decl, |
| 5564 |
new_stmt); |
| 5565 |
|
| 5566 |
if (maybe_clean_or_replace_eh_stmt (old_stmt, new_stmt)) |
| 5567 |
bitmap_set_bit (to_purge, dest->index); |
| 5568 |
if (can_make_abnormal_goto |
| 5569 |
&& !stmt_can_make_abnormal_goto (new_stmt)) |
| 5570 |
bitmap_set_bit (to_purge_abnormal, dest->index); |
| 5571 |
} |
| 5572 |
} |
| 5573 |
|
| 5574 |
if (EDGE_COUNT (dest->succs) > 0) |
| 5575 |
{ |
| 5576 |
/* Avoid warnings emitted from folding statements that |
| 5577 |
became unreachable because of inlined function parameter |
| 5578 |
propagation. */ |
| 5579 |
e = find_taken_edge (dest, NULL_TREE); |
| 5580 |
if (e) |
| 5581 |
stack.quick_push (e); |
| 5582 |
else |
| 5583 |
{ |
| 5584 |
edge_iterator ei; |
| 5585 |
FOR_EACH_EDGE (e, ei, dest->succs) |
| 5586 |
stack.safe_push (e); |
| 5587 |
} |
| 5588 |
} |
| 5589 |
} |
| 5590 |
|
| 5591 |
gimple_purge_all_dead_eh_edges (to_purge); |
| 5592 |
gimple_purge_all_dead_abnormal_call_edges (to_purge_abnormal); |
| 5593 |
} |
| 5594 |
|
| 5595 |
/* Expand calls to inline functions in the body of FN. */ |
| 5596 |
|
| 5597 |
unsigned int |
| 5598 |
optimize_inline_calls (tree fn) |
| 5599 |
{ |
| 5600 |
copy_body_data id; |
| 5601 |
basic_block bb; |
| 5602 |
int last = n_basic_blocks_for_fn (cfun); |
| 5603 |
bool inlined_p = false; |
| 5604 |
|
| 5605 |
/* Clear out ID. */ |
| 5606 |
memset (&id, 0, sizeof (id)); |
| 5607 |
|
| 5608 |
id.src_node = id.dst_node = cgraph_node::get (fn); |
| 5609 |
gcc_assert (id.dst_node->definition); |
| 5610 |
id.dst_fn = fn; |
| 5611 |
/* Or any functions that aren't finished yet. */ |
| 5612 |
if (current_function_decl) |
| 5613 |
id.dst_fn = current_function_decl; |
| 5614 |
|
| 5615 |
id.copy_decl = copy_decl_maybe_to_var; |
| 5616 |
id.transform_call_graph_edges = CB_CGE_DUPLICATE; |
| 5617 |
id.transform_new_cfg = false; |
| 5618 |
id.transform_return_to_modify = true; |
| 5619 |
id.transform_parameter = true; |
| 5620 |
id.statements_to_fold = new hash_set<gimple *>; |
| 5621 |
|
| 5622 |
push_gimplify_context (); |
| 5623 |
|
| 5624 |
/* We make no attempts to keep dominance info up-to-date. */ |
| 5625 |
free_dominance_info (CDI_DOMINATORS); |
| 5626 |
free_dominance_info (CDI_POST_DOMINATORS); |
| 5627 |
|
| 5628 |
/* Register specific gimple functions. */ |
| 5629 |
gimple_register_cfg_hooks (); |
| 5630 |
|
| 5631 |
/* Reach the trees by walking over the CFG, and note the |
| 5632 |
enclosing basic-blocks in the call edges. */ |
| 5633 |
/* We walk the blocks going forward, because inlined function bodies |
| 5634 |
will split id->current_basic_block, and the new blocks will |
| 5635 |
follow it; we'll trudge through them, processing their CALL_EXPRs |
| 5636 |
along the way. */ |
| 5637 |
auto_bitmap to_purge; |
| 5638 |
FOR_EACH_BB_FN (bb, cfun) |
| 5639 |
inlined_p |= gimple_expand_calls_inline (bb, &id, to_purge); |
| 5640 |
|
| 5641 |
pop_gimplify_context (NULL); |
| 5642 |
|
| 5643 |
if (flag_checking) |
| 5644 |
{ |
| 5645 |
struct cgraph_edge *e; |
| 5646 |
|
| 5647 |
id.dst_node->verify (); |
| 5648 |
|
| 5649 |
/* Double check that we inlined everything we are supposed to inline. */ |
| 5650 |
for (e = id.dst_node->callees; e; e = e->next_callee) |
| 5651 |
gcc_assert (e->inline_failed); |
| 5652 |
} |
| 5653 |
|
| 5654 |
/* If we didn't inline into the function there is nothing to do. */ |
| 5655 |
if (!inlined_p) |
| 5656 |
{ |
| 5657 |
delete id.statements_to_fold; |
| 5658 |
return 0; |
| 5659 |
} |
| 5660 |
|
| 5661 |
/* Fold queued statements. */ |
| 5662 |
update_max_bb_count (); |
| 5663 |
fold_marked_statements (last, id.statements_to_fold); |
| 5664 |
delete id.statements_to_fold; |
| 5665 |
|
| 5666 |
/* Finally purge EH and abnormal edges from the call stmts we inlined. |
| 5667 |
We need to do this after fold_marked_statements since that may walk |
| 5668 |
the SSA use-def chain. */ |
| 5669 |
unsigned i; |
| 5670 |
bitmap_iterator bi; |
| 5671 |
EXECUTE_IF_SET_IN_BITMAP (to_purge, 0, i, bi) |
| 5672 |
{ |
| 5673 |
basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i); |
| 5674 |
if (bb) |
| 5675 |
{ |
| 5676 |
gimple_purge_dead_eh_edges (bb); |
| 5677 |
gimple_purge_dead_abnormal_call_edges (bb); |
| 5678 |
} |
| 5679 |
} |
| 5680 |
|
| 5681 |
gcc_assert (!id.debug_stmts.exists ()); |
| 5682 |
|
| 5683 |
/* Renumber the lexical scoping (non-code) blocks consecutively. */ |
| 5684 |
number_blocks (fn); |
| 5685 |
|
| 5686 |
delete_unreachable_blocks_update_callgraph (id.dst_node, false); |
| 5687 |
id.dst_node->calls_comdat_local = id.dst_node->check_calls_comdat_local_p (); |
| 5688 |
|
| 5689 |
if (flag_checking) |
| 5690 |
id.dst_node->verify (); |
| 5691 |
|
| 5692 |
/* It would be nice to check SSA/CFG/statement consistency here, but it is |
| 5693 |
not possible yet - the IPA passes might make various functions to not |
| 5694 |
throw and they don't care to proactively update local EH info. This is |
| 5695 |
done later in fixup_cfg pass that also execute the verification. */ |
| 5696 |
return (TODO_update_ssa |
| 5697 |
| TODO_cleanup_cfg |
| 5698 |
| (gimple_in_ssa_p (cfun) ? TODO_remove_unused_locals : 0) |
| 5699 |
| (gimple_in_ssa_p (cfun) ? TODO_update_address_taken : 0)); |
| 5700 |
} |
| 5701 |
|
| 5702 |
/* Passed to walk_tree. Copies the node pointed to, if appropriate. */ |
| 5703 |
|
| 5704 |
tree |
| 5705 |
copy_tree_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) |
| 5706 |
{ |
| 5707 |
enum tree_code code = TREE_CODE (*tp); |
| 5708 |
enum tree_code_class cl = TREE_CODE_CLASS (code); |
| 5709 |
|
| 5710 |
/* We make copies of most nodes. */ |
| 5711 |
if (IS_EXPR_CODE_CLASS (cl) |
| 5712 |
|| code == TREE_LIST |
| 5713 |
|| code == TREE_VEC |
| 5714 |
|| code == TYPE_DECL |
| 5715 |
|| code == OMP_CLAUSE) |
| 5716 |
{ |
| 5717 |
/* Because the chain gets clobbered when we make a copy, we save it |
| 5718 |
here. */ |
| 5719 |
tree chain = NULL_TREE, new_tree; |
| 5720 |
|
| 5721 |
if (CODE_CONTAINS_STRUCT (code, TS_COMMON)) |
| 5722 |
chain = TREE_CHAIN (*tp); |
| 5723 |
|
| 5724 |
/* Copy the node. */ |
| 5725 |
new_tree = copy_node (*tp); |
| 5726 |
|
| 5727 |
*tp = new_tree; |
| 5728 |
|
| 5729 |
/* Now, restore the chain, if appropriate. That will cause |
| 5730 |
walk_tree to walk into the chain as well. */ |
| 5731 |
if (code == PARM_DECL |
| 5732 |
|| code == TREE_LIST |
| 5733 |
|| code == OMP_CLAUSE) |
| 5734 |
TREE_CHAIN (*tp) = chain; |
| 5735 |
|
| 5736 |
/* For now, we don't update BLOCKs when we make copies. So, we |
| 5737 |
have to nullify all BIND_EXPRs. */ |
| 5738 |
if (TREE_CODE (*tp) == BIND_EXPR) |
| 5739 |
BIND_EXPR_BLOCK (*tp) = NULL_TREE; |
| 5740 |
} |
| 5741 |
else if (code == CONSTRUCTOR) |
| 5742 |
{ |
| 5743 |
/* CONSTRUCTOR nodes need special handling because |
| 5744 |
we need to duplicate the vector of elements. */ |
| 5745 |
tree new_tree; |
| 5746 |
|
| 5747 |
new_tree = copy_node (*tp); |
| 5748 |
CONSTRUCTOR_ELTS (new_tree) = vec_safe_copy (CONSTRUCTOR_ELTS (*tp)); |
| 5749 |
*tp = new_tree; |
| 5750 |
} |
| 5751 |
else if (code == STATEMENT_LIST) |
| 5752 |
/* We used to just abort on STATEMENT_LIST, but we can run into them |
| 5753 |
with statement-expressions (c++/40975). */ |
| 5754 |
copy_statement_list (tp); |
| 5755 |
else if (TREE_CODE_CLASS (code) == tcc_type) |
| 5756 |
*walk_subtrees = 0; |
| 5757 |
else if (TREE_CODE_CLASS (code) == tcc_declaration) |
| 5758 |
*walk_subtrees = 0; |
| 5759 |
else if (TREE_CODE_CLASS (code) == tcc_constant) |
| 5760 |
*walk_subtrees = 0; |
| 5761 |
return NULL_TREE; |
| 5762 |
} |
| 5763 |
|
| 5764 |
/* The SAVE_EXPR pointed to by TP is being copied. If ST contains |
| 5765 |
information indicating to what new SAVE_EXPR this one should be mapped, |
| 5766 |
use that one. Otherwise, create a new node and enter it in ST. FN is |
| 5767 |
the function into which the copy will be placed. */ |
| 5768 |
|
| 5769 |
static void |
| 5770 |
remap_save_expr (tree *tp, hash_map<tree, tree> *st, int *walk_subtrees) |
| 5771 |
{ |
| 5772 |
tree *n; |
| 5773 |
tree t; |
| 5774 |
|
| 5775 |
/* See if we already encountered this SAVE_EXPR. */ |
| 5776 |
n = st->get (*tp); |
| 5777 |
|
| 5778 |
/* If we didn't already remap this SAVE_EXPR, do so now. */ |
| 5779 |
if (!n) |
| 5780 |
{ |
| 5781 |
t = copy_node (*tp); |
| 5782 |
|
| 5783 |
/* Remember this SAVE_EXPR. */ |
| 5784 |
st->put (*tp, t); |
| 5785 |
/* Make sure we don't remap an already-remapped SAVE_EXPR. */ |
| 5786 |
st->put (t, t); |
| 5787 |
} |
| 5788 |
else |
| 5789 |
{ |
| 5790 |
/* We've already walked into this SAVE_EXPR; don't do it again. */ |
| 5791 |
*walk_subtrees = 0; |
| 5792 |
t = *n; |
| 5793 |
} |
| 5794 |
|
| 5795 |
/* Replace this SAVE_EXPR with the copy. */ |
| 5796 |
*tp = t; |
| 5797 |
} |
| 5798 |
|
| 5799 |
/* Called via walk_gimple_seq. If *GSIP points to a GIMPLE_LABEL for a local |
| 5800 |
label, copies the declaration and enters it in the splay_tree in DATA (which |
| 5801 |
is really a 'copy_body_data *'. */ |
| 5802 |
|
| 5803 |
static tree |
| 5804 |
mark_local_labels_stmt (gimple_stmt_iterator *gsip, |
| 5805 |
bool *handled_ops_p ATTRIBUTE_UNUSED, |
| 5806 |
struct walk_stmt_info *wi) |
| 5807 |
{ |
| 5808 |
copy_body_data *id = (copy_body_data *) wi->info; |
| 5809 |
glabel *stmt = dyn_cast <glabel *> (gsi_stmt (*gsip)); |
| 5810 |
|
| 5811 |
if (stmt) |
| 5812 |
{ |
| 5813 |
tree decl = gimple_label_label (stmt); |
| 5814 |
|
| 5815 |
/* Copy the decl and remember the copy. */ |
| 5816 |
insert_decl_map (id, decl, id->copy_decl (decl, id)); |
| 5817 |
} |
| 5818 |
|
| 5819 |
return NULL_TREE; |
| 5820 |
} |
| 5821 |
|
| 5822 |
static gimple_seq duplicate_remap_omp_clause_seq (gimple_seq seq, |
| 5823 |
struct walk_stmt_info *wi); |
| 5824 |
|
| 5825 |
/* Called via walk_gimple_seq by copy_gimple_seq_and_replace_local. |
| 5826 |
Using the splay_tree pointed to by ST (which is really a `splay_tree'), |
| 5827 |
remaps all local declarations to appropriate replacements in gimple |
| 5828 |
operands. */ |
| 5829 |
|
| 5830 |
static tree |
| 5831 |
replace_locals_op (tree *tp, int *walk_subtrees, void *data) |
| 5832 |
{ |
| 5833 |
struct walk_stmt_info *wi = (struct walk_stmt_info*) data; |
| 5834 |
copy_body_data *id = (copy_body_data *) wi->info; |
| 5835 |
hash_map<tree, tree> *st = id->decl_map; |
| 5836 |
tree *n; |
| 5837 |
tree expr = *tp; |
| 5838 |
|
| 5839 |
/* For recursive invocations this is no longer the LHS itself. */ |
| 5840 |
bool is_lhs = wi->is_lhs; |
| 5841 |
wi->is_lhs = false; |
| 5842 |
|
| 5843 |
if (TREE_CODE (expr) == SSA_NAME) |
| 5844 |
{ |
| 5845 |
*tp = remap_ssa_name (*tp, id); |
| 5846 |
*walk_subtrees = 0; |
| 5847 |
if (is_lhs) |
| 5848 |
SSA_NAME_DEF_STMT (*tp) = gsi_stmt (wi->gsi); |
| 5849 |
} |
| 5850 |
/* Only a local declaration (variable or label). */ |
| 5851 |
else if ((VAR_P (expr) && !TREE_STATIC (expr)) |
| 5852 |
|| TREE_CODE (expr) == LABEL_DECL) |
| 5853 |
{ |
| 5854 |
/* Lookup the declaration. */ |
| 5855 |
n = st->get (expr); |
| 5856 |
|
| 5857 |
/* If it's there, remap it. */ |
| 5858 |
if (n) |
| 5859 |
*tp = *n; |
| 5860 |
*walk_subtrees = 0; |
| 5861 |
} |
| 5862 |
else if (TREE_CODE (expr) == STATEMENT_LIST |
| 5863 |
|| TREE_CODE (expr) == BIND_EXPR |
| 5864 |
|| TREE_CODE (expr) == SAVE_EXPR) |
| 5865 |
gcc_unreachable (); |
| 5866 |
else if (TREE_CODE (expr) == TARGET_EXPR) |
| 5867 |
{ |
| 5868 |
/* Don't mess with a TARGET_EXPR that hasn't been expanded. |
| 5869 |
It's OK for this to happen if it was part of a subtree that |
| 5870 |
isn't immediately expanded, such as operand 2 of another |
| 5871 |
TARGET_EXPR. */ |
| 5872 |
if (!TREE_OPERAND (expr, 1)) |
| 5873 |
{ |
| 5874 |
TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3); |
| 5875 |
TREE_OPERAND (expr, 3) = NULL_TREE; |
| 5876 |
} |
| 5877 |
} |
| 5878 |
else if (TREE_CODE (expr) == OMP_CLAUSE) |
| 5879 |
{ |
| 5880 |
/* Before the omplower pass completes, some OMP clauses can contain |
| 5881 |
sequences that are neither copied by gimple_seq_copy nor walked by |
| 5882 |
walk_gimple_seq. To make copy_gimple_seq_and_replace_locals work even |
| 5883 |
in those situations, we have to copy and process them explicitely. */ |
| 5884 |
|
| 5885 |
if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_LASTPRIVATE) |
| 5886 |
{ |
| 5887 |
gimple_seq seq = OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (expr); |
| 5888 |
seq = duplicate_remap_omp_clause_seq (seq, wi); |
| 5889 |
OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (expr) = seq; |
| 5890 |
} |
| 5891 |
else if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_LINEAR) |
| 5892 |
{ |
| 5893 |
gimple_seq seq = OMP_CLAUSE_LINEAR_GIMPLE_SEQ (expr); |
| 5894 |
seq = duplicate_remap_omp_clause_seq (seq, wi); |
| 5895 |
OMP_CLAUSE_LINEAR_GIMPLE_SEQ (expr) = seq; |
| 5896 |
} |
| 5897 |
else if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_REDUCTION) |
| 5898 |
{ |
| 5899 |
gimple_seq seq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr); |
| 5900 |
seq = duplicate_remap_omp_clause_seq (seq, wi); |
| 5901 |
OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr) = seq; |
| 5902 |
seq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr); |
| 5903 |
seq = duplicate_remap_omp_clause_seq (seq, wi); |
| 5904 |
OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr) = seq; |
| 5905 |
} |
| 5906 |
} |
| 5907 |
|
| 5908 |
/* Keep iterating. */ |
| 5909 |
return NULL_TREE; |
| 5910 |
} |
| 5911 |
|
| 5912 |
|
| 5913 |
/* Called via walk_gimple_seq by copy_gimple_seq_and_replace_local. |
| 5914 |
Using the splay_tree pointed to by ST (which is really a `splay_tree'), |
| 5915 |
remaps all local declarations to appropriate replacements in gimple |
| 5916 |
statements. */ |
| 5917 |
|
| 5918 |
static tree |
| 5919 |
replace_locals_stmt (gimple_stmt_iterator *gsip, |
| 5920 |
bool *handled_ops_p ATTRIBUTE_UNUSED, |
| 5921 |
struct walk_stmt_info *wi) |
| 5922 |
{ |
| 5923 |
copy_body_data *id = (copy_body_data *) wi->info; |
| 5924 |
gimple *gs = gsi_stmt (*gsip); |
| 5925 |
|
| 5926 |
if (gbind *stmt = dyn_cast <gbind *> (gs)) |
| 5927 |
{ |
| 5928 |
tree block = gimple_bind_block (stmt); |
| 5929 |
|
| 5930 |
if (block) |
| 5931 |
{ |
| 5932 |
remap_block (&block, id); |
| 5933 |
gimple_bind_set_block (stmt, block); |
| 5934 |
} |
| 5935 |
|
| 5936 |
/* This will remap a lot of the same decls again, but this should be |
| 5937 |
harmless. */ |
| 5938 |
if (gimple_bind_vars (stmt)) |
| 5939 |
{ |
| 5940 |
tree old_var, decls = gimple_bind_vars (stmt); |
| 5941 |
|
| 5942 |
for (old_var = decls; old_var; old_var = DECL_CHAIN (old_var)) |
| 5943 |
if (!can_be_nonlocal (old_var, id) |
| 5944 |
&& ! variably_modified_type_p (TREE_TYPE (old_var), id->src_fn)) |
| 5945 |
remap_decl (old_var, id); |
| 5946 |
|
| 5947 |
gcc_checking_assert (!id->prevent_decl_creation_for_types); |
| 5948 |
id->prevent_decl_creation_for_types = true; |
| 5949 |
gimple_bind_set_vars (stmt, remap_decls (decls, NULL, id)); |
| 5950 |
id->prevent_decl_creation_for_types = false; |
| 5951 |
} |
| 5952 |
} |
| 5953 |
|
| 5954 |
/* Keep iterating. */ |
| 5955 |
return NULL_TREE; |
| 5956 |
} |
| 5957 |
|
| 5958 |
/* Create a copy of SEQ and remap all decls in it. */ |
| 5959 |
|
| 5960 |
static gimple_seq |
| 5961 |
duplicate_remap_omp_clause_seq (gimple_seq seq, struct walk_stmt_info *wi) |
| 5962 |
{ |
| 5963 |
if (!seq) |
| 5964 |
return NULL; |
| 5965 |
|
| 5966 |
/* If there are any labels in OMP sequences, they can be only referred to in |
| 5967 |
the sequence itself and therefore we can do both here. */ |
| 5968 |
walk_gimple_seq (seq, mark_local_labels_stmt, NULL, wi); |
| 5969 |
gimple_seq copy = gimple_seq_copy (seq); |
| 5970 |
walk_gimple_seq (copy, replace_locals_stmt, replace_locals_op, wi); |
| 5971 |
return copy; |
| 5972 |
} |
| 5973 |
|
| 5974 |
/* Copies everything in SEQ and replaces variables and labels local to |
| 5975 |
current_function_decl. */ |
| 5976 |
|
| 5977 |
gimple_seq |
| 5978 |
copy_gimple_seq_and_replace_locals (gimple_seq seq) |
| 5979 |
{ |
| 5980 |
copy_body_data id; |
| 5981 |
struct walk_stmt_info wi; |
| 5982 |
gimple_seq copy; |
| 5983 |
|
| 5984 |
/* There's nothing to do for NULL_TREE. */ |
| 5985 |
if (seq == NULL) |
| 5986 |
return seq; |
| 5987 |
|
| 5988 |
/* Set up ID. */ |
| 5989 |
memset (&id, 0, sizeof (id)); |
| 5990 |
id.src_fn = current_function_decl; |
| 5991 |
id.dst_fn = current_function_decl; |
| 5992 |
id.src_cfun = cfun; |
| 5993 |
id.decl_map = new hash_map<tree, tree>; |
| 5994 |
id.debug_map = NULL; |
| 5995 |
|
| 5996 |
id.copy_decl = copy_decl_no_change; |
| 5997 |
id.transform_call_graph_edges = CB_CGE_DUPLICATE; |
| 5998 |
id.transform_new_cfg = false; |
| 5999 |
id.transform_return_to_modify = false; |
| 6000 |
id.transform_parameter = false; |
| 6001 |
|
| 6002 |
/* Walk the tree once to find local labels. */ |
| 6003 |
memset (&wi, 0, sizeof (wi)); |
| 6004 |
hash_set<tree> visited; |
| 6005 |
wi.info = &id; |
| 6006 |
wi.pset = &visited; |
| 6007 |
walk_gimple_seq (seq, mark_local_labels_stmt, NULL, &wi); |
| 6008 |
|
| 6009 |
copy = gimple_seq_copy (seq); |
| 6010 |
|
| 6011 |
/* Walk the copy, remapping decls. */ |
| 6012 |
memset (&wi, 0, sizeof (wi)); |
| 6013 |
wi.info = &id; |
| 6014 |
walk_gimple_seq (copy, replace_locals_stmt, replace_locals_op, &wi); |
| 6015 |
|
| 6016 |
/* Clean up. */ |
| 6017 |
delete id.decl_map; |
| 6018 |
if (id.debug_map) |
| 6019 |
delete id.debug_map; |
| 6020 |
if (id.dependence_map) |
| 6021 |
{ |
| 6022 |
delete id.dependence_map; |
| 6023 |
id.dependence_map = NULL; |
| 6024 |
} |
| 6025 |
|
| 6026 |
return copy; |
| 6027 |
} |
| 6028 |
|
| 6029 |
|
| 6030 |
/* Allow someone to determine if SEARCH is a child of TOP from gdb. */ |
| 6031 |
|
| 6032 |
static tree |
| 6033 |
debug_find_tree_1 (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, void *data) |
| 6034 |
{ |
| 6035 |
if (*tp == data) |
| 6036 |
return (tree) data; |
| 6037 |
else |
| 6038 |
return NULL; |
| 6039 |
} |
| 6040 |
|
| 6041 |
DEBUG_FUNCTION bool |
| 6042 |
debug_find_tree (tree top, tree search) |
| 6043 |
{ |
| 6044 |
return walk_tree_without_duplicates (&top, debug_find_tree_1, search) != 0; |
| 6045 |
} |
| 6046 |
|
| 6047 |
|
| 6048 |
/* Declare the variables created by the inliner. Add all the variables in |
| 6049 |
VARS to BIND_EXPR. */ |
| 6050 |
|
| 6051 |
static void |
| 6052 |
declare_inline_vars (tree block, tree vars) |
| 6053 |
{ |
| 6054 |
tree t; |
| 6055 |
for (t = vars; t; t = DECL_CHAIN (t)) |
| 6056 |
{ |
| 6057 |
DECL_SEEN_IN_BIND_EXPR_P (t) = 1; |
| 6058 |
gcc_assert (!TREE_STATIC (t) && !TREE_ASM_WRITTEN (t)); |
| 6059 |
add_local_decl (cfun, t); |
| 6060 |
} |
| 6061 |
|
| 6062 |
if (block) |
| 6063 |
BLOCK_VARS (block) = chainon (BLOCK_VARS (block), vars); |
| 6064 |
} |
| 6065 |
|
| 6066 |
/* Copy NODE (which must be a DECL). The DECL originally was in the FROM_FN, |
| 6067 |
but now it will be in the TO_FN. PARM_TO_VAR means enable PARM_DECL to |
| 6068 |
VAR_DECL translation. */ |
| 6069 |
|
| 6070 |
tree |
| 6071 |
copy_decl_for_dup_finish (copy_body_data *id, tree decl, tree copy) |
| 6072 |
{ |
| 6073 |
/* Don't generate debug information for the copy if we wouldn't have |
| 6074 |
generated it for the copy either. */ |
| 6075 |
DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (decl); |
| 6076 |
DECL_IGNORED_P (copy) = DECL_IGNORED_P (decl); |
| 6077 |
|
| 6078 |
/* Set the DECL_ABSTRACT_ORIGIN so the debugging routines know what |
| 6079 |
declaration inspired this copy. */ |
| 6080 |
DECL_ABSTRACT_ORIGIN (copy) = DECL_ORIGIN (decl); |
| 6081 |
|
| 6082 |
/* The new variable/label has no RTL, yet. */ |
| 6083 |
if (HAS_RTL_P (copy) |
| 6084 |
&& !TREE_STATIC (copy) && !DECL_EXTERNAL (copy)) |
| 6085 |
SET_DECL_RTL (copy, 0); |
| 6086 |
/* For vector typed decls make sure to update DECL_MODE according |
| 6087 |
to the new function context. */ |
| 6088 |
if (VECTOR_TYPE_P (TREE_TYPE (copy))) |
| 6089 |
SET_DECL_MODE (copy, TYPE_MODE (TREE_TYPE (copy))); |
| 6090 |
|
| 6091 |
/* These args would always appear unused, if not for this. */ |
| 6092 |
TREE_USED (copy) = 1; |
| 6093 |
|
| 6094 |
/* Set the context for the new declaration. */ |
| 6095 |
if (!DECL_CONTEXT (decl)) |
| 6096 |
/* Globals stay global. */ |
| 6097 |
; |
| 6098 |
else if (DECL_CONTEXT (decl) != id->src_fn) |
| 6099 |
/* Things that weren't in the scope of the function we're inlining |
| 6100 |
from aren't in the scope we're inlining to, either. */ |
| 6101 |
; |
| 6102 |
else if (TREE_STATIC (decl)) |
| 6103 |
/* Function-scoped static variables should stay in the original |
| 6104 |
function. */ |
| 6105 |
; |
| 6106 |
else |
| 6107 |
{ |
| 6108 |
/* Ordinary automatic local variables are now in the scope of the |
| 6109 |
new function. */ |
| 6110 |
DECL_CONTEXT (copy) = id->dst_fn; |
| 6111 |
if (VAR_P (copy) && id->dst_simt_vars && !is_gimple_reg (copy)) |
| 6112 |
{ |
| 6113 |
if (!lookup_attribute ("omp simt private", DECL_ATTRIBUTES (copy))) |
| 6114 |
DECL_ATTRIBUTES (copy) |
| 6115 |
= tree_cons (get_identifier ("omp simt private"), NULL, |
| 6116 |
DECL_ATTRIBUTES (copy)); |
| 6117 |
id->dst_simt_vars->safe_push (copy); |
| 6118 |
} |
| 6119 |
} |
| 6120 |
|
| 6121 |
return copy; |
| 6122 |
} |
| 6123 |
|
| 6124 |
/* Create a new VAR_DECL that is indentical in all respect to DECL except that |
| 6125 |
DECL can be either a VAR_DECL, a PARM_DECL or RESULT_DECL. The original |
| 6126 |
DECL must come from ID->src_fn and the copy will be part of ID->dst_fn. */ |
| 6127 |
|
| 6128 |
tree |
| 6129 |
copy_decl_to_var (tree decl, copy_body_data *id) |
| 6130 |
{ |
| 6131 |
tree copy, type; |
| 6132 |
|
| 6133 |
gcc_assert (TREE_CODE (decl) == PARM_DECL |
| 6134 |
|| TREE_CODE (decl) == RESULT_DECL); |
| 6135 |
|
| 6136 |
type = TREE_TYPE (decl); |
| 6137 |
|
| 6138 |
copy = build_decl (DECL_SOURCE_LOCATION (id->dst_fn), |
| 6139 |
VAR_DECL, DECL_NAME (decl), type); |
| 6140 |
if (DECL_PT_UID_SET_P (decl)) |
| 6141 |
SET_DECL_PT_UID (copy, DECL_PT_UID (decl)); |
| 6142 |
TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl); |
| 6143 |
TREE_READONLY (copy) = TREE_READONLY (decl); |
| 6144 |
TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl); |
| 6145 |
DECL_NOT_GIMPLE_REG_P (copy) = DECL_NOT_GIMPLE_REG_P (decl); |
| 6146 |
DECL_BY_REFERENCE (copy) = DECL_BY_REFERENCE (decl); |
| 6147 |
|
| 6148 |
return copy_decl_for_dup_finish (id, decl, copy); |
| 6149 |
} |
| 6150 |
|
| 6151 |
/* Like copy_decl_to_var, but create a return slot object instead of a |
| 6152 |
pointer variable for return by invisible reference. */ |
| 6153 |
|
| 6154 |
static tree |
| 6155 |
copy_result_decl_to_var (tree decl, copy_body_data *id) |
| 6156 |
{ |
| 6157 |
tree copy, type; |
| 6158 |
|
| 6159 |
gcc_assert (TREE_CODE (decl) == PARM_DECL |
| 6160 |
|| TREE_CODE (decl) == RESULT_DECL); |
| 6161 |
|
| 6162 |
type = TREE_TYPE (decl); |
| 6163 |
if (DECL_BY_REFERENCE (decl)) |
| 6164 |
type = TREE_TYPE (type); |
| 6165 |
|
| 6166 |
copy = build_decl (DECL_SOURCE_LOCATION (id->dst_fn), |
| 6167 |
VAR_DECL, DECL_NAME (decl), type); |
| 6168 |
if (DECL_PT_UID_SET_P (decl)) |
| 6169 |
SET_DECL_PT_UID (copy, DECL_PT_UID (decl)); |
| 6170 |
TREE_READONLY (copy) = TREE_READONLY (decl); |
| 6171 |
TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl); |
| 6172 |
if (!DECL_BY_REFERENCE (decl)) |
| 6173 |
{ |
| 6174 |
TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl); |
| 6175 |
DECL_NOT_GIMPLE_REG_P (copy) |
| 6176 |
= (DECL_NOT_GIMPLE_REG_P (decl) |
| 6177 |
/* RESULT_DECLs are treated special by needs_to_live_in_memory, |
| 6178 |
mirror that to the created VAR_DECL. */ |
| 6179 |
|| (TREE_CODE (decl) == RESULT_DECL |
| 6180 |
&& aggregate_value_p (decl, id->src_fn))); |
| 6181 |
} |
| 6182 |
|
| 6183 |
return copy_decl_for_dup_finish (id, decl, copy); |
| 6184 |
} |
| 6185 |
|
| 6186 |
tree |
| 6187 |
copy_decl_no_change (tree decl, copy_body_data *id) |
| 6188 |
{ |
| 6189 |
tree copy; |
| 6190 |
|
| 6191 |
copy = copy_node (decl); |
| 6192 |
|
| 6193 |
/* The COPY is not abstract; it will be generated in DST_FN. */ |
| 6194 |
DECL_ABSTRACT_P (copy) = false; |
| 6195 |
lang_hooks.dup_lang_specific_decl (copy); |
| 6196 |
|
| 6197 |
/* TREE_ADDRESSABLE isn't used to indicate that a label's address has |
| 6198 |
been taken; it's for internal bookkeeping in expand_goto_internal. */ |
| 6199 |
if (TREE_CODE (copy) == LABEL_DECL) |
| 6200 |
{ |
| 6201 |
TREE_ADDRESSABLE (copy) = 0; |
| 6202 |
LABEL_DECL_UID (copy) = -1; |
| 6203 |
} |
| 6204 |
|
| 6205 |
return copy_decl_for_dup_finish (id, decl, copy); |
| 6206 |
} |
| 6207 |
|
| 6208 |
static tree |
| 6209 |
copy_decl_maybe_to_var (tree decl, copy_body_data *id) |
| 6210 |
{ |
| 6211 |
if (TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL) |
| 6212 |
return copy_decl_to_var (decl, id); |
| 6213 |
else |
| 6214 |
return copy_decl_no_change (decl, id); |
| 6215 |
} |
| 6216 |
|
| 6217 |
/* Return a copy of the function's argument tree without any modifications. */ |
| 6218 |
|
| 6219 |
static tree |
| 6220 |
copy_arguments_nochange (tree orig_parm, copy_body_data * id) |
| 6221 |
{ |
| 6222 |
tree arg, *parg; |
| 6223 |
tree new_parm = NULL; |
| 6224 |
|
| 6225 |
parg = &new_parm; |
| 6226 |
for (arg = orig_parm; arg; arg = DECL_CHAIN (arg)) |
| 6227 |
{ |
| 6228 |
tree new_tree = remap_decl (arg, id); |
| 6229 |
if (TREE_CODE (new_tree) != PARM_DECL) |
| 6230 |
new_tree = id->copy_decl (arg, id); |
| 6231 |
lang_hooks.dup_lang_specific_decl (new_tree); |
| 6232 |
*parg = new_tree; |
| 6233 |
parg = &DECL_CHAIN (new_tree); |
| 6234 |
} |
| 6235 |
return new_parm; |
| 6236 |
} |
| 6237 |
|
| 6238 |
/* Return a copy of the function's static chain. */ |
| 6239 |
static tree |
| 6240 |
copy_static_chain (tree static_chain, copy_body_data * id) |
| 6241 |
{ |
| 6242 |
tree *chain_copy, *pvar; |
| 6243 |
|
| 6244 |
chain_copy = &static_chain; |
| 6245 |
for (pvar = chain_copy; *pvar; pvar = &DECL_CHAIN (*pvar)) |
| 6246 |
{ |
| 6247 |
tree new_tree = remap_decl (*pvar, id); |
| 6248 |
lang_hooks.dup_lang_specific_decl (new_tree); |
| 6249 |
DECL_CHAIN (new_tree) = DECL_CHAIN (*pvar); |
| 6250 |
*pvar = new_tree; |
| 6251 |
} |
| 6252 |
return static_chain; |
| 6253 |
} |
| 6254 |
|
| 6255 |
/* Return true if the function is allowed to be versioned. |
| 6256 |
This is a guard for the versioning functionality. */ |
| 6257 |
|
| 6258 |
bool |
| 6259 |
tree_versionable_function_p (tree fndecl) |
| 6260 |
{ |
| 6261 |
return (!lookup_attribute ("noclone", DECL_ATTRIBUTES (fndecl)) |
| 6262 |
&& copy_forbidden (DECL_STRUCT_FUNCTION (fndecl)) == NULL); |
| 6263 |
} |
| 6264 |
|
| 6265 |
/* Update clone info after duplication. */ |
| 6266 |
|
| 6267 |
static void |
| 6268 |
update_clone_info (copy_body_data * id) |
| 6269 |
{ |
| 6270 |
struct cgraph_node *this_node = id->dst_node; |
| 6271 |
if (!this_node->clones) |
| 6272 |
return; |
| 6273 |
for (cgraph_node *node = this_node->clones; node != this_node;) |
| 6274 |
{ |
| 6275 |
/* First update replace maps to match the new body. */ |
| 6276 |
clone_info *info = clone_info::get (node); |
| 6277 |
if (info && info->tree_map) |
| 6278 |
{ |
| 6279 |
unsigned int i; |
| 6280 |
for (i = 0; i < vec_safe_length (info->tree_map); i++) |
| 6281 |
{ |
| 6282 |
struct ipa_replace_map *replace_info; |
| 6283 |
replace_info = (*info->tree_map)[i]; |
| 6284 |
walk_tree (&replace_info->new_tree, copy_tree_body_r, id, NULL); |
| 6285 |
} |
| 6286 |
} |
| 6287 |
|
| 6288 |
if (node->clones) |
| 6289 |
node = node->clones; |
| 6290 |
else if (node->next_sibling_clone) |
| 6291 |
node = node->next_sibling_clone; |
| 6292 |
else |
| 6293 |
{ |
| 6294 |
while (node != id->dst_node && !node->next_sibling_clone) |
| 6295 |
node = node->clone_of; |
| 6296 |
if (node != id->dst_node) |
| 6297 |
node = node->next_sibling_clone; |
| 6298 |
} |
| 6299 |
} |
| 6300 |
} |
| 6301 |
|
| 6302 |
/* Create a copy of a function's tree. |
| 6303 |
OLD_DECL and NEW_DECL are FUNCTION_DECL tree nodes |
| 6304 |
of the original function and the new copied function |
| 6305 |
respectively. In case we want to replace a DECL |
| 6306 |
tree with another tree while duplicating the function's |
| 6307 |
body, TREE_MAP represents the mapping between these |
| 6308 |
trees. If UPDATE_CLONES is set, the call_stmt fields |
| 6309 |
of edges of clones of the function will be updated. |
| 6310 |
|
| 6311 |
If non-NULL PARAM_ADJUSTMENTS determines how function prototype (i.e. the |
| 6312 |
function parameters and return value) should be modified). |
| 6313 |
If non-NULL BLOCKS_TO_COPY determine what basic blocks to copy. |
| 6314 |
If non_NULL NEW_ENTRY determine new entry BB of the clone. |
| 6315 |
*/ |
| 6316 |
void |
| 6317 |
tree_function_versioning (tree old_decl, tree new_decl, |
| 6318 |
vec<ipa_replace_map *, va_gc> *tree_map, |
| 6319 |
ipa_param_adjustments *param_adjustments, |
| 6320 |
bool update_clones, bitmap blocks_to_copy, |
| 6321 |
basic_block new_entry) |
| 6322 |
{ |
| 6323 |
struct cgraph_node *old_version_node; |
| 6324 |
struct cgraph_node *new_version_node; |
| 6325 |
copy_body_data id; |
| 6326 |
tree p; |
| 6327 |
unsigned i; |
| 6328 |
struct ipa_replace_map *replace_info; |
| 6329 |
basic_block old_entry_block, bb; |
| 6330 |
auto_vec<gimple *, 10> init_stmts; |
| 6331 |
tree vars = NULL_TREE; |
| 6332 |
|
| 6333 |
/* We can get called recursively from expand_call_inline via clone |
| 6334 |
materialization. While expand_call_inline maintains input_location |
| 6335 |
we cannot tolerate it to leak into the materialized clone. */ |
| 6336 |
location_t saved_location = input_location; |
| 6337 |
input_location = UNKNOWN_LOCATION; |
| 6338 |
|
| 6339 |
gcc_assert (TREE_CODE (old_decl) == FUNCTION_DECL |
| 6340 |
&& TREE_CODE (new_decl) == FUNCTION_DECL); |
| 6341 |
DECL_POSSIBLY_INLINED (old_decl) = 1; |
| 6342 |
|
| 6343 |
old_version_node = cgraph_node::get (old_decl); |
| 6344 |
gcc_checking_assert (old_version_node); |
| 6345 |
new_version_node = cgraph_node::get (new_decl); |
| 6346 |
gcc_checking_assert (new_version_node); |
| 6347 |
|
| 6348 |
/* Copy over debug args. */ |
| 6349 |
if (DECL_HAS_DEBUG_ARGS_P (old_decl)) |
| 6350 |
{ |
| 6351 |
vec<tree, va_gc> **new_debug_args, **old_debug_args; |
| 6352 |
gcc_checking_assert (decl_debug_args_lookup (new_decl) == NULL); |
| 6353 |
DECL_HAS_DEBUG_ARGS_P (new_decl) = 0; |
| 6354 |
old_debug_args = decl_debug_args_lookup (old_decl); |
| 6355 |
if (old_debug_args) |
| 6356 |
{ |
| 6357 |
new_debug_args = decl_debug_args_insert (new_decl); |
| 6358 |
*new_debug_args = vec_safe_copy (*old_debug_args); |
| 6359 |
} |
| 6360 |
} |
| 6361 |
|
| 6362 |
/* Output the inlining info for this abstract function, since it has been |
| 6363 |
inlined. If we don't do this now, we can lose the information about the |
| 6364 |
variables in the function when the blocks get blown away as soon as we |
| 6365 |
remove the cgraph node. */ |
| 6366 |
(*debug_hooks->outlining_inline_function) (old_decl); |
| 6367 |
|
| 6368 |
DECL_ARTIFICIAL (new_decl) = 1; |
| 6369 |
DECL_ABSTRACT_ORIGIN (new_decl) = DECL_ORIGIN (old_decl); |
| 6370 |
if (DECL_ORIGIN (old_decl) == old_decl) |
| 6371 |
old_version_node->used_as_abstract_origin = true; |
| 6372 |
DECL_FUNCTION_PERSONALITY (new_decl) = DECL_FUNCTION_PERSONALITY (old_decl); |
| 6373 |
|
| 6374 |
/* Prepare the data structures for the tree copy. */ |
| 6375 |
memset (&id, 0, sizeof (id)); |
| 6376 |
|
| 6377 |
/* Generate a new name for the new version. */ |
| 6378 |
id.statements_to_fold = new hash_set<gimple *>; |
| 6379 |
|
| 6380 |
id.decl_map = new hash_map<tree, tree>; |
| 6381 |
id.debug_map = NULL; |
| 6382 |
id.src_fn = old_decl; |
| 6383 |
id.dst_fn = new_decl; |
| 6384 |
id.src_node = old_version_node; |
| 6385 |
id.dst_node = new_version_node; |
| 6386 |
id.src_cfun = DECL_STRUCT_FUNCTION (old_decl); |
| 6387 |
id.blocks_to_copy = blocks_to_copy; |
| 6388 |
|
| 6389 |
id.copy_decl = copy_decl_no_change; |
| 6390 |
id.transform_call_graph_edges |
| 6391 |
= update_clones ? CB_CGE_MOVE_CLONES : CB_CGE_MOVE; |
| 6392 |
id.transform_new_cfg = true; |
| 6393 |
id.transform_return_to_modify = false; |
| 6394 |
id.transform_parameter = false; |
| 6395 |
|
| 6396 |
old_entry_block = ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (old_decl)); |
| 6397 |
DECL_RESULT (new_decl) = DECL_RESULT (old_decl); |
| 6398 |
DECL_ARGUMENTS (new_decl) = DECL_ARGUMENTS (old_decl); |
| 6399 |
initialize_cfun (new_decl, old_decl, |
| 6400 |
new_entry ? new_entry->count : old_entry_block->count); |
| 6401 |
new_version_node->has_omp_variant_constructs |
| 6402 |
= old_version_node->has_omp_variant_constructs; |
| 6403 |
if (DECL_STRUCT_FUNCTION (new_decl)->gimple_df) |
| 6404 |
DECL_STRUCT_FUNCTION (new_decl)->gimple_df->ipa_pta |
| 6405 |
= id.src_cfun->gimple_df->ipa_pta; |
| 6406 |
|
| 6407 |
/* Copy the function's static chain. */ |
| 6408 |
p = DECL_STRUCT_FUNCTION (old_decl)->static_chain_decl; |
| 6409 |
if (p) |
| 6410 |
DECL_STRUCT_FUNCTION (new_decl)->static_chain_decl |
| 6411 |
= copy_static_chain (p, &id); |
| 6412 |
|
| 6413 |
auto_vec<int, 16> new_param_indices; |
| 6414 |
clone_info *info = clone_info::get (old_version_node); |
| 6415 |
ipa_param_adjustments *old_param_adjustments |
| 6416 |
= info ? info->param_adjustments : NULL; |
| 6417 |
if (old_param_adjustments) |
| 6418 |
old_param_adjustments->get_updated_indices (&new_param_indices); |
| 6419 |
|
| 6420 |
/* If there's a tree_map, prepare for substitution. */ |
| 6421 |
if (tree_map) |
| 6422 |
for (i = 0; i < tree_map->length (); i++) |
| 6423 |
{ |
| 6424 |
gimple *init; |
| 6425 |
replace_info = (*tree_map)[i]; |
| 6426 |
|
| 6427 |
int p = replace_info->parm_num; |
| 6428 |
if (old_param_adjustments) |
| 6429 |
p = new_param_indices[p]; |
| 6430 |
|
| 6431 |
tree parm; |
| 6432 |
for (parm = DECL_ARGUMENTS (old_decl); p; |
| 6433 |
parm = DECL_CHAIN (parm)) |
| 6434 |
p--; |
| 6435 |
gcc_assert (parm); |
| 6436 |
init = setup_one_parameter (&id, parm, replace_info->new_tree, |
| 6437 |
id.src_fn, NULL, &vars); |
| 6438 |
if (init) |
| 6439 |
init_stmts.safe_push (init); |
| 6440 |
} |
| 6441 |
|
| 6442 |
ipa_param_body_adjustments *param_body_adjs = NULL; |
| 6443 |
if (param_adjustments) |
| 6444 |
{ |
| 6445 |
param_body_adjs = new ipa_param_body_adjustments (param_adjustments, |
| 6446 |
new_decl, old_decl, |
| 6447 |
&id, &vars, tree_map); |
| 6448 |
id.param_body_adjs = param_body_adjs; |
| 6449 |
DECL_ARGUMENTS (new_decl) = param_body_adjs->get_new_param_chain (); |
| 6450 |
} |
| 6451 |
else if (DECL_ARGUMENTS (old_decl) != NULL_TREE) |
| 6452 |
DECL_ARGUMENTS (new_decl) |
| 6453 |
= copy_arguments_nochange (DECL_ARGUMENTS (old_decl), &id); |
| 6454 |
|
| 6455 |
DECL_INITIAL (new_decl) = remap_blocks (DECL_INITIAL (id.src_fn), &id); |
| 6456 |
BLOCK_SUPERCONTEXT (DECL_INITIAL (new_decl)) = new_decl; |
| 6457 |
|
| 6458 |
declare_inline_vars (DECL_INITIAL (new_decl), vars); |
| 6459 |
|
| 6460 |
if (!vec_safe_is_empty (DECL_STRUCT_FUNCTION (old_decl)->local_decls)) |
| 6461 |
/* Add local vars. */ |
| 6462 |
add_local_variables (DECL_STRUCT_FUNCTION (old_decl), cfun, &id); |
| 6463 |
|
| 6464 |
if (DECL_RESULT (old_decl) == NULL_TREE) |
| 6465 |
; |
| 6466 |
else if (param_adjustments && param_adjustments->m_skip_return |
| 6467 |
&& !VOID_TYPE_P (TREE_TYPE (DECL_RESULT (old_decl)))) |
| 6468 |
{ |
| 6469 |
tree resdecl_repl = copy_result_decl_to_var (DECL_RESULT (old_decl), |
| 6470 |
&id); |
| 6471 |
declare_inline_vars (NULL, resdecl_repl); |
| 6472 |
if (DECL_BY_REFERENCE (DECL_RESULT (old_decl))) |
| 6473 |
resdecl_repl = build_fold_addr_expr (resdecl_repl); |
| 6474 |
insert_decl_map (&id, DECL_RESULT (old_decl), resdecl_repl); |
| 6475 |
|
| 6476 |
DECL_RESULT (new_decl) |
| 6477 |
= build_decl (DECL_SOURCE_LOCATION (DECL_RESULT (old_decl)), |
| 6478 |
RESULT_DECL, NULL_TREE, void_type_node); |
| 6479 |
DECL_CONTEXT (DECL_RESULT (new_decl)) = new_decl; |
| 6480 |
DECL_IS_MALLOC (new_decl) = false; |
| 6481 |
cfun->returns_struct = 0; |
| 6482 |
cfun->returns_pcc_struct = 0; |
| 6483 |
} |
| 6484 |
else |
| 6485 |
{ |
| 6486 |
tree old_name; |
| 6487 |
DECL_RESULT (new_decl) = remap_decl (DECL_RESULT (old_decl), &id); |
| 6488 |
lang_hooks.dup_lang_specific_decl (DECL_RESULT (new_decl)); |
| 6489 |
if (gimple_in_ssa_p (id.src_cfun) |
| 6490 |
&& DECL_BY_REFERENCE (DECL_RESULT (old_decl)) |
| 6491 |
&& (old_name = ssa_default_def (id.src_cfun, DECL_RESULT (old_decl)))) |
| 6492 |
{ |
| 6493 |
tree new_name = make_ssa_name (DECL_RESULT (new_decl)); |
| 6494 |
insert_decl_map (&id, old_name, new_name); |
| 6495 |
SSA_NAME_DEF_STMT (new_name) = gimple_build_nop (); |
| 6496 |
set_ssa_default_def (cfun, DECL_RESULT (new_decl), new_name); |
| 6497 |
} |
| 6498 |
} |
| 6499 |
|
| 6500 |
/* Set up the destination functions loop tree. */ |
| 6501 |
if (loops_for_fn (DECL_STRUCT_FUNCTION (old_decl)) != NULL) |
| 6502 |
{ |
| 6503 |
cfun->curr_properties &= ~PROP_loops; |
| 6504 |
loop_optimizer_init (AVOID_CFG_MODIFICATIONS); |
| 6505 |
cfun->curr_properties |= PROP_loops; |
| 6506 |
} |
| 6507 |
|
| 6508 |
/* Copy the Function's body. */ |
| 6509 |
copy_body (&id, ENTRY_BLOCK_PTR_FOR_FN (cfun), EXIT_BLOCK_PTR_FOR_FN (cfun), |
| 6510 |
new_entry); |
| 6511 |
|
| 6512 |
/* Renumber the lexical scoping (non-code) blocks consecutively. */ |
| 6513 |
number_blocks (new_decl); |
| 6514 |
|
| 6515 |
/* We want to create the BB unconditionally, so that the addition of |
| 6516 |
debug stmts doesn't affect BB count, which may in the end cause |
| 6517 |
codegen differences. */ |
| 6518 |
bb = split_edge (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun))); |
| 6519 |
while (init_stmts.length ()) |
| 6520 |
insert_init_stmt (&id, bb, init_stmts.pop ()); |
| 6521 |
if (param_body_adjs) |
| 6522 |
param_body_adjs->append_init_stmts (bb); |
| 6523 |
update_clone_info (&id); |
| 6524 |
|
| 6525 |
/* Remap the nonlocal_goto_save_area, if any. */ |
| 6526 |
if (cfun->nonlocal_goto_save_area) |
| 6527 |
{ |
| 6528 |
struct walk_stmt_info wi; |
| 6529 |
|
| 6530 |
memset (&wi, 0, sizeof (wi)); |
| 6531 |
wi.info = &id; |
| 6532 |
walk_tree (&cfun->nonlocal_goto_save_area, remap_gimple_op_r, &wi, NULL); |
| 6533 |
} |
| 6534 |
|
| 6535 |
/* Clean up. */ |
| 6536 |
delete id.decl_map; |
| 6537 |
if (id.debug_map) |
| 6538 |
delete id.debug_map; |
| 6539 |
free_dominance_info (CDI_DOMINATORS); |
| 6540 |
free_dominance_info (CDI_POST_DOMINATORS); |
| 6541 |
|
| 6542 |
update_max_bb_count (); |
| 6543 |
fold_marked_statements (0, id.statements_to_fold); |
| 6544 |
delete id.statements_to_fold; |
| 6545 |
delete_unreachable_blocks_update_callgraph (id.dst_node, update_clones); |
| 6546 |
if (id.dst_node->definition) |
| 6547 |
cgraph_edge::rebuild_references (); |
| 6548 |
if (loops_state_satisfies_p (LOOPS_NEED_FIXUP)) |
| 6549 |
{ |
| 6550 |
calculate_dominance_info (CDI_DOMINATORS); |
| 6551 |
fix_loop_structure (NULL); |
| 6552 |
} |
| 6553 |
update_ssa (TODO_update_ssa); |
| 6554 |
|
| 6555 |
/* After partial cloning we need to rescale frequencies, so they are |
| 6556 |
within proper range in the cloned function. */ |
| 6557 |
if (new_entry) |
| 6558 |
{ |
| 6559 |
struct cgraph_edge *e; |
| 6560 |
rebuild_frequencies (); |
| 6561 |
|
| 6562 |
new_version_node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; |
| 6563 |
for (e = new_version_node->callees; e; e = e->next_callee) |
| 6564 |
{ |
| 6565 |
basic_block bb = gimple_bb (e->call_stmt); |
| 6566 |
e->count = bb->count; |
| 6567 |
} |
| 6568 |
for (e = new_version_node->indirect_calls; e; e = e->next_callee) |
| 6569 |
{ |
| 6570 |
basic_block bb = gimple_bb (e->call_stmt); |
| 6571 |
e->count = bb->count; |
| 6572 |
} |
| 6573 |
} |
| 6574 |
|
| 6575 |
if (param_body_adjs && MAY_HAVE_DEBUG_BIND_STMTS) |
| 6576 |
{ |
| 6577 |
vec<tree, va_gc> **debug_args = NULL; |
| 6578 |
unsigned int len = 0; |
| 6579 |
unsigned reset_len = param_body_adjs->m_reset_debug_decls.length (); |
| 6580 |
|
| 6581 |
for (i = 0; i < reset_len; i++) |
| 6582 |
{ |
| 6583 |
tree parm = param_body_adjs->m_reset_debug_decls[i]; |
| 6584 |
gcc_assert (is_gimple_reg (parm)); |
| 6585 |
tree ddecl; |
| 6586 |
|
| 6587 |
if (debug_args == NULL) |
| 6588 |
{ |
| 6589 |
debug_args = decl_debug_args_insert (new_decl); |
| 6590 |
len = vec_safe_length (*debug_args); |
| 6591 |
} |
| 6592 |
ddecl = build_debug_expr_decl (TREE_TYPE (parm)); |
| 6593 |
/* FIXME: Is setting the mode really necessary? */ |
| 6594 |
SET_DECL_MODE (ddecl, DECL_MODE (parm)); |
| 6595 |
vec_safe_push (*debug_args, DECL_ORIGIN (parm)); |
| 6596 |
vec_safe_push (*debug_args, ddecl); |
| 6597 |
} |
| 6598 |
if (debug_args != NULL) |
| 6599 |
{ |
| 6600 |
/* On the callee side, add |
| 6601 |
DEBUG D#Y s=> parm |
| 6602 |
DEBUG var => D#Y |
| 6603 |
stmts to the first bb where var is a VAR_DECL created for the |
| 6604 |
optimized away parameter in DECL_INITIAL block. This hints |
| 6605 |
in the debug info that var (whole DECL_ORIGIN is the parm |
| 6606 |
PARM_DECL) is optimized away, but could be looked up at the |
| 6607 |
call site as value of D#X there. */ |
| 6608 |
gimple_stmt_iterator cgsi |
| 6609 |
= gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun))); |
| 6610 |
gimple *def_temp; |
| 6611 |
tree var = vars; |
| 6612 |
i = vec_safe_length (*debug_args); |
| 6613 |
do |
| 6614 |
{ |
| 6615 |
tree vexpr = NULL_TREE; |
| 6616 |
i -= 2; |
| 6617 |
while (var != NULL_TREE |
| 6618 |
&& DECL_ABSTRACT_ORIGIN (var) != (**debug_args)[i]) |
| 6619 |
var = TREE_CHAIN (var); |
| 6620 |
if (var == NULL_TREE) |
| 6621 |
break; |
| 6622 |
tree parm = (**debug_args)[i]; |
| 6623 |
if (tree parm_ddef = ssa_default_def (id.src_cfun, parm)) |
| 6624 |
if (tree *d |
| 6625 |
= param_body_adjs->m_dead_ssa_debug_equiv.get (parm_ddef)) |
| 6626 |
vexpr = *d; |
| 6627 |
if (!vexpr) |
| 6628 |
{ |
| 6629 |
vexpr = build_debug_expr_decl (TREE_TYPE (parm)); |
| 6630 |
/* FIXME: Is setting the mode really necessary? */ |
| 6631 |
SET_DECL_MODE (vexpr, DECL_MODE (parm)); |
| 6632 |
} |
| 6633 |
def_temp = gimple_build_debug_bind (var, vexpr, NULL); |
| 6634 |
gsi_insert_before (&cgsi, def_temp, GSI_NEW_STMT); |
| 6635 |
def_temp = gimple_build_debug_source_bind (vexpr, parm, NULL); |
| 6636 |
gsi_insert_before (&cgsi, def_temp, GSI_NEW_STMT); |
| 6637 |
} |
| 6638 |
while (i > len); |
| 6639 |
} |
| 6640 |
} |
| 6641 |
delete param_body_adjs; |
| 6642 |
free_dominance_info (CDI_DOMINATORS); |
| 6643 |
free_dominance_info (CDI_POST_DOMINATORS); |
| 6644 |
|
| 6645 |
gcc_assert (!id.debug_stmts.exists ()); |
| 6646 |
pop_cfun (); |
| 6647 |
input_location = saved_location; |
| 6648 |
return; |
| 6649 |
} |
| 6650 |
|
| 6651 |
/* EXP is CALL_EXPR present in a GENERIC expression tree. Try to integrate |
| 6652 |
the callee and return the inlined body on success. */ |
| 6653 |
|
| 6654 |
tree |
| 6655 |
maybe_inline_call_in_expr (tree exp) |
| 6656 |
{ |
| 6657 |
tree fn = get_callee_fndecl (exp); |
| 6658 |
|
| 6659 |
/* We can only try to inline "const" functions. */ |
| 6660 |
if (fn && TREE_READONLY (fn) && DECL_SAVED_TREE (fn)) |
| 6661 |
{ |
| 6662 |
call_expr_arg_iterator iter; |
| 6663 |
copy_body_data id; |
| 6664 |
tree param, arg, t; |
| 6665 |
hash_map<tree, tree> decl_map; |
| 6666 |
|
| 6667 |
/* Remap the parameters. */ |
| 6668 |
for (param = DECL_ARGUMENTS (fn), arg = first_call_expr_arg (exp, &iter); |
| 6669 |
param; |
| 6670 |
param = DECL_CHAIN (param), arg = next_call_expr_arg (&iter)) |
| 6671 |
decl_map.put (param, arg); |
| 6672 |
|
| 6673 |
memset (&id, 0, sizeof (id)); |
| 6674 |
id.src_fn = fn; |
| 6675 |
id.dst_fn = current_function_decl; |
| 6676 |
id.src_cfun = DECL_STRUCT_FUNCTION (fn); |
| 6677 |
id.decl_map = &decl_map; |
| 6678 |
|
| 6679 |
id.copy_decl = copy_decl_no_change; |
| 6680 |
id.transform_call_graph_edges = CB_CGE_DUPLICATE; |
| 6681 |
id.transform_new_cfg = false; |
| 6682 |
id.transform_return_to_modify = true; |
| 6683 |
id.transform_parameter = true; |
| 6684 |
|
| 6685 |
/* Make sure not to unshare trees behind the front-end's back |
| 6686 |
since front-end specific mechanisms may rely on sharing. */ |
| 6687 |
id.regimplify = false; |
| 6688 |
id.do_not_unshare = true; |
| 6689 |
|
| 6690 |
/* We're not inside any EH region. */ |
| 6691 |
id.eh_lp_nr = 0; |
| 6692 |
|
| 6693 |
t = copy_tree_body (&id); |
| 6694 |
|
| 6695 |
/* We can only return something suitable for use in a GENERIC |
| 6696 |
expression tree. */ |
| 6697 |
if (TREE_CODE (t) == MODIFY_EXPR) |
| 6698 |
return TREE_OPERAND (t, 1); |
| 6699 |
} |
| 6700 |
|
| 6701 |
return NULL_TREE; |
| 6702 |
} |
| 6703 |
|
| 6704 |
/* Duplicate a type, fields and all. */ |
| 6705 |
|
| 6706 |
tree |
| 6707 |
build_duplicate_type (tree type) |
| 6708 |
{ |
| 6709 |
struct copy_body_data id; |
| 6710 |
|
| 6711 |
memset (&id, 0, sizeof (id)); |
| 6712 |
id.src_fn = current_function_decl; |
| 6713 |
id.dst_fn = current_function_decl; |
| 6714 |
id.src_cfun = cfun; |
| 6715 |
id.decl_map = new hash_map<tree, tree>; |
| 6716 |
id.debug_map = NULL; |
| 6717 |
id.copy_decl = copy_decl_no_change; |
| 6718 |
|
| 6719 |
type = remap_type_1 (type, &id); |
| 6720 |
|
| 6721 |
delete id.decl_map; |
| 6722 |
if (id.debug_map) |
| 6723 |
delete id.debug_map; |
| 6724 |
|
| 6725 |
TYPE_CANONICAL (type) = type; |
| 6726 |
|
| 6727 |
return type; |
| 6728 |
} |
| 6729 |
|
| 6730 |
/* Unshare the entire DECL_SAVED_TREE of FN and return the remapped |
| 6731 |
parameters and RESULT_DECL in PARMS and RESULT. Used by C++ constexpr |
| 6732 |
evaluation. */ |
| 6733 |
|
| 6734 |
tree |
| 6735 |
copy_fn (tree fn, tree& parms, tree& result) |
| 6736 |
{ |
| 6737 |
copy_body_data id; |
| 6738 |
tree param; |
| 6739 |
hash_map<tree, tree> decl_map; |
| 6740 |
|
| 6741 |
tree *p = &parms; |
| 6742 |
*p = NULL_TREE; |
| 6743 |
|
| 6744 |
memset (&id, 0, sizeof (id)); |
| 6745 |
id.src_fn = fn; |
| 6746 |
id.dst_fn = current_function_decl; |
| 6747 |
id.src_cfun = DECL_STRUCT_FUNCTION (fn); |
| 6748 |
id.decl_map = &decl_map; |
| 6749 |
|
| 6750 |
id.copy_decl = [] (tree decl, copy_body_data *id) |
| 6751 |
{ |
| 6752 |
if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL) |
| 6753 |
/* Don't make copies of local types or injected enumerators, |
| 6754 |
the C++ constexpr evaluator doesn't need them and they |
| 6755 |
confuse modules streaming. */ |
| 6756 |
return decl; |
| 6757 |
return copy_decl_no_change (decl, id); |
| 6758 |
}; |
| 6759 |
id.transform_call_graph_edges = CB_CGE_DUPLICATE; |
| 6760 |
id.transform_new_cfg = false; |
| 6761 |
id.transform_return_to_modify = false; |
| 6762 |
id.transform_parameter = true; |
| 6763 |
|
| 6764 |
/* Make sure not to unshare trees behind the front-end's back |
| 6765 |
since front-end specific mechanisms may rely on sharing. */ |
| 6766 |
id.regimplify = false; |
| 6767 |
id.do_not_unshare = true; |
| 6768 |
id.do_not_fold = true; |
| 6769 |
|
| 6770 |
/* We're not inside any EH region. */ |
| 6771 |
id.eh_lp_nr = 0; |
| 6772 |
|
| 6773 |
/* Remap the parameters and result and return them to the caller. */ |
| 6774 |
for (param = DECL_ARGUMENTS (fn); |
| 6775 |
param; |
| 6776 |
param = DECL_CHAIN (param)) |
| 6777 |
{ |
| 6778 |
*p = remap_decl (param, &id); |
| 6779 |
p = &DECL_CHAIN (*p); |
| 6780 |
} |
| 6781 |
|
| 6782 |
if (DECL_RESULT (fn)) |
| 6783 |
result = remap_decl (DECL_RESULT (fn), &id); |
| 6784 |
else |
| 6785 |
result = NULL_TREE; |
| 6786 |
|
| 6787 |
return copy_tree_body (&id); |
| 6788 |
} |