| 1 |
/* A pass for lowering trees to RTL. |
| 2 |
Copyright (C) 2004-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. |
| 5 |
|
| 6 |
GCC is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 3, or (at your option) |
| 9 |
any later version. |
| 10 |
|
| 11 |
GCC is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with GCC; see the file COPYING3. If not see |
| 18 |
<http://www.gnu.org/licenses/>. */ |
| 19 |
|
| 20 |
#include "config.h" |
| 21 |
#include "system.h" |
| 22 |
#include "coretypes.h" |
| 23 |
#include "backend.h" |
| 24 |
#include "target.h" |
| 25 |
#include "rtl.h" |
| 26 |
#include "tree.h" |
| 27 |
#include "gimple.h" |
| 28 |
#include "cfghooks.h" |
| 29 |
#include "tree-pass.h" |
| 30 |
#include "memmodel.h" |
| 31 |
#include "tm_p.h" |
| 32 |
#include "ssa.h" |
| 33 |
#include "optabs.h" |
| 34 |
#include "regs.h" /* For reg_renumber. */ |
| 35 |
#include "emit-rtl.h" |
| 36 |
#include "recog.h" |
| 37 |
#include "cgraph.h" |
| 38 |
#include "diagnostic.h" |
| 39 |
#include "fold-const.h" |
| 40 |
#include "varasm.h" |
| 41 |
#include "stor-layout.h" |
| 42 |
#include "stmt.h" |
| 43 |
#include "print-tree.h" |
| 44 |
#include "cfgrtl.h" |
| 45 |
#include "cfganal.h" |
| 46 |
#include "cfgbuild.h" |
| 47 |
#include "cfgcleanup.h" |
| 48 |
#include "dojump.h" |
| 49 |
#include "explow.h" |
| 50 |
#include "calls.h" |
| 51 |
#include "expr.h" |
| 52 |
#include "internal-fn.h" |
| 53 |
#include "tree-eh.h" |
| 54 |
#include "gimple-iterator.h" |
| 55 |
#include "gimple-expr.h" |
| 56 |
#include "gimple-walk.h" |
| 57 |
#include "tree-cfg.h" |
| 58 |
#include "tree-dfa.h" |
| 59 |
#include "tree-ssa.h" |
| 60 |
#include "except.h" |
| 61 |
#include "gimple-pretty-print.h" |
| 62 |
#include "toplev.h" |
| 63 |
#include "debug.h" |
| 64 |
#include "tree-inline.h" |
| 65 |
#include "value-prof.h" |
| 66 |
#include "tree-ssa-live.h" |
| 67 |
#include "tree-outof-ssa.h" |
| 68 |
#include "cfgloop.h" |
| 69 |
#include "insn-attr.h" /* For INSN_SCHEDULING. */ |
| 70 |
#include "stringpool.h" |
| 71 |
#include "attribs.h" |
| 72 |
#include "asan.h" |
| 73 |
#include "tree-ssa-address.h" |
| 74 |
#include "output.h" |
| 75 |
#include "builtins.h" |
| 76 |
#include "opts.h" |
| 77 |
#include "rtl-iter.h" |
| 78 |
|
| 79 |
/* Some systems use __main in a way incompatible with its use in gcc, in these |
| 80 |
cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to |
| 81 |
give the same symbol without quotes for an alternative entry point. You |
| 82 |
must define both, or neither. */ |
| 83 |
#ifndef NAME__MAIN |
| 84 |
#define NAME__MAIN "__main" |
| 85 |
#endif |
| 86 |
|
| 87 |
/* This variable holds information helping the rewriting of SSA trees |
| 88 |
into RTL. */ |
| 89 |
struct ssaexpand SA; |
| 90 |
|
| 91 |
/* This variable holds the currently expanded gimple statement for purposes |
| 92 |
of comminucating the profile info to the builtin expanders. */ |
| 93 |
gimple *currently_expanding_gimple_stmt; |
| 94 |
|
| 95 |
static rtx expand_debug_expr (tree); |
| 96 |
|
| 97 |
static bool defer_stack_allocation (tree, bool); |
| 98 |
|
| 99 |
static void record_alignment_for_reg_var (unsigned int); |
| 100 |
|
| 101 |
/* Return an expression tree corresponding to the RHS of GIMPLE |
| 102 |
statement STMT. */ |
| 103 |
|
| 104 |
tree |
| 105 |
gimple_assign_rhs_to_tree (gimple *stmt) |
| 106 |
{ |
| 107 |
tree t; |
| 108 |
switch (gimple_assign_rhs_class (stmt)) |
| 109 |
{ |
| 110 |
case GIMPLE_TERNARY_RHS: |
| 111 |
t = build3 (gimple_assign_rhs_code (stmt), |
| 112 |
TREE_TYPE (gimple_assign_lhs (stmt)), |
| 113 |
gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt), |
| 114 |
gimple_assign_rhs3 (stmt)); |
| 115 |
break; |
| 116 |
case GIMPLE_BINARY_RHS: |
| 117 |
t = build2 (gimple_assign_rhs_code (stmt), |
| 118 |
TREE_TYPE (gimple_assign_lhs (stmt)), |
| 119 |
gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt)); |
| 120 |
break; |
| 121 |
case GIMPLE_UNARY_RHS: |
| 122 |
t = build1 (gimple_assign_rhs_code (stmt), |
| 123 |
TREE_TYPE (gimple_assign_lhs (stmt)), |
| 124 |
gimple_assign_rhs1 (stmt)); |
| 125 |
break; |
| 126 |
case GIMPLE_SINGLE_RHS: |
| 127 |
{ |
| 128 |
t = gimple_assign_rhs1 (stmt); |
| 129 |
/* Avoid modifying this tree in place below. */ |
| 130 |
if ((gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t) |
| 131 |
&& gimple_location (stmt) != EXPR_LOCATION (t)) |
| 132 |
|| (gimple_block (stmt) && currently_expanding_to_rtl |
| 133 |
&& EXPR_P (t))) |
| 134 |
t = copy_node (t); |
| 135 |
break; |
| 136 |
} |
| 137 |
default: |
| 138 |
gcc_unreachable (); |
| 139 |
} |
| 140 |
|
| 141 |
if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t)) |
| 142 |
SET_EXPR_LOCATION (t, gimple_location (stmt)); |
| 143 |
|
| 144 |
return t; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
#ifndef STACK_ALIGNMENT_NEEDED |
| 149 |
#define STACK_ALIGNMENT_NEEDED 1 |
| 150 |
#endif |
| 151 |
|
| 152 |
#define SSAVAR(x) (TREE_CODE (x) == SSA_NAME ? SSA_NAME_VAR (x) : x) |
| 153 |
|
| 154 |
/* Choose either CUR or NEXT as the leader DECL for a partition. |
| 155 |
Prefer ignored decls, to simplify debug dumps and reduce ambiguity |
| 156 |
out of the same user variable being in multiple partitions (this is |
| 157 |
less likely for compiler-introduced temps). */ |
| 158 |
|
| 159 |
static tree |
| 160 |
leader_merge (tree cur, tree next) |
| 161 |
{ |
| 162 |
if (cur == NULL || cur == next) |
| 163 |
return next; |
| 164 |
|
| 165 |
if (DECL_P (cur) && DECL_IGNORED_P (cur)) |
| 166 |
return cur; |
| 167 |
|
| 168 |
if (DECL_P (next) && DECL_IGNORED_P (next)) |
| 169 |
return next; |
| 170 |
|
| 171 |
return cur; |
| 172 |
} |
| 173 |
|
| 174 |
/* Associate declaration T with storage space X. If T is no |
| 175 |
SSA name this is exactly SET_DECL_RTL, otherwise make the |
| 176 |
partition of T associated with X. */ |
| 177 |
static inline void |
| 178 |
set_rtl (tree t, rtx x) |
| 179 |
{ |
| 180 |
gcc_checking_assert (!x |
| 181 |
|| !(TREE_CODE (t) == SSA_NAME || is_gimple_reg (t)) |
| 182 |
|| (use_register_for_decl (t) |
| 183 |
? (REG_P (x) |
| 184 |
|| (GET_CODE (x) == CONCAT |
| 185 |
&& (REG_P (XEXP (x, 0)) |
| 186 |
|| SUBREG_P (XEXP (x, 0))) |
| 187 |
&& (REG_P (XEXP (x, 1)) |
| 188 |
|| SUBREG_P (XEXP (x, 1)))) |
| 189 |
/* We need to accept PARALLELs for RESUT_DECLs |
| 190 |
because of vector types with BLKmode returned |
| 191 |
in multiple registers, but they are supposed |
| 192 |
to be uncoalesced. */ |
| 193 |
|| (GET_CODE (x) == PARALLEL |
| 194 |
&& SSAVAR (t) |
| 195 |
&& TREE_CODE (SSAVAR (t)) == RESULT_DECL |
| 196 |
&& (GET_MODE (x) == BLKmode |
| 197 |
|| !flag_tree_coalesce_vars))) |
| 198 |
: (MEM_P (x) || x == pc_rtx |
| 199 |
|| (GET_CODE (x) == CONCAT |
| 200 |
&& MEM_P (XEXP (x, 0)) |
| 201 |
&& MEM_P (XEXP (x, 1)))))); |
| 202 |
/* Check that the RTL for SSA_NAMEs and gimple-reg PARM_DECLs and |
| 203 |
RESULT_DECLs has the expected mode. For memory, we accept |
| 204 |
unpromoted modes, since that's what we're likely to get. For |
| 205 |
PARM_DECLs and RESULT_DECLs, we'll have been called by |
| 206 |
set_parm_rtl, which will give us the default def, so we don't |
| 207 |
have to compute it ourselves. For RESULT_DECLs, we accept mode |
| 208 |
mismatches too, as long as we have BLKmode or are not coalescing |
| 209 |
across variables, so that we don't reject BLKmode PARALLELs or |
| 210 |
unpromoted REGs. */ |
| 211 |
gcc_checking_assert (!x || x == pc_rtx || TREE_CODE (t) != SSA_NAME |
| 212 |
|| (SSAVAR (t) |
| 213 |
&& TREE_CODE (SSAVAR (t)) == RESULT_DECL |
| 214 |
&& (promote_ssa_mode (t, NULL) == BLKmode |
| 215 |
|| !flag_tree_coalesce_vars)) |
| 216 |
|| !use_register_for_decl (t) |
| 217 |
|| GET_MODE (x) == promote_ssa_mode (t, NULL)); |
| 218 |
|
| 219 |
if (x) |
| 220 |
{ |
| 221 |
bool skip = false; |
| 222 |
tree cur = NULL_TREE; |
| 223 |
rtx xm = x; |
| 224 |
|
| 225 |
retry: |
| 226 |
if (MEM_P (xm)) |
| 227 |
cur = MEM_EXPR (xm); |
| 228 |
else if (REG_P (xm)) |
| 229 |
cur = REG_EXPR (xm); |
| 230 |
else if (SUBREG_P (xm)) |
| 231 |
{ |
| 232 |
gcc_assert (subreg_lowpart_p (xm)); |
| 233 |
xm = SUBREG_REG (xm); |
| 234 |
goto retry; |
| 235 |
} |
| 236 |
else if (GET_CODE (xm) == CONCAT) |
| 237 |
{ |
| 238 |
xm = XEXP (xm, 0); |
| 239 |
goto retry; |
| 240 |
} |
| 241 |
else if (GET_CODE (xm) == PARALLEL) |
| 242 |
{ |
| 243 |
xm = XVECEXP (xm, 0, 0); |
| 244 |
gcc_assert (GET_CODE (xm) == EXPR_LIST); |
| 245 |
xm = XEXP (xm, 0); |
| 246 |
goto retry; |
| 247 |
} |
| 248 |
else if (xm == pc_rtx) |
| 249 |
skip = true; |
| 250 |
else |
| 251 |
gcc_unreachable (); |
| 252 |
|
| 253 |
tree next = skip ? cur : leader_merge (cur, SSAVAR (t) ? SSAVAR (t) : t); |
| 254 |
|
| 255 |
if (cur != next) |
| 256 |
{ |
| 257 |
if (MEM_P (x)) |
| 258 |
set_mem_attributes (x, |
| 259 |
next && TREE_CODE (next) == SSA_NAME |
| 260 |
? TREE_TYPE (next) |
| 261 |
: next, true); |
| 262 |
else |
| 263 |
set_reg_attrs_for_decl_rtl (next, x); |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
if (TREE_CODE (t) == SSA_NAME) |
| 268 |
{ |
| 269 |
int part = var_to_partition (SA.map, t); |
| 270 |
if (part != NO_PARTITION) |
| 271 |
{ |
| 272 |
if (SA.partition_to_pseudo[part]) |
| 273 |
gcc_assert (SA.partition_to_pseudo[part] == x); |
| 274 |
else if (x != pc_rtx) |
| 275 |
SA.partition_to_pseudo[part] = x; |
| 276 |
} |
| 277 |
/* For the benefit of debug information at -O0 (where |
| 278 |
vartracking doesn't run) record the place also in the base |
| 279 |
DECL. For PARMs and RESULTs, do so only when setting the |
| 280 |
default def. */ |
| 281 |
if (x && x != pc_rtx && SSA_NAME_VAR (t) |
| 282 |
&& (VAR_P (SSA_NAME_VAR (t)) |
| 283 |
|| SSA_NAME_IS_DEFAULT_DEF (t))) |
| 284 |
{ |
| 285 |
tree var = SSA_NAME_VAR (t); |
| 286 |
/* If we don't yet have something recorded, just record it now. */ |
| 287 |
if (!DECL_RTL_SET_P (var)) |
| 288 |
SET_DECL_RTL (var, x); |
| 289 |
/* If we have it set already to "multiple places" don't |
| 290 |
change this. */ |
| 291 |
else if (DECL_RTL (var) == pc_rtx) |
| 292 |
; |
| 293 |
/* If we have something recorded and it's not the same place |
| 294 |
as we want to record now, we have multiple partitions for the |
| 295 |
same base variable, with different places. We can't just |
| 296 |
randomly chose one, hence we have to say that we don't know. |
| 297 |
This only happens with optimization, and there var-tracking |
| 298 |
will figure out the right thing. */ |
| 299 |
else if (DECL_RTL (var) != x) |
| 300 |
SET_DECL_RTL (var, pc_rtx); |
| 301 |
} |
| 302 |
} |
| 303 |
else |
| 304 |
SET_DECL_RTL (t, x); |
| 305 |
} |
| 306 |
|
| 307 |
/* This structure holds data relevant to one variable that will be |
| 308 |
placed in a stack slot. */ |
| 309 |
class stack_var |
| 310 |
{ |
| 311 |
public: |
| 312 |
/* The Variable. */ |
| 313 |
tree decl; |
| 314 |
|
| 315 |
/* Initially, the size of the variable. Later, the size of the partition, |
| 316 |
if this variable becomes it's partition's representative. */ |
| 317 |
poly_uint64 size; |
| 318 |
|
| 319 |
/* The *byte* alignment required for this variable. Or as, with the |
| 320 |
size, the alignment for this partition. */ |
| 321 |
unsigned int alignb; |
| 322 |
|
| 323 |
/* The partition representative. */ |
| 324 |
unsigned representative; |
| 325 |
|
| 326 |
/* The next stack variable in the partition, or EOC. */ |
| 327 |
unsigned next; |
| 328 |
|
| 329 |
/* The numbers of conflicting stack variables. */ |
| 330 |
bitmap conflicts; |
| 331 |
}; |
| 332 |
|
| 333 |
#define EOC ((unsigned)-1) |
| 334 |
|
| 335 |
/* We have an array of such objects while deciding allocation. */ |
| 336 |
static class stack_var *stack_vars; |
| 337 |
static unsigned stack_vars_alloc; |
| 338 |
static unsigned stack_vars_num; |
| 339 |
static hash_map<tree, unsigned> *decl_to_stack_part; |
| 340 |
|
| 341 |
#define INVALID_STACK_INDEX ((unsigned)-1) |
| 342 |
|
| 343 |
/* Conflict bitmaps go on this obstack. This allows us to destroy |
| 344 |
all of them in one big sweep. */ |
| 345 |
static bitmap_obstack stack_var_bitmap_obstack; |
| 346 |
|
| 347 |
/* An array of indices such that stack_vars[stack_vars_sorted[i]].size |
| 348 |
is non-decreasing. */ |
| 349 |
static unsigned *stack_vars_sorted; |
| 350 |
|
| 351 |
/* The phase of the stack frame. This is the known misalignment of |
| 352 |
virtual_stack_vars_rtx from PREFERRED_STACK_BOUNDARY. That is, |
| 353 |
(frame_offset+frame_phase) % PREFERRED_STACK_BOUNDARY == 0. */ |
| 354 |
static int frame_phase; |
| 355 |
|
| 356 |
/* Used during expand_used_vars to remember if we saw any decls for |
| 357 |
which we'd like to enable stack smashing protection. */ |
| 358 |
static bool has_protected_decls; |
| 359 |
|
| 360 |
/* Used during expand_used_vars. Remember if we say a character buffer |
| 361 |
smaller than our cutoff threshold. Used for -Wstack-protector. */ |
| 362 |
static bool has_short_buffer; |
| 363 |
|
| 364 |
/* Compute the byte alignment to use for DECL. Ignore alignment |
| 365 |
we can't do with expected alignment of the stack boundary. */ |
| 366 |
|
| 367 |
static unsigned int |
| 368 |
align_local_variable (tree decl, bool really_expand) |
| 369 |
{ |
| 370 |
unsigned int align; |
| 371 |
|
| 372 |
if (TREE_CODE (decl) == SSA_NAME) |
| 373 |
{ |
| 374 |
tree type = TREE_TYPE (decl); |
| 375 |
machine_mode mode = TYPE_MODE (type); |
| 376 |
|
| 377 |
align = TYPE_ALIGN (type); |
| 378 |
if (mode != BLKmode |
| 379 |
&& align < GET_MODE_ALIGNMENT (mode)) |
| 380 |
align = GET_MODE_ALIGNMENT (mode); |
| 381 |
} |
| 382 |
else |
| 383 |
align = LOCAL_DECL_ALIGNMENT (decl); |
| 384 |
|
| 385 |
if (hwasan_sanitize_stack_p ()) |
| 386 |
align = MAX (align, (unsigned) HWASAN_TAG_GRANULE_SIZE * BITS_PER_UNIT); |
| 387 |
|
| 388 |
if (TREE_CODE (decl) != SSA_NAME && really_expand) |
| 389 |
/* Don't change DECL_ALIGN when called from estimated_stack_frame_size. |
| 390 |
That is done before IPA and could bump alignment based on host |
| 391 |
backend even for offloaded code which wants different |
| 392 |
LOCAL_DECL_ALIGNMENT. */ |
| 393 |
SET_DECL_ALIGN (decl, align); |
| 394 |
|
| 395 |
return align / BITS_PER_UNIT; |
| 396 |
} |
| 397 |
|
| 398 |
/* Align given offset BASE with ALIGN. Truncate up if ALIGN_UP is true, |
| 399 |
down otherwise. Return truncated BASE value. */ |
| 400 |
|
| 401 |
static inline unsigned HOST_WIDE_INT |
| 402 |
align_base (HOST_WIDE_INT base, unsigned HOST_WIDE_INT align, bool align_up) |
| 403 |
{ |
| 404 |
return align_up ? (base + align - 1) & -align : base & -align; |
| 405 |
} |
| 406 |
|
| 407 |
/* Allocate SIZE bytes at byte alignment ALIGN from the stack frame. |
| 408 |
Return the frame offset. */ |
| 409 |
|
| 410 |
static poly_int64 |
| 411 |
alloc_stack_frame_space (poly_int64 size, unsigned HOST_WIDE_INT align) |
| 412 |
{ |
| 413 |
poly_int64 offset, new_frame_offset; |
| 414 |
|
| 415 |
if (FRAME_GROWS_DOWNWARD) |
| 416 |
{ |
| 417 |
new_frame_offset |
| 418 |
= aligned_lower_bound (frame_offset - frame_phase - size, |
| 419 |
align) + frame_phase; |
| 420 |
offset = new_frame_offset; |
| 421 |
} |
| 422 |
else |
| 423 |
{ |
| 424 |
new_frame_offset |
| 425 |
= aligned_upper_bound (frame_offset - frame_phase, |
| 426 |
align) + frame_phase; |
| 427 |
offset = new_frame_offset; |
| 428 |
new_frame_offset += size; |
| 429 |
} |
| 430 |
frame_offset = new_frame_offset; |
| 431 |
|
| 432 |
if (frame_offset_overflow (frame_offset, cfun->decl)) |
| 433 |
frame_offset = offset = 0; |
| 434 |
|
| 435 |
return offset; |
| 436 |
} |
| 437 |
|
| 438 |
/* Ensure that the stack is aligned to ALIGN bytes. |
| 439 |
Return the new frame offset. */ |
| 440 |
static poly_int64 |
| 441 |
align_frame_offset (unsigned HOST_WIDE_INT align) |
| 442 |
{ |
| 443 |
return alloc_stack_frame_space (0, align); |
| 444 |
} |
| 445 |
|
| 446 |
/* Accumulate DECL into STACK_VARS. */ |
| 447 |
|
| 448 |
static void |
| 449 |
add_stack_var (tree decl, bool really_expand) |
| 450 |
{ |
| 451 |
class stack_var *v; |
| 452 |
|
| 453 |
if (stack_vars_num >= stack_vars_alloc) |
| 454 |
{ |
| 455 |
if (stack_vars_alloc) |
| 456 |
stack_vars_alloc = stack_vars_alloc * 3 / 2; |
| 457 |
else |
| 458 |
stack_vars_alloc = 32; |
| 459 |
stack_vars |
| 460 |
= XRESIZEVEC (class stack_var, stack_vars, stack_vars_alloc); |
| 461 |
} |
| 462 |
if (!decl_to_stack_part) |
| 463 |
decl_to_stack_part = new hash_map<tree, unsigned>; |
| 464 |
|
| 465 |
v = &stack_vars[stack_vars_num]; |
| 466 |
decl_to_stack_part->put (decl, stack_vars_num); |
| 467 |
|
| 468 |
v->decl = decl; |
| 469 |
tree size = TREE_CODE (decl) == SSA_NAME |
| 470 |
? TYPE_SIZE_UNIT (TREE_TYPE (decl)) |
| 471 |
: DECL_SIZE_UNIT (decl); |
| 472 |
v->size = tree_to_poly_uint64 (size); |
| 473 |
/* Ensure that all variables have size, so that &a != &b for any two |
| 474 |
variables that are simultaneously live. */ |
| 475 |
if (known_eq (v->size, 0U)) |
| 476 |
v->size = 1; |
| 477 |
v->alignb = align_local_variable (decl, really_expand); |
| 478 |
/* An alignment of zero can mightily confuse us later. */ |
| 479 |
gcc_assert (v->alignb != 0); |
| 480 |
|
| 481 |
/* All variables are initially in their own partition. */ |
| 482 |
v->representative = stack_vars_num; |
| 483 |
v->next = EOC; |
| 484 |
|
| 485 |
/* All variables initially conflict with no other. */ |
| 486 |
v->conflicts = NULL; |
| 487 |
|
| 488 |
/* Ensure that this decl doesn't get put onto the list twice. */ |
| 489 |
set_rtl (decl, pc_rtx); |
| 490 |
|
| 491 |
stack_vars_num++; |
| 492 |
} |
| 493 |
|
| 494 |
/* Make the decls associated with luid's X and Y conflict. */ |
| 495 |
|
| 496 |
static void |
| 497 |
add_stack_var_conflict (unsigned x, unsigned y) |
| 498 |
{ |
| 499 |
class stack_var *a = &stack_vars[x]; |
| 500 |
class stack_var *b = &stack_vars[y]; |
| 501 |
if (x == y) |
| 502 |
return; |
| 503 |
if (!a->conflicts) |
| 504 |
a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack); |
| 505 |
if (!b->conflicts) |
| 506 |
b->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack); |
| 507 |
bitmap_set_bit (a->conflicts, y); |
| 508 |
bitmap_set_bit (b->conflicts, x); |
| 509 |
} |
| 510 |
|
| 511 |
/* Check whether the decls associated with luid's X and Y conflict. */ |
| 512 |
|
| 513 |
static bool |
| 514 |
stack_var_conflict_p (unsigned x, unsigned y) |
| 515 |
{ |
| 516 |
class stack_var *a = &stack_vars[x]; |
| 517 |
class stack_var *b = &stack_vars[y]; |
| 518 |
if (x == y) |
| 519 |
return false; |
| 520 |
/* Partitions containing an SSA name result from gimple registers |
| 521 |
with things like unsupported modes. They are top-level and |
| 522 |
hence conflict with everything else. */ |
| 523 |
if (TREE_CODE (a->decl) == SSA_NAME || TREE_CODE (b->decl) == SSA_NAME) |
| 524 |
return true; |
| 525 |
|
| 526 |
if (!a->conflicts || !b->conflicts) |
| 527 |
return false; |
| 528 |
return bitmap_bit_p (a->conflicts, y); |
| 529 |
} |
| 530 |
|
| 531 |
/* Returns the DECL's index into the stack_vars array. |
| 532 |
If the DECL does not exist return INVALID_STACK_INDEX. */ |
| 533 |
static unsigned |
| 534 |
decl_stack_index (tree decl) |
| 535 |
{ |
| 536 |
if (!decl) |
| 537 |
return INVALID_STACK_INDEX; |
| 538 |
if (!DECL_P (decl)) |
| 539 |
return INVALID_STACK_INDEX; |
| 540 |
if (DECL_RTL_IF_SET (decl) != pc_rtx) |
| 541 |
return INVALID_STACK_INDEX; |
| 542 |
unsigned *v = decl_to_stack_part->get (decl); |
| 543 |
if (!v) |
| 544 |
return INVALID_STACK_INDEX; |
| 545 |
|
| 546 |
unsigned indx = *v; |
| 547 |
gcc_checking_assert (indx != INVALID_STACK_INDEX); |
| 548 |
gcc_checking_assert (indx < stack_vars_num); |
| 549 |
return indx; |
| 550 |
} |
| 551 |
|
| 552 |
/* Callback for walk_stmt_ops. If OP is a decl touched by add_stack_var |
| 553 |
enter its partition number into bitmap DATA. */ |
| 554 |
|
| 555 |
static bool |
| 556 |
visit_op (gimple *, tree op, tree, void *data) |
| 557 |
{ |
| 558 |
bitmap active = (bitmap)data; |
| 559 |
op = get_base_address (op); |
| 560 |
unsigned idx = decl_stack_index (op); |
| 561 |
if (idx != INVALID_STACK_INDEX) |
| 562 |
bitmap_set_bit (active, idx); |
| 563 |
return false; |
| 564 |
} |
| 565 |
|
| 566 |
/* Callback for walk_stmt_ops. If OP is a decl touched by add_stack_var |
| 567 |
record conflicts between it and all currently active other partitions |
| 568 |
from bitmap DATA. */ |
| 569 |
|
| 570 |
static bool |
| 571 |
visit_conflict (gimple *, tree op, tree, void *data) |
| 572 |
{ |
| 573 |
bitmap active = (bitmap)data; |
| 574 |
op = get_base_address (op); |
| 575 |
unsigned num = decl_stack_index (op); |
| 576 |
if (num != INVALID_STACK_INDEX |
| 577 |
&& bitmap_set_bit (active, num)) |
| 578 |
{ |
| 579 |
bitmap_iterator bi; |
| 580 |
unsigned i; |
| 581 |
gcc_assert (num < stack_vars_num); |
| 582 |
EXECUTE_IF_SET_IN_BITMAP (active, 0, i, bi) |
| 583 |
add_stack_var_conflict (num, i); |
| 584 |
} |
| 585 |
return false; |
| 586 |
} |
| 587 |
|
| 588 |
/* A cache for ssa name to address of stack variables. |
| 589 |
When taking into account if a ssa name refers to an |
| 590 |
address of a stack variable, we need to walk the |
| 591 |
expressions backwards to find the addresses. This |
| 592 |
cache is there so we don't need to walk the expressions |
| 593 |
all the time. */ |
| 594 |
struct vars_ssa_cache |
| 595 |
{ |
| 596 |
private: |
| 597 |
/* Currently an entry is a bitmap of all of the known stack variables |
| 598 |
addresses that are referenced by the ssa name. |
| 599 |
When the bitmap is the nullptr, then there is no cache. |
| 600 |
Currently only empty bitmaps are shared. |
| 601 |
The reason for why empty cache is not just a null is so we know the |
| 602 |
cache for an entry is filled in. */ |
| 603 |
struct entry |
| 604 |
{ |
| 605 |
bitmap bmap = nullptr; |
| 606 |
}; |
| 607 |
entry *vars_ssa_caches; |
| 608 |
public: |
| 609 |
|
| 610 |
vars_ssa_cache(); |
| 611 |
~vars_ssa_cache(); |
| 612 |
const_bitmap operator() (tree name); |
| 613 |
void dump (FILE *file); |
| 614 |
|
| 615 |
private: |
| 616 |
/* Can't copy. */ |
| 617 |
vars_ssa_cache(const vars_ssa_cache&) = delete; |
| 618 |
vars_ssa_cache(vars_ssa_cache&&) = delete; |
| 619 |
|
| 620 |
/* The shared empty bitmap. */ |
| 621 |
bitmap empty; |
| 622 |
|
| 623 |
/* Unshare the index, currently only need |
| 624 |
to unshare if the entry was empty. */ |
| 625 |
void unshare(int indx) |
| 626 |
{ |
| 627 |
if (vars_ssa_caches[indx].bmap == empty) |
| 628 |
vars_ssa_caches[indx].bmap = BITMAP_ALLOC (&stack_var_bitmap_obstack); |
| 629 |
} |
| 630 |
void create (tree); |
| 631 |
bool exists (tree use); |
| 632 |
void add_one (tree old_name, unsigned); |
| 633 |
bool update (tree old_name, tree use); |
| 634 |
}; |
| 635 |
|
| 636 |
/* Constructor of the cache, create the cache array. */ |
| 637 |
vars_ssa_cache::vars_ssa_cache () |
| 638 |
{ |
| 639 |
vars_ssa_caches = new entry[num_ssa_names]{}; |
| 640 |
|
| 641 |
/* Create the shared empty bitmap too. */ |
| 642 |
empty = BITMAP_ALLOC (&stack_var_bitmap_obstack); |
| 643 |
} |
| 644 |
|
| 645 |
/* Delete the array. The bitmaps will be freed |
| 646 |
when stack_var_bitmap_obstack is freed. */ |
| 647 |
vars_ssa_cache::~vars_ssa_cache () |
| 648 |
{ |
| 649 |
delete []vars_ssa_caches; |
| 650 |
} |
| 651 |
|
| 652 |
/* Create an empty entry for the USE ssa name. */ |
| 653 |
void |
| 654 |
vars_ssa_cache::create (tree use) |
| 655 |
{ |
| 656 |
int num = SSA_NAME_VERSION (use); |
| 657 |
if (vars_ssa_caches[num].bmap) |
| 658 |
return; |
| 659 |
vars_ssa_caches[num].bmap = empty; |
| 660 |
} |
| 661 |
|
| 662 |
/* Returns true if the cache for USE exists. */ |
| 663 |
bool |
| 664 |
vars_ssa_cache::exists (tree use) |
| 665 |
{ |
| 666 |
int num = SSA_NAME_VERSION (use); |
| 667 |
return vars_ssa_caches[num].bmap != nullptr; |
| 668 |
} |
| 669 |
|
| 670 |
/* Add to USE's bitmap for stack variable IDX. */ |
| 671 |
void |
| 672 |
vars_ssa_cache::add_one (tree use, unsigned idx) |
| 673 |
{ |
| 674 |
gcc_assert (idx != INVALID_STACK_INDEX); |
| 675 |
int num = SSA_NAME_VERSION (use); |
| 676 |
gcc_assert (vars_ssa_caches[num].bmap); |
| 677 |
unshare (num); |
| 678 |
bitmap_set_bit (vars_ssa_caches[num].bmap, idx); |
| 679 |
} |
| 680 |
|
| 681 |
/* Update cache of OLD_NAME from the USE's cache. */ |
| 682 |
bool |
| 683 |
vars_ssa_cache::update (tree old_name, tree use) |
| 684 |
{ |
| 685 |
if (old_name == use) |
| 686 |
return false; |
| 687 |
int num = SSA_NAME_VERSION (use); |
| 688 |
int old_num = SSA_NAME_VERSION (old_name); |
| 689 |
|
| 690 |
/* If the old name was empty, then there is nothing to be updated. */ |
| 691 |
if (vars_ssa_caches[num].bmap == empty) |
| 692 |
return false; |
| 693 |
unshare (old_num); |
| 694 |
return bitmap_ior_into (vars_ssa_caches[old_num].bmap, vars_ssa_caches[num].bmap); |
| 695 |
} |
| 696 |
|
| 697 |
/* Dump out the cache. Note empty and non-filled |
| 698 |
in ssa names are not printed out. */ |
| 699 |
void |
| 700 |
vars_ssa_cache::dump (FILE *file) |
| 701 |
{ |
| 702 |
fprintf (file, "var ssa address cache\n"); |
| 703 |
for (unsigned num = 0; num < num_ssa_names; num++) |
| 704 |
{ |
| 705 |
if (!vars_ssa_caches[num].bmap |
| 706 |
|| vars_ssa_caches[num].bmap == empty) |
| 707 |
continue; |
| 708 |
fprintf (file, "_%d refers to:\n", num); |
| 709 |
bitmap_iterator bi; |
| 710 |
unsigned i; |
| 711 |
EXECUTE_IF_SET_IN_BITMAP (vars_ssa_caches[num].bmap, 0, i, bi) |
| 712 |
{ |
| 713 |
fputc ('\t', file); |
| 714 |
print_generic_expr (file, stack_vars[i].decl, dump_flags); |
| 715 |
} |
| 716 |
fputc ('\n', file); |
| 717 |
} |
| 718 |
fputc ('\n', file); |
| 719 |
} |
| 720 |
|
| 721 |
/* Returns the filled in cache for NAME. |
| 722 |
This will fill in the cache if it does not exist already. |
| 723 |
Returns an empty for ssa names that can't contain pointers |
| 724 |
(only intergal types and pointer types will contain pointers). */ |
| 725 |
|
| 726 |
const_bitmap |
| 727 |
vars_ssa_cache::operator() (tree name) |
| 728 |
{ |
| 729 |
gcc_assert (TREE_CODE (name) == SSA_NAME); |
| 730 |
|
| 731 |
if (!POINTER_TYPE_P (TREE_TYPE (name)) |
| 732 |
&& !ANY_INTEGRAL_TYPE_P (TREE_TYPE (name))) |
| 733 |
return empty; |
| 734 |
|
| 735 |
if (exists (name)) |
| 736 |
return vars_ssa_caches[SSA_NAME_VERSION (name)].bmap; |
| 737 |
|
| 738 |
auto_vec<std::pair<tree,tree>, 4> work_list; |
| 739 |
auto_vec<std::pair<tree,tree>, 4> update_cache_list; |
| 740 |
|
| 741 |
work_list.safe_push (std::make_pair (name, name)); |
| 742 |
|
| 743 |
while (!work_list.is_empty ()) |
| 744 |
{ |
| 745 |
auto item = work_list.pop(); |
| 746 |
tree use = item.first; |
| 747 |
tree old_name = item.second; |
| 748 |
if (TREE_CODE (use) == ADDR_EXPR) |
| 749 |
{ |
| 750 |
tree op = TREE_OPERAND (use, 0); |
| 751 |
op = get_base_address (op); |
| 752 |
unsigned idx = decl_stack_index (op); |
| 753 |
if (idx != INVALID_STACK_INDEX) |
| 754 |
add_one (old_name, idx); |
| 755 |
continue; |
| 756 |
} |
| 757 |
|
| 758 |
if (TREE_CODE (use) != SSA_NAME) |
| 759 |
continue; |
| 760 |
|
| 761 |
if (!POINTER_TYPE_P (TREE_TYPE (use)) |
| 762 |
&& !ANY_INTEGRAL_TYPE_P (TREE_TYPE (use))) |
| 763 |
continue; |
| 764 |
|
| 765 |
/* Mark the old ssa name needs to be update from the use. */ |
| 766 |
update_cache_list.safe_push (item); |
| 767 |
|
| 768 |
/* If the cache exists for the use, don't try to recreate it. */ |
| 769 |
if (exists (use)) |
| 770 |
continue; |
| 771 |
|
| 772 |
/* Create the cache bitmap for the use and also |
| 773 |
so we don't go into an infinite loop for some phi nodes with loops. */ |
| 774 |
create (use); |
| 775 |
|
| 776 |
gimple *g = SSA_NAME_DEF_STMT (use); |
| 777 |
|
| 778 |
/* CONSTRUCTOR here is always a vector initialization, |
| 779 |
walk each element too. */ |
| 780 |
if (gimple_assign_single_p (g) |
| 781 |
&& TREE_CODE (gimple_assign_rhs1 (g)) == CONSTRUCTOR) |
| 782 |
{ |
| 783 |
tree ctr = gimple_assign_rhs1 (g); |
| 784 |
unsigned i; |
| 785 |
tree elm; |
| 786 |
FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctr), i, elm) |
| 787 |
work_list.safe_push (std::make_pair (elm, use)); |
| 788 |
} |
| 789 |
/* For assignments, walk each operand for possible addresses. |
| 790 |
For PHI nodes, walk each argument. */ |
| 791 |
else if (gassign *a = dyn_cast <gassign *> (g)) |
| 792 |
{ |
| 793 |
/* operand 0 is the lhs. */ |
| 794 |
for (unsigned i = 1; i < gimple_num_ops (g); i++) |
| 795 |
work_list.safe_push (std::make_pair (gimple_op (a, i), use)); |
| 796 |
} |
| 797 |
else if (gphi *p = dyn_cast <gphi *> (g)) |
| 798 |
for (unsigned i = 0; i < gimple_phi_num_args (p); ++i) |
| 799 |
work_list.safe_push (std::make_pair (gimple_phi_arg_def (p, i), use)); |
| 800 |
} |
| 801 |
|
| 802 |
/* Update the cache. Note a loop is needed as phi nodes could |
| 803 |
cause a loop to form. The number of times through this loop |
| 804 |
will be small though. */ |
| 805 |
bool changed; |
| 806 |
do { |
| 807 |
changed = false; |
| 808 |
for (auto &e : update_cache_list) |
| 809 |
{ |
| 810 |
if (update (e.second, e.first)) |
| 811 |
changed = true; |
| 812 |
} |
| 813 |
} while (changed); |
| 814 |
|
| 815 |
return vars_ssa_caches[SSA_NAME_VERSION (name)].bmap; |
| 816 |
} |
| 817 |
|
| 818 |
/* Helper function for add_scope_conflicts_1. For USE on |
| 819 |
a stmt, if it is a SSA_NAME and in its defining statement |
| 820 |
is known to be based on some ADDR_EXPR, invoke VISIT |
| 821 |
on that ADDR_EXPR. */ |
| 822 |
|
| 823 |
static inline void |
| 824 |
add_scope_conflicts_2 (vars_ssa_cache &cache, tree name, |
| 825 |
bitmap work, walk_stmt_load_store_addr_fn visit) |
| 826 |
{ |
| 827 |
gcc_assert (TREE_CODE (name) == SSA_NAME); |
| 828 |
|
| 829 |
/* Querry the cache for the mapping of addresses that are referendd by |
| 830 |
ssa name NAME. Querrying it will fill in it. */ |
| 831 |
bitmap_iterator bi; |
| 832 |
unsigned i; |
| 833 |
const_bitmap bmap = cache (name); |
| 834 |
/* Visit each stack variable that is referenced. */ |
| 835 |
EXECUTE_IF_SET_IN_BITMAP (bmap, 0, i, bi) |
| 836 |
visit (nullptr, stack_vars[i].decl, nullptr, work); |
| 837 |
} |
| 838 |
|
| 839 |
/* Helper routine for add_scope_conflicts, calculating the active partitions |
| 840 |
at the end of BB, leaving the result in WORK. We're called to generate |
| 841 |
conflicts when FOR_CONFLICT is true, otherwise we're just tracking |
| 842 |
liveness. */ |
| 843 |
|
| 844 |
static void |
| 845 |
add_scope_conflicts_1 (vars_ssa_cache &cache, basic_block bb, bitmap work, bool for_conflict) |
| 846 |
{ |
| 847 |
edge e; |
| 848 |
edge_iterator ei; |
| 849 |
gimple_stmt_iterator gsi; |
| 850 |
walk_stmt_load_store_addr_fn visit; |
| 851 |
use_operand_p use_p; |
| 852 |
ssa_op_iter iter; |
| 853 |
bool had_non_clobbers = false; |
| 854 |
|
| 855 |
bitmap_clear (work); |
| 856 |
/* The copy what was alive out going from the edges. */ |
| 857 |
FOR_EACH_EDGE (e, ei, bb->preds) |
| 858 |
bitmap_ior_into (work, (bitmap)e->src->aux); |
| 859 |
|
| 860 |
visit = for_conflict ? visit_conflict : visit_op; |
| 861 |
|
| 862 |
/* Addresses coming into the bb via phis are alive at the entry point. */ |
| 863 |
for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
| 864 |
add_scope_conflicts_2 (cache, gimple_phi_result (gsi_stmt (gsi)), work, visit_op); |
| 865 |
|
| 866 |
for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
| 867 |
{ |
| 868 |
gimple *stmt = gsi_stmt (gsi); |
| 869 |
|
| 870 |
/* Debug statements are not considered for liveness. */ |
| 871 |
if (is_gimple_debug (stmt)) |
| 872 |
continue; |
| 873 |
|
| 874 |
/* If we had `var = {CLOBBER}`, then var is no longer |
| 875 |
considered alive after this point but might become |
| 876 |
alive later on. */ |
| 877 |
if (gimple_clobber_p (stmt)) |
| 878 |
{ |
| 879 |
tree lhs = gimple_assign_lhs (stmt); |
| 880 |
/* Handle only plain var clobbers, not partial ones. |
| 881 |
Nested functions lowering and C++ front-end inserts clobbers |
| 882 |
which are partial clobbers. */ |
| 883 |
if (!VAR_P (lhs)) |
| 884 |
continue; |
| 885 |
unsigned indx = decl_stack_index (lhs); |
| 886 |
if (indx != INVALID_STACK_INDEX) |
| 887 |
bitmap_clear_bit (work, indx); |
| 888 |
} |
| 889 |
else |
| 890 |
{ |
| 891 |
if (for_conflict && !had_non_clobbers) |
| 892 |
{ |
| 893 |
/* When we are inheriting live variables from our predecessors |
| 894 |
through a CFG merge we might not see an actual mention of |
| 895 |
the variables to record the approprate conflict as defs/uses |
| 896 |
might be through indirect stores/loads. For this reason |
| 897 |
we have to make sure each live variable conflicts with |
| 898 |
each other. When there's just a single predecessor the |
| 899 |
set of conflicts is already up-to-date. |
| 900 |
We perform this delayed at the first real instruction to |
| 901 |
allow clobbers starting this block to remove variables from |
| 902 |
the set of live variables. */ |
| 903 |
bitmap_iterator bi; |
| 904 |
unsigned i; |
| 905 |
if (EDGE_COUNT (bb->preds) > 1) |
| 906 |
EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi) |
| 907 |
{ |
| 908 |
class stack_var *a = &stack_vars[i]; |
| 909 |
if (!a->conflicts) |
| 910 |
a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack); |
| 911 |
bitmap_ior_into (a->conflicts, work); |
| 912 |
} |
| 913 |
had_non_clobbers = true; |
| 914 |
} |
| 915 |
walk_stmt_load_store_addr_ops (stmt, work, visit, visit, visit); |
| 916 |
FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE) |
| 917 |
add_scope_conflicts_2 (cache, USE_FROM_PTR (use_p), work, visit); |
| 918 |
} |
| 919 |
} |
| 920 |
|
| 921 |
/* When there was no real instruction but there's a CFG merge we need |
| 922 |
to add the conflicts now. */ |
| 923 |
if (for_conflict && !had_non_clobbers && EDGE_COUNT (bb->preds) > 1) |
| 924 |
{ |
| 925 |
bitmap_iterator bi; |
| 926 |
unsigned i; |
| 927 |
EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi) |
| 928 |
{ |
| 929 |
class stack_var *a = &stack_vars[i]; |
| 930 |
if (!a->conflicts) |
| 931 |
a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack); |
| 932 |
bitmap_ior_into (a->conflicts, work); |
| 933 |
} |
| 934 |
} |
| 935 |
} |
| 936 |
|
| 937 |
/* Generate stack partition conflicts between all partitions that are |
| 938 |
simultaneously live. */ |
| 939 |
|
| 940 |
static void |
| 941 |
add_scope_conflicts (void) |
| 942 |
{ |
| 943 |
/* If there is only one variable, there is nothing to be done as |
| 944 |
there is only possible partition. */ |
| 945 |
if (stack_vars_num == 1) |
| 946 |
return; |
| 947 |
|
| 948 |
basic_block bb; |
| 949 |
bool changed; |
| 950 |
bitmap work = BITMAP_ALLOC (NULL); |
| 951 |
int *rpo; |
| 952 |
int n_bbs; |
| 953 |
|
| 954 |
vars_ssa_cache cache; |
| 955 |
|
| 956 |
/* We approximate the live range of a stack variable by taking the first |
| 957 |
mention of its name as starting point(s), and by the end-of-scope |
| 958 |
death clobber added by gimplify as ending point(s) of the range. |
| 959 |
This overapproximates in the case we for instance moved an address-taken |
| 960 |
operation upward, without also moving a dereference to it upwards. |
| 961 |
But it's conservatively correct as a variable never can hold values |
| 962 |
before its name is mentioned at least once. |
| 963 |
|
| 964 |
We then do a mostly classical bitmap liveness algorithm. */ |
| 965 |
|
| 966 |
FOR_ALL_BB_FN (bb, cfun) |
| 967 |
bb->aux = BITMAP_ALLOC (&stack_var_bitmap_obstack); |
| 968 |
|
| 969 |
rpo = XNEWVEC (int, last_basic_block_for_fn (cfun)); |
| 970 |
n_bbs = pre_and_rev_post_order_compute (NULL, rpo, false); |
| 971 |
|
| 972 |
changed = true; |
| 973 |
while (changed) |
| 974 |
{ |
| 975 |
int i; |
| 976 |
changed = false; |
| 977 |
for (i = 0; i < n_bbs; i++) |
| 978 |
{ |
| 979 |
bitmap active; |
| 980 |
bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]); |
| 981 |
active = (bitmap)bb->aux; |
| 982 |
add_scope_conflicts_1 (cache, bb, work, false); |
| 983 |
if (bitmap_ior_into (active, work)) |
| 984 |
changed = true; |
| 985 |
} |
| 986 |
} |
| 987 |
|
| 988 |
FOR_EACH_BB_FN (bb, cfun) |
| 989 |
add_scope_conflicts_1 (cache, bb, work, true); |
| 990 |
|
| 991 |
if (dump_file && (dump_flags & TDF_DETAILS)) |
| 992 |
cache.dump (dump_file); |
| 993 |
|
| 994 |
free (rpo); |
| 995 |
BITMAP_FREE (work); |
| 996 |
FOR_ALL_BB_FN (bb, cfun) |
| 997 |
BITMAP_FREE (bb->aux); |
| 998 |
} |
| 999 |
|
| 1000 |
/* A subroutine of partition_stack_vars. A comparison function for qsort, |
| 1001 |
sorting an array of indices by the properties of the object. */ |
| 1002 |
|
| 1003 |
static int |
| 1004 |
stack_var_cmp (const void *a, const void *b) |
| 1005 |
{ |
| 1006 |
unsigned ia = *(const unsigned *)a; |
| 1007 |
unsigned ib = *(const unsigned *)b; |
| 1008 |
unsigned int aligna = stack_vars[ia].alignb; |
| 1009 |
unsigned int alignb = stack_vars[ib].alignb; |
| 1010 |
poly_int64 sizea = stack_vars[ia].size; |
| 1011 |
poly_int64 sizeb = stack_vars[ib].size; |
| 1012 |
tree decla = stack_vars[ia].decl; |
| 1013 |
tree declb = stack_vars[ib].decl; |
| 1014 |
bool largea, largeb; |
| 1015 |
unsigned int uida, uidb; |
| 1016 |
|
| 1017 |
/* Primary compare on "large" alignment. Large comes first. */ |
| 1018 |
largea = (aligna * BITS_PER_UNIT > MAX_SUPPORTED_STACK_ALIGNMENT); |
| 1019 |
largeb = (alignb * BITS_PER_UNIT > MAX_SUPPORTED_STACK_ALIGNMENT); |
| 1020 |
if (largea != largeb) |
| 1021 |
return (int)largeb - (int)largea; |
| 1022 |
|
| 1023 |
/* Secondary compare on size, decreasing */ |
| 1024 |
int diff = compare_sizes_for_sort (sizeb, sizea); |
| 1025 |
if (diff != 0) |
| 1026 |
return diff; |
| 1027 |
|
| 1028 |
/* Tertiary compare on true alignment, decreasing. */ |
| 1029 |
if (aligna < alignb) |
| 1030 |
return -1; |
| 1031 |
if (aligna > alignb) |
| 1032 |
return 1; |
| 1033 |
|
| 1034 |
/* Final compare on ID for sort stability, increasing. |
| 1035 |
Two SSA names are compared by their version, SSA names come before |
| 1036 |
non-SSA names, and two normal decls are compared by their DECL_UID. */ |
| 1037 |
if (TREE_CODE (decla) == SSA_NAME) |
| 1038 |
{ |
| 1039 |
if (TREE_CODE (declb) == SSA_NAME) |
| 1040 |
uida = SSA_NAME_VERSION (decla), uidb = SSA_NAME_VERSION (declb); |
| 1041 |
else |
| 1042 |
return -1; |
| 1043 |
} |
| 1044 |
else if (TREE_CODE (declb) == SSA_NAME) |
| 1045 |
return 1; |
| 1046 |
else |
| 1047 |
uida = DECL_UID (decla), uidb = DECL_UID (declb); |
| 1048 |
if (uida < uidb) |
| 1049 |
return 1; |
| 1050 |
if (uida > uidb) |
| 1051 |
return -1; |
| 1052 |
return 0; |
| 1053 |
} |
| 1054 |
|
| 1055 |
struct part_traits : unbounded_int_hashmap_traits <unsigned , bitmap> {}; |
| 1056 |
typedef hash_map<unsigned, bitmap, part_traits> part_hashmap; |
| 1057 |
|
| 1058 |
/* If the points-to solution *PI points to variables that are in a partition |
| 1059 |
together with other variables add all partition members to the pointed-to |
| 1060 |
variables bitmap. */ |
| 1061 |
|
| 1062 |
static void |
| 1063 |
add_partitioned_vars_to_ptset (struct pt_solution *pt, |
| 1064 |
part_hashmap *decls_to_partitions, |
| 1065 |
hash_set<bitmap> *visited, bitmap temp) |
| 1066 |
{ |
| 1067 |
bitmap_iterator bi; |
| 1068 |
unsigned i; |
| 1069 |
bitmap *part; |
| 1070 |
|
| 1071 |
if (pt->anything |
| 1072 |
|| pt->vars == NULL |
| 1073 |
/* The pointed-to vars bitmap is shared, it is enough to |
| 1074 |
visit it once. */ |
| 1075 |
|| visited->add (pt->vars)) |
| 1076 |
return; |
| 1077 |
|
| 1078 |
bitmap_clear (temp); |
| 1079 |
|
| 1080 |
/* By using a temporary bitmap to store all members of the partitions |
| 1081 |
we have to add we make sure to visit each of the partitions only |
| 1082 |
once. */ |
| 1083 |
EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi) |
| 1084 |
if ((!temp |
| 1085 |
|| !bitmap_bit_p (temp, i)) |
| 1086 |
&& (part = decls_to_partitions->get (i))) |
| 1087 |
bitmap_ior_into (temp, *part); |
| 1088 |
if (!bitmap_empty_p (temp)) |
| 1089 |
bitmap_ior_into (pt->vars, temp); |
| 1090 |
} |
| 1091 |
|
| 1092 |
/* Update points-to sets based on partition info, so we can use them on RTL. |
| 1093 |
The bitmaps representing stack partitions will be saved until expand, |
| 1094 |
where partitioned decls used as bases in memory expressions will be |
| 1095 |
rewritten. |
| 1096 |
|
| 1097 |
It is not necessary to update TBAA info on accesses to the coalesced |
| 1098 |
storage since our memory model doesn't allow TBAA to be used for |
| 1099 |
WAW or WAR dependences. For RAW when the write is to an old object |
| 1100 |
the new object would not have been initialized at the point of the |
| 1101 |
read, invoking undefined behavior. */ |
| 1102 |
|
| 1103 |
static void |
| 1104 |
update_alias_info_with_stack_vars (void) |
| 1105 |
{ |
| 1106 |
part_hashmap *decls_to_partitions = NULL; |
| 1107 |
unsigned i, j; |
| 1108 |
tree var = NULL_TREE; |
| 1109 |
|
| 1110 |
for (i = 0; i < stack_vars_num; i++) |
| 1111 |
{ |
| 1112 |
bitmap part = NULL; |
| 1113 |
tree name; |
| 1114 |
struct ptr_info_def *pi; |
| 1115 |
|
| 1116 |
/* Not interested in partitions with single variable. */ |
| 1117 |
if (stack_vars[i].representative != i |
| 1118 |
|| stack_vars[i].next == EOC) |
| 1119 |
continue; |
| 1120 |
|
| 1121 |
if (!decls_to_partitions) |
| 1122 |
{ |
| 1123 |
decls_to_partitions = new part_hashmap; |
| 1124 |
cfun->gimple_df->decls_to_pointers = new hash_map<tree, tree>; |
| 1125 |
} |
| 1126 |
|
| 1127 |
/* Create an SSA_NAME that points to the partition for use |
| 1128 |
as base during alias-oracle queries on RTL for bases that |
| 1129 |
have been partitioned. */ |
| 1130 |
if (var == NULL_TREE) |
| 1131 |
var = create_tmp_var (ptr_type_node); |
| 1132 |
name = make_ssa_name (var); |
| 1133 |
|
| 1134 |
/* Create bitmaps representing partitions. They will be used for |
| 1135 |
points-to sets later, so use GGC alloc. */ |
| 1136 |
part = BITMAP_GGC_ALLOC (); |
| 1137 |
for (j = i; j != EOC; j = stack_vars[j].next) |
| 1138 |
{ |
| 1139 |
tree decl = stack_vars[j].decl; |
| 1140 |
unsigned int uid = DECL_PT_UID (decl); |
| 1141 |
bitmap_set_bit (part, uid); |
| 1142 |
decls_to_partitions->put (uid, part); |
| 1143 |
cfun->gimple_df->decls_to_pointers->put (decl, name); |
| 1144 |
if (TREE_ADDRESSABLE (decl)) |
| 1145 |
TREE_ADDRESSABLE (name) = 1; |
| 1146 |
} |
| 1147 |
|
| 1148 |
/* Make the SSA name point to all partition members. */ |
| 1149 |
pi = get_ptr_info (name); |
| 1150 |
pt_solution_set (&pi->pt, part, false); |
| 1151 |
} |
| 1152 |
|
| 1153 |
/* Make all points-to sets that contain one member of a partition |
| 1154 |
contain all members of the partition. */ |
| 1155 |
if (decls_to_partitions) |
| 1156 |
{ |
| 1157 |
unsigned i; |
| 1158 |
tree name; |
| 1159 |
hash_set<bitmap> visited; |
| 1160 |
bitmap temp = BITMAP_ALLOC (&stack_var_bitmap_obstack); |
| 1161 |
|
| 1162 |
FOR_EACH_SSA_NAME (i, name, cfun) |
| 1163 |
{ |
| 1164 |
struct ptr_info_def *pi; |
| 1165 |
|
| 1166 |
if (POINTER_TYPE_P (TREE_TYPE (name)) |
| 1167 |
&& ((pi = SSA_NAME_PTR_INFO (name)) != NULL)) |
| 1168 |
add_partitioned_vars_to_ptset (&pi->pt, decls_to_partitions, |
| 1169 |
&visited, temp); |
| 1170 |
} |
| 1171 |
|
| 1172 |
add_partitioned_vars_to_ptset (&cfun->gimple_df->escaped, |
| 1173 |
decls_to_partitions, &visited, temp); |
| 1174 |
add_partitioned_vars_to_ptset (&cfun->gimple_df->escaped_return, |
| 1175 |
decls_to_partitions, &visited, temp); |
| 1176 |
delete decls_to_partitions; |
| 1177 |
BITMAP_FREE (temp); |
| 1178 |
} |
| 1179 |
} |
| 1180 |
|
| 1181 |
/* A subroutine of partition_stack_vars. The UNION portion of a UNION/FIND |
| 1182 |
partitioning algorithm. Partitions A and B are known to be non-conflicting. |
| 1183 |
Merge them into a single partition A. */ |
| 1184 |
|
| 1185 |
static void |
| 1186 |
union_stack_vars (unsigned a, unsigned b) |
| 1187 |
{ |
| 1188 |
class stack_var *vb = &stack_vars[b]; |
| 1189 |
bitmap_iterator bi; |
| 1190 |
unsigned u; |
| 1191 |
|
| 1192 |
gcc_assert (stack_vars[b].next == EOC); |
| 1193 |
/* Add B to A's partition. */ |
| 1194 |
stack_vars[b].next = stack_vars[a].next; |
| 1195 |
stack_vars[b].representative = a; |
| 1196 |
stack_vars[a].next = b; |
| 1197 |
|
| 1198 |
/* Make sure A is big enough to hold B. */ |
| 1199 |
stack_vars[a].size = upper_bound (stack_vars[a].size, stack_vars[b].size); |
| 1200 |
|
| 1201 |
/* Update the required alignment of partition A to account for B. */ |
| 1202 |
if (stack_vars[a].alignb < stack_vars[b].alignb) |
| 1203 |
stack_vars[a].alignb = stack_vars[b].alignb; |
| 1204 |
|
| 1205 |
/* Update the interference graph and merge the conflicts. */ |
| 1206 |
if (vb->conflicts) |
| 1207 |
{ |
| 1208 |
EXECUTE_IF_SET_IN_BITMAP (vb->conflicts, 0, u, bi) |
| 1209 |
add_stack_var_conflict (a, stack_vars[u].representative); |
| 1210 |
BITMAP_FREE (vb->conflicts); |
| 1211 |
} |
| 1212 |
} |
| 1213 |
|
| 1214 |
/* A subroutine of expand_used_vars. Binpack the variables into |
| 1215 |
partitions constrained by the interference graph. The overall |
| 1216 |
algorithm used is as follows: |
| 1217 |
|
| 1218 |
Sort the objects by size in descending order. |
| 1219 |
For each object A { |
| 1220 |
S = size(A) |
| 1221 |
O = 0 |
| 1222 |
loop { |
| 1223 |
Look for the largest non-conflicting object B with size <= S. |
| 1224 |
UNION (A, B) |
| 1225 |
} |
| 1226 |
} |
| 1227 |
*/ |
| 1228 |
|
| 1229 |
static void |
| 1230 |
partition_stack_vars (void) |
| 1231 |
{ |
| 1232 |
unsigned si, sj, n = stack_vars_num; |
| 1233 |
|
| 1234 |
stack_vars_sorted = XNEWVEC (unsigned, stack_vars_num); |
| 1235 |
for (si = 0; si < n; ++si) |
| 1236 |
stack_vars_sorted[si] = si; |
| 1237 |
|
| 1238 |
if (n == 1) |
| 1239 |
return; |
| 1240 |
|
| 1241 |
qsort (stack_vars_sorted, n, sizeof (unsigned), stack_var_cmp); |
| 1242 |
|
| 1243 |
for (si = 0; si < n; ++si) |
| 1244 |
{ |
| 1245 |
unsigned i = stack_vars_sorted[si]; |
| 1246 |
unsigned int ialign = stack_vars[i].alignb; |
| 1247 |
poly_int64 isize = stack_vars[i].size; |
| 1248 |
|
| 1249 |
/* Ignore objects that aren't partition representatives. If we |
| 1250 |
see a var that is not a partition representative, it must |
| 1251 |
have been merged earlier. */ |
| 1252 |
if (stack_vars[i].representative != i) |
| 1253 |
continue; |
| 1254 |
|
| 1255 |
for (sj = si + 1; sj < n; ++sj) |
| 1256 |
{ |
| 1257 |
unsigned j = stack_vars_sorted[sj]; |
| 1258 |
unsigned int jalign = stack_vars[j].alignb; |
| 1259 |
poly_int64 jsize = stack_vars[j].size; |
| 1260 |
|
| 1261 |
/* Ignore objects that aren't partition representatives. */ |
| 1262 |
if (stack_vars[j].representative != j) |
| 1263 |
continue; |
| 1264 |
|
| 1265 |
/* Do not mix objects of "small" (supported) alignment |
| 1266 |
and "large" (unsupported) alignment. */ |
| 1267 |
if ((ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT) |
| 1268 |
!= (jalign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)) |
| 1269 |
break; |
| 1270 |
|
| 1271 |
/* For Address Sanitizer do not mix objects with different |
| 1272 |
sizes, as the shorter vars wouldn't be adequately protected. |
| 1273 |
Don't do that for "large" (unsupported) alignment objects, |
| 1274 |
those aren't protected anyway. */ |
| 1275 |
if (asan_sanitize_stack_p () |
| 1276 |
&& maybe_ne (isize, jsize) |
| 1277 |
&& ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT) |
| 1278 |
break; |
| 1279 |
|
| 1280 |
/* Ignore conflicting objects. */ |
| 1281 |
if (stack_var_conflict_p (i, j)) |
| 1282 |
continue; |
| 1283 |
|
| 1284 |
/* UNION the objects, placing J at OFFSET. */ |
| 1285 |
union_stack_vars (i, j); |
| 1286 |
} |
| 1287 |
} |
| 1288 |
|
| 1289 |
update_alias_info_with_stack_vars (); |
| 1290 |
} |
| 1291 |
|
| 1292 |
/* A debugging aid for expand_used_vars. Dump the generated partitions. */ |
| 1293 |
|
| 1294 |
static void |
| 1295 |
dump_stack_var_partition (void) |
| 1296 |
{ |
| 1297 |
unsigned si, i, j, n = stack_vars_num; |
| 1298 |
|
| 1299 |
for (si = 0; si < n; ++si) |
| 1300 |
{ |
| 1301 |
i = stack_vars_sorted[si]; |
| 1302 |
|
| 1303 |
/* Skip variables that aren't partition representatives, for now. */ |
| 1304 |
if (stack_vars[i].representative != i) |
| 1305 |
continue; |
| 1306 |
|
| 1307 |
fprintf (dump_file, "Partition %u: size ", i); |
| 1308 |
print_dec (stack_vars[i].size, dump_file); |
| 1309 |
fprintf (dump_file, " align %u\n", stack_vars[i].alignb); |
| 1310 |
|
| 1311 |
for (j = i; j != EOC; j = stack_vars[j].next) |
| 1312 |
{ |
| 1313 |
fputc ('\t', dump_file); |
| 1314 |
print_generic_expr (dump_file, stack_vars[j].decl, dump_flags); |
| 1315 |
} |
| 1316 |
fputc ('\n', dump_file); |
| 1317 |
} |
| 1318 |
} |
| 1319 |
|
| 1320 |
/* Assign rtl to DECL at BASE + OFFSET. */ |
| 1321 |
|
| 1322 |
static void |
| 1323 |
expand_one_stack_var_at (tree decl, rtx base, unsigned base_align, |
| 1324 |
poly_int64 offset) |
| 1325 |
{ |
| 1326 |
unsigned align; |
| 1327 |
rtx x; |
| 1328 |
|
| 1329 |
/* If this fails, we've overflowed the stack frame. Error nicely? */ |
| 1330 |
gcc_assert (known_eq (offset, trunc_int_for_mode (offset, Pmode))); |
| 1331 |
|
| 1332 |
if (hwasan_sanitize_stack_p ()) |
| 1333 |
x = targetm.memtag.add_tag (base, offset, |
| 1334 |
hwasan_current_frame_tag ()); |
| 1335 |
else |
| 1336 |
x = plus_constant (Pmode, base, offset); |
| 1337 |
|
| 1338 |
x = gen_rtx_MEM (TREE_CODE (decl) == SSA_NAME |
| 1339 |
? TYPE_MODE (TREE_TYPE (decl)) |
| 1340 |
: DECL_MODE (decl), x); |
| 1341 |
|
| 1342 |
/* Set alignment we actually gave this decl if it isn't an SSA name. |
| 1343 |
If it is we generate stack slots only accidentally so it isn't as |
| 1344 |
important, we'll simply set the alignment directly on the MEM. */ |
| 1345 |
|
| 1346 |
if (stack_vars_base_reg_p (base)) |
| 1347 |
offset -= frame_phase; |
| 1348 |
align = known_alignment (offset); |
| 1349 |
align *= BITS_PER_UNIT; |
| 1350 |
if (align == 0 || align > base_align) |
| 1351 |
align = base_align; |
| 1352 |
|
| 1353 |
if (TREE_CODE (decl) != SSA_NAME) |
| 1354 |
{ |
| 1355 |
/* One would think that we could assert that we're not decreasing |
| 1356 |
alignment here, but (at least) the i386 port does exactly this |
| 1357 |
via the MINIMUM_ALIGNMENT hook. */ |
| 1358 |
|
| 1359 |
SET_DECL_ALIGN (decl, align); |
| 1360 |
DECL_USER_ALIGN (decl) = 0; |
| 1361 |
} |
| 1362 |
|
| 1363 |
set_rtl (decl, x); |
| 1364 |
|
| 1365 |
set_mem_align (x, align); |
| 1366 |
} |
| 1367 |
|
| 1368 |
class stack_vars_data |
| 1369 |
{ |
| 1370 |
public: |
| 1371 |
/* Vector of offset pairs, always end of some padding followed |
| 1372 |
by start of the padding that needs Address Sanitizer protection. |
| 1373 |
The vector is in reversed, highest offset pairs come first. */ |
| 1374 |
auto_vec<HOST_WIDE_INT> asan_vec; |
| 1375 |
|
| 1376 |
/* Vector of partition representative decls in between the paddings. */ |
| 1377 |
auto_vec<tree> asan_decl_vec; |
| 1378 |
|
| 1379 |
/* Base pseudo register for Address Sanitizer protected automatic vars. */ |
| 1380 |
rtx asan_base; |
| 1381 |
|
| 1382 |
/* Alignment needed for the Address Sanitizer protected automatic vars. */ |
| 1383 |
unsigned int asan_alignb; |
| 1384 |
}; |
| 1385 |
|
| 1386 |
/* A subroutine of expand_used_vars. Give each partition representative |
| 1387 |
a unique location within the stack frame. Update each partition member |
| 1388 |
with that location. */ |
| 1389 |
static void |
| 1390 |
expand_stack_vars (bool (*pred) (unsigned), class stack_vars_data *data) |
| 1391 |
{ |
| 1392 |
unsigned si, i, j, n = stack_vars_num; |
| 1393 |
poly_uint64 large_size = 0, large_alloc = 0; |
| 1394 |
rtx large_base = NULL; |
| 1395 |
rtx large_untagged_base = NULL; |
| 1396 |
unsigned large_align = 0; |
| 1397 |
bool large_allocation_done = false; |
| 1398 |
tree decl; |
| 1399 |
|
| 1400 |
/* Determine if there are any variables requiring "large" alignment. |
| 1401 |
Since these are dynamically allocated, we only process these if |
| 1402 |
no predicate involved. */ |
| 1403 |
large_align = stack_vars[stack_vars_sorted[0]].alignb * BITS_PER_UNIT; |
| 1404 |
if (pred == NULL && large_align > MAX_SUPPORTED_STACK_ALIGNMENT) |
| 1405 |
{ |
| 1406 |
/* Find the total size of these variables. */ |
| 1407 |
for (si = 0; si < n; ++si) |
| 1408 |
{ |
| 1409 |
unsigned alignb; |
| 1410 |
|
| 1411 |
i = stack_vars_sorted[si]; |
| 1412 |
alignb = stack_vars[i].alignb; |
| 1413 |
|
| 1414 |
/* All "large" alignment decls come before all "small" alignment |
| 1415 |
decls, but "large" alignment decls are not sorted based on |
| 1416 |
their alignment. Increase large_align to track the largest |
| 1417 |
required alignment. */ |
| 1418 |
if ((alignb * BITS_PER_UNIT) > large_align) |
| 1419 |
large_align = alignb * BITS_PER_UNIT; |
| 1420 |
|
| 1421 |
/* Stop when we get to the first decl with "small" alignment. */ |
| 1422 |
if (alignb * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT) |
| 1423 |
break; |
| 1424 |
|
| 1425 |
/* Skip variables that aren't partition representatives. */ |
| 1426 |
if (stack_vars[i].representative != i) |
| 1427 |
continue; |
| 1428 |
|
| 1429 |
/* Skip variables that have already had rtl assigned. See also |
| 1430 |
add_stack_var where we perpetrate this pc_rtx hack. */ |
| 1431 |
decl = stack_vars[i].decl; |
| 1432 |
if (TREE_CODE (decl) == SSA_NAME |
| 1433 |
? SA.partition_to_pseudo[var_to_partition (SA.map, decl)] != NULL_RTX |
| 1434 |
: DECL_RTL (decl) != pc_rtx) |
| 1435 |
continue; |
| 1436 |
|
| 1437 |
large_size = aligned_upper_bound (large_size, alignb); |
| 1438 |
large_size += stack_vars[i].size; |
| 1439 |
} |
| 1440 |
} |
| 1441 |
|
| 1442 |
for (si = 0; si < n; ++si) |
| 1443 |
{ |
| 1444 |
rtx base; |
| 1445 |
unsigned base_align, alignb; |
| 1446 |
poly_int64 offset = 0; |
| 1447 |
|
| 1448 |
i = stack_vars_sorted[si]; |
| 1449 |
|
| 1450 |
/* Skip variables that aren't partition representatives, for now. */ |
| 1451 |
if (stack_vars[i].representative != i) |
| 1452 |
continue; |
| 1453 |
|
| 1454 |
/* Skip variables that have already had rtl assigned. See also |
| 1455 |
add_stack_var where we perpetrate this pc_rtx hack. */ |
| 1456 |
decl = stack_vars[i].decl; |
| 1457 |
if (TREE_CODE (decl) == SSA_NAME |
| 1458 |
? SA.partition_to_pseudo[var_to_partition (SA.map, decl)] != NULL_RTX |
| 1459 |
: DECL_RTL (decl) != pc_rtx) |
| 1460 |
continue; |
| 1461 |
|
| 1462 |
/* Check the predicate to see whether this variable should be |
| 1463 |
allocated in this pass. */ |
| 1464 |
if (pred && !pred (i)) |
| 1465 |
continue; |
| 1466 |
|
| 1467 |
base = (hwasan_sanitize_stack_p () |
| 1468 |
? hwasan_frame_base () |
| 1469 |
: virtual_stack_vars_rtx); |
| 1470 |
alignb = stack_vars[i].alignb; |
| 1471 |
if (alignb * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT) |
| 1472 |
{ |
| 1473 |
poly_int64 hwasan_orig_offset; |
| 1474 |
if (hwasan_sanitize_stack_p ()) |
| 1475 |
{ |
| 1476 |
/* There must be no tag granule "shared" between different |
| 1477 |
objects. This means that no HWASAN_TAG_GRANULE_SIZE byte |
| 1478 |
chunk can have more than one object in it. |
| 1479 |
|
| 1480 |
We ensure this by forcing the end of the last bit of data to |
| 1481 |
be aligned to HWASAN_TAG_GRANULE_SIZE bytes here, and setting |
| 1482 |
the start of each variable to be aligned to |
| 1483 |
HWASAN_TAG_GRANULE_SIZE bytes in `align_local_variable`. |
| 1484 |
|
| 1485 |
We can't align just one of the start or end, since there are |
| 1486 |
untagged things stored on the stack which we do not align to |
| 1487 |
HWASAN_TAG_GRANULE_SIZE bytes. If we only aligned the start |
| 1488 |
or the end of tagged objects then untagged objects could end |
| 1489 |
up sharing the first granule of a tagged object or sharing the |
| 1490 |
last granule of a tagged object respectively. */ |
| 1491 |
hwasan_orig_offset = align_frame_offset (HWASAN_TAG_GRANULE_SIZE); |
| 1492 |
gcc_assert (stack_vars[i].alignb >= HWASAN_TAG_GRANULE_SIZE); |
| 1493 |
} |
| 1494 |
/* ASAN description strings don't yet have a syntax for expressing |
| 1495 |
polynomial offsets. */ |
| 1496 |
HOST_WIDE_INT prev_offset; |
| 1497 |
if (asan_sanitize_stack_p () |
| 1498 |
&& pred |
| 1499 |
&& frame_offset.is_constant (&prev_offset) |
| 1500 |
&& stack_vars[i].size.is_constant ()) |
| 1501 |
{ |
| 1502 |
if (data->asan_vec.is_empty ()) |
| 1503 |
{ |
| 1504 |
align_frame_offset (ASAN_RED_ZONE_SIZE); |
| 1505 |
prev_offset = frame_offset.to_constant (); |
| 1506 |
} |
| 1507 |
prev_offset = align_base (prev_offset, |
| 1508 |
ASAN_MIN_RED_ZONE_SIZE, |
| 1509 |
!FRAME_GROWS_DOWNWARD); |
| 1510 |
tree repr_decl = NULL_TREE; |
| 1511 |
unsigned HOST_WIDE_INT size |
| 1512 |
= asan_var_and_redzone_size (stack_vars[i].size.to_constant ()); |
| 1513 |
if (data->asan_vec.is_empty ()) |
| 1514 |
size = MAX (size, ASAN_RED_ZONE_SIZE); |
| 1515 |
|
| 1516 |
unsigned HOST_WIDE_INT alignment = MAX (alignb, |
| 1517 |
ASAN_MIN_RED_ZONE_SIZE); |
| 1518 |
offset = alloc_stack_frame_space (size, alignment); |
| 1519 |
|
| 1520 |
data->asan_vec.safe_push (prev_offset); |
| 1521 |
/* Allocating a constant amount of space from a constant |
| 1522 |
starting offset must give a constant result. */ |
| 1523 |
data->asan_vec.safe_push ((offset + stack_vars[i].size) |
| 1524 |
.to_constant ()); |
| 1525 |
/* Find best representative of the partition. |
| 1526 |
Prefer those with DECL_NAME, even better |
| 1527 |
satisfying asan_protect_stack_decl predicate. */ |
| 1528 |
for (j = i; j != EOC; j = stack_vars[j].next) |
| 1529 |
if (asan_protect_stack_decl (stack_vars[j].decl) |
| 1530 |
&& DECL_NAME (stack_vars[j].decl)) |
| 1531 |
{ |
| 1532 |
repr_decl = stack_vars[j].decl; |
| 1533 |
break; |
| 1534 |
} |
| 1535 |
else if (repr_decl == NULL_TREE |
| 1536 |
&& DECL_P (stack_vars[j].decl) |
| 1537 |
&& DECL_NAME (stack_vars[j].decl)) |
| 1538 |
repr_decl = stack_vars[j].decl; |
| 1539 |
if (repr_decl == NULL_TREE) |
| 1540 |
repr_decl = stack_vars[i].decl; |
| 1541 |
data->asan_decl_vec.safe_push (repr_decl); |
| 1542 |
|
| 1543 |
/* Make sure a representative is unpoison if another |
| 1544 |
variable in the partition is handled by |
| 1545 |
use-after-scope sanitization. */ |
| 1546 |
if (asan_handled_variables != NULL |
| 1547 |
&& !asan_handled_variables->contains (repr_decl)) |
| 1548 |
{ |
| 1549 |
for (j = i; j != EOC; j = stack_vars[j].next) |
| 1550 |
if (asan_handled_variables->contains (stack_vars[j].decl)) |
| 1551 |
break; |
| 1552 |
if (j != EOC) |
| 1553 |
asan_handled_variables->add (repr_decl); |
| 1554 |
} |
| 1555 |
|
| 1556 |
data->asan_alignb = MAX (data->asan_alignb, alignb); |
| 1557 |
if (data->asan_base == NULL) |
| 1558 |
data->asan_base = gen_reg_rtx (Pmode); |
| 1559 |
base = data->asan_base; |
| 1560 |
|
| 1561 |
if (!STRICT_ALIGNMENT) |
| 1562 |
base_align = crtl->max_used_stack_slot_alignment; |
| 1563 |
else |
| 1564 |
base_align = MAX (crtl->max_used_stack_slot_alignment, |
| 1565 |
GET_MODE_ALIGNMENT (SImode) |
| 1566 |
<< ASAN_SHADOW_SHIFT); |
| 1567 |
} |
| 1568 |
else |
| 1569 |
{ |
| 1570 |
offset = alloc_stack_frame_space (stack_vars[i].size, alignb); |
| 1571 |
base_align = crtl->max_used_stack_slot_alignment; |
| 1572 |
|
| 1573 |
if (hwasan_sanitize_stack_p ()) |
| 1574 |
{ |
| 1575 |
/* Align again since the point of this alignment is to handle |
| 1576 |
the "end" of the object (i.e. smallest address after the |
| 1577 |
stack object). For FRAME_GROWS_DOWNWARD that requires |
| 1578 |
aligning the stack before allocating, but for a frame that |
| 1579 |
grows upwards that requires aligning the stack after |
| 1580 |
allocation. |
| 1581 |
|
| 1582 |
Use `frame_offset` to record the offset value rather than |
| 1583 |
`offset` since the `frame_offset` describes the extent |
| 1584 |
allocated for this particular variable while `offset` |
| 1585 |
describes the address that this variable starts at. */ |
| 1586 |
align_frame_offset (HWASAN_TAG_GRANULE_SIZE); |
| 1587 |
hwasan_record_stack_var (virtual_stack_vars_rtx, base, |
| 1588 |
hwasan_orig_offset, frame_offset); |
| 1589 |
} |
| 1590 |
} |
| 1591 |
} |
| 1592 |
else |
| 1593 |
{ |
| 1594 |
/* Large alignment is only processed in the last pass. */ |
| 1595 |
if (pred) |
| 1596 |
continue; |
| 1597 |
|
| 1598 |
/* If there were any variables requiring "large" alignment, allocate |
| 1599 |
space. */ |
| 1600 |
if (maybe_ne (large_size, 0U) && ! large_allocation_done) |
| 1601 |
{ |
| 1602 |
poly_int64 loffset; |
| 1603 |
rtx large_allocsize; |
| 1604 |
|
| 1605 |
large_allocsize = gen_int_mode (large_size, Pmode); |
| 1606 |
get_dynamic_stack_size (&large_allocsize, 0, large_align, NULL); |
| 1607 |
loffset = alloc_stack_frame_space |
| 1608 |
(rtx_to_poly_int64 (large_allocsize), |
| 1609 |
PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT); |
| 1610 |
large_base = get_dynamic_stack_base (loffset, large_align, base); |
| 1611 |
large_allocation_done = true; |
| 1612 |
} |
| 1613 |
|
| 1614 |
gcc_assert (large_base != NULL); |
| 1615 |
large_alloc = aligned_upper_bound (large_alloc, alignb); |
| 1616 |
offset = large_alloc; |
| 1617 |
large_alloc += stack_vars[i].size; |
| 1618 |
if (hwasan_sanitize_stack_p ()) |
| 1619 |
{ |
| 1620 |
/* An object with a large alignment requirement means that the |
| 1621 |
alignment requirement is greater than the required alignment |
| 1622 |
for tags. */ |
| 1623 |
if (!large_untagged_base) |
| 1624 |
large_untagged_base |
| 1625 |
= targetm.memtag.untagged_pointer (large_base, NULL_RTX); |
| 1626 |
/* Ensure the end of the variable is also aligned correctly. */ |
| 1627 |
poly_int64 align_again |
| 1628 |
= aligned_upper_bound (large_alloc, HWASAN_TAG_GRANULE_SIZE); |
| 1629 |
/* For large allocations we always allocate a chunk of space |
| 1630 |
(which is addressed by large_untagged_base/large_base) and |
| 1631 |
then use positive offsets from that. Hence the farthest |
| 1632 |
offset is `align_again` and the nearest offset from the base |
| 1633 |
is `offset`. */ |
| 1634 |
hwasan_record_stack_var (large_untagged_base, large_base, |
| 1635 |
offset, align_again); |
| 1636 |
} |
| 1637 |
|
| 1638 |
base = large_base; |
| 1639 |
base_align = large_align; |
| 1640 |
} |
| 1641 |
|
| 1642 |
/* Create rtl for each variable based on their location within the |
| 1643 |
partition. */ |
| 1644 |
for (j = i; j != EOC; j = stack_vars[j].next) |
| 1645 |
{ |
| 1646 |
expand_one_stack_var_at (stack_vars[j].decl, |
| 1647 |
base, base_align, offset); |
| 1648 |
} |
| 1649 |
if (hwasan_sanitize_stack_p ()) |
| 1650 |
hwasan_increment_frame_tag (); |
| 1651 |
} |
| 1652 |
|
| 1653 |
gcc_assert (known_eq (large_alloc, large_size)); |
| 1654 |
} |
| 1655 |
|
| 1656 |
/* Take into account all sizes of partitions and reset DECL_RTLs. */ |
| 1657 |
static poly_uint64 |
| 1658 |
account_stack_vars (void) |
| 1659 |
{ |
| 1660 |
unsigned si, j, i, n = stack_vars_num; |
| 1661 |
poly_uint64 size = 0; |
| 1662 |
|
| 1663 |
for (si = 0; si < n; ++si) |
| 1664 |
{ |
| 1665 |
i = stack_vars_sorted[si]; |
| 1666 |
|
| 1667 |
/* Skip variables that aren't partition representatives, for now. */ |
| 1668 |
if (stack_vars[i].representative != i) |
| 1669 |
continue; |
| 1670 |
|
| 1671 |
size += stack_vars[i].size; |
| 1672 |
for (j = i; j != EOC; j = stack_vars[j].next) |
| 1673 |
set_rtl (stack_vars[j].decl, NULL); |
| 1674 |
} |
| 1675 |
return size; |
| 1676 |
} |
| 1677 |
|
| 1678 |
/* Record the RTL assignment X for the default def of PARM. */ |
| 1679 |
|
| 1680 |
extern void |
| 1681 |
set_parm_rtl (tree parm, rtx x) |
| 1682 |
{ |
| 1683 |
gcc_assert (TREE_CODE (parm) == PARM_DECL |
| 1684 |
|| TREE_CODE (parm) == RESULT_DECL); |
| 1685 |
|
| 1686 |
if (x && !MEM_P (x)) |
| 1687 |
{ |
| 1688 |
unsigned int align = MINIMUM_ALIGNMENT (TREE_TYPE (parm), |
| 1689 |
TYPE_MODE (TREE_TYPE (parm)), |
| 1690 |
TYPE_ALIGN (TREE_TYPE (parm))); |
| 1691 |
|
| 1692 |
/* If the variable alignment is very large we'll dynamicaly |
| 1693 |
allocate it, which means that in-frame portion is just a |
| 1694 |
pointer. ??? We've got a pseudo for sure here, do we |
| 1695 |
actually dynamically allocate its spilling area if needed? |
| 1696 |
??? Isn't it a problem when Pmode alignment also exceeds |
| 1697 |
MAX_SUPPORTED_STACK_ALIGNMENT, as can happen on cris and lm32? */ |
| 1698 |
if (align > MAX_SUPPORTED_STACK_ALIGNMENT) |
| 1699 |
align = GET_MODE_ALIGNMENT (Pmode); |
| 1700 |
|
| 1701 |
record_alignment_for_reg_var (align); |
| 1702 |
} |
| 1703 |
|
| 1704 |
tree ssa = ssa_default_def (cfun, parm); |
| 1705 |
if (!ssa) |
| 1706 |
return set_rtl (parm, x); |
| 1707 |
|
| 1708 |
int part = var_to_partition (SA.map, ssa); |
| 1709 |
gcc_assert (part != NO_PARTITION); |
| 1710 |
|
| 1711 |
bool changed = bitmap_bit_p (SA.partitions_for_parm_default_defs, part); |
| 1712 |
gcc_assert (changed); |
| 1713 |
|
| 1714 |
set_rtl (ssa, x); |
| 1715 |
gcc_assert (DECL_RTL (parm) == x); |
| 1716 |
} |
| 1717 |
|
| 1718 |
/* A subroutine of expand_one_var. Called to immediately assign rtl |
| 1719 |
to a variable to be allocated in the stack frame. */ |
| 1720 |
|
| 1721 |
static void |
| 1722 |
expand_one_stack_var_1 (tree var) |
| 1723 |
{ |
| 1724 |
poly_uint64 size; |
| 1725 |
poly_int64 offset; |
| 1726 |
unsigned byte_align; |
| 1727 |
|
| 1728 |
if (TREE_CODE (var) == SSA_NAME) |
| 1729 |
{ |
| 1730 |
tree type = TREE_TYPE (var); |
| 1731 |
size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (type)); |
| 1732 |
} |
| 1733 |
else |
| 1734 |
size = tree_to_poly_uint64 (DECL_SIZE_UNIT (var)); |
| 1735 |
|
| 1736 |
byte_align = align_local_variable (var, true); |
| 1737 |
|
| 1738 |
/* We handle highly aligned variables in expand_stack_vars. */ |
| 1739 |
gcc_assert (byte_align * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT); |
| 1740 |
|
| 1741 |
rtx base; |
| 1742 |
if (hwasan_sanitize_stack_p ()) |
| 1743 |
{ |
| 1744 |
/* Allocate zero bytes to align the stack. */ |
| 1745 |
poly_int64 hwasan_orig_offset |
| 1746 |
= align_frame_offset (HWASAN_TAG_GRANULE_SIZE); |
| 1747 |
offset = alloc_stack_frame_space (size, byte_align); |
| 1748 |
align_frame_offset (HWASAN_TAG_GRANULE_SIZE); |
| 1749 |
base = hwasan_frame_base (); |
| 1750 |
/* Use `frame_offset` to automatically account for machines where the |
| 1751 |
frame grows upwards. |
| 1752 |
|
| 1753 |
`offset` will always point to the "start" of the stack object, which |
| 1754 |
will be the smallest address, for ! FRAME_GROWS_DOWNWARD this is *not* |
| 1755 |
the "furthest" offset from the base delimiting the current stack |
| 1756 |
object. `frame_offset` will always delimit the extent that the frame. |
| 1757 |
*/ |
| 1758 |
hwasan_record_stack_var (virtual_stack_vars_rtx, base, |
| 1759 |
hwasan_orig_offset, frame_offset); |
| 1760 |
} |
| 1761 |
else |
| 1762 |
{ |
| 1763 |
offset = alloc_stack_frame_space (size, byte_align); |
| 1764 |
base = virtual_stack_vars_rtx; |
| 1765 |
} |
| 1766 |
|
| 1767 |
expand_one_stack_var_at (var, base, |
| 1768 |
crtl->max_used_stack_slot_alignment, offset); |
| 1769 |
|
| 1770 |
if (hwasan_sanitize_stack_p ()) |
| 1771 |
hwasan_increment_frame_tag (); |
| 1772 |
} |
| 1773 |
|
| 1774 |
/* Wrapper for expand_one_stack_var_1 that checks SSA_NAMEs are |
| 1775 |
already assigned some MEM. */ |
| 1776 |
|
| 1777 |
static void |
| 1778 |
expand_one_stack_var (tree var) |
| 1779 |
{ |
| 1780 |
if (TREE_CODE (var) == SSA_NAME) |
| 1781 |
{ |
| 1782 |
int part = var_to_partition (SA.map, var); |
| 1783 |
if (part != NO_PARTITION) |
| 1784 |
{ |
| 1785 |
rtx x = SA.partition_to_pseudo[part]; |
| 1786 |
gcc_assert (x); |
| 1787 |
gcc_assert (MEM_P (x)); |
| 1788 |
return; |
| 1789 |
} |
| 1790 |
} |
| 1791 |
|
| 1792 |
return expand_one_stack_var_1 (var); |
| 1793 |
} |
| 1794 |
|
| 1795 |
/* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL |
| 1796 |
that will reside in a hard register. */ |
| 1797 |
|
| 1798 |
static void |
| 1799 |
expand_one_hard_reg_var (tree var) |
| 1800 |
{ |
| 1801 |
rest_of_decl_compilation (var, 0, 0); |
| 1802 |
} |
| 1803 |
|
| 1804 |
/* Record the alignment requirements of some variable assigned to a |
| 1805 |
pseudo. */ |
| 1806 |
|
| 1807 |
static void |
| 1808 |
record_alignment_for_reg_var (unsigned int align) |
| 1809 |
{ |
| 1810 |
if (SUPPORTS_STACK_ALIGNMENT |
| 1811 |
&& crtl->stack_alignment_estimated < align) |
| 1812 |
{ |
| 1813 |
/* stack_alignment_estimated shouldn't change after stack |
| 1814 |
realign decision made */ |
| 1815 |
gcc_assert (!crtl->stack_realign_processed); |
| 1816 |
crtl->stack_alignment_estimated = align; |
| 1817 |
} |
| 1818 |
|
| 1819 |
/* stack_alignment_needed > PREFERRED_STACK_BOUNDARY is permitted. |
| 1820 |
So here we only make sure stack_alignment_needed >= align. */ |
| 1821 |
if (crtl->stack_alignment_needed < align) |
| 1822 |
crtl->stack_alignment_needed = align; |
| 1823 |
if (crtl->max_used_stack_slot_alignment < align) |
| 1824 |
crtl->max_used_stack_slot_alignment = align; |
| 1825 |
} |
| 1826 |
|
| 1827 |
/* Create RTL for an SSA partition. */ |
| 1828 |
|
| 1829 |
static void |
| 1830 |
expand_one_ssa_partition (tree var) |
| 1831 |
{ |
| 1832 |
int part = var_to_partition (SA.map, var); |
| 1833 |
gcc_assert (part != NO_PARTITION); |
| 1834 |
|
| 1835 |
if (SA.partition_to_pseudo[part]) |
| 1836 |
return; |
| 1837 |
|
| 1838 |
unsigned int align = MINIMUM_ALIGNMENT (TREE_TYPE (var), |
| 1839 |
TYPE_MODE (TREE_TYPE (var)), |
| 1840 |
TYPE_ALIGN (TREE_TYPE (var))); |
| 1841 |
|
| 1842 |
/* If the variable alignment is very large we'll dynamicaly allocate |
| 1843 |
it, which means that in-frame portion is just a pointer. */ |
| 1844 |
if (align > MAX_SUPPORTED_STACK_ALIGNMENT) |
| 1845 |
align = GET_MODE_ALIGNMENT (Pmode); |
| 1846 |
|
| 1847 |
record_alignment_for_reg_var (align); |
| 1848 |
|
| 1849 |
if (!use_register_for_decl (var)) |
| 1850 |
{ |
| 1851 |
if (defer_stack_allocation (var, true)) |
| 1852 |
add_stack_var (var, true); |
| 1853 |
else |
| 1854 |
expand_one_stack_var_1 (var); |
| 1855 |
return; |
| 1856 |
} |
| 1857 |
|
| 1858 |
machine_mode reg_mode = promote_ssa_mode (var, NULL); |
| 1859 |
rtx x = gen_reg_rtx (reg_mode); |
| 1860 |
|
| 1861 |
set_rtl (var, x); |
| 1862 |
|
| 1863 |
/* For a promoted variable, X will not be used directly but wrapped in a |
| 1864 |
SUBREG with SUBREG_PROMOTED_VAR_P set, which means that the RTL land |
| 1865 |
will assume that its upper bits can be inferred from its lower bits. |
| 1866 |
Therefore, if X isn't initialized on every path from the entry, then |
| 1867 |
we must do it manually in order to fulfill the above assumption. */ |
| 1868 |
if (reg_mode != TYPE_MODE (TREE_TYPE (var)) |
| 1869 |
&& bitmap_bit_p (SA.partitions_for_undefined_values, part)) |
| 1870 |
emit_move_insn (x, CONST0_RTX (reg_mode)); |
| 1871 |
} |
| 1872 |
|
| 1873 |
/* Record the association between the RTL generated for partition PART |
| 1874 |
and the underlying variable of the SSA_NAME VAR. */ |
| 1875 |
|
| 1876 |
static void |
| 1877 |
adjust_one_expanded_partition_var (tree var) |
| 1878 |
{ |
| 1879 |
if (!var) |
| 1880 |
return; |
| 1881 |
|
| 1882 |
tree decl = SSA_NAME_VAR (var); |
| 1883 |
|
| 1884 |
int part = var_to_partition (SA.map, var); |
| 1885 |
if (part == NO_PARTITION) |
| 1886 |
return; |
| 1887 |
|
| 1888 |
rtx x = SA.partition_to_pseudo[part]; |
| 1889 |
|
| 1890 |
gcc_assert (x); |
| 1891 |
|
| 1892 |
set_rtl (var, x); |
| 1893 |
|
| 1894 |
if (!REG_P (x)) |
| 1895 |
return; |
| 1896 |
|
| 1897 |
/* Note if the object is a user variable. */ |
| 1898 |
if (decl && !DECL_ARTIFICIAL (decl)) |
| 1899 |
mark_user_reg (x); |
| 1900 |
|
| 1901 |
if (POINTER_TYPE_P (decl ? TREE_TYPE (decl) : TREE_TYPE (var))) |
| 1902 |
mark_reg_pointer (x, get_pointer_alignment (var)); |
| 1903 |
} |
| 1904 |
|
| 1905 |
/* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL |
| 1906 |
that will reside in a pseudo register. */ |
| 1907 |
|
| 1908 |
static void |
| 1909 |
expand_one_register_var (tree var) |
| 1910 |
{ |
| 1911 |
if (TREE_CODE (var) == SSA_NAME) |
| 1912 |
{ |
| 1913 |
int part = var_to_partition (SA.map, var); |
| 1914 |
if (part != NO_PARTITION) |
| 1915 |
{ |
| 1916 |
rtx x = SA.partition_to_pseudo[part]; |
| 1917 |
gcc_assert (x); |
| 1918 |
gcc_assert (REG_P (x)); |
| 1919 |
return; |
| 1920 |
} |
| 1921 |
gcc_unreachable (); |
| 1922 |
} |
| 1923 |
|
| 1924 |
tree decl = var; |
| 1925 |
tree type = TREE_TYPE (decl); |
| 1926 |
machine_mode reg_mode = promote_decl_mode (decl, NULL); |
| 1927 |
rtx x = gen_reg_rtx (reg_mode); |
| 1928 |
|
| 1929 |
set_rtl (var, x); |
| 1930 |
|
| 1931 |
/* Note if the object is a user variable. */ |
| 1932 |
if (!DECL_ARTIFICIAL (decl)) |
| 1933 |
mark_user_reg (x); |
| 1934 |
|
| 1935 |
if (POINTER_TYPE_P (type)) |
| 1936 |
mark_reg_pointer (x, get_pointer_alignment (var)); |
| 1937 |
} |
| 1938 |
|
| 1939 |
/* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that |
| 1940 |
has some associated error, e.g. its type is error-mark. We just need |
| 1941 |
to pick something that won't crash the rest of the compiler. */ |
| 1942 |
|
| 1943 |
static void |
| 1944 |
expand_one_error_var (tree var) |
| 1945 |
{ |
| 1946 |
machine_mode mode = DECL_MODE (var); |
| 1947 |
rtx x; |
| 1948 |
|
| 1949 |
if (mode == BLKmode) |
| 1950 |
x = gen_rtx_MEM (BLKmode, const0_rtx); |
| 1951 |
else if (mode == VOIDmode) |
| 1952 |
x = const0_rtx; |
| 1953 |
else |
| 1954 |
x = gen_reg_rtx (mode); |
| 1955 |
|
| 1956 |
SET_DECL_RTL (var, x); |
| 1957 |
} |
| 1958 |
|
| 1959 |
/* A subroutine of expand_one_var. VAR is a variable that will be |
| 1960 |
allocated to the local stack frame. Return true if we wish to |
| 1961 |
add VAR to STACK_VARS so that it will be coalesced with other |
| 1962 |
variables. Return false to allocate VAR immediately. |
| 1963 |
|
| 1964 |
This function is used to reduce the number of variables considered |
| 1965 |
for coalescing, which reduces the size of the quadratic problem. */ |
| 1966 |
|
| 1967 |
static bool |
| 1968 |
defer_stack_allocation (tree var, bool toplevel) |
| 1969 |
{ |
| 1970 |
tree size_unit = TREE_CODE (var) == SSA_NAME |
| 1971 |
? TYPE_SIZE_UNIT (TREE_TYPE (var)) |
| 1972 |
: DECL_SIZE_UNIT (var); |
| 1973 |
poly_uint64 size; |
| 1974 |
|
| 1975 |
/* Whether the variable is small enough for immediate allocation not to be |
| 1976 |
a problem with regard to the frame size. */ |
| 1977 |
bool smallish |
| 1978 |
= (poly_int_tree_p (size_unit, &size) |
| 1979 |
&& (estimated_poly_value (size) |
| 1980 |
< param_min_size_for_stack_sharing)); |
| 1981 |
|
| 1982 |
/* If stack protection is enabled, *all* stack variables must be deferred, |
| 1983 |
so that we can re-order the strings to the top of the frame. |
| 1984 |
Similarly for Address Sanitizer. */ |
| 1985 |
if (flag_stack_protect || asan_sanitize_stack_p ()) |
| 1986 |
return true; |
| 1987 |
|
| 1988 |
unsigned int align = TREE_CODE (var) == SSA_NAME |
| 1989 |
? TYPE_ALIGN (TREE_TYPE (var)) |
| 1990 |
: DECL_ALIGN (var); |
| 1991 |
|
| 1992 |
/* We handle "large" alignment via dynamic allocation. We want to handle |
| 1993 |
this extra complication in only one place, so defer them. */ |
| 1994 |
if (align > MAX_SUPPORTED_STACK_ALIGNMENT) |
| 1995 |
return true; |
| 1996 |
|
| 1997 |
bool ignored = TREE_CODE (var) == SSA_NAME |
| 1998 |
? !SSAVAR (var) || DECL_IGNORED_P (SSA_NAME_VAR (var)) |
| 1999 |
: DECL_IGNORED_P (var); |
| 2000 |
|
| 2001 |
/* When optimization is enabled, DECL_IGNORED_P variables originally scoped |
| 2002 |
might be detached from their block and appear at toplevel when we reach |
| 2003 |
here. We want to coalesce them with variables from other blocks when |
| 2004 |
the immediate contribution to the frame size would be noticeable. */ |
| 2005 |
if (toplevel && optimize > 0 && ignored && !smallish) |
| 2006 |
return true; |
| 2007 |
|
| 2008 |
/* Variables declared in the outermost scope automatically conflict |
| 2009 |
with every other variable. The only reason to want to defer them |
| 2010 |
at all is that, after sorting, we can more efficiently pack |
| 2011 |
small variables in the stack frame. Continue to defer at -O2. */ |
| 2012 |
if (toplevel && optimize < 2) |
| 2013 |
return false; |
| 2014 |
|
| 2015 |
/* Without optimization, *most* variables are allocated from the |
| 2016 |
stack, which makes the quadratic problem large exactly when we |
| 2017 |
want compilation to proceed as quickly as possible. On the |
| 2018 |
other hand, we don't want the function's stack frame size to |
| 2019 |
get completely out of hand. So we avoid adding scalars and |
| 2020 |
"small" aggregates to the list at all. */ |
| 2021 |
if (optimize == 0 && smallish) |
| 2022 |
return false; |
| 2023 |
|
| 2024 |
return true; |
| 2025 |
} |
| 2026 |
|
| 2027 |
/* A subroutine of expand_used_vars. Expand one variable according to |
| 2028 |
its flavor. Variables to be placed on the stack are not actually |
| 2029 |
expanded yet, merely recorded. |
| 2030 |
When REALLY_EXPAND is false, only add stack values to be allocated. |
| 2031 |
Return stack usage this variable is supposed to take. |
| 2032 |
*/ |
| 2033 |
|
| 2034 |
static poly_uint64 |
| 2035 |
expand_one_var (tree var, bool toplevel, bool really_expand, |
| 2036 |
bitmap forced_stack_var = NULL) |
| 2037 |
{ |
| 2038 |
unsigned int align = BITS_PER_UNIT; |
| 2039 |
tree origvar = var; |
| 2040 |
|
| 2041 |
var = SSAVAR (var); |
| 2042 |
|
| 2043 |
if (TREE_TYPE (var) != error_mark_node && VAR_P (var)) |
| 2044 |
{ |
| 2045 |
if (is_global_var (var)) |
| 2046 |
return 0; |
| 2047 |
|
| 2048 |
/* Because we don't know if VAR will be in register or on stack, |
| 2049 |
we conservatively assume it will be on stack even if VAR is |
| 2050 |
eventually put into register after RA pass. For non-automatic |
| 2051 |
variables, which won't be on stack, we collect alignment of |
| 2052 |
type and ignore user specified alignment. Similarly for |
| 2053 |
SSA_NAMEs for which use_register_for_decl returns true. */ |
| 2054 |
if (TREE_STATIC (var) |
| 2055 |
|| DECL_EXTERNAL (var) |
| 2056 |
|| (TREE_CODE (origvar) == SSA_NAME && use_register_for_decl (var))) |
| 2057 |
align = MINIMUM_ALIGNMENT (TREE_TYPE (var), |
| 2058 |
TYPE_MODE (TREE_TYPE (var)), |
| 2059 |
TYPE_ALIGN (TREE_TYPE (var))); |
| 2060 |
else if (DECL_HAS_VALUE_EXPR_P (var) |
| 2061 |
|| (DECL_RTL_SET_P (var) && MEM_P (DECL_RTL (var)))) |
| 2062 |
/* Don't consider debug only variables with DECL_HAS_VALUE_EXPR_P set |
| 2063 |
or variables which were assigned a stack slot already by |
| 2064 |
expand_one_stack_var_at - in the latter case DECL_ALIGN has been |
| 2065 |
changed from the offset chosen to it. */ |
| 2066 |
align = crtl->stack_alignment_estimated; |
| 2067 |
else |
| 2068 |
align = MINIMUM_ALIGNMENT (var, DECL_MODE (var), DECL_ALIGN (var)); |
| 2069 |
|
| 2070 |
/* If the variable alignment is very large we'll dynamicaly allocate |
| 2071 |
it, which means that in-frame portion is just a pointer. */ |
| 2072 |
if (align > MAX_SUPPORTED_STACK_ALIGNMENT) |
| 2073 |
align = GET_MODE_ALIGNMENT (Pmode); |
| 2074 |
} |
| 2075 |
|
| 2076 |
record_alignment_for_reg_var (align); |
| 2077 |
|
| 2078 |
poly_uint64 size; |
| 2079 |
if (TREE_CODE (origvar) == SSA_NAME) |
| 2080 |
{ |
| 2081 |
gcc_assert (!VAR_P (var) |
| 2082 |
|| (!DECL_EXTERNAL (var) |
| 2083 |
&& !DECL_HAS_VALUE_EXPR_P (var) |
| 2084 |
&& !TREE_STATIC (var) |
| 2085 |
&& TREE_TYPE (var) != error_mark_node |
| 2086 |
&& !DECL_HARD_REGISTER (var) |
| 2087 |
&& really_expand)); |
| 2088 |
} |
| 2089 |
if (!VAR_P (var) && TREE_CODE (origvar) != SSA_NAME) |
| 2090 |
; |
| 2091 |
else if (DECL_EXTERNAL (var)) |
| 2092 |
; |
| 2093 |
else if (DECL_HAS_VALUE_EXPR_P (var)) |
| 2094 |
; |
| 2095 |
else if (TREE_STATIC (var)) |
| 2096 |
; |
| 2097 |
else if (TREE_CODE (origvar) != SSA_NAME && DECL_RTL_SET_P (var)) |
| 2098 |
; |
| 2099 |
else if (TREE_TYPE (var) == error_mark_node) |
| 2100 |
{ |
| 2101 |
if (really_expand) |
| 2102 |
expand_one_error_var (var); |
| 2103 |
} |
| 2104 |
else if (VAR_P (var) && DECL_HARD_REGISTER (var)) |
| 2105 |
{ |
| 2106 |
if (really_expand) |
| 2107 |
{ |
| 2108 |
expand_one_hard_reg_var (var); |
| 2109 |
if (!DECL_HARD_REGISTER (var)) |
| 2110 |
/* Invalid register specification. */ |
| 2111 |
expand_one_error_var (var); |
| 2112 |
} |
| 2113 |
} |
| 2114 |
else if (use_register_for_decl (var) |
| 2115 |
&& (!forced_stack_var |
| 2116 |
|| !bitmap_bit_p (forced_stack_var, DECL_UID (var)))) |
| 2117 |
{ |
| 2118 |
if (really_expand) |
| 2119 |
expand_one_register_var (origvar); |
| 2120 |
} |
| 2121 |
else if (!poly_int_tree_p (DECL_SIZE_UNIT (var), &size) |
| 2122 |
|| !valid_constant_size_p (DECL_SIZE_UNIT (var))) |
| 2123 |
{ |
| 2124 |
/* Reject variables which cover more than half of the address-space. */ |
| 2125 |
if (really_expand) |
| 2126 |
{ |
| 2127 |
if (DECL_NONLOCAL_FRAME (var)) |
| 2128 |
error_at (DECL_SOURCE_LOCATION (current_function_decl), |
| 2129 |
"total size of local objects is too large"); |
| 2130 |
else |
| 2131 |
error_at (DECL_SOURCE_LOCATION (var), |
| 2132 |
"size of variable %q+D is too large", var); |
| 2133 |
expand_one_error_var (var); |
| 2134 |
} |
| 2135 |
} |
| 2136 |
else if (defer_stack_allocation (var, toplevel)) |
| 2137 |
add_stack_var (origvar, really_expand); |
| 2138 |
else |
| 2139 |
{ |
| 2140 |
if (really_expand) |
| 2141 |
{ |
| 2142 |
if (lookup_attribute ("naked", |
| 2143 |
DECL_ATTRIBUTES (current_function_decl))) |
| 2144 |
error ("cannot allocate stack for variable %q+D, naked function", |
| 2145 |
var); |
| 2146 |
|
| 2147 |
expand_one_stack_var (origvar); |
| 2148 |
} |
| 2149 |
return size; |
| 2150 |
} |
| 2151 |
return 0; |
| 2152 |
} |
| 2153 |
|
| 2154 |
/* A subroutine of expand_used_vars. Walk down through the BLOCK tree |
| 2155 |
expanding variables. Those variables that can be put into registers |
| 2156 |
are allocated pseudos; those that can't are put on the stack. |
| 2157 |
|
| 2158 |
TOPLEVEL is true if this is the outermost BLOCK. */ |
| 2159 |
|
| 2160 |
static void |
| 2161 |
expand_used_vars_for_block (tree block, bool toplevel, bitmap forced_stack_vars) |
| 2162 |
{ |
| 2163 |
tree t; |
| 2164 |
|
| 2165 |
/* Expand all variables at this level. */ |
| 2166 |
for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t)) |
| 2167 |
if (TREE_USED (t) |
| 2168 |
&& ((!VAR_P (t) && TREE_CODE (t) != RESULT_DECL) |
| 2169 |
|| !DECL_NONSHAREABLE (t))) |
| 2170 |
expand_one_var (t, toplevel, true, forced_stack_vars); |
| 2171 |
|
| 2172 |
/* Expand all variables at containing levels. */ |
| 2173 |
for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t)) |
| 2174 |
expand_used_vars_for_block (t, false, forced_stack_vars); |
| 2175 |
} |
| 2176 |
|
| 2177 |
/* A subroutine of expand_used_vars. Walk down through the BLOCK tree |
| 2178 |
and clear TREE_USED on all local variables. */ |
| 2179 |
|
| 2180 |
static void |
| 2181 |
clear_tree_used (tree block) |
| 2182 |
{ |
| 2183 |
tree t; |
| 2184 |
|
| 2185 |
for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t)) |
| 2186 |
/* if (!TREE_STATIC (t) && !DECL_EXTERNAL (t)) */ |
| 2187 |
if ((!VAR_P (t) && TREE_CODE (t) != RESULT_DECL) |
| 2188 |
|| !DECL_NONSHAREABLE (t)) |
| 2189 |
TREE_USED (t) = 0; |
| 2190 |
|
| 2191 |
for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t)) |
| 2192 |
clear_tree_used (t); |
| 2193 |
} |
| 2194 |
|
| 2195 |
/* Examine TYPE and determine a bit mask of the following features. */ |
| 2196 |
|
| 2197 |
#define SPCT_HAS_LARGE_CHAR_ARRAY 1 |
| 2198 |
#define SPCT_HAS_SMALL_CHAR_ARRAY 2 |
| 2199 |
#define SPCT_HAS_ARRAY 4 |
| 2200 |
#define SPCT_HAS_AGGREGATE 8 |
| 2201 |
|
| 2202 |
static unsigned int |
| 2203 |
stack_protect_classify_type (tree type) |
| 2204 |
{ |
| 2205 |
unsigned int ret = 0; |
| 2206 |
tree t; |
| 2207 |
|
| 2208 |
switch (TREE_CODE (type)) |
| 2209 |
{ |
| 2210 |
case ARRAY_TYPE: |
| 2211 |
t = TYPE_MAIN_VARIANT (TREE_TYPE (type)); |
| 2212 |
if (t == char_type_node |
| 2213 |
|| t == signed_char_type_node |
| 2214 |
|| t == unsigned_char_type_node) |
| 2215 |
{ |
| 2216 |
unsigned HOST_WIDE_INT max = param_ssp_buffer_size; |
| 2217 |
unsigned HOST_WIDE_INT len; |
| 2218 |
|
| 2219 |
if (!TYPE_SIZE_UNIT (type) |
| 2220 |
|| !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))) |
| 2221 |
len = max; |
| 2222 |
else |
| 2223 |
len = tree_to_uhwi (TYPE_SIZE_UNIT (type)); |
| 2224 |
|
| 2225 |
if (len < max) |
| 2226 |
ret = SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_ARRAY; |
| 2227 |
else |
| 2228 |
ret = SPCT_HAS_LARGE_CHAR_ARRAY | SPCT_HAS_ARRAY; |
| 2229 |
} |
| 2230 |
else |
| 2231 |
ret = SPCT_HAS_ARRAY; |
| 2232 |
break; |
| 2233 |
|
| 2234 |
case UNION_TYPE: |
| 2235 |
case QUAL_UNION_TYPE: |
| 2236 |
case RECORD_TYPE: |
| 2237 |
ret = SPCT_HAS_AGGREGATE; |
| 2238 |
for (t = TYPE_FIELDS (type); t ; t = TREE_CHAIN (t)) |
| 2239 |
if (TREE_CODE (t) == FIELD_DECL) |
| 2240 |
ret |= stack_protect_classify_type (TREE_TYPE (t)); |
| 2241 |
break; |
| 2242 |
|
| 2243 |
default: |
| 2244 |
break; |
| 2245 |
} |
| 2246 |
|
| 2247 |
return ret; |
| 2248 |
} |
| 2249 |
|
| 2250 |
/* Return nonzero if DECL should be segregated into the "vulnerable" upper |
| 2251 |
part of the local stack frame. Remember if we ever return nonzero for |
| 2252 |
any variable in this function. The return value is the phase number in |
| 2253 |
which the variable should be allocated. */ |
| 2254 |
|
| 2255 |
static int |
| 2256 |
stack_protect_decl_phase (tree decl) |
| 2257 |
{ |
| 2258 |
unsigned int bits = stack_protect_classify_type (TREE_TYPE (decl)); |
| 2259 |
int ret = 0; |
| 2260 |
|
| 2261 |
if (bits & SPCT_HAS_SMALL_CHAR_ARRAY) |
| 2262 |
has_short_buffer = true; |
| 2263 |
|
| 2264 |
tree attribs = DECL_ATTRIBUTES (current_function_decl); |
| 2265 |
if (!lookup_attribute ("no_stack_protector", attribs) |
| 2266 |
&& (flag_stack_protect == SPCT_FLAG_ALL |
| 2267 |
|| flag_stack_protect == SPCT_FLAG_STRONG |
| 2268 |
|| (flag_stack_protect == SPCT_FLAG_EXPLICIT |
| 2269 |
&& lookup_attribute ("stack_protect", attribs)))) |
| 2270 |
{ |
| 2271 |
if ((bits & (SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_LARGE_CHAR_ARRAY)) |
| 2272 |
&& !(bits & SPCT_HAS_AGGREGATE)) |
| 2273 |
ret = 1; |
| 2274 |
else if (bits & SPCT_HAS_ARRAY) |
| 2275 |
ret = 2; |
| 2276 |
} |
| 2277 |
else |
| 2278 |
ret = (bits & SPCT_HAS_LARGE_CHAR_ARRAY) != 0; |
| 2279 |
|
| 2280 |
if (ret) |
| 2281 |
has_protected_decls = true; |
| 2282 |
|
| 2283 |
return ret; |
| 2284 |
} |
| 2285 |
|
| 2286 |
/* Two helper routines that check for phase 1 and phase 2. These are used |
| 2287 |
as callbacks for expand_stack_vars. */ |
| 2288 |
|
| 2289 |
static bool |
| 2290 |
stack_protect_decl_phase_1 (unsigned i) |
| 2291 |
{ |
| 2292 |
return stack_protect_decl_phase (stack_vars[i].decl) == 1; |
| 2293 |
} |
| 2294 |
|
| 2295 |
static bool |
| 2296 |
stack_protect_decl_phase_2 (unsigned i) |
| 2297 |
{ |
| 2298 |
return stack_protect_decl_phase (stack_vars[i].decl) == 2; |
| 2299 |
} |
| 2300 |
|
| 2301 |
/* And helper function that checks for asan phase (with stack protector |
| 2302 |
it is phase 3). This is used as callback for expand_stack_vars. |
| 2303 |
Returns true if any of the vars in the partition need to be protected. */ |
| 2304 |
|
| 2305 |
static bool |
| 2306 |
asan_decl_phase_3 (unsigned i) |
| 2307 |
{ |
| 2308 |
while (i != EOC) |
| 2309 |
{ |
| 2310 |
if (asan_protect_stack_decl (stack_vars[i].decl)) |
| 2311 |
return true; |
| 2312 |
i = stack_vars[i].next; |
| 2313 |
} |
| 2314 |
return false; |
| 2315 |
} |
| 2316 |
|
| 2317 |
/* Ensure that variables in different stack protection phases conflict |
| 2318 |
so that they are not merged and share the same stack slot. |
| 2319 |
Return true if there are any address taken variables. */ |
| 2320 |
|
| 2321 |
static bool |
| 2322 |
add_stack_protection_conflicts (void) |
| 2323 |
{ |
| 2324 |
unsigned i, j, n = stack_vars_num; |
| 2325 |
unsigned char *phase; |
| 2326 |
bool ret = false; |
| 2327 |
|
| 2328 |
phase = XNEWVEC (unsigned char, n); |
| 2329 |
for (i = 0; i < n; ++i) |
| 2330 |
{ |
| 2331 |
phase[i] = stack_protect_decl_phase (stack_vars[i].decl); |
| 2332 |
if (TREE_ADDRESSABLE (stack_vars[i].decl)) |
| 2333 |
ret = true; |
| 2334 |
} |
| 2335 |
|
| 2336 |
for (i = 0; i < n; ++i) |
| 2337 |
{ |
| 2338 |
unsigned char ph_i = phase[i]; |
| 2339 |
for (j = i + 1; j < n; ++j) |
| 2340 |
if (ph_i != phase[j]) |
| 2341 |
add_stack_var_conflict (i, j); |
| 2342 |
} |
| 2343 |
|
| 2344 |
XDELETEVEC (phase); |
| 2345 |
return ret; |
| 2346 |
} |
| 2347 |
|
| 2348 |
/* Create a decl for the guard at the top of the stack frame. */ |
| 2349 |
|
| 2350 |
static void |
| 2351 |
create_stack_guard (void) |
| 2352 |
{ |
| 2353 |
tree guard = build_decl (DECL_SOURCE_LOCATION (current_function_decl), |
| 2354 |
VAR_DECL, NULL, ptr_type_node); |
| 2355 |
TREE_THIS_VOLATILE (guard) = 1; |
| 2356 |
TREE_USED (guard) = 1; |
| 2357 |
expand_one_stack_var (guard); |
| 2358 |
crtl->stack_protect_guard = guard; |
| 2359 |
} |
| 2360 |
|
| 2361 |
/* Prepare for expanding variables. */ |
| 2362 |
static void |
| 2363 |
init_vars_expansion (void) |
| 2364 |
{ |
| 2365 |
/* Conflict bitmaps, and a few related temporary bitmaps, go here. */ |
| 2366 |
bitmap_obstack_initialize (&stack_var_bitmap_obstack); |
| 2367 |
|
| 2368 |
/* A map from decl to stack partition. */ |
| 2369 |
decl_to_stack_part = new hash_map<tree, unsigned>; |
| 2370 |
|
| 2371 |
/* Initialize local stack smashing state. */ |
| 2372 |
has_protected_decls = false; |
| 2373 |
has_short_buffer = false; |
| 2374 |
if (hwasan_sanitize_stack_p ()) |
| 2375 |
hwasan_record_frame_init (); |
| 2376 |
} |
| 2377 |
|
| 2378 |
/* Free up stack variable graph data. */ |
| 2379 |
static void |
| 2380 |
fini_vars_expansion (void) |
| 2381 |
{ |
| 2382 |
bitmap_obstack_release (&stack_var_bitmap_obstack); |
| 2383 |
if (stack_vars) |
| 2384 |
XDELETEVEC (stack_vars); |
| 2385 |
if (stack_vars_sorted) |
| 2386 |
XDELETEVEC (stack_vars_sorted); |
| 2387 |
stack_vars = NULL; |
| 2388 |
stack_vars_sorted = NULL; |
| 2389 |
stack_vars_alloc = stack_vars_num = 0; |
| 2390 |
delete decl_to_stack_part; |
| 2391 |
decl_to_stack_part = NULL; |
| 2392 |
} |
| 2393 |
|
| 2394 |
/* Make a fair guess for the size of the stack frame of the function |
| 2395 |
in NODE. This doesn't have to be exact, the result is only used in |
| 2396 |
the inline heuristics. So we don't want to run the full stack var |
| 2397 |
packing algorithm (which is quadratic in the number of stack vars). |
| 2398 |
Instead, we calculate the total size of all stack vars. This turns |
| 2399 |
out to be a pretty fair estimate -- packing of stack vars doesn't |
| 2400 |
happen very often. */ |
| 2401 |
|
| 2402 |
HOST_WIDE_INT |
| 2403 |
estimated_stack_frame_size (struct cgraph_node *node) |
| 2404 |
{ |
| 2405 |
poly_int64 size = 0; |
| 2406 |
unsigned i; |
| 2407 |
tree var; |
| 2408 |
struct function *fn = DECL_STRUCT_FUNCTION (node->decl); |
| 2409 |
|
| 2410 |
push_cfun (fn); |
| 2411 |
|
| 2412 |
init_vars_expansion (); |
| 2413 |
|
| 2414 |
FOR_EACH_LOCAL_DECL (fn, i, var) |
| 2415 |
if (auto_var_in_fn_p (var, fn->decl)) |
| 2416 |
size += expand_one_var (var, true, false); |
| 2417 |
|
| 2418 |
if (stack_vars_num > 0) |
| 2419 |
{ |
| 2420 |
/* Fake sorting the stack vars for account_stack_vars (). */ |
| 2421 |
stack_vars_sorted = XNEWVEC (unsigned , stack_vars_num); |
| 2422 |
for (i = 0; i < stack_vars_num; ++i) |
| 2423 |
stack_vars_sorted[i] = i; |
| 2424 |
size += account_stack_vars (); |
| 2425 |
} |
| 2426 |
|
| 2427 |
fini_vars_expansion (); |
| 2428 |
pop_cfun (); |
| 2429 |
return estimated_poly_value (size); |
| 2430 |
} |
| 2431 |
|
| 2432 |
/* Check if the current function has calls that use a return slot. */ |
| 2433 |
|
| 2434 |
static bool |
| 2435 |
stack_protect_return_slot_p () |
| 2436 |
{ |
| 2437 |
basic_block bb; |
| 2438 |
|
| 2439 |
FOR_ALL_BB_FN (bb, cfun) |
| 2440 |
for (gimple_stmt_iterator gsi = gsi_start_bb (bb); |
| 2441 |
!gsi_end_p (gsi); gsi_next (&gsi)) |
| 2442 |
{ |
| 2443 |
gimple *stmt = gsi_stmt (gsi); |
| 2444 |
/* This assumes that calls to internal-only functions never |
| 2445 |
use a return slot. */ |
| 2446 |
if (is_gimple_call (stmt) |
| 2447 |
&& !gimple_call_internal_p (stmt) |
| 2448 |
&& aggregate_value_p (TREE_TYPE (gimple_call_fntype (stmt)), |
| 2449 |
gimple_call_fndecl (stmt))) |
| 2450 |
return true; |
| 2451 |
} |
| 2452 |
return false; |
| 2453 |
} |
| 2454 |
|
| 2455 |
/* Expand all variables used in the function. */ |
| 2456 |
|
| 2457 |
static rtx_insn * |
| 2458 |
expand_used_vars (bitmap forced_stack_vars) |
| 2459 |
{ |
| 2460 |
tree var, outer_block = DECL_INITIAL (current_function_decl); |
| 2461 |
auto_vec<tree> maybe_local_decls; |
| 2462 |
rtx_insn *var_end_seq = NULL; |
| 2463 |
unsigned i; |
| 2464 |
unsigned len; |
| 2465 |
bool gen_stack_protect_signal = false; |
| 2466 |
|
| 2467 |
/* Compute the phase of the stack frame for this function. */ |
| 2468 |
{ |
| 2469 |
int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; |
| 2470 |
int off = targetm.starting_frame_offset () % align; |
| 2471 |
frame_phase = off ? align - off : 0; |
| 2472 |
} |
| 2473 |
|
| 2474 |
/* Set TREE_USED on all variables in the local_decls. */ |
| 2475 |
FOR_EACH_LOCAL_DECL (cfun, i, var) |
| 2476 |
TREE_USED (var) = 1; |
| 2477 |
/* Clear TREE_USED on all variables associated with a block scope. */ |
| 2478 |
clear_tree_used (DECL_INITIAL (current_function_decl)); |
| 2479 |
|
| 2480 |
init_vars_expansion (); |
| 2481 |
|
| 2482 |
if (targetm.use_pseudo_pic_reg ()) |
| 2483 |
pic_offset_table_rtx = gen_reg_rtx (Pmode); |
| 2484 |
|
| 2485 |
for (i = 0; i < SA.map->num_partitions; i++) |
| 2486 |
{ |
| 2487 |
if (bitmap_bit_p (SA.partitions_for_parm_default_defs, i)) |
| 2488 |
continue; |
| 2489 |
|
| 2490 |
tree var = partition_to_var (SA.map, i); |
| 2491 |
|
| 2492 |
gcc_assert (!virtual_operand_p (var)); |
| 2493 |
|
| 2494 |
expand_one_ssa_partition (var); |
| 2495 |
} |
| 2496 |
|
| 2497 |
if (flag_stack_protect == SPCT_FLAG_STRONG) |
| 2498 |
gen_stack_protect_signal = stack_protect_return_slot_p (); |
| 2499 |
|
| 2500 |
/* At this point all variables on the local_decls with TREE_USED |
| 2501 |
set are not associated with any block scope. Lay them out. */ |
| 2502 |
|
| 2503 |
len = vec_safe_length (cfun->local_decls); |
| 2504 |
FOR_EACH_LOCAL_DECL (cfun, i, var) |
| 2505 |
{ |
| 2506 |
bool expand_now = false; |
| 2507 |
|
| 2508 |
/* Expanded above already. */ |
| 2509 |
if (is_gimple_reg (var)) |
| 2510 |
{ |
| 2511 |
TREE_USED (var) = 0; |
| 2512 |
goto next; |
| 2513 |
} |
| 2514 |
/* We didn't set a block for static or extern because it's hard |
| 2515 |
to tell the difference between a global variable (re)declared |
| 2516 |
in a local scope, and one that's really declared there to |
| 2517 |
begin with. And it doesn't really matter much, since we're |
| 2518 |
not giving them stack space. Expand them now. */ |
| 2519 |
else if (TREE_STATIC (var) || DECL_EXTERNAL (var)) |
| 2520 |
expand_now = true; |
| 2521 |
|
| 2522 |
/* Expand variables not associated with any block now. Those created by |
| 2523 |
the optimizers could be live anywhere in the function. Those that |
| 2524 |
could possibly have been scoped originally and detached from their |
| 2525 |
block will have their allocation deferred so we coalesce them with |
| 2526 |
others when optimization is enabled. */ |
| 2527 |
else if (TREE_USED (var)) |
| 2528 |
expand_now = true; |
| 2529 |
|
| 2530 |
/* Finally, mark all variables on the list as used. We'll use |
| 2531 |
this in a moment when we expand those associated with scopes. */ |
| 2532 |
TREE_USED (var) = 1; |
| 2533 |
|
| 2534 |
if (expand_now) |
| 2535 |
expand_one_var (var, true, true, forced_stack_vars); |
| 2536 |
|
| 2537 |
next: |
| 2538 |
if (DECL_ARTIFICIAL (var) && !DECL_IGNORED_P (var)) |
| 2539 |
{ |
| 2540 |
rtx rtl = DECL_RTL_IF_SET (var); |
| 2541 |
|
| 2542 |
/* Keep artificial non-ignored vars in cfun->local_decls |
| 2543 |
chain until instantiate_decls. */ |
| 2544 |
if (rtl && (MEM_P (rtl) || GET_CODE (rtl) == CONCAT)) |
| 2545 |
add_local_decl (cfun, var); |
| 2546 |
else if (rtl == NULL_RTX) |
| 2547 |
/* If rtl isn't set yet, which can happen e.g. with |
| 2548 |
-fstack-protector, retry before returning from this |
| 2549 |
function. */ |
| 2550 |
maybe_local_decls.safe_push (var); |
| 2551 |
} |
| 2552 |
} |
| 2553 |
|
| 2554 |
/* We duplicated some of the decls in CFUN->LOCAL_DECLS. |
| 2555 |
|
| 2556 |
+-----------------+-----------------+ |
| 2557 |
| ...processed... | ...duplicates...| |
| 2558 |
+-----------------+-----------------+ |
| 2559 |
^ |
| 2560 |
+-- LEN points here. |
| 2561 |
|
| 2562 |
We just want the duplicates, as those are the artificial |
| 2563 |
non-ignored vars that we want to keep until instantiate_decls. |
| 2564 |
Move them down and truncate the array. */ |
| 2565 |
if (!vec_safe_is_empty (cfun->local_decls)) |
| 2566 |
cfun->local_decls->block_remove (0, len); |
| 2567 |
|
| 2568 |
/* At this point, all variables within the block tree with TREE_USED |
| 2569 |
set are actually used by the optimized function. Lay them out. */ |
| 2570 |
expand_used_vars_for_block (outer_block, true, forced_stack_vars); |
| 2571 |
|
| 2572 |
tree attribs = DECL_ATTRIBUTES (current_function_decl); |
| 2573 |
if (stack_vars_num > 0) |
| 2574 |
{ |
| 2575 |
bool has_addressable_vars = false; |
| 2576 |
|
| 2577 |
add_scope_conflicts (); |
| 2578 |
|
| 2579 |
/* If stack protection is enabled, we don't share space between |
| 2580 |
vulnerable data and non-vulnerable data. */ |
| 2581 |
if (flag_stack_protect != 0 |
| 2582 |
&& !lookup_attribute ("no_stack_protector", attribs) |
| 2583 |
&& (flag_stack_protect != SPCT_FLAG_EXPLICIT |
| 2584 |
|| (flag_stack_protect == SPCT_FLAG_EXPLICIT |
| 2585 |
&& lookup_attribute ("stack_protect", attribs)))) |
| 2586 |
has_addressable_vars = add_stack_protection_conflicts (); |
| 2587 |
|
| 2588 |
if (flag_stack_protect == SPCT_FLAG_STRONG && has_addressable_vars) |
| 2589 |
gen_stack_protect_signal = true; |
| 2590 |
|
| 2591 |
/* Now that we have collected all stack variables, and have computed a |
| 2592 |
minimal interference graph, attempt to save some stack space. */ |
| 2593 |
partition_stack_vars (); |
| 2594 |
if (dump_file) |
| 2595 |
dump_stack_var_partition (); |
| 2596 |
} |
| 2597 |
|
| 2598 |
|
| 2599 |
if (!lookup_attribute ("no_stack_protector", attribs)) |
| 2600 |
switch (flag_stack_protect) |
| 2601 |
{ |
| 2602 |
case SPCT_FLAG_ALL: |
| 2603 |
create_stack_guard (); |
| 2604 |
break; |
| 2605 |
|
| 2606 |
case SPCT_FLAG_STRONG: |
| 2607 |
if (gen_stack_protect_signal |
| 2608 |
|| cfun->calls_alloca |
| 2609 |
|| has_protected_decls |
| 2610 |
|| lookup_attribute ("stack_protect", attribs)) |
| 2611 |
create_stack_guard (); |
| 2612 |
break; |
| 2613 |
|
| 2614 |
case SPCT_FLAG_DEFAULT: |
| 2615 |
if (cfun->calls_alloca |
| 2616 |
|| has_protected_decls |
| 2617 |
|| lookup_attribute ("stack_protect", attribs)) |
| 2618 |
create_stack_guard (); |
| 2619 |
break; |
| 2620 |
|
| 2621 |
case SPCT_FLAG_EXPLICIT: |
| 2622 |
if (lookup_attribute ("stack_protect", attribs)) |
| 2623 |
create_stack_guard (); |
| 2624 |
break; |
| 2625 |
|
| 2626 |
default: |
| 2627 |
break; |
| 2628 |
} |
| 2629 |
|
| 2630 |
/* Assign rtl to each variable based on these partitions. */ |
| 2631 |
if (stack_vars_num > 0) |
| 2632 |
{ |
| 2633 |
class stack_vars_data data; |
| 2634 |
|
| 2635 |
data.asan_base = NULL_RTX; |
| 2636 |
data.asan_alignb = 0; |
| 2637 |
|
| 2638 |
/* Reorder decls to be protected by iterating over the variables |
| 2639 |
array multiple times, and allocating out of each phase in turn. */ |
| 2640 |
/* ??? We could probably integrate this into the qsort we did |
| 2641 |
earlier, such that we naturally see these variables first, |
| 2642 |
and thus naturally allocate things in the right order. */ |
| 2643 |
if (has_protected_decls) |
| 2644 |
{ |
| 2645 |
/* Phase 1 contains only character arrays. */ |
| 2646 |
expand_stack_vars (stack_protect_decl_phase_1, &data); |
| 2647 |
|
| 2648 |
/* Phase 2 contains other kinds of arrays. */ |
| 2649 |
if (!lookup_attribute ("no_stack_protector", attribs) |
| 2650 |
&& (flag_stack_protect == SPCT_FLAG_ALL |
| 2651 |
|| flag_stack_protect == SPCT_FLAG_STRONG |
| 2652 |
|| (flag_stack_protect == SPCT_FLAG_EXPLICIT |
| 2653 |
&& lookup_attribute ("stack_protect", attribs)))) |
| 2654 |
expand_stack_vars (stack_protect_decl_phase_2, &data); |
| 2655 |
} |
| 2656 |
|
| 2657 |
if (asan_sanitize_stack_p ()) |
| 2658 |
/* Phase 3, any partitions that need asan protection |
| 2659 |
in addition to phase 1 and 2. */ |
| 2660 |
expand_stack_vars (asan_decl_phase_3, &data); |
| 2661 |
|
| 2662 |
/* ASAN description strings don't yet have a syntax for expressing |
| 2663 |
polynomial offsets. */ |
| 2664 |
HOST_WIDE_INT prev_offset; |
| 2665 |
if (!data.asan_vec.is_empty () |
| 2666 |
&& frame_offset.is_constant (&prev_offset)) |
| 2667 |
{ |
| 2668 |
HOST_WIDE_INT offset, sz, redzonesz; |
| 2669 |
redzonesz = ASAN_RED_ZONE_SIZE; |
| 2670 |
sz = data.asan_vec[0] - prev_offset; |
| 2671 |
if (data.asan_alignb > ASAN_RED_ZONE_SIZE |
| 2672 |
&& data.asan_alignb <= 4096 |
| 2673 |
&& sz + ASAN_RED_ZONE_SIZE >= (int) data.asan_alignb) |
| 2674 |
redzonesz = ((sz + ASAN_RED_ZONE_SIZE + data.asan_alignb - 1) |
| 2675 |
& ~(data.asan_alignb - HOST_WIDE_INT_1)) - sz; |
| 2676 |
/* Allocating a constant amount of space from a constant |
| 2677 |
starting offset must give a constant result. */ |
| 2678 |
offset = (alloc_stack_frame_space (redzonesz, ASAN_RED_ZONE_SIZE) |
| 2679 |
.to_constant ()); |
| 2680 |
data.asan_vec.safe_push (prev_offset); |
| 2681 |
data.asan_vec.safe_push (offset); |
| 2682 |
/* Leave space for alignment if STRICT_ALIGNMENT. */ |
| 2683 |
if (STRICT_ALIGNMENT) |
| 2684 |
alloc_stack_frame_space ((GET_MODE_ALIGNMENT (SImode) |
| 2685 |
<< ASAN_SHADOW_SHIFT) |
| 2686 |
/ BITS_PER_UNIT, 1); |
| 2687 |
|
| 2688 |
var_end_seq |
| 2689 |
= asan_emit_stack_protection (virtual_stack_vars_rtx, |
| 2690 |
data.asan_base, |
| 2691 |
data.asan_alignb, |
| 2692 |
data.asan_vec.address (), |
| 2693 |
data.asan_decl_vec.address (), |
| 2694 |
data.asan_vec.length ()); |
| 2695 |
} |
| 2696 |
|
| 2697 |
expand_stack_vars (NULL, &data); |
| 2698 |
} |
| 2699 |
|
| 2700 |
if (hwasan_sanitize_stack_p ()) |
| 2701 |
hwasan_emit_prologue (); |
| 2702 |
if (asan_sanitize_allocas_p () && cfun->calls_alloca) |
| 2703 |
var_end_seq = asan_emit_allocas_unpoison (virtual_stack_dynamic_rtx, |
| 2704 |
virtual_stack_vars_rtx, |
| 2705 |
var_end_seq); |
| 2706 |
else if (hwasan_sanitize_allocas_p () && cfun->calls_alloca) |
| 2707 |
/* When using out-of-line instrumentation we only want to emit one function |
| 2708 |
call for clearing the tags in a region of shadow stack. When there are |
| 2709 |
alloca calls in this frame we want to emit a call using the |
| 2710 |
virtual_stack_dynamic_rtx, but when not we use the hwasan_frame_extent |
| 2711 |
rtx we created in expand_stack_vars. */ |
| 2712 |
var_end_seq = hwasan_emit_untag_frame (virtual_stack_dynamic_rtx, |
| 2713 |
virtual_stack_vars_rtx); |
| 2714 |
else if (hwasan_sanitize_stack_p ()) |
| 2715 |
/* If no variables were stored on the stack, `hwasan_get_frame_extent` |
| 2716 |
will return NULL_RTX and hence `hwasan_emit_untag_frame` will return |
| 2717 |
NULL (i.e. an empty sequence). */ |
| 2718 |
var_end_seq = hwasan_emit_untag_frame (hwasan_get_frame_extent (), |
| 2719 |
virtual_stack_vars_rtx); |
| 2720 |
|
| 2721 |
fini_vars_expansion (); |
| 2722 |
|
| 2723 |
/* If there were any artificial non-ignored vars without rtl |
| 2724 |
found earlier, see if deferred stack allocation hasn't assigned |
| 2725 |
rtl to them. */ |
| 2726 |
FOR_EACH_VEC_ELT_REVERSE (maybe_local_decls, i, var) |
| 2727 |
{ |
| 2728 |
rtx rtl = DECL_RTL_IF_SET (var); |
| 2729 |
|
| 2730 |
/* Keep artificial non-ignored vars in cfun->local_decls |
| 2731 |
chain until instantiate_decls. */ |
| 2732 |
if (rtl && (MEM_P (rtl) || GET_CODE (rtl) == CONCAT)) |
| 2733 |
add_local_decl (cfun, var); |
| 2734 |
} |
| 2735 |
|
| 2736 |
/* If the target requires that FRAME_OFFSET be aligned, do it. */ |
| 2737 |
if (STACK_ALIGNMENT_NEEDED) |
| 2738 |
{ |
| 2739 |
HOST_WIDE_INT align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; |
| 2740 |
if (FRAME_GROWS_DOWNWARD) |
| 2741 |
frame_offset = aligned_lower_bound (frame_offset, align); |
| 2742 |
else |
| 2743 |
frame_offset = aligned_upper_bound (frame_offset, align); |
| 2744 |
} |
| 2745 |
|
| 2746 |
return var_end_seq; |
| 2747 |
} |
| 2748 |
|
| 2749 |
|
| 2750 |
/* If we need to produce a detailed dump, print the tree representation |
| 2751 |
for STMT to the dump file. SINCE is the last RTX after which the RTL |
| 2752 |
generated for STMT should have been appended. */ |
| 2753 |
|
| 2754 |
static void |
| 2755 |
maybe_dump_rtl_for_gimple_stmt (gimple *stmt, rtx_insn *since) |
| 2756 |
{ |
| 2757 |
if (dump_file && (dump_flags & TDF_DETAILS)) |
| 2758 |
{ |
| 2759 |
fprintf (dump_file, "\n;; "); |
| 2760 |
print_gimple_stmt (dump_file, stmt, 0, |
| 2761 |
TDF_SLIM | (dump_flags & TDF_LINENO)); |
| 2762 |
fprintf (dump_file, "\n"); |
| 2763 |
|
| 2764 |
print_rtl (dump_file, since ? NEXT_INSN (since) : since); |
| 2765 |
} |
| 2766 |
} |
| 2767 |
|
| 2768 |
/* Maps the blocks that do not contain tree labels to rtx labels. */ |
| 2769 |
|
| 2770 |
static hash_map<basic_block, rtx_code_label *> *lab_rtx_for_bb; |
| 2771 |
|
| 2772 |
/* Returns the label_rtx expression for a label starting basic block BB. */ |
| 2773 |
|
| 2774 |
static rtx_code_label * |
| 2775 |
label_rtx_for_bb (basic_block bb ATTRIBUTE_UNUSED) |
| 2776 |
{ |
| 2777 |
if (bb->flags & BB_RTL) |
| 2778 |
return block_label (bb); |
| 2779 |
|
| 2780 |
rtx_code_label **elt = lab_rtx_for_bb->get (bb); |
| 2781 |
if (elt) |
| 2782 |
return *elt; |
| 2783 |
|
| 2784 |
/* Find the tree label if it is present. */ |
| 2785 |
gimple_stmt_iterator gsi = gsi_start_bb (bb); |
| 2786 |
glabel *lab_stmt; |
| 2787 |
if (!gsi_end_p (gsi) |
| 2788 |
&& (lab_stmt = dyn_cast <glabel *> (gsi_stmt (gsi))) |
| 2789 |
&& !DECL_NONLOCAL (gimple_label_label (lab_stmt))) |
| 2790 |
return jump_target_rtx (gimple_label_label (lab_stmt)); |
| 2791 |
|
| 2792 |
rtx_code_label *l = gen_label_rtx (); |
| 2793 |
lab_rtx_for_bb->put (bb, l); |
| 2794 |
return l; |
| 2795 |
} |
| 2796 |
|
| 2797 |
|
| 2798 |
/* A subroutine of expand_gimple_cond. Given E, a fallthrough edge |
| 2799 |
of a basic block where we just expanded the conditional at the end, |
| 2800 |
possibly clean up the CFG and instruction sequence. LAST is the |
| 2801 |
last instruction before the just emitted jump sequence. */ |
| 2802 |
|
| 2803 |
static void |
| 2804 |
maybe_cleanup_end_of_block (edge e, rtx_insn *last) |
| 2805 |
{ |
| 2806 |
/* Special case: when jumpif decides that the condition is |
| 2807 |
trivial it emits an unconditional jump (and the necessary |
| 2808 |
barrier). But we still have two edges, the fallthru one is |
| 2809 |
wrong. purge_dead_edges would clean this up later. Unfortunately |
| 2810 |
we have to insert insns (and split edges) before |
| 2811 |
find_many_sub_basic_blocks and hence before purge_dead_edges. |
| 2812 |
But splitting edges might create new blocks which depend on the |
| 2813 |
fact that if there are two edges there's no barrier. So the |
| 2814 |
barrier would get lost and verify_flow_info would ICE. Instead |
| 2815 |
of auditing all edge splitters to care for the barrier (which |
| 2816 |
normally isn't there in a cleaned CFG), fix it here. */ |
| 2817 |
if (BARRIER_P (get_last_insn ())) |
| 2818 |
{ |
| 2819 |
rtx_insn *insn; |
| 2820 |
remove_edge (e); |
| 2821 |
/* Now, we have a single successor block, if we have insns to |
| 2822 |
insert on the remaining edge we potentially will insert |
| 2823 |
it at the end of this block (if the dest block isn't feasible) |
| 2824 |
in order to avoid splitting the edge. This insertion will take |
| 2825 |
place in front of the last jump. But we might have emitted |
| 2826 |
multiple jumps (conditional and one unconditional) to the |
| 2827 |
same destination. Inserting in front of the last one then |
| 2828 |
is a problem. See PR 40021. We fix this by deleting all |
| 2829 |
jumps except the last unconditional one. */ |
| 2830 |
insn = PREV_INSN (get_last_insn ()); |
| 2831 |
/* Make sure we have an unconditional jump. Otherwise we're |
| 2832 |
confused. */ |
| 2833 |
gcc_assert (JUMP_P (insn) && !any_condjump_p (insn)); |
| 2834 |
for (insn = PREV_INSN (insn); insn != last;) |
| 2835 |
{ |
| 2836 |
insn = PREV_INSN (insn); |
| 2837 |
if (JUMP_P (NEXT_INSN (insn))) |
| 2838 |
{ |
| 2839 |
if (!any_condjump_p (NEXT_INSN (insn))) |
| 2840 |
{ |
| 2841 |
gcc_assert (BARRIER_P (NEXT_INSN (NEXT_INSN (insn)))); |
| 2842 |
delete_insn (NEXT_INSN (NEXT_INSN (insn))); |
| 2843 |
} |
| 2844 |
delete_insn (NEXT_INSN (insn)); |
| 2845 |
} |
| 2846 |
} |
| 2847 |
} |
| 2848 |
} |
| 2849 |
|
| 2850 |
/* A subroutine of expand_gimple_basic_block. Expand one GIMPLE_COND. |
| 2851 |
Returns a new basic block if we've terminated the current basic |
| 2852 |
block and created a new one. */ |
| 2853 |
|
| 2854 |
static basic_block |
| 2855 |
expand_gimple_cond (basic_block bb, gcond *stmt) |
| 2856 |
{ |
| 2857 |
basic_block new_bb, dest; |
| 2858 |
edge true_edge; |
| 2859 |
edge false_edge; |
| 2860 |
rtx_insn *last2, *last; |
| 2861 |
enum tree_code code; |
| 2862 |
tree op0, op1; |
| 2863 |
|
| 2864 |
code = gimple_cond_code (stmt); |
| 2865 |
op0 = gimple_cond_lhs (stmt); |
| 2866 |
op1 = gimple_cond_rhs (stmt); |
| 2867 |
/* We're sometimes presented with such code: |
| 2868 |
D.123_1 = x < y; |
| 2869 |
if (D.123_1 != 0) |
| 2870 |
... |
| 2871 |
This would expand to two comparisons which then later might |
| 2872 |
be cleaned up by combine. But some pattern matchers like if-conversion |
| 2873 |
work better when there's only one compare, so make up for this |
| 2874 |
here as special exception if TER would have made the same change. */ |
| 2875 |
if (SA.values |
| 2876 |
&& TREE_CODE (op0) == SSA_NAME |
| 2877 |
&& TREE_CODE (TREE_TYPE (op0)) == BOOLEAN_TYPE |
| 2878 |
&& TREE_CODE (op1) == INTEGER_CST |
| 2879 |
&& ((gimple_cond_code (stmt) == NE_EXPR |
| 2880 |
&& integer_zerop (op1)) |
| 2881 |
|| (gimple_cond_code (stmt) == EQ_EXPR |
| 2882 |
&& integer_onep (op1))) |
| 2883 |
&& bitmap_bit_p (SA.values, SSA_NAME_VERSION (op0))) |
| 2884 |
{ |
| 2885 |
gimple *second = SSA_NAME_DEF_STMT (op0); |
| 2886 |
if (gimple_code (second) == GIMPLE_ASSIGN) |
| 2887 |
{ |
| 2888 |
enum tree_code code2 = gimple_assign_rhs_code (second); |
| 2889 |
if (TREE_CODE_CLASS (code2) == tcc_comparison) |
| 2890 |
{ |
| 2891 |
code = code2; |
| 2892 |
op0 = gimple_assign_rhs1 (second); |
| 2893 |
op1 = gimple_assign_rhs2 (second); |
| 2894 |
} |
| 2895 |
/* If jumps are cheap and the target does not support conditional |
| 2896 |
compare, turn some more codes into jumpy sequences. */ |
| 2897 |
else if (BRANCH_COST (optimize_insn_for_speed_p (), false) < 4 |
| 2898 |
&& !targetm.have_ccmp ()) |
| 2899 |
{ |
| 2900 |
if ((code2 == BIT_AND_EXPR |
| 2901 |
&& TYPE_PRECISION (TREE_TYPE (op0)) == 1 |
| 2902 |
&& TREE_CODE (gimple_assign_rhs2 (second)) != INTEGER_CST) |
| 2903 |
|| code2 == TRUTH_AND_EXPR) |
| 2904 |
{ |
| 2905 |
code = TRUTH_ANDIF_EXPR; |
| 2906 |
op0 = gimple_assign_rhs1 (second); |
| 2907 |
op1 = gimple_assign_rhs2 (second); |
| 2908 |
} |
| 2909 |
else if (code2 == BIT_IOR_EXPR || code2 == TRUTH_OR_EXPR) |
| 2910 |
{ |
| 2911 |
code = TRUTH_ORIF_EXPR; |
| 2912 |
op0 = gimple_assign_rhs1 (second); |
| 2913 |
op1 = gimple_assign_rhs2 (second); |
| 2914 |
} |
| 2915 |
} |
| 2916 |
} |
| 2917 |
} |
| 2918 |
|
| 2919 |
/* Optimize (x % C1) == C2 or (x % C1) != C2 if it is beneficial |
| 2920 |
into (x - C2) * C3 < C4. */ |
| 2921 |
if ((code == EQ_EXPR || code == NE_EXPR) |
| 2922 |
&& TREE_CODE (op0) == SSA_NAME |
| 2923 |
&& TREE_CODE (op1) == INTEGER_CST) |
| 2924 |
code = maybe_optimize_mod_cmp (code, &op0, &op1); |
| 2925 |
|
| 2926 |
/* Optimize (x - y) < 0 into x < y if x - y has undefined overflow. */ |
| 2927 |
if (!TYPE_UNSIGNED (TREE_TYPE (op0)) |
| 2928 |
&& (code == LT_EXPR || code == LE_EXPR |
| 2929 |
|| code == GT_EXPR || code == GE_EXPR) |
| 2930 |
&& integer_zerop (op1) |
| 2931 |
&& TREE_CODE (op0) == SSA_NAME) |
| 2932 |
maybe_optimize_sub_cmp_0 (code, &op0, &op1); |
| 2933 |
|
| 2934 |
last2 = last = get_last_insn (); |
| 2935 |
|
| 2936 |
extract_true_false_edges_from_block (bb, &true_edge, &false_edge); |
| 2937 |
set_curr_insn_location (gimple_location (stmt)); |
| 2938 |
|
| 2939 |
/* These flags have no purpose in RTL land. */ |
| 2940 |
true_edge->flags &= ~EDGE_TRUE_VALUE; |
| 2941 |
false_edge->flags &= ~EDGE_FALSE_VALUE; |
| 2942 |
|
| 2943 |
/* We can either have a pure conditional jump with one fallthru edge or |
| 2944 |
two-way jump that needs to be decomposed into two basic blocks. */ |
| 2945 |
if (false_edge->dest == bb->next_bb) |
| 2946 |
{ |
| 2947 |
jumpif_1 (code, op0, op1, label_rtx_for_bb (true_edge->dest), |
| 2948 |
true_edge->probability); |
| 2949 |
maybe_dump_rtl_for_gimple_stmt (stmt, last); |
| 2950 |
if (true_edge->goto_locus != UNKNOWN_LOCATION) |
| 2951 |
set_curr_insn_location (true_edge->goto_locus); |
| 2952 |
false_edge->flags |= EDGE_FALLTHRU; |
| 2953 |
maybe_cleanup_end_of_block (false_edge, last); |
| 2954 |
return NULL; |
| 2955 |
} |
| 2956 |
if (true_edge->dest == bb->next_bb) |
| 2957 |
{ |
| 2958 |
jumpifnot_1 (code, op0, op1, label_rtx_for_bb (false_edge->dest), |
| 2959 |
false_edge->probability); |
| 2960 |
maybe_dump_rtl_for_gimple_stmt (stmt, last); |
| 2961 |
if (false_edge->goto_locus != UNKNOWN_LOCATION) |
| 2962 |
set_curr_insn_location (false_edge->goto_locus); |
| 2963 |
true_edge->flags |= EDGE_FALLTHRU; |
| 2964 |
maybe_cleanup_end_of_block (true_edge, last); |
| 2965 |
return NULL; |
| 2966 |
} |
| 2967 |
|
| 2968 |
jumpif_1 (code, op0, op1, label_rtx_for_bb (true_edge->dest), |
| 2969 |
true_edge->probability); |
| 2970 |
last = get_last_insn (); |
| 2971 |
if (false_edge->goto_locus != UNKNOWN_LOCATION) |
| 2972 |
set_curr_insn_location (false_edge->goto_locus); |
| 2973 |
emit_jump (label_rtx_for_bb (false_edge->dest)); |
| 2974 |
|
| 2975 |
BB_END (bb) = last; |
| 2976 |
if (BARRIER_P (BB_END (bb))) |
| 2977 |
BB_END (bb) = PREV_INSN (BB_END (bb)); |
| 2978 |
update_bb_for_insn (bb); |
| 2979 |
|
| 2980 |
new_bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb); |
| 2981 |
dest = false_edge->dest; |
| 2982 |
redirect_edge_succ (false_edge, new_bb); |
| 2983 |
false_edge->flags |= EDGE_FALLTHRU; |
| 2984 |
new_bb->count = false_edge->count (); |
| 2985 |
loop_p loop = find_common_loop (bb->loop_father, dest->loop_father); |
| 2986 |
add_bb_to_loop (new_bb, loop); |
| 2987 |
if (loop->latch == bb |
| 2988 |
&& loop->header == dest) |
| 2989 |
loop->latch = new_bb; |
| 2990 |
make_single_succ_edge (new_bb, dest, 0); |
| 2991 |
if (BARRIER_P (BB_END (new_bb))) |
| 2992 |
BB_END (new_bb) = PREV_INSN (BB_END (new_bb)); |
| 2993 |
update_bb_for_insn (new_bb); |
| 2994 |
|
| 2995 |
maybe_dump_rtl_for_gimple_stmt (stmt, last2); |
| 2996 |
|
| 2997 |
if (true_edge->goto_locus != UNKNOWN_LOCATION) |
| 2998 |
{ |
| 2999 |
set_curr_insn_location (true_edge->goto_locus); |
| 3000 |
true_edge->goto_locus = curr_insn_location (); |
| 3001 |
} |
| 3002 |
|
| 3003 |
return new_bb; |
| 3004 |
} |
| 3005 |
|
| 3006 |
/* Mark all calls that can have a transaction restart. */ |
| 3007 |
|
| 3008 |
static void |
| 3009 |
mark_transaction_restart_calls (gimple *stmt) |
| 3010 |
{ |
| 3011 |
struct tm_restart_node dummy; |
| 3012 |
tm_restart_node **slot; |
| 3013 |
|
| 3014 |
if (!cfun->gimple_df->tm_restart) |
| 3015 |
return; |
| 3016 |
|
| 3017 |
dummy.stmt = stmt; |
| 3018 |
slot = cfun->gimple_df->tm_restart->find_slot (&dummy, NO_INSERT); |
| 3019 |
if (slot) |
| 3020 |
{ |
| 3021 |
struct tm_restart_node *n = *slot; |
| 3022 |
tree list = n->label_or_list; |
| 3023 |
rtx_insn *insn; |
| 3024 |
|
| 3025 |
for (insn = next_real_insn (get_last_insn ()); |
| 3026 |
!CALL_P (insn); |
| 3027 |
insn = next_real_insn (insn)) |
| 3028 |
continue; |
| 3029 |
|
| 3030 |
if (TREE_CODE (list) == LABEL_DECL) |
| 3031 |
add_reg_note (insn, REG_TM, label_rtx (list)); |
| 3032 |
else |
| 3033 |
for (; list ; list = TREE_CHAIN (list)) |
| 3034 |
add_reg_note (insn, REG_TM, label_rtx (TREE_VALUE (list))); |
| 3035 |
} |
| 3036 |
} |
| 3037 |
|
| 3038 |
/* A subroutine of expand_gimple_stmt_1, expanding one GIMPLE_CALL |
| 3039 |
statement STMT. */ |
| 3040 |
|
| 3041 |
static void |
| 3042 |
expand_call_stmt (gcall *stmt) |
| 3043 |
{ |
| 3044 |
tree exp, decl, lhs; |
| 3045 |
bool builtin_p; |
| 3046 |
size_t i; |
| 3047 |
|
| 3048 |
if (gimple_call_internal_p (stmt)) |
| 3049 |
{ |
| 3050 |
expand_internal_call (stmt); |
| 3051 |
return; |
| 3052 |
} |
| 3053 |
|
| 3054 |
/* If this is a call to a built-in function and it has no effect other |
| 3055 |
than setting the lhs, try to implement it using an internal function |
| 3056 |
instead. */ |
| 3057 |
decl = gimple_call_fndecl (stmt); |
| 3058 |
if (gimple_call_lhs (stmt) |
| 3059 |
&& !gimple_has_side_effects (stmt) |
| 3060 |
&& (optimize || (decl && called_as_built_in (decl)))) |
| 3061 |
{ |
| 3062 |
internal_fn ifn = replacement_internal_fn (stmt); |
| 3063 |
if (ifn != IFN_LAST) |
| 3064 |
{ |
| 3065 |
expand_internal_call (ifn, stmt); |
| 3066 |
return; |
| 3067 |
} |
| 3068 |
} |
| 3069 |
|
| 3070 |
exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3); |
| 3071 |
|
| 3072 |
CALL_EXPR_FN (exp) = gimple_call_fn (stmt); |
| 3073 |
builtin_p = decl && fndecl_built_in_p (decl); |
| 3074 |
|
| 3075 |
/* If this is not a builtin function, the function type through which the |
| 3076 |
call is made may be different from the type of the function. */ |
| 3077 |
if (!builtin_p) |
| 3078 |
CALL_EXPR_FN (exp) |
| 3079 |
= fold_convert (build_pointer_type (gimple_call_fntype (stmt)), |
| 3080 |
CALL_EXPR_FN (exp)); |
| 3081 |
|
| 3082 |
TREE_TYPE (exp) = gimple_call_return_type (stmt); |
| 3083 |
CALL_EXPR_STATIC_CHAIN (exp) = gimple_call_chain (stmt); |
| 3084 |
|
| 3085 |
for (i = 0; i < gimple_call_num_args (stmt); i++) |
| 3086 |
{ |
| 3087 |
tree arg = gimple_call_arg (stmt, i); |
| 3088 |
gimple *def; |
| 3089 |
/* TER addresses into arguments of builtin functions so we have a |
| 3090 |
chance to infer more correct alignment information. See PR39954. */ |
| 3091 |
if (builtin_p |
| 3092 |
&& TREE_CODE (arg) == SSA_NAME |
| 3093 |
&& (def = get_gimple_for_ssa_name (arg)) |
| 3094 |
&& is_gimple_assign (def) |
| 3095 |
&& gimple_assign_rhs_code (def) == ADDR_EXPR) |
| 3096 |
arg = gimple_assign_rhs1 (def); |
| 3097 |
CALL_EXPR_ARG (exp, i) = arg; |
| 3098 |
} |
| 3099 |
|
| 3100 |
if (gimple_has_side_effects (stmt) |
| 3101 |
/* ??? Downstream in expand_expr_real_1 we assume that expressions |
| 3102 |
w/o side-effects do not throw so work around this here. */ |
| 3103 |
|| stmt_could_throw_p (cfun, stmt)) |
| 3104 |
TREE_SIDE_EFFECTS (exp) = 1; |
| 3105 |
|
| 3106 |
if (gimple_call_nothrow_p (stmt)) |
| 3107 |
TREE_NOTHROW (exp) = 1; |
| 3108 |
|
| 3109 |
CALL_EXPR_TAILCALL (exp) = gimple_call_tail_p (stmt); |
| 3110 |
CALL_EXPR_MUST_TAIL_CALL (exp) = gimple_call_must_tail_p (stmt); |
| 3111 |
CALL_EXPR_RETURN_SLOT_OPT (exp) = gimple_call_return_slot_opt_p (stmt); |
| 3112 |
if (decl |
| 3113 |
&& fndecl_built_in_p (decl, BUILT_IN_NORMAL) |
| 3114 |
&& ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl))) |
| 3115 |
CALL_ALLOCA_FOR_VAR_P (exp) = gimple_call_alloca_for_var_p (stmt); |
| 3116 |
else |
| 3117 |
CALL_FROM_THUNK_P (exp) = gimple_call_from_thunk_p (stmt); |
| 3118 |
CALL_EXPR_VA_ARG_PACK (exp) = gimple_call_va_arg_pack_p (stmt); |
| 3119 |
CALL_EXPR_BY_DESCRIPTOR (exp) = gimple_call_by_descriptor_p (stmt); |
| 3120 |
SET_EXPR_LOCATION (exp, gimple_location (stmt)); |
| 3121 |
|
| 3122 |
/* Must come after copying location. */ |
| 3123 |
copy_warning (exp, stmt); |
| 3124 |
|
| 3125 |
/* Ensure RTL is created for debug args. */ |
| 3126 |
if (decl && DECL_HAS_DEBUG_ARGS_P (decl)) |
| 3127 |
{ |
| 3128 |
vec<tree, va_gc> **debug_args = decl_debug_args_lookup (decl); |
| 3129 |
unsigned int ix; |
| 3130 |
tree dtemp; |
| 3131 |
|
| 3132 |
if (debug_args) |
| 3133 |
for (ix = 1; (*debug_args)->iterate (ix, &dtemp); ix += 2) |
| 3134 |
{ |
| 3135 |
gcc_assert (TREE_CODE (dtemp) == DEBUG_EXPR_DECL); |
| 3136 |
expand_debug_expr (dtemp); |
| 3137 |
} |
| 3138 |
} |
| 3139 |
|
| 3140 |
rtx_insn *before_call = get_last_insn (); |
| 3141 |
lhs = gimple_call_lhs (stmt); |
| 3142 |
if (lhs) |
| 3143 |
expand_assignment (lhs, exp, false); |
| 3144 |
else |
| 3145 |
expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL); |
| 3146 |
|
| 3147 |
/* If the gimple call is an indirect call and has 'nocf_check' |
| 3148 |
attribute find a generated CALL insn to mark it as no |
| 3149 |
control-flow verification is needed. */ |
| 3150 |
if (gimple_call_nocf_check_p (stmt) |
| 3151 |
&& !gimple_call_fndecl (stmt)) |
| 3152 |
{ |
| 3153 |
rtx_insn *last = get_last_insn (); |
| 3154 |
while (!CALL_P (last) |
| 3155 |
&& last != before_call) |
| 3156 |
last = PREV_INSN (last); |
| 3157 |
|
| 3158 |
if (last != before_call) |
| 3159 |
add_reg_note (last, REG_CALL_NOCF_CHECK, const0_rtx); |
| 3160 |
} |
| 3161 |
|
| 3162 |
mark_transaction_restart_calls (stmt); |
| 3163 |
} |
| 3164 |
|
| 3165 |
|
| 3166 |
/* Generate RTL for an asm statement (explicit assembler code). |
| 3167 |
STRING is a STRING_CST node containing the assembler code text, |
| 3168 |
or an ADDR_EXPR containing a STRING_CST. VOL nonzero means the |
| 3169 |
insn is volatile; don't optimize it. */ |
| 3170 |
|
| 3171 |
static void |
| 3172 |
expand_asm_loc (tree string, int vol, location_t locus) |
| 3173 |
{ |
| 3174 |
rtx body; |
| 3175 |
|
| 3176 |
body = gen_rtx_ASM_INPUT_loc (VOIDmode, |
| 3177 |
ggc_strdup (TREE_STRING_POINTER (string)), |
| 3178 |
locus); |
| 3179 |
|
| 3180 |
MEM_VOLATILE_P (body) = vol; |
| 3181 |
|
| 3182 |
/* Non-empty basic ASM implicitly clobbers memory. */ |
| 3183 |
if (TREE_STRING_LENGTH (string) != 0) |
| 3184 |
{ |
| 3185 |
rtx asm_op, clob; |
| 3186 |
unsigned i, nclobbers; |
| 3187 |
auto_vec<rtx> input_rvec, output_rvec; |
| 3188 |
auto_vec<machine_mode> input_mode; |
| 3189 |
auto_vec<const char *> constraints; |
| 3190 |
auto_vec<rtx> use_rvec; |
| 3191 |
auto_vec<rtx> clobber_rvec; |
| 3192 |
HARD_REG_SET clobbered_regs; |
| 3193 |
CLEAR_HARD_REG_SET (clobbered_regs); |
| 3194 |
|
| 3195 |
clob = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode)); |
| 3196 |
clobber_rvec.safe_push (clob); |
| 3197 |
|
| 3198 |
if (targetm.md_asm_adjust) |
| 3199 |
targetm.md_asm_adjust (output_rvec, input_rvec, input_mode, |
| 3200 |
constraints, use_rvec, clobber_rvec, |
| 3201 |
clobbered_regs, locus); |
| 3202 |
|
| 3203 |
asm_op = body; |
| 3204 |
nclobbers = clobber_rvec.length (); |
| 3205 |
auto nuses = use_rvec.length (); |
| 3206 |
body = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (1 + nuses + nclobbers)); |
| 3207 |
|
| 3208 |
i = 0; |
| 3209 |
XVECEXP (body, 0, i++) = asm_op; |
| 3210 |
for (rtx use : use_rvec) |
| 3211 |
XVECEXP (body, 0, i++) = gen_rtx_USE (VOIDmode, use); |
| 3212 |
for (rtx clobber : clobber_rvec) |
| 3213 |
XVECEXP (body, 0, i++) = gen_rtx_CLOBBER (VOIDmode, clobber); |
| 3214 |
} |
| 3215 |
|
| 3216 |
emit_insn (body); |
| 3217 |
} |
| 3218 |
|
| 3219 |
/* Return the number of times character C occurs in string S. */ |
| 3220 |
static int |
| 3221 |
n_occurrences (int c, const char *s) |
| 3222 |
{ |
| 3223 |
int n = 0; |
| 3224 |
while (*s) |
| 3225 |
n += (*s++ == c); |
| 3226 |
return n; |
| 3227 |
} |
| 3228 |
|
| 3229 |
/* A subroutine of expand_asm_operands. Check that all operands have |
| 3230 |
the same number of alternatives. Return true if so. */ |
| 3231 |
|
| 3232 |
static bool |
| 3233 |
check_operand_nalternatives (const vec<const char *> &constraints) |
| 3234 |
{ |
| 3235 |
unsigned len = constraints.length(); |
| 3236 |
if (len > 0) |
| 3237 |
{ |
| 3238 |
int nalternatives = n_occurrences (',', constraints[0]); |
| 3239 |
|
| 3240 |
if (nalternatives + 1 > MAX_RECOG_ALTERNATIVES) |
| 3241 |
{ |
| 3242 |
error ("too many alternatives in %<asm%>"); |
| 3243 |
return false; |
| 3244 |
} |
| 3245 |
|
| 3246 |
for (unsigned i = 1; i < len; ++i) |
| 3247 |
if (n_occurrences (',', constraints[i]) != nalternatives) |
| 3248 |
{ |
| 3249 |
error ("operand constraints for %<asm%> differ " |
| 3250 |
"in number of alternatives"); |
| 3251 |
return false; |
| 3252 |
} |
| 3253 |
} |
| 3254 |
return true; |
| 3255 |
} |
| 3256 |
|
| 3257 |
/* Check for overlap between registers marked in CLOBBERED_REGS and |
| 3258 |
anything inappropriate in T. Emit error and return the register |
| 3259 |
variable definition for error, NULL_TREE for ok. */ |
| 3260 |
|
| 3261 |
static bool |
| 3262 |
tree_conflicts_with_clobbers_p (tree t, HARD_REG_SET *clobbered_regs, |
| 3263 |
location_t loc) |
| 3264 |
{ |
| 3265 |
/* Conflicts between asm-declared register variables and the clobber |
| 3266 |
list are not allowed. */ |
| 3267 |
tree overlap = tree_overlaps_hard_reg_set (t, clobbered_regs); |
| 3268 |
|
| 3269 |
if (overlap) |
| 3270 |
{ |
| 3271 |
error_at (loc, "%<asm%> specifier for variable %qE conflicts with " |
| 3272 |
"%<asm%> clobber list", DECL_NAME (overlap)); |
| 3273 |
|
| 3274 |
/* Reset registerness to stop multiple errors emitted for a single |
| 3275 |
variable. */ |
| 3276 |
DECL_REGISTER (overlap) = 0; |
| 3277 |
return true; |
| 3278 |
} |
| 3279 |
|
| 3280 |
return false; |
| 3281 |
} |
| 3282 |
|
| 3283 |
/* Check that the given REGNO spanning NREGS is a valid |
| 3284 |
asm clobber operand. Some HW registers cannot be |
| 3285 |
saved/restored, hence they should not be clobbered by |
| 3286 |
asm statements. */ |
| 3287 |
static bool |
| 3288 |
asm_clobber_reg_is_valid (int regno, int nregs, const char *regname) |
| 3289 |
{ |
| 3290 |
bool is_valid = true; |
| 3291 |
HARD_REG_SET regset; |
| 3292 |
|
| 3293 |
CLEAR_HARD_REG_SET (regset); |
| 3294 |
|
| 3295 |
add_range_to_hard_reg_set (®set, regno, nregs); |
| 3296 |
|
| 3297 |
/* Clobbering the PIC register is an error. */ |
| 3298 |
if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM |
| 3299 |
&& overlaps_hard_reg_set_p (regset, Pmode, PIC_OFFSET_TABLE_REGNUM)) |
| 3300 |
{ |
| 3301 |
/* ??? Diagnose during gimplification? */ |
| 3302 |
error ("PIC register clobbered by %qs in %<asm%>", regname); |
| 3303 |
is_valid = false; |
| 3304 |
} |
| 3305 |
else if (!in_hard_reg_set_p |
| 3306 |
(accessible_reg_set, reg_raw_mode[regno], regno)) |
| 3307 |
{ |
| 3308 |
/* ??? Diagnose during gimplification? */ |
| 3309 |
error ("the register %qs cannot be clobbered in %<asm%>" |
| 3310 |
" for the current target", regname); |
| 3311 |
is_valid = false; |
| 3312 |
} |
| 3313 |
|
| 3314 |
/* Clobbering the stack pointer register is deprecated. GCC expects |
| 3315 |
the value of the stack pointer after an asm statement to be the same |
| 3316 |
as it was before, so no asm can validly clobber the stack pointer in |
| 3317 |
the usual sense. Adding the stack pointer to the clobber list has |
| 3318 |
traditionally had some undocumented and somewhat obscure side-effects. */ |
| 3319 |
if (overlaps_hard_reg_set_p (regset, Pmode, STACK_POINTER_REGNUM)) |
| 3320 |
{ |
| 3321 |
crtl->sp_is_clobbered_by_asm = true; |
| 3322 |
if (warning (OPT_Wdeprecated, "listing the stack pointer register" |
| 3323 |
" %qs in a clobber list is deprecated", regname)) |
| 3324 |
inform (input_location, "the value of the stack pointer after" |
| 3325 |
" an %<asm%> statement must be the same as it was before" |
| 3326 |
" the statement"); |
| 3327 |
} |
| 3328 |
|
| 3329 |
return is_valid; |
| 3330 |
} |
| 3331 |
|
| 3332 |
/* Generate RTL for an asm statement with arguments. |
| 3333 |
STRING is the instruction template. |
| 3334 |
OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs. |
| 3335 |
Each output or input has an expression in the TREE_VALUE and |
| 3336 |
a tree list in TREE_PURPOSE which in turn contains a constraint |
| 3337 |
name in TREE_VALUE (or NULL_TREE) and a constraint string |
| 3338 |
in TREE_PURPOSE. |
| 3339 |
CLOBBERS is a list of STRING_CST nodes each naming a hard register |
| 3340 |
that is clobbered by this insn. |
| 3341 |
|
| 3342 |
LABELS is a list of labels, and if LABELS is non-NULL, FALLTHRU_BB |
| 3343 |
should be the fallthru basic block of the asm goto. |
| 3344 |
|
| 3345 |
Not all kinds of lvalue that may appear in OUTPUTS can be stored directly. |
| 3346 |
Some elements of OUTPUTS may be replaced with trees representing temporary |
| 3347 |
values. The caller should copy those temporary values to the originally |
| 3348 |
specified lvalues. |
| 3349 |
|
| 3350 |
VOL nonzero means the insn is volatile; don't optimize it. */ |
| 3351 |
|
| 3352 |
static void |
| 3353 |
expand_asm_stmt (gasm *stmt) |
| 3354 |
{ |
| 3355 |
class save_input_location |
| 3356 |
{ |
| 3357 |
location_t old; |
| 3358 |
|
| 3359 |
public: |
| 3360 |
explicit save_input_location(location_t where) |
| 3361 |
{ |
| 3362 |
old = input_location; |
| 3363 |
input_location = where; |
| 3364 |
} |
| 3365 |
|
| 3366 |
~save_input_location() |
| 3367 |
{ |
| 3368 |
input_location = old; |
| 3369 |
} |
| 3370 |
}; |
| 3371 |
|
| 3372 |
location_t locus = gimple_location (stmt); |
| 3373 |
|
| 3374 |
if (gimple_asm_basic_p (stmt)) |
| 3375 |
{ |
| 3376 |
const char *s = gimple_asm_string (stmt); |
| 3377 |
tree string = build_string (strlen (s), s); |
| 3378 |
expand_asm_loc (string, gimple_asm_volatile_p (stmt), locus); |
| 3379 |
return; |
| 3380 |
} |
| 3381 |
|
| 3382 |
/* There are some legacy diagnostics in here. */ |
| 3383 |
save_input_location s_i_l(locus); |
| 3384 |
|
| 3385 |
unsigned noutputs = gimple_asm_noutputs (stmt); |
| 3386 |
unsigned ninputs = gimple_asm_ninputs (stmt); |
| 3387 |
unsigned nlabels = gimple_asm_nlabels (stmt); |
| 3388 |
unsigned i; |
| 3389 |
bool error_seen = false; |
| 3390 |
|
| 3391 |
/* ??? Diagnose during gimplification? */ |
| 3392 |
if (ninputs + noutputs + nlabels > MAX_RECOG_OPERANDS) |
| 3393 |
{ |
| 3394 |
error_at (locus, "more than %d operands in %<asm%>", MAX_RECOG_OPERANDS); |
| 3395 |
return; |
| 3396 |
} |
| 3397 |
|
| 3398 |
auto_vec<tree, MAX_RECOG_OPERANDS> output_tvec; |
| 3399 |
auto_vec<tree, MAX_RECOG_OPERANDS> input_tvec; |
| 3400 |
auto_vec<const char *, MAX_RECOG_OPERANDS> constraints; |
| 3401 |
|
| 3402 |
/* Copy the gimple vectors into new vectors that we can manipulate. */ |
| 3403 |
|
| 3404 |
output_tvec.safe_grow (noutputs, true); |
| 3405 |
input_tvec.safe_grow (ninputs, true); |
| 3406 |
constraints.safe_grow (noutputs + ninputs, true); |
| 3407 |
|
| 3408 |
for (i = 0; i < noutputs; ++i) |
| 3409 |
{ |
| 3410 |
tree t = gimple_asm_output_op (stmt, i); |
| 3411 |
output_tvec[i] = TREE_VALUE (t); |
| 3412 |
constraints[i] = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); |
| 3413 |
} |
| 3414 |
for (i = 0; i < ninputs; i++) |
| 3415 |
{ |
| 3416 |
tree t = gimple_asm_input_op (stmt, i); |
| 3417 |
input_tvec[i] = TREE_VALUE (t); |
| 3418 |
constraints[i + noutputs] |
| 3419 |
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); |
| 3420 |
} |
| 3421 |
|
| 3422 |
/* ??? Diagnose during gimplification? */ |
| 3423 |
if (! check_operand_nalternatives (constraints)) |
| 3424 |
return; |
| 3425 |
|
| 3426 |
/* Count the number of meaningful clobbered registers, ignoring what |
| 3427 |
we would ignore later. */ |
| 3428 |
auto_vec<rtx> clobber_rvec; |
| 3429 |
HARD_REG_SET clobbered_regs; |
| 3430 |
CLEAR_HARD_REG_SET (clobbered_regs); |
| 3431 |
|
| 3432 |
if (unsigned n = gimple_asm_nclobbers (stmt)) |
| 3433 |
{ |
| 3434 |
clobber_rvec.reserve (n); |
| 3435 |
for (i = 0; i < n; i++) |
| 3436 |
{ |
| 3437 |
tree t = gimple_asm_clobber_op (stmt, i); |
| 3438 |
const char *regname = TREE_STRING_POINTER (TREE_VALUE (t)); |
| 3439 |
int nregs, j; |
| 3440 |
|
| 3441 |
j = decode_reg_name_and_count (regname, &nregs); |
| 3442 |
if (j < 0) |
| 3443 |
{ |
| 3444 |
if (j == -2) |
| 3445 |
{ |
| 3446 |
/* ??? Diagnose during gimplification? */ |
| 3447 |
error_at (locus, "unknown register name %qs in %<asm%>", |
| 3448 |
regname); |
| 3449 |
error_seen = true; |
| 3450 |
} |
| 3451 |
else if (j == -4) |
| 3452 |
{ |
| 3453 |
rtx x = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode)); |
| 3454 |
clobber_rvec.safe_push (x); |
| 3455 |
} |
| 3456 |
else if (j == -5) |
| 3457 |
{ |
| 3458 |
if (targetm.redzone_clobber) |
| 3459 |
if (rtx x = targetm.redzone_clobber ()) |
| 3460 |
clobber_rvec.safe_push (x); |
| 3461 |
} |
| 3462 |
else |
| 3463 |
{ |
| 3464 |
/* Otherwise we should have -1 == empty string |
| 3465 |
or -3 == cc, which is not a register. */ |
| 3466 |
gcc_assert (j == -1 || j == -3); |
| 3467 |
} |
| 3468 |
} |
| 3469 |
else |
| 3470 |
for (int reg = j; reg < j + nregs; reg++) |
| 3471 |
{ |
| 3472 |
if (!asm_clobber_reg_is_valid (reg, nregs, regname)) |
| 3473 |
return; |
| 3474 |
|
| 3475 |
SET_HARD_REG_BIT (clobbered_regs, reg); |
| 3476 |
rtx x = gen_rtx_REG (reg_raw_mode[reg], reg); |
| 3477 |
clobber_rvec.safe_push (x); |
| 3478 |
} |
| 3479 |
} |
| 3480 |
} |
| 3481 |
|
| 3482 |
/* First pass over inputs and outputs checks validity and sets |
| 3483 |
mark_addressable if needed. */ |
| 3484 |
/* ??? Diagnose during gimplification? */ |
| 3485 |
|
| 3486 |
for (i = 0; i < noutputs; ++i) |
| 3487 |
{ |
| 3488 |
tree val = output_tvec[i]; |
| 3489 |
tree type = TREE_TYPE (val); |
| 3490 |
const char *constraint; |
| 3491 |
bool is_inout; |
| 3492 |
bool allows_reg; |
| 3493 |
bool allows_mem; |
| 3494 |
|
| 3495 |
/* Try to parse the output constraint. If that fails, there's |
| 3496 |
no point in going further. */ |
| 3497 |
constraint = constraints[i]; |
| 3498 |
if (!parse_output_constraint (&constraint, i, ninputs, noutputs, |
| 3499 |
&allows_mem, &allows_reg, &is_inout)) |
| 3500 |
return; |
| 3501 |
|
| 3502 |
/* If the output is a hard register, verify it doesn't conflict with |
| 3503 |
any other operand's possible hard register use. */ |
| 3504 |
if (DECL_P (val) |
| 3505 |
&& REG_P (DECL_RTL (val)) |
| 3506 |
&& HARD_REGISTER_P (DECL_RTL (val))) |
| 3507 |
{ |
| 3508 |
unsigned j, output_hregno = REGNO (DECL_RTL (val)); |
| 3509 |
bool early_clobber_p = strchr (constraints[i], '&') != NULL; |
| 3510 |
unsigned long match; |
| 3511 |
|
| 3512 |
/* Verify the other outputs do not use the same hard register. */ |
| 3513 |
for (j = i + 1; j < noutputs; ++j) |
| 3514 |
if (DECL_P (output_tvec[j]) |
| 3515 |
&& REG_P (DECL_RTL (output_tvec[j])) |
| 3516 |
&& HARD_REGISTER_P (DECL_RTL (output_tvec[j])) |
| 3517 |
&& output_hregno == REGNO (DECL_RTL (output_tvec[j]))) |
| 3518 |
{ |
| 3519 |
error_at (locus, "invalid hard register usage between output " |
| 3520 |
"operands"); |
| 3521 |
error_seen = true; |
| 3522 |
} |
| 3523 |
|
| 3524 |
/* Verify matching constraint operands use the same hard register |
| 3525 |
and that the non-matching constraint operands do not use the same |
| 3526 |
hard register if the output is an early clobber operand. */ |
| 3527 |
for (j = 0; j < ninputs; ++j) |
| 3528 |
if (DECL_P (input_tvec[j]) |
| 3529 |
&& REG_P (DECL_RTL (input_tvec[j])) |
| 3530 |
&& HARD_REGISTER_P (DECL_RTL (input_tvec[j]))) |
| 3531 |
{ |
| 3532 |
unsigned input_hregno = REGNO (DECL_RTL (input_tvec[j])); |
| 3533 |
switch (*constraints[j + noutputs]) |
| 3534 |
{ |
| 3535 |
case '0': case '1': case '2': case '3': case '4': |
| 3536 |
case '5': case '6': case '7': case '8': case '9': |
| 3537 |
match = strtoul (constraints[j + noutputs], NULL, 10); |
| 3538 |
break; |
| 3539 |
default: |
| 3540 |
match = ULONG_MAX; |
| 3541 |
break; |
| 3542 |
} |
| 3543 |
if (i == match |
| 3544 |
&& output_hregno != input_hregno) |
| 3545 |
{ |
| 3546 |
error_at (locus, "invalid hard register usage between " |
| 3547 |
"output operand and matching constraint operand"); |
| 3548 |
error_seen = true; |
| 3549 |
} |
| 3550 |
else if (early_clobber_p |
| 3551 |
&& i != match |
| 3552 |
&& output_hregno == input_hregno) |
| 3553 |
{ |
| 3554 |
error_at (locus, "invalid hard register usage between " |
| 3555 |
"earlyclobber operand and input operand"); |
| 3556 |
error_seen = true; |
| 3557 |
} |
| 3558 |
} |
| 3559 |
} |
| 3560 |
|
| 3561 |
if (! allows_reg |
| 3562 |
&& (allows_mem |
| 3563 |
|| is_inout |
| 3564 |
|| (DECL_P (val) |
| 3565 |
&& REG_P (DECL_RTL (val)) |
| 3566 |
&& GET_MODE (DECL_RTL (val)) != TYPE_MODE (type)))) |
| 3567 |
mark_addressable (val); |
| 3568 |
} |
| 3569 |
|
| 3570 |
for (i = 0; i < ninputs; ++i) |
| 3571 |
{ |
| 3572 |
bool allows_reg, allows_mem; |
| 3573 |
const char *constraint; |
| 3574 |
|
| 3575 |
constraint = constraints[i + noutputs]; |
| 3576 |
if (! parse_input_constraint (&constraint, i, ninputs, noutputs, 0, |
| 3577 |
constraints.address (), |
| 3578 |
&allows_mem, &allows_reg)) |
| 3579 |
return; |
| 3580 |
|
| 3581 |
if (! allows_reg && allows_mem) |
| 3582 |
mark_addressable (input_tvec[i]); |
| 3583 |
} |
| 3584 |
|
| 3585 |
/* Second pass evaluates arguments. */ |
| 3586 |
|
| 3587 |
/* Make sure stack is consistent for asm goto. */ |
| 3588 |
if (nlabels > 0) |
| 3589 |
do_pending_stack_adjust (); |
| 3590 |
int old_generating_concat_p = generating_concat_p; |
| 3591 |
|
| 3592 |
/* Vector of RTX's of evaluated output operands. */ |
| 3593 |
auto_vec<rtx, MAX_RECOG_OPERANDS> output_rvec; |
| 3594 |
auto_vec<int, MAX_RECOG_OPERANDS> inout_opnum; |
| 3595 |
rtx_insn *after_rtl_seq = NULL, *after_rtl_end = NULL; |
| 3596 |
|
| 3597 |
output_rvec.safe_grow (noutputs, true); |
| 3598 |
|
| 3599 |
for (i = 0; i < noutputs; ++i) |
| 3600 |
{ |
| 3601 |
tree val = output_tvec[i]; |
| 3602 |
tree type = TREE_TYPE (val); |
| 3603 |
bool is_inout, allows_reg, allows_mem, ok; |
| 3604 |
rtx op; |
| 3605 |
|
| 3606 |
ok = parse_output_constraint (&constraints[i], i, ninputs, |
| 3607 |
noutputs, &allows_mem, &allows_reg, |
| 3608 |
&is_inout); |
| 3609 |
gcc_assert (ok); |
| 3610 |
|
| 3611 |
/* If an output operand is not a decl or indirect ref and our constraint |
| 3612 |
allows a register, make a temporary to act as an intermediate. |
| 3613 |
Make the asm insn write into that, then we will copy it to |
| 3614 |
the real output operand. Likewise for promoted variables. */ |
| 3615 |
|
| 3616 |
generating_concat_p = 0; |
| 3617 |
|
| 3618 |
gcc_assert (TREE_CODE (val) != INDIRECT_REF); |
| 3619 |
if (((TREE_CODE (val) == MEM_REF |
| 3620 |
&& TREE_CODE (TREE_OPERAND (val, 0)) != ADDR_EXPR) |
| 3621 |
&& allows_mem) |
| 3622 |
|| (DECL_P (val) |
| 3623 |
&& (allows_mem || REG_P (DECL_RTL (val))) |
| 3624 |
&& ! (REG_P (DECL_RTL (val)) |
| 3625 |
&& GET_MODE (DECL_RTL (val)) != TYPE_MODE (type))) |
| 3626 |
|| ! allows_reg |
| 3627 |
|| is_inout |
| 3628 |
|| TREE_ADDRESSABLE (type) |
| 3629 |
|| (!tree_fits_poly_int64_p (TYPE_SIZE (type)) |
| 3630 |
&& !known_size_p (max_int_size_in_bytes (type)))) |
| 3631 |
{ |
| 3632 |
op = expand_expr (val, NULL_RTX, VOIDmode, |
| 3633 |
!allows_reg ? EXPAND_MEMORY : EXPAND_WRITE); |
| 3634 |
if (MEM_P (op)) |
| 3635 |
op = validize_mem (op); |
| 3636 |
|
| 3637 |
if (! allows_reg && !MEM_P (op)) |
| 3638 |
{ |
| 3639 |
error_at (locus, "output number %d not directly addressable", i); |
| 3640 |
error_seen = true; |
| 3641 |
} |
| 3642 |
if ((! allows_mem && MEM_P (op) && GET_MODE (op) != BLKmode) |
| 3643 |
|| GET_CODE (op) == CONCAT) |
| 3644 |
{ |
| 3645 |
rtx old_op = op; |
| 3646 |
op = gen_reg_rtx (GET_MODE (op)); |
| 3647 |
|
| 3648 |
generating_concat_p = old_generating_concat_p; |
| 3649 |
|
| 3650 |
if (is_inout) |
| 3651 |
emit_move_insn (op, old_op); |
| 3652 |
|
| 3653 |
push_to_sequence2 (after_rtl_seq, after_rtl_end); |
| 3654 |
emit_move_insn (old_op, op); |
| 3655 |
after_rtl_seq = get_insns (); |
| 3656 |
after_rtl_end = get_last_insn (); |
| 3657 |
end_sequence (); |
| 3658 |
} |
| 3659 |
} |
| 3660 |
else |
| 3661 |
{ |
| 3662 |
op = assign_temp (type, 0, 1); |
| 3663 |
op = validize_mem (op); |
| 3664 |
if (!MEM_P (op) && TREE_CODE (val) == SSA_NAME) |
| 3665 |
set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (val), op); |
| 3666 |
|
| 3667 |
generating_concat_p = old_generating_concat_p; |
| 3668 |
|
| 3669 |
push_to_sequence2 (after_rtl_seq, after_rtl_end); |
| 3670 |
expand_assignment (val, make_tree (type, op), false); |
| 3671 |
after_rtl_seq = get_insns (); |
| 3672 |
after_rtl_end = get_last_insn (); |
| 3673 |
end_sequence (); |
| 3674 |
} |
| 3675 |
output_rvec[i] = op; |
| 3676 |
|
| 3677 |
if (is_inout) |
| 3678 |
inout_opnum.safe_push (i); |
| 3679 |
} |
| 3680 |
|
| 3681 |
const char *str = gimple_asm_string (stmt); |
| 3682 |
if (error_seen) |
| 3683 |
{ |
| 3684 |
ninputs = 0; |
| 3685 |
noutputs = 0; |
| 3686 |
inout_opnum.truncate (0); |
| 3687 |
output_rvec.truncate (0); |
| 3688 |
clobber_rvec.truncate (0); |
| 3689 |
constraints.truncate (0); |
| 3690 |
CLEAR_HARD_REG_SET (clobbered_regs); |
| 3691 |
str = ""; |
| 3692 |
} |
| 3693 |
|
| 3694 |
auto_vec<rtx, MAX_RECOG_OPERANDS> input_rvec; |
| 3695 |
auto_vec<machine_mode, MAX_RECOG_OPERANDS> input_mode; |
| 3696 |
|
| 3697 |
input_rvec.safe_grow (ninputs, true); |
| 3698 |
input_mode.safe_grow (ninputs, true); |
| 3699 |
|
| 3700 |
generating_concat_p = 0; |
| 3701 |
|
| 3702 |
for (i = 0; i < ninputs; ++i) |
| 3703 |
{ |
| 3704 |
tree val = input_tvec[i]; |
| 3705 |
tree type = TREE_TYPE (val); |
| 3706 |
bool allows_reg, allows_mem, ok; |
| 3707 |
const char *constraint; |
| 3708 |
rtx op; |
| 3709 |
|
| 3710 |
constraint = constraints[i + noutputs]; |
| 3711 |
ok = parse_input_constraint (&constraint, i, ninputs, noutputs, 0, |
| 3712 |
constraints.address (), |
| 3713 |
&allows_mem, &allows_reg); |
| 3714 |
gcc_assert (ok); |
| 3715 |
|
| 3716 |
/* EXPAND_INITIALIZER will not generate code for valid initializer |
| 3717 |
constants, but will still generate code for other types of operand. |
| 3718 |
This is the behavior we want for constant constraints. */ |
| 3719 |
op = expand_expr (val, NULL_RTX, VOIDmode, |
| 3720 |
allows_reg ? EXPAND_NORMAL |
| 3721 |
: allows_mem ? EXPAND_MEMORY |
| 3722 |
: EXPAND_INITIALIZER); |
| 3723 |
|
| 3724 |
/* Never pass a CONCAT to an ASM. */ |
| 3725 |
if (GET_CODE (op) == CONCAT) |
| 3726 |
op = force_reg (GET_MODE (op), op); |
| 3727 |
else if (MEM_P (op)) |
| 3728 |
op = validize_mem (op); |
| 3729 |
|
| 3730 |
if (asm_operand_ok (op, constraint, NULL) <= 0) |
| 3731 |
{ |
| 3732 |
if (allows_reg && TYPE_MODE (type) != BLKmode) |
| 3733 |
op = force_reg (TYPE_MODE (type), op); |
| 3734 |
else if (!allows_mem) |
| 3735 |
warning_at (locus, 0, "%<asm%> operand %d probably does not match " |
| 3736 |
"constraints", i + noutputs); |
| 3737 |
else if (MEM_P (op)) |
| 3738 |
{ |
| 3739 |
/* We won't recognize either volatile memory or memory |
| 3740 |
with a queued address as available a memory_operand |
| 3741 |
at this point. Ignore it: clearly this *is* a memory. */ |
| 3742 |
} |
| 3743 |
else |
| 3744 |
gcc_unreachable (); |
| 3745 |
} |
| 3746 |
input_rvec[i] = op; |
| 3747 |
input_mode[i] = TYPE_MODE (type); |
| 3748 |
} |
| 3749 |
|
| 3750 |
/* For in-out operands, copy output rtx to input rtx. */ |
| 3751 |
unsigned ninout = inout_opnum.length (); |
| 3752 |
for (i = 0; i < ninout; i++) |
| 3753 |
{ |
| 3754 |
int j = inout_opnum[i]; |
| 3755 |
rtx o = output_rvec[j]; |
| 3756 |
|
| 3757 |
input_rvec.safe_push (o); |
| 3758 |
input_mode.safe_push (GET_MODE (o)); |
| 3759 |
|
| 3760 |
char buffer[16]; |
| 3761 |
sprintf (buffer, "%d", j); |
| 3762 |
constraints.safe_push (ggc_strdup (buffer)); |
| 3763 |
} |
| 3764 |
ninputs += ninout; |
| 3765 |
|
| 3766 |
/* Sometimes we wish to automatically clobber registers across an asm. |
| 3767 |
Case in point is when the i386 backend moved from cc0 to a hard reg -- |
| 3768 |
maintaining source-level compatibility means automatically clobbering |
| 3769 |
the flags register. */ |
| 3770 |
auto_vec<rtx> use_rvec; |
| 3771 |
if (targetm.md_asm_adjust) |
| 3772 |
{ |
| 3773 |
rtx_insn *after_md_seq |
| 3774 |
= targetm.md_asm_adjust (output_rvec, input_rvec, input_mode, |
| 3775 |
constraints, use_rvec, clobber_rvec, |
| 3776 |
clobbered_regs, locus); |
| 3777 |
if (after_md_seq) |
| 3778 |
{ |
| 3779 |
push_to_sequence (after_md_seq); |
| 3780 |
emit_insn (after_rtl_seq); |
| 3781 |
after_rtl_seq = get_insns (); |
| 3782 |
after_rtl_end = get_last_insn (); |
| 3783 |
end_sequence (); |
| 3784 |
} |
| 3785 |
} |
| 3786 |
|
| 3787 |
/* Do not allow the hook to change the output and input count, |
| 3788 |
lest it mess up the operand numbering. */ |
| 3789 |
gcc_assert (output_rvec.length() == noutputs); |
| 3790 |
gcc_assert (input_rvec.length() == ninputs); |
| 3791 |
gcc_assert (constraints.length() == noutputs + ninputs); |
| 3792 |
|
| 3793 |
/* But it certainly can adjust the uses and clobbers. */ |
| 3794 |
unsigned nuses = use_rvec.length (); |
| 3795 |
unsigned nclobbers = clobber_rvec.length (); |
| 3796 |
|
| 3797 |
/* Third pass checks for easy conflicts. */ |
| 3798 |
/* ??? Why are we doing this on trees instead of rtx. */ |
| 3799 |
|
| 3800 |
bool clobber_conflict_found = 0; |
| 3801 |
for (i = 0; i < noutputs; ++i) |
| 3802 |
if (tree_conflicts_with_clobbers_p (output_tvec[i], &clobbered_regs, locus)) |
| 3803 |
clobber_conflict_found = 1; |
| 3804 |
for (i = 0; i < ninputs - ninout; ++i) |
| 3805 |
if (tree_conflicts_with_clobbers_p (input_tvec[i], &clobbered_regs, locus)) |
| 3806 |
clobber_conflict_found = 1; |
| 3807 |
|
| 3808 |
/* Make vectors for the expression-rtx, constraint strings, |
| 3809 |
and named operands. */ |
| 3810 |
|
| 3811 |
rtvec argvec = rtvec_alloc (ninputs); |
| 3812 |
rtvec constraintvec = rtvec_alloc (ninputs); |
| 3813 |
rtvec labelvec = rtvec_alloc (nlabels); |
| 3814 |
|
| 3815 |
rtx body = gen_rtx_ASM_OPERANDS ((noutputs == 0 ? VOIDmode |
| 3816 |
: GET_MODE (output_rvec[0])), |
| 3817 |
ggc_strdup (str), |
| 3818 |
"", 0, argvec, constraintvec, |
| 3819 |
labelvec, locus); |
| 3820 |
MEM_VOLATILE_P (body) = gimple_asm_volatile_p (stmt); |
| 3821 |
|
| 3822 |
for (i = 0; i < ninputs; ++i) |
| 3823 |
{ |
| 3824 |
ASM_OPERANDS_INPUT (body, i) = input_rvec[i]; |
| 3825 |
ASM_OPERANDS_INPUT_CONSTRAINT_EXP (body, i) |
| 3826 |
= gen_rtx_ASM_INPUT_loc (input_mode[i], |
| 3827 |
constraints[i + noutputs], |
| 3828 |
locus); |
| 3829 |
} |
| 3830 |
|
| 3831 |
/* Copy labels to the vector. */ |
| 3832 |
rtx_code_label *fallthru_label = NULL; |
| 3833 |
if (nlabels > 0) |
| 3834 |
{ |
| 3835 |
basic_block fallthru_bb = NULL; |
| 3836 |
edge fallthru = find_fallthru_edge (gimple_bb (stmt)->succs); |
| 3837 |
if (fallthru) |
| 3838 |
fallthru_bb = fallthru->dest; |
| 3839 |
|
| 3840 |
for (i = 0; i < nlabels; ++i) |
| 3841 |
{ |
| 3842 |
tree label = TREE_VALUE (gimple_asm_label_op (stmt, i)); |
| 3843 |
rtx_insn *r; |
| 3844 |
/* If asm goto has any labels in the fallthru basic block, use |
| 3845 |
a label that we emit immediately after the asm goto. Expansion |
| 3846 |
may insert further instructions into the same basic block after |
| 3847 |
asm goto and if we don't do this, insertion of instructions on |
| 3848 |
the fallthru edge might misbehave. See PR58670. */ |
| 3849 |
if (fallthru_bb && label_to_block (cfun, label) == fallthru_bb) |
| 3850 |
{ |
| 3851 |
if (fallthru_label == NULL_RTX) |
| 3852 |
fallthru_label = gen_label_rtx (); |
| 3853 |
r = fallthru_label; |
| 3854 |
} |
| 3855 |
else |
| 3856 |
r = label_rtx (label); |
| 3857 |
ASM_OPERANDS_LABEL (body, i) = gen_rtx_LABEL_REF (Pmode, r); |
| 3858 |
} |
| 3859 |
} |
| 3860 |
|
| 3861 |
/* Now, for each output, construct an rtx |
| 3862 |
(set OUTPUT (asm_operands INSN OUTPUTCONSTRAINT OUTPUTNUMBER |
| 3863 |
ARGVEC CONSTRAINTS OPNAMES)) |
| 3864 |
If there is more than one, put them inside a PARALLEL. */ |
| 3865 |
|
| 3866 |
if (noutputs == 0 && nuses == 0 && nclobbers == 0) |
| 3867 |
{ |
| 3868 |
/* No output operands: put in a raw ASM_OPERANDS rtx. */ |
| 3869 |
if (nlabels > 0) |
| 3870 |
emit_jump_insn (body); |
| 3871 |
else |
| 3872 |
emit_insn (body); |
| 3873 |
} |
| 3874 |
else if (noutputs == 1 && nuses == 0 && nclobbers == 0) |
| 3875 |
{ |
| 3876 |
ASM_OPERANDS_OUTPUT_CONSTRAINT (body) = constraints[0]; |
| 3877 |
if (nlabels > 0) |
| 3878 |
emit_jump_insn (gen_rtx_SET (output_rvec[0], body)); |
| 3879 |
else |
| 3880 |
emit_insn (gen_rtx_SET (output_rvec[0], body)); |
| 3881 |
} |
| 3882 |
else |
| 3883 |
{ |
| 3884 |
rtx obody = body; |
| 3885 |
int num = noutputs; |
| 3886 |
|
| 3887 |
if (num == 0) |
| 3888 |
num = 1; |
| 3889 |
|
| 3890 |
body = gen_rtx_PARALLEL (VOIDmode, |
| 3891 |
rtvec_alloc (num + nuses + nclobbers)); |
| 3892 |
|
| 3893 |
/* For each output operand, store a SET. */ |
| 3894 |
for (i = 0; i < noutputs; ++i) |
| 3895 |
{ |
| 3896 |
rtx src, o = output_rvec[i]; |
| 3897 |
if (i == 0) |
| 3898 |
{ |
| 3899 |
ASM_OPERANDS_OUTPUT_CONSTRAINT (obody) = constraints[0]; |
| 3900 |
src = obody; |
| 3901 |
} |
| 3902 |
else |
| 3903 |
{ |
| 3904 |
src = gen_rtx_ASM_OPERANDS (GET_MODE (o), |
| 3905 |
ASM_OPERANDS_TEMPLATE (obody), |
| 3906 |
constraints[i], i, argvec, |
| 3907 |
constraintvec, labelvec, locus); |
| 3908 |
MEM_VOLATILE_P (src) = gimple_asm_volatile_p (stmt); |
| 3909 |
} |
| 3910 |
XVECEXP (body, 0, i) = gen_rtx_SET (o, src); |
| 3911 |
} |
| 3912 |
|
| 3913 |
/* If there are no outputs (but there are some clobbers) |
| 3914 |
store the bare ASM_OPERANDS into the PARALLEL. */ |
| 3915 |
if (i == 0) |
| 3916 |
XVECEXP (body, 0, i++) = obody; |
| 3917 |
|
| 3918 |
/* Add the uses specified by the target hook. No checking should |
| 3919 |
be needed since this doesn't come directly from user code. */ |
| 3920 |
for (rtx use : use_rvec) |
| 3921 |
XVECEXP (body, 0, i++) = gen_rtx_USE (VOIDmode, use); |
| 3922 |
|
| 3923 |
/* Store (clobber REG) for each clobbered register specified. */ |
| 3924 |
for (unsigned j = 0; j < nclobbers; ++j) |
| 3925 |
{ |
| 3926 |
rtx clobbered_reg = clobber_rvec[j]; |
| 3927 |
|
| 3928 |
/* Do sanity check for overlap between clobbers and respectively |
| 3929 |
input and outputs that hasn't been handled. Such overlap |
| 3930 |
should have been detected and reported above. */ |
| 3931 |
if (!clobber_conflict_found && REG_P (clobbered_reg)) |
| 3932 |
{ |
| 3933 |
/* We test the old body (obody) contents to avoid |
| 3934 |
tripping over the under-construction body. */ |
| 3935 |
for (unsigned k = 0; k < noutputs; ++k) |
| 3936 |
if (reg_overlap_mentioned_p (clobbered_reg, output_rvec[k])) |
| 3937 |
internal_error ("%<asm%> clobber conflict with " |
| 3938 |
"output operand"); |
| 3939 |
|
| 3940 |
for (unsigned k = 0; k < ninputs - ninout; ++k) |
| 3941 |
if (reg_overlap_mentioned_p (clobbered_reg, input_rvec[k])) |
| 3942 |
internal_error ("%<asm%> clobber conflict with " |
| 3943 |
"input operand"); |
| 3944 |
} |
| 3945 |
|
| 3946 |
XVECEXP (body, 0, i++) = gen_rtx_CLOBBER (VOIDmode, clobbered_reg); |
| 3947 |
} |
| 3948 |
|
| 3949 |
if (nlabels > 0) |
| 3950 |
emit_jump_insn (body); |
| 3951 |
else |
| 3952 |
emit_insn (body); |
| 3953 |
} |
| 3954 |
|
| 3955 |
generating_concat_p = old_generating_concat_p; |
| 3956 |
|
| 3957 |
if (fallthru_label) |
| 3958 |
emit_label (fallthru_label); |
| 3959 |
|
| 3960 |
if (after_rtl_seq) |
| 3961 |
{ |
| 3962 |
if (nlabels == 0) |
| 3963 |
emit_insn (after_rtl_seq); |
| 3964 |
else |
| 3965 |
{ |
| 3966 |
edge e; |
| 3967 |
edge_iterator ei; |
| 3968 |
unsigned int cnt = EDGE_COUNT (gimple_bb (stmt)->succs); |
| 3969 |
|
| 3970 |
FOR_EACH_EDGE (e, ei, gimple_bb (stmt)->succs) |
| 3971 |
{ |
| 3972 |
rtx_insn *copy; |
| 3973 |
if (--cnt == 0) |
| 3974 |
copy = after_rtl_seq; |
| 3975 |
else |
| 3976 |
{ |
| 3977 |
start_sequence (); |
| 3978 |
duplicate_insn_chain (after_rtl_seq, after_rtl_end, |
| 3979 |
NULL, NULL); |
| 3980 |
copy = get_insns (); |
| 3981 |
end_sequence (); |
| 3982 |
} |
| 3983 |
prepend_insn_to_edge (copy, e); |
| 3984 |
} |
| 3985 |
} |
| 3986 |
} |
| 3987 |
|
| 3988 |
free_temp_slots (); |
| 3989 |
crtl->has_asm_statement = 1; |
| 3990 |
} |
| 3991 |
|
| 3992 |
/* Emit code to jump to the address |
| 3993 |
specified by the pointer expression EXP. */ |
| 3994 |
|
| 3995 |
static void |
| 3996 |
expand_computed_goto (tree exp) |
| 3997 |
{ |
| 3998 |
rtx x = expand_normal (exp); |
| 3999 |
|
| 4000 |
do_pending_stack_adjust (); |
| 4001 |
emit_indirect_jump (x); |
| 4002 |
} |
| 4003 |
|
| 4004 |
/* Generate RTL code for a `goto' statement with target label LABEL. |
| 4005 |
LABEL should be a LABEL_DECL tree node that was or will later be |
| 4006 |
defined with `expand_label'. */ |
| 4007 |
|
| 4008 |
static void |
| 4009 |
expand_goto (tree label) |
| 4010 |
{ |
| 4011 |
if (flag_checking) |
| 4012 |
{ |
| 4013 |
/* Check for a nonlocal goto to a containing function. Should have |
| 4014 |
gotten translated to __builtin_nonlocal_goto. */ |
| 4015 |
tree context = decl_function_context (label); |
| 4016 |
gcc_assert (!context || context == current_function_decl); |
| 4017 |
} |
| 4018 |
|
| 4019 |
emit_jump (jump_target_rtx (label)); |
| 4020 |
} |
| 4021 |
|
| 4022 |
/* Output a return with no value. */ |
| 4023 |
|
| 4024 |
static void |
| 4025 |
expand_null_return_1 (void) |
| 4026 |
{ |
| 4027 |
clear_pending_stack_adjust (); |
| 4028 |
do_pending_stack_adjust (); |
| 4029 |
emit_jump (return_label); |
| 4030 |
} |
| 4031 |
|
| 4032 |
/* Generate RTL to return from the current function, with no value. |
| 4033 |
(That is, we do not do anything about returning any value.) */ |
| 4034 |
|
| 4035 |
void |
| 4036 |
expand_null_return (void) |
| 4037 |
{ |
| 4038 |
/* If this function was declared to return a value, but we |
| 4039 |
didn't, clobber the return registers so that they are not |
| 4040 |
propagated live to the rest of the function. */ |
| 4041 |
clobber_return_register (); |
| 4042 |
|
| 4043 |
expand_null_return_1 (); |
| 4044 |
} |
| 4045 |
|
| 4046 |
/* Generate RTL to return from the current function, with value VAL. */ |
| 4047 |
|
| 4048 |
static void |
| 4049 |
expand_value_return (rtx val) |
| 4050 |
{ |
| 4051 |
/* Copy the value to the return location unless it's already there. */ |
| 4052 |
|
| 4053 |
tree decl = DECL_RESULT (current_function_decl); |
| 4054 |
rtx return_reg = DECL_RTL (decl); |
| 4055 |
if (return_reg != val) |
| 4056 |
{ |
| 4057 |
tree funtype = TREE_TYPE (current_function_decl); |
| 4058 |
tree type = TREE_TYPE (decl); |
| 4059 |
int unsignedp = TYPE_UNSIGNED (type); |
| 4060 |
machine_mode old_mode = DECL_MODE (decl); |
| 4061 |
machine_mode mode; |
| 4062 |
if (DECL_BY_REFERENCE (decl)) |
| 4063 |
mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 2); |
| 4064 |
else |
| 4065 |
mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 1); |
| 4066 |
|
| 4067 |
if (mode != old_mode) |
| 4068 |
{ |
| 4069 |
/* Some ABIs require scalar floating point modes to be returned |
| 4070 |
in a wider scalar integer mode. We need to explicitly |
| 4071 |
reinterpret to an integer mode of the correct precision |
| 4072 |
before extending to the desired result. */ |
| 4073 |
if (SCALAR_INT_MODE_P (mode) |
| 4074 |
&& SCALAR_FLOAT_MODE_P (old_mode) |
| 4075 |
&& known_gt (GET_MODE_SIZE (mode), GET_MODE_SIZE (old_mode))) |
| 4076 |
val = convert_float_to_wider_int (mode, old_mode, val); |
| 4077 |
else |
| 4078 |
val = convert_modes (mode, old_mode, val, unsignedp); |
| 4079 |
} |
| 4080 |
|
| 4081 |
if (GET_CODE (return_reg) == PARALLEL) |
| 4082 |
emit_group_load (return_reg, val, type, int_size_in_bytes (type)); |
| 4083 |
else |
| 4084 |
emit_move_insn (return_reg, val); |
| 4085 |
} |
| 4086 |
|
| 4087 |
expand_null_return_1 (); |
| 4088 |
} |
| 4089 |
|
| 4090 |
/* Generate RTL to evaluate the expression RETVAL and return it |
| 4091 |
from the current function. */ |
| 4092 |
|
| 4093 |
static void |
| 4094 |
expand_return (tree retval) |
| 4095 |
{ |
| 4096 |
rtx result_rtl; |
| 4097 |
rtx val = 0; |
| 4098 |
tree retval_rhs; |
| 4099 |
|
| 4100 |
/* If function wants no value, give it none. */ |
| 4101 |
if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl)))) |
| 4102 |
{ |
| 4103 |
expand_normal (retval); |
| 4104 |
expand_null_return (); |
| 4105 |
return; |
| 4106 |
} |
| 4107 |
|
| 4108 |
if (retval == error_mark_node) |
| 4109 |
{ |
| 4110 |
/* Treat this like a return of no value from a function that |
| 4111 |
returns a value. */ |
| 4112 |
expand_null_return (); |
| 4113 |
return; |
| 4114 |
} |
| 4115 |
else if ((TREE_CODE (retval) == MODIFY_EXPR |
| 4116 |
|| TREE_CODE (retval) == INIT_EXPR) |
| 4117 |
&& TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL) |
| 4118 |
retval_rhs = TREE_OPERAND (retval, 1); |
| 4119 |
else |
| 4120 |
retval_rhs = retval; |
| 4121 |
|
| 4122 |
result_rtl = DECL_RTL (DECL_RESULT (current_function_decl)); |
| 4123 |
|
| 4124 |
/* If we are returning the RESULT_DECL, then the value has already |
| 4125 |
been stored into it, so we don't have to do anything special. */ |
| 4126 |
if (TREE_CODE (retval_rhs) == RESULT_DECL) |
| 4127 |
expand_value_return (result_rtl); |
| 4128 |
|
| 4129 |
/* If the result is an aggregate that is being returned in one (or more) |
| 4130 |
registers, load the registers here. */ |
| 4131 |
|
| 4132 |
else if (retval_rhs != 0 |
| 4133 |
&& TYPE_MODE (TREE_TYPE (retval_rhs)) == BLKmode |
| 4134 |
&& REG_P (result_rtl)) |
| 4135 |
{ |
| 4136 |
val = copy_blkmode_to_reg (GET_MODE (result_rtl), retval_rhs); |
| 4137 |
if (val) |
| 4138 |
{ |
| 4139 |
/* Use the mode of the result value on the return register. */ |
| 4140 |
PUT_MODE (result_rtl, GET_MODE (val)); |
| 4141 |
expand_value_return (val); |
| 4142 |
} |
| 4143 |
else |
| 4144 |
expand_null_return (); |
| 4145 |
} |
| 4146 |
else if (retval_rhs != 0 |
| 4147 |
&& !VOID_TYPE_P (TREE_TYPE (retval_rhs)) |
| 4148 |
&& (REG_P (result_rtl) |
| 4149 |
|| (GET_CODE (result_rtl) == PARALLEL))) |
| 4150 |
{ |
| 4151 |
/* Compute the return value into a temporary (usually a pseudo reg). */ |
| 4152 |
val |
| 4153 |
= assign_temp (TREE_TYPE (DECL_RESULT (current_function_decl)), 0, 1); |
| 4154 |
val = expand_expr (retval_rhs, val, GET_MODE (val), EXPAND_NORMAL); |
| 4155 |
val = force_not_mem (val); |
| 4156 |
expand_value_return (val); |
| 4157 |
} |
| 4158 |
else |
| 4159 |
{ |
| 4160 |
/* No hard reg used; calculate value into hard return reg. */ |
| 4161 |
expand_expr (retval, const0_rtx, VOIDmode, EXPAND_NORMAL); |
| 4162 |
expand_value_return (result_rtl); |
| 4163 |
} |
| 4164 |
} |
| 4165 |
|
| 4166 |
/* Expand a clobber of LHS. If LHS is stored it in a multi-part |
| 4167 |
register, tell the rtl optimizers that its value is no longer |
| 4168 |
needed. */ |
| 4169 |
|
| 4170 |
static void |
| 4171 |
expand_clobber (tree lhs) |
| 4172 |
{ |
| 4173 |
if (DECL_P (lhs)) |
| 4174 |
{ |
| 4175 |
rtx decl_rtl = DECL_RTL_IF_SET (lhs); |
| 4176 |
if (decl_rtl && REG_P (decl_rtl)) |
| 4177 |
{ |
| 4178 |
machine_mode decl_mode = GET_MODE (decl_rtl); |
| 4179 |
if (maybe_gt (GET_MODE_SIZE (decl_mode), |
| 4180 |
REGMODE_NATURAL_SIZE (decl_mode))) |
| 4181 |
emit_clobber (decl_rtl); |
| 4182 |
} |
| 4183 |
} |
| 4184 |
} |
| 4185 |
|
| 4186 |
/* A subroutine of expand_gimple_stmt, expanding one gimple statement |
| 4187 |
STMT that doesn't require special handling for outgoing edges. That |
| 4188 |
is no tailcalls and no GIMPLE_COND. */ |
| 4189 |
|
| 4190 |
static void |
| 4191 |
expand_gimple_stmt_1 (gimple *stmt) |
| 4192 |
{ |
| 4193 |
tree op0; |
| 4194 |
|
| 4195 |
set_curr_insn_location (gimple_location (stmt)); |
| 4196 |
|
| 4197 |
switch (gimple_code (stmt)) |
| 4198 |
{ |
| 4199 |
case GIMPLE_GOTO: |
| 4200 |
op0 = gimple_goto_dest (stmt); |
| 4201 |
if (TREE_CODE (op0) == LABEL_DECL) |
| 4202 |
expand_goto (op0); |
| 4203 |
else |
| 4204 |
expand_computed_goto (op0); |
| 4205 |
break; |
| 4206 |
case GIMPLE_LABEL: |
| 4207 |
expand_label (gimple_label_label (as_a <glabel *> (stmt))); |
| 4208 |
break; |
| 4209 |
case GIMPLE_NOP: |
| 4210 |
case GIMPLE_PREDICT: |
| 4211 |
break; |
| 4212 |
case GIMPLE_SWITCH: |
| 4213 |
{ |
| 4214 |
gswitch *swtch = as_a <gswitch *> (stmt); |
| 4215 |
if (gimple_switch_num_labels (swtch) == 1) |
| 4216 |
expand_goto (CASE_LABEL (gimple_switch_default_label (swtch))); |
| 4217 |
else |
| 4218 |
expand_case (swtch); |
| 4219 |
} |
| 4220 |
break; |
| 4221 |
case GIMPLE_ASM: |
| 4222 |
expand_asm_stmt (as_a <gasm *> (stmt)); |
| 4223 |
break; |
| 4224 |
case GIMPLE_CALL: |
| 4225 |
expand_call_stmt (as_a <gcall *> (stmt)); |
| 4226 |
break; |
| 4227 |
|
| 4228 |
case GIMPLE_RETURN: |
| 4229 |
{ |
| 4230 |
op0 = gimple_return_retval (as_a <greturn *> (stmt)); |
| 4231 |
|
| 4232 |
/* If a return doesn't have a location, it very likely represents |
| 4233 |
multiple user returns so we cannot let it inherit the location |
| 4234 |
of the last statement of the previous basic block in RTL. */ |
| 4235 |
if (!gimple_has_location (stmt)) |
| 4236 |
set_curr_insn_location (cfun->function_end_locus); |
| 4237 |
|
| 4238 |
if (op0 && op0 != error_mark_node) |
| 4239 |
{ |
| 4240 |
tree result = DECL_RESULT (current_function_decl); |
| 4241 |
|
| 4242 |
/* If we are not returning the current function's RESULT_DECL, |
| 4243 |
build an assignment to it. */ |
| 4244 |
if (op0 != result) |
| 4245 |
{ |
| 4246 |
/* I believe that a function's RESULT_DECL is unique. */ |
| 4247 |
gcc_assert (TREE_CODE (op0) != RESULT_DECL); |
| 4248 |
|
| 4249 |
/* ??? We'd like to use simply expand_assignment here, |
| 4250 |
but this fails if the value is of BLKmode but the return |
| 4251 |
decl is a register. expand_return has special handling |
| 4252 |
for this combination, which eventually should move |
| 4253 |
to common code. See comments there. Until then, let's |
| 4254 |
build a modify expression :-/ */ |
| 4255 |
op0 = build2 (MODIFY_EXPR, TREE_TYPE (result), |
| 4256 |
result, op0); |
| 4257 |
} |
| 4258 |
} |
| 4259 |
|
| 4260 |
if (!op0) |
| 4261 |
expand_null_return (); |
| 4262 |
else |
| 4263 |
expand_return (op0); |
| 4264 |
} |
| 4265 |
break; |
| 4266 |
|
| 4267 |
case GIMPLE_ASSIGN: |
| 4268 |
{ |
| 4269 |
gassign *assign_stmt = as_a <gassign *> (stmt); |
| 4270 |
tree lhs = gimple_assign_lhs (assign_stmt); |
| 4271 |
|
| 4272 |
/* Tree expand used to fiddle with |= and &= of two bitfield |
| 4273 |
COMPONENT_REFs here. This can't happen with gimple, the LHS |
| 4274 |
of binary assigns must be a gimple reg. */ |
| 4275 |
|
| 4276 |
if (TREE_CODE (lhs) != SSA_NAME |
| 4277 |
|| gimple_assign_rhs_class (assign_stmt) == GIMPLE_SINGLE_RHS) |
| 4278 |
{ |
| 4279 |
tree rhs = gimple_assign_rhs1 (assign_stmt); |
| 4280 |
gcc_assert (gimple_assign_rhs_class (assign_stmt) |
| 4281 |
== GIMPLE_SINGLE_RHS); |
| 4282 |
if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (rhs) |
| 4283 |
/* Do not put locations on possibly shared trees. */ |
| 4284 |
&& !is_gimple_min_invariant (rhs)) |
| 4285 |
SET_EXPR_LOCATION (rhs, gimple_location (stmt)); |
| 4286 |
if (TREE_CLOBBER_P (rhs)) |
| 4287 |
/* This is a clobber to mark the going out of scope for |
| 4288 |
this LHS. */ |
| 4289 |
expand_clobber (lhs); |
| 4290 |
else |
| 4291 |
expand_assignment (lhs, rhs, |
| 4292 |
gimple_assign_nontemporal_move_p ( |
| 4293 |
assign_stmt)); |
| 4294 |
} |
| 4295 |
else |
| 4296 |
{ |
| 4297 |
rtx target, temp; |
| 4298 |
gcc_assert (!gimple_assign_nontemporal_move_p (assign_stmt)); |
| 4299 |
bool promoted = false; |
| 4300 |
|
| 4301 |
target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE); |
| 4302 |
if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target)) |
| 4303 |
promoted = true; |
| 4304 |
|
| 4305 |
/* If we store into a promoted register, don't directly |
| 4306 |
expand to target. */ |
| 4307 |
temp = promoted ? NULL_RTX : target; |
| 4308 |
temp = expand_expr_real_gassign (assign_stmt, temp, |
| 4309 |
GET_MODE (target), EXPAND_NORMAL); |
| 4310 |
|
| 4311 |
if (temp == target) |
| 4312 |
; |
| 4313 |
else if (promoted) |
| 4314 |
{ |
| 4315 |
int unsignedp = SUBREG_PROMOTED_SIGN (target); |
| 4316 |
/* If TEMP is a VOIDmode constant, use convert_modes to make |
| 4317 |
sure that we properly convert it. */ |
| 4318 |
if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode) |
| 4319 |
{ |
| 4320 |
temp = convert_modes (GET_MODE (target), |
| 4321 |
TYPE_MODE (TREE_TYPE (lhs)), |
| 4322 |
temp, unsignedp); |
| 4323 |
temp = convert_modes (GET_MODE (SUBREG_REG (target)), |
| 4324 |
GET_MODE (target), temp, unsignedp); |
| 4325 |
} |
| 4326 |
|
| 4327 |
convert_move (SUBREG_REG (target), temp, unsignedp); |
| 4328 |
} |
| 4329 |
else |
| 4330 |
{ |
| 4331 |
temp = force_operand (temp, target); |
| 4332 |
if (temp == target) |
| 4333 |
; |
| 4334 |
else if (GET_MODE (target) != BLKmode) |
| 4335 |
emit_move_insn (target, temp); |
| 4336 |
else |
| 4337 |
emit_block_move (target, temp, expr_size (lhs), |
| 4338 |
BLOCK_OP_NORMAL); |
| 4339 |
} |
| 4340 |
} |
| 4341 |
} |
| 4342 |
break; |
| 4343 |
|
| 4344 |
default: |
| 4345 |
gcc_unreachable (); |
| 4346 |
} |
| 4347 |
} |
| 4348 |
|
| 4349 |
/* Expand one gimple statement STMT and return the last RTL instruction |
| 4350 |
before any of the newly generated ones. |
| 4351 |
|
| 4352 |
In addition to generating the necessary RTL instructions this also |
| 4353 |
sets REG_EH_REGION notes if necessary and sets the current source |
| 4354 |
location for diagnostics. */ |
| 4355 |
|
| 4356 |
static rtx_insn * |
| 4357 |
expand_gimple_stmt (gimple *stmt) |
| 4358 |
{ |
| 4359 |
location_t saved_location = input_location; |
| 4360 |
rtx_insn *last = get_last_insn (); |
| 4361 |
int lp_nr; |
| 4362 |
|
| 4363 |
gcc_assert (cfun); |
| 4364 |
|
| 4365 |
/* We need to save and restore the current source location so that errors |
| 4366 |
discovered during expansion are emitted with the right location. But |
| 4367 |
it would be better if the diagnostic routines used the source location |
| 4368 |
embedded in the tree nodes rather than globals. */ |
| 4369 |
if (gimple_has_location (stmt)) |
| 4370 |
input_location = gimple_location (stmt); |
| 4371 |
|
| 4372 |
expand_gimple_stmt_1 (stmt); |
| 4373 |
|
| 4374 |
/* Free any temporaries used to evaluate this statement. */ |
| 4375 |
free_temp_slots (); |
| 4376 |
|
| 4377 |
input_location = saved_location; |
| 4378 |
|
| 4379 |
/* Mark all insns that may trap. */ |
| 4380 |
lp_nr = lookup_stmt_eh_lp (stmt); |
| 4381 |
if (lp_nr) |
| 4382 |
{ |
| 4383 |
rtx_insn *insn; |
| 4384 |
for (insn = next_real_insn (last); insn; |
| 4385 |
insn = next_real_insn (insn)) |
| 4386 |
{ |
| 4387 |
if (! find_reg_note (insn, REG_EH_REGION, NULL_RTX) |
| 4388 |
/* If we want exceptions for non-call insns, any |
| 4389 |
may_trap_p instruction may throw. */ |
| 4390 |
&& GET_CODE (PATTERN (insn)) != CLOBBER |
| 4391 |
&& GET_CODE (PATTERN (insn)) != USE |
| 4392 |
&& insn_could_throw_p (insn)) |
| 4393 |
make_reg_eh_region_note (insn, 0, lp_nr); |
| 4394 |
} |
| 4395 |
} |
| 4396 |
|
| 4397 |
return last; |
| 4398 |
} |
| 4399 |
|
| 4400 |
/* A subroutine of expand_gimple_basic_block. Expand one GIMPLE_CALL |
| 4401 |
that has CALL_EXPR_TAILCALL set. Returns non-null if we actually |
| 4402 |
generated a tail call (something that might be denied by the ABI |
| 4403 |
rules governing the call; see calls.cc). |
| 4404 |
|
| 4405 |
Sets CAN_FALLTHRU if we generated a *conditional* tail call, and |
| 4406 |
can still reach the rest of BB. The case here is __builtin_sqrt, |
| 4407 |
where the NaN result goes through the external function (with a |
| 4408 |
tailcall) and the normal result happens via a sqrt instruction. */ |
| 4409 |
|
| 4410 |
static basic_block |
| 4411 |
expand_gimple_tailcall (basic_block bb, gcall *stmt, bool *can_fallthru, |
| 4412 |
rtx_insn *asan_epilog_seq) |
| 4413 |
{ |
| 4414 |
rtx_insn *last2, *last, *first = get_last_insn (); |
| 4415 |
edge e; |
| 4416 |
edge_iterator ei; |
| 4417 |
profile_probability probability; |
| 4418 |
|
| 4419 |
last2 = last = expand_gimple_stmt (stmt); |
| 4420 |
|
| 4421 |
for (last = NEXT_INSN (last); last; last = NEXT_INSN (last)) |
| 4422 |
if (CALL_P (last) && SIBLING_CALL_P (last)) |
| 4423 |
goto found; |
| 4424 |
|
| 4425 |
maybe_dump_rtl_for_gimple_stmt (stmt, last2); |
| 4426 |
|
| 4427 |
*can_fallthru = true; |
| 4428 |
return NULL; |
| 4429 |
|
| 4430 |
found: |
| 4431 |
|
| 4432 |
if (asan_epilog_seq) |
| 4433 |
{ |
| 4434 |
/* We need to emit a copy of the asan_epilog_seq before |
| 4435 |
the insns emitted by expand_gimple_stmt above. The sequence |
| 4436 |
can contain labels, which need to be remapped. */ |
| 4437 |
hash_map<rtx, rtx> label_map; |
| 4438 |
start_sequence (); |
| 4439 |
emit_note (NOTE_INSN_DELETED); |
| 4440 |
for (rtx_insn *insn = asan_epilog_seq; insn; insn = NEXT_INSN (insn)) |
| 4441 |
switch (GET_CODE (insn)) |
| 4442 |
{ |
| 4443 |
case INSN: |
| 4444 |
case CALL_INSN: |
| 4445 |
case JUMP_INSN: |
| 4446 |
emit_copy_of_insn_after (insn, get_last_insn ()); |
| 4447 |
break; |
| 4448 |
case CODE_LABEL: |
| 4449 |
label_map.put ((rtx) insn, (rtx) emit_label (gen_label_rtx ())); |
| 4450 |
break; |
| 4451 |
case BARRIER: |
| 4452 |
emit_barrier (); |
| 4453 |
break; |
| 4454 |
default: |
| 4455 |
gcc_unreachable (); |
| 4456 |
} |
| 4457 |
for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
| 4458 |
if (JUMP_P (insn)) |
| 4459 |
{ |
| 4460 |
subrtx_ptr_iterator::array_type array; |
| 4461 |
FOR_EACH_SUBRTX_PTR (iter, array, &PATTERN (insn), ALL) |
| 4462 |
{ |
| 4463 |
rtx *loc = *iter; |
| 4464 |
if (LABEL_REF_P (*loc)) |
| 4465 |
{ |
| 4466 |
rtx *lab = label_map.get ((rtx) label_ref_label (*loc)); |
| 4467 |
gcc_assert (lab); |
| 4468 |
set_label_ref_label (*loc, as_a <rtx_insn *> (*lab)); |
| 4469 |
} |
| 4470 |
} |
| 4471 |
if (JUMP_LABEL (insn)) |
| 4472 |
{ |
| 4473 |
rtx *lab = label_map.get (JUMP_LABEL (insn)); |
| 4474 |
gcc_assert (lab); |
| 4475 |
JUMP_LABEL (insn) = *lab; |
| 4476 |
} |
| 4477 |
} |
| 4478 |
asan_epilog_seq = NEXT_INSN (get_insns ()); |
| 4479 |
end_sequence (); |
| 4480 |
emit_insn_before (asan_epilog_seq, NEXT_INSN (first)); |
| 4481 |
} |
| 4482 |
|
| 4483 |
/* ??? Wouldn't it be better to just reset any pending stack adjust? |
| 4484 |
Any instructions emitted here are about to be deleted. */ |
| 4485 |
do_pending_stack_adjust (); |
| 4486 |
|
| 4487 |
/* Remove any non-eh, non-abnormal edges that don't go to exit. */ |
| 4488 |
/* ??? I.e. the fallthrough edge. HOWEVER! If there were to be |
| 4489 |
EH or abnormal edges, we shouldn't have created a tail call in |
| 4490 |
the first place. So it seems to me we should just be removing |
| 4491 |
all edges here, or redirecting the existing fallthru edge to |
| 4492 |
the exit block. */ |
| 4493 |
|
| 4494 |
probability = profile_probability::never (); |
| 4495 |
|
| 4496 |
for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); ) |
| 4497 |
{ |
| 4498 |
if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH))) |
| 4499 |
{ |
| 4500 |
if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)) |
| 4501 |
e->dest->count -= e->count (); |
| 4502 |
probability += e->probability; |
| 4503 |
remove_edge (e); |
| 4504 |
} |
| 4505 |
else |
| 4506 |
ei_next (&ei); |
| 4507 |
} |
| 4508 |
|
| 4509 |
/* This is somewhat ugly: the call_expr expander often emits instructions |
| 4510 |
after the sibcall (to perform the function return). These confuse the |
| 4511 |
find_many_sub_basic_blocks code, so we need to get rid of these. */ |
| 4512 |
last = NEXT_INSN (last); |
| 4513 |
gcc_assert (BARRIER_P (last)); |
| 4514 |
|
| 4515 |
*can_fallthru = false; |
| 4516 |
while (NEXT_INSN (last)) |
| 4517 |
{ |
| 4518 |
/* For instance an sqrt builtin expander expands if with |
| 4519 |
sibcall in the then and label for `else`. */ |
| 4520 |
if (LABEL_P (NEXT_INSN (last))) |
| 4521 |
{ |
| 4522 |
*can_fallthru = true; |
| 4523 |
break; |
| 4524 |
} |
| 4525 |
delete_insn (NEXT_INSN (last)); |
| 4526 |
} |
| 4527 |
|
| 4528 |
e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), EDGE_ABNORMAL |
| 4529 |
| EDGE_SIBCALL); |
| 4530 |
e->probability = probability; |
| 4531 |
BB_END (bb) = last; |
| 4532 |
update_bb_for_insn (bb); |
| 4533 |
|
| 4534 |
if (NEXT_INSN (last)) |
| 4535 |
{ |
| 4536 |
bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb); |
| 4537 |
|
| 4538 |
last = BB_END (bb); |
| 4539 |
if (BARRIER_P (last)) |
| 4540 |
BB_END (bb) = PREV_INSN (last); |
| 4541 |
} |
| 4542 |
|
| 4543 |
maybe_dump_rtl_for_gimple_stmt (stmt, last2); |
| 4544 |
|
| 4545 |
return bb; |
| 4546 |
} |
| 4547 |
|
| 4548 |
/* Return the difference between the floor and the truncated result of |
| 4549 |
a signed division by OP1 with remainder MOD. */ |
| 4550 |
static rtx |
| 4551 |
floor_sdiv_adjust (machine_mode mode, rtx mod, rtx op1) |
| 4552 |
{ |
| 4553 |
/* (mod != 0 ? (op1 / mod < 0 ? -1 : 0) : 0) */ |
| 4554 |
return gen_rtx_IF_THEN_ELSE |
| 4555 |
(mode, gen_rtx_NE (BImode, mod, const0_rtx), |
| 4556 |
gen_rtx_IF_THEN_ELSE |
| 4557 |
(mode, gen_rtx_LT (BImode, |
| 4558 |
gen_rtx_DIV (mode, op1, mod), |
| 4559 |
const0_rtx), |
| 4560 |
constm1_rtx, const0_rtx), |
| 4561 |
const0_rtx); |
| 4562 |
} |
| 4563 |
|
| 4564 |
/* Return the difference between the ceil and the truncated result of |
| 4565 |
a signed division by OP1 with remainder MOD. */ |
| 4566 |
static rtx |
| 4567 |
ceil_sdiv_adjust (machine_mode mode, rtx mod, rtx op1) |
| 4568 |
{ |
| 4569 |
/* (mod != 0 ? (op1 / mod > 0 ? 1 : 0) : 0) */ |
| 4570 |
return gen_rtx_IF_THEN_ELSE |
| 4571 |
(mode, gen_rtx_NE (BImode, mod, const0_rtx), |
| 4572 |
gen_rtx_IF_THEN_ELSE |
| 4573 |
(mode, gen_rtx_GT (BImode, |
| 4574 |
gen_rtx_DIV (mode, op1, mod), |
| 4575 |
const0_rtx), |
| 4576 |
const1_rtx, const0_rtx), |
| 4577 |
const0_rtx); |
| 4578 |
} |
| 4579 |
|
| 4580 |
/* Return the difference between the ceil and the truncated result of |
| 4581 |
an unsigned division by OP1 with remainder MOD. */ |
| 4582 |
static rtx |
| 4583 |
ceil_udiv_adjust (machine_mode mode, rtx mod, rtx op1 ATTRIBUTE_UNUSED) |
| 4584 |
{ |
| 4585 |
/* (mod != 0 ? 1 : 0) */ |
| 4586 |
return gen_rtx_IF_THEN_ELSE |
| 4587 |
(mode, gen_rtx_NE (BImode, mod, const0_rtx), |
| 4588 |
const1_rtx, const0_rtx); |
| 4589 |
} |
| 4590 |
|
| 4591 |
/* Return the difference between the rounded and the truncated result |
| 4592 |
of a signed division by OP1 with remainder MOD. Halfway cases are |
| 4593 |
rounded away from zero, rather than to the nearest even number. */ |
| 4594 |
static rtx |
| 4595 |
round_sdiv_adjust (machine_mode mode, rtx mod, rtx op1) |
| 4596 |
{ |
| 4597 |
/* (abs (mod) >= abs (op1) - abs (mod) |
| 4598 |
? (op1 / mod > 0 ? 1 : -1) |
| 4599 |
: 0) */ |
| 4600 |
return gen_rtx_IF_THEN_ELSE |
| 4601 |
(mode, gen_rtx_GE (BImode, gen_rtx_ABS (mode, mod), |
| 4602 |
gen_rtx_MINUS (mode, |
| 4603 |
gen_rtx_ABS (mode, op1), |
| 4604 |
gen_rtx_ABS (mode, mod))), |
| 4605 |
gen_rtx_IF_THEN_ELSE |
| 4606 |
(mode, gen_rtx_GT (BImode, |
| 4607 |
gen_rtx_DIV (mode, op1, mod), |
| 4608 |
const0_rtx), |
| 4609 |
const1_rtx, constm1_rtx), |
| 4610 |
const0_rtx); |
| 4611 |
} |
| 4612 |
|
| 4613 |
/* Return the difference between the rounded and the truncated result |
| 4614 |
of a unsigned division by OP1 with remainder MOD. Halfway cases |
| 4615 |
are rounded away from zero, rather than to the nearest even |
| 4616 |
number. */ |
| 4617 |
static rtx |
| 4618 |
round_udiv_adjust (machine_mode mode, rtx mod, rtx op1) |
| 4619 |
{ |
| 4620 |
/* (mod >= op1 - mod ? 1 : 0) */ |
| 4621 |
return gen_rtx_IF_THEN_ELSE |
| 4622 |
(mode, gen_rtx_GE (BImode, mod, |
| 4623 |
gen_rtx_MINUS (mode, op1, mod)), |
| 4624 |
const1_rtx, const0_rtx); |
| 4625 |
} |
| 4626 |
|
| 4627 |
/* Convert X to MODE, that must be Pmode or ptr_mode, without emitting |
| 4628 |
any rtl. */ |
| 4629 |
|
| 4630 |
static rtx |
| 4631 |
convert_debug_memory_address (scalar_int_mode mode, rtx x, |
| 4632 |
addr_space_t as) |
| 4633 |
{ |
| 4634 |
#ifndef POINTERS_EXTEND_UNSIGNED |
| 4635 |
gcc_assert (mode == Pmode |
| 4636 |
|| mode == targetm.addr_space.address_mode (as)); |
| 4637 |
gcc_assert (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode); |
| 4638 |
#else |
| 4639 |
rtx temp; |
| 4640 |
|
| 4641 |
gcc_assert (targetm.addr_space.valid_pointer_mode (mode, as)); |
| 4642 |
|
| 4643 |
if (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode) |
| 4644 |
return x; |
| 4645 |
|
| 4646 |
/* X must have some form of address mode already. */ |
| 4647 |
scalar_int_mode xmode = as_a <scalar_int_mode> (GET_MODE (x)); |
| 4648 |
if (GET_MODE_PRECISION (mode) < GET_MODE_PRECISION (xmode)) |
| 4649 |
x = lowpart_subreg (mode, x, xmode); |
| 4650 |
else if (POINTERS_EXTEND_UNSIGNED > 0) |
| 4651 |
x = gen_rtx_ZERO_EXTEND (mode, x); |
| 4652 |
else if (!POINTERS_EXTEND_UNSIGNED) |
| 4653 |
x = gen_rtx_SIGN_EXTEND (mode, x); |
| 4654 |
else |
| 4655 |
{ |
| 4656 |
switch (GET_CODE (x)) |
| 4657 |
{ |
| 4658 |
case SUBREG: |
| 4659 |
if ((SUBREG_PROMOTED_VAR_P (x) |
| 4660 |
|| (REG_P (SUBREG_REG (x)) && REG_POINTER (SUBREG_REG (x))) |
| 4661 |
|| (GET_CODE (SUBREG_REG (x)) == PLUS |
| 4662 |
&& REG_P (XEXP (SUBREG_REG (x), 0)) |
| 4663 |
&& REG_POINTER (XEXP (SUBREG_REG (x), 0)) |
| 4664 |
&& CONST_INT_P (XEXP (SUBREG_REG (x), 1)))) |
| 4665 |
&& GET_MODE (SUBREG_REG (x)) == mode) |
| 4666 |
return SUBREG_REG (x); |
| 4667 |
break; |
| 4668 |
case LABEL_REF: |
| 4669 |
temp = gen_rtx_LABEL_REF (mode, label_ref_label (x)); |
| 4670 |
LABEL_REF_NONLOCAL_P (temp) = LABEL_REF_NONLOCAL_P (x); |
| 4671 |
return temp; |
| 4672 |
case SYMBOL_REF: |
| 4673 |
temp = shallow_copy_rtx (x); |
| 4674 |
PUT_MODE (temp, mode); |
| 4675 |
return temp; |
| 4676 |
case CONST: |
| 4677 |
temp = convert_debug_memory_address (mode, XEXP (x, 0), as); |
| 4678 |
if (temp) |
| 4679 |
temp = gen_rtx_CONST (mode, temp); |
| 4680 |
return temp; |
| 4681 |
case PLUS: |
| 4682 |
case MINUS: |
| 4683 |
if (CONST_INT_P (XEXP (x, 1))) |
| 4684 |
{ |
| 4685 |
temp = convert_debug_memory_address (mode, XEXP (x, 0), as); |
| 4686 |
if (temp) |
| 4687 |
return gen_rtx_fmt_ee (GET_CODE (x), mode, temp, XEXP (x, 1)); |
| 4688 |
} |
| 4689 |
break; |
| 4690 |
default: |
| 4691 |
break; |
| 4692 |
} |
| 4693 |
/* Don't know how to express ptr_extend as operation in debug info. */ |
| 4694 |
return NULL; |
| 4695 |
} |
| 4696 |
#endif /* POINTERS_EXTEND_UNSIGNED */ |
| 4697 |
|
| 4698 |
return x; |
| 4699 |
} |
| 4700 |
|
| 4701 |
/* Map from SSA_NAMEs to corresponding DEBUG_EXPR_DECLs created |
| 4702 |
by avoid_deep_ter_for_debug. */ |
| 4703 |
|
| 4704 |
static hash_map<tree, tree> *deep_ter_debug_map; |
| 4705 |
|
| 4706 |
/* Split too deep TER chains for debug stmts using debug temporaries. */ |
| 4707 |
|
| 4708 |
static void |
| 4709 |
avoid_deep_ter_for_debug (gimple *stmt, int depth) |
| 4710 |
{ |
| 4711 |
use_operand_p use_p; |
| 4712 |
ssa_op_iter iter; |
| 4713 |
FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE) |
| 4714 |
{ |
| 4715 |
tree use = USE_FROM_PTR (use_p); |
| 4716 |
if (TREE_CODE (use) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (use)) |
| 4717 |
continue; |
| 4718 |
gimple *g = get_gimple_for_ssa_name (use); |
| 4719 |
if (g == NULL) |
| 4720 |
continue; |
| 4721 |
if ((depth > 6 || !is_gimple_assign (g)) && !stmt_ends_bb_p (g)) |
| 4722 |
{ |
| 4723 |
if (deep_ter_debug_map == NULL) |
| 4724 |
deep_ter_debug_map = new hash_map<tree, tree>; |
| 4725 |
|
| 4726 |
tree &vexpr = deep_ter_debug_map->get_or_insert (use); |
| 4727 |
if (vexpr != NULL) |
| 4728 |
continue; |
| 4729 |
vexpr = build_debug_expr_decl (TREE_TYPE (use)); |
| 4730 |
gimple *def_temp = gimple_build_debug_bind (vexpr, use, g); |
| 4731 |
gimple_stmt_iterator gsi = gsi_for_stmt (g); |
| 4732 |
gsi_insert_after (&gsi, def_temp, GSI_NEW_STMT); |
| 4733 |
avoid_deep_ter_for_debug (def_temp, 0); |
| 4734 |
} |
| 4735 |
else |
| 4736 |
avoid_deep_ter_for_debug (g, depth + 1); |
| 4737 |
} |
| 4738 |
} |
| 4739 |
|
| 4740 |
/* Return an RTX equivalent to the value of the parameter DECL. */ |
| 4741 |
|
| 4742 |
static rtx |
| 4743 |
expand_debug_parm_decl (tree decl) |
| 4744 |
{ |
| 4745 |
rtx incoming = DECL_INCOMING_RTL (decl); |
| 4746 |
|
| 4747 |
if (incoming |
| 4748 |
&& GET_MODE (incoming) != BLKmode |
| 4749 |
&& ((REG_P (incoming) && HARD_REGISTER_P (incoming)) |
| 4750 |
|| (MEM_P (incoming) |
| 4751 |
&& REG_P (XEXP (incoming, 0)) |
| 4752 |
&& HARD_REGISTER_P (XEXP (incoming, 0))))) |
| 4753 |
{ |
| 4754 |
rtx rtl = gen_rtx_ENTRY_VALUE (GET_MODE (incoming)); |
| 4755 |
|
| 4756 |
#ifdef HAVE_window_save |
| 4757 |
/* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers. |
| 4758 |
If the target machine has an explicit window save instruction, the |
| 4759 |
actual entry value is the corresponding OUTGOING_REGNO instead. */ |
| 4760 |
if (REG_P (incoming) |
| 4761 |
&& OUTGOING_REGNO (REGNO (incoming)) != REGNO (incoming)) |
| 4762 |
incoming |
| 4763 |
= gen_rtx_REG_offset (incoming, GET_MODE (incoming), |
| 4764 |
OUTGOING_REGNO (REGNO (incoming)), 0); |
| 4765 |
else if (MEM_P (incoming)) |
| 4766 |
{ |
| 4767 |
rtx reg = XEXP (incoming, 0); |
| 4768 |
if (OUTGOING_REGNO (REGNO (reg)) != REGNO (reg)) |
| 4769 |
{ |
| 4770 |
reg = gen_raw_REG (GET_MODE (reg), OUTGOING_REGNO (REGNO (reg))); |
| 4771 |
incoming = replace_equiv_address_nv (incoming, reg); |
| 4772 |
} |
| 4773 |
else |
| 4774 |
incoming = copy_rtx (incoming); |
| 4775 |
} |
| 4776 |
#endif |
| 4777 |
|
| 4778 |
ENTRY_VALUE_EXP (rtl) = incoming; |
| 4779 |
return rtl; |
| 4780 |
} |
| 4781 |
|
| 4782 |
if (incoming |
| 4783 |
&& GET_MODE (incoming) != BLKmode |
| 4784 |
&& !TREE_ADDRESSABLE (decl) |
| 4785 |
&& MEM_P (incoming) |
| 4786 |
&& (XEXP (incoming, 0) == virtual_incoming_args_rtx |
| 4787 |
|| (GET_CODE (XEXP (incoming, 0)) == PLUS |
| 4788 |
&& XEXP (XEXP (incoming, 0), 0) == virtual_incoming_args_rtx |
| 4789 |
&& CONST_INT_P (XEXP (XEXP (incoming, 0), 1))))) |
| 4790 |
return copy_rtx (incoming); |
| 4791 |
|
| 4792 |
return NULL_RTX; |
| 4793 |
} |
| 4794 |
|
| 4795 |
/* Return an RTX equivalent to the value of the tree expression EXP. */ |
| 4796 |
|
| 4797 |
static rtx |
| 4798 |
expand_debug_expr (tree exp) |
| 4799 |
{ |
| 4800 |
rtx op0 = NULL_RTX, op1 = NULL_RTX, op2 = NULL_RTX; |
| 4801 |
machine_mode mode = TYPE_MODE (TREE_TYPE (exp)); |
| 4802 |
machine_mode inner_mode = VOIDmode; |
| 4803 |
int unsignedp = TYPE_UNSIGNED (TREE_TYPE (exp)); |
| 4804 |
addr_space_t as; |
| 4805 |
scalar_int_mode op0_mode, op1_mode, addr_mode; |
| 4806 |
|
| 4807 |
switch (TREE_CODE_CLASS (TREE_CODE (exp))) |
| 4808 |
{ |
| 4809 |
case tcc_expression: |
| 4810 |
switch (TREE_CODE (exp)) |
| 4811 |
{ |
| 4812 |
case COND_EXPR: |
| 4813 |
case DOT_PROD_EXPR: |
| 4814 |
case SAD_EXPR: |
| 4815 |
case WIDEN_MULT_PLUS_EXPR: |
| 4816 |
case WIDEN_MULT_MINUS_EXPR: |
| 4817 |
goto ternary; |
| 4818 |
|
| 4819 |
case TRUTH_ANDIF_EXPR: |
| 4820 |
case TRUTH_ORIF_EXPR: |
| 4821 |
case TRUTH_AND_EXPR: |
| 4822 |
case TRUTH_OR_EXPR: |
| 4823 |
case TRUTH_XOR_EXPR: |
| 4824 |
goto binary; |
| 4825 |
|
| 4826 |
case TRUTH_NOT_EXPR: |
| 4827 |
goto unary; |
| 4828 |
|
| 4829 |
default: |
| 4830 |
break; |
| 4831 |
} |
| 4832 |
break; |
| 4833 |
|
| 4834 |
ternary: |
| 4835 |
op2 = expand_debug_expr (TREE_OPERAND (exp, 2)); |
| 4836 |
if (!op2) |
| 4837 |
return NULL_RTX; |
| 4838 |
/* Fall through. */ |
| 4839 |
|
| 4840 |
binary: |
| 4841 |
case tcc_binary: |
| 4842 |
if (mode == BLKmode) |
| 4843 |
return NULL_RTX; |
| 4844 |
op1 = expand_debug_expr (TREE_OPERAND (exp, 1)); |
| 4845 |
if (!op1) |
| 4846 |
return NULL_RTX; |
| 4847 |
switch (TREE_CODE (exp)) |
| 4848 |
{ |
| 4849 |
case LSHIFT_EXPR: |
| 4850 |
case RSHIFT_EXPR: |
| 4851 |
case LROTATE_EXPR: |
| 4852 |
case RROTATE_EXPR: |
| 4853 |
case WIDEN_LSHIFT_EXPR: |
| 4854 |
/* Ensure second operand isn't wider than the first one. */ |
| 4855 |
inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1))); |
| 4856 |
if (is_a <scalar_int_mode> (inner_mode, &op1_mode) |
| 4857 |
&& (GET_MODE_UNIT_PRECISION (mode) |
| 4858 |
< GET_MODE_PRECISION (op1_mode))) |
| 4859 |
op1 = lowpart_subreg (GET_MODE_INNER (mode), op1, op1_mode); |
| 4860 |
break; |
| 4861 |
default: |
| 4862 |
break; |
| 4863 |
} |
| 4864 |
/* Fall through. */ |
| 4865 |
|
| 4866 |
unary: |
| 4867 |
case tcc_unary: |
| 4868 |
if (mode == BLKmode) |
| 4869 |
return NULL_RTX; |
| 4870 |
inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))); |
| 4871 |
op0 = expand_debug_expr (TREE_OPERAND (exp, 0)); |
| 4872 |
if (!op0) |
| 4873 |
return NULL_RTX; |
| 4874 |
break; |
| 4875 |
|
| 4876 |
case tcc_comparison: |
| 4877 |
unsignedp = TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))); |
| 4878 |
goto binary; |
| 4879 |
|
| 4880 |
case tcc_type: |
| 4881 |
case tcc_statement: |
| 4882 |
gcc_unreachable (); |
| 4883 |
|
| 4884 |
case tcc_constant: |
| 4885 |
case tcc_exceptional: |
| 4886 |
case tcc_declaration: |
| 4887 |
case tcc_reference: |
| 4888 |
case tcc_vl_exp: |
| 4889 |
break; |
| 4890 |
} |
| 4891 |
|
| 4892 |
switch (TREE_CODE (exp)) |
| 4893 |
{ |
| 4894 |
case STRING_CST: |
| 4895 |
if (!lookup_constant_def (exp)) |
| 4896 |
{ |
| 4897 |
if (strlen (TREE_STRING_POINTER (exp)) + 1 |
| 4898 |
!= (size_t) TREE_STRING_LENGTH (exp)) |
| 4899 |
return NULL_RTX; |
| 4900 |
op0 = gen_rtx_CONST_STRING (Pmode, TREE_STRING_POINTER (exp)); |
| 4901 |
op0 = gen_rtx_MEM (BLKmode, op0); |
| 4902 |
set_mem_attributes (op0, exp, 0); |
| 4903 |
return op0; |
| 4904 |
} |
| 4905 |
/* Fall through. */ |
| 4906 |
|
| 4907 |
case INTEGER_CST: |
| 4908 |
if (TREE_CODE (TREE_TYPE (exp)) == BITINT_TYPE |
| 4909 |
&& TYPE_MODE (TREE_TYPE (exp)) == BLKmode) |
| 4910 |
return NULL; |
| 4911 |
/* FALLTHRU */ |
| 4912 |
case REAL_CST: |
| 4913 |
case FIXED_CST: |
| 4914 |
op0 = expand_expr (exp, NULL_RTX, mode, EXPAND_INITIALIZER); |
| 4915 |
return op0; |
| 4916 |
|
| 4917 |
case POLY_INT_CST: |
| 4918 |
return immed_wide_int_const (poly_int_cst_value (exp), mode); |
| 4919 |
|
| 4920 |
case COMPLEX_CST: |
| 4921 |
gcc_assert (COMPLEX_MODE_P (mode)); |
| 4922 |
op0 = expand_debug_expr (TREE_REALPART (exp)); |
| 4923 |
op1 = expand_debug_expr (TREE_IMAGPART (exp)); |
| 4924 |
return gen_rtx_CONCAT (mode, op0, op1); |
| 4925 |
|
| 4926 |
case DEBUG_EXPR_DECL: |
| 4927 |
op0 = DECL_RTL_IF_SET (exp); |
| 4928 |
|
| 4929 |
if (op0) |
| 4930 |
{ |
| 4931 |
if (GET_MODE (op0) != mode) |
| 4932 |
gcc_assert (VECTOR_TYPE_P (TREE_TYPE (exp))); |
| 4933 |
else |
| 4934 |
return op0; |
| 4935 |
} |
| 4936 |
|
| 4937 |
op0 = gen_rtx_DEBUG_EXPR (mode); |
| 4938 |
DEBUG_EXPR_TREE_DECL (op0) = exp; |
| 4939 |
SET_DECL_RTL (exp, op0); |
| 4940 |
|
| 4941 |
return op0; |
| 4942 |
|
| 4943 |
case VAR_DECL: |
| 4944 |
case PARM_DECL: |
| 4945 |
case FUNCTION_DECL: |
| 4946 |
case LABEL_DECL: |
| 4947 |
case CONST_DECL: |
| 4948 |
case RESULT_DECL: |
| 4949 |
op0 = DECL_RTL_IF_SET (exp); |
| 4950 |
|
| 4951 |
/* This decl was probably optimized away. */ |
| 4952 |
if (!op0 |
| 4953 |
/* At least label RTXen are sometimes replaced by |
| 4954 |
NOTE_INSN_DELETED_LABEL. Any notes here are not |
| 4955 |
handled by copy_rtx. */ |
| 4956 |
|| NOTE_P (op0)) |
| 4957 |
{ |
| 4958 |
if (!VAR_P (exp) |
| 4959 |
|| DECL_EXTERNAL (exp) |
| 4960 |
|| !TREE_STATIC (exp) |
| 4961 |
|| !DECL_NAME (exp) |
| 4962 |
|| DECL_HARD_REGISTER (exp) |
| 4963 |
|| DECL_IN_CONSTANT_POOL (exp) |
| 4964 |
|| mode == VOIDmode |
| 4965 |
|| symtab_node::get (exp) == NULL) |
| 4966 |
return NULL; |
| 4967 |
|
| 4968 |
op0 = make_decl_rtl_for_debug (exp); |
| 4969 |
if (!MEM_P (op0) |
| 4970 |
|| GET_CODE (XEXP (op0, 0)) != SYMBOL_REF |
| 4971 |
|| SYMBOL_REF_DECL (XEXP (op0, 0)) != exp) |
| 4972 |
return NULL; |
| 4973 |
} |
| 4974 |
else if (VAR_P (exp) |
| 4975 |
&& is_global_var (exp) |
| 4976 |
&& symtab_node::get (exp) == NULL) |
| 4977 |
return NULL; |
| 4978 |
else |
| 4979 |
op0 = copy_rtx (op0); |
| 4980 |
|
| 4981 |
if (GET_MODE (op0) == BLKmode |
| 4982 |
/* If op0 is not BLKmode, but mode is, adjust_mode |
| 4983 |
below would ICE. While it is likely a FE bug, |
| 4984 |
try to be robust here. See PR43166. */ |
| 4985 |
|| mode == BLKmode |
| 4986 |
|| (mode == VOIDmode && GET_MODE (op0) != VOIDmode)) |
| 4987 |
{ |
| 4988 |
gcc_assert (MEM_P (op0)); |
| 4989 |
op0 = adjust_address_nv (op0, mode, 0); |
| 4990 |
return op0; |
| 4991 |
} |
| 4992 |
|
| 4993 |
/* Fall through. */ |
| 4994 |
|
| 4995 |
adjust_mode: |
| 4996 |
case PAREN_EXPR: |
| 4997 |
CASE_CONVERT: |
| 4998 |
{ |
| 4999 |
inner_mode = GET_MODE (op0); |
| 5000 |
|
| 5001 |
if (mode == inner_mode) |
| 5002 |
return op0; |
| 5003 |
|
| 5004 |
if (inner_mode == VOIDmode) |
| 5005 |
{ |
| 5006 |
if (TREE_CODE (exp) == SSA_NAME) |
| 5007 |
inner_mode = TYPE_MODE (TREE_TYPE (exp)); |
| 5008 |
else |
| 5009 |
inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))); |
| 5010 |
if (mode == inner_mode) |
| 5011 |
return op0; |
| 5012 |
} |
| 5013 |
|
| 5014 |
if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode)) |
| 5015 |
{ |
| 5016 |
if (GET_MODE_UNIT_BITSIZE (mode) |
| 5017 |
== GET_MODE_UNIT_BITSIZE (inner_mode)) |
| 5018 |
op0 = simplify_gen_subreg (mode, op0, inner_mode, 0); |
| 5019 |
else if (GET_MODE_UNIT_BITSIZE (mode) |
| 5020 |
< GET_MODE_UNIT_BITSIZE (inner_mode)) |
| 5021 |
op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode); |
| 5022 |
else |
| 5023 |
op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode); |
| 5024 |
} |
| 5025 |
else if (FLOAT_MODE_P (mode)) |
| 5026 |
{ |
| 5027 |
gcc_assert (TREE_CODE (exp) != SSA_NAME); |
| 5028 |
if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)))) |
| 5029 |
op0 = simplify_gen_unary (UNSIGNED_FLOAT, mode, op0, inner_mode); |
| 5030 |
else |
| 5031 |
op0 = simplify_gen_unary (FLOAT, mode, op0, inner_mode); |
| 5032 |
} |
| 5033 |
else if (FLOAT_MODE_P (inner_mode)) |
| 5034 |
{ |
| 5035 |
if (unsignedp) |
| 5036 |
op0 = simplify_gen_unary (UNSIGNED_FIX, mode, op0, inner_mode); |
| 5037 |
else |
| 5038 |
op0 = simplify_gen_unary (FIX, mode, op0, inner_mode); |
| 5039 |
} |
| 5040 |
else if (GET_MODE_UNIT_PRECISION (mode) |
| 5041 |
== GET_MODE_UNIT_PRECISION (inner_mode)) |
| 5042 |
op0 = lowpart_subreg (mode, op0, inner_mode); |
| 5043 |
else if (GET_MODE_UNIT_PRECISION (mode) |
| 5044 |
< GET_MODE_UNIT_PRECISION (inner_mode)) |
| 5045 |
op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode); |
| 5046 |
else if (UNARY_CLASS_P (exp) |
| 5047 |
? TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))) |
| 5048 |
: unsignedp) |
| 5049 |
op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode); |
| 5050 |
else |
| 5051 |
op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode); |
| 5052 |
|
| 5053 |
return op0; |
| 5054 |
} |
| 5055 |
|
| 5056 |
case MEM_REF: |
| 5057 |
if (!is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0))) |
| 5058 |
{ |
| 5059 |
tree newexp = fold_binary (MEM_REF, TREE_TYPE (exp), |
| 5060 |
TREE_OPERAND (exp, 0), |
| 5061 |
TREE_OPERAND (exp, 1)); |
| 5062 |
if (newexp) |
| 5063 |
return expand_debug_expr (newexp); |
| 5064 |
} |
| 5065 |
/* FALLTHROUGH */ |
| 5066 |
case INDIRECT_REF: |
| 5067 |
inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))); |
| 5068 |
op0 = expand_debug_expr (TREE_OPERAND (exp, 0)); |
| 5069 |
if (!op0) |
| 5070 |
return NULL; |
| 5071 |
|
| 5072 |
if (TREE_CODE (exp) == MEM_REF) |
| 5073 |
{ |
| 5074 |
if (GET_CODE (op0) == DEBUG_IMPLICIT_PTR |
| 5075 |
|| (GET_CODE (op0) == PLUS |
| 5076 |
&& GET_CODE (XEXP (op0, 0)) == DEBUG_IMPLICIT_PTR)) |
| 5077 |
/* (mem (debug_implicit_ptr)) might confuse aliasing. |
| 5078 |
Instead just use get_inner_reference. */ |
| 5079 |
goto component_ref; |
| 5080 |
|
| 5081 |
op1 = expand_debug_expr (TREE_OPERAND (exp, 1)); |
| 5082 |
poly_int64 offset; |
| 5083 |
if (!op1 || !poly_int_rtx_p (op1, &offset)) |
| 5084 |
return NULL; |
| 5085 |
|
| 5086 |
op0 = plus_constant (inner_mode, op0, offset); |
| 5087 |
} |
| 5088 |
|
| 5089 |
as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))); |
| 5090 |
|
| 5091 |
op0 = convert_debug_memory_address (targetm.addr_space.address_mode (as), |
| 5092 |
op0, as); |
| 5093 |
if (op0 == NULL_RTX) |
| 5094 |
return NULL; |
| 5095 |
|
| 5096 |
op0 = gen_rtx_MEM (mode, op0); |
| 5097 |
set_mem_attributes (op0, exp, 0); |
| 5098 |
if (TREE_CODE (exp) == MEM_REF |
| 5099 |
&& !is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0))) |
| 5100 |
set_mem_expr (op0, NULL_TREE); |
| 5101 |
set_mem_addr_space (op0, as); |
| 5102 |
|
| 5103 |
return op0; |
| 5104 |
|
| 5105 |
case TARGET_MEM_REF: |
| 5106 |
if (TREE_CODE (TMR_BASE (exp)) == ADDR_EXPR |
| 5107 |
&& !DECL_RTL_SET_P (TREE_OPERAND (TMR_BASE (exp), 0))) |
| 5108 |
return NULL; |
| 5109 |
|
| 5110 |
op0 = expand_debug_expr |
| 5111 |
(tree_mem_ref_addr (build_pointer_type (TREE_TYPE (exp)), exp)); |
| 5112 |
if (!op0) |
| 5113 |
return NULL; |
| 5114 |
|
| 5115 |
as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))); |
| 5116 |
op0 = convert_debug_memory_address (targetm.addr_space.address_mode (as), |
| 5117 |
op0, as); |
| 5118 |
if (op0 == NULL_RTX) |
| 5119 |
return NULL; |
| 5120 |
|
| 5121 |
op0 = gen_rtx_MEM (mode, op0); |
| 5122 |
|
| 5123 |
set_mem_attributes (op0, exp, 0); |
| 5124 |
set_mem_addr_space (op0, as); |
| 5125 |
|
| 5126 |
return op0; |
| 5127 |
|
| 5128 |
component_ref: |
| 5129 |
case ARRAY_REF: |
| 5130 |
case ARRAY_RANGE_REF: |
| 5131 |
case COMPONENT_REF: |
| 5132 |
case BIT_FIELD_REF: |
| 5133 |
case REALPART_EXPR: |
| 5134 |
case IMAGPART_EXPR: |
| 5135 |
case VIEW_CONVERT_EXPR: |
| 5136 |
{ |
| 5137 |
machine_mode mode1; |
| 5138 |
poly_int64 bitsize, bitpos; |
| 5139 |
tree offset; |
| 5140 |
int reversep, volatilep = 0; |
| 5141 |
tree tem |
| 5142 |
= get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1, |
| 5143 |
&unsignedp, &reversep, &volatilep); |
| 5144 |
rtx orig_op0; |
| 5145 |
|
| 5146 |
if (known_eq (bitsize, 0)) |
| 5147 |
return NULL; |
| 5148 |
|
| 5149 |
orig_op0 = op0 = expand_debug_expr (tem); |
| 5150 |
|
| 5151 |
if (!op0) |
| 5152 |
return NULL; |
| 5153 |
|
| 5154 |
if (offset) |
| 5155 |
{ |
| 5156 |
machine_mode addrmode, offmode; |
| 5157 |
|
| 5158 |
if (!MEM_P (op0)) |
| 5159 |
return NULL; |
| 5160 |
|
| 5161 |
op0 = XEXP (op0, 0); |
| 5162 |
addrmode = GET_MODE (op0); |
| 5163 |
if (addrmode == VOIDmode) |
| 5164 |
addrmode = Pmode; |
| 5165 |
|
| 5166 |
op1 = expand_debug_expr (offset); |
| 5167 |
if (!op1) |
| 5168 |
return NULL; |
| 5169 |
|
| 5170 |
offmode = GET_MODE (op1); |
| 5171 |
if (offmode == VOIDmode) |
| 5172 |
offmode = TYPE_MODE (TREE_TYPE (offset)); |
| 5173 |
|
| 5174 |
if (addrmode != offmode) |
| 5175 |
op1 = lowpart_subreg (addrmode, op1, offmode); |
| 5176 |
|
| 5177 |
/* Don't use offset_address here, we don't need a |
| 5178 |
recognizable address, and we don't want to generate |
| 5179 |
code. */ |
| 5180 |
op0 = gen_rtx_MEM (mode, simplify_gen_binary (PLUS, addrmode, |
| 5181 |
op0, op1)); |
| 5182 |
} |
| 5183 |
|
| 5184 |
if (MEM_P (op0)) |
| 5185 |
{ |
| 5186 |
if (mode1 == VOIDmode) |
| 5187 |
{ |
| 5188 |
if (maybe_gt (bitsize, MAX_BITSIZE_MODE_ANY_INT)) |
| 5189 |
return NULL; |
| 5190 |
/* Bitfield. */ |
| 5191 |
mode1 = smallest_int_mode_for_size (bitsize).require (); |
| 5192 |
} |
| 5193 |
poly_int64 bytepos = bits_to_bytes_round_down (bitpos); |
| 5194 |
if (maybe_ne (bytepos, 0)) |
| 5195 |
{ |
| 5196 |
op0 = adjust_address_nv (op0, mode1, bytepos); |
| 5197 |
bitpos = num_trailing_bits (bitpos); |
| 5198 |
} |
| 5199 |
else if (known_eq (bitpos, 0) |
| 5200 |
&& known_eq (bitsize, GET_MODE_BITSIZE (mode))) |
| 5201 |
op0 = adjust_address_nv (op0, mode, 0); |
| 5202 |
else if (GET_MODE (op0) != mode1) |
| 5203 |
op0 = adjust_address_nv (op0, mode1, 0); |
| 5204 |
else |
| 5205 |
op0 = copy_rtx (op0); |
| 5206 |
if (op0 == orig_op0) |
| 5207 |
op0 = shallow_copy_rtx (op0); |
| 5208 |
if (TREE_CODE (tem) != SSA_NAME) |
| 5209 |
set_mem_attributes (op0, exp, 0); |
| 5210 |
} |
| 5211 |
|
| 5212 |
if (known_eq (bitpos, 0) && mode == GET_MODE (op0)) |
| 5213 |
return op0; |
| 5214 |
|
| 5215 |
if (maybe_lt (bitpos, 0)) |
| 5216 |
return NULL; |
| 5217 |
|
| 5218 |
if (GET_MODE (op0) == BLKmode || mode == BLKmode) |
| 5219 |
return NULL; |
| 5220 |
|
| 5221 |
poly_int64 bytepos; |
| 5222 |
if (multiple_p (bitpos, BITS_PER_UNIT, &bytepos) |
| 5223 |
&& known_eq (bitsize, GET_MODE_BITSIZE (mode1))) |
| 5224 |
{ |
| 5225 |
machine_mode opmode = GET_MODE (op0); |
| 5226 |
|
| 5227 |
if (opmode == VOIDmode) |
| 5228 |
opmode = TYPE_MODE (TREE_TYPE (tem)); |
| 5229 |
|
| 5230 |
/* This condition may hold if we're expanding the address |
| 5231 |
right past the end of an array that turned out not to |
| 5232 |
be addressable (i.e., the address was only computed in |
| 5233 |
debug stmts). The gen_subreg below would rightfully |
| 5234 |
crash, and the address doesn't really exist, so just |
| 5235 |
drop it. */ |
| 5236 |
if (known_ge (bitpos, GET_MODE_BITSIZE (opmode))) |
| 5237 |
return NULL; |
| 5238 |
|
| 5239 |
if (multiple_p (bitpos, GET_MODE_BITSIZE (mode))) |
| 5240 |
return simplify_gen_subreg (mode, op0, opmode, bytepos); |
| 5241 |
} |
| 5242 |
|
| 5243 |
return simplify_gen_ternary (SCALAR_INT_MODE_P (GET_MODE (op0)) |
| 5244 |
&& TYPE_UNSIGNED (TREE_TYPE (exp)) |
| 5245 |
? SIGN_EXTRACT |
| 5246 |
: ZERO_EXTRACT, mode, |
| 5247 |
GET_MODE (op0) != VOIDmode |
| 5248 |
? GET_MODE (op0) |
| 5249 |
: TYPE_MODE (TREE_TYPE (tem)), |
| 5250 |
op0, gen_int_mode (bitsize, word_mode), |
| 5251 |
gen_int_mode (bitpos, word_mode)); |
| 5252 |
} |
| 5253 |
|
| 5254 |
case ABS_EXPR: |
| 5255 |
case ABSU_EXPR: |
| 5256 |
return simplify_gen_unary (ABS, mode, op0, mode); |
| 5257 |
|
| 5258 |
case NEGATE_EXPR: |
| 5259 |
return simplify_gen_unary (NEG, mode, op0, mode); |
| 5260 |
|
| 5261 |
case BIT_NOT_EXPR: |
| 5262 |
return simplify_gen_unary (NOT, mode, op0, mode); |
| 5263 |
|
| 5264 |
case FLOAT_EXPR: |
| 5265 |
return simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, |
| 5266 |
0))) |
| 5267 |
? UNSIGNED_FLOAT : FLOAT, mode, op0, |
| 5268 |
inner_mode); |
| 5269 |
|
| 5270 |
case FIX_TRUNC_EXPR: |
| 5271 |
return simplify_gen_unary (unsignedp ? UNSIGNED_FIX : FIX, mode, op0, |
| 5272 |
inner_mode); |
| 5273 |
|
| 5274 |
case POINTER_PLUS_EXPR: |
| 5275 |
/* For the rare target where pointers are not the same size as |
| 5276 |
size_t, we need to check for mis-matched modes and correct |
| 5277 |
the addend. */ |
| 5278 |
if (op0 && op1 |
| 5279 |
&& is_a <scalar_int_mode> (GET_MODE (op0), &op0_mode) |
| 5280 |
&& is_a <scalar_int_mode> (GET_MODE (op1), &op1_mode) |
| 5281 |
&& op0_mode != op1_mode) |
| 5282 |
{ |
| 5283 |
if (GET_MODE_BITSIZE (op0_mode) < GET_MODE_BITSIZE (op1_mode) |
| 5284 |
/* If OP0 is a partial mode, then we must truncate, even |
| 5285 |
if it has the same bitsize as OP1 as GCC's |
| 5286 |
representation of partial modes is opaque. */ |
| 5287 |
|| (GET_MODE_CLASS (op0_mode) == MODE_PARTIAL_INT |
| 5288 |
&& (GET_MODE_BITSIZE (op0_mode) |
| 5289 |
== GET_MODE_BITSIZE (op1_mode)))) |
| 5290 |
op1 = simplify_gen_unary (TRUNCATE, op0_mode, op1, op1_mode); |
| 5291 |
else |
| 5292 |
/* We always sign-extend, regardless of the signedness of |
| 5293 |
the operand, because the operand is always unsigned |
| 5294 |
here even if the original C expression is signed. */ |
| 5295 |
op1 = simplify_gen_unary (SIGN_EXTEND, op0_mode, op1, op1_mode); |
| 5296 |
} |
| 5297 |
/* Fall through. */ |
| 5298 |
case PLUS_EXPR: |
| 5299 |
return simplify_gen_binary (PLUS, mode, op0, op1); |
| 5300 |
|
| 5301 |
case MINUS_EXPR: |
| 5302 |
case POINTER_DIFF_EXPR: |
| 5303 |
return simplify_gen_binary (MINUS, mode, op0, op1); |
| 5304 |
|
| 5305 |
case MULT_EXPR: |
| 5306 |
return simplify_gen_binary (MULT, mode, op0, op1); |
| 5307 |
|
| 5308 |
case RDIV_EXPR: |
| 5309 |
case TRUNC_DIV_EXPR: |
| 5310 |
case EXACT_DIV_EXPR: |
| 5311 |
if (unsignedp) |
| 5312 |
return simplify_gen_binary (UDIV, mode, op0, op1); |
| 5313 |
else |
| 5314 |
return simplify_gen_binary (DIV, mode, op0, op1); |
| 5315 |
|
| 5316 |
case TRUNC_MOD_EXPR: |
| 5317 |
return simplify_gen_binary (unsignedp ? UMOD : MOD, mode, op0, op1); |
| 5318 |
|
| 5319 |
case FLOOR_DIV_EXPR: |
| 5320 |
if (unsignedp) |
| 5321 |
return simplify_gen_binary (UDIV, mode, op0, op1); |
| 5322 |
else |
| 5323 |
{ |
| 5324 |
rtx div = simplify_gen_binary (DIV, mode, op0, op1); |
| 5325 |
rtx mod = simplify_gen_binary (MOD, mode, op0, op1); |
| 5326 |
rtx adj = floor_sdiv_adjust (mode, mod, op1); |
| 5327 |
return simplify_gen_binary (PLUS, mode, div, adj); |
| 5328 |
} |
| 5329 |
|
| 5330 |
case FLOOR_MOD_EXPR: |
| 5331 |
if (unsignedp) |
| 5332 |
return simplify_gen_binary (UMOD, mode, op0, op1); |
| 5333 |
else |
| 5334 |
{ |
| 5335 |
rtx mod = simplify_gen_binary (MOD, mode, op0, op1); |
| 5336 |
rtx adj = floor_sdiv_adjust (mode, mod, op1); |
| 5337 |
adj = simplify_gen_unary (NEG, mode, |
| 5338 |
simplify_gen_binary (MULT, mode, adj, op1), |
| 5339 |
mode); |
| 5340 |
return simplify_gen_binary (PLUS, mode, mod, adj); |
| 5341 |
} |
| 5342 |
|
| 5343 |
case CEIL_DIV_EXPR: |
| 5344 |
if (unsignedp) |
| 5345 |
{ |
| 5346 |
rtx div = simplify_gen_binary (UDIV, mode, op0, op1); |
| 5347 |
rtx mod = simplify_gen_binary (UMOD, mode, op0, op1); |
| 5348 |
rtx adj = ceil_udiv_adjust (mode, mod, op1); |
| 5349 |
return simplify_gen_binary (PLUS, mode, div, adj); |
| 5350 |
} |
| 5351 |
else |
| 5352 |
{ |
| 5353 |
rtx div = simplify_gen_binary (DIV, mode, op0, op1); |
| 5354 |
rtx mod = simplify_gen_binary (MOD, mode, op0, op1); |
| 5355 |
rtx adj = ceil_sdiv_adjust (mode, mod, op1); |
| 5356 |
return simplify_gen_binary (PLUS, mode, div, adj); |
| 5357 |
} |
| 5358 |
|
| 5359 |
case CEIL_MOD_EXPR: |
| 5360 |
if (unsignedp) |
| 5361 |
{ |
| 5362 |
rtx mod = simplify_gen_binary (UMOD, mode, op0, op1); |
| 5363 |
rtx adj = ceil_udiv_adjust (mode, mod, op1); |
| 5364 |
adj = simplify_gen_unary (NEG, mode, |
| 5365 |
simplify_gen_binary (MULT, mode, adj, op1), |
| 5366 |
mode); |
| 5367 |
return simplify_gen_binary (PLUS, mode, mod, adj); |
| 5368 |
} |
| 5369 |
else |
| 5370 |
{ |
| 5371 |
rtx mod = simplify_gen_binary (MOD, mode, op0, op1); |
| 5372 |
rtx adj = ceil_sdiv_adjust (mode, mod, op1); |
| 5373 |
adj = simplify_gen_unary (NEG, mode, |
| 5374 |
simplify_gen_binary (MULT, mode, adj, op1), |
| 5375 |
mode); |
| 5376 |
return simplify_gen_binary (PLUS, mode, mod, adj); |
| 5377 |
} |
| 5378 |
|
| 5379 |
case ROUND_DIV_EXPR: |
| 5380 |
if (unsignedp) |
| 5381 |
{ |
| 5382 |
rtx div = simplify_gen_binary (UDIV, mode, op0, op1); |
| 5383 |
rtx mod = simplify_gen_binary (UMOD, mode, op0, op1); |
| 5384 |
rtx adj = round_udiv_adjust (mode, mod, op1); |
| 5385 |
return simplify_gen_binary (PLUS, mode, div, adj); |
| 5386 |
} |
| 5387 |
else |
| 5388 |
{ |
| 5389 |
rtx div = simplify_gen_binary (DIV, mode, op0, op1); |
| 5390 |
rtx mod = simplify_gen_binary (MOD, mode, op0, op1); |
| 5391 |
rtx adj = round_sdiv_adjust (mode, mod, op1); |
| 5392 |
return simplify_gen_binary (PLUS, mode, div, adj); |
| 5393 |
} |
| 5394 |
|
| 5395 |
case ROUND_MOD_EXPR: |
| 5396 |
if (unsignedp) |
| 5397 |
{ |
| 5398 |
rtx mod = simplify_gen_binary (UMOD, mode, op0, op1); |
| 5399 |
rtx adj = round_udiv_adjust (mode, mod, op1); |
| 5400 |
adj = simplify_gen_unary (NEG, mode, |
| 5401 |
simplify_gen_binary (MULT, mode, adj, op1), |
| 5402 |
mode); |
| 5403 |
return simplify_gen_binary (PLUS, mode, mod, adj); |
| 5404 |
} |
| 5405 |
else |
| 5406 |
{ |
| 5407 |
rtx mod = simplify_gen_binary (MOD, mode, op0, op1); |
| 5408 |
rtx adj = round_sdiv_adjust (mode, mod, op1); |
| 5409 |
adj = simplify_gen_unary (NEG, mode, |
| 5410 |
simplify_gen_binary (MULT, mode, adj, op1), |
| 5411 |
mode); |
| 5412 |
return simplify_gen_binary (PLUS, mode, mod, adj); |
| 5413 |
} |
| 5414 |
|
| 5415 |
case LSHIFT_EXPR: |
| 5416 |
return simplify_gen_binary (ASHIFT, mode, op0, op1); |
| 5417 |
|
| 5418 |
case RSHIFT_EXPR: |
| 5419 |
if (unsignedp) |
| 5420 |
return simplify_gen_binary (LSHIFTRT, mode, op0, op1); |
| 5421 |
else |
| 5422 |
return simplify_gen_binary (ASHIFTRT, mode, op0, op1); |
| 5423 |
|
| 5424 |
case LROTATE_EXPR: |
| 5425 |
return simplify_gen_binary (ROTATE, mode, op0, op1); |
| 5426 |
|
| 5427 |
case RROTATE_EXPR: |
| 5428 |
return simplify_gen_binary (ROTATERT, mode, op0, op1); |
| 5429 |
|
| 5430 |
case MIN_EXPR: |
| 5431 |
return simplify_gen_binary (unsignedp ? UMIN : SMIN, mode, op0, op1); |
| 5432 |
|
| 5433 |
case MAX_EXPR: |
| 5434 |
return simplify_gen_binary (unsignedp ? UMAX : SMAX, mode, op0, op1); |
| 5435 |
|
| 5436 |
case BIT_AND_EXPR: |
| 5437 |
case TRUTH_AND_EXPR: |
| 5438 |
return simplify_gen_binary (AND, mode, op0, op1); |
| 5439 |
|
| 5440 |
case BIT_IOR_EXPR: |
| 5441 |
case TRUTH_OR_EXPR: |
| 5442 |
return simplify_gen_binary (IOR, mode, op0, op1); |
| 5443 |
|
| 5444 |
case BIT_XOR_EXPR: |
| 5445 |
case TRUTH_XOR_EXPR: |
| 5446 |
return simplify_gen_binary (XOR, mode, op0, op1); |
| 5447 |
|
| 5448 |
case TRUTH_ANDIF_EXPR: |
| 5449 |
return gen_rtx_IF_THEN_ELSE (mode, op0, op1, const0_rtx); |
| 5450 |
|
| 5451 |
case TRUTH_ORIF_EXPR: |
| 5452 |
return gen_rtx_IF_THEN_ELSE (mode, op0, const_true_rtx, op1); |
| 5453 |
|
| 5454 |
case TRUTH_NOT_EXPR: |
| 5455 |
return simplify_gen_relational (EQ, mode, inner_mode, op0, const0_rtx); |
| 5456 |
|
| 5457 |
case LT_EXPR: |
| 5458 |
return simplify_gen_relational (unsignedp ? LTU : LT, mode, inner_mode, |
| 5459 |
op0, op1); |
| 5460 |
|
| 5461 |
case LE_EXPR: |
| 5462 |
return simplify_gen_relational (unsignedp ? LEU : LE, mode, inner_mode, |
| 5463 |
op0, op1); |
| 5464 |
|
| 5465 |
case GT_EXPR: |
| 5466 |
return simplify_gen_relational (unsignedp ? GTU : GT, mode, inner_mode, |
| 5467 |
op0, op1); |
| 5468 |
|
| 5469 |
case GE_EXPR: |
| 5470 |
return simplify_gen_relational (unsignedp ? GEU : GE, mode, inner_mode, |
| 5471 |
op0, op1); |
| 5472 |
|
| 5473 |
case EQ_EXPR: |
| 5474 |
return simplify_gen_relational (EQ, mode, inner_mode, op0, op1); |
| 5475 |
|
| 5476 |
case NE_EXPR: |
| 5477 |
return simplify_gen_relational (NE, mode, inner_mode, op0, op1); |
| 5478 |
|
| 5479 |
case UNORDERED_EXPR: |
| 5480 |
return simplify_gen_relational (UNORDERED, mode, inner_mode, op0, op1); |
| 5481 |
|
| 5482 |
case ORDERED_EXPR: |
| 5483 |
return simplify_gen_relational (ORDERED, mode, inner_mode, op0, op1); |
| 5484 |
|
| 5485 |
case UNLT_EXPR: |
| 5486 |
return simplify_gen_relational (UNLT, mode, inner_mode, op0, op1); |
| 5487 |
|
| 5488 |
case UNLE_EXPR: |
| 5489 |
return simplify_gen_relational (UNLE, mode, inner_mode, op0, op1); |
| 5490 |
|
| 5491 |
case UNGT_EXPR: |
| 5492 |
return simplify_gen_relational (UNGT, mode, inner_mode, op0, op1); |
| 5493 |
|
| 5494 |
case UNGE_EXPR: |
| 5495 |
return simplify_gen_relational (UNGE, mode, inner_mode, op0, op1); |
| 5496 |
|
| 5497 |
case UNEQ_EXPR: |
| 5498 |
return simplify_gen_relational (UNEQ, mode, inner_mode, op0, op1); |
| 5499 |
|
| 5500 |
case LTGT_EXPR: |
| 5501 |
return simplify_gen_relational (LTGT, mode, inner_mode, op0, op1); |
| 5502 |
|
| 5503 |
case COND_EXPR: |
| 5504 |
return gen_rtx_IF_THEN_ELSE (mode, op0, op1, op2); |
| 5505 |
|
| 5506 |
case COMPLEX_EXPR: |
| 5507 |
gcc_assert (COMPLEX_MODE_P (mode)); |
| 5508 |
if (GET_MODE (op0) == VOIDmode) |
| 5509 |
op0 = gen_rtx_CONST (GET_MODE_INNER (mode), op0); |
| 5510 |
if (GET_MODE (op1) == VOIDmode) |
| 5511 |
op1 = gen_rtx_CONST (GET_MODE_INNER (mode), op1); |
| 5512 |
return gen_rtx_CONCAT (mode, op0, op1); |
| 5513 |
|
| 5514 |
case CONJ_EXPR: |
| 5515 |
if (GET_CODE (op0) == CONCAT) |
| 5516 |
return gen_rtx_CONCAT (mode, XEXP (op0, 0), |
| 5517 |
simplify_gen_unary (NEG, GET_MODE_INNER (mode), |
| 5518 |
XEXP (op0, 1), |
| 5519 |
GET_MODE_INNER (mode))); |
| 5520 |
else |
| 5521 |
{ |
| 5522 |
scalar_mode imode = GET_MODE_INNER (mode); |
| 5523 |
rtx re, im; |
| 5524 |
|
| 5525 |
if (MEM_P (op0)) |
| 5526 |
{ |
| 5527 |
re = adjust_address_nv (op0, imode, 0); |
| 5528 |
im = adjust_address_nv (op0, imode, GET_MODE_SIZE (imode)); |
| 5529 |
} |
| 5530 |
else |
| 5531 |
{ |
| 5532 |
scalar_int_mode ifmode; |
| 5533 |
scalar_int_mode ihmode; |
| 5534 |
rtx halfsize; |
| 5535 |
if (!int_mode_for_mode (mode).exists (&ifmode) |
| 5536 |
|| !int_mode_for_mode (imode).exists (&ihmode)) |
| 5537 |
return NULL; |
| 5538 |
halfsize = GEN_INT (GET_MODE_BITSIZE (ihmode)); |
| 5539 |
re = op0; |
| 5540 |
if (mode != ifmode) |
| 5541 |
re = gen_rtx_SUBREG (ifmode, re, 0); |
| 5542 |
re = gen_rtx_ZERO_EXTRACT (ihmode, re, halfsize, const0_rtx); |
| 5543 |
if (imode != ihmode) |
| 5544 |
re = gen_rtx_SUBREG (imode, re, 0); |
| 5545 |
im = copy_rtx (op0); |
| 5546 |
if (mode != ifmode) |
| 5547 |
im = gen_rtx_SUBREG (ifmode, im, 0); |
| 5548 |
im = gen_rtx_ZERO_EXTRACT (ihmode, im, halfsize, halfsize); |
| 5549 |
if (imode != ihmode) |
| 5550 |
im = gen_rtx_SUBREG (imode, im, 0); |
| 5551 |
} |
| 5552 |
im = gen_rtx_NEG (imode, im); |
| 5553 |
return gen_rtx_CONCAT (mode, re, im); |
| 5554 |
} |
| 5555 |
|
| 5556 |
case ADDR_EXPR: |
| 5557 |
op0 = expand_debug_expr (TREE_OPERAND (exp, 0)); |
| 5558 |
if (!op0 || !MEM_P (op0)) |
| 5559 |
{ |
| 5560 |
if ((TREE_CODE (TREE_OPERAND (exp, 0)) == VAR_DECL |
| 5561 |
|| TREE_CODE (TREE_OPERAND (exp, 0)) == PARM_DECL |
| 5562 |
|| TREE_CODE (TREE_OPERAND (exp, 0)) == RESULT_DECL) |
| 5563 |
&& (!TREE_ADDRESSABLE (TREE_OPERAND (exp, 0)) |
| 5564 |
|| target_for_debug_bind (TREE_OPERAND (exp, 0)))) |
| 5565 |
return gen_rtx_DEBUG_IMPLICIT_PTR (mode, TREE_OPERAND (exp, 0)); |
| 5566 |
|
| 5567 |
if (handled_component_p (TREE_OPERAND (exp, 0))) |
| 5568 |
{ |
| 5569 |
poly_int64 bitoffset, bitsize, maxsize, byteoffset; |
| 5570 |
bool reverse; |
| 5571 |
tree decl |
| 5572 |
= get_ref_base_and_extent (TREE_OPERAND (exp, 0), &bitoffset, |
| 5573 |
&bitsize, &maxsize, &reverse); |
| 5574 |
if ((VAR_P (decl) |
| 5575 |
|| TREE_CODE (decl) == PARM_DECL |
| 5576 |
|| TREE_CODE (decl) == RESULT_DECL) |
| 5577 |
&& (!TREE_ADDRESSABLE (decl) |
| 5578 |
|| target_for_debug_bind (decl)) |
| 5579 |
&& multiple_p (bitoffset, BITS_PER_UNIT, &byteoffset) |
| 5580 |
&& known_gt (bitsize, 0) |
| 5581 |
&& known_eq (bitsize, maxsize)) |
| 5582 |
{ |
| 5583 |
rtx base = gen_rtx_DEBUG_IMPLICIT_PTR (mode, decl); |
| 5584 |
return plus_constant (mode, base, byteoffset); |
| 5585 |
} |
| 5586 |
} |
| 5587 |
|
| 5588 |
if (TREE_CODE (TREE_OPERAND (exp, 0)) == MEM_REF |
| 5589 |
&& TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) |
| 5590 |
== ADDR_EXPR) |
| 5591 |
{ |
| 5592 |
op0 = expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp, 0), |
| 5593 |
0)); |
| 5594 |
if (op0 != NULL |
| 5595 |
&& (GET_CODE (op0) == DEBUG_IMPLICIT_PTR |
| 5596 |
|| (GET_CODE (op0) == PLUS |
| 5597 |
&& GET_CODE (XEXP (op0, 0)) == DEBUG_IMPLICIT_PTR |
| 5598 |
&& CONST_INT_P (XEXP (op0, 1))))) |
| 5599 |
{ |
| 5600 |
op1 = expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp, 0), |
| 5601 |
1)); |
| 5602 |
poly_int64 offset; |
| 5603 |
if (!op1 || !poly_int_rtx_p (op1, &offset)) |
| 5604 |
return NULL; |
| 5605 |
|
| 5606 |
return plus_constant (mode, op0, offset); |
| 5607 |
} |
| 5608 |
} |
| 5609 |
|
| 5610 |
return NULL; |
| 5611 |
} |
| 5612 |
|
| 5613 |
as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp))); |
| 5614 |
addr_mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (exp)); |
| 5615 |
op0 = convert_debug_memory_address (addr_mode, XEXP (op0, 0), as); |
| 5616 |
|
| 5617 |
return op0; |
| 5618 |
|
| 5619 |
case VECTOR_CST: |
| 5620 |
{ |
| 5621 |
unsigned HOST_WIDE_INT i, nelts; |
| 5622 |
|
| 5623 |
if (!VECTOR_CST_NELTS (exp).is_constant (&nelts)) |
| 5624 |
return NULL; |
| 5625 |
|
| 5626 |
op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts)); |
| 5627 |
|
| 5628 |
for (i = 0; i < nelts; ++i) |
| 5629 |
{ |
| 5630 |
op1 = expand_debug_expr (VECTOR_CST_ELT (exp, i)); |
| 5631 |
if (!op1) |
| 5632 |
return NULL; |
| 5633 |
XVECEXP (op0, 0, i) = op1; |
| 5634 |
} |
| 5635 |
|
| 5636 |
return op0; |
| 5637 |
} |
| 5638 |
|
| 5639 |
case CONSTRUCTOR: |
| 5640 |
if (TREE_CLOBBER_P (exp)) |
| 5641 |
return NULL; |
| 5642 |
else if (TREE_CODE (TREE_TYPE (exp)) == VECTOR_TYPE) |
| 5643 |
{ |
| 5644 |
unsigned i; |
| 5645 |
poly_uint64 elts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp)); |
| 5646 |
unsigned HOST_WIDE_INT nelts = constant_lower_bound (elts); |
| 5647 |
tree val; |
| 5648 |
|
| 5649 |
op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts)); |
| 5650 |
|
| 5651 |
FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), i, val) |
| 5652 |
{ |
| 5653 |
op1 = expand_debug_expr (val); |
| 5654 |
if (!op1) |
| 5655 |
return NULL; |
| 5656 |
XVECEXP (op0, 0, i) = op1; |
| 5657 |
} |
| 5658 |
|
| 5659 |
if (i < nelts) |
| 5660 |
{ |
| 5661 |
op1 = expand_debug_expr |
| 5662 |
(build_zero_cst (TREE_TYPE (TREE_TYPE (exp)))); |
| 5663 |
|
| 5664 |
if (!op1) |
| 5665 |
return NULL; |
| 5666 |
|
| 5667 |
for (; i < nelts; i++) |
| 5668 |
XVECEXP (op0, 0, i) = op1; |
| 5669 |
} |
| 5670 |
|
| 5671 |
return op0; |
| 5672 |
} |
| 5673 |
else |
| 5674 |
goto flag_unsupported; |
| 5675 |
|
| 5676 |
case CALL_EXPR: |
| 5677 |
/* ??? Maybe handle some builtins? */ |
| 5678 |
return NULL; |
| 5679 |
|
| 5680 |
case SSA_NAME: |
| 5681 |
{ |
| 5682 |
gimple *g = get_gimple_for_ssa_name (exp); |
| 5683 |
if (g) |
| 5684 |
{ |
| 5685 |
tree t = NULL_TREE; |
| 5686 |
if (deep_ter_debug_map) |
| 5687 |
{ |
| 5688 |
tree *slot = deep_ter_debug_map->get (exp); |
| 5689 |
if (slot) |
| 5690 |
t = *slot; |
| 5691 |
} |
| 5692 |
if (t == NULL_TREE) |
| 5693 |
{ |
| 5694 |
if (is_gimple_assign (g)) |
| 5695 |
t = gimple_assign_rhs_to_tree (g); |
| 5696 |
else |
| 5697 |
/* expand_debug_expr doesn't handle CALL_EXPR right now. */ |
| 5698 |
return NULL; |
| 5699 |
} |
| 5700 |
op0 = expand_debug_expr (t); |
| 5701 |
if (!op0) |
| 5702 |
return NULL; |
| 5703 |
} |
| 5704 |
else |
| 5705 |
{ |
| 5706 |
/* If this is a reference to an incoming value of |
| 5707 |
parameter that is never used in the code or where the |
| 5708 |
incoming value is never used in the code, use |
| 5709 |
PARM_DECL's DECL_RTL if set. */ |
| 5710 |
if (SSA_NAME_IS_DEFAULT_DEF (exp) |
| 5711 |
&& SSA_NAME_VAR (exp) |
| 5712 |
&& TREE_CODE (SSA_NAME_VAR (exp)) == PARM_DECL |
| 5713 |
&& has_zero_uses (exp)) |
| 5714 |
{ |
| 5715 |
op0 = expand_debug_parm_decl (SSA_NAME_VAR (exp)); |
| 5716 |
if (op0) |
| 5717 |
goto adjust_mode; |
| 5718 |
op0 = expand_debug_expr (SSA_NAME_VAR (exp)); |
| 5719 |
if (op0) |
| 5720 |
goto adjust_mode; |
| 5721 |
} |
| 5722 |
|
| 5723 |
int part = var_to_partition (SA.map, exp); |
| 5724 |
|
| 5725 |
if (part == NO_PARTITION) |
| 5726 |
return NULL; |
| 5727 |
|
| 5728 |
gcc_assert (part >= 0 && (unsigned)part < SA.map->num_partitions); |
| 5729 |
|
| 5730 |
op0 = copy_rtx (SA.partition_to_pseudo[part]); |
| 5731 |
} |
| 5732 |
goto adjust_mode; |
| 5733 |
} |
| 5734 |
|
| 5735 |
case ERROR_MARK: |
| 5736 |
return NULL; |
| 5737 |
|
| 5738 |
/* Vector stuff. For most of the codes we don't have rtl codes. */ |
| 5739 |
case REALIGN_LOAD_EXPR: |
| 5740 |
case VEC_COND_EXPR: |
| 5741 |
case VEC_PACK_FIX_TRUNC_EXPR: |
| 5742 |
case VEC_PACK_FLOAT_EXPR: |
| 5743 |
case VEC_PACK_SAT_EXPR: |
| 5744 |
case VEC_PACK_TRUNC_EXPR: |
| 5745 |
case VEC_UNPACK_FIX_TRUNC_HI_EXPR: |
| 5746 |
case VEC_UNPACK_FIX_TRUNC_LO_EXPR: |
| 5747 |
case VEC_UNPACK_FLOAT_HI_EXPR: |
| 5748 |
case VEC_UNPACK_FLOAT_LO_EXPR: |
| 5749 |
case VEC_UNPACK_HI_EXPR: |
| 5750 |
case VEC_UNPACK_LO_EXPR: |
| 5751 |
case VEC_WIDEN_MULT_HI_EXPR: |
| 5752 |
case VEC_WIDEN_MULT_LO_EXPR: |
| 5753 |
case VEC_WIDEN_MULT_EVEN_EXPR: |
| 5754 |
case VEC_WIDEN_MULT_ODD_EXPR: |
| 5755 |
case VEC_WIDEN_LSHIFT_HI_EXPR: |
| 5756 |
case VEC_WIDEN_LSHIFT_LO_EXPR: |
| 5757 |
case VEC_PERM_EXPR: |
| 5758 |
case VEC_DUPLICATE_EXPR: |
| 5759 |
case VEC_SERIES_EXPR: |
| 5760 |
case SAD_EXPR: |
| 5761 |
return NULL; |
| 5762 |
|
| 5763 |
/* Misc codes. */ |
| 5764 |
case ADDR_SPACE_CONVERT_EXPR: |
| 5765 |
case FIXED_CONVERT_EXPR: |
| 5766 |
case OBJ_TYPE_REF: |
| 5767 |
case WITH_SIZE_EXPR: |
| 5768 |
case BIT_INSERT_EXPR: |
| 5769 |
return NULL; |
| 5770 |
|
| 5771 |
case DOT_PROD_EXPR: |
| 5772 |
if (SCALAR_INT_MODE_P (GET_MODE (op0)) |
| 5773 |
&& SCALAR_INT_MODE_P (mode)) |
| 5774 |
{ |
| 5775 |
op0 |
| 5776 |
= simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, |
| 5777 |
0))) |
| 5778 |
? ZERO_EXTEND : SIGN_EXTEND, mode, op0, |
| 5779 |
inner_mode); |
| 5780 |
op1 |
| 5781 |
= simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, |
| 5782 |
1))) |
| 5783 |
? ZERO_EXTEND : SIGN_EXTEND, mode, op1, |
| 5784 |
inner_mode); |
| 5785 |
op0 = simplify_gen_binary (MULT, mode, op0, op1); |
| 5786 |
return simplify_gen_binary (PLUS, mode, op0, op2); |
| 5787 |
} |
| 5788 |
return NULL; |
| 5789 |
|
| 5790 |
case WIDEN_MULT_EXPR: |
| 5791 |
case WIDEN_MULT_PLUS_EXPR: |
| 5792 |
case WIDEN_MULT_MINUS_EXPR: |
| 5793 |
if (SCALAR_INT_MODE_P (GET_MODE (op0)) |
| 5794 |
&& SCALAR_INT_MODE_P (mode)) |
| 5795 |
{ |
| 5796 |
inner_mode = GET_MODE (op0); |
| 5797 |
if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)))) |
| 5798 |
op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode); |
| 5799 |
else |
| 5800 |
op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode); |
| 5801 |
if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1)))) |
| 5802 |
op1 = simplify_gen_unary (ZERO_EXTEND, mode, op1, inner_mode); |
| 5803 |
else |
| 5804 |
op1 = simplify_gen_unary (SIGN_EXTEND, mode, op1, inner_mode); |
| 5805 |
op0 = simplify_gen_binary (MULT, mode, op0, op1); |
| 5806 |
if (TREE_CODE (exp) == WIDEN_MULT_EXPR) |
| 5807 |
return op0; |
| 5808 |
else if (TREE_CODE (exp) == WIDEN_MULT_PLUS_EXPR) |
| 5809 |
return simplify_gen_binary (PLUS, mode, op0, op2); |
| 5810 |
else |
| 5811 |
return simplify_gen_binary (MINUS, mode, op2, op0); |
| 5812 |
} |
| 5813 |
return NULL; |
| 5814 |
|
| 5815 |
case MULT_HIGHPART_EXPR: |
| 5816 |
/* ??? Similar to the above. */ |
| 5817 |
return NULL; |
| 5818 |
|
| 5819 |
case WIDEN_SUM_EXPR: |
| 5820 |
case WIDEN_LSHIFT_EXPR: |
| 5821 |
if (SCALAR_INT_MODE_P (GET_MODE (op0)) |
| 5822 |
&& SCALAR_INT_MODE_P (mode)) |
| 5823 |
{ |
| 5824 |
op0 |
| 5825 |
= simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, |
| 5826 |
0))) |
| 5827 |
? ZERO_EXTEND : SIGN_EXTEND, mode, op0, |
| 5828 |
inner_mode); |
| 5829 |
return simplify_gen_binary (TREE_CODE (exp) == WIDEN_LSHIFT_EXPR |
| 5830 |
? ASHIFT : PLUS, mode, op0, op1); |
| 5831 |
} |
| 5832 |
return NULL; |
| 5833 |
|
| 5834 |
default: |
| 5835 |
flag_unsupported: |
| 5836 |
if (flag_checking) |
| 5837 |
{ |
| 5838 |
debug_tree (exp); |
| 5839 |
gcc_unreachable (); |
| 5840 |
} |
| 5841 |
return NULL; |
| 5842 |
} |
| 5843 |
} |
| 5844 |
|
| 5845 |
/* Return an RTX equivalent to the source bind value of the tree expression |
| 5846 |
EXP. */ |
| 5847 |
|
| 5848 |
static rtx |
| 5849 |
expand_debug_source_expr (tree exp) |
| 5850 |
{ |
| 5851 |
rtx op0 = NULL_RTX; |
| 5852 |
machine_mode mode = VOIDmode, inner_mode; |
| 5853 |
|
| 5854 |
switch (TREE_CODE (exp)) |
| 5855 |
{ |
| 5856 |
case VAR_DECL: |
| 5857 |
if (DECL_ABSTRACT_ORIGIN (exp)) |
| 5858 |
return expand_debug_source_expr (DECL_ABSTRACT_ORIGIN (exp)); |
| 5859 |
break; |
| 5860 |
case PARM_DECL: |
| 5861 |
{ |
| 5862 |
mode = DECL_MODE (exp); |
| 5863 |
op0 = expand_debug_parm_decl (exp); |
| 5864 |
if (op0) |
| 5865 |
break; |
| 5866 |
/* See if this isn't an argument that has been completely |
| 5867 |
optimized out. */ |
| 5868 |
if (!DECL_RTL_SET_P (exp) |
| 5869 |
&& !DECL_INCOMING_RTL (exp) |
| 5870 |
&& DECL_ABSTRACT_ORIGIN (current_function_decl)) |
| 5871 |
{ |
| 5872 |
tree aexp = DECL_ORIGIN (exp); |
| 5873 |
if (DECL_CONTEXT (aexp) |
| 5874 |
== DECL_ABSTRACT_ORIGIN (current_function_decl)) |
| 5875 |
{ |
| 5876 |
vec<tree, va_gc> **debug_args; |
| 5877 |
unsigned int ix; |
| 5878 |
tree ddecl; |
| 5879 |
debug_args = decl_debug_args_lookup (current_function_decl); |
| 5880 |
if (debug_args != NULL) |
| 5881 |
{ |
| 5882 |
for (ix = 0; vec_safe_iterate (*debug_args, ix, &ddecl); |
| 5883 |
ix += 2) |
| 5884 |
if (ddecl == aexp) |
| 5885 |
return gen_rtx_DEBUG_PARAMETER_REF (mode, aexp); |
| 5886 |
} |
| 5887 |
} |
| 5888 |
} |
| 5889 |
break; |
| 5890 |
} |
| 5891 |
default: |
| 5892 |
break; |
| 5893 |
} |
| 5894 |
|
| 5895 |
if (op0 == NULL_RTX) |
| 5896 |
return NULL_RTX; |
| 5897 |
|
| 5898 |
inner_mode = GET_MODE (op0); |
| 5899 |
if (mode == inner_mode) |
| 5900 |
return op0; |
| 5901 |
|
| 5902 |
if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode)) |
| 5903 |
{ |
| 5904 |
if (GET_MODE_UNIT_BITSIZE (mode) |
| 5905 |
== GET_MODE_UNIT_BITSIZE (inner_mode)) |
| 5906 |
op0 = simplify_gen_subreg (mode, op0, inner_mode, 0); |
| 5907 |
else if (GET_MODE_UNIT_BITSIZE (mode) |
| 5908 |
< GET_MODE_UNIT_BITSIZE (inner_mode)) |
| 5909 |
op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode); |
| 5910 |
else |
| 5911 |
op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode); |
| 5912 |
} |
| 5913 |
else if (FLOAT_MODE_P (mode)) |
| 5914 |
gcc_unreachable (); |
| 5915 |
else if (FLOAT_MODE_P (inner_mode)) |
| 5916 |
{ |
| 5917 |
if (TYPE_UNSIGNED (TREE_TYPE (exp))) |
| 5918 |
op0 = simplify_gen_unary (UNSIGNED_FIX, mode, op0, inner_mode); |
| 5919 |
else |
| 5920 |
op0 = simplify_gen_unary (FIX, mode, op0, inner_mode); |
| 5921 |
} |
| 5922 |
else if (GET_MODE_UNIT_PRECISION (mode) |
| 5923 |
== GET_MODE_UNIT_PRECISION (inner_mode)) |
| 5924 |
op0 = lowpart_subreg (mode, op0, inner_mode); |
| 5925 |
else if (GET_MODE_UNIT_PRECISION (mode) |
| 5926 |
< GET_MODE_UNIT_PRECISION (inner_mode)) |
| 5927 |
op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode); |
| 5928 |
else if (TYPE_UNSIGNED (TREE_TYPE (exp))) |
| 5929 |
op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode); |
| 5930 |
else |
| 5931 |
op0 = simplify_gen_unary (SIGN_EXTEND, mode, op0, inner_mode); |
| 5932 |
|
| 5933 |
return op0; |
| 5934 |
} |
| 5935 |
|
| 5936 |
/* Ensure INSN_VAR_LOCATION_LOC (insn) doesn't have unbound complexity. |
| 5937 |
Allow 4 levels of rtl nesting for most rtl codes, and if we see anything |
| 5938 |
deeper than that, create DEBUG_EXPRs and emit DEBUG_INSNs before INSN. */ |
| 5939 |
|
| 5940 |
static void |
| 5941 |
avoid_complex_debug_insns (rtx_insn *insn, rtx *exp_p, int depth) |
| 5942 |
{ |
| 5943 |
rtx exp = *exp_p; |
| 5944 |
|
| 5945 |
if (exp == NULL_RTX) |
| 5946 |
return; |
| 5947 |
|
| 5948 |
if ((OBJECT_P (exp) && !MEM_P (exp)) || GET_CODE (exp) == CLOBBER) |
| 5949 |
return; |
| 5950 |
|
| 5951 |
if (depth == 4) |
| 5952 |
{ |
| 5953 |
/* Create DEBUG_EXPR (and DEBUG_EXPR_DECL). */ |
| 5954 |
rtx dval = make_debug_expr_from_rtl (exp); |
| 5955 |
|
| 5956 |
/* Emit a debug bind insn before INSN. */ |
| 5957 |
rtx bind = gen_rtx_VAR_LOCATION (GET_MODE (exp), |
| 5958 |
DEBUG_EXPR_TREE_DECL (dval), exp, |
| 5959 |
VAR_INIT_STATUS_INITIALIZED); |
| 5960 |
|
| 5961 |
emit_debug_insn_before (bind, insn); |
| 5962 |
*exp_p = dval; |
| 5963 |
return; |
| 5964 |
} |
| 5965 |
|
| 5966 |
const char *format_ptr = GET_RTX_FORMAT (GET_CODE (exp)); |
| 5967 |
int i, j; |
| 5968 |
for (i = 0; i < GET_RTX_LENGTH (GET_CODE (exp)); i++) |
| 5969 |
switch (*format_ptr++) |
| 5970 |
{ |
| 5971 |
case 'e': |
| 5972 |
avoid_complex_debug_insns (insn, &XEXP (exp, i), depth + 1); |
| 5973 |
break; |
| 5974 |
|
| 5975 |
case 'E': |
| 5976 |
case 'V': |
| 5977 |
for (j = 0; j < XVECLEN (exp, i); j++) |
| 5978 |
avoid_complex_debug_insns (insn, &XVECEXP (exp, i, j), depth + 1); |
| 5979 |
break; |
| 5980 |
|
| 5981 |
default: |
| 5982 |
break; |
| 5983 |
} |
| 5984 |
} |
| 5985 |
|
| 5986 |
/* Expand the _LOCs in debug insns. We run this after expanding all |
| 5987 |
regular insns, so that any variables referenced in the function |
| 5988 |
will have their DECL_RTLs set. */ |
| 5989 |
|
| 5990 |
static void |
| 5991 |
expand_debug_locations (void) |
| 5992 |
{ |
| 5993 |
rtx_insn *insn; |
| 5994 |
rtx_insn *last = get_last_insn (); |
| 5995 |
int save_strict_alias = flag_strict_aliasing; |
| 5996 |
|
| 5997 |
/* New alias sets while setting up memory attributes cause |
| 5998 |
-fcompare-debug failures, even though it doesn't bring about any |
| 5999 |
codegen changes. */ |
| 6000 |
flag_strict_aliasing = 0; |
| 6001 |
|
| 6002 |
for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
| 6003 |
if (DEBUG_BIND_INSN_P (insn)) |
| 6004 |
{ |
| 6005 |
tree value = (tree)INSN_VAR_LOCATION_LOC (insn); |
| 6006 |
rtx val; |
| 6007 |
rtx_insn *prev_insn, *insn2; |
| 6008 |
machine_mode mode; |
| 6009 |
|
| 6010 |
if (value == NULL_TREE) |
| 6011 |
val = NULL_RTX; |
| 6012 |
else |
| 6013 |
{ |
| 6014 |
if (INSN_VAR_LOCATION_STATUS (insn) |
| 6015 |
== VAR_INIT_STATUS_UNINITIALIZED) |
| 6016 |
val = expand_debug_source_expr (value); |
| 6017 |
/* The avoid_deep_ter_for_debug function inserts |
| 6018 |
debug bind stmts after SSA_NAME definition, with the |
| 6019 |
SSA_NAME as the whole bind location. Disable temporarily |
| 6020 |
expansion of that SSA_NAME into the DEBUG_EXPR_DECL |
| 6021 |
being defined in this DEBUG_INSN. */ |
| 6022 |
else if (deep_ter_debug_map && TREE_CODE (value) == SSA_NAME) |
| 6023 |
{ |
| 6024 |
tree *slot = deep_ter_debug_map->get (value); |
| 6025 |
if (slot) |
| 6026 |
{ |
| 6027 |
if (*slot == INSN_VAR_LOCATION_DECL (insn)) |
| 6028 |
*slot = NULL_TREE; |
| 6029 |
else |
| 6030 |
slot = NULL; |
| 6031 |
} |
| 6032 |
val = expand_debug_expr (value); |
| 6033 |
if (slot) |
| 6034 |
*slot = INSN_VAR_LOCATION_DECL (insn); |
| 6035 |
} |
| 6036 |
else |
| 6037 |
val = expand_debug_expr (value); |
| 6038 |
gcc_assert (last == get_last_insn ()); |
| 6039 |
} |
| 6040 |
|
| 6041 |
if (!val) |
| 6042 |
val = gen_rtx_UNKNOWN_VAR_LOC (); |
| 6043 |
else |
| 6044 |
{ |
| 6045 |
mode = GET_MODE (INSN_VAR_LOCATION (insn)); |
| 6046 |
|
| 6047 |
gcc_assert (mode == GET_MODE (val) |
| 6048 |
|| (GET_MODE (val) == VOIDmode |
| 6049 |
&& (CONST_SCALAR_INT_P (val) |
| 6050 |
|| GET_CODE (val) == CONST_FIXED |
| 6051 |
|| GET_CODE (val) == LABEL_REF))); |
| 6052 |
} |
| 6053 |
|
| 6054 |
INSN_VAR_LOCATION_LOC (insn) = val; |
| 6055 |
prev_insn = PREV_INSN (insn); |
| 6056 |
for (insn2 = insn; insn2 != prev_insn; insn2 = PREV_INSN (insn2)) |
| 6057 |
avoid_complex_debug_insns (insn2, &INSN_VAR_LOCATION_LOC (insn2), 0); |
| 6058 |
} |
| 6059 |
|
| 6060 |
flag_strict_aliasing = save_strict_alias; |
| 6061 |
} |
| 6062 |
|
| 6063 |
/* Performs swapping operands of commutative operations to expand |
| 6064 |
the expensive one first. */ |
| 6065 |
|
| 6066 |
static void |
| 6067 |
reorder_operands (basic_block bb) |
| 6068 |
{ |
| 6069 |
unsigned int *lattice; /* Hold cost of each statement. */ |
| 6070 |
unsigned int i = 0, n = 0; |
| 6071 |
gimple_stmt_iterator gsi; |
| 6072 |
gimple_seq stmts; |
| 6073 |
gimple *stmt; |
| 6074 |
bool swap; |
| 6075 |
tree op0, op1; |
| 6076 |
ssa_op_iter iter; |
| 6077 |
use_operand_p use_p; |
| 6078 |
gimple *def0, *def1; |
| 6079 |
|
| 6080 |
/* Compute cost of each statement using estimate_num_insns. */ |
| 6081 |
stmts = bb_seq (bb); |
| 6082 |
for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi)) |
| 6083 |
{ |
| 6084 |
stmt = gsi_stmt (gsi); |
| 6085 |
if (!is_gimple_debug (stmt)) |
| 6086 |
gimple_set_uid (stmt, n++); |
| 6087 |
} |
| 6088 |
lattice = XNEWVEC (unsigned int, n); |
| 6089 |
for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi)) |
| 6090 |
{ |
| 6091 |
unsigned cost; |
| 6092 |
stmt = gsi_stmt (gsi); |
| 6093 |
if (is_gimple_debug (stmt)) |
| 6094 |
continue; |
| 6095 |
cost = estimate_num_insns (stmt, &eni_size_weights); |
| 6096 |
lattice[i] = cost; |
| 6097 |
FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE) |
| 6098 |
{ |
| 6099 |
tree use = USE_FROM_PTR (use_p); |
| 6100 |
gimple *def_stmt; |
| 6101 |
if (TREE_CODE (use) != SSA_NAME) |
| 6102 |
continue; |
| 6103 |
def_stmt = get_gimple_for_ssa_name (use); |
| 6104 |
if (!def_stmt) |
| 6105 |
continue; |
| 6106 |
lattice[i] += lattice[gimple_uid (def_stmt)]; |
| 6107 |
} |
| 6108 |
i++; |
| 6109 |
if (!is_gimple_assign (stmt) |
| 6110 |
|| !commutative_tree_code (gimple_assign_rhs_code (stmt))) |
| 6111 |
continue; |
| 6112 |
op0 = gimple_op (stmt, 1); |
| 6113 |
op1 = gimple_op (stmt, 2); |
| 6114 |
if (TREE_CODE (op0) != SSA_NAME |
| 6115 |
|| TREE_CODE (op1) != SSA_NAME) |
| 6116 |
continue; |
| 6117 |
/* Swap operands if the second one is more expensive. */ |
| 6118 |
def0 = get_gimple_for_ssa_name (op0); |
| 6119 |
def1 = get_gimple_for_ssa_name (op1); |
| 6120 |
if (!def1) |
| 6121 |
continue; |
| 6122 |
swap = false; |
| 6123 |
if (!def0 || lattice[gimple_uid (def1)] > lattice[gimple_uid (def0)]) |
| 6124 |
swap = true; |
| 6125 |
if (swap) |
| 6126 |
{ |
| 6127 |
if (dump_file && (dump_flags & TDF_DETAILS)) |
| 6128 |
{ |
| 6129 |
fprintf (dump_file, "Swap operands in stmt:\n"); |
| 6130 |
print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); |
| 6131 |
fprintf (dump_file, "Cost left opnd=%d, right opnd=%d\n", |
| 6132 |
def0 ? lattice[gimple_uid (def0)] : 0, |
| 6133 |
lattice[gimple_uid (def1)]); |
| 6134 |
} |
| 6135 |
swap_ssa_operands (stmt, gimple_assign_rhs1_ptr (stmt), |
| 6136 |
gimple_assign_rhs2_ptr (stmt)); |
| 6137 |
} |
| 6138 |
} |
| 6139 |
XDELETE (lattice); |
| 6140 |
} |
| 6141 |
|
| 6142 |
/* Expand basic block BB from GIMPLE trees to RTL. */ |
| 6143 |
|
| 6144 |
static basic_block |
| 6145 |
expand_gimple_basic_block (basic_block bb, rtx_insn *asan_epilog_seq) |
| 6146 |
{ |
| 6147 |
gimple_stmt_iterator gsi; |
| 6148 |
gimple_seq stmts; |
| 6149 |
gimple *stmt = NULL; |
| 6150 |
rtx_note *note = NULL; |
| 6151 |
rtx_insn *last; |
| 6152 |
edge e; |
| 6153 |
edge_iterator ei; |
| 6154 |
bool nondebug_stmt_seen = false; |
| 6155 |
|
| 6156 |
if (dump_file) |
| 6157 |
fprintf (dump_file, "\n;; Generating RTL for gimple basic block %d\n", |
| 6158 |
bb->index); |
| 6159 |
|
| 6160 |
/* Note that since we are now transitioning from GIMPLE to RTL, we |
| 6161 |
cannot use the gsi_*_bb() routines because they expect the basic |
| 6162 |
block to be in GIMPLE, instead of RTL. Therefore, we need to |
| 6163 |
access the BB sequence directly. */ |
| 6164 |
if (optimize) |
| 6165 |
reorder_operands (bb); |
| 6166 |
stmts = bb_seq (bb); |
| 6167 |
bb->il.gimple.seq = NULL; |
| 6168 |
bb->il.gimple.phi_nodes = NULL; |
| 6169 |
rtl_profile_for_bb (bb); |
| 6170 |
init_rtl_bb_info (bb); |
| 6171 |
bb->flags |= BB_RTL; |
| 6172 |
|
| 6173 |
/* Remove the RETURN_EXPR if we may fall though to the exit |
| 6174 |
instead. */ |
| 6175 |
gsi = gsi_last (stmts); |
| 6176 |
if (!gsi_end_p (gsi) |
| 6177 |
&& gimple_code (gsi_stmt (gsi)) == GIMPLE_RETURN) |
| 6178 |
{ |
| 6179 |
greturn *ret_stmt = as_a <greturn *> (gsi_stmt (gsi)); |
| 6180 |
|
| 6181 |
gcc_assert (single_succ_p (bb)); |
| 6182 |
gcc_assert (single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun)); |
| 6183 |
|
| 6184 |
if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun) |
| 6185 |
&& !gimple_return_retval (ret_stmt)) |
| 6186 |
{ |
| 6187 |
gsi_remove (&gsi, false); |
| 6188 |
single_succ_edge (bb)->flags |= EDGE_FALLTHRU; |
| 6189 |
} |
| 6190 |
} |
| 6191 |
|
| 6192 |
gsi = gsi_start (stmts); |
| 6193 |
if (!gsi_end_p (gsi)) |
| 6194 |
{ |
| 6195 |
stmt = gsi_stmt (gsi); |
| 6196 |
if (gimple_code (stmt) != GIMPLE_LABEL) |
| 6197 |
stmt = NULL; |
| 6198 |
} |
| 6199 |
|
| 6200 |
rtx_code_label **elt = lab_rtx_for_bb->get (bb); |
| 6201 |
|
| 6202 |
if (stmt || elt) |
| 6203 |
{ |
| 6204 |
gcc_checking_assert (!note); |
| 6205 |
last = get_last_insn (); |
| 6206 |
|
| 6207 |
if (stmt) |
| 6208 |
{ |
| 6209 |
expand_gimple_stmt (stmt); |
| 6210 |
gsi_next (&gsi); |
| 6211 |
} |
| 6212 |
|
| 6213 |
if (elt) |
| 6214 |
emit_label (*elt); |
| 6215 |
|
| 6216 |
BB_HEAD (bb) = NEXT_INSN (last); |
| 6217 |
if (NOTE_P (BB_HEAD (bb))) |
| 6218 |
BB_HEAD (bb) = NEXT_INSN (BB_HEAD (bb)); |
| 6219 |
gcc_assert (LABEL_P (BB_HEAD (bb))); |
| 6220 |
note = emit_note_after (NOTE_INSN_BASIC_BLOCK, BB_HEAD (bb)); |
| 6221 |
|
| 6222 |
maybe_dump_rtl_for_gimple_stmt (stmt, last); |
| 6223 |
} |
| 6224 |
else |
| 6225 |
BB_HEAD (bb) = note = emit_note (NOTE_INSN_BASIC_BLOCK); |
| 6226 |
|
| 6227 |
if (note) |
| 6228 |
NOTE_BASIC_BLOCK (note) = bb; |
| 6229 |
|
| 6230 |
for (; !gsi_end_p (gsi); gsi_next (&gsi)) |
| 6231 |
{ |
| 6232 |
basic_block new_bb; |
| 6233 |
|
| 6234 |
stmt = gsi_stmt (gsi); |
| 6235 |
if (!is_gimple_debug (stmt)) |
| 6236 |
nondebug_stmt_seen = true; |
| 6237 |
|
| 6238 |
/* If this statement is a non-debug one, and we generate debug |
| 6239 |
insns, then this one might be the last real use of a TERed |
| 6240 |
SSA_NAME, but where there are still some debug uses further |
| 6241 |
down. Expanding the current SSA name in such further debug |
| 6242 |
uses by their RHS might lead to wrong debug info, as coalescing |
| 6243 |
might make the operands of such RHS be placed into the same |
| 6244 |
pseudo as something else. Like so: |
| 6245 |
a_1 = a_0 + 1; // Assume a_1 is TERed and a_0 is dead |
| 6246 |
use(a_1); |
| 6247 |
a_2 = ... |
| 6248 |
#DEBUG ... => a_1 |
| 6249 |
As a_0 and a_2 don't overlap in lifetime, assume they are coalesced. |
| 6250 |
If we now would expand a_1 by it's RHS (a_0 + 1) in the debug use, |
| 6251 |
the write to a_2 would actually have clobbered the place which |
| 6252 |
formerly held a_0. |
| 6253 |
|
| 6254 |
So, instead of that, we recognize the situation, and generate |
| 6255 |
debug temporaries at the last real use of TERed SSA names: |
| 6256 |
a_1 = a_0 + 1; |
| 6257 |
#DEBUG #D1 => a_1 |
| 6258 |
use(a_1); |
| 6259 |
a_2 = ... |
| 6260 |
#DEBUG ... => #D1 |
| 6261 |
*/ |
| 6262 |
if (MAY_HAVE_DEBUG_BIND_INSNS |
| 6263 |
&& SA.values |
| 6264 |
&& !is_gimple_debug (stmt)) |
| 6265 |
{ |
| 6266 |
ssa_op_iter iter; |
| 6267 |
tree op; |
| 6268 |
gimple *def; |
| 6269 |
|
| 6270 |
location_t sloc = curr_insn_location (); |
| 6271 |
|
| 6272 |
/* Look for SSA names that have their last use here (TERed |
| 6273 |
names always have only one real use). */ |
| 6274 |
FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE) |
| 6275 |
if ((def = get_gimple_for_ssa_name (op)) |
| 6276 |
&& is_gimple_assign (def)) |
| 6277 |
{ |
| 6278 |
imm_use_iterator imm_iter; |
| 6279 |
use_operand_p use_p; |
| 6280 |
bool have_debug_uses = false; |
| 6281 |
|
| 6282 |
FOR_EACH_IMM_USE_FAST (use_p, imm_iter, op) |
| 6283 |
{ |
| 6284 |
if (gimple_debug_bind_p (USE_STMT (use_p))) |
| 6285 |
{ |
| 6286 |
have_debug_uses = true; |
| 6287 |
break; |
| 6288 |
} |
| 6289 |
} |
| 6290 |
|
| 6291 |
if (have_debug_uses) |
| 6292 |
{ |
| 6293 |
/* OP is a TERed SSA name, with DEF its defining |
| 6294 |
statement, and where OP is used in further debug |
| 6295 |
instructions. Generate a debug temporary, and |
| 6296 |
replace all uses of OP in debug insns with that |
| 6297 |
temporary. */ |
| 6298 |
gimple *debugstmt; |
| 6299 |
tree value = gimple_assign_rhs_to_tree (def); |
| 6300 |
tree vexpr = build_debug_expr_decl (TREE_TYPE (value)); |
| 6301 |
rtx val; |
| 6302 |
machine_mode mode; |
| 6303 |
|
| 6304 |
set_curr_insn_location (gimple_location (def)); |
| 6305 |
|
| 6306 |
if (DECL_P (value)) |
| 6307 |
mode = DECL_MODE (value); |
| 6308 |
else |
| 6309 |
mode = TYPE_MODE (TREE_TYPE (value)); |
| 6310 |
/* FIXME: Is setting the mode really necessary? */ |
| 6311 |
SET_DECL_MODE (vexpr, mode); |
| 6312 |
|
| 6313 |
val = gen_rtx_VAR_LOCATION |
| 6314 |
(mode, vexpr, (rtx)value, VAR_INIT_STATUS_INITIALIZED); |
| 6315 |
|
| 6316 |
emit_debug_insn (val); |
| 6317 |
|
| 6318 |
FOR_EACH_IMM_USE_STMT (debugstmt, imm_iter, op) |
| 6319 |
{ |
| 6320 |
if (!gimple_debug_bind_p (debugstmt)) |
| 6321 |
continue; |
| 6322 |
|
| 6323 |
FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter) |
| 6324 |
SET_USE (use_p, vexpr); |
| 6325 |
|
| 6326 |
update_stmt (debugstmt); |
| 6327 |
} |
| 6328 |
} |
| 6329 |
} |
| 6330 |
set_curr_insn_location (sloc); |
| 6331 |
} |
| 6332 |
|
| 6333 |
currently_expanding_gimple_stmt = stmt; |
| 6334 |
|
| 6335 |
/* Expand this statement, then evaluate the resulting RTL and |
| 6336 |
fixup the CFG accordingly. */ |
| 6337 |
if (gimple_code (stmt) == GIMPLE_COND) |
| 6338 |
{ |
| 6339 |
new_bb = expand_gimple_cond (bb, as_a <gcond *> (stmt)); |
| 6340 |
if (new_bb) |
| 6341 |
{ |
| 6342 |
currently_expanding_gimple_stmt = NULL; |
| 6343 |
return new_bb; |
| 6344 |
} |
| 6345 |
} |
| 6346 |
else if (is_gimple_debug (stmt)) |
| 6347 |
{ |
| 6348 |
location_t sloc = curr_insn_location (); |
| 6349 |
gimple_stmt_iterator nsi = gsi; |
| 6350 |
|
| 6351 |
for (;;) |
| 6352 |
{ |
| 6353 |
tree var; |
| 6354 |
tree value = NULL_TREE; |
| 6355 |
rtx val = NULL_RTX; |
| 6356 |
machine_mode mode; |
| 6357 |
|
| 6358 |
if (!gimple_debug_nonbind_marker_p (stmt)) |
| 6359 |
{ |
| 6360 |
if (gimple_debug_bind_p (stmt)) |
| 6361 |
{ |
| 6362 |
var = gimple_debug_bind_get_var (stmt); |
| 6363 |
|
| 6364 |
if (TREE_CODE (var) != DEBUG_EXPR_DECL |
| 6365 |
&& TREE_CODE (var) != LABEL_DECL |
| 6366 |
&& !target_for_debug_bind (var)) |
| 6367 |
goto delink_debug_stmt; |
| 6368 |
|
| 6369 |
if (DECL_P (var) && !VECTOR_TYPE_P (TREE_TYPE (var))) |
| 6370 |
mode = DECL_MODE (var); |
| 6371 |
else |
| 6372 |
mode = TYPE_MODE (TREE_TYPE (var)); |
| 6373 |
|
| 6374 |
if (gimple_debug_bind_has_value_p (stmt)) |
| 6375 |
value = gimple_debug_bind_get_value (stmt); |
| 6376 |
|
| 6377 |
val = gen_rtx_VAR_LOCATION |
| 6378 |
(mode, var, (rtx)value, VAR_INIT_STATUS_INITIALIZED); |
| 6379 |
} |
| 6380 |
else if (gimple_debug_source_bind_p (stmt)) |
| 6381 |
{ |
| 6382 |
var = gimple_debug_source_bind_get_var (stmt); |
| 6383 |
|
| 6384 |
value = gimple_debug_source_bind_get_value (stmt); |
| 6385 |
|
| 6386 |
if (!VECTOR_TYPE_P (TREE_TYPE (var))) |
| 6387 |
mode = DECL_MODE (var); |
| 6388 |
else |
| 6389 |
mode = TYPE_MODE (TREE_TYPE (var)); |
| 6390 |
|
| 6391 |
val = gen_rtx_VAR_LOCATION (mode, var, (rtx)value, |
| 6392 |
VAR_INIT_STATUS_UNINITIALIZED); |
| 6393 |
} |
| 6394 |
else |
| 6395 |
gcc_unreachable (); |
| 6396 |
} |
| 6397 |
/* If this function was first compiled with markers |
| 6398 |
enabled, but they're now disable (e.g. LTO), drop |
| 6399 |
them on the floor. */ |
| 6400 |
else if (gimple_debug_nonbind_marker_p (stmt) |
| 6401 |
&& !MAY_HAVE_DEBUG_MARKER_INSNS) |
| 6402 |
goto delink_debug_stmt; |
| 6403 |
else if (gimple_debug_begin_stmt_p (stmt)) |
| 6404 |
val = GEN_RTX_DEBUG_MARKER_BEGIN_STMT_PAT (); |
| 6405 |
else if (gimple_debug_inline_entry_p (stmt)) |
| 6406 |
val = GEN_RTX_DEBUG_MARKER_INLINE_ENTRY_PAT (); |
| 6407 |
else |
| 6408 |
gcc_unreachable (); |
| 6409 |
|
| 6410 |
last = get_last_insn (); |
| 6411 |
|
| 6412 |
set_curr_insn_location (gimple_location (stmt)); |
| 6413 |
|
| 6414 |
emit_debug_insn (val); |
| 6415 |
|
| 6416 |
if (dump_file && (dump_flags & TDF_DETAILS)) |
| 6417 |
{ |
| 6418 |
/* We can't dump the insn with a TREE where an RTX |
| 6419 |
is expected. */ |
| 6420 |
if (GET_CODE (val) == VAR_LOCATION) |
| 6421 |
{ |
| 6422 |
gcc_checking_assert (PAT_VAR_LOCATION_LOC (val) == (rtx)value); |
| 6423 |
PAT_VAR_LOCATION_LOC (val) = const0_rtx; |
| 6424 |
} |
| 6425 |
maybe_dump_rtl_for_gimple_stmt (stmt, last); |
| 6426 |
if (GET_CODE (val) == VAR_LOCATION) |
| 6427 |
PAT_VAR_LOCATION_LOC (val) = (rtx)value; |
| 6428 |
} |
| 6429 |
|
| 6430 |
delink_debug_stmt: |
| 6431 |
/* In order not to generate too many debug temporaries, |
| 6432 |
we delink all uses of debug statements we already expanded. |
| 6433 |
Therefore debug statements between definition and real |
| 6434 |
use of TERed SSA names will continue to use the SSA name, |
| 6435 |
and not be replaced with debug temps. */ |
| 6436 |
delink_stmt_imm_use (stmt); |
| 6437 |
|
| 6438 |
gsi = nsi; |
| 6439 |
gsi_next (&nsi); |
| 6440 |
if (gsi_end_p (nsi)) |
| 6441 |
break; |
| 6442 |
stmt = gsi_stmt (nsi); |
| 6443 |
if (!is_gimple_debug (stmt)) |
| 6444 |
break; |
| 6445 |
} |
| 6446 |
|
| 6447 |
set_curr_insn_location (sloc); |
| 6448 |
} |
| 6449 |
else |
| 6450 |
{ |
| 6451 |
gcall *call_stmt = dyn_cast <gcall *> (stmt); |
| 6452 |
if (call_stmt |
| 6453 |
&& asan_epilog_seq |
| 6454 |
&& gimple_call_tail_p (call_stmt) |
| 6455 |
&& !gimple_call_must_tail_p (call_stmt)) |
| 6456 |
gimple_call_set_tail (call_stmt, false); |
| 6457 |
|
| 6458 |
if (call_stmt && gimple_call_tail_p (call_stmt)) |
| 6459 |
{ |
| 6460 |
bool can_fallthru; |
| 6461 |
new_bb = expand_gimple_tailcall (bb, call_stmt, &can_fallthru, |
| 6462 |
asan_epilog_seq); |
| 6463 |
if (new_bb) |
| 6464 |
{ |
| 6465 |
if (can_fallthru) |
| 6466 |
bb = new_bb; |
| 6467 |
else |
| 6468 |
{ |
| 6469 |
currently_expanding_gimple_stmt = NULL; |
| 6470 |
return new_bb; |
| 6471 |
} |
| 6472 |
} |
| 6473 |
} |
| 6474 |
else |
| 6475 |
{ |
| 6476 |
def_operand_p def_p; |
| 6477 |
def_p = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_DEF); |
| 6478 |
|
| 6479 |
if (def_p != NULL) |
| 6480 |
{ |
| 6481 |
/* Ignore this stmt if it is in the list of |
| 6482 |
replaceable expressions. */ |
| 6483 |
if (SA.values |
| 6484 |
&& bitmap_bit_p (SA.values, |
| 6485 |
SSA_NAME_VERSION (DEF_FROM_PTR (def_p)))) |
| 6486 |
continue; |
| 6487 |
} |
| 6488 |
last = expand_gimple_stmt (stmt); |
| 6489 |
maybe_dump_rtl_for_gimple_stmt (stmt, last); |
| 6490 |
} |
| 6491 |
} |
| 6492 |
} |
| 6493 |
|
| 6494 |
currently_expanding_gimple_stmt = NULL; |
| 6495 |
|
| 6496 |
/* Expand implicit goto and convert goto_locus. */ |
| 6497 |
FOR_EACH_EDGE (e, ei, bb->succs) |
| 6498 |
{ |
| 6499 |
if (e->goto_locus != UNKNOWN_LOCATION || !nondebug_stmt_seen) |
| 6500 |
set_curr_insn_location (e->goto_locus); |
| 6501 |
if ((e->flags & EDGE_FALLTHRU) && e->dest != bb->next_bb) |
| 6502 |
{ |
| 6503 |
emit_jump (label_rtx_for_bb (e->dest)); |
| 6504 |
e->flags &= ~EDGE_FALLTHRU; |
| 6505 |
} |
| 6506 |
} |
| 6507 |
|
| 6508 |
/* Expanded RTL can create a jump in the last instruction of block. |
| 6509 |
This later might be assumed to be a jump to successor and break edge insertion. |
| 6510 |
We need to insert dummy move to prevent this. PR41440. */ |
| 6511 |
if (single_succ_p (bb) |
| 6512 |
&& (single_succ_edge (bb)->flags & EDGE_FALLTHRU) |
| 6513 |
&& (last = get_last_insn ()) |
| 6514 |
&& (JUMP_P (last) |
| 6515 |
|| (DEBUG_INSN_P (last) |
| 6516 |
&& JUMP_P (prev_nondebug_insn (last))))) |
| 6517 |
{ |
| 6518 |
rtx dummy = gen_reg_rtx (SImode); |
| 6519 |
emit_insn_after_noloc (gen_move_insn (dummy, dummy), last, NULL); |
| 6520 |
} |
| 6521 |
|
| 6522 |
/* A __builtin_unreachable () will insert a barrier that should end |
| 6523 |
the basic block. In gimple, any code after it will have already |
| 6524 |
deleted, even without optimization. If we emit additional code |
| 6525 |
here, as we would to adjust the stack after a call, it should be |
| 6526 |
eventually deleted, but it confuses internal checkers (PR118006) |
| 6527 |
and optimizers before it does, because we don't expect to find |
| 6528 |
barriers inside basic blocks. */ |
| 6529 |
if (!BARRIER_P (get_last_insn ())) |
| 6530 |
do_pending_stack_adjust (); |
| 6531 |
else |
| 6532 |
discard_pending_stack_adjust (); |
| 6533 |
|
| 6534 |
/* Find the block tail. The last insn in the block is the insn |
| 6535 |
before a barrier and/or table jump insn. */ |
| 6536 |
last = get_last_insn (); |
| 6537 |
if (BARRIER_P (last)) |
| 6538 |
last = PREV_INSN (last); |
| 6539 |
if (JUMP_TABLE_DATA_P (last)) |
| 6540 |
last = PREV_INSN (PREV_INSN (last)); |
| 6541 |
if (BARRIER_P (last)) |
| 6542 |
last = PREV_INSN (last); |
| 6543 |
BB_END (bb) = last; |
| 6544 |
|
| 6545 |
update_bb_for_insn (bb); |
| 6546 |
|
| 6547 |
return bb; |
| 6548 |
} |
| 6549 |
|
| 6550 |
|
| 6551 |
/* Create a basic block for initialization code. */ |
| 6552 |
|
| 6553 |
static basic_block |
| 6554 |
construct_init_block (void) |
| 6555 |
{ |
| 6556 |
basic_block init_block, first_block; |
| 6557 |
edge e = NULL; |
| 6558 |
int flags; |
| 6559 |
|
| 6560 |
/* Multiple entry points not supported yet. */ |
| 6561 |
gcc_assert (EDGE_COUNT (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs) == 1); |
| 6562 |
init_rtl_bb_info (ENTRY_BLOCK_PTR_FOR_FN (cfun)); |
| 6563 |
init_rtl_bb_info (EXIT_BLOCK_PTR_FOR_FN (cfun)); |
| 6564 |
ENTRY_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL; |
| 6565 |
EXIT_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL; |
| 6566 |
|
| 6567 |
e = EDGE_SUCC (ENTRY_BLOCK_PTR_FOR_FN (cfun), 0); |
| 6568 |
|
| 6569 |
/* When entry edge points to first basic block, we don't need jump, |
| 6570 |
otherwise we have to jump into proper target. */ |
| 6571 |
if (e && e->dest != ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb) |
| 6572 |
{ |
| 6573 |
tree label = gimple_block_label (e->dest); |
| 6574 |
|
| 6575 |
emit_jump (jump_target_rtx (label)); |
| 6576 |
flags = 0; |
| 6577 |
} |
| 6578 |
else |
| 6579 |
flags = EDGE_FALLTHRU; |
| 6580 |
|
| 6581 |
init_block = create_basic_block (NEXT_INSN (get_insns ()), |
| 6582 |
get_last_insn (), |
| 6583 |
ENTRY_BLOCK_PTR_FOR_FN (cfun)); |
| 6584 |
init_block->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; |
| 6585 |
add_bb_to_loop (init_block, ENTRY_BLOCK_PTR_FOR_FN (cfun)->loop_father); |
| 6586 |
if (e) |
| 6587 |
{ |
| 6588 |
first_block = e->dest; |
| 6589 |
redirect_edge_succ (e, init_block); |
| 6590 |
make_single_succ_edge (init_block, first_block, flags); |
| 6591 |
} |
| 6592 |
else |
| 6593 |
make_single_succ_edge (init_block, EXIT_BLOCK_PTR_FOR_FN (cfun), |
| 6594 |
EDGE_FALLTHRU); |
| 6595 |
|
| 6596 |
update_bb_for_insn (init_block); |
| 6597 |
return init_block; |
| 6598 |
} |
| 6599 |
|
| 6600 |
/* For each lexical block, set BLOCK_NUMBER to the depth at which it is |
| 6601 |
found in the block tree. */ |
| 6602 |
|
| 6603 |
static void |
| 6604 |
set_block_levels (tree block, int level) |
| 6605 |
{ |
| 6606 |
while (block) |
| 6607 |
{ |
| 6608 |
BLOCK_NUMBER (block) = level; |
| 6609 |
set_block_levels (BLOCK_SUBBLOCKS (block), level + 1); |
| 6610 |
block = BLOCK_CHAIN (block); |
| 6611 |
} |
| 6612 |
} |
| 6613 |
|
| 6614 |
/* Create a block containing landing pads and similar stuff. */ |
| 6615 |
|
| 6616 |
static void |
| 6617 |
construct_exit_block (void) |
| 6618 |
{ |
| 6619 |
rtx_insn *head = get_last_insn (); |
| 6620 |
rtx_insn *end; |
| 6621 |
basic_block exit_block; |
| 6622 |
edge e, e2; |
| 6623 |
unsigned ix; |
| 6624 |
edge_iterator ei; |
| 6625 |
basic_block prev_bb = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb; |
| 6626 |
rtx_insn *orig_end = BB_END (prev_bb); |
| 6627 |
|
| 6628 |
rtl_profile_for_bb (EXIT_BLOCK_PTR_FOR_FN (cfun)); |
| 6629 |
|
| 6630 |
/* Make sure the locus is set to the end of the function, so that |
| 6631 |
epilogue line numbers and warnings are set properly. */ |
| 6632 |
if (LOCATION_LOCUS (cfun->function_end_locus) != UNKNOWN_LOCATION) |
| 6633 |
input_location = cfun->function_end_locus; |
| 6634 |
|
| 6635 |
/* Generate rtl for function exit. */ |
| 6636 |
expand_function_end (); |
| 6637 |
|
| 6638 |
end = get_last_insn (); |
| 6639 |
if (head == end) |
| 6640 |
return; |
| 6641 |
/* While emitting the function end we could move end of the last basic |
| 6642 |
block. */ |
| 6643 |
BB_END (prev_bb) = orig_end; |
| 6644 |
while (NEXT_INSN (head) && NOTE_P (NEXT_INSN (head))) |
| 6645 |
head = NEXT_INSN (head); |
| 6646 |
/* But make sure exit_block starts with RETURN_LABEL, otherwise the |
| 6647 |
bb count counting will be confused. Any instructions before that |
| 6648 |
label are emitted for the case where PREV_BB falls through into the |
| 6649 |
exit block, so append those instructions to prev_bb in that case. */ |
| 6650 |
if (NEXT_INSN (head) != return_label) |
| 6651 |
{ |
| 6652 |
while (NEXT_INSN (head) != return_label) |
| 6653 |
{ |
| 6654 |
if (!NOTE_P (NEXT_INSN (head))) |
| 6655 |
BB_END (prev_bb) = NEXT_INSN (head); |
| 6656 |
head = NEXT_INSN (head); |
| 6657 |
} |
| 6658 |
} |
| 6659 |
exit_block = create_basic_block (NEXT_INSN (head), end, prev_bb); |
| 6660 |
exit_block->count = EXIT_BLOCK_PTR_FOR_FN (cfun)->count; |
| 6661 |
add_bb_to_loop (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun)->loop_father); |
| 6662 |
|
| 6663 |
ix = 0; |
| 6664 |
while (ix < EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)) |
| 6665 |
{ |
| 6666 |
e = EDGE_PRED (EXIT_BLOCK_PTR_FOR_FN (cfun), ix); |
| 6667 |
if (!(e->flags & EDGE_ABNORMAL)) |
| 6668 |
redirect_edge_succ (e, exit_block); |
| 6669 |
else |
| 6670 |
ix++; |
| 6671 |
} |
| 6672 |
|
| 6673 |
e = make_single_succ_edge (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun), |
| 6674 |
EDGE_FALLTHRU); |
| 6675 |
FOR_EACH_EDGE (e2, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds) |
| 6676 |
if (e2 != e) |
| 6677 |
{ |
| 6678 |
exit_block->count -= e2->count (); |
| 6679 |
} |
| 6680 |
update_bb_for_insn (exit_block); |
| 6681 |
} |
| 6682 |
|
| 6683 |
/* Helper function for discover_nonconstant_array_refs. |
| 6684 |
Look for ARRAY_REF nodes with non-constant indexes and mark them |
| 6685 |
addressable. */ |
| 6686 |
|
| 6687 |
static tree |
| 6688 |
discover_nonconstant_array_refs_r (tree * tp, int *walk_subtrees, |
| 6689 |
void *data) |
| 6690 |
{ |
| 6691 |
tree t = *tp; |
| 6692 |
bitmap forced_stack_vars = (bitmap)((walk_stmt_info *)data)->info; |
| 6693 |
|
| 6694 |
if (IS_TYPE_OR_DECL_P (t)) |
| 6695 |
*walk_subtrees = 0; |
| 6696 |
else if (REFERENCE_CLASS_P (t) && TREE_THIS_VOLATILE (t)) |
| 6697 |
{ |
| 6698 |
t = get_base_address (t); |
| 6699 |
if (t && DECL_P (t) |
| 6700 |
&& DECL_MODE (t) != BLKmode |
| 6701 |
&& !TREE_ADDRESSABLE (t)) |
| 6702 |
bitmap_set_bit (forced_stack_vars, DECL_UID (t)); |
| 6703 |
*walk_subtrees = 0; |
| 6704 |
} |
| 6705 |
else if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) |
| 6706 |
{ |
| 6707 |
while (((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) |
| 6708 |
&& is_gimple_min_invariant (TREE_OPERAND (t, 1)) |
| 6709 |
&& (!TREE_OPERAND (t, 2) |
| 6710 |
|| is_gimple_min_invariant (TREE_OPERAND (t, 2)))) |
| 6711 |
|| (TREE_CODE (t) == COMPONENT_REF |
| 6712 |
&& (!TREE_OPERAND (t,2) |
| 6713 |
|| is_gimple_min_invariant (TREE_OPERAND (t, 2)))) |
| 6714 |
|| TREE_CODE (t) == BIT_FIELD_REF |
| 6715 |
|| TREE_CODE (t) == REALPART_EXPR |
| 6716 |
|| TREE_CODE (t) == IMAGPART_EXPR |
| 6717 |
|| TREE_CODE (t) == VIEW_CONVERT_EXPR |
| 6718 |
|| CONVERT_EXPR_P (t)) |
| 6719 |
t = TREE_OPERAND (t, 0); |
| 6720 |
|
| 6721 |
if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) |
| 6722 |
{ |
| 6723 |
t = get_base_address (t); |
| 6724 |
if (t && DECL_P (t) |
| 6725 |
&& DECL_MODE (t) != BLKmode |
| 6726 |
&& !TREE_ADDRESSABLE (t)) |
| 6727 |
bitmap_set_bit (forced_stack_vars, DECL_UID (t)); |
| 6728 |
} |
| 6729 |
|
| 6730 |
*walk_subtrees = 0; |
| 6731 |
} |
| 6732 |
/* References of size POLY_INT_CST to a fixed-size object must go |
| 6733 |
through memory. It's more efficient to force that here than |
| 6734 |
to create temporary slots on the fly. |
| 6735 |
RTL expansion expectes TARGET_MEM_REF to always address actual memory. |
| 6736 |
Also, force to stack non-BLKmode vars accessed through VIEW_CONVERT_EXPR |
| 6737 |
to BLKmode type. */ |
| 6738 |
else if (TREE_CODE (t) == TARGET_MEM_REF |
| 6739 |
|| (TREE_CODE (t) == MEM_REF |
| 6740 |
&& TYPE_SIZE (TREE_TYPE (t)) |
| 6741 |
&& POLY_INT_CST_P (TYPE_SIZE (TREE_TYPE (t)))) |
| 6742 |
|| (TREE_CODE (t) == VIEW_CONVERT_EXPR |
| 6743 |
&& TYPE_MODE (TREE_TYPE (t)) == BLKmode)) |
| 6744 |
{ |
| 6745 |
tree base = get_base_address (t); |
| 6746 |
if (base |
| 6747 |
&& DECL_P (base) |
| 6748 |
&& !TREE_ADDRESSABLE (base) |
| 6749 |
&& DECL_MODE (base) != BLKmode |
| 6750 |
&& GET_MODE_SIZE (DECL_MODE (base)).is_constant ()) |
| 6751 |
bitmap_set_bit (forced_stack_vars, DECL_UID (base)); |
| 6752 |
*walk_subtrees = 0; |
| 6753 |
} |
| 6754 |
|
| 6755 |
return NULL_TREE; |
| 6756 |
} |
| 6757 |
|
| 6758 |
/* If there's a chance to get a pseudo for t then if it would be of float mode |
| 6759 |
and the actual access is via an integer mode (lowered memcpy or similar |
| 6760 |
access) then avoid the register expansion if the mode likely is not storage |
| 6761 |
suitable for raw bits processing (like XFmode on i?86). */ |
| 6762 |
|
| 6763 |
static void |
| 6764 |
avoid_type_punning_on_regs (tree t, bitmap forced_stack_vars) |
| 6765 |
{ |
| 6766 |
machine_mode access_mode = TYPE_MODE (TREE_TYPE (t)); |
| 6767 |
if (access_mode != BLKmode |
| 6768 |
&& !SCALAR_INT_MODE_P (access_mode)) |
| 6769 |
return; |
| 6770 |
tree base = get_base_address (t); |
| 6771 |
if (DECL_P (base) |
| 6772 |
&& !TREE_ADDRESSABLE (base) |
| 6773 |
&& FLOAT_MODE_P (DECL_MODE (base)) |
| 6774 |
&& maybe_lt (GET_MODE_PRECISION (DECL_MODE (base)), |
| 6775 |
GET_MODE_BITSIZE (GET_MODE_INNER (DECL_MODE (base)))) |
| 6776 |
/* Double check in the expensive way we really would get a pseudo. */ |
| 6777 |
&& use_register_for_decl (base)) |
| 6778 |
bitmap_set_bit (forced_stack_vars, DECL_UID (base)); |
| 6779 |
} |
| 6780 |
|
| 6781 |
/* RTL expansion is not able to compile array references with variable |
| 6782 |
offsets for arrays stored in single register. Discover such |
| 6783 |
expressions and mark variables as addressable to avoid this |
| 6784 |
scenario. */ |
| 6785 |
|
| 6786 |
static void |
| 6787 |
discover_nonconstant_array_refs (bitmap forced_stack_vars) |
| 6788 |
{ |
| 6789 |
basic_block bb; |
| 6790 |
gimple_stmt_iterator gsi; |
| 6791 |
|
| 6792 |
walk_stmt_info wi = {}; |
| 6793 |
wi.info = forced_stack_vars; |
| 6794 |
FOR_EACH_BB_FN (bb, cfun) |
| 6795 |
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
| 6796 |
{ |
| 6797 |
gimple *stmt = gsi_stmt (gsi); |
| 6798 |
if (!is_gimple_debug (stmt)) |
| 6799 |
{ |
| 6800 |
walk_gimple_op (stmt, discover_nonconstant_array_refs_r, &wi); |
| 6801 |
gcall *call = dyn_cast <gcall *> (stmt); |
| 6802 |
if (call && gimple_call_internal_p (call)) |
| 6803 |
{ |
| 6804 |
tree cand = NULL_TREE; |
| 6805 |
switch (gimple_call_internal_fn (call)) |
| 6806 |
{ |
| 6807 |
case IFN_LOAD_LANES: |
| 6808 |
/* The source must be a MEM. */ |
| 6809 |
cand = gimple_call_arg (call, 0); |
| 6810 |
break; |
| 6811 |
case IFN_STORE_LANES: |
| 6812 |
/* The destination must be a MEM. */ |
| 6813 |
cand = gimple_call_lhs (call); |
| 6814 |
break; |
| 6815 |
default: |
| 6816 |
break; |
| 6817 |
} |
| 6818 |
if (cand) |
| 6819 |
cand = get_base_address (cand); |
| 6820 |
if (cand |
| 6821 |
&& DECL_P (cand) |
| 6822 |
&& use_register_for_decl (cand)) |
| 6823 |
bitmap_set_bit (forced_stack_vars, DECL_UID (cand)); |
| 6824 |
} |
| 6825 |
if (gimple_vdef (stmt)) |
| 6826 |
{ |
| 6827 |
tree t = gimple_get_lhs (stmt); |
| 6828 |
if (t && REFERENCE_CLASS_P (t)) |
| 6829 |
avoid_type_punning_on_regs (t, forced_stack_vars); |
| 6830 |
} |
| 6831 |
} |
| 6832 |
} |
| 6833 |
} |
| 6834 |
|
| 6835 |
/* This function sets crtl->args.internal_arg_pointer to a virtual |
| 6836 |
register if DRAP is needed. Local register allocator will replace |
| 6837 |
virtual_incoming_args_rtx with the virtual register. */ |
| 6838 |
|
| 6839 |
static void |
| 6840 |
expand_stack_alignment (void) |
| 6841 |
{ |
| 6842 |
rtx drap_rtx; |
| 6843 |
unsigned int preferred_stack_boundary; |
| 6844 |
|
| 6845 |
if (! SUPPORTS_STACK_ALIGNMENT) |
| 6846 |
return; |
| 6847 |
|
| 6848 |
if (cfun->calls_alloca |
| 6849 |
|| cfun->has_nonlocal_label |
| 6850 |
|| crtl->has_nonlocal_goto) |
| 6851 |
crtl->need_drap = true; |
| 6852 |
|
| 6853 |
/* Call update_stack_boundary here again to update incoming stack |
| 6854 |
boundary. It may set incoming stack alignment to a different |
| 6855 |
value after RTL expansion. TARGET_FUNCTION_OK_FOR_SIBCALL may |
| 6856 |
use the minimum incoming stack alignment to check if it is OK |
| 6857 |
to perform sibcall optimization since sibcall optimization will |
| 6858 |
only align the outgoing stack to incoming stack boundary. */ |
| 6859 |
if (targetm.calls.update_stack_boundary) |
| 6860 |
targetm.calls.update_stack_boundary (); |
| 6861 |
|
| 6862 |
/* The incoming stack frame has to be aligned at least at |
| 6863 |
parm_stack_boundary. */ |
| 6864 |
gcc_assert (crtl->parm_stack_boundary <= INCOMING_STACK_BOUNDARY); |
| 6865 |
|
| 6866 |
/* Update crtl->stack_alignment_estimated and use it later to align |
| 6867 |
stack. We check PREFERRED_STACK_BOUNDARY if there may be non-call |
| 6868 |
exceptions since callgraph doesn't collect incoming stack alignment |
| 6869 |
in this case. */ |
| 6870 |
if (cfun->can_throw_non_call_exceptions |
| 6871 |
&& PREFERRED_STACK_BOUNDARY > crtl->preferred_stack_boundary) |
| 6872 |
preferred_stack_boundary = PREFERRED_STACK_BOUNDARY; |
| 6873 |
else |
| 6874 |
preferred_stack_boundary = crtl->preferred_stack_boundary; |
| 6875 |
if (preferred_stack_boundary > crtl->stack_alignment_estimated) |
| 6876 |
crtl->stack_alignment_estimated = preferred_stack_boundary; |
| 6877 |
if (preferred_stack_boundary > crtl->stack_alignment_needed) |
| 6878 |
crtl->stack_alignment_needed = preferred_stack_boundary; |
| 6879 |
|
| 6880 |
gcc_assert (crtl->stack_alignment_needed |
| 6881 |
<= crtl->stack_alignment_estimated); |
| 6882 |
|
| 6883 |
crtl->stack_realign_needed |
| 6884 |
= INCOMING_STACK_BOUNDARY < crtl->stack_alignment_estimated; |
| 6885 |
crtl->stack_realign_tried = crtl->stack_realign_needed; |
| 6886 |
|
| 6887 |
crtl->stack_realign_processed = true; |
| 6888 |
|
| 6889 |
/* Target has to redefine TARGET_GET_DRAP_RTX to support stack |
| 6890 |
alignment. */ |
| 6891 |
gcc_assert (targetm.calls.get_drap_rtx != NULL); |
| 6892 |
drap_rtx = targetm.calls.get_drap_rtx (); |
| 6893 |
|
| 6894 |
/* stack_realign_drap and drap_rtx must match. */ |
| 6895 |
gcc_assert ((stack_realign_drap != 0) == (drap_rtx != NULL)); |
| 6896 |
|
| 6897 |
/* Do nothing if NULL is returned, which means DRAP is not needed. */ |
| 6898 |
if (drap_rtx != NULL) |
| 6899 |
{ |
| 6900 |
crtl->args.internal_arg_pointer = drap_rtx; |
| 6901 |
|
| 6902 |
/* Call fixup_tail_calls to clean up REG_EQUIV note if DRAP is |
| 6903 |
needed. */ |
| 6904 |
fixup_tail_calls (); |
| 6905 |
} |
| 6906 |
} |
| 6907 |
|
| 6908 |
|
| 6909 |
static void |
| 6910 |
expand_main_function (void) |
| 6911 |
{ |
| 6912 |
#if (defined(INVOKE__main) \ |
| 6913 |
|| (!defined(HAS_INIT_SECTION) \ |
| 6914 |
&& !defined(INIT_SECTION_ASM_OP) \ |
| 6915 |
&& !defined(INIT_ARRAY_SECTION_ASM_OP))) |
| 6916 |
emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode); |
| 6917 |
#endif |
| 6918 |
} |
| 6919 |
|
| 6920 |
|
| 6921 |
/* Expand code to initialize the stack_protect_guard. This is invoked at |
| 6922 |
the beginning of a function to be protected. */ |
| 6923 |
|
| 6924 |
static void |
| 6925 |
stack_protect_prologue (void) |
| 6926 |
{ |
| 6927 |
tree guard_decl = targetm.stack_protect_guard (); |
| 6928 |
rtx x, y; |
| 6929 |
|
| 6930 |
crtl->stack_protect_guard_decl = guard_decl; |
| 6931 |
x = expand_normal (crtl->stack_protect_guard); |
| 6932 |
|
| 6933 |
if (targetm.have_stack_protect_combined_set () && guard_decl) |
| 6934 |
{ |
| 6935 |
gcc_assert (DECL_P (guard_decl)); |
| 6936 |
y = DECL_RTL (guard_decl); |
| 6937 |
|
| 6938 |
/* Allow the target to compute address of Y and copy it to X without |
| 6939 |
leaking Y into a register. This combined address + copy pattern |
| 6940 |
allows the target to prevent spilling of any intermediate results by |
| 6941 |
splitting it after register allocator. */ |
| 6942 |
if (rtx_insn *insn = targetm.gen_stack_protect_combined_set (x, y)) |
| 6943 |
{ |
| 6944 |
emit_insn (insn); |
| 6945 |
return; |
| 6946 |
} |
| 6947 |
} |
| 6948 |
|
| 6949 |
if (guard_decl) |
| 6950 |
y = expand_normal (guard_decl); |
| 6951 |
else |
| 6952 |
y = const0_rtx; |
| 6953 |
|
| 6954 |
/* Allow the target to copy from Y to X without leaking Y into a |
| 6955 |
register. */ |
| 6956 |
if (targetm.have_stack_protect_set ()) |
| 6957 |
if (rtx_insn *insn = targetm.gen_stack_protect_set (x, y)) |
| 6958 |
{ |
| 6959 |
emit_insn (insn); |
| 6960 |
return; |
| 6961 |
} |
| 6962 |
|
| 6963 |
/* Otherwise do a straight move. */ |
| 6964 |
emit_move_insn (x, y); |
| 6965 |
} |
| 6966 |
|
| 6967 |
/* Translate the intermediate representation contained in the CFG |
| 6968 |
from GIMPLE trees to RTL. |
| 6969 |
|
| 6970 |
We do conversion per basic block and preserve/update the tree CFG. |
| 6971 |
This implies we have to do some magic as the CFG can simultaneously |
| 6972 |
consist of basic blocks containing RTL and GIMPLE trees. This can |
| 6973 |
confuse the CFG hooks, so be careful to not manipulate CFG during |
| 6974 |
the expansion. */ |
| 6975 |
|
| 6976 |
namespace { |
| 6977 |
|
| 6978 |
const pass_data pass_data_expand = |
| 6979 |
{ |
| 6980 |
RTL_PASS, /* type */ |
| 6981 |
"expand", /* name */ |
| 6982 |
OPTGROUP_NONE, /* optinfo_flags */ |
| 6983 |
TV_EXPAND, /* tv_id */ |
| 6984 |
( PROP_ssa | PROP_gimple_leh | PROP_cfg |
| 6985 |
| PROP_gimple_lcx |
| 6986 |
| PROP_gimple_lvec |
| 6987 |
| PROP_gimple_lva), /* properties_required */ |
| 6988 |
PROP_rtl, /* properties_provided */ |
| 6989 |
( PROP_ssa | PROP_gimple ), /* properties_destroyed */ |
| 6990 |
0, /* todo_flags_start */ |
| 6991 |
0, /* todo_flags_finish */ |
| 6992 |
}; |
| 6993 |
|
| 6994 |
class pass_expand : public rtl_opt_pass |
| 6995 |
{ |
| 6996 |
public: |
| 6997 |
pass_expand (gcc::context *ctxt) |
| 6998 |
: rtl_opt_pass (pass_data_expand, ctxt) |
| 6999 |
{} |
| 7000 |
|
| 7001 |
/* opt_pass methods: */ |
| 7002 |
unsigned int execute (function *) final override; |
| 7003 |
|
| 7004 |
}; // class pass_expand |
| 7005 |
|
| 7006 |
unsigned int |
| 7007 |
pass_expand::execute (function *fun) |
| 7008 |
{ |
| 7009 |
basic_block bb, init_block; |
| 7010 |
edge_iterator ei; |
| 7011 |
edge e; |
| 7012 |
rtx_insn *var_seq, *var_ret_seq; |
| 7013 |
unsigned i; |
| 7014 |
|
| 7015 |
timevar_push (TV_OUT_OF_SSA); |
| 7016 |
rewrite_out_of_ssa (&SA); |
| 7017 |
timevar_pop (TV_OUT_OF_SSA); |
| 7018 |
SA.partition_to_pseudo = XCNEWVEC (rtx, SA.map->num_partitions); |
| 7019 |
|
| 7020 |
if (MAY_HAVE_DEBUG_BIND_STMTS && flag_tree_ter) |
| 7021 |
{ |
| 7022 |
gimple_stmt_iterator gsi; |
| 7023 |
FOR_EACH_BB_FN (bb, cfun) |
| 7024 |
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
| 7025 |
if (gimple_debug_bind_p (gsi_stmt (gsi))) |
| 7026 |
avoid_deep_ter_for_debug (gsi_stmt (gsi), 0); |
| 7027 |
} |
| 7028 |
|
| 7029 |
/* Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE. */ |
| 7030 |
auto_bitmap forced_stack_vars; |
| 7031 |
discover_nonconstant_array_refs (forced_stack_vars); |
| 7032 |
|
| 7033 |
/* Make sure all values used by the optimization passes have sane |
| 7034 |
defaults. */ |
| 7035 |
reg_renumber = 0; |
| 7036 |
|
| 7037 |
/* Some backends want to know that we are expanding to RTL. */ |
| 7038 |
currently_expanding_to_rtl = 1; |
| 7039 |
/* Dominators are not kept up-to-date as we may create new basic-blocks. */ |
| 7040 |
free_dominance_info (CDI_DOMINATORS); |
| 7041 |
|
| 7042 |
rtl_profile_for_bb (ENTRY_BLOCK_PTR_FOR_FN (fun)); |
| 7043 |
|
| 7044 |
insn_locations_init (); |
| 7045 |
if (!DECL_IS_UNDECLARED_BUILTIN (current_function_decl)) |
| 7046 |
{ |
| 7047 |
/* Eventually, all FEs should explicitly set function_start_locus. */ |
| 7048 |
if (LOCATION_LOCUS (fun->function_start_locus) == UNKNOWN_LOCATION) |
| 7049 |
set_curr_insn_location |
| 7050 |
(DECL_SOURCE_LOCATION (current_function_decl)); |
| 7051 |
else |
| 7052 |
set_curr_insn_location (fun->function_start_locus); |
| 7053 |
} |
| 7054 |
else |
| 7055 |
set_curr_insn_location (UNKNOWN_LOCATION); |
| 7056 |
prologue_location = curr_insn_location (); |
| 7057 |
|
| 7058 |
#ifdef INSN_SCHEDULING |
| 7059 |
init_sched_attrs (); |
| 7060 |
#endif |
| 7061 |
|
| 7062 |
/* Make sure first insn is a note even if we don't want linenums. |
| 7063 |
This makes sure the first insn will never be deleted. |
| 7064 |
Also, final expects a note to appear there. */ |
| 7065 |
emit_note (NOTE_INSN_DELETED); |
| 7066 |
|
| 7067 |
targetm.expand_to_rtl_hook (); |
| 7068 |
crtl->init_stack_alignment (); |
| 7069 |
fun->cfg->max_jumptable_ents = 0; |
| 7070 |
|
| 7071 |
/* Resovle the function section. Some targets, like ARM EABI rely on knowledge |
| 7072 |
of the function section at exapnsion time to predict distance of calls. */ |
| 7073 |
resolve_unique_section (current_function_decl, 0, flag_function_sections); |
| 7074 |
|
| 7075 |
/* Expand the variables recorded during gimple lowering. */ |
| 7076 |
timevar_push (TV_VAR_EXPAND); |
| 7077 |
start_sequence (); |
| 7078 |
|
| 7079 |
var_ret_seq = expand_used_vars (forced_stack_vars); |
| 7080 |
|
| 7081 |
var_seq = get_insns (); |
| 7082 |
end_sequence (); |
| 7083 |
timevar_pop (TV_VAR_EXPAND); |
| 7084 |
|
| 7085 |
/* Honor stack protection warnings. */ |
| 7086 |
if (warn_stack_protect) |
| 7087 |
{ |
| 7088 |
if (fun->calls_alloca) |
| 7089 |
warning (OPT_Wstack_protector, |
| 7090 |
"stack protector not protecting local variables: " |
| 7091 |
"variable length buffer"); |
| 7092 |
if (has_short_buffer && !crtl->stack_protect_guard) |
| 7093 |
warning (OPT_Wstack_protector, |
| 7094 |
"stack protector not protecting function: " |
| 7095 |
"all local arrays are less than %d bytes long", |
| 7096 |
(int) param_ssp_buffer_size); |
| 7097 |
} |
| 7098 |
|
| 7099 |
/* Temporarily mark PARM_DECLs and RESULT_DECLs we need to expand to |
| 7100 |
memory addressable so expand_function_start can emit the required |
| 7101 |
copies. */ |
| 7102 |
auto_vec<tree, 16> marked_parms; |
| 7103 |
for (tree parm = DECL_ARGUMENTS (current_function_decl); parm; |
| 7104 |
parm = DECL_CHAIN (parm)) |
| 7105 |
if (!TREE_ADDRESSABLE (parm) |
| 7106 |
&& bitmap_bit_p (forced_stack_vars, DECL_UID (parm))) |
| 7107 |
{ |
| 7108 |
TREE_ADDRESSABLE (parm) = 1; |
| 7109 |
marked_parms.safe_push (parm); |
| 7110 |
} |
| 7111 |
if (DECL_RESULT (current_function_decl) |
| 7112 |
&& !TREE_ADDRESSABLE (DECL_RESULT (current_function_decl)) |
| 7113 |
&& bitmap_bit_p (forced_stack_vars, |
| 7114 |
DECL_UID (DECL_RESULT (current_function_decl)))) |
| 7115 |
{ |
| 7116 |
TREE_ADDRESSABLE (DECL_RESULT (current_function_decl)) = 1; |
| 7117 |
marked_parms.safe_push (DECL_RESULT (current_function_decl)); |
| 7118 |
} |
| 7119 |
|
| 7120 |
/* Set up parameters and prepare for return, for the function. */ |
| 7121 |
expand_function_start (current_function_decl); |
| 7122 |
|
| 7123 |
/* Clear TREE_ADDRESSABLE again. */ |
| 7124 |
while (!marked_parms.is_empty ()) |
| 7125 |
TREE_ADDRESSABLE (marked_parms.pop ()) = 0; |
| 7126 |
|
| 7127 |
/* If we emitted any instructions for setting up the variables, |
| 7128 |
emit them before the FUNCTION_START note. */ |
| 7129 |
if (var_seq) |
| 7130 |
{ |
| 7131 |
emit_insn_before (var_seq, parm_birth_insn); |
| 7132 |
|
| 7133 |
/* In expand_function_end we'll insert the alloca save/restore |
| 7134 |
before parm_birth_insn. We've just insertted an alloca call. |
| 7135 |
Adjust the pointer to match. */ |
| 7136 |
parm_birth_insn = var_seq; |
| 7137 |
} |
| 7138 |
|
| 7139 |
/* Now propagate the RTL assignment of each partition to the |
| 7140 |
underlying var of each SSA_NAME. */ |
| 7141 |
tree name; |
| 7142 |
|
| 7143 |
FOR_EACH_SSA_NAME (i, name, cfun) |
| 7144 |
{ |
| 7145 |
/* We might have generated new SSA names in |
| 7146 |
update_alias_info_with_stack_vars. They will have a NULL |
| 7147 |
defining statements, and won't be part of the partitioning, |
| 7148 |
so ignore those. */ |
| 7149 |
if (!SSA_NAME_DEF_STMT (name)) |
| 7150 |
continue; |
| 7151 |
|
| 7152 |
adjust_one_expanded_partition_var (name); |
| 7153 |
} |
| 7154 |
|
| 7155 |
/* Clean up RTL of variables that straddle across multiple |
| 7156 |
partitions, and check that the rtl of any PARM_DECLs that are not |
| 7157 |
cleaned up is that of their default defs. */ |
| 7158 |
FOR_EACH_SSA_NAME (i, name, cfun) |
| 7159 |
{ |
| 7160 |
int part; |
| 7161 |
|
| 7162 |
/* We might have generated new SSA names in |
| 7163 |
update_alias_info_with_stack_vars. They will have a NULL |
| 7164 |
defining statements, and won't be part of the partitioning, |
| 7165 |
so ignore those. */ |
| 7166 |
if (!SSA_NAME_DEF_STMT (name)) |
| 7167 |
continue; |
| 7168 |
part = var_to_partition (SA.map, name); |
| 7169 |
if (part == NO_PARTITION) |
| 7170 |
continue; |
| 7171 |
|
| 7172 |
/* If this decl was marked as living in multiple places, reset |
| 7173 |
this now to NULL. */ |
| 7174 |
tree var = SSA_NAME_VAR (name); |
| 7175 |
if (var && DECL_RTL_IF_SET (var) == pc_rtx) |
| 7176 |
SET_DECL_RTL (var, NULL); |
| 7177 |
/* Check that the pseudos chosen by assign_parms are those of |
| 7178 |
the corresponding default defs. */ |
| 7179 |
else if (SSA_NAME_IS_DEFAULT_DEF (name) |
| 7180 |
&& (TREE_CODE (var) == PARM_DECL |
| 7181 |
|| TREE_CODE (var) == RESULT_DECL)) |
| 7182 |
{ |
| 7183 |
rtx in = DECL_RTL_IF_SET (var); |
| 7184 |
gcc_assert (in); |
| 7185 |
rtx out = SA.partition_to_pseudo[part]; |
| 7186 |
gcc_assert (in == out); |
| 7187 |
|
| 7188 |
/* Now reset VAR's RTL to IN, so that the _EXPR attrs match |
| 7189 |
those expected by debug backends for each parm and for |
| 7190 |
the result. This is particularly important for stabs, |
| 7191 |
whose register elimination from parm's DECL_RTL may cause |
| 7192 |
-fcompare-debug differences as SET_DECL_RTL changes reg's |
| 7193 |
attrs. So, make sure the RTL already has the parm as the |
| 7194 |
EXPR, so that it won't change. */ |
| 7195 |
SET_DECL_RTL (var, NULL_RTX); |
| 7196 |
if (MEM_P (in)) |
| 7197 |
set_mem_attributes (in, var, true); |
| 7198 |
SET_DECL_RTL (var, in); |
| 7199 |
} |
| 7200 |
} |
| 7201 |
|
| 7202 |
/* If this function is `main', emit a call to `__main' |
| 7203 |
to run global initializers, etc. */ |
| 7204 |
if (DECL_NAME (current_function_decl) |
| 7205 |
&& MAIN_NAME_P (DECL_NAME (current_function_decl)) |
| 7206 |
&& DECL_FILE_SCOPE_P (current_function_decl)) |
| 7207 |
expand_main_function (); |
| 7208 |
|
| 7209 |
/* Initialize the stack_protect_guard field. This must happen after the |
| 7210 |
call to __main (if any) so that the external decl is initialized. */ |
| 7211 |
if (crtl->stack_protect_guard && targetm.stack_protect_runtime_enabled_p ()) |
| 7212 |
stack_protect_prologue (); |
| 7213 |
|
| 7214 |
expand_phi_nodes (&SA); |
| 7215 |
|
| 7216 |
/* Release any stale SSA redirection data. */ |
| 7217 |
redirect_edge_var_map_empty (); |
| 7218 |
|
| 7219 |
/* Register rtl specific functions for cfg. */ |
| 7220 |
rtl_register_cfg_hooks (); |
| 7221 |
|
| 7222 |
init_block = construct_init_block (); |
| 7223 |
|
| 7224 |
/* Clear EDGE_EXECUTABLE on the entry edge(s). It is cleaned from the |
| 7225 |
remaining edges later. */ |
| 7226 |
FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (fun)->succs) |
| 7227 |
e->flags &= ~EDGE_EXECUTABLE; |
| 7228 |
|
| 7229 |
/* If the function has too many markers, drop them while expanding. */ |
| 7230 |
if (cfun->debug_marker_count |
| 7231 |
>= param_max_debug_marker_count) |
| 7232 |
cfun->debug_nonbind_markers = false; |
| 7233 |
|
| 7234 |
lab_rtx_for_bb = new hash_map<basic_block, rtx_code_label *>; |
| 7235 |
FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR_FOR_FN (fun), |
| 7236 |
next_bb) |
| 7237 |
bb = expand_gimple_basic_block (bb, var_ret_seq); |
| 7238 |
|
| 7239 |
if (MAY_HAVE_DEBUG_BIND_INSNS) |
| 7240 |
expand_debug_locations (); |
| 7241 |
|
| 7242 |
if (deep_ter_debug_map) |
| 7243 |
{ |
| 7244 |
delete deep_ter_debug_map; |
| 7245 |
deep_ter_debug_map = NULL; |
| 7246 |
} |
| 7247 |
|
| 7248 |
/* Free stuff we no longer need after GIMPLE optimizations. */ |
| 7249 |
free_dominance_info (CDI_DOMINATORS); |
| 7250 |
free_dominance_info (CDI_POST_DOMINATORS); |
| 7251 |
delete_tree_cfg_annotations (fun); |
| 7252 |
|
| 7253 |
timevar_push (TV_OUT_OF_SSA); |
| 7254 |
finish_out_of_ssa (&SA); |
| 7255 |
timevar_pop (TV_OUT_OF_SSA); |
| 7256 |
|
| 7257 |
timevar_push (TV_POST_EXPAND); |
| 7258 |
/* We are no longer in SSA form. */ |
| 7259 |
fun->gimple_df->in_ssa_p = false; |
| 7260 |
loops_state_clear (LOOP_CLOSED_SSA); |
| 7261 |
|
| 7262 |
/* Expansion is used by optimization passes too, set maybe_hot_insn_p |
| 7263 |
conservatively to true until they are all profile aware. */ |
| 7264 |
delete lab_rtx_for_bb; |
| 7265 |
free_histograms (fun); |
| 7266 |
|
| 7267 |
construct_exit_block (); |
| 7268 |
insn_locations_finalize (); |
| 7269 |
|
| 7270 |
if (var_ret_seq) |
| 7271 |
{ |
| 7272 |
rtx_insn *after = return_label; |
| 7273 |
rtx_insn *next = NEXT_INSN (after); |
| 7274 |
if (next && NOTE_INSN_BASIC_BLOCK_P (next)) |
| 7275 |
after = next; |
| 7276 |
emit_insn_after (var_ret_seq, after); |
| 7277 |
} |
| 7278 |
|
| 7279 |
if (hwasan_sanitize_stack_p ()) |
| 7280 |
hwasan_maybe_emit_frame_base_init (); |
| 7281 |
|
| 7282 |
/* Zap the tree EH table. */ |
| 7283 |
set_eh_throw_stmt_table (fun, NULL); |
| 7284 |
|
| 7285 |
/* We need JUMP_LABEL be set in order to redirect jumps, and hence |
| 7286 |
split edges which edge insertions might do. */ |
| 7287 |
rebuild_jump_labels (get_insns ()); |
| 7288 |
|
| 7289 |
/* If we have a single successor to the entry block, put the pending insns |
| 7290 |
after parm birth, but before NOTE_INSNS_FUNCTION_BEG. */ |
| 7291 |
if (single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (fun))) |
| 7292 |
{ |
| 7293 |
edge e = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (fun)); |
| 7294 |
if (e->insns.r) |
| 7295 |
{ |
| 7296 |
rtx_insn *insns = e->insns.r; |
| 7297 |
e->insns.r = NULL; |
| 7298 |
rebuild_jump_labels_chain (insns); |
| 7299 |
if (NOTE_P (parm_birth_insn) |
| 7300 |
&& NOTE_KIND (parm_birth_insn) == NOTE_INSN_FUNCTION_BEG) |
| 7301 |
emit_insn_before_noloc (insns, parm_birth_insn, e->dest); |
| 7302 |
else |
| 7303 |
emit_insn_after_noloc (insns, parm_birth_insn, e->dest); |
| 7304 |
} |
| 7305 |
} |
| 7306 |
|
| 7307 |
/* Otherwise, as well as for other edges, take the usual way. */ |
| 7308 |
commit_edge_insertions (); |
| 7309 |
|
| 7310 |
/* We're done expanding trees to RTL. */ |
| 7311 |
currently_expanding_to_rtl = 0; |
| 7312 |
|
| 7313 |
flush_mark_addressable_queue (); |
| 7314 |
|
| 7315 |
FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (fun)->next_bb, |
| 7316 |
EXIT_BLOCK_PTR_FOR_FN (fun), next_bb) |
| 7317 |
{ |
| 7318 |
edge e; |
| 7319 |
edge_iterator ei; |
| 7320 |
for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); ) |
| 7321 |
{ |
| 7322 |
/* Clear EDGE_EXECUTABLE. This flag is never used in the backend. */ |
| 7323 |
e->flags &= ~EDGE_EXECUTABLE; |
| 7324 |
|
| 7325 |
/* At the moment not all abnormal edges match the RTL |
| 7326 |
representation. It is safe to remove them here as |
| 7327 |
find_many_sub_basic_blocks will rediscover them. |
| 7328 |
In the future we should get this fixed properly. */ |
| 7329 |
if ((e->flags & EDGE_ABNORMAL) |
| 7330 |
&& !(e->flags & EDGE_SIBCALL)) |
| 7331 |
remove_edge (e); |
| 7332 |
else |
| 7333 |
ei_next (&ei); |
| 7334 |
} |
| 7335 |
} |
| 7336 |
|
| 7337 |
auto_sbitmap blocks (last_basic_block_for_fn (fun)); |
| 7338 |
bitmap_ones (blocks); |
| 7339 |
find_many_sub_basic_blocks (blocks); |
| 7340 |
purge_all_dead_edges (); |
| 7341 |
|
| 7342 |
/* After initial rtl generation, call back to finish generating |
| 7343 |
exception support code. We need to do this before cleaning up |
| 7344 |
the CFG as the code does not expect dead landing pads. */ |
| 7345 |
if (fun->eh->region_tree != NULL) |
| 7346 |
finish_eh_generation (); |
| 7347 |
|
| 7348 |
/* Call expand_stack_alignment after finishing all |
| 7349 |
updates to crtl->preferred_stack_boundary. */ |
| 7350 |
expand_stack_alignment (); |
| 7351 |
|
| 7352 |
/* Fixup REG_EQUIV notes in the prologue if there are tailcalls in this |
| 7353 |
function. */ |
| 7354 |
if (crtl->tail_call_emit) |
| 7355 |
fixup_tail_calls (); |
| 7356 |
|
| 7357 |
HOST_WIDE_INT patch_area_size, patch_area_entry; |
| 7358 |
parse_and_check_patch_area (flag_patchable_function_entry, false, |
| 7359 |
&patch_area_size, &patch_area_entry); |
| 7360 |
|
| 7361 |
tree patchable_function_entry_attr |
| 7362 |
= lookup_attribute ("patchable_function_entry", |
| 7363 |
DECL_ATTRIBUTES (cfun->decl)); |
| 7364 |
if (patchable_function_entry_attr) |
| 7365 |
{ |
| 7366 |
tree pp_val = TREE_VALUE (patchable_function_entry_attr); |
| 7367 |
tree patchable_function_entry_value1 = TREE_VALUE (pp_val); |
| 7368 |
|
| 7369 |
patch_area_size = tree_to_uhwi (patchable_function_entry_value1); |
| 7370 |
patch_area_entry = 0; |
| 7371 |
if (TREE_CHAIN (pp_val) != NULL_TREE) |
| 7372 |
{ |
| 7373 |
tree patchable_function_entry_value2 |
| 7374 |
= TREE_VALUE (TREE_CHAIN (pp_val)); |
| 7375 |
patch_area_entry = tree_to_uhwi (patchable_function_entry_value2); |
| 7376 |
} |
| 7377 |
} |
| 7378 |
|
| 7379 |
if (patch_area_entry > patch_area_size) |
| 7380 |
{ |
| 7381 |
if (patch_area_size > 0) |
| 7382 |
warning (OPT_Wattributes, |
| 7383 |
"patchable function entry %wu exceeds size %wu", |
| 7384 |
patch_area_entry, patch_area_size); |
| 7385 |
patch_area_entry = 0; |
| 7386 |
} |
| 7387 |
|
| 7388 |
crtl->patch_area_size = patch_area_size; |
| 7389 |
crtl->patch_area_entry = patch_area_entry; |
| 7390 |
|
| 7391 |
/* BB subdivision may have created basic blocks that are only reachable |
| 7392 |
from unlikely bbs but not marked as such in the profile. */ |
| 7393 |
if (optimize) |
| 7394 |
propagate_unlikely_bbs_forward (); |
| 7395 |
|
| 7396 |
/* Remove unreachable blocks, otherwise we cannot compute dominators |
| 7397 |
which are needed for loop state verification. As a side-effect |
| 7398 |
this also compacts blocks. |
| 7399 |
??? We cannot remove trivially dead insns here as for example |
| 7400 |
the DRAP reg on i?86 is not magically live at this point. |
| 7401 |
gcc.c-torture/execute/ipa-sra-2.c execution, -Os -m32 fails otherwise. */ |
| 7402 |
cleanup_cfg (CLEANUP_NO_INSN_DEL); |
| 7403 |
|
| 7404 |
checking_verify_flow_info (); |
| 7405 |
|
| 7406 |
/* Initialize pseudos allocated for hard registers. */ |
| 7407 |
emit_initial_value_sets (); |
| 7408 |
|
| 7409 |
/* And finally unshare all RTL. */ |
| 7410 |
unshare_all_rtl (); |
| 7411 |
|
| 7412 |
/* There's no need to defer outputting this function any more; we |
| 7413 |
know we want to output it. */ |
| 7414 |
DECL_DEFER_OUTPUT (current_function_decl) = 0; |
| 7415 |
|
| 7416 |
/* Now that we're done expanding trees to RTL, we shouldn't have any |
| 7417 |
more CONCATs anywhere. */ |
| 7418 |
generating_concat_p = 0; |
| 7419 |
|
| 7420 |
if (dump_file) |
| 7421 |
{ |
| 7422 |
fprintf (dump_file, |
| 7423 |
"\n\n;;\n;; Full RTL generated for this function:\n;;\n"); |
| 7424 |
/* And the pass manager will dump RTL for us. */ |
| 7425 |
} |
| 7426 |
|
| 7427 |
/* If we're emitting a nested function, make sure its parent gets |
| 7428 |
emitted as well. Doing otherwise confuses debug info. */ |
| 7429 |
{ |
| 7430 |
tree parent; |
| 7431 |
for (parent = DECL_CONTEXT (current_function_decl); |
| 7432 |
parent != NULL_TREE; |
| 7433 |
parent = get_containing_scope (parent)) |
| 7434 |
if (TREE_CODE (parent) == FUNCTION_DECL) |
| 7435 |
TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1; |
| 7436 |
} |
| 7437 |
|
| 7438 |
TREE_ASM_WRITTEN (current_function_decl) = 1; |
| 7439 |
|
| 7440 |
/* After expanding, the return labels are no longer needed. */ |
| 7441 |
return_label = NULL; |
| 7442 |
naked_return_label = NULL; |
| 7443 |
|
| 7444 |
/* After expanding, the tm_restart map is no longer needed. */ |
| 7445 |
if (fun->gimple_df->tm_restart) |
| 7446 |
fun->gimple_df->tm_restart = NULL; |
| 7447 |
|
| 7448 |
/* Tag the blocks with a depth number so that change_scope can find |
| 7449 |
the common parent easily. */ |
| 7450 |
set_block_levels (DECL_INITIAL (fun->decl), 0); |
| 7451 |
default_rtl_profile (); |
| 7452 |
|
| 7453 |
/* For -dx discard loops now, otherwise IL verify in clean_state will |
| 7454 |
ICE. */ |
| 7455 |
if (rtl_dump_and_exit) |
| 7456 |
{ |
| 7457 |
cfun->curr_properties &= ~PROP_loops; |
| 7458 |
loop_optimizer_finalize (); |
| 7459 |
} |
| 7460 |
|
| 7461 |
timevar_pop (TV_POST_EXPAND); |
| 7462 |
|
| 7463 |
return 0; |
| 7464 |
} |
| 7465 |
|
| 7466 |
} // anon namespace |
| 7467 |
|
| 7468 |
rtl_opt_pass * |
| 7469 |
make_pass_expand (gcc::context *ctxt) |
| 7470 |
{ |
| 7471 |
return new pass_expand (ctxt); |
| 7472 |
} |