1 /* Emit RTL for the GCC expander. 2 Copyright (C) 1987-2024 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 it under 7 the terms of the GNU General Public License as published by the Free 8 Software Foundation; either version 3, or (at your option) any later 9 version. 10 11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 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 21 /* Middle-to-low level generation of rtx code and insns. 22 23 This file contains support functions for creating rtl expressions 24 and manipulating them in the doubly-linked chain of insns. 25 26 The patterns of the insns are created by machine-dependent 27 routines in insn-emit.cc, which is generated automatically from 28 the machine description. These routines make the individual rtx's 29 of the pattern with `gen_rtx_fmt_ee' and others in genrtl.[ch], 30 which are automatically generated from rtl.def; what is machine 31 dependent is the kind of rtx's they make and what arguments they 32 use. */ 33 34 #include "config.h" 35 #include "system.h" 36 #include "coretypes.h" 37 #include "memmodel.h" 38 #include "backend.h" 39 #include "target.h" 40 #include "rtl.h" 41 #include "tree.h" 42 #include "df.h" 43 #include "tm_p.h" 44 #include "stringpool.h" 45 #include "insn-config.h" 46 #include "regs.h" 47 #include "emit-rtl.h" 48 #include "recog.h" 49 #include "diagnostic-core.h" 50 #include "alias.h" 51 #include "fold-const.h" 52 #include "varasm.h" 53 #include "cfgrtl.h" 54 #include "tree-eh.h" 55 #include "explow.h" 56 #include "expr.h" 57 #include "builtins.h" 58 #include "rtl-iter.h" 59 #include "stor-layout.h" 60 #include "opts.h" 61 #include "optabs.h" 62 #include "predict.h" 63 #include "rtx-vector-builder.h" 64 #include "gimple.h" 65 #include "gimple-ssa.h" 66 #include "gimplify.h" 67 68 struct target_rtl default_target_rtl; 69 #if SWITCHABLE_TARGET 70 struct target_rtl *this_target_rtl = &default_target_rtl; 71 #endif 72 73 #define initial_regno_reg_rtx (this_target_rtl->x_initial_regno_reg_rtx) 74 75 /* Commonly used modes. */ 76 77 scalar_int_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */ 78 scalar_int_mode word_mode; /* Mode whose width is BITS_PER_WORD. */ 79 scalar_int_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */ 80 81 /* Datastructures maintained for currently processed function in RTL form. */ 82 83 struct rtl_data x_rtl; 84 85 /* Indexed by pseudo register number, gives the rtx for that pseudo. 86 Allocated in parallel with regno_pointer_align. 87 FIXME: We could put it into emit_status struct, but gengtype is not able to deal 88 with length attribute nested in top level structures. */ 89 90 rtx * regno_reg_rtx; 91 92 /* This is *not* reset after each function. It gives each CODE_LABEL 93 in the entire compilation a unique label number. */ 94 95 static GTY(()) int label_num = 1; 96 97 /* We record floating-point CONST_DOUBLEs in each floating-point mode for 98 the values of 0, 1, and 2. For the integer entries and VOIDmode, we 99 record a copy of const[012]_rtx and constm1_rtx. CONSTM1_RTX 100 is set only for MODE_INT and MODE_VECTOR_INT modes. */ 101 102 rtx const_tiny_rtx[4][(int) MAX_MACHINE_MODE]; 103 104 rtx const_true_rtx; 105 106 REAL_VALUE_TYPE dconst0; 107 REAL_VALUE_TYPE dconst1; 108 REAL_VALUE_TYPE dconst2; 109 REAL_VALUE_TYPE dconstm0; 110 REAL_VALUE_TYPE dconstm1; 111 REAL_VALUE_TYPE dconsthalf; 112 REAL_VALUE_TYPE dconstinf; 113 REAL_VALUE_TYPE dconstninf; 114 115 /* Record fixed-point constant 0 and 1. */ 116 FIXED_VALUE_TYPE fconst0[MAX_FCONST0]; 117 FIXED_VALUE_TYPE fconst1[MAX_FCONST1]; 118 119 /* We make one copy of (const_int C) where C is in 120 [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT] 121 to save space during the compilation and simplify comparisons of 122 integers. */ 123 124 rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1]; 125 126 /* Standard pieces of rtx, to be substituted directly into things. */ 127 rtx pc_rtx; 128 rtx ret_rtx; 129 rtx simple_return_rtx; 130 131 /* Marker used for denoting an INSN, which should never be accessed (i.e., 132 this pointer should normally never be dereferenced), but is required to be 133 distinct from NULL_RTX. Currently used by peephole2 pass. */ 134 rtx_insn *invalid_insn_rtx; 135 136 /* A hash table storing CONST_INTs whose absolute value is greater 137 than MAX_SAVED_CONST_INT. */ 138 139 struct const_int_hasher : ggc_cache_ptr_hash<rtx_def> 140 { 141 typedef HOST_WIDE_INT compare_type; 142 143 static hashval_t hash (rtx i); 144 static bool equal (rtx i, HOST_WIDE_INT h); 145 }; 146 147 static GTY ((cache)) hash_table<const_int_hasher> *const_int_htab; 148 149 struct const_wide_int_hasher : ggc_cache_ptr_hash<rtx_def> 150 { 151 static hashval_t hash (rtx x); 152 static bool equal (rtx x, rtx y); 153 }; 154 155 static GTY ((cache)) hash_table<const_wide_int_hasher> *const_wide_int_htab; 156 157 struct const_poly_int_hasher : ggc_cache_ptr_hash<rtx_def> 158 { 159 typedef std::pair<machine_mode, poly_wide_int_ref> compare_type; 160 161 static hashval_t hash (rtx x); 162 static bool equal (rtx x, const compare_type &y); 163 }; 164 165 static GTY ((cache)) hash_table<const_poly_int_hasher> *const_poly_int_htab; 166 167 /* A hash table storing register attribute structures. */ 168 struct reg_attr_hasher : ggc_cache_ptr_hash<reg_attrs> 169 { 170 static hashval_t hash (reg_attrs *x); 171 static bool equal (reg_attrs *a, reg_attrs *b); 172 }; 173 174 static GTY ((cache)) hash_table<reg_attr_hasher> *reg_attrs_htab; 175 176 /* A hash table storing all CONST_DOUBLEs. */ 177 struct const_double_hasher : ggc_cache_ptr_hash<rtx_def> 178 { 179 static hashval_t hash (rtx x); 180 static bool equal (rtx x, rtx y); 181 }; 182 183 static GTY ((cache)) hash_table<const_double_hasher> *const_double_htab; 184 185 /* A hash table storing all CONST_FIXEDs. */ 186 struct const_fixed_hasher : ggc_cache_ptr_hash<rtx_def> 187 { 188 static hashval_t hash (rtx x); 189 static bool equal (rtx x, rtx y); 190 }; 191 192 static GTY ((cache)) hash_table<const_fixed_hasher> *const_fixed_htab; 193 194 #define cur_insn_uid (crtl->emit.x_cur_insn_uid) 195 #define cur_debug_insn_uid (crtl->emit.x_cur_debug_insn_uid) 196 #define first_label_num (crtl->emit.x_first_label_num) 197 198 static void set_used_decls (tree); 199 static void mark_label_nuses (rtx); 200 #if TARGET_SUPPORTS_WIDE_INT 201 static rtx lookup_const_wide_int (rtx); 202 #endif 203 static rtx lookup_const_double (rtx); 204 static rtx lookup_const_fixed (rtx); 205 static rtx gen_const_vector (machine_mode, int); 206 static void copy_rtx_if_shared_1 (rtx *orig); 207 208 /* Probability of the conditional branch currently proceeded by try_split. */ 209 profile_probability split_branch_probability; 210 211 /* Returns a hash code for X (which is a really a CONST_INT). */ 213 214 hashval_t 215 const_int_hasher::hash (rtx x) 216 { 217 return (hashval_t) INTVAL (x); 218 } 219 220 /* Returns true if the value represented by X (which is really a 221 CONST_INT) is the same as that given by Y (which is really a 222 HOST_WIDE_INT *). */ 223 224 bool 225 const_int_hasher::equal (rtx x, HOST_WIDE_INT y) 226 { 227 return (INTVAL (x) == y); 228 } 229 230 #if TARGET_SUPPORTS_WIDE_INT 231 /* Returns a hash code for X (which is a really a CONST_WIDE_INT). */ 232 233 hashval_t 234 const_wide_int_hasher::hash (rtx x) 235 { 236 int i; 237 unsigned HOST_WIDE_INT hash = 0; 238 const_rtx xr = x; 239 240 for (i = 0; i < CONST_WIDE_INT_NUNITS (xr); i++) 241 hash += CONST_WIDE_INT_ELT (xr, i); 242 243 return (hashval_t) hash; 244 } 245 246 /* Returns true if the value represented by X (which is really a 247 CONST_WIDE_INT) is the same as that given by Y (which is really a 248 CONST_WIDE_INT). */ 249 250 bool 251 const_wide_int_hasher::equal (rtx x, rtx y) 252 { 253 int i; 254 const_rtx xr = x; 255 const_rtx yr = y; 256 if (CONST_WIDE_INT_NUNITS (xr) != CONST_WIDE_INT_NUNITS (yr)) 257 return false; 258 259 for (i = 0; i < CONST_WIDE_INT_NUNITS (xr); i++) 260 if (CONST_WIDE_INT_ELT (xr, i) != CONST_WIDE_INT_ELT (yr, i)) 261 return false; 262 263 return true; 264 } 265 #endif 266 267 /* Returns a hash code for CONST_POLY_INT X. */ 268 269 hashval_t 270 const_poly_int_hasher::hash (rtx x) 271 { 272 inchash::hash h; 273 h.add_int (GET_MODE (x)); 274 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i) 275 h.add_wide_int (CONST_POLY_INT_COEFFS (x)[i]); 276 return h.end (); 277 } 278 279 /* Returns true if CONST_POLY_INT X is an rtx representation of Y. */ 280 281 bool 282 const_poly_int_hasher::equal (rtx x, const compare_type &y) 283 { 284 if (GET_MODE (x) != y.first) 285 return false; 286 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i) 287 if (CONST_POLY_INT_COEFFS (x)[i] != y.second.coeffs[i]) 288 return false; 289 return true; 290 } 291 292 /* Returns a hash code for X (which is really a CONST_DOUBLE). */ 293 hashval_t 294 const_double_hasher::hash (rtx x) 295 { 296 const_rtx const value = x; 297 hashval_t h; 298 299 if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (value) == VOIDmode) 300 h = CONST_DOUBLE_LOW (value) ^ CONST_DOUBLE_HIGH (value); 301 else 302 { 303 h = real_hash (CONST_DOUBLE_REAL_VALUE (value)); 304 /* MODE is used in the comparison, so it should be in the hash. */ 305 h ^= GET_MODE (value); 306 } 307 return h; 308 } 309 310 /* Returns true if the value represented by X (really a ...) 311 is the same as that represented by Y (really a ...) */ 312 bool 313 const_double_hasher::equal (rtx x, rtx y) 314 { 315 const_rtx const a = x, b = y; 316 317 if (GET_MODE (a) != GET_MODE (b)) 318 return false; 319 if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (a) == VOIDmode) 320 return (CONST_DOUBLE_LOW (a) == CONST_DOUBLE_LOW (b) 321 && CONST_DOUBLE_HIGH (a) == CONST_DOUBLE_HIGH (b)); 322 else 323 return real_identical (CONST_DOUBLE_REAL_VALUE (a), 324 CONST_DOUBLE_REAL_VALUE (b)); 325 } 326 327 /* Returns a hash code for X (which is really a CONST_FIXED). */ 328 329 hashval_t 330 const_fixed_hasher::hash (rtx x) 331 { 332 const_rtx const value = x; 333 hashval_t h; 334 335 h = fixed_hash (CONST_FIXED_VALUE (value)); 336 /* MODE is used in the comparison, so it should be in the hash. */ 337 h ^= GET_MODE (value); 338 return h; 339 } 340 341 /* Returns true if the value represented by X is the same as that 342 represented by Y. */ 343 344 bool 345 const_fixed_hasher::equal (rtx x, rtx y) 346 { 347 const_rtx const a = x, b = y; 348 349 if (GET_MODE (a) != GET_MODE (b)) 350 return false; 351 return fixed_identical (CONST_FIXED_VALUE (a), CONST_FIXED_VALUE (b)); 352 } 353 354 /* Return true if the given memory attributes are equal. */ 355 356 bool 357 mem_attrs_eq_p (const class mem_attrs *p, const class mem_attrs *q) 358 { 359 if (p == q) 360 return true; 361 if (!p || !q) 362 return false; 363 return (p->alias == q->alias 364 && p->offset_known_p == q->offset_known_p 365 && (!p->offset_known_p || known_eq (p->offset, q->offset)) 366 && p->size_known_p == q->size_known_p 367 && (!p->size_known_p || known_eq (p->size, q->size)) 368 && p->align == q->align 369 && p->addrspace == q->addrspace 370 && (p->expr == q->expr 371 || (p->expr != NULL_TREE && q->expr != NULL_TREE 372 && operand_equal_p (p->expr, q->expr, 0)))); 373 } 374 375 /* Set MEM's memory attributes so that they are the same as ATTRS. */ 376 377 static void 378 set_mem_attrs (rtx mem, mem_attrs *attrs) 379 { 380 /* If everything is the default, we can just clear the attributes. */ 381 if (mem_attrs_eq_p (attrs, mode_mem_attrs[(int) GET_MODE (mem)])) 382 { 383 MEM_ATTRS (mem) = 0; 384 return; 385 } 386 387 if (!MEM_ATTRS (mem) 388 || !mem_attrs_eq_p (attrs, MEM_ATTRS (mem))) 389 { 390 MEM_ATTRS (mem) = ggc_alloc<mem_attrs> (); 391 memcpy (MEM_ATTRS (mem), attrs, sizeof (mem_attrs)); 392 } 393 } 394 395 /* Returns a hash code for X (which is a really a reg_attrs *). */ 396 397 hashval_t 398 reg_attr_hasher::hash (reg_attrs *x) 399 { 400 const reg_attrs *const p = x; 401 402 inchash::hash h; 403 h.add_ptr (p->decl); 404 h.add_poly_hwi (p->offset); 405 return h.end (); 406 } 407 408 /* Returns true if the value represented by X is the same as that given by 409 Y. */ 410 411 bool 412 reg_attr_hasher::equal (reg_attrs *x, reg_attrs *y) 413 { 414 const reg_attrs *const p = x; 415 const reg_attrs *const q = y; 416 417 return (p->decl == q->decl && known_eq (p->offset, q->offset)); 418 } 419 /* Allocate a new reg_attrs structure and insert it into the hash table if 420 one identical to it is not already in the table. We are doing this for 421 MEM of mode MODE. */ 422 423 static reg_attrs * 424 get_reg_attrs (tree decl, poly_int64 offset) 425 { 426 reg_attrs attrs; 427 428 /* If everything is the default, we can just return zero. */ 429 if (decl == 0 && known_eq (offset, 0)) 430 return 0; 431 432 attrs.decl = decl; 433 attrs.offset = offset; 434 435 reg_attrs **slot = reg_attrs_htab->find_slot (&attrs, INSERT); 436 if (*slot == 0) 437 { 438 *slot = ggc_alloc<reg_attrs> (); 439 memcpy (*slot, &attrs, sizeof (reg_attrs)); 440 } 441 442 return *slot; 443 } 444 445 446 #if !HAVE_blockage 447 /* Generate an empty ASM_INPUT, which is used to block attempts to schedule, 448 and to block register equivalences to be seen across this insn. */ 449 450 rtx 451 gen_blockage (void) 452 { 453 rtx x = gen_rtx_ASM_INPUT (VOIDmode, ""); 454 MEM_VOLATILE_P (x) = true; 455 return x; 456 } 457 #endif 458 459 460 /* Set the mode and register number of X to MODE and REGNO. */ 461 462 void 463 set_mode_and_regno (rtx x, machine_mode mode, unsigned int regno) 464 { 465 unsigned int nregs = (HARD_REGISTER_NUM_P (regno) 466 ? hard_regno_nregs (regno, mode) 467 : 1); 468 PUT_MODE_RAW (x, mode); 469 set_regno_raw (x, regno, nregs); 470 } 471 472 /* Initialize a fresh REG rtx with mode MODE and register REGNO. */ 473 474 rtx 475 init_raw_REG (rtx x, machine_mode mode, unsigned int regno) 476 { 477 set_mode_and_regno (x, mode, regno); 478 REG_ATTRS (x) = NULL; 479 ORIGINAL_REGNO (x) = regno; 480 return x; 481 } 482 483 /* Generate a new REG rtx. Make sure ORIGINAL_REGNO is set properly, and 484 don't attempt to share with the various global pieces of rtl (such as 485 frame_pointer_rtx). */ 486 487 rtx 488 gen_raw_REG (machine_mode mode, unsigned int regno) 489 { 490 rtx x = rtx_alloc (REG MEM_STAT_INFO); 491 init_raw_REG (x, mode, regno); 492 return x; 493 } 494 495 /* There are some RTL codes that require special attention; the generation 496 functions do the raw handling. If you add to this list, modify 497 special_rtx in gengenrtl.cc as well. */ 498 499 rtx_expr_list * 500 gen_rtx_EXPR_LIST (machine_mode mode, rtx expr, rtx expr_list) 501 { 502 return as_a <rtx_expr_list *> (gen_rtx_fmt_ee (EXPR_LIST, mode, expr, 503 expr_list)); 504 } 505 506 rtx_insn_list * 507 gen_rtx_INSN_LIST (machine_mode mode, rtx insn, rtx insn_list) 508 { 509 return as_a <rtx_insn_list *> (gen_rtx_fmt_ue (INSN_LIST, mode, insn, 510 insn_list)); 511 } 512 513 rtx_insn * 514 gen_rtx_INSN (machine_mode mode, rtx_insn *prev_insn, rtx_insn *next_insn, 515 basic_block bb, rtx pattern, int location, int code, 516 rtx reg_notes) 517 { 518 return as_a <rtx_insn *> (gen_rtx_fmt_uuBeiie (INSN, mode, 519 prev_insn, next_insn, 520 bb, pattern, location, code, 521 reg_notes)); 522 } 523 524 rtx 525 gen_rtx_CONST_INT (machine_mode mode ATTRIBUTE_UNUSED, HOST_WIDE_INT arg) 526 { 527 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT) 528 return const_int_rtx[arg + MAX_SAVED_CONST_INT]; 529 530 #if STORE_FLAG_VALUE != 1 && STORE_FLAG_VALUE != -1 531 if (const_true_rtx && arg == STORE_FLAG_VALUE) 532 return const_true_rtx; 533 #endif 534 535 /* Look up the CONST_INT in the hash table. */ 536 rtx *slot = const_int_htab->find_slot_with_hash (arg, (hashval_t) arg, 537 INSERT); 538 if (*slot == 0) 539 *slot = gen_rtx_raw_CONST_INT (VOIDmode, arg); 540 541 return *slot; 542 } 543 544 rtx 545 gen_int_mode (poly_int64 c, machine_mode mode) 546 { 547 c = trunc_int_for_mode (c, mode); 548 if (c.is_constant ()) 549 return GEN_INT (c.coeffs[0]); 550 unsigned int prec = GET_MODE_PRECISION (as_a <scalar_mode> (mode)); 551 return immed_wide_int_const (poly_wide_int::from (c, prec, SIGNED), mode); 552 } 553 554 /* CONST_DOUBLEs might be created from pairs of integers, or from 555 REAL_VALUE_TYPEs. Also, their length is known only at run time, 556 so we cannot use gen_rtx_raw_CONST_DOUBLE. */ 557 558 /* Determine whether REAL, a CONST_DOUBLE, already exists in the 559 hash table. If so, return its counterpart; otherwise add it 560 to the hash table and return it. */ 561 static rtx 562 lookup_const_double (rtx real) 563 { 564 rtx *slot = const_double_htab->find_slot (real, INSERT); 565 if (*slot == 0) 566 *slot = real; 567 568 return *slot; 569 } 570 571 /* Return a CONST_DOUBLE rtx for a floating-point value specified by 572 VALUE in mode MODE. */ 573 rtx 574 const_double_from_real_value (REAL_VALUE_TYPE value, machine_mode mode) 575 { 576 rtx real = rtx_alloc (CONST_DOUBLE); 577 PUT_MODE (real, mode); 578 579 real->u.rv = value; 580 581 return lookup_const_double (real); 582 } 583 584 /* Determine whether FIXED, a CONST_FIXED, already exists in the 585 hash table. If so, return its counterpart; otherwise add it 586 to the hash table and return it. */ 587 588 static rtx 589 lookup_const_fixed (rtx fixed) 590 { 591 rtx *slot = const_fixed_htab->find_slot (fixed, INSERT); 592 if (*slot == 0) 593 *slot = fixed; 594 595 return *slot; 596 } 597 598 /* Return a CONST_FIXED rtx for a fixed-point value specified by 599 VALUE in mode MODE. */ 600 601 rtx 602 const_fixed_from_fixed_value (FIXED_VALUE_TYPE value, machine_mode mode) 603 { 604 rtx fixed = rtx_alloc (CONST_FIXED); 605 PUT_MODE (fixed, mode); 606 607 fixed->u.fv = value; 608 609 return lookup_const_fixed (fixed); 610 } 611 612 #if TARGET_SUPPORTS_WIDE_INT == 0 613 /* Constructs double_int from rtx CST. */ 614 615 double_int 616 rtx_to_double_int (const_rtx cst) 617 { 618 double_int r; 619 620 if (CONST_INT_P (cst)) 621 r = double_int::from_shwi (INTVAL (cst)); 622 else if (CONST_DOUBLE_AS_INT_P (cst)) 623 { 624 r.low = CONST_DOUBLE_LOW (cst); 625 r.high = CONST_DOUBLE_HIGH (cst); 626 } 627 else 628 gcc_unreachable (); 629 630 return r; 631 } 632 #endif 633 634 #if TARGET_SUPPORTS_WIDE_INT 635 /* Determine whether CONST_WIDE_INT WINT already exists in the hash table. 636 If so, return its counterpart; otherwise add it to the hash table and 637 return it. */ 638 639 static rtx 640 lookup_const_wide_int (rtx wint) 641 { 642 rtx *slot = const_wide_int_htab->find_slot (wint, INSERT); 643 if (*slot == 0) 644 *slot = wint; 645 646 return *slot; 647 } 648 #endif 649 650 /* Return an rtx constant for V, given that the constant has mode MODE. 651 The returned rtx will be a CONST_INT if V fits, otherwise it will be 652 a CONST_DOUBLE (if !TARGET_SUPPORTS_WIDE_INT) or a CONST_WIDE_INT 653 (if TARGET_SUPPORTS_WIDE_INT). */ 654 655 static rtx 656 immed_wide_int_const_1 (const wide_int_ref &v, machine_mode mode) 657 { 658 unsigned int len = v.get_len (); 659 /* Not scalar_int_mode because we also allow pointer bound modes. */ 660 unsigned int prec = GET_MODE_PRECISION (as_a <scalar_mode> (mode)); 661 662 /* Allow truncation but not extension since we do not know if the 663 number is signed or unsigned. */ 664 gcc_assert (prec <= v.get_precision ()); 665 666 if (len < 2 || prec <= HOST_BITS_PER_WIDE_INT) 667 return gen_int_mode (v.elt (0), mode); 668 669 #if TARGET_SUPPORTS_WIDE_INT 670 { 671 unsigned int i; 672 rtx value; 673 unsigned int blocks_needed 674 = (prec + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT; 675 676 if (len > blocks_needed) 677 len = blocks_needed; 678 679 value = const_wide_int_alloc (len); 680 681 /* It is so tempting to just put the mode in here. Must control 682 myself ... */ 683 PUT_MODE (value, VOIDmode); 684 CWI_PUT_NUM_ELEM (value, len); 685 686 for (i = 0; i < len; i++) 687 CONST_WIDE_INT_ELT (value, i) = v.elt (i); 688 689 return lookup_const_wide_int (value); 690 } 691 #else 692 return immed_double_const (v.elt (0), v.elt (1), mode); 693 #endif 694 } 695 696 #if TARGET_SUPPORTS_WIDE_INT == 0 697 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair 698 of ints: I0 is the low-order word and I1 is the high-order word. 699 For values that are larger than HOST_BITS_PER_DOUBLE_INT, the 700 implied upper bits are copies of the high bit of i1. The value 701 itself is neither signed nor unsigned. Do not use this routine for 702 non-integer modes; convert to REAL_VALUE_TYPE and use 703 const_double_from_real_value. */ 704 705 rtx 706 immed_double_const (HOST_WIDE_INT i0, HOST_WIDE_INT i1, machine_mode mode) 707 { 708 rtx value; 709 unsigned int i; 710 711 /* There are the following cases (note that there are no modes with 712 HOST_BITS_PER_WIDE_INT < GET_MODE_BITSIZE (mode) < HOST_BITS_PER_DOUBLE_INT): 713 714 1) If GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT, then we use 715 gen_int_mode. 716 2) If the value of the integer fits into HOST_WIDE_INT anyway 717 (i.e., i1 consists only from copies of the sign bit, and sign 718 of i0 and i1 are the same), then we return a CONST_INT for i0. 719 3) Otherwise, we create a CONST_DOUBLE for i0 and i1. */ 720 scalar_mode smode; 721 if (is_a <scalar_mode> (mode, &smode) 722 && GET_MODE_BITSIZE (smode) <= HOST_BITS_PER_WIDE_INT) 723 return gen_int_mode (i0, mode); 724 725 /* If this integer fits in one word, return a CONST_INT. */ 726 if ((i1 == 0 && i0 >= 0) || (i1 == ~0 && i0 < 0)) 727 return GEN_INT (i0); 728 729 /* We use VOIDmode for integers. */ 730 value = rtx_alloc (CONST_DOUBLE); 731 PUT_MODE (value, VOIDmode); 732 733 CONST_DOUBLE_LOW (value) = i0; 734 CONST_DOUBLE_HIGH (value) = i1; 735 736 for (i = 2; i < (sizeof CONST_DOUBLE_FORMAT - 1); i++) 737 XWINT (value, i) = 0; 738 739 return lookup_const_double (value); 740 } 741 #endif 742 743 /* Return an rtx representation of C in mode MODE. */ 744 745 rtx 746 immed_wide_int_const (const poly_wide_int_ref &c, machine_mode mode) 747 { 748 if (c.is_constant ()) 749 return immed_wide_int_const_1 (c.coeffs[0], mode); 750 751 /* Not scalar_int_mode because we also allow pointer bound modes. */ 752 unsigned int prec = GET_MODE_PRECISION (as_a <scalar_mode> (mode)); 753 754 /* Allow truncation but not extension since we do not know if the 755 number is signed or unsigned. */ 756 gcc_assert (prec <= c.coeffs[0].get_precision ()); 757 poly_wide_int newc = poly_wide_int::from (c, prec, SIGNED); 758 759 /* See whether we already have an rtx for this constant. */ 760 inchash::hash h; 761 h.add_int (mode); 762 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i) 763 h.add_wide_int (newc.coeffs[i]); 764 const_poly_int_hasher::compare_type typed_value (mode, newc); 765 rtx *slot = const_poly_int_htab->find_slot_with_hash (typed_value, 766 h.end (), INSERT); 767 rtx x = *slot; 768 if (x) 769 return x; 770 771 /* Create a new rtx. There's a choice to be made here between installing 772 the actual mode of the rtx or leaving it as VOIDmode (for consistency 773 with CONST_INT). In practice the handling of the codes is different 774 enough that we get no benefit from using VOIDmode, and various places 775 assume that VOIDmode implies CONST_INT. Using the real mode seems like 776 the right long-term direction anyway. */ 777 typedef trailing_wide_ints<NUM_POLY_INT_COEFFS> twi; 778 size_t extra_size = twi::extra_size (prec); 779 x = rtx_alloc_v (CONST_POLY_INT, 780 sizeof (struct const_poly_int_def) + extra_size); 781 PUT_MODE (x, mode); 782 CONST_POLY_INT_COEFFS (x).set_precision (prec); 783 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i) 784 CONST_POLY_INT_COEFFS (x)[i] = newc.coeffs[i]; 785 786 *slot = x; 787 return x; 788 } 789 790 rtx 791 gen_rtx_REG (machine_mode mode, unsigned int regno) 792 { 793 /* In case the MD file explicitly references the frame pointer, have 794 all such references point to the same frame pointer. This is 795 used during frame pointer elimination to distinguish the explicit 796 references to these registers from pseudos that happened to be 797 assigned to them. 798 799 If we have eliminated the frame pointer or arg pointer, we will 800 be using it as a normal register, for example as a spill 801 register. In such cases, we might be accessing it in a mode that 802 is not Pmode and therefore cannot use the pre-allocated rtx. 803 804 Also don't do this when we are making new REGs in reload, since 805 we don't want to get confused with the real pointers. */ 806 807 if (mode == Pmode && !reload_in_progress && !lra_in_progress) 808 { 809 if (regno == FRAME_POINTER_REGNUM 810 && (!reload_completed || frame_pointer_needed)) 811 return frame_pointer_rtx; 812 813 if (!HARD_FRAME_POINTER_IS_FRAME_POINTER 814 && regno == HARD_FRAME_POINTER_REGNUM 815 && (!reload_completed || frame_pointer_needed)) 816 return hard_frame_pointer_rtx; 817 #if !HARD_FRAME_POINTER_IS_ARG_POINTER 818 if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM 819 && regno == ARG_POINTER_REGNUM) 820 return arg_pointer_rtx; 821 #endif 822 #ifdef RETURN_ADDRESS_POINTER_REGNUM 823 if (regno == RETURN_ADDRESS_POINTER_REGNUM) 824 return return_address_pointer_rtx; 825 #endif 826 if (regno == (unsigned) PIC_OFFSET_TABLE_REGNUM 827 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM 828 && fixed_regs[PIC_OFFSET_TABLE_REGNUM]) 829 return pic_offset_table_rtx; 830 if (regno == STACK_POINTER_REGNUM) 831 return stack_pointer_rtx; 832 } 833 834 #if 0 835 /* If the per-function register table has been set up, try to re-use 836 an existing entry in that table to avoid useless generation of RTL. 837 838 This code is disabled for now until we can fix the various backends 839 which depend on having non-shared hard registers in some cases. Long 840 term we want to re-enable this code as it can significantly cut down 841 on the amount of useless RTL that gets generated. 842 843 We'll also need to fix some code that runs after reload that wants to 844 set ORIGINAL_REGNO. */ 845 846 if (cfun 847 && cfun->emit 848 && regno_reg_rtx 849 && regno < FIRST_PSEUDO_REGISTER 850 && reg_raw_mode[regno] == mode) 851 return regno_reg_rtx[regno]; 852 #endif 853 854 return gen_raw_REG (mode, regno); 855 } 856 857 rtx 858 gen_rtx_MEM (machine_mode mode, rtx addr) 859 { 860 rtx rt = gen_rtx_raw_MEM (mode, addr); 861 862 /* This field is not cleared by the mere allocation of the rtx, so 863 we clear it here. */ 864 MEM_ATTRS (rt) = 0; 865 866 return rt; 867 } 868 869 /* Generate a memory referring to non-trapping constant memory. */ 870 871 rtx 872 gen_const_mem (machine_mode mode, rtx addr) 873 { 874 rtx mem = gen_rtx_MEM (mode, addr); 875 MEM_READONLY_P (mem) = 1; 876 MEM_NOTRAP_P (mem) = 1; 877 return mem; 878 } 879 880 /* Generate a MEM referring to fixed portions of the frame, e.g., register 881 save areas. */ 882 883 rtx 884 gen_frame_mem (machine_mode mode, rtx addr) 885 { 886 rtx mem = gen_rtx_MEM (mode, addr); 887 MEM_NOTRAP_P (mem) = 1; 888 set_mem_alias_set (mem, get_frame_alias_set ()); 889 return mem; 890 } 891 892 /* Generate a MEM referring to a temporary use of the stack, not part 893 of the fixed stack frame. For example, something which is pushed 894 by a target splitter. */ 895 rtx 896 gen_tmp_stack_mem (machine_mode mode, rtx addr) 897 { 898 rtx mem = gen_rtx_MEM (mode, addr); 899 MEM_NOTRAP_P (mem) = 1; 900 if (!cfun->calls_alloca) 901 set_mem_alias_set (mem, get_frame_alias_set ()); 902 return mem; 903 } 904 905 /* We want to create (subreg:OMODE (obj:IMODE) OFFSET). Return true if 906 this construct would be valid, and false otherwise. */ 907 908 bool 909 validate_subreg (machine_mode omode, machine_mode imode, 910 const_rtx reg, poly_uint64 offset) 911 { 912 poly_uint64 isize = GET_MODE_SIZE (imode); 913 poly_uint64 osize = GET_MODE_SIZE (omode); 914 915 /* The sizes must be ordered, so that we know whether the subreg 916 is partial, paradoxical or complete. */ 917 if (!ordered_p (isize, osize)) 918 return false; 919 920 /* All subregs must be aligned. */ 921 if (!multiple_p (offset, osize)) 922 return false; 923 924 /* The subreg offset cannot be outside the inner object. */ 925 if (maybe_ge (offset, isize)) 926 return false; 927 928 poly_uint64 regsize = REGMODE_NATURAL_SIZE (imode); 929 930 /* ??? This should not be here. Temporarily continue to allow word_mode 931 subregs of anything. The most common offender is (subreg:SI (reg:DF)). 932 Generally, backends are doing something sketchy but it'll take time to 933 fix them all. */ 934 if (omode == word_mode) 935 ; 936 /* ??? Similarly, e.g. with (subreg:DF (reg:TI)). Though store_bit_field 937 is the culprit here, and not the backends. */ 938 else if (known_ge (osize, regsize) && known_ge (isize, osize)) 939 ; 940 /* Allow component subregs of complex and vector. Though given the below 941 extraction rules, it's not always clear what that means. */ 942 else if ((COMPLEX_MODE_P (imode) || VECTOR_MODE_P (imode)) 943 && GET_MODE_INNER (imode) == omode) 944 ; 945 /* ??? x86 sse code makes heavy use of *paradoxical* vector subregs, 946 i.e. (subreg:V4SF (reg:SF) 0) or (subreg:V4SF (reg:V2SF) 0). This 947 surely isn't the cleanest way to represent this. It's questionable 948 if this ought to be represented at all -- why can't this all be hidden 949 in post-reload splitters that make arbitrarily mode changes to the 950 registers themselves. */ 951 else if (VECTOR_MODE_P (omode) 952 && GET_MODE_UNIT_SIZE (omode) == GET_MODE_UNIT_SIZE (imode)) 953 ; 954 /* Subregs involving floating point modes are not allowed to 955 change size unless it's an insert into a complex mode. 956 Therefore (subreg:DI (reg:DF) 0) and (subreg:CS (reg:SF) 0) are fine, but 957 (subreg:SI (reg:DF) 0) isn't. */ 958 else if ((FLOAT_MODE_P (imode) || FLOAT_MODE_P (omode)) 959 && !COMPLEX_MODE_P (omode)) 960 { 961 if (! (known_eq (isize, osize) 962 /* LRA can use subreg to store a floating point value in 963 an integer mode. Although the floating point and the 964 integer modes need the same number of hard registers, 965 the size of floating point mode can be less than the 966 integer mode. LRA also uses subregs for a register 967 should be used in different mode in on insn. */ 968 || lra_in_progress)) 969 return false; 970 } 971 972 /* Paradoxical subregs must have offset zero. */ 973 if (maybe_gt (osize, isize)) 974 return known_eq (offset, 0U); 975 976 /* This is a normal subreg. Verify that the offset is representable. */ 977 978 /* For hard registers, we already have most of these rules collected in 979 subreg_offset_representable_p. */ 980 if (reg && REG_P (reg) && HARD_REGISTER_P (reg)) 981 { 982 unsigned int regno = REGNO (reg); 983 984 if ((COMPLEX_MODE_P (imode) || VECTOR_MODE_P (imode)) 985 && GET_MODE_INNER (imode) == omode) 986 ; 987 else if (!REG_CAN_CHANGE_MODE_P (regno, imode, omode)) 988 return false; 989 990 return subreg_offset_representable_p (regno, imode, offset, omode); 991 } 992 /* Do not allow SUBREG with stricter alignment than the inner MEM. */ 993 else if (reg && MEM_P (reg) && STRICT_ALIGNMENT 994 && MEM_ALIGN (reg) < GET_MODE_ALIGNMENT (omode)) 995 return false; 996 997 /* The outer size must be ordered wrt the register size, otherwise 998 we wouldn't know at compile time how many registers the outer 999 mode occupies. */ 1000 if (!ordered_p (osize, regsize)) 1001 return false; 1002 1003 /* For pseudo registers, we want most of the same checks. Namely: 1004 1005 Assume that the pseudo register will be allocated to hard registers 1006 that can hold REGSIZE bytes each. If OSIZE is not a multiple of REGSIZE, 1007 the remainder must correspond to the lowpart of the containing hard 1008 register. If BYTES_BIG_ENDIAN, the lowpart is at the highest offset, 1009 otherwise it is at the lowest offset. 1010 1011 Given that we've already checked the mode and offset alignment, 1012 we only have to check subblock subregs here. */ 1013 if (maybe_lt (osize, regsize) 1014 && ! (lra_in_progress && (FLOAT_MODE_P (imode) || FLOAT_MODE_P (omode)))) 1015 { 1016 /* It is invalid for the target to pick a register size for a mode 1017 that isn't ordered wrt to the size of that mode. */ 1018 poly_uint64 block_size = ordered_min (isize, regsize); 1019 unsigned int start_reg; 1020 poly_uint64 offset_within_reg; 1021 if (!can_div_trunc_p (offset, block_size, &start_reg, &offset_within_reg) 1022 || (BYTES_BIG_ENDIAN 1023 ? maybe_ne (offset_within_reg, block_size - osize) 1024 : maybe_ne (offset_within_reg, 0U))) 1025 return false; 1026 } 1027 return true; 1028 } 1029 1030 rtx 1031 gen_rtx_SUBREG (machine_mode mode, rtx reg, poly_uint64 offset) 1032 { 1033 gcc_assert (validate_subreg (mode, GET_MODE (reg), reg, offset)); 1034 return gen_rtx_raw_SUBREG (mode, reg, offset); 1035 } 1036 1037 /* Generate a SUBREG representing the least-significant part of REG if MODE 1038 is smaller than mode of REG, otherwise paradoxical SUBREG. */ 1039 1040 rtx 1041 gen_lowpart_SUBREG (machine_mode mode, rtx reg) 1042 { 1043 machine_mode inmode; 1044 1045 inmode = GET_MODE (reg); 1046 if (inmode == VOIDmode) 1047 inmode = mode; 1048 return gen_rtx_SUBREG (mode, reg, 1049 subreg_lowpart_offset (mode, inmode)); 1050 } 1051 1052 rtx 1053 gen_rtx_VAR_LOCATION (machine_mode mode, tree decl, rtx loc, 1054 enum var_init_status status) 1055 { 1056 rtx x = gen_rtx_fmt_te (VAR_LOCATION, mode, decl, loc); 1057 PAT_VAR_LOCATION_STATUS (x) = status; 1058 return x; 1059 } 1060 1061 1063 /* Create an rtvec and stores within it the RTXen passed in the arguments. */ 1064 1065 rtvec 1066 gen_rtvec (int n, ...) 1067 { 1068 int i; 1069 rtvec rt_val; 1070 va_list p; 1071 1072 va_start (p, n); 1073 1074 /* Don't allocate an empty rtvec... */ 1075 if (n == 0) 1076 { 1077 va_end (p); 1078 return NULL_RTVEC; 1079 } 1080 1081 rt_val = rtvec_alloc (n); 1082 1083 for (i = 0; i < n; i++) 1084 rt_val->elem[i] = va_arg (p, rtx); 1085 1086 va_end (p); 1087 return rt_val; 1088 } 1089 1090 rtvec 1091 gen_rtvec_v (int n, rtx *argp) 1092 { 1093 int i; 1094 rtvec rt_val; 1095 1096 /* Don't allocate an empty rtvec... */ 1097 if (n == 0) 1098 return NULL_RTVEC; 1099 1100 rt_val = rtvec_alloc (n); 1101 1102 for (i = 0; i < n; i++) 1103 rt_val->elem[i] = *argp++; 1104 1105 return rt_val; 1106 } 1107 1108 rtvec 1109 gen_rtvec_v (int n, rtx_insn **argp) 1110 { 1111 int i; 1112 rtvec rt_val; 1113 1114 /* Don't allocate an empty rtvec... */ 1115 if (n == 0) 1116 return NULL_RTVEC; 1117 1118 rt_val = rtvec_alloc (n); 1119 1120 for (i = 0; i < n; i++) 1121 rt_val->elem[i] = *argp++; 1122 1123 return rt_val; 1124 } 1125 1126 1127 /* Return the number of bytes between the start of an OUTER_MODE 1129 in-memory value and the start of an INNER_MODE in-memory value, 1130 given that the former is a lowpart of the latter. It may be a 1131 paradoxical lowpart, in which case the offset will be negative 1132 on big-endian targets. */ 1133 1134 poly_int64 1135 byte_lowpart_offset (machine_mode outer_mode, 1136 machine_mode inner_mode) 1137 { 1138 if (paradoxical_subreg_p (outer_mode, inner_mode)) 1139 return -subreg_lowpart_offset (inner_mode, outer_mode); 1140 else 1141 return subreg_lowpart_offset (outer_mode, inner_mode); 1142 } 1143 1144 /* Return the offset of (subreg:OUTER_MODE (mem:INNER_MODE X) OFFSET) 1145 from address X. For paradoxical big-endian subregs this is a 1146 negative value, otherwise it's the same as OFFSET. */ 1147 1148 poly_int64 1149 subreg_memory_offset (machine_mode outer_mode, machine_mode inner_mode, 1150 poly_uint64 offset) 1151 { 1152 if (paradoxical_subreg_p (outer_mode, inner_mode)) 1153 { 1154 gcc_assert (known_eq (offset, 0U)); 1155 return -subreg_lowpart_offset (inner_mode, outer_mode); 1156 } 1157 return offset; 1158 } 1159 1160 /* As above, but return the offset that existing subreg X would have 1161 if SUBREG_REG (X) were stored in memory. The only significant thing 1162 about the current SUBREG_REG is its mode. */ 1163 1164 poly_int64 1165 subreg_memory_offset (const_rtx x) 1166 { 1167 return subreg_memory_offset (GET_MODE (x), GET_MODE (SUBREG_REG (x)), 1168 SUBREG_BYTE (x)); 1169 } 1170 1171 /* Generate a REG rtx for a new pseudo register of mode MODE. 1173 This pseudo is assigned the next sequential register number. */ 1174 1175 rtx 1176 gen_reg_rtx (machine_mode mode) 1177 { 1178 rtx val; 1179 unsigned int align = GET_MODE_ALIGNMENT (mode); 1180 1181 gcc_assert (can_create_pseudo_p ()); 1182 1183 /* If a virtual register with bigger mode alignment is generated, 1184 increase stack alignment estimation because it might be spilled 1185 to stack later. */ 1186 if (SUPPORTS_STACK_ALIGNMENT 1187 && crtl->stack_alignment_estimated < align 1188 && !crtl->stack_realign_processed) 1189 { 1190 unsigned int min_align = MINIMUM_ALIGNMENT (NULL, mode, align); 1191 if (crtl->stack_alignment_estimated < min_align) 1192 crtl->stack_alignment_estimated = min_align; 1193 } 1194 1195 if (generating_concat_p 1196 && (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT 1197 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)) 1198 { 1199 /* For complex modes, don't make a single pseudo. 1200 Instead, make a CONCAT of two pseudos. 1201 This allows noncontiguous allocation of the real and imaginary parts, 1202 which makes much better code. Besides, allocating DCmode 1203 pseudos overstrains reload on some machines like the 386. */ 1204 rtx realpart, imagpart; 1205 machine_mode partmode = GET_MODE_INNER (mode); 1206 1207 realpart = gen_reg_rtx (partmode); 1208 imagpart = gen_reg_rtx (partmode); 1209 return gen_rtx_CONCAT (mode, realpart, imagpart); 1210 } 1211 1212 /* Do not call gen_reg_rtx with uninitialized crtl. */ 1213 gcc_assert (crtl->emit.regno_pointer_align_length); 1214 1215 crtl->emit.ensure_regno_capacity (); 1216 gcc_assert (reg_rtx_no < crtl->emit.regno_pointer_align_length); 1217 1218 val = gen_raw_REG (mode, reg_rtx_no); 1219 regno_reg_rtx[reg_rtx_no++] = val; 1220 return val; 1221 } 1222 1223 /* Make sure m_regno_pointer_align, and regno_reg_rtx are large 1224 enough to have elements in the range 0 <= idx <= reg_rtx_no. */ 1225 1226 void 1227 emit_status::ensure_regno_capacity () 1228 { 1229 int old_size = regno_pointer_align_length; 1230 1231 if (reg_rtx_no < old_size) 1232 return; 1233 1234 int new_size = old_size * 2; 1235 while (reg_rtx_no >= new_size) 1236 new_size *= 2; 1237 1238 char *tmp = XRESIZEVEC (char, regno_pointer_align, new_size); 1239 memset (tmp + old_size, 0, new_size - old_size); 1240 regno_pointer_align = (unsigned char *) tmp; 1241 1242 rtx *new1 = GGC_RESIZEVEC (rtx, regno_reg_rtx, new_size); 1243 memset (new1 + old_size, 0, (new_size - old_size) * sizeof (rtx)); 1244 regno_reg_rtx = new1; 1245 1246 crtl->emit.regno_pointer_align_length = new_size; 1247 } 1248 1249 /* Return TRUE if REG is a PARM_DECL, FALSE otherwise. */ 1250 1251 bool 1252 reg_is_parm_p (rtx reg) 1253 { 1254 tree decl; 1255 1256 gcc_assert (REG_P (reg)); 1257 decl = REG_EXPR (reg); 1258 return (decl && TREE_CODE (decl) == PARM_DECL); 1259 } 1260 1261 /* Update NEW with the same attributes as REG, but with OFFSET added 1262 to the REG_OFFSET. */ 1263 1264 static void 1265 update_reg_offset (rtx new_rtx, rtx reg, poly_int64 offset) 1266 { 1267 REG_ATTRS (new_rtx) = get_reg_attrs (REG_EXPR (reg), 1268 REG_OFFSET (reg) + offset); 1269 } 1270 1271 /* Generate a register with same attributes as REG, but with OFFSET 1272 added to the REG_OFFSET. */ 1273 1274 rtx 1275 gen_rtx_REG_offset (rtx reg, machine_mode mode, unsigned int regno, 1276 poly_int64 offset) 1277 { 1278 /* Use gen_raw_REG rather than gen_rtx_REG, because otherwise we'd 1279 overwrite REG_ATTRS (and in the callers often ORIGINAL_REGNO too) 1280 of the shared REG rtxes like stack_pointer_rtx etc. This should 1281 happen only for SUBREGs from DEBUG_INSNs, RA should ensure 1282 multi-word registers don't overlap the special registers like 1283 stack pointer. */ 1284 rtx new_rtx = gen_raw_REG (mode, regno); 1285 1286 update_reg_offset (new_rtx, reg, offset); 1287 return new_rtx; 1288 } 1289 1290 /* Generate a new pseudo-register with the same attributes as REG, but 1291 with OFFSET added to the REG_OFFSET. */ 1292 1293 rtx 1294 gen_reg_rtx_offset (rtx reg, machine_mode mode, int offset) 1295 { 1296 rtx new_rtx = gen_reg_rtx (mode); 1297 1298 update_reg_offset (new_rtx, reg, offset); 1299 return new_rtx; 1300 } 1301 1302 /* Adjust REG in-place so that it has mode MODE. It is assumed that the 1303 new register is a (possibly paradoxical) lowpart of the old one. */ 1304 1305 void 1306 adjust_reg_mode (rtx reg, machine_mode mode) 1307 { 1308 update_reg_offset (reg, reg, byte_lowpart_offset (mode, GET_MODE (reg))); 1309 PUT_MODE (reg, mode); 1310 } 1311 1312 /* Copy REG's attributes from X, if X has any attributes. If REG and X 1313 have different modes, REG is a (possibly paradoxical) lowpart of X. */ 1314 1315 void 1316 set_reg_attrs_from_value (rtx reg, rtx x) 1317 { 1318 poly_int64 offset; 1319 bool can_be_reg_pointer = true; 1320 1321 /* Don't call mark_reg_pointer for incompatible pointer sign 1322 extension. */ 1323 while (GET_CODE (x) == SIGN_EXTEND 1324 || GET_CODE (x) == ZERO_EXTEND 1325 || GET_CODE (x) == TRUNCATE 1326 || (GET_CODE (x) == SUBREG && subreg_lowpart_p (x))) 1327 { 1328 #if defined(POINTERS_EXTEND_UNSIGNED) 1329 if (((GET_CODE (x) == SIGN_EXTEND && POINTERS_EXTEND_UNSIGNED) 1330 || (GET_CODE (x) == ZERO_EXTEND && ! POINTERS_EXTEND_UNSIGNED) 1331 || (paradoxical_subreg_p (x) 1332 && ! (SUBREG_PROMOTED_VAR_P (x) 1333 && SUBREG_CHECK_PROMOTED_SIGN (x, 1334 POINTERS_EXTEND_UNSIGNED)))) 1335 && !targetm.have_ptr_extend ()) 1336 can_be_reg_pointer = false; 1337 #endif 1338 x = XEXP (x, 0); 1339 } 1340 1341 /* Hard registers can be reused for multiple purposes within the same 1342 function, so setting REG_ATTRS, REG_POINTER and REG_POINTER_ALIGN 1343 on them is wrong. */ 1344 if (HARD_REGISTER_P (reg)) 1345 return; 1346 1347 offset = byte_lowpart_offset (GET_MODE (reg), GET_MODE (x)); 1348 if (MEM_P (x)) 1349 { 1350 if (MEM_OFFSET_KNOWN_P (x)) 1351 REG_ATTRS (reg) = get_reg_attrs (MEM_EXPR (x), 1352 MEM_OFFSET (x) + offset); 1353 if (can_be_reg_pointer && MEM_POINTER (x)) 1354 mark_reg_pointer (reg, 0); 1355 } 1356 else if (REG_P (x)) 1357 { 1358 if (REG_ATTRS (x)) 1359 update_reg_offset (reg, x, offset); 1360 if (can_be_reg_pointer && REG_POINTER (x)) 1361 mark_reg_pointer (reg, REGNO_POINTER_ALIGN (REGNO (x))); 1362 } 1363 } 1364 1365 /* Generate a REG rtx for a new pseudo register, copying the mode 1366 and attributes from X. */ 1367 1368 rtx 1369 gen_reg_rtx_and_attrs (rtx x) 1370 { 1371 rtx reg = gen_reg_rtx (GET_MODE (x)); 1372 set_reg_attrs_from_value (reg, x); 1373 return reg; 1374 } 1375 1376 /* Set the register attributes for registers contained in PARM_RTX. 1377 Use needed values from memory attributes of MEM. */ 1378 1379 void 1380 set_reg_attrs_for_parm (rtx parm_rtx, rtx mem) 1381 { 1382 if (REG_P (parm_rtx)) 1383 set_reg_attrs_from_value (parm_rtx, mem); 1384 else if (GET_CODE (parm_rtx) == PARALLEL) 1385 { 1386 /* Check for a NULL entry in the first slot, used to indicate that the 1387 parameter goes both on the stack and in registers. */ 1388 int i = XEXP (XVECEXP (parm_rtx, 0, 0), 0) ? 0 : 1; 1389 for (; i < XVECLEN (parm_rtx, 0); i++) 1390 { 1391 rtx x = XVECEXP (parm_rtx, 0, i); 1392 if (REG_P (XEXP (x, 0))) 1393 REG_ATTRS (XEXP (x, 0)) 1394 = get_reg_attrs (MEM_EXPR (mem), 1395 INTVAL (XEXP (x, 1))); 1396 } 1397 } 1398 } 1399 1400 /* Set the REG_ATTRS for registers in value X, given that X represents 1401 decl T. */ 1402 1403 void 1404 set_reg_attrs_for_decl_rtl (tree t, rtx x) 1405 { 1406 if (!t) 1407 return; 1408 tree tdecl = t; 1409 if (GET_CODE (x) == SUBREG) 1410 { 1411 gcc_assert (subreg_lowpart_p (x)); 1412 x = SUBREG_REG (x); 1413 } 1414 if (REG_P (x)) 1415 REG_ATTRS (x) 1416 = get_reg_attrs (t, byte_lowpart_offset (GET_MODE (x), 1417 DECL_P (tdecl) 1418 ? DECL_MODE (tdecl) 1419 : TYPE_MODE (TREE_TYPE (tdecl)))); 1420 if (GET_CODE (x) == CONCAT) 1421 { 1422 if (REG_P (XEXP (x, 0))) 1423 REG_ATTRS (XEXP (x, 0)) = get_reg_attrs (t, 0); 1424 if (REG_P (XEXP (x, 1))) 1425 REG_ATTRS (XEXP (x, 1)) 1426 = get_reg_attrs (t, GET_MODE_UNIT_SIZE (GET_MODE (XEXP (x, 0)))); 1427 } 1428 if (GET_CODE (x) == PARALLEL) 1429 { 1430 int i, start; 1431 1432 /* Check for a NULL entry, used to indicate that the parameter goes 1433 both on the stack and in registers. */ 1434 if (XEXP (XVECEXP (x, 0, 0), 0)) 1435 start = 0; 1436 else 1437 start = 1; 1438 1439 for (i = start; i < XVECLEN (x, 0); i++) 1440 { 1441 rtx y = XVECEXP (x, 0, i); 1442 if (REG_P (XEXP (y, 0))) 1443 REG_ATTRS (XEXP (y, 0)) = get_reg_attrs (t, INTVAL (XEXP (y, 1))); 1444 } 1445 } 1446 } 1447 1448 /* Assign the RTX X to declaration T. */ 1449 1450 void 1451 set_decl_rtl (tree t, rtx x) 1452 { 1453 DECL_WRTL_CHECK (t)->decl_with_rtl.rtl = x; 1454 if (x) 1455 set_reg_attrs_for_decl_rtl (t, x); 1456 } 1457 1458 /* Assign the RTX X to parameter declaration T. BY_REFERENCE_P is true 1459 if the ABI requires the parameter to be passed by reference. */ 1460 1461 void 1462 set_decl_incoming_rtl (tree t, rtx x, bool by_reference_p) 1463 { 1464 DECL_INCOMING_RTL (t) = x; 1465 if (x && !by_reference_p) 1466 set_reg_attrs_for_decl_rtl (t, x); 1467 } 1468 1469 /* Identify REG (which may be a CONCAT) as a user register. */ 1470 1471 void 1472 mark_user_reg (rtx reg) 1473 { 1474 if (GET_CODE (reg) == CONCAT) 1475 { 1476 REG_USERVAR_P (XEXP (reg, 0)) = 1; 1477 REG_USERVAR_P (XEXP (reg, 1)) = 1; 1478 } 1479 else 1480 { 1481 gcc_assert (REG_P (reg)); 1482 REG_USERVAR_P (reg) = 1; 1483 } 1484 } 1485 1486 /* Identify REG as a probable pointer register and show its alignment 1487 as ALIGN, if nonzero. */ 1488 1489 void 1490 mark_reg_pointer (rtx reg, int align) 1491 { 1492 if (! REG_POINTER (reg)) 1493 { 1494 REG_POINTER (reg) = 1; 1495 1496 if (align) 1497 REGNO_POINTER_ALIGN (REGNO (reg)) = align; 1498 } 1499 else if (align && align < REGNO_POINTER_ALIGN (REGNO (reg))) 1500 /* We can no-longer be sure just how aligned this pointer is. */ 1501 REGNO_POINTER_ALIGN (REGNO (reg)) = align; 1502 } 1503 1504 /* Return 1 plus largest pseudo reg number used in the current function. */ 1505 1506 int 1507 max_reg_num (void) 1508 { 1509 return reg_rtx_no; 1510 } 1511 1512 /* Return 1 + the largest label number used so far in the current function. */ 1513 1514 int 1515 max_label_num (void) 1516 { 1517 return label_num; 1518 } 1519 1520 /* Return first label number used in this function (if any were used). */ 1521 1522 int 1523 get_first_label_num (void) 1524 { 1525 return first_label_num; 1526 } 1527 1528 /* If the rtx for label was created during the expansion of a nested 1529 function, then first_label_num won't include this label number. 1530 Fix this now so that array indices work later. */ 1531 1532 void 1533 maybe_set_first_label_num (rtx_code_label *x) 1534 { 1535 if (CODE_LABEL_NUMBER (x) < first_label_num) 1536 first_label_num = CODE_LABEL_NUMBER (x); 1537 } 1538 1539 /* For use by the RTL function loader, when mingling with normal 1540 functions. 1541 Ensure that label_num is greater than the label num of X, to avoid 1542 duplicate labels in the generated assembler. */ 1543 1544 void 1545 maybe_set_max_label_num (rtx_code_label *x) 1546 { 1547 if (CODE_LABEL_NUMBER (x) >= label_num) 1548 label_num = CODE_LABEL_NUMBER (x) + 1; 1549 } 1550 1551 1552 /* Return a value representing some low-order bits of X, where the number 1554 of low-order bits is given by MODE. Note that no conversion is done 1555 between floating-point and fixed-point values, rather, the bit 1556 representation is returned. 1557 1558 This function handles the cases in common between gen_lowpart, below, 1559 and two variants in cse.cc and combine.cc. These are the cases that can 1560 be safely handled at all points in the compilation. 1561 1562 If this is not a case we can handle, return 0. */ 1563 1564 rtx 1565 gen_lowpart_common (machine_mode mode, rtx x) 1566 { 1567 poly_uint64 msize = GET_MODE_SIZE (mode); 1568 machine_mode innermode; 1569 1570 /* Unfortunately, this routine doesn't take a parameter for the mode of X, 1571 so we have to make one up. Yuk. */ 1572 innermode = GET_MODE (x); 1573 if (CONST_INT_P (x) 1574 && known_le (msize * BITS_PER_UNIT, 1575 (unsigned HOST_WIDE_INT) HOST_BITS_PER_WIDE_INT)) 1576 innermode = int_mode_for_size (HOST_BITS_PER_WIDE_INT, 0).require (); 1577 else if (innermode == VOIDmode) 1578 innermode = int_mode_for_size (HOST_BITS_PER_DOUBLE_INT, 0).require (); 1579 1580 gcc_assert (innermode != VOIDmode && innermode != BLKmode); 1581 1582 if (innermode == mode) 1583 return x; 1584 1585 /* The size of the outer and inner modes must be ordered. */ 1586 poly_uint64 xsize = GET_MODE_SIZE (innermode); 1587 if (!ordered_p (msize, xsize)) 1588 return 0; 1589 1590 if (SCALAR_FLOAT_MODE_P (mode)) 1591 { 1592 /* Don't allow paradoxical FLOAT_MODE subregs. */ 1593 if (maybe_gt (msize, xsize)) 1594 return 0; 1595 } 1596 else 1597 { 1598 /* MODE must occupy no more of the underlying registers than X. */ 1599 poly_uint64 regsize = REGMODE_NATURAL_SIZE (innermode); 1600 unsigned int mregs, xregs; 1601 if (!can_div_away_from_zero_p (msize, regsize, &mregs) 1602 || !can_div_away_from_zero_p (xsize, regsize, &xregs) 1603 || mregs > xregs) 1604 return 0; 1605 } 1606 1607 scalar_int_mode int_mode, int_innermode, from_mode; 1608 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND) 1609 && is_a <scalar_int_mode> (mode, &int_mode) 1610 && is_a <scalar_int_mode> (innermode, &int_innermode) 1611 && is_a <scalar_int_mode> (GET_MODE (XEXP (x, 0)), &from_mode)) 1612 { 1613 /* If we are getting the low-order part of something that has been 1614 sign- or zero-extended, we can either just use the object being 1615 extended or make a narrower extension. If we want an even smaller 1616 piece than the size of the object being extended, call ourselves 1617 recursively. 1618 1619 This case is used mostly by combine and cse. */ 1620 1621 if (from_mode == int_mode) 1622 return XEXP (x, 0); 1623 else if (GET_MODE_SIZE (int_mode) < GET_MODE_SIZE (from_mode)) 1624 return gen_lowpart_common (int_mode, XEXP (x, 0)); 1625 else if (GET_MODE_SIZE (int_mode) < GET_MODE_SIZE (int_innermode)) 1626 return gen_rtx_fmt_e (GET_CODE (x), int_mode, XEXP (x, 0)); 1627 } 1628 else if (GET_CODE (x) == SUBREG || REG_P (x) 1629 || GET_CODE (x) == CONCAT || GET_CODE (x) == CONST_VECTOR 1630 || CONST_DOUBLE_AS_FLOAT_P (x) || CONST_SCALAR_INT_P (x) 1631 || CONST_POLY_INT_P (x)) 1632 return lowpart_subreg (mode, x, innermode); 1633 1634 /* Otherwise, we can't do this. */ 1635 return 0; 1636 } 1637 1638 rtx 1640 gen_highpart (machine_mode mode, rtx x) 1641 { 1642 poly_uint64 msize = GET_MODE_SIZE (mode); 1643 rtx result; 1644 1645 /* This case loses if X is a subreg. To catch bugs early, 1646 complain if an invalid MODE is used even in other cases. */ 1647 gcc_assert (known_le (msize, (unsigned int) UNITS_PER_WORD) 1648 || known_eq (msize, GET_MODE_UNIT_SIZE (GET_MODE (x)))); 1649 1650 /* gen_lowpart_common handles a lot of special cases due to needing to handle 1651 paradoxical subregs; it only calls simplify_gen_subreg when certain that 1652 it will produce something meaningful. The only case we need to handle 1653 specially here is MEM. */ 1654 if (MEM_P (x)) 1655 { 1656 poly_int64 offset = subreg_highpart_offset (mode, GET_MODE (x)); 1657 return adjust_address (x, mode, offset); 1658 } 1659 1660 result = simplify_gen_subreg (mode, x, GET_MODE (x), 1661 subreg_highpart_offset (mode, GET_MODE (x))); 1662 /* Since we handle MEM directly above, we should never get a MEM back 1663 from simplify_gen_subreg. */ 1664 gcc_assert (result && !MEM_P (result)); 1665 1666 return result; 1667 } 1668 1669 /* Like gen_highpart, but accept mode of EXP operand in case EXP can 1670 be VOIDmode constant. */ 1671 rtx 1672 gen_highpart_mode (machine_mode outermode, machine_mode innermode, rtx exp) 1673 { 1674 if (GET_MODE (exp) != VOIDmode) 1675 { 1676 gcc_assert (GET_MODE (exp) == innermode); 1677 return gen_highpart (outermode, exp); 1678 } 1679 return simplify_gen_subreg (outermode, exp, innermode, 1680 subreg_highpart_offset (outermode, innermode)); 1681 } 1682 1683 /* Return the SUBREG_BYTE for a lowpart subreg whose outer mode has 1684 OUTER_BYTES bytes and whose inner mode has INNER_BYTES bytes. */ 1685 1686 poly_uint64 1687 subreg_size_lowpart_offset (poly_uint64 outer_bytes, poly_uint64 inner_bytes) 1688 { 1689 gcc_checking_assert (ordered_p (outer_bytes, inner_bytes)); 1690 if (maybe_gt (outer_bytes, inner_bytes)) 1691 /* Paradoxical subregs always have a SUBREG_BYTE of 0. */ 1692 return 0; 1693 1694 if (BYTES_BIG_ENDIAN && WORDS_BIG_ENDIAN) 1695 return inner_bytes - outer_bytes; 1696 else if (!BYTES_BIG_ENDIAN && !WORDS_BIG_ENDIAN) 1697 return 0; 1698 else 1699 return subreg_size_offset_from_lsb (outer_bytes, inner_bytes, 0); 1700 } 1701 1702 /* Return the SUBREG_BYTE for a highpart subreg whose outer mode has 1703 OUTER_BYTES bytes and whose inner mode has INNER_BYTES bytes. */ 1704 1705 poly_uint64 1706 subreg_size_highpart_offset (poly_uint64 outer_bytes, poly_uint64 inner_bytes) 1707 { 1708 gcc_assert (known_ge (inner_bytes, outer_bytes)); 1709 1710 if (BYTES_BIG_ENDIAN && WORDS_BIG_ENDIAN) 1711 return 0; 1712 else if (!BYTES_BIG_ENDIAN && !WORDS_BIG_ENDIAN) 1713 return inner_bytes - outer_bytes; 1714 else 1715 return subreg_size_offset_from_lsb (outer_bytes, inner_bytes, 1716 (inner_bytes - outer_bytes) 1717 * BITS_PER_UNIT); 1718 } 1719 1720 /* Return true iff X, assumed to be a SUBREG, 1721 refers to the least significant part of its containing reg. 1722 If X is not a SUBREG, always return true (it is its own low part!). */ 1723 1724 bool 1725 subreg_lowpart_p (const_rtx x) 1726 { 1727 if (GET_CODE (x) != SUBREG) 1728 return true; 1729 else if (GET_MODE (SUBREG_REG (x)) == VOIDmode) 1730 return false; 1731 1732 return known_eq (subreg_lowpart_offset (GET_MODE (x), 1733 GET_MODE (SUBREG_REG (x))), 1734 SUBREG_BYTE (x)); 1735 } 1736 1737 /* Return subword OFFSET of operand OP. 1739 The word number, OFFSET, is interpreted as the word number starting 1740 at the low-order address. OFFSET 0 is the low-order word if not 1741 WORDS_BIG_ENDIAN, otherwise it is the high-order word. 1742 1743 If we cannot extract the required word, we return zero. Otherwise, 1744 an rtx corresponding to the requested word will be returned. 1745 1746 VALIDATE_ADDRESS is nonzero if the address should be validated. Before 1747 reload has completed, a valid address will always be returned. After 1748 reload, if a valid address cannot be returned, we return zero. 1749 1750 If VALIDATE_ADDRESS is zero, we simply form the required address; validating 1751 it is the responsibility of the caller. 1752 1753 MODE is the mode of OP in case it is a CONST_INT. 1754 1755 ??? This is still rather broken for some cases. The problem for the 1756 moment is that all callers of this thing provide no 'goal mode' to 1757 tell us to work with. This exists because all callers were written 1758 in a word based SUBREG world. 1759 Now use of this function can be deprecated by simplify_subreg in most 1760 cases. 1761 */ 1762 1763 rtx 1764 operand_subword (rtx op, poly_uint64 offset, int validate_address, 1765 machine_mode mode) 1766 { 1767 if (mode == VOIDmode) 1768 mode = GET_MODE (op); 1769 1770 gcc_assert (mode != VOIDmode); 1771 1772 /* If OP is narrower than a word, fail. */ 1773 if (mode != BLKmode 1774 && maybe_lt (GET_MODE_SIZE (mode), UNITS_PER_WORD)) 1775 return 0; 1776 1777 /* If we want a word outside OP, return zero. */ 1778 if (mode != BLKmode 1779 && maybe_gt ((offset + 1) * UNITS_PER_WORD, GET_MODE_SIZE (mode))) 1780 return const0_rtx; 1781 1782 /* Form a new MEM at the requested address. */ 1783 if (MEM_P (op)) 1784 { 1785 rtx new_rtx = adjust_address_nv (op, word_mode, offset * UNITS_PER_WORD); 1786 1787 if (! validate_address) 1788 return new_rtx; 1789 1790 else if (reload_completed) 1791 { 1792 if (! strict_memory_address_addr_space_p (word_mode, 1793 XEXP (new_rtx, 0), 1794 MEM_ADDR_SPACE (op))) 1795 return 0; 1796 } 1797 else 1798 return replace_equiv_address (new_rtx, XEXP (new_rtx, 0)); 1799 } 1800 1801 /* Rest can be handled by simplify_subreg. */ 1802 return simplify_gen_subreg (word_mode, op, mode, (offset * UNITS_PER_WORD)); 1803 } 1804 1805 /* Similar to `operand_subword', but never return 0. If we can't 1806 extract the required subword, put OP into a register and try again. 1807 The second attempt must succeed. We always validate the address in 1808 this case. 1809 1810 MODE is the mode of OP, in case it is CONST_INT. */ 1811 1812 rtx 1813 operand_subword_force (rtx op, poly_uint64 offset, machine_mode mode) 1814 { 1815 rtx result = operand_subword (op, offset, 1, mode); 1816 1817 if (result) 1818 return result; 1819 1820 if (mode != BLKmode && mode != VOIDmode) 1821 { 1822 /* If this is a register which cannot be accessed by words, copy it 1823 to a pseudo register. */ 1824 if (REG_P (op)) 1825 op = copy_to_reg (op); 1826 else 1827 op = force_reg (mode, op); 1828 } 1829 1830 result = operand_subword (op, offset, 1, mode); 1831 gcc_assert (result); 1832 1833 return result; 1834 } 1835 1836 mem_attrs::mem_attrs () 1838 : expr (NULL_TREE), 1839 offset (0), 1840 size (0), 1841 alias (0), 1842 align (0), 1843 addrspace (ADDR_SPACE_GENERIC), 1844 offset_known_p (false), 1845 size_known_p (false) 1846 {} 1847 1848 /* Returns true if both MEM_EXPR can be considered equal 1849 and false otherwise. */ 1850 1851 bool 1852 mem_expr_equal_p (const_tree expr1, const_tree expr2) 1853 { 1854 if (expr1 == expr2) 1855 return true; 1856 1857 if (! expr1 || ! expr2) 1858 return false; 1859 1860 if (TREE_CODE (expr1) != TREE_CODE (expr2)) 1861 return false; 1862 1863 return operand_equal_p (expr1, expr2, 0); 1864 } 1865 1866 /* Return OFFSET if XEXP (MEM, 0) - OFFSET is known to be ALIGN 1867 bits aligned for 0 <= OFFSET < ALIGN / BITS_PER_UNIT, or 1868 -1 if not known. */ 1869 1870 int 1871 get_mem_align_offset (rtx mem, unsigned int align) 1872 { 1873 tree expr; 1874 poly_uint64 offset; 1875 1876 /* This function can't use 1877 if (!MEM_EXPR (mem) || !MEM_OFFSET_KNOWN_P (mem) 1878 || (MAX (MEM_ALIGN (mem), 1879 MAX (align, get_object_alignment (MEM_EXPR (mem)))) 1880 < align)) 1881 return -1; 1882 else 1883 return (- MEM_OFFSET (mem)) & (align / BITS_PER_UNIT - 1); 1884 for two reasons: 1885 - COMPONENT_REFs in MEM_EXPR can have NULL first operand, 1886 for <variable>. get_inner_reference doesn't handle it and 1887 even if it did, the alignment in that case needs to be determined 1888 from DECL_FIELD_CONTEXT's TYPE_ALIGN. 1889 - it would do suboptimal job for COMPONENT_REFs, even if MEM_EXPR 1890 isn't sufficiently aligned, the object it is in might be. */ 1891 gcc_assert (MEM_P (mem)); 1892 expr = MEM_EXPR (mem); 1893 if (expr == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem)) 1894 return -1; 1895 1896 offset = MEM_OFFSET (mem); 1897 if (DECL_P (expr)) 1898 { 1899 if (DECL_ALIGN (expr) < align) 1900 return -1; 1901 } 1902 else if (INDIRECT_REF_P (expr)) 1903 { 1904 if (TYPE_ALIGN (TREE_TYPE (expr)) < (unsigned int) align) 1905 return -1; 1906 } 1907 else if (TREE_CODE (expr) == COMPONENT_REF) 1908 { 1909 while (1) 1910 { 1911 tree inner = TREE_OPERAND (expr, 0); 1912 tree field = TREE_OPERAND (expr, 1); 1913 tree byte_offset = component_ref_field_offset (expr); 1914 tree bit_offset = DECL_FIELD_BIT_OFFSET (field); 1915 1916 poly_uint64 suboffset; 1917 if (!byte_offset 1918 || !poly_int_tree_p (byte_offset, &suboffset) 1919 || !tree_fits_uhwi_p (bit_offset)) 1920 return -1; 1921 1922 offset += suboffset; 1923 offset += tree_to_uhwi (bit_offset) / BITS_PER_UNIT; 1924 1925 if (inner == NULL_TREE) 1926 { 1927 if (TYPE_ALIGN (DECL_FIELD_CONTEXT (field)) 1928 < (unsigned int) align) 1929 return -1; 1930 break; 1931 } 1932 else if (DECL_P (inner)) 1933 { 1934 if (DECL_ALIGN (inner) < align) 1935 return -1; 1936 break; 1937 } 1938 else if (TREE_CODE (inner) != COMPONENT_REF) 1939 return -1; 1940 expr = inner; 1941 } 1942 } 1943 else 1944 return -1; 1945 1946 HOST_WIDE_INT misalign; 1947 if (!known_misalignment (offset, align / BITS_PER_UNIT, &misalign)) 1948 return -1; 1949 return misalign; 1950 } 1951 1952 /* Given REF (a MEM) and T, either the type of X or the expression 1953 corresponding to REF, set the memory attributes. OBJECTP is nonzero 1954 if we are making a new object of this type. BITPOS is nonzero if 1955 there is an offset outstanding on T that will be applied later. */ 1956 1957 void 1958 set_mem_attributes_minus_bitpos (rtx ref, tree t, int objectp, 1959 poly_int64 bitpos) 1960 { 1961 poly_int64 apply_bitpos = 0; 1962 tree type; 1963 class mem_attrs attrs, *defattrs, *refattrs; 1964 addr_space_t as; 1965 1966 /* It can happen that type_for_mode was given a mode for which there 1967 is no language-level type. In which case it returns NULL, which 1968 we can see here. */ 1969 if (t == NULL_TREE) 1970 return; 1971 1972 type = TYPE_P (t) ? t : TREE_TYPE (t); 1973 if (type == error_mark_node) 1974 return; 1975 1976 /* If we have already set DECL_RTL = ref, get_alias_set will get the 1977 wrong answer, as it assumes that DECL_RTL already has the right alias 1978 info. Callers should not set DECL_RTL until after the call to 1979 set_mem_attributes. */ 1980 gcc_assert (!DECL_P (t) || ref != DECL_RTL_IF_SET (t)); 1981 1982 /* Get the alias set from the expression or type (perhaps using a 1983 front-end routine) and use it. */ 1984 attrs.alias = get_alias_set (t); 1985 1986 MEM_VOLATILE_P (ref) |= TYPE_VOLATILE (type); 1987 MEM_POINTER (ref) = POINTER_TYPE_P (type); 1988 1989 /* Default values from pre-existing memory attributes if present. */ 1990 refattrs = MEM_ATTRS (ref); 1991 if (refattrs) 1992 { 1993 /* ??? Can this ever happen? Calling this routine on a MEM that 1994 already carries memory attributes should probably be invalid. */ 1995 attrs.expr = refattrs->expr; 1996 attrs.offset_known_p = refattrs->offset_known_p; 1997 attrs.offset = refattrs->offset; 1998 attrs.size_known_p = refattrs->size_known_p; 1999 attrs.size = refattrs->size; 2000 attrs.align = refattrs->align; 2001 } 2002 2003 /* Otherwise, default values from the mode of the MEM reference. */ 2004 else 2005 { 2006 defattrs = mode_mem_attrs[(int) GET_MODE (ref)]; 2007 gcc_assert (!defattrs->expr); 2008 gcc_assert (!defattrs->offset_known_p); 2009 2010 /* Respect mode size. */ 2011 attrs.size_known_p = defattrs->size_known_p; 2012 attrs.size = defattrs->size; 2013 /* ??? Is this really necessary? We probably should always get 2014 the size from the type below. */ 2015 2016 /* Respect mode alignment for STRICT_ALIGNMENT targets if T is a type; 2017 if T is an object, always compute the object alignment below. */ 2018 if (TYPE_P (t)) 2019 attrs.align = defattrs->align; 2020 else 2021 attrs.align = BITS_PER_UNIT; 2022 /* ??? If T is a type, respecting mode alignment may *also* be wrong 2023 e.g. if the type carries an alignment attribute. Should we be 2024 able to simply always use TYPE_ALIGN? */ 2025 } 2026 2027 /* We can set the alignment from the type if we are making an object or if 2028 this is an INDIRECT_REF. */ 2029 if (objectp || TREE_CODE (t) == INDIRECT_REF) 2030 attrs.align = MAX (attrs.align, TYPE_ALIGN (type)); 2031 2032 /* If the size is known, we can set that. */ 2033 tree new_size = TYPE_SIZE_UNIT (type); 2034 2035 /* The address-space is that of the type. */ 2036 as = TYPE_ADDR_SPACE (type); 2037 2038 /* If T is not a type, we may be able to deduce some more information about 2039 the expression. */ 2040 if (! TYPE_P (t)) 2041 { 2042 tree base; 2043 2044 if (TREE_THIS_VOLATILE (t)) 2045 MEM_VOLATILE_P (ref) = 1; 2046 2047 /* Now remove any conversions: they don't change what the underlying 2048 object is. Likewise for SAVE_EXPR. */ 2049 while (CONVERT_EXPR_P (t) 2050 || TREE_CODE (t) == VIEW_CONVERT_EXPR 2051 || TREE_CODE (t) == SAVE_EXPR) 2052 t = TREE_OPERAND (t, 0); 2053 2054 /* Note whether this expression can trap. */ 2055 MEM_NOTRAP_P (ref) = !tree_could_trap_p (t); 2056 2057 base = get_base_address (t); 2058 if (base) 2059 { 2060 if (DECL_P (base) 2061 && TREE_READONLY (base) 2062 && (TREE_STATIC (base) || DECL_EXTERNAL (base)) 2063 && !TREE_THIS_VOLATILE (base)) 2064 MEM_READONLY_P (ref) = 1; 2065 2066 /* Mark static const strings readonly as well. */ 2067 if (TREE_CODE (base) == STRING_CST 2068 && TREE_READONLY (base) 2069 && TREE_STATIC (base)) 2070 MEM_READONLY_P (ref) = 1; 2071 2072 /* Address-space information is on the base object. */ 2073 if (TREE_CODE (base) == MEM_REF 2074 || TREE_CODE (base) == TARGET_MEM_REF) 2075 as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (base, 2076 0)))); 2077 else 2078 as = TYPE_ADDR_SPACE (TREE_TYPE (base)); 2079 } 2080 2081 /* If this expression uses it's parent's alias set, mark it such 2082 that we won't change it. */ 2083 if (component_uses_parent_alias_set_from (t) != NULL_TREE) 2084 MEM_KEEP_ALIAS_SET_P (ref) = 1; 2085 2086 /* If this is a decl, set the attributes of the MEM from it. */ 2087 if (DECL_P (t)) 2088 { 2089 attrs.expr = t; 2090 attrs.offset_known_p = true; 2091 attrs.offset = 0; 2092 apply_bitpos = bitpos; 2093 new_size = DECL_SIZE_UNIT (t); 2094 } 2095 2096 /* ??? If we end up with a constant or a descriptor do not 2097 record a MEM_EXPR. */ 2098 else if (CONSTANT_CLASS_P (t) 2099 || TREE_CODE (t) == CONSTRUCTOR) 2100 ; 2101 2102 /* If this is a field reference, record it. */ 2103 else if (TREE_CODE (t) == COMPONENT_REF) 2104 { 2105 attrs.expr = t; 2106 attrs.offset_known_p = true; 2107 attrs.offset = 0; 2108 apply_bitpos = bitpos; 2109 if (DECL_BIT_FIELD (TREE_OPERAND (t, 1))) 2110 new_size = DECL_SIZE_UNIT (TREE_OPERAND (t, 1)); 2111 } 2112 2113 /* Else record it. */ 2114 else 2115 { 2116 gcc_assert (handled_component_p (t) 2117 || TREE_CODE (t) == MEM_REF 2118 || TREE_CODE (t) == TARGET_MEM_REF); 2119 attrs.expr = t; 2120 attrs.offset_known_p = true; 2121 attrs.offset = 0; 2122 apply_bitpos = bitpos; 2123 } 2124 2125 /* If this is a reference based on a partitioned decl replace the 2126 base with a MEM_REF of the pointer representative we created 2127 during stack slot partitioning. */ 2128 if (attrs.expr 2129 && VAR_P (base) 2130 && ! is_global_var (base) 2131 && cfun->gimple_df->decls_to_pointers != NULL) 2132 { 2133 tree *namep = cfun->gimple_df->decls_to_pointers->get (base); 2134 if (namep) 2135 { 2136 attrs.expr = unshare_expr (attrs.expr); 2137 tree *orig_base = &attrs.expr; 2138 while (handled_component_p (*orig_base)) 2139 orig_base = &TREE_OPERAND (*orig_base, 0); 2140 if (TREE_CODE (*orig_base) == MEM_REF 2141 || TREE_CODE (*orig_base) == TARGET_MEM_REF) 2142 TREE_OPERAND (*orig_base, 0) = *namep; 2143 else 2144 { 2145 tree aptrt = reference_alias_ptr_type (*orig_base); 2146 *orig_base = build2 (MEM_REF, TREE_TYPE (*orig_base), 2147 *namep, build_int_cst (aptrt, 0)); 2148 } 2149 } 2150 } 2151 2152 /* Compute the alignment. */ 2153 unsigned int obj_align; 2154 unsigned HOST_WIDE_INT obj_bitpos; 2155 get_object_alignment_1 (t, &obj_align, &obj_bitpos); 2156 unsigned int diff_align = known_alignment (obj_bitpos - bitpos); 2157 if (diff_align != 0) 2158 obj_align = MIN (obj_align, diff_align); 2159 attrs.align = MAX (attrs.align, obj_align); 2160 } 2161 2162 poly_uint64 const_size; 2163 if (poly_int_tree_p (new_size, &const_size)) 2164 { 2165 attrs.size_known_p = true; 2166 attrs.size = const_size; 2167 } 2168 2169 /* If we modified OFFSET based on T, then subtract the outstanding 2170 bit position offset. Similarly, increase the size of the accessed 2171 object to contain the negative offset. */ 2172 if (maybe_ne (apply_bitpos, 0)) 2173 { 2174 gcc_assert (attrs.offset_known_p); 2175 poly_int64 bytepos = bits_to_bytes_round_down (apply_bitpos); 2176 attrs.offset -= bytepos; 2177 if (attrs.size_known_p) 2178 attrs.size += bytepos; 2179 } 2180 2181 /* Now set the attributes we computed above. */ 2182 attrs.addrspace = as; 2183 set_mem_attrs (ref, &attrs); 2184 } 2185 2186 void 2187 set_mem_attributes (rtx ref, tree t, int objectp) 2188 { 2189 set_mem_attributes_minus_bitpos (ref, t, objectp, 0); 2190 } 2191 2192 /* Set the alias set of MEM to SET. */ 2193 2194 void 2195 set_mem_alias_set (rtx mem, alias_set_type set) 2196 { 2197 /* If the new and old alias sets don't conflict, something is wrong. */ 2198 gcc_checking_assert (alias_sets_conflict_p (set, MEM_ALIAS_SET (mem))); 2199 mem_attrs attrs (*get_mem_attrs (mem)); 2200 attrs.alias = set; 2201 set_mem_attrs (mem, &attrs); 2202 } 2203 2204 /* Set the address space of MEM to ADDRSPACE (target-defined). */ 2205 2206 void 2207 set_mem_addr_space (rtx mem, addr_space_t addrspace) 2208 { 2209 mem_attrs attrs (*get_mem_attrs (mem)); 2210 attrs.addrspace = addrspace; 2211 set_mem_attrs (mem, &attrs); 2212 } 2213 2214 /* Set the alignment of MEM to ALIGN bits. */ 2215 2216 void 2217 set_mem_align (rtx mem, unsigned int align) 2218 { 2219 mem_attrs attrs (*get_mem_attrs (mem)); 2220 attrs.align = align; 2221 set_mem_attrs (mem, &attrs); 2222 } 2223 2224 /* Set the expr for MEM to EXPR. */ 2225 2226 void 2227 set_mem_expr (rtx mem, tree expr) 2228 { 2229 mem_attrs attrs (*get_mem_attrs (mem)); 2230 attrs.expr = expr; 2231 set_mem_attrs (mem, &attrs); 2232 } 2233 2234 /* Set the offset of MEM to OFFSET. */ 2235 2236 void 2237 set_mem_offset (rtx mem, poly_int64 offset) 2238 { 2239 mem_attrs attrs (*get_mem_attrs (mem)); 2240 attrs.offset_known_p = true; 2241 attrs.offset = offset; 2242 set_mem_attrs (mem, &attrs); 2243 } 2244 2245 /* Clear the offset of MEM. */ 2246 2247 void 2248 clear_mem_offset (rtx mem) 2249 { 2250 mem_attrs attrs (*get_mem_attrs (mem)); 2251 attrs.offset_known_p = false; 2252 set_mem_attrs (mem, &attrs); 2253 } 2254 2255 /* Set the size of MEM to SIZE. */ 2256 2257 void 2258 set_mem_size (rtx mem, poly_int64 size) 2259 { 2260 mem_attrs attrs (*get_mem_attrs (mem)); 2261 attrs.size_known_p = true; 2262 attrs.size = size; 2263 set_mem_attrs (mem, &attrs); 2264 } 2265 2266 /* Clear the size of MEM. */ 2267 2268 void 2269 clear_mem_size (rtx mem) 2270 { 2271 mem_attrs attrs (*get_mem_attrs (mem)); 2272 attrs.size_known_p = false; 2273 set_mem_attrs (mem, &attrs); 2274 } 2275 2276 /* Return a memory reference like MEMREF, but with its mode changed to MODE 2278 and its address changed to ADDR. (VOIDmode means don't change the mode. 2279 NULL for ADDR means don't change the address.) VALIDATE is nonzero if the 2280 returned memory location is required to be valid. INPLACE is true if any 2281 changes can be made directly to MEMREF or false if MEMREF must be treated 2282 as immutable. 2283 2284 The memory attributes are not changed. */ 2285 2286 static rtx 2287 change_address_1 (rtx memref, machine_mode mode, rtx addr, int validate, 2288 bool inplace) 2289 { 2290 addr_space_t as; 2291 rtx new_rtx; 2292 2293 gcc_assert (MEM_P (memref)); 2294 as = MEM_ADDR_SPACE (memref); 2295 if (mode == VOIDmode) 2296 mode = GET_MODE (memref); 2297 if (addr == 0) 2298 addr = XEXP (memref, 0); 2299 if (mode == GET_MODE (memref) && addr == XEXP (memref, 0) 2300 && (!validate || memory_address_addr_space_p (mode, addr, as))) 2301 return memref; 2302 2303 /* Don't validate address for LRA. LRA can make the address valid 2304 by itself in most efficient way. */ 2305 if (validate && !lra_in_progress) 2306 { 2307 if (reload_in_progress || reload_completed) 2308 gcc_assert (memory_address_addr_space_p (mode, addr, as)); 2309 else 2310 addr = memory_address_addr_space (mode, addr, as); 2311 } 2312 2313 if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref)) 2314 return memref; 2315 2316 if (inplace) 2317 { 2318 XEXP (memref, 0) = addr; 2319 return memref; 2320 } 2321 2322 new_rtx = gen_rtx_MEM (mode, addr); 2323 MEM_COPY_ATTRIBUTES (new_rtx, memref); 2324 return new_rtx; 2325 } 2326 2327 /* Like change_address_1 with VALIDATE nonzero, but we are not saying in what 2328 way we are changing MEMREF, so we only preserve the alias set. */ 2329 2330 rtx 2331 change_address (rtx memref, machine_mode mode, rtx addr) 2332 { 2333 rtx new_rtx = change_address_1 (memref, mode, addr, 1, false); 2334 machine_mode mmode = GET_MODE (new_rtx); 2335 class mem_attrs *defattrs; 2336 2337 mem_attrs attrs (*get_mem_attrs (memref)); 2338 defattrs = mode_mem_attrs[(int) mmode]; 2339 attrs.expr = NULL_TREE; 2340 attrs.offset_known_p = false; 2341 attrs.size_known_p = defattrs->size_known_p; 2342 attrs.size = defattrs->size; 2343 attrs.align = defattrs->align; 2344 2345 /* If there are no changes, just return the original memory reference. */ 2346 if (new_rtx == memref) 2347 { 2348 if (mem_attrs_eq_p (get_mem_attrs (memref), &attrs)) 2349 return new_rtx; 2350 2351 new_rtx = gen_rtx_MEM (mmode, XEXP (memref, 0)); 2352 MEM_COPY_ATTRIBUTES (new_rtx, memref); 2353 } 2354 2355 set_mem_attrs (new_rtx, &attrs); 2356 return new_rtx; 2357 } 2358 2359 /* Return a memory reference like MEMREF, but with its mode changed 2360 to MODE and its address offset by OFFSET bytes. If VALIDATE is 2361 nonzero, the memory address is forced to be valid. 2362 If ADJUST_ADDRESS is zero, OFFSET is only used to update MEM_ATTRS 2363 and the caller is responsible for adjusting MEMREF base register. 2364 If ADJUST_OBJECT is zero, the underlying object associated with the 2365 memory reference is left unchanged and the caller is responsible for 2366 dealing with it. Otherwise, if the new memory reference is outside 2367 the underlying object, even partially, then the object is dropped. 2368 SIZE, if nonzero, is the size of an access in cases where MODE 2369 has no inherent size. */ 2370 2371 rtx 2372 adjust_address_1 (rtx memref, machine_mode mode, poly_int64 offset, 2373 int validate, int adjust_address, int adjust_object, 2374 poly_int64 size) 2375 { 2376 rtx addr = XEXP (memref, 0); 2377 rtx new_rtx; 2378 scalar_int_mode address_mode; 2379 class mem_attrs attrs (*get_mem_attrs (memref)), *defattrs; 2380 unsigned HOST_WIDE_INT max_align; 2381 #ifdef POINTERS_EXTEND_UNSIGNED 2382 scalar_int_mode pointer_mode 2383 = targetm.addr_space.pointer_mode (attrs.addrspace); 2384 #endif 2385 2386 /* VOIDmode means no mode change for change_address_1. */ 2387 if (mode == VOIDmode) 2388 mode = GET_MODE (memref); 2389 2390 /* Take the size of non-BLKmode accesses from the mode. */ 2391 defattrs = mode_mem_attrs[(int) mode]; 2392 if (defattrs->size_known_p) 2393 size = defattrs->size; 2394 2395 /* If there are no changes, just return the original memory reference. */ 2396 if (mode == GET_MODE (memref) 2397 && known_eq (offset, 0) 2398 && (known_eq (size, 0) 2399 || (attrs.size_known_p && known_eq (attrs.size, size))) 2400 && (!validate || memory_address_addr_space_p (mode, addr, 2401 attrs.addrspace))) 2402 return memref; 2403 2404 /* ??? Prefer to create garbage instead of creating shared rtl. 2405 This may happen even if offset is nonzero -- consider 2406 (plus (plus reg reg) const_int) -- so do this always. */ 2407 addr = copy_rtx (addr); 2408 2409 /* Convert a possibly large offset to a signed value within the 2410 range of the target address space. */ 2411 address_mode = get_address_mode (memref); 2412 offset = trunc_int_for_mode (offset, address_mode); 2413 2414 if (adjust_address) 2415 { 2416 /* If MEMREF is a LO_SUM and the offset is within the alignment of the 2417 object, we can merge it into the LO_SUM. */ 2418 if (GET_MODE (memref) != BLKmode 2419 && GET_CODE (addr) == LO_SUM 2420 && known_in_range_p (offset, 2421 0, (GET_MODE_ALIGNMENT (GET_MODE (memref)) 2422 / BITS_PER_UNIT))) 2423 addr = gen_rtx_LO_SUM (address_mode, XEXP (addr, 0), 2424 plus_constant (address_mode, 2425 XEXP (addr, 1), offset)); 2426 #ifdef POINTERS_EXTEND_UNSIGNED 2427 /* If MEMREF is a ZERO_EXTEND from pointer_mode and the offset is valid 2428 in that mode, we merge it into the ZERO_EXTEND. We take advantage of 2429 the fact that pointers are not allowed to overflow. */ 2430 else if (POINTERS_EXTEND_UNSIGNED > 0 2431 && GET_CODE (addr) == ZERO_EXTEND 2432 && GET_MODE (XEXP (addr, 0)) == pointer_mode 2433 && known_eq (trunc_int_for_mode (offset, pointer_mode), offset)) 2434 addr = gen_rtx_ZERO_EXTEND (address_mode, 2435 plus_constant (pointer_mode, 2436 XEXP (addr, 0), offset)); 2437 #endif 2438 else 2439 addr = plus_constant (address_mode, addr, offset); 2440 } 2441 2442 new_rtx = change_address_1 (memref, mode, addr, validate, false); 2443 2444 /* If the address is a REG, change_address_1 rightfully returns memref, 2445 but this would destroy memref's MEM_ATTRS. */ 2446 if (new_rtx == memref && maybe_ne (offset, 0)) 2447 new_rtx = copy_rtx (new_rtx); 2448 2449 /* Conservatively drop the object if we don't know where we start from. */ 2450 if (adjust_object && (!attrs.offset_known_p || !attrs.size_known_p)) 2451 { 2452 attrs.expr = NULL_TREE; 2453 attrs.alias = 0; 2454 } 2455 2456 /* Compute the new values of the memory attributes due to this adjustment. 2457 We add the offsets and update the alignment. */ 2458 if (attrs.offset_known_p) 2459 { 2460 attrs.offset += offset; 2461 2462 /* Drop the object if the new left end is not within its bounds. */ 2463 if (adjust_object && maybe_lt (attrs.offset, 0)) 2464 { 2465 attrs.expr = NULL_TREE; 2466 attrs.alias = 0; 2467 } 2468 } 2469 2470 /* Compute the new alignment by taking the MIN of the alignment and the 2471 lowest-order set bit in OFFSET, but don't change the alignment if OFFSET 2472 if zero. */ 2473 if (maybe_ne (offset, 0)) 2474 { 2475 max_align = known_alignment (offset) * BITS_PER_UNIT; 2476 attrs.align = MIN (attrs.align, max_align); 2477 } 2478 2479 if (maybe_ne (size, 0)) 2480 { 2481 /* Drop the object if the new right end is not within its bounds. */ 2482 if (adjust_object && maybe_gt (offset + size, attrs.size)) 2483 { 2484 attrs.expr = NULL_TREE; 2485 attrs.alias = 0; 2486 } 2487 attrs.size_known_p = true; 2488 attrs.size = size; 2489 } 2490 else if (attrs.size_known_p) 2491 { 2492 gcc_assert (!adjust_object); 2493 attrs.size -= offset; 2494 /* ??? The store_by_pieces machinery generates negative sizes, 2495 so don't assert for that here. */ 2496 } 2497 2498 set_mem_attrs (new_rtx, &attrs); 2499 2500 return new_rtx; 2501 } 2502 2503 /* Return a memory reference like MEMREF, but with its mode changed 2504 to MODE and its address changed to ADDR, which is assumed to be 2505 MEMREF offset by OFFSET bytes. If VALIDATE is 2506 nonzero, the memory address is forced to be valid. */ 2507 2508 rtx 2509 adjust_automodify_address_1 (rtx memref, machine_mode mode, rtx addr, 2510 poly_int64 offset, int validate) 2511 { 2512 memref = change_address_1 (memref, VOIDmode, addr, validate, false); 2513 return adjust_address_1 (memref, mode, offset, validate, 0, 0, 0); 2514 } 2515 2516 /* Return a memory reference like MEMREF, but whose address is changed by 2517 adding OFFSET, an RTX, to it. POW2 is the highest power of two factor 2518 known to be in OFFSET (possibly 1). */ 2519 2520 rtx 2521 offset_address (rtx memref, rtx offset, unsigned HOST_WIDE_INT pow2) 2522 { 2523 rtx new_rtx, addr = XEXP (memref, 0); 2524 machine_mode address_mode; 2525 class mem_attrs *defattrs; 2526 2527 mem_attrs attrs (*get_mem_attrs (memref)); 2528 address_mode = get_address_mode (memref); 2529 new_rtx = simplify_gen_binary (PLUS, address_mode, addr, offset); 2530 2531 /* At this point we don't know _why_ the address is invalid. It 2532 could have secondary memory references, multiplies or anything. 2533 2534 However, if we did go and rearrange things, we can wind up not 2535 being able to recognize the magic around pic_offset_table_rtx. 2536 This stuff is fragile, and is yet another example of why it is 2537 bad to expose PIC machinery too early. */ 2538 if (! memory_address_addr_space_p (GET_MODE (memref), new_rtx, 2539 attrs.addrspace) 2540 && GET_CODE (addr) == PLUS 2541 && XEXP (addr, 0) == pic_offset_table_rtx) 2542 { 2543 addr = force_reg (GET_MODE (addr), addr); 2544 new_rtx = simplify_gen_binary (PLUS, address_mode, addr, offset); 2545 } 2546 2547 update_temp_slot_address (XEXP (memref, 0), new_rtx); 2548 new_rtx = change_address_1 (memref, VOIDmode, new_rtx, 1, false); 2549 2550 /* If there are no changes, just return the original memory reference. */ 2551 if (new_rtx == memref) 2552 return new_rtx; 2553 2554 /* Update the alignment to reflect the offset. Reset the offset, which 2555 we don't know. */ 2556 defattrs = mode_mem_attrs[(int) GET_MODE (new_rtx)]; 2557 attrs.offset_known_p = false; 2558 attrs.size_known_p = defattrs->size_known_p; 2559 attrs.size = defattrs->size; 2560 attrs.align = MIN (attrs.align, pow2 * BITS_PER_UNIT); 2561 set_mem_attrs (new_rtx, &attrs); 2562 return new_rtx; 2563 } 2564 2565 /* Return a memory reference like MEMREF, but with its address changed to 2566 ADDR. The caller is asserting that the actual piece of memory pointed 2567 to is the same, just the form of the address is being changed, such as 2568 by putting something into a register. INPLACE is true if any changes 2569 can be made directly to MEMREF or false if MEMREF must be treated as 2570 immutable. */ 2571 2572 rtx 2573 replace_equiv_address (rtx memref, rtx addr, bool inplace) 2574 { 2575 /* change_address_1 copies the memory attribute structure without change 2576 and that's exactly what we want here. */ 2577 update_temp_slot_address (XEXP (memref, 0), addr); 2578 return change_address_1 (memref, VOIDmode, addr, 1, inplace); 2579 } 2580 2581 /* Likewise, but the reference is not required to be valid. */ 2582 2583 rtx 2584 replace_equiv_address_nv (rtx memref, rtx addr, bool inplace) 2585 { 2586 return change_address_1 (memref, VOIDmode, addr, 0, inplace); 2587 } 2588 2589 2590 /* Emit insns to reload VALUE into a new register. VALUE is an 2591 auto-increment or auto-decrement RTX whose operand is a register or 2592 memory location; so reloading involves incrementing that location. 2593 2594 INC_AMOUNT is the number to increment or decrement by (always 2595 positive and ignored for POST_MODIFY/PRE_MODIFY). 2596 2597 Return a pseudo containing the result. */ 2598 rtx 2599 address_reload_context::emit_autoinc (rtx value, poly_int64 inc_amount) 2600 { 2601 /* Since we're going to call recog, and might be called within recog, 2602 we need to ensure we save and restore recog_data. */ 2603 recog_data_saver recog_save; 2604 2605 /* REG or MEM to be copied and incremented. */ 2606 rtx incloc = XEXP (value, 0); 2607 2608 const rtx_code code = GET_CODE (value); 2609 const bool post_p 2610 = code == POST_DEC || code == POST_INC || code == POST_MODIFY; 2611 2612 bool plus_p = true; 2613 rtx inc; 2614 if (code == PRE_MODIFY || code == POST_MODIFY) 2615 { 2616 gcc_assert (GET_CODE (XEXP (value, 1)) == PLUS 2617 || GET_CODE (XEXP (value, 1)) == MINUS); 2618 gcc_assert (rtx_equal_p (XEXP (XEXP (value, 1), 0), XEXP (value, 0))); 2619 plus_p = GET_CODE (XEXP (value, 1)) == PLUS; 2620 inc = XEXP (XEXP (value, 1), 1); 2621 } 2622 else 2623 { 2624 if (code == PRE_DEC || code == POST_DEC) 2625 inc_amount = -inc_amount; 2626 2627 inc = gen_int_mode (inc_amount, GET_MODE (value)); 2628 } 2629 2630 rtx result; 2631 if (!post_p && REG_P (incloc)) 2632 result = incloc; 2633 else 2634 { 2635 result = get_reload_reg (); 2636 /* First copy the location to the result register. */ 2637 emit_insn (gen_move_insn (result, incloc)); 2638 } 2639 2640 /* See if we can directly increment INCLOC. */ 2641 rtx_insn *last = get_last_insn (); 2642 rtx_insn *add_insn = emit_insn (plus_p 2643 ? gen_add2_insn (incloc, inc) 2644 : gen_sub2_insn (incloc, inc)); 2645 const int icode = recog_memoized (add_insn); 2646 if (icode >= 0) 2647 { 2648 if (!post_p && result != incloc) 2649 emit_insn (gen_move_insn (result, incloc)); 2650 return result; 2651 } 2652 delete_insns_since (last); 2653 2654 /* If couldn't do the increment directly, must increment in RESULT. 2655 The way we do this depends on whether this is pre- or 2656 post-increment. For pre-increment, copy INCLOC to the reload 2657 register, increment it there, then save back. */ 2658 if (!post_p) 2659 { 2660 if (incloc != result) 2661 emit_insn (gen_move_insn (result, incloc)); 2662 if (plus_p) 2663 emit_insn (gen_add2_insn (result, inc)); 2664 else 2665 emit_insn (gen_sub2_insn (result, inc)); 2666 if (incloc != result) 2667 emit_insn (gen_move_insn (incloc, result)); 2668 } 2669 else 2670 { 2671 /* Post-increment. 2672 2673 Because this might be a jump insn or a compare, and because 2674 RESULT may not be available after the insn in an input 2675 reload, we must do the incrementing before the insn being 2676 reloaded for. 2677 2678 We have already copied INCLOC to RESULT. Increment the copy in 2679 RESULT, save that back, then decrement RESULT so it has 2680 the original value. */ 2681 if (plus_p) 2682 emit_insn (gen_add2_insn (result, inc)); 2683 else 2684 emit_insn (gen_sub2_insn (result, inc)); 2685 emit_insn (gen_move_insn (incloc, result)); 2686 /* Restore non-modified value for the result. We prefer this 2687 way because it does not require an additional hard 2688 register. */ 2689 if (plus_p) 2690 { 2691 poly_int64 offset; 2692 if (poly_int_rtx_p (inc, &offset)) 2693 emit_insn (gen_add2_insn (result, 2694 gen_int_mode (-offset, 2695 GET_MODE (result)))); 2696 else 2697 emit_insn (gen_sub2_insn (result, inc)); 2698 } 2699 else 2700 emit_insn (gen_add2_insn (result, inc)); 2701 } 2702 return result; 2703 } 2704 2705 /* Return a memory reference like MEM, but with the address reloaded into a 2706 pseudo register. */ 2707 2708 rtx 2709 force_reload_address (rtx mem) 2710 { 2711 rtx addr = XEXP (mem, 0); 2712 if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC) 2713 { 2714 const auto size = GET_MODE_SIZE (GET_MODE (mem)); 2715 addr = address_reload_context ().emit_autoinc (addr, size); 2716 } 2717 else 2718 addr = force_reg (Pmode, addr); 2719 2720 return replace_equiv_address (mem, addr); 2721 } 2722 2723 /* Return a memory reference like MEMREF, but with its mode widened to 2724 MODE and offset by OFFSET. This would be used by targets that e.g. 2725 cannot issue QImode memory operations and have to use SImode memory 2726 operations plus masking logic. */ 2727 2728 rtx 2729 widen_memory_access (rtx memref, machine_mode mode, poly_int64 offset) 2730 { 2731 rtx new_rtx = adjust_address_1 (memref, mode, offset, 1, 1, 0, 0); 2732 poly_uint64 size = GET_MODE_SIZE (mode); 2733 2734 /* If there are no changes, just return the original memory reference. */ 2735 if (new_rtx == memref) 2736 return new_rtx; 2737 2738 mem_attrs attrs (*get_mem_attrs (new_rtx)); 2739 2740 /* If we don't know what offset we were at within the expression, then 2741 we can't know if we've overstepped the bounds. */ 2742 if (! attrs.offset_known_p) 2743 attrs.expr = NULL_TREE; 2744 2745 while (attrs.expr) 2746 { 2747 if (TREE_CODE (attrs.expr) == COMPONENT_REF) 2748 { 2749 tree field = TREE_OPERAND (attrs.expr, 1); 2750 tree offset = component_ref_field_offset (attrs.expr); 2751 2752 if (! DECL_SIZE_UNIT (field)) 2753 { 2754 attrs.expr = NULL_TREE; 2755 break; 2756 } 2757 2758 /* Is the field at least as large as the access? If so, ok, 2759 otherwise strip back to the containing structure. */ 2760 if (poly_int_tree_p (DECL_SIZE_UNIT (field)) 2761 && known_ge (wi::to_poly_offset (DECL_SIZE_UNIT (field)), size) 2762 && known_ge (attrs.offset, 0)) 2763 break; 2764 2765 poly_uint64 suboffset; 2766 if (!poly_int_tree_p (offset, &suboffset)) 2767 { 2768 attrs.expr = NULL_TREE; 2769 break; 2770 } 2771 2772 attrs.expr = TREE_OPERAND (attrs.expr, 0); 2773 attrs.offset += suboffset; 2774 attrs.offset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field)) 2775 / BITS_PER_UNIT); 2776 } 2777 /* Similarly for the decl. */ 2778 else if (DECL_P (attrs.expr) 2779 && DECL_SIZE_UNIT (attrs.expr) 2780 && poly_int_tree_p (DECL_SIZE_UNIT (attrs.expr)) 2781 && known_ge (wi::to_poly_offset (DECL_SIZE_UNIT (attrs.expr)), 2782 size) 2783 && known_ge (attrs.offset, 0)) 2784 break; 2785 else 2786 { 2787 /* The widened memory access overflows the expression, which means 2788 that it could alias another expression. Zap it. */ 2789 attrs.expr = NULL_TREE; 2790 break; 2791 } 2792 } 2793 2794 if (! attrs.expr) 2795 attrs.offset_known_p = false; 2796 2797 /* The widened memory may alias other stuff, so zap the alias set. */ 2798 /* ??? Maybe use get_alias_set on any remaining expression. */ 2799 attrs.alias = 0; 2800 attrs.size_known_p = true; 2801 attrs.size = size; 2802 set_mem_attrs (new_rtx, &attrs); 2803 return new_rtx; 2804 } 2805 2806 /* A fake decl that is used as the MEM_EXPR of spill slots. */ 2808 static GTY(()) tree spill_slot_decl; 2809 2810 tree 2811 get_spill_slot_decl (bool force_build_p) 2812 { 2813 tree d = spill_slot_decl; 2814 rtx rd; 2815 2816 if (d || !force_build_p) 2817 return d; 2818 2819 d = build_decl (DECL_SOURCE_LOCATION (current_function_decl), 2820 VAR_DECL, get_identifier ("%sfp"), void_type_node); 2821 DECL_ARTIFICIAL (d) = 1; 2822 DECL_IGNORED_P (d) = 1; 2823 TREE_USED (d) = 1; 2824 spill_slot_decl = d; 2825 2826 rd = gen_rtx_MEM (BLKmode, frame_pointer_rtx); 2827 MEM_NOTRAP_P (rd) = 1; 2828 mem_attrs attrs (*mode_mem_attrs[(int) BLKmode]); 2829 attrs.alias = new_alias_set (); 2830 attrs.expr = d; 2831 set_mem_attrs (rd, &attrs); 2832 SET_DECL_RTL (d, rd); 2833 2834 return d; 2835 } 2836 2837 /* Given MEM, a result from assign_stack_local, fill in the memory 2838 attributes as appropriate for a register allocator spill slot. 2839 These slots are not aliasable by other memory. We arrange for 2840 them all to use a single MEM_EXPR, so that the aliasing code can 2841 work properly in the case of shared spill slots. */ 2842 2843 void 2844 set_mem_attrs_for_spill (rtx mem) 2845 { 2846 rtx addr; 2847 2848 mem_attrs attrs (*get_mem_attrs (mem)); 2849 attrs.expr = get_spill_slot_decl (true); 2850 attrs.alias = MEM_ALIAS_SET (DECL_RTL (attrs.expr)); 2851 attrs.addrspace = ADDR_SPACE_GENERIC; 2852 2853 /* We expect the incoming memory to be of the form: 2854 (mem:MODE (plus (reg sfp) (const_int offset))) 2855 with perhaps the plus missing for offset = 0. */ 2856 addr = XEXP (mem, 0); 2857 attrs.offset_known_p = true; 2858 strip_offset (addr, &attrs.offset); 2859 2860 set_mem_attrs (mem, &attrs); 2861 MEM_NOTRAP_P (mem) = 1; 2862 } 2863 2864 /* Return a newly created CODE_LABEL rtx with a unique label number. */ 2866 2867 rtx_code_label * 2868 gen_label_rtx (void) 2869 { 2870 return as_a <rtx_code_label *> ( 2871 gen_rtx_CODE_LABEL (VOIDmode, NULL_RTX, NULL_RTX, 2872 NULL, label_num++, NULL)); 2873 } 2874 2875 /* For procedure integration. */ 2877 2878 /* Install new pointers to the first and last insns in the chain. 2879 Also, set cur_insn_uid to one higher than the last in use. 2880 Used for an inline-procedure after copying the insn chain. */ 2881 2882 void 2883 set_new_first_and_last_insn (rtx_insn *first, rtx_insn *last) 2884 { 2885 rtx_insn *insn; 2886 2887 set_first_insn (first); 2888 set_last_insn (last); 2889 cur_insn_uid = 0; 2890 2891 if (param_min_nondebug_insn_uid || MAY_HAVE_DEBUG_INSNS) 2892 { 2893 int debug_count = 0; 2894 2895 cur_insn_uid = param_min_nondebug_insn_uid - 1; 2896 cur_debug_insn_uid = 0; 2897 2898 for (insn = first; insn; insn = NEXT_INSN (insn)) 2899 if (INSN_UID (insn) < param_min_nondebug_insn_uid) 2900 cur_debug_insn_uid = MAX (cur_debug_insn_uid, INSN_UID (insn)); 2901 else 2902 { 2903 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn)); 2904 if (DEBUG_INSN_P (insn)) 2905 debug_count++; 2906 } 2907 2908 if (debug_count) 2909 cur_debug_insn_uid = param_min_nondebug_insn_uid + debug_count; 2910 else 2911 cur_debug_insn_uid++; 2912 } 2913 else 2914 for (insn = first; insn; insn = NEXT_INSN (insn)) 2915 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn)); 2916 2917 cur_insn_uid++; 2918 } 2919 2920 /* Go through all the RTL insn bodies and copy any invalid shared 2922 structure. This routine should only be called once. */ 2923 2924 static void 2925 unshare_all_rtl_1 (rtx_insn *insn) 2926 { 2927 /* Unshare just about everything else. */ 2928 unshare_all_rtl_in_chain (insn); 2929 2930 /* Make sure the addresses of stack slots found outside the insn chain 2931 (such as, in DECL_RTL of a variable) are not shared 2932 with the insn chain. 2933 2934 This special care is necessary when the stack slot MEM does not 2935 actually appear in the insn chain. If it does appear, its address 2936 is unshared from all else at that point. */ 2937 unsigned int i; 2938 rtx temp; 2939 FOR_EACH_VEC_SAFE_ELT (stack_slot_list, i, temp) 2940 (*stack_slot_list)[i] = copy_rtx_if_shared (temp); 2941 } 2942 2943 /* Go through all the RTL insn bodies and copy any invalid shared 2944 structure, again. This is a fairly expensive thing to do so it 2945 should be done sparingly. */ 2946 2947 void 2948 unshare_all_rtl_again (rtx_insn *insn) 2949 { 2950 rtx_insn *p; 2951 tree decl; 2952 2953 for (p = insn; p; p = NEXT_INSN (p)) 2954 if (INSN_P (p)) 2955 { 2956 reset_used_flags (PATTERN (p)); 2957 reset_used_flags (REG_NOTES (p)); 2958 if (CALL_P (p)) 2959 reset_used_flags (CALL_INSN_FUNCTION_USAGE (p)); 2960 } 2961 2962 /* Make sure that virtual stack slots are not shared. */ 2963 set_used_decls (DECL_INITIAL (cfun->decl)); 2964 2965 /* Make sure that virtual parameters are not shared. */ 2966 for (decl = DECL_ARGUMENTS (cfun->decl); decl; decl = DECL_CHAIN (decl)) 2967 set_used_flags (DECL_RTL (decl)); 2968 2969 rtx temp; 2970 unsigned int i; 2971 FOR_EACH_VEC_SAFE_ELT (stack_slot_list, i, temp) 2972 reset_used_flags (temp); 2973 2974 unshare_all_rtl_1 (insn); 2975 } 2976 2977 void 2978 unshare_all_rtl (void) 2979 { 2980 unshare_all_rtl_1 (get_insns ()); 2981 2982 for (tree decl = DECL_ARGUMENTS (cfun->decl); decl; decl = DECL_CHAIN (decl)) 2983 { 2984 if (DECL_RTL_SET_P (decl)) 2985 SET_DECL_RTL (decl, copy_rtx_if_shared (DECL_RTL (decl))); 2986 DECL_INCOMING_RTL (decl) = copy_rtx_if_shared (DECL_INCOMING_RTL (decl)); 2987 } 2988 } 2989 2990 2991 /* Check that ORIG is not marked when it should not be and mark ORIG as in use, 2992 Recursively does the same for subexpressions. */ 2993 2994 static void 2995 verify_rtx_sharing (rtx orig, rtx insn) 2996 { 2997 rtx x = orig; 2998 int i; 2999 enum rtx_code code; 3000 const char *format_ptr; 3001 3002 if (x == 0) 3003 return; 3004 3005 code = GET_CODE (x); 3006 3007 /* These types may be freely shared. */ 3008 3009 switch (code) 3010 { 3011 case REG: 3012 case DEBUG_EXPR: 3013 case VALUE: 3014 CASE_CONST_ANY: 3015 case SYMBOL_REF: 3016 case LABEL_REF: 3017 case CODE_LABEL: 3018 case PC: 3019 case RETURN: 3020 case SIMPLE_RETURN: 3021 case SCRATCH: 3022 /* SCRATCH must be shared because they represent distinct values. */ 3023 return; 3024 case CLOBBER: 3025 /* Share clobbers of hard registers, but do not share pseudo reg 3026 clobbers or clobbers of hard registers that originated as pseudos. 3027 This is needed to allow safe register renaming. */ 3028 if (REG_P (XEXP (x, 0)) 3029 && HARD_REGISTER_NUM_P (REGNO (XEXP (x, 0))) 3030 && HARD_REGISTER_NUM_P (ORIGINAL_REGNO (XEXP (x, 0)))) 3031 return; 3032 break; 3033 3034 case CONST: 3035 if (shared_const_p (orig)) 3036 return; 3037 break; 3038 3039 case MEM: 3040 /* A MEM is allowed to be shared if its address is constant. */ 3041 if (CONSTANT_ADDRESS_P (XEXP (x, 0)) 3042 || reload_completed || reload_in_progress) 3043 return; 3044 3045 break; 3046 3047 default: 3048 break; 3049 } 3050 3051 /* This rtx may not be shared. If it has already been seen, 3052 replace it with a copy of itself. */ 3053 if (flag_checking && RTX_FLAG (x, used)) 3054 { 3055 error ("invalid rtl sharing found in the insn"); 3056 debug_rtx (insn); 3057 error ("shared rtx"); 3058 debug_rtx (x); 3059 internal_error ("internal consistency failure"); 3060 } 3061 gcc_assert (!RTX_FLAG (x, used)); 3062 3063 RTX_FLAG (x, used) = 1; 3064 3065 /* Now scan the subexpressions recursively. */ 3066 3067 format_ptr = GET_RTX_FORMAT (code); 3068 3069 for (i = 0; i < GET_RTX_LENGTH (code); i++) 3070 { 3071 switch (*format_ptr++) 3072 { 3073 case 'e': 3074 verify_rtx_sharing (XEXP (x, i), insn); 3075 break; 3076 3077 case 'E': 3078 if (XVEC (x, i) != NULL) 3079 { 3080 int j; 3081 int len = XVECLEN (x, i); 3082 3083 for (j = 0; j < len; j++) 3084 { 3085 /* We allow sharing of ASM_OPERANDS inside single 3086 instruction. */ 3087 if (j && GET_CODE (XVECEXP (x, i, j)) == SET 3088 && (GET_CODE (SET_SRC (XVECEXP (x, i, j))) 3089 == ASM_OPERANDS)) 3090 verify_rtx_sharing (SET_DEST (XVECEXP (x, i, j)), insn); 3091 else 3092 verify_rtx_sharing (XVECEXP (x, i, j), insn); 3093 } 3094 } 3095 break; 3096 } 3097 } 3098 } 3099 3100 /* Reset used-flags for INSN. */ 3101 3102 static void 3103 reset_insn_used_flags (rtx insn) 3104 { 3105 gcc_assert (INSN_P (insn)); 3106 reset_used_flags (PATTERN (insn)); 3107 reset_used_flags (REG_NOTES (insn)); 3108 if (CALL_P (insn)) 3109 reset_used_flags (CALL_INSN_FUNCTION_USAGE (insn)); 3110 } 3111 3112 /* Go through all the RTL insn bodies and clear all the USED bits. */ 3113 3114 static void 3115 reset_all_used_flags (void) 3116 { 3117 rtx_insn *p; 3118 3119 for (p = get_insns (); p; p = NEXT_INSN (p)) 3120 if (INSN_P (p)) 3121 { 3122 rtx pat = PATTERN (p); 3123 if (GET_CODE (pat) != SEQUENCE) 3124 reset_insn_used_flags (p); 3125 else 3126 { 3127 gcc_assert (REG_NOTES (p) == NULL); 3128 for (int i = 0; i < XVECLEN (pat, 0); i++) 3129 { 3130 rtx insn = XVECEXP (pat, 0, i); 3131 if (INSN_P (insn)) 3132 reset_insn_used_flags (insn); 3133 } 3134 } 3135 } 3136 } 3137 3138 /* Verify sharing in INSN. */ 3139 3140 static void 3141 verify_insn_sharing (rtx insn) 3142 { 3143 gcc_assert (INSN_P (insn)); 3144 verify_rtx_sharing (PATTERN (insn), insn); 3145 verify_rtx_sharing (REG_NOTES (insn), insn); 3146 if (CALL_P (insn)) 3147 verify_rtx_sharing (CALL_INSN_FUNCTION_USAGE (insn), insn); 3148 } 3149 3150 /* Go through all the RTL insn bodies and check that there is no unexpected 3151 sharing in between the subexpressions. */ 3152 3153 DEBUG_FUNCTION void 3154 verify_rtl_sharing (void) 3155 { 3156 rtx_insn *p; 3157 3158 timevar_push (TV_VERIFY_RTL_SHARING); 3159 3160 reset_all_used_flags (); 3161 3162 for (p = get_insns (); p; p = NEXT_INSN (p)) 3163 if (INSN_P (p)) 3164 { 3165 rtx pat = PATTERN (p); 3166 if (GET_CODE (pat) != SEQUENCE) 3167 verify_insn_sharing (p); 3168 else 3169 for (int i = 0; i < XVECLEN (pat, 0); i++) 3170 { 3171 rtx insn = XVECEXP (pat, 0, i); 3172 if (INSN_P (insn)) 3173 verify_insn_sharing (insn); 3174 } 3175 } 3176 3177 reset_all_used_flags (); 3178 3179 timevar_pop (TV_VERIFY_RTL_SHARING); 3180 } 3181 3182 /* Go through all the RTL insn bodies and copy any invalid shared structure. 3183 Assumes the mark bits are cleared at entry. */ 3184 3185 void 3186 unshare_all_rtl_in_chain (rtx_insn *insn) 3187 { 3188 for (; insn; insn = NEXT_INSN (insn)) 3189 if (INSN_P (insn)) 3190 { 3191 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn)); 3192 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn)); 3193 if (CALL_P (insn)) 3194 CALL_INSN_FUNCTION_USAGE (insn) 3195 = copy_rtx_if_shared (CALL_INSN_FUNCTION_USAGE (insn)); 3196 } 3197 } 3198 3199 /* Go through all virtual stack slots of a function and mark them as 3200 shared. We never replace the DECL_RTLs themselves with a copy, 3201 but expressions mentioned into a DECL_RTL cannot be shared with 3202 expressions in the instruction stream. 3203 3204 Note that reload may convert pseudo registers into memories in-place. 3205 Pseudo registers are always shared, but MEMs never are. Thus if we 3206 reset the used flags on MEMs in the instruction stream, we must set 3207 them again on MEMs that appear in DECL_RTLs. */ 3208 3209 static void 3210 set_used_decls (tree blk) 3211 { 3212 tree t; 3213 3214 /* Mark decls. */ 3215 for (t = BLOCK_VARS (blk); t; t = DECL_CHAIN (t)) 3216 if (DECL_RTL_SET_P (t)) 3217 set_used_flags (DECL_RTL (t)); 3218 3219 /* Now process sub-blocks. */ 3220 for (t = BLOCK_SUBBLOCKS (blk); t; t = BLOCK_CHAIN (t)) 3221 set_used_decls (t); 3222 } 3223 3224 /* Mark ORIG as in use, and return a copy of it if it was already in use. 3225 Recursively does the same for subexpressions. Uses 3226 copy_rtx_if_shared_1 to reduce stack space. */ 3227 3228 rtx 3229 copy_rtx_if_shared (rtx orig) 3230 { 3231 copy_rtx_if_shared_1 (&orig); 3232 return orig; 3233 } 3234 3235 /* Mark *ORIG1 as in use, and set it to a copy of it if it was already in 3236 use. Recursively does the same for subexpressions. */ 3237 3238 static void 3239 copy_rtx_if_shared_1 (rtx *orig1) 3240 { 3241 rtx x; 3242 int i; 3243 enum rtx_code code; 3244 rtx *last_ptr; 3245 const char *format_ptr; 3246 int copied = 0; 3247 int length; 3248 3249 /* Repeat is used to turn tail-recursion into iteration. */ 3250 repeat: 3251 x = *orig1; 3252 3253 if (x == 0) 3254 return; 3255 3256 code = GET_CODE (x); 3257 3258 /* These types may be freely shared. */ 3259 3260 switch (code) 3261 { 3262 case REG: 3263 case DEBUG_EXPR: 3264 case VALUE: 3265 CASE_CONST_ANY: 3266 case SYMBOL_REF: 3267 case LABEL_REF: 3268 case CODE_LABEL: 3269 case PC: 3270 case RETURN: 3271 case SIMPLE_RETURN: 3272 case SCRATCH: 3273 /* SCRATCH must be shared because they represent distinct values. */ 3274 return; 3275 case CLOBBER: 3276 /* Share clobbers of hard registers, but do not share pseudo reg 3277 clobbers or clobbers of hard registers that originated as pseudos. 3278 This is needed to allow safe register renaming. */ 3279 if (REG_P (XEXP (x, 0)) 3280 && HARD_REGISTER_NUM_P (REGNO (XEXP (x, 0))) 3281 && HARD_REGISTER_NUM_P (ORIGINAL_REGNO (XEXP (x, 0)))) 3282 return; 3283 break; 3284 3285 case CONST: 3286 if (shared_const_p (x)) 3287 return; 3288 break; 3289 3290 case DEBUG_INSN: 3291 case INSN: 3292 case JUMP_INSN: 3293 case CALL_INSN: 3294 case NOTE: 3295 case BARRIER: 3296 /* The chain of insns is not being copied. */ 3297 return; 3298 3299 default: 3300 break; 3301 } 3302 3303 /* This rtx may not be shared. If it has already been seen, 3304 replace it with a copy of itself. */ 3305 3306 if (RTX_FLAG (x, used)) 3307 { 3308 x = shallow_copy_rtx (x); 3309 copied = 1; 3310 } 3311 RTX_FLAG (x, used) = 1; 3312 3313 /* Now scan the subexpressions recursively. 3314 We can store any replaced subexpressions directly into X 3315 since we know X is not shared! Any vectors in X 3316 must be copied if X was copied. */ 3317 3318 format_ptr = GET_RTX_FORMAT (code); 3319 length = GET_RTX_LENGTH (code); 3320 last_ptr = NULL; 3321 3322 for (i = 0; i < length; i++) 3323 { 3324 switch (*format_ptr++) 3325 { 3326 case 'e': 3327 if (last_ptr) 3328 copy_rtx_if_shared_1 (last_ptr); 3329 last_ptr = &XEXP (x, i); 3330 break; 3331 3332 case 'E': 3333 if (XVEC (x, i) != NULL) 3334 { 3335 int j; 3336 int len = XVECLEN (x, i); 3337 3338 /* Copy the vector iff I copied the rtx and the length 3339 is nonzero. */ 3340 if (copied && len > 0) 3341 XVEC (x, i) = gen_rtvec_v (len, XVEC (x, i)->elem); 3342 3343 /* Call recursively on all inside the vector. */ 3344 for (j = 0; j < len; j++) 3345 { 3346 if (last_ptr) 3347 copy_rtx_if_shared_1 (last_ptr); 3348 last_ptr = &XVECEXP (x, i, j); 3349 } 3350 } 3351 break; 3352 } 3353 } 3354 *orig1 = x; 3355 if (last_ptr) 3356 { 3357 orig1 = last_ptr; 3358 goto repeat; 3359 } 3360 } 3361 3362 /* Set the USED bit in X and its non-shareable subparts to FLAG. */ 3363 3364 static void 3365 mark_used_flags (rtx x, int flag) 3366 { 3367 int i, j; 3368 enum rtx_code code; 3369 const char *format_ptr; 3370 int length; 3371 3372 /* Repeat is used to turn tail-recursion into iteration. */ 3373 repeat: 3374 if (x == 0) 3375 return; 3376 3377 code = GET_CODE (x); 3378 3379 /* These types may be freely shared so we needn't do any resetting 3380 for them. */ 3381 3382 switch (code) 3383 { 3384 case REG: 3385 case DEBUG_EXPR: 3386 case VALUE: 3387 CASE_CONST_ANY: 3388 case SYMBOL_REF: 3389 case CODE_LABEL: 3390 case PC: 3391 case RETURN: 3392 case SIMPLE_RETURN: 3393 return; 3394 3395 case DEBUG_INSN: 3396 case INSN: 3397 case JUMP_INSN: 3398 case CALL_INSN: 3399 case NOTE: 3400 case LABEL_REF: 3401 case BARRIER: 3402 /* The chain of insns is not being copied. */ 3403 return; 3404 3405 default: 3406 break; 3407 } 3408 3409 RTX_FLAG (x, used) = flag; 3410 3411 format_ptr = GET_RTX_FORMAT (code); 3412 length = GET_RTX_LENGTH (code); 3413 3414 for (i = 0; i < length; i++) 3415 { 3416 switch (*format_ptr++) 3417 { 3418 case 'e': 3419 if (i == length-1) 3420 { 3421 x = XEXP (x, i); 3422 goto repeat; 3423 } 3424 mark_used_flags (XEXP (x, i), flag); 3425 break; 3426 3427 case 'E': 3428 for (j = 0; j < XVECLEN (x, i); j++) 3429 mark_used_flags (XVECEXP (x, i, j), flag); 3430 break; 3431 } 3432 } 3433 } 3434 3435 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used 3436 to look for shared sub-parts. */ 3437 3438 void 3439 reset_used_flags (rtx x) 3440 { 3441 mark_used_flags (x, 0); 3442 } 3443 3444 /* Set all the USED bits in X to allow copy_rtx_if_shared to be used 3445 to look for shared sub-parts. */ 3446 3447 void 3448 set_used_flags (rtx x) 3449 { 3450 mark_used_flags (x, 1); 3451 } 3452 3453 /* Copy X if necessary so that it won't be altered by changes in OTHER. 3455 Return X or the rtx for the pseudo reg the value of X was copied into. 3456 OTHER must be valid as a SET_DEST. */ 3457 3458 rtx 3459 make_safe_from (rtx x, rtx other) 3460 { 3461 while (1) 3462 switch (GET_CODE (other)) 3463 { 3464 case SUBREG: 3465 other = SUBREG_REG (other); 3466 break; 3467 case STRICT_LOW_PART: 3468 case SIGN_EXTEND: 3469 case ZERO_EXTEND: 3470 other = XEXP (other, 0); 3471 break; 3472 default: 3473 goto done; 3474 } 3475 done: 3476 if ((MEM_P (other) 3477 && ! CONSTANT_P (x) 3478 && !REG_P (x) 3479 && GET_CODE (x) != SUBREG) 3480 || (REG_P (other) 3481 && (REGNO (other) < FIRST_PSEUDO_REGISTER 3482 || reg_mentioned_p (other, x)))) 3483 { 3484 rtx temp = gen_reg_rtx (GET_MODE (x)); 3485 emit_move_insn (temp, x); 3486 return temp; 3487 } 3488 return x; 3489 } 3490 3491 /* Emission of insns (adding them to the doubly-linked list). */ 3493 3494 /* Return the last insn emitted, even if it is in a sequence now pushed. */ 3495 3496 rtx_insn * 3497 get_last_insn_anywhere (void) 3498 { 3499 struct sequence_stack *seq; 3500 for (seq = get_current_sequence (); seq; seq = seq->next) 3501 if (seq->last != 0) 3502 return seq->last; 3503 return 0; 3504 } 3505 3506 /* Return the first nonnote insn emitted in current sequence or current 3507 function. This routine looks inside SEQUENCEs. */ 3508 3509 rtx_insn * 3510 get_first_nonnote_insn (void) 3511 { 3512 rtx_insn *insn = get_insns (); 3513 3514 if (insn) 3515 { 3516 if (NOTE_P (insn)) 3517 for (insn = next_insn (insn); 3518 insn && NOTE_P (insn); 3519 insn = next_insn (insn)) 3520 continue; 3521 else 3522 { 3523 if (NONJUMP_INSN_P (insn) 3524 && GET_CODE (PATTERN (insn)) == SEQUENCE) 3525 insn = as_a <rtx_sequence *> (PATTERN (insn))->insn (0); 3526 } 3527 } 3528 3529 return insn; 3530 } 3531 3532 /* Return the last nonnote insn emitted in current sequence or current 3533 function. This routine looks inside SEQUENCEs. */ 3534 3535 rtx_insn * 3536 get_last_nonnote_insn (void) 3537 { 3538 rtx_insn *insn = get_last_insn (); 3539 3540 if (insn) 3541 { 3542 if (NOTE_P (insn)) 3543 for (insn = previous_insn (insn); 3544 insn && NOTE_P (insn); 3545 insn = previous_insn (insn)) 3546 continue; 3547 else 3548 { 3549 if (NONJUMP_INSN_P (insn)) 3550 if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn))) 3551 insn = seq->insn (seq->len () - 1); 3552 } 3553 } 3554 3555 return insn; 3556 } 3557 3558 /* Return the number of actual (non-debug) insns emitted in this 3559 function. */ 3560 3561 int 3562 get_max_insn_count (void) 3563 { 3564 int n = cur_insn_uid; 3565 3566 /* The table size must be stable across -g, to avoid codegen 3567 differences due to debug insns, and not be affected by 3568 -fmin-insn-uid, to avoid excessive table size and to simplify 3569 debugging of -fcompare-debug failures. */ 3570 if (cur_debug_insn_uid > param_min_nondebug_insn_uid) 3571 n -= cur_debug_insn_uid; 3572 else 3573 n -= param_min_nondebug_insn_uid; 3574 3575 return n; 3576 } 3577 3578 3579 /* Return the next insn. If it is a SEQUENCE, return the first insn 3581 of the sequence. */ 3582 3583 rtx_insn * 3584 next_insn (rtx_insn *insn) 3585 { 3586 if (insn) 3587 { 3588 insn = NEXT_INSN (insn); 3589 if (insn && NONJUMP_INSN_P (insn) 3590 && GET_CODE (PATTERN (insn)) == SEQUENCE) 3591 insn = as_a <rtx_sequence *> (PATTERN (insn))->insn (0); 3592 } 3593 3594 return insn; 3595 } 3596 3597 /* Return the previous insn. If it is a SEQUENCE, return the last insn 3598 of the sequence. */ 3599 3600 rtx_insn * 3601 previous_insn (rtx_insn *insn) 3602 { 3603 if (insn) 3604 { 3605 insn = PREV_INSN (insn); 3606 if (insn && NONJUMP_INSN_P (insn)) 3607 if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn))) 3608 insn = seq->insn (seq->len () - 1); 3609 } 3610 3611 return insn; 3612 } 3613 3614 /* Return the next insn after INSN that is not a NOTE. This routine does not 3615 look inside SEQUENCEs. */ 3616 3617 rtx_insn * 3618 next_nonnote_insn (rtx_insn *insn) 3619 { 3620 while (insn) 3621 { 3622 insn = NEXT_INSN (insn); 3623 if (insn == 0 || !NOTE_P (insn)) 3624 break; 3625 } 3626 3627 return insn; 3628 } 3629 3630 /* Return the next insn after INSN that is not a DEBUG_INSN. This 3631 routine does not look inside SEQUENCEs. */ 3632 3633 rtx_insn * 3634 next_nondebug_insn (rtx_insn *insn) 3635 { 3636 while (insn) 3637 { 3638 insn = NEXT_INSN (insn); 3639 if (insn == 0 || !DEBUG_INSN_P (insn)) 3640 break; 3641 } 3642 3643 return insn; 3644 } 3645 3646 /* Return the previous insn before INSN that is not a NOTE. This routine does 3647 not look inside SEQUENCEs. */ 3648 3649 rtx_insn * 3650 prev_nonnote_insn (rtx_insn *insn) 3651 { 3652 while (insn) 3653 { 3654 insn = PREV_INSN (insn); 3655 if (insn == 0 || !NOTE_P (insn)) 3656 break; 3657 } 3658 3659 return insn; 3660 } 3661 3662 /* Return the previous insn before INSN that is not a DEBUG_INSN. 3663 This routine does not look inside SEQUENCEs. */ 3664 3665 rtx_insn * 3666 prev_nondebug_insn (rtx_insn *insn) 3667 { 3668 while (insn) 3669 { 3670 insn = PREV_INSN (insn); 3671 if (insn == 0 || !DEBUG_INSN_P (insn)) 3672 break; 3673 } 3674 3675 return insn; 3676 } 3677 3678 /* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN. 3679 This routine does not look inside SEQUENCEs. */ 3680 3681 rtx_insn * 3682 next_nonnote_nondebug_insn (rtx_insn *insn) 3683 { 3684 while (insn) 3685 { 3686 insn = NEXT_INSN (insn); 3687 if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn))) 3688 break; 3689 } 3690 3691 return insn; 3692 } 3693 3694 /* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN, 3695 but stop the search before we enter another basic block. This 3696 routine does not look inside SEQUENCEs. */ 3697 3698 rtx_insn * 3699 next_nonnote_nondebug_insn_bb (rtx_insn *insn) 3700 { 3701 while (insn) 3702 { 3703 insn = NEXT_INSN (insn); 3704 if (insn == 0) 3705 break; 3706 if (DEBUG_INSN_P (insn)) 3707 continue; 3708 if (!NOTE_P (insn)) 3709 break; 3710 if (NOTE_INSN_BASIC_BLOCK_P (insn)) 3711 return NULL; 3712 } 3713 3714 return insn; 3715 } 3716 3717 /* Return the previous insn before INSN that is not a NOTE nor DEBUG_INSN. 3718 This routine does not look inside SEQUENCEs. */ 3719 3720 rtx_insn * 3721 prev_nonnote_nondebug_insn (rtx_insn *insn) 3722 { 3723 while (insn) 3724 { 3725 insn = PREV_INSN (insn); 3726 if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn))) 3727 break; 3728 } 3729 3730 return insn; 3731 } 3732 3733 /* Return the previous insn before INSN that is not a NOTE nor 3734 DEBUG_INSN, but stop the search before we enter another basic 3735 block. This routine does not look inside SEQUENCEs. */ 3736 3737 rtx_insn * 3738 prev_nonnote_nondebug_insn_bb (rtx_insn *insn) 3739 { 3740 while (insn) 3741 { 3742 insn = PREV_INSN (insn); 3743 if (insn == 0) 3744 break; 3745 if (DEBUG_INSN_P (insn)) 3746 continue; 3747 if (!NOTE_P (insn)) 3748 break; 3749 if (NOTE_INSN_BASIC_BLOCK_P (insn)) 3750 return NULL; 3751 } 3752 3753 return insn; 3754 } 3755 3756 /* Return the next INSN, CALL_INSN, JUMP_INSN or DEBUG_INSN after INSN; 3757 or 0, if there is none. This routine does not look inside 3758 SEQUENCEs. */ 3759 3760 rtx_insn * 3761 next_real_insn (rtx_insn *insn) 3762 { 3763 while (insn) 3764 { 3765 insn = NEXT_INSN (insn); 3766 if (insn == 0 || INSN_P (insn)) 3767 break; 3768 } 3769 3770 return insn; 3771 } 3772 3773 /* Return the last INSN, CALL_INSN, JUMP_INSN or DEBUG_INSN before INSN; 3774 or 0, if there is none. This routine does not look inside 3775 SEQUENCEs. */ 3776 3777 rtx_insn * 3778 prev_real_insn (rtx_insn *insn) 3779 { 3780 while (insn) 3781 { 3782 insn = PREV_INSN (insn); 3783 if (insn == 0 || INSN_P (insn)) 3784 break; 3785 } 3786 3787 return insn; 3788 } 3789 3790 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN; 3791 or 0, if there is none. This routine does not look inside 3792 SEQUENCEs. */ 3793 3794 rtx_insn * 3795 next_real_nondebug_insn (rtx uncast_insn) 3796 { 3797 rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn); 3798 3799 while (insn) 3800 { 3801 insn = NEXT_INSN (insn); 3802 if (insn == 0 || NONDEBUG_INSN_P (insn)) 3803 break; 3804 } 3805 3806 return insn; 3807 } 3808 3809 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN; 3810 or 0, if there is none. This routine does not look inside 3811 SEQUENCEs. */ 3812 3813 rtx_insn * 3814 prev_real_nondebug_insn (rtx_insn *insn) 3815 { 3816 while (insn) 3817 { 3818 insn = PREV_INSN (insn); 3819 if (insn == 0 || NONDEBUG_INSN_P (insn)) 3820 break; 3821 } 3822 3823 return insn; 3824 } 3825 3826 /* Return the last CALL_INSN in the current list, or 0 if there is none. 3827 This routine does not look inside SEQUENCEs. */ 3828 3829 rtx_call_insn * 3830 last_call_insn (void) 3831 { 3832 rtx_insn *insn; 3833 3834 for (insn = get_last_insn (); 3835 insn && !CALL_P (insn); 3836 insn = PREV_INSN (insn)) 3837 ; 3838 3839 return safe_as_a <rtx_call_insn *> (insn); 3840 } 3841 3842 bool 3843 active_insn_p (const rtx_insn *insn) 3844 { 3845 return (CALL_P (insn) || JUMP_P (insn) 3846 || JUMP_TABLE_DATA_P (insn) /* FIXME */ 3847 || (NONJUMP_INSN_P (insn) 3848 && (! reload_completed 3849 || (GET_CODE (PATTERN (insn)) != USE 3850 && GET_CODE (PATTERN (insn)) != CLOBBER)))); 3851 } 3852 3853 /* Find the next insn after INSN that really does something. This routine 3854 does not look inside SEQUENCEs. After reload this also skips over 3855 standalone USE and CLOBBER insn. */ 3856 3857 rtx_insn * 3858 next_active_insn (rtx_insn *insn) 3859 { 3860 while (insn) 3861 { 3862 insn = NEXT_INSN (insn); 3863 if (insn == 0 || active_insn_p (insn)) 3864 break; 3865 } 3866 3867 return insn; 3868 } 3869 3870 /* Find the last insn before INSN that really does something. This routine 3871 does not look inside SEQUENCEs. After reload this also skips over 3872 standalone USE and CLOBBER insn. */ 3873 3874 rtx_insn * 3875 prev_active_insn (rtx_insn *insn) 3876 { 3877 while (insn) 3878 { 3879 insn = PREV_INSN (insn); 3880 if (insn == 0 || active_insn_p (insn)) 3881 break; 3882 } 3883 3884 return insn; 3885 } 3886 3887 /* Find a RTX_AUTOINC class rtx which matches DATA. */ 3889 3890 static int 3891 find_auto_inc (const_rtx x, const_rtx reg) 3892 { 3893 subrtx_iterator::array_type array; 3894 FOR_EACH_SUBRTX (iter, array, x, NONCONST) 3895 { 3896 const_rtx x = *iter; 3897 if (GET_RTX_CLASS (GET_CODE (x)) == RTX_AUTOINC 3898 && rtx_equal_p (reg, XEXP (x, 0))) 3899 return true; 3900 } 3901 return false; 3902 } 3903 3904 /* Increment the label uses for all labels present in rtx. */ 3905 3906 static void 3907 mark_label_nuses (rtx x) 3908 { 3909 enum rtx_code code; 3910 int i, j; 3911 const char *fmt; 3912 3913 code = GET_CODE (x); 3914 if (code == LABEL_REF && LABEL_P (label_ref_label (x))) 3915 LABEL_NUSES (label_ref_label (x))++; 3916 3917 fmt = GET_RTX_FORMAT (code); 3918 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 3919 { 3920 if (fmt[i] == 'e') 3921 mark_label_nuses (XEXP (x, i)); 3922 else if (fmt[i] == 'E') 3923 for (j = XVECLEN (x, i) - 1; j >= 0; j--) 3924 mark_label_nuses (XVECEXP (x, i, j)); 3925 } 3926 } 3927 3928 3929 /* Try splitting insns that can be split for better scheduling. 3931 PAT is the pattern which might split. 3932 TRIAL is the insn providing PAT. 3933 LAST is nonzero if we should return the last insn of the sequence produced. 3934 3935 If this routine succeeds in splitting, it returns the first or last 3936 replacement insn depending on the value of LAST. Otherwise, it 3937 returns TRIAL. If the insn to be returned can be split, it will be. */ 3938 3939 rtx_insn * 3940 try_split (rtx pat, rtx_insn *trial, int last) 3941 { 3942 rtx_insn *before, *after; 3943 rtx note; 3944 rtx_insn *seq, *tem; 3945 profile_probability probability; 3946 rtx_insn *insn_last, *insn; 3947 int njumps = 0; 3948 rtx_insn *call_insn = NULL; 3949 3950 if (any_condjump_p (trial) 3951 && (note = find_reg_note (trial, REG_BR_PROB, 0))) 3952 split_branch_probability 3953 = profile_probability::from_reg_br_prob_note (XINT (note, 0)); 3954 else 3955 split_branch_probability = profile_probability::uninitialized (); 3956 3957 probability = split_branch_probability; 3958 3959 seq = split_insns (pat, trial); 3960 3961 split_branch_probability = profile_probability::uninitialized (); 3962 3963 if (!seq) 3964 return trial; 3965 3966 int split_insn_count = 0; 3967 /* Avoid infinite loop if any insn of the result matches 3968 the original pattern. */ 3969 insn_last = seq; 3970 while (1) 3971 { 3972 if (INSN_P (insn_last) 3973 && rtx_equal_p (PATTERN (insn_last), pat)) 3974 return trial; 3975 split_insn_count++; 3976 if (!NEXT_INSN (insn_last)) 3977 break; 3978 insn_last = NEXT_INSN (insn_last); 3979 } 3980 3981 /* We're not good at redistributing frame information if 3982 the split occurs before reload or if it results in more 3983 than one insn. */ 3984 if (RTX_FRAME_RELATED_P (trial)) 3985 { 3986 if (!reload_completed || split_insn_count != 1) 3987 return trial; 3988 3989 rtx_insn *new_insn = seq; 3990 rtx_insn *old_insn = trial; 3991 copy_frame_info_to_split_insn (old_insn, new_insn); 3992 } 3993 3994 /* We will be adding the new sequence to the function. The splitters 3995 may have introduced invalid RTL sharing, so unshare the sequence now. */ 3996 unshare_all_rtl_in_chain (seq); 3997 3998 /* Mark labels and copy flags. */ 3999 for (insn = insn_last; insn ; insn = PREV_INSN (insn)) 4000 { 4001 if (JUMP_P (insn)) 4002 { 4003 if (JUMP_P (trial)) 4004 CROSSING_JUMP_P (insn) = CROSSING_JUMP_P (trial); 4005 mark_jump_label (PATTERN (insn), insn, 0); 4006 njumps++; 4007 if (probability.initialized_p () 4008 && any_condjump_p (insn) 4009 && !find_reg_note (insn, REG_BR_PROB, 0)) 4010 { 4011 /* We can preserve the REG_BR_PROB notes only if exactly 4012 one jump is created, otherwise the machine description 4013 is responsible for this step using 4014 split_branch_probability variable. */ 4015 gcc_assert (njumps == 1); 4016 add_reg_br_prob_note (insn, probability); 4017 } 4018 } 4019 } 4020 4021 /* If we are splitting a CALL_INSN, look for the CALL_INSN 4022 in SEQ and copy any additional information across. */ 4023 if (CALL_P (trial)) 4024 { 4025 for (insn = insn_last; insn ; insn = PREV_INSN (insn)) 4026 if (CALL_P (insn)) 4027 { 4028 gcc_assert (call_insn == NULL_RTX); 4029 call_insn = insn; 4030 4031 /* Add the old CALL_INSN_FUNCTION_USAGE to whatever the 4032 target may have explicitly specified. */ 4033 rtx *p = &CALL_INSN_FUNCTION_USAGE (insn); 4034 while (*p) 4035 p = &XEXP (*p, 1); 4036 *p = CALL_INSN_FUNCTION_USAGE (trial); 4037 4038 /* If the old call was a sibling call, the new one must 4039 be too. */ 4040 SIBLING_CALL_P (insn) = SIBLING_CALL_P (trial); 4041 } 4042 } 4043 4044 /* Copy notes, particularly those related to the CFG. */ 4045 for (note = REG_NOTES (trial); note; note = XEXP (note, 1)) 4046 { 4047 switch (REG_NOTE_KIND (note)) 4048 { 4049 case REG_EH_REGION: 4050 copy_reg_eh_region_note_backward (note, insn_last, NULL); 4051 break; 4052 4053 case REG_NORETURN: 4054 case REG_SETJMP: 4055 case REG_TM: 4056 case REG_CALL_NOCF_CHECK: 4057 case REG_CALL_ARG_LOCATION: 4058 for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn)) 4059 { 4060 if (CALL_P (insn)) 4061 add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0)); 4062 } 4063 break; 4064 4065 case REG_NON_LOCAL_GOTO: 4066 case REG_LABEL_TARGET: 4067 for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn)) 4068 { 4069 if (JUMP_P (insn)) 4070 add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0)); 4071 } 4072 break; 4073 4074 case REG_INC: 4075 if (!AUTO_INC_DEC) 4076 break; 4077 4078 for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn)) 4079 { 4080 rtx reg = XEXP (note, 0); 4081 if (!FIND_REG_INC_NOTE (insn, reg) 4082 && find_auto_inc (PATTERN (insn), reg)) 4083 add_reg_note (insn, REG_INC, reg); 4084 } 4085 break; 4086 4087 case REG_ARGS_SIZE: 4088 fixup_args_size_notes (NULL, insn_last, get_args_size (note)); 4089 break; 4090 4091 case REG_CALL_DECL: 4092 case REG_UNTYPED_CALL: 4093 gcc_assert (call_insn != NULL_RTX); 4094 add_reg_note (call_insn, REG_NOTE_KIND (note), XEXP (note, 0)); 4095 break; 4096 4097 default: 4098 break; 4099 } 4100 } 4101 4102 /* If there are LABELS inside the split insns increment the 4103 usage count so we don't delete the label. */ 4104 if (INSN_P (trial)) 4105 { 4106 insn = insn_last; 4107 while (insn != NULL_RTX) 4108 { 4109 /* JUMP_P insns have already been "marked" above. */ 4110 if (NONJUMP_INSN_P (insn)) 4111 mark_label_nuses (PATTERN (insn)); 4112 4113 insn = PREV_INSN (insn); 4114 } 4115 } 4116 4117 before = PREV_INSN (trial); 4118 after = NEXT_INSN (trial); 4119 4120 emit_insn_after_setloc (seq, trial, INSN_LOCATION (trial)); 4121 4122 delete_insn (trial); 4123 4124 /* Recursively call try_split for each new insn created; by the 4125 time control returns here that insn will be fully split, so 4126 set LAST and continue from the insn after the one returned. 4127 We can't use next_active_insn here since AFTER may be a note. 4128 Ignore deleted insns, which can be occur if not optimizing. */ 4129 for (tem = NEXT_INSN (before); tem != after; tem = NEXT_INSN (tem)) 4130 if (! tem->deleted () && INSN_P (tem)) 4131 tem = try_split (PATTERN (tem), tem, 1); 4132 4133 /* Return either the first or the last insn, depending on which was 4134 requested. */ 4135 return last 4136 ? (after ? PREV_INSN (after) : get_last_insn ()) 4137 : NEXT_INSN (before); 4138 } 4139 4140 /* Make and return an INSN rtx, initializing all its slots. 4142 Store PATTERN in the pattern slots. */ 4143 4144 rtx_insn * 4145 make_insn_raw (rtx pattern) 4146 { 4147 rtx_insn *insn; 4148 4149 insn = as_a <rtx_insn *> (rtx_alloc (INSN)); 4150 4151 INSN_UID (insn) = cur_insn_uid++; 4152 PATTERN (insn) = pattern; 4153 INSN_CODE (insn) = -1; 4154 REG_NOTES (insn) = NULL; 4155 INSN_LOCATION (insn) = curr_insn_location (); 4156 BLOCK_FOR_INSN (insn) = NULL; 4157 4158 #ifdef ENABLE_RTL_CHECKING 4159 if (insn 4160 && INSN_P (insn) 4161 && (returnjump_p (insn) 4162 || (GET_CODE (insn) == SET 4163 && SET_DEST (insn) == pc_rtx))) 4164 { 4165 warning (0, "ICE: %<emit_insn%> used where %<emit_jump_insn%> needed:"); 4166 debug_rtx (insn); 4167 } 4168 #endif 4169 4170 return insn; 4171 } 4172 4173 /* Like `make_insn_raw' but make a DEBUG_INSN instead of an insn. */ 4174 4175 static rtx_insn * 4176 make_debug_insn_raw (rtx pattern) 4177 { 4178 rtx_debug_insn *insn; 4179 4180 insn = as_a <rtx_debug_insn *> (rtx_alloc (DEBUG_INSN)); 4181 INSN_UID (insn) = cur_debug_insn_uid++; 4182 if (cur_debug_insn_uid > param_min_nondebug_insn_uid) 4183 INSN_UID (insn) = cur_insn_uid++; 4184 4185 PATTERN (insn) = pattern; 4186 INSN_CODE (insn) = -1; 4187 REG_NOTES (insn) = NULL; 4188 INSN_LOCATION (insn) = curr_insn_location (); 4189 BLOCK_FOR_INSN (insn) = NULL; 4190 4191 return insn; 4192 } 4193 4194 /* Like `make_insn_raw' but make a JUMP_INSN instead of an insn. */ 4195 4196 static rtx_insn * 4197 make_jump_insn_raw (rtx pattern) 4198 { 4199 rtx_jump_insn *insn; 4200 4201 insn = as_a <rtx_jump_insn *> (rtx_alloc (JUMP_INSN)); 4202 INSN_UID (insn) = cur_insn_uid++; 4203 4204 PATTERN (insn) = pattern; 4205 INSN_CODE (insn) = -1; 4206 REG_NOTES (insn) = NULL; 4207 JUMP_LABEL (insn) = NULL; 4208 INSN_LOCATION (insn) = curr_insn_location (); 4209 BLOCK_FOR_INSN (insn) = NULL; 4210 4211 return insn; 4212 } 4213 4214 /* Like `make_insn_raw' but make a CALL_INSN instead of an insn. */ 4215 4216 static rtx_insn * 4217 make_call_insn_raw (rtx pattern) 4218 { 4219 rtx_call_insn *insn; 4220 4221 insn = as_a <rtx_call_insn *> (rtx_alloc (CALL_INSN)); 4222 INSN_UID (insn) = cur_insn_uid++; 4223 4224 PATTERN (insn) = pattern; 4225 INSN_CODE (insn) = -1; 4226 REG_NOTES (insn) = NULL; 4227 CALL_INSN_FUNCTION_USAGE (insn) = NULL; 4228 INSN_LOCATION (insn) = curr_insn_location (); 4229 BLOCK_FOR_INSN (insn) = NULL; 4230 4231 return insn; 4232 } 4233 4234 /* Like `make_insn_raw' but make a NOTE instead of an insn. */ 4235 4236 static rtx_note * 4237 make_note_raw (enum insn_note subtype) 4238 { 4239 /* Some notes are never created this way at all. These notes are 4240 only created by patching out insns. */ 4241 gcc_assert (subtype != NOTE_INSN_DELETED_LABEL 4242 && subtype != NOTE_INSN_DELETED_DEBUG_LABEL); 4243 4244 rtx_note *note = as_a <rtx_note *> (rtx_alloc (NOTE)); 4245 INSN_UID (note) = cur_insn_uid++; 4246 NOTE_KIND (note) = subtype; 4247 BLOCK_FOR_INSN (note) = NULL; 4248 memset (&NOTE_DATA (note), 0, sizeof (NOTE_DATA (note))); 4249 return note; 4250 } 4251 4252 /* Add INSN to the end of the doubly-linked list, between PREV and NEXT. 4254 INSN may be any object that can appear in the chain: INSN_P and NOTE_P objects, 4255 but also BARRIERs and JUMP_TABLE_DATAs. PREV and NEXT may be NULL. */ 4256 4257 static inline void 4258 link_insn_into_chain (rtx_insn *insn, rtx_insn *prev, rtx_insn *next) 4259 { 4260 SET_PREV_INSN (insn) = prev; 4261 SET_NEXT_INSN (insn) = next; 4262 if (prev != NULL) 4263 { 4264 SET_NEXT_INSN (prev) = insn; 4265 if (NONJUMP_INSN_P (prev) && GET_CODE (PATTERN (prev)) == SEQUENCE) 4266 { 4267 rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (prev)); 4268 SET_NEXT_INSN (sequence->insn (sequence->len () - 1)) = insn; 4269 } 4270 } 4271 if (next != NULL) 4272 { 4273 SET_PREV_INSN (next) = insn; 4274 if (NONJUMP_INSN_P (next) && GET_CODE (PATTERN (next)) == SEQUENCE) 4275 { 4276 rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (next)); 4277 SET_PREV_INSN (sequence->insn (0)) = insn; 4278 } 4279 } 4280 4281 if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE) 4282 { 4283 rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (insn)); 4284 SET_PREV_INSN (sequence->insn (0)) = prev; 4285 SET_NEXT_INSN (sequence->insn (sequence->len () - 1)) = next; 4286 } 4287 } 4288 4289 /* Add INSN to the end of the doubly-linked list. 4290 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */ 4291 4292 void 4293 add_insn (rtx_insn *insn) 4294 { 4295 rtx_insn *prev = get_last_insn (); 4296 link_insn_into_chain (insn, prev, NULL); 4297 if (get_insns () == NULL) 4298 set_first_insn (insn); 4299 set_last_insn (insn); 4300 } 4301 4302 /* Add INSN into the doubly-linked list after insn AFTER. */ 4303 4304 static void 4305 add_insn_after_nobb (rtx_insn *insn, rtx_insn *after) 4306 { 4307 rtx_insn *next = NEXT_INSN (after); 4308 4309 gcc_assert (!optimize || !after->deleted ()); 4310 4311 link_insn_into_chain (insn, after, next); 4312 4313 if (next == NULL) 4314 { 4315 struct sequence_stack *seq; 4316 4317 for (seq = get_current_sequence (); seq; seq = seq->next) 4318 if (after == seq->last) 4319 { 4320 seq->last = insn; 4321 break; 4322 } 4323 } 4324 } 4325 4326 /* Add INSN into the doubly-linked list before insn BEFORE. */ 4327 4328 static void 4329 add_insn_before_nobb (rtx_insn *insn, rtx_insn *before) 4330 { 4331 rtx_insn *prev = PREV_INSN (before); 4332 4333 gcc_assert (!optimize || !before->deleted ()); 4334 4335 link_insn_into_chain (insn, prev, before); 4336 4337 if (prev == NULL) 4338 { 4339 struct sequence_stack *seq; 4340 4341 for (seq = get_current_sequence (); seq; seq = seq->next) 4342 if (before == seq->first) 4343 { 4344 seq->first = insn; 4345 break; 4346 } 4347 4348 gcc_assert (seq); 4349 } 4350 } 4351 4352 /* Like add_insn_after_nobb, but try to set BLOCK_FOR_INSN. 4353 If BB is NULL, an attempt is made to infer the bb from before. 4354 4355 This and the next function should be the only functions called 4356 to insert an insn once delay slots have been filled since only 4357 they know how to update a SEQUENCE. */ 4358 4359 void 4360 add_insn_after (rtx_insn *insn, rtx_insn *after, basic_block bb) 4361 { 4362 add_insn_after_nobb (insn, after); 4363 if (!BARRIER_P (after) 4364 && !BARRIER_P (insn) 4365 && (bb = BLOCK_FOR_INSN (after))) 4366 { 4367 set_block_for_insn (insn, bb); 4368 if (INSN_P (insn)) 4369 df_insn_rescan (insn); 4370 /* Should not happen as first in the BB is always 4371 either NOTE or LABEL. */ 4372 if (BB_END (bb) == after 4373 /* Avoid clobbering of structure when creating new BB. */ 4374 && !BARRIER_P (insn) 4375 && !NOTE_INSN_BASIC_BLOCK_P (insn)) 4376 BB_END (bb) = insn; 4377 } 4378 } 4379 4380 /* Like add_insn_before_nobb, but try to set BLOCK_FOR_INSN. 4381 If BB is NULL, an attempt is made to infer the bb from before. 4382 4383 This and the previous function should be the only functions called 4384 to insert an insn once delay slots have been filled since only 4385 they know how to update a SEQUENCE. */ 4386 4387 void 4388 add_insn_before (rtx_insn *insn, rtx_insn *before, basic_block bb) 4389 { 4390 add_insn_before_nobb (insn, before); 4391 4392 if (!bb 4393 && !BARRIER_P (before) 4394 && !BARRIER_P (insn)) 4395 bb = BLOCK_FOR_INSN (before); 4396 4397 if (bb) 4398 { 4399 set_block_for_insn (insn, bb); 4400 if (INSN_P (insn)) 4401 df_insn_rescan (insn); 4402 /* Should not happen as first in the BB is always either NOTE or 4403 LABEL. */ 4404 gcc_assert (BB_HEAD (bb) != insn 4405 /* Avoid clobbering of structure when creating new BB. */ 4406 || BARRIER_P (insn) 4407 || NOTE_INSN_BASIC_BLOCK_P (insn)); 4408 } 4409 } 4410 4411 /* Replace insn with an deleted instruction note. */ 4412 4413 void 4414 set_insn_deleted (rtx_insn *insn) 4415 { 4416 if (INSN_P (insn)) 4417 df_insn_delete (insn); 4418 PUT_CODE (insn, NOTE); 4419 NOTE_KIND (insn) = NOTE_INSN_DELETED; 4420 } 4421 4422 4423 /* Unlink INSN from the insn chain. 4424 4425 This function knows how to handle sequences. 4426 4427 This function does not invalidate data flow information associated with 4428 INSN (i.e. does not call df_insn_delete). That makes this function 4429 usable for only disconnecting an insn from the chain, and re-emit it 4430 elsewhere later. 4431 4432 To later insert INSN elsewhere in the insn chain via add_insn and 4433 similar functions, PREV_INSN and NEXT_INSN must be nullified by 4434 the caller. Nullifying them here breaks many insn chain walks. 4435 4436 To really delete an insn and related DF information, use delete_insn. */ 4437 4438 void 4439 remove_insn (rtx_insn *insn) 4440 { 4441 rtx_insn *next = NEXT_INSN (insn); 4442 rtx_insn *prev = PREV_INSN (insn); 4443 basic_block bb; 4444 4445 if (prev) 4446 { 4447 SET_NEXT_INSN (prev) = next; 4448 if (NONJUMP_INSN_P (prev) && GET_CODE (PATTERN (prev)) == SEQUENCE) 4449 { 4450 rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (prev)); 4451 SET_NEXT_INSN (sequence->insn (sequence->len () - 1)) = next; 4452 } 4453 } 4454 else 4455 { 4456 struct sequence_stack *seq; 4457 4458 for (seq = get_current_sequence (); seq; seq = seq->next) 4459 if (insn == seq->first) 4460 { 4461 seq->first = next; 4462 break; 4463 } 4464 4465 gcc_assert (seq); 4466 } 4467 4468 if (next) 4469 { 4470 SET_PREV_INSN (next) = prev; 4471 if (NONJUMP_INSN_P (next) && GET_CODE (PATTERN (next)) == SEQUENCE) 4472 { 4473 rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (next)); 4474 SET_PREV_INSN (sequence->insn (0)) = prev; 4475 } 4476 } 4477 else 4478 { 4479 struct sequence_stack *seq; 4480 4481 for (seq = get_current_sequence (); seq; seq = seq->next) 4482 if (insn == seq->last) 4483 { 4484 seq->last = prev; 4485 break; 4486 } 4487 4488 gcc_assert (seq); 4489 } 4490 4491 /* Fix up basic block boundaries, if necessary. */ 4492 if (!BARRIER_P (insn) 4493 && (bb = BLOCK_FOR_INSN (insn))) 4494 { 4495 if (BB_HEAD (bb) == insn) 4496 { 4497 /* Never ever delete the basic block note without deleting whole 4498 basic block. */ 4499 gcc_assert (!NOTE_P (insn)); 4500 BB_HEAD (bb) = next; 4501 } 4502 if (BB_END (bb) == insn) 4503 BB_END (bb) = prev; 4504 } 4505 } 4506 4507 /* Append CALL_FUSAGE to the CALL_INSN_FUNCTION_USAGE for CALL_INSN. */ 4508 4509 void 4510 add_function_usage_to (rtx call_insn, rtx call_fusage) 4511 { 4512 gcc_assert (call_insn && CALL_P (call_insn)); 4513 4514 /* Put the register usage information on the CALL. If there is already 4515 some usage information, put ours at the end. */ 4516 if (CALL_INSN_FUNCTION_USAGE (call_insn)) 4517 { 4518 rtx link; 4519 4520 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0; 4521 link = XEXP (link, 1)) 4522 ; 4523 4524 XEXP (link, 1) = call_fusage; 4525 } 4526 else 4527 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage; 4528 } 4529 4530 /* Delete all insns made since FROM. 4531 FROM becomes the new last instruction. */ 4532 4533 void 4534 delete_insns_since (rtx_insn *from) 4535 { 4536 if (from == 0) 4537 set_first_insn (0); 4538 else 4539 SET_NEXT_INSN (from) = 0; 4540 set_last_insn (from); 4541 } 4542 4543 /* This function is deprecated, please use sequences instead. 4544 4545 Move a consecutive bunch of insns to a different place in the chain. 4546 The insns to be moved are those between FROM and TO. 4547 They are moved to a new position after the insn AFTER. 4548 AFTER must not be FROM or TO or any insn in between. 4549 4550 This function does not know about SEQUENCEs and hence should not be 4551 called after delay-slot filling has been done. */ 4552 4553 void 4554 reorder_insns_nobb (rtx_insn *from, rtx_insn *to, rtx_insn *after) 4555 { 4556 if (flag_checking) 4557 { 4558 for (rtx_insn *x = from; x != to; x = NEXT_INSN (x)) 4559 gcc_assert (after != x); 4560 gcc_assert (after != to); 4561 } 4562 4563 /* Splice this bunch out of where it is now. */ 4564 if (PREV_INSN (from)) 4565 SET_NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to); 4566 if (NEXT_INSN (to)) 4567 SET_PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from); 4568 if (get_last_insn () == to) 4569 set_last_insn (PREV_INSN (from)); 4570 if (get_insns () == from) 4571 set_first_insn (NEXT_INSN (to)); 4572 4573 /* Make the new neighbors point to it and it to them. */ 4574 if (NEXT_INSN (after)) 4575 SET_PREV_INSN (NEXT_INSN (after)) = to; 4576 4577 SET_NEXT_INSN (to) = NEXT_INSN (after); 4578 SET_PREV_INSN (from) = after; 4579 SET_NEXT_INSN (after) = from; 4580 if (after == get_last_insn ()) 4581 set_last_insn (to); 4582 } 4583 4584 /* Same as function above, but take care to update BB boundaries. */ 4585 void 4586 reorder_insns (rtx_insn *from, rtx_insn *to, rtx_insn *after) 4587 { 4588 rtx_insn *prev = PREV_INSN (from); 4589 basic_block bb, bb2; 4590 4591 reorder_insns_nobb (from, to, after); 4592 4593 if (!BARRIER_P (after) 4594 && (bb = BLOCK_FOR_INSN (after))) 4595 { 4596 rtx_insn *x; 4597 df_set_bb_dirty (bb); 4598 4599 if (!BARRIER_P (from) 4600 && (bb2 = BLOCK_FOR_INSN (from))) 4601 { 4602 if (BB_END (bb2) == to) 4603 BB_END (bb2) = prev; 4604 df_set_bb_dirty (bb2); 4605 } 4606 4607 if (BB_END (bb) == after) 4608 BB_END (bb) = to; 4609 4610 for (x = from; x != NEXT_INSN (to); x = NEXT_INSN (x)) 4611 if (!BARRIER_P (x)) 4612 df_insn_change_bb (x, bb); 4613 } 4614 } 4615 4616 4617 /* Emit insn(s) of given code and pattern 4619 at a specified place within the doubly-linked list. 4620 4621 All of the emit_foo global entry points accept an object 4622 X which is either an insn list or a PATTERN of a single 4623 instruction. 4624 4625 There are thus a few canonical ways to generate code and 4626 emit it at a specific place in the instruction stream. For 4627 example, consider the instruction named SPOT and the fact that 4628 we would like to emit some instructions before SPOT. We might 4629 do it like this: 4630 4631 start_sequence (); 4632 ... emit the new instructions ... 4633 insns_head = get_insns (); 4634 end_sequence (); 4635 4636 emit_insn_before (insns_head, SPOT); 4637 4638 It used to be common to generate SEQUENCE rtl instead, but that 4639 is a relic of the past which no longer occurs. The reason is that 4640 SEQUENCE rtl results in much fragmented RTL memory since the SEQUENCE 4641 generated would almost certainly die right after it was created. */ 4642 4643 static rtx_insn * 4644 emit_pattern_before_noloc (rtx x, rtx_insn *before, rtx_insn *last, 4645 basic_block bb, 4646 rtx_insn *(*make_raw) (rtx)) 4647 { 4648 rtx_insn *insn; 4649 4650 gcc_assert (before); 4651 4652 if (x == NULL_RTX) 4653 return last; 4654 4655 switch (GET_CODE (x)) 4656 { 4657 case DEBUG_INSN: 4658 case INSN: 4659 case JUMP_INSN: 4660 case CALL_INSN: 4661 case CODE_LABEL: 4662 case BARRIER: 4663 case NOTE: 4664 insn = as_a <rtx_insn *> (x); 4665 while (insn) 4666 { 4667 rtx_insn *next = NEXT_INSN (insn); 4668 add_insn_before (insn, before, bb); 4669 last = insn; 4670 insn = next; 4671 } 4672 break; 4673 4674 #ifdef ENABLE_RTL_CHECKING 4675 case SEQUENCE: 4676 gcc_unreachable (); 4677 break; 4678 #endif 4679 4680 default: 4681 last = (*make_raw) (x); 4682 add_insn_before (last, before, bb); 4683 break; 4684 } 4685 4686 return last; 4687 } 4688 4689 /* Make X be output before the instruction BEFORE. */ 4690 4691 rtx_insn * 4692 emit_insn_before_noloc (rtx x, rtx_insn *before, basic_block bb) 4693 { 4694 return emit_pattern_before_noloc (x, before, before, bb, make_insn_raw); 4695 } 4696 4697 /* Make an instruction with body X and code JUMP_INSN 4698 and output it before the instruction BEFORE. */ 4699 4700 rtx_jump_insn * 4701 emit_jump_insn_before_noloc (rtx x, rtx_insn *before) 4702 { 4703 return as_a <rtx_jump_insn *> ( 4704 emit_pattern_before_noloc (x, before, NULL, NULL, 4705 make_jump_insn_raw)); 4706 } 4707 4708 /* Make an instruction with body X and code CALL_INSN 4709 and output it before the instruction BEFORE. */ 4710 4711 rtx_insn * 4712 emit_call_insn_before_noloc (rtx x, rtx_insn *before) 4713 { 4714 return emit_pattern_before_noloc (x, before, NULL, NULL, 4715 make_call_insn_raw); 4716 } 4717 4718 /* Make an instruction with body X and code DEBUG_INSN 4719 and output it before the instruction BEFORE. */ 4720 4721 rtx_insn * 4722 emit_debug_insn_before_noloc (rtx x, rtx_insn *before) 4723 { 4724 return emit_pattern_before_noloc (x, before, NULL, NULL, 4725 make_debug_insn_raw); 4726 } 4727 4728 /* Make an insn of code BARRIER 4729 and output it before the insn BEFORE. */ 4730 4731 rtx_barrier * 4732 emit_barrier_before (rtx_insn *before) 4733 { 4734 rtx_barrier *insn = as_a <rtx_barrier *> (rtx_alloc (BARRIER)); 4735 4736 INSN_UID (insn) = cur_insn_uid++; 4737 4738 add_insn_before (insn, before, NULL); 4739 return insn; 4740 } 4741 4742 /* Emit the label LABEL before the insn BEFORE. */ 4743 4744 rtx_code_label * 4745 emit_label_before (rtx_code_label *label, rtx_insn *before) 4746 { 4747 gcc_checking_assert (INSN_UID (label) == 0); 4748 INSN_UID (label) = cur_insn_uid++; 4749 add_insn_before (label, before, NULL); 4750 return label; 4751 } 4752 4753 /* Helper for emit_insn_after, handles lists of instructions 4755 efficiently. */ 4756 4757 static rtx_insn * 4758 emit_insn_after_1 (rtx_insn *first, rtx_insn *after, basic_block bb) 4759 { 4760 rtx_insn *last; 4761 rtx_insn *after_after; 4762 if (!bb && !BARRIER_P (after)) 4763 bb = BLOCK_FOR_INSN (after); 4764 4765 if (bb) 4766 { 4767 df_set_bb_dirty (bb); 4768 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last)) 4769 if (!BARRIER_P (last)) 4770 { 4771 set_block_for_insn (last, bb); 4772 df_insn_rescan (last); 4773 } 4774 if (!BARRIER_P (last)) 4775 { 4776 set_block_for_insn (last, bb); 4777 df_insn_rescan (last); 4778 } 4779 if (BB_END (bb) == after) 4780 BB_END (bb) = last; 4781 } 4782 else 4783 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last)) 4784 continue; 4785 4786 after_after = NEXT_INSN (after); 4787 4788 SET_NEXT_INSN (after) = first; 4789 SET_PREV_INSN (first) = after; 4790 SET_NEXT_INSN (last) = after_after; 4791 if (after_after) 4792 SET_PREV_INSN (after_after) = last; 4793 4794 if (after == get_last_insn ()) 4795 set_last_insn (last); 4796 4797 return last; 4798 } 4799 4800 static rtx_insn * 4801 emit_pattern_after_noloc (rtx x, rtx_insn *after, basic_block bb, 4802 rtx_insn *(*make_raw)(rtx)) 4803 { 4804 rtx_insn *last = after; 4805 4806 gcc_assert (after); 4807 4808 if (x == NULL_RTX) 4809 return last; 4810 4811 switch (GET_CODE (x)) 4812 { 4813 case DEBUG_INSN: 4814 case INSN: 4815 case JUMP_INSN: 4816 case CALL_INSN: 4817 case CODE_LABEL: 4818 case BARRIER: 4819 case NOTE: 4820 last = emit_insn_after_1 (as_a <rtx_insn *> (x), after, bb); 4821 break; 4822 4823 #ifdef ENABLE_RTL_CHECKING 4824 case SEQUENCE: 4825 gcc_unreachable (); 4826 break; 4827 #endif 4828 4829 default: 4830 last = (*make_raw) (x); 4831 add_insn_after (last, after, bb); 4832 break; 4833 } 4834 4835 return last; 4836 } 4837 4838 /* Make X be output after the insn AFTER and set the BB of insn. If 4839 BB is NULL, an attempt is made to infer the BB from AFTER. */ 4840 4841 rtx_insn * 4842 emit_insn_after_noloc (rtx x, rtx_insn *after, basic_block bb) 4843 { 4844 return emit_pattern_after_noloc (x, after, bb, make_insn_raw); 4845 } 4846 4847 4848 /* Make an insn of code JUMP_INSN with body X 4849 and output it after the insn AFTER. */ 4850 4851 rtx_jump_insn * 4852 emit_jump_insn_after_noloc (rtx x, rtx_insn *after) 4853 { 4854 return as_a <rtx_jump_insn *> ( 4855 emit_pattern_after_noloc (x, after, NULL, make_jump_insn_raw)); 4856 } 4857 4858 /* Make an instruction with body X and code CALL_INSN 4859 and output it after the instruction AFTER. */ 4860 4861 rtx_insn * 4862 emit_call_insn_after_noloc (rtx x, rtx_insn *after) 4863 { 4864 return emit_pattern_after_noloc (x, after, NULL, make_call_insn_raw); 4865 } 4866 4867 /* Make an instruction with body X and code CALL_INSN 4868 and output it after the instruction AFTER. */ 4869 4870 rtx_insn * 4871 emit_debug_insn_after_noloc (rtx x, rtx_insn *after) 4872 { 4873 return emit_pattern_after_noloc (x, after, NULL, make_debug_insn_raw); 4874 } 4875 4876 /* Make an insn of code BARRIER 4877 and output it after the insn AFTER. */ 4878 4879 rtx_barrier * 4880 emit_barrier_after (rtx_insn *after) 4881 { 4882 rtx_barrier *insn = as_a <rtx_barrier *> (rtx_alloc (BARRIER)); 4883 4884 INSN_UID (insn) = cur_insn_uid++; 4885 4886 add_insn_after (insn, after, NULL); 4887 return insn; 4888 } 4889 4890 /* Emit the label LABEL after the insn AFTER. */ 4891 4892 rtx_insn * 4893 emit_label_after (rtx_insn *label, rtx_insn *after) 4894 { 4895 gcc_checking_assert (INSN_UID (label) == 0); 4896 INSN_UID (label) = cur_insn_uid++; 4897 add_insn_after (label, after, NULL); 4898 return label; 4899 } 4900 4901 /* Notes require a bit of special handling: Some notes need to have their 4903 BLOCK_FOR_INSN set, others should never have it set, and some should 4904 have it set or clear depending on the context. */ 4905 4906 /* Return true iff a note of kind SUBTYPE should be emitted with routines 4907 that never set BLOCK_FOR_INSN on NOTE. BB_BOUNDARY is true if the 4908 caller is asked to emit a note before BB_HEAD, or after BB_END. */ 4909 4910 static bool 4911 note_outside_basic_block_p (enum insn_note subtype, bool on_bb_boundary_p) 4912 { 4913 switch (subtype) 4914 { 4915 /* NOTE_INSN_SWITCH_TEXT_SECTIONS only appears between basic blocks. */ 4916 case NOTE_INSN_SWITCH_TEXT_SECTIONS: 4917 return true; 4918 4919 /* Notes for var tracking and EH region markers can appear between or 4920 inside basic blocks. If the caller is emitting on the basic block 4921 boundary, do not set BLOCK_FOR_INSN on the new note. */ 4922 case NOTE_INSN_VAR_LOCATION: 4923 case NOTE_INSN_EH_REGION_BEG: 4924 case NOTE_INSN_EH_REGION_END: 4925 return on_bb_boundary_p; 4926 4927 /* Otherwise, BLOCK_FOR_INSN must be set. */ 4928 default: 4929 return false; 4930 } 4931 } 4932 4933 /* Emit a note of subtype SUBTYPE after the insn AFTER. */ 4934 4935 rtx_note * 4936 emit_note_after (enum insn_note subtype, rtx_insn *after) 4937 { 4938 rtx_note *note = make_note_raw (subtype); 4939 basic_block bb = BARRIER_P (after) ? NULL : BLOCK_FOR_INSN (after); 4940 bool on_bb_boundary_p = (bb != NULL && BB_END (bb) == after); 4941 4942 if (note_outside_basic_block_p (subtype, on_bb_boundary_p)) 4943 add_insn_after_nobb (note, after); 4944 else 4945 add_insn_after (note, after, bb); 4946 return note; 4947 } 4948 4949 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */ 4950 4951 rtx_note * 4952 emit_note_before (enum insn_note subtype, rtx_insn *before) 4953 { 4954 rtx_note *note = make_note_raw (subtype); 4955 basic_block bb = BARRIER_P (before) ? NULL : BLOCK_FOR_INSN (before); 4956 bool on_bb_boundary_p = (bb != NULL && BB_HEAD (bb) == before); 4957 4958 if (note_outside_basic_block_p (subtype, on_bb_boundary_p)) 4959 add_insn_before_nobb (note, before); 4960 else 4961 add_insn_before (note, before, bb); 4962 return note; 4963 } 4964 4965 /* Insert PATTERN after AFTER, setting its INSN_LOCATION to LOC. 4967 MAKE_RAW indicates how to turn PATTERN into a real insn. */ 4968 4969 static rtx_insn * 4970 emit_pattern_after_setloc (rtx pattern, rtx_insn *after, location_t loc, 4971 rtx_insn *(*make_raw) (rtx)) 4972 { 4973 rtx_insn *last = emit_pattern_after_noloc (pattern, after, NULL, make_raw); 4974 4975 if (pattern == NULL_RTX || !loc) 4976 return last; 4977 4978 after = NEXT_INSN (after); 4979 while (1) 4980 { 4981 if (active_insn_p (after) 4982 && !JUMP_TABLE_DATA_P (after) /* FIXME */ 4983 && !INSN_LOCATION (after)) 4984 INSN_LOCATION (after) = loc; 4985 if (after == last) 4986 break; 4987 after = NEXT_INSN (after); 4988 } 4989 return last; 4990 } 4991 4992 /* Insert PATTERN after AFTER. MAKE_RAW indicates how to turn PATTERN 4993 into a real insn. SKIP_DEBUG_INSNS indicates whether to insert after 4994 any DEBUG_INSNs. */ 4995 4996 static rtx_insn * 4997 emit_pattern_after (rtx pattern, rtx_insn *after, bool skip_debug_insns, 4998 rtx_insn *(*make_raw) (rtx)) 4999 { 5000 rtx_insn *prev = after; 5001 5002 if (skip_debug_insns) 5003 while (DEBUG_INSN_P (prev)) 5004 prev = PREV_INSN (prev); 5005 5006 if (INSN_P (prev)) 5007 return emit_pattern_after_setloc (pattern, after, INSN_LOCATION (prev), 5008 make_raw); 5009 else 5010 return emit_pattern_after_noloc (pattern, after, NULL, make_raw); 5011 } 5012 5013 /* Like emit_insn_after_noloc, but set INSN_LOCATION according to LOC. */ 5014 rtx_insn * 5015 emit_insn_after_setloc (rtx pattern, rtx_insn *after, location_t loc) 5016 { 5017 return emit_pattern_after_setloc (pattern, after, loc, make_insn_raw); 5018 } 5019 5020 /* Like emit_insn_after_noloc, but set INSN_LOCATION according to AFTER. */ 5021 rtx_insn * 5022 emit_insn_after (rtx pattern, rtx_insn *after) 5023 { 5024 return emit_pattern_after (pattern, after, true, make_insn_raw); 5025 } 5026 5027 /* Like emit_jump_insn_after_noloc, but set INSN_LOCATION according to LOC. */ 5028 rtx_jump_insn * 5029 emit_jump_insn_after_setloc (rtx pattern, rtx_insn *after, location_t loc) 5030 { 5031 return as_a <rtx_jump_insn *> ( 5032 emit_pattern_after_setloc (pattern, after, loc, make_jump_insn_raw)); 5033 } 5034 5035 /* Like emit_jump_insn_after_noloc, but set INSN_LOCATION according to AFTER. */ 5036 rtx_jump_insn * 5037 emit_jump_insn_after (rtx pattern, rtx_insn *after) 5038 { 5039 return as_a <rtx_jump_insn *> ( 5040 emit_pattern_after (pattern, after, true, make_jump_insn_raw)); 5041 } 5042 5043 /* Like emit_call_insn_after_noloc, but set INSN_LOCATION according to LOC. */ 5044 rtx_insn * 5045 emit_call_insn_after_setloc (rtx pattern, rtx_insn *after, location_t loc) 5046 { 5047 return emit_pattern_after_setloc (pattern, after, loc, make_call_insn_raw); 5048 } 5049 5050 /* Like emit_call_insn_after_noloc, but set INSN_LOCATION according to AFTER. */ 5051 rtx_insn * 5052 emit_call_insn_after (rtx pattern, rtx_insn *after) 5053 { 5054 return emit_pattern_after (pattern, after, true, make_call_insn_raw); 5055 } 5056 5057 /* Like emit_debug_insn_after_noloc, but set INSN_LOCATION according to LOC. */ 5058 rtx_insn * 5059 emit_debug_insn_after_setloc (rtx pattern, rtx_insn *after, location_t loc) 5060 { 5061 return emit_pattern_after_setloc (pattern, after, loc, make_debug_insn_raw); 5062 } 5063 5064 /* Like emit_debug_insn_after_noloc, but set INSN_LOCATION according to AFTER. */ 5065 rtx_insn * 5066 emit_debug_insn_after (rtx pattern, rtx_insn *after) 5067 { 5068 return emit_pattern_after (pattern, after, false, make_debug_insn_raw); 5069 } 5070 5071 /* Insert PATTERN before BEFORE, setting its INSN_LOCATION to LOC. 5072 MAKE_RAW indicates how to turn PATTERN into a real insn. INSNP 5073 indicates if PATTERN is meant for an INSN as opposed to a JUMP_INSN, 5074 CALL_INSN, etc. */ 5075 5076 static rtx_insn * 5077 emit_pattern_before_setloc (rtx pattern, rtx_insn *before, location_t loc, 5078 bool insnp, rtx_insn *(*make_raw) (rtx)) 5079 { 5080 rtx_insn *first = PREV_INSN (before); 5081 rtx_insn *last = emit_pattern_before_noloc (pattern, before, 5082 insnp ? before : NULL, 5083 NULL, make_raw); 5084 5085 if (pattern == NULL_RTX || !loc) 5086 return last; 5087 5088 if (!first) 5089 first = get_insns (); 5090 else 5091 first = NEXT_INSN (first); 5092 while (1) 5093 { 5094 if (active_insn_p (first) 5095 && !JUMP_TABLE_DATA_P (first) /* FIXME */ 5096 && !INSN_LOCATION (first)) 5097 INSN_LOCATION (first) = loc; 5098 if (first == last) 5099 break; 5100 first = NEXT_INSN (first); 5101 } 5102 return last; 5103 } 5104 5105 /* Insert PATTERN before BEFORE. MAKE_RAW indicates how to turn PATTERN 5106 into a real insn. SKIP_DEBUG_INSNS indicates whether to insert 5107 before any DEBUG_INSNs. INSNP indicates if PATTERN is meant for an 5108 INSN as opposed to a JUMP_INSN, CALL_INSN, etc. */ 5109 5110 static rtx_insn * 5111 emit_pattern_before (rtx pattern, rtx_insn *before, bool skip_debug_insns, 5112 bool insnp, rtx_insn *(*make_raw) (rtx)) 5113 { 5114 rtx_insn *next = before; 5115 5116 if (skip_debug_insns) 5117 while (DEBUG_INSN_P (next)) 5118 next = PREV_INSN (next); 5119 5120 if (INSN_P (next)) 5121 return emit_pattern_before_setloc (pattern, before, INSN_LOCATION (next), 5122 insnp, make_raw); 5123 else 5124 return emit_pattern_before_noloc (pattern, before, 5125 insnp ? before : NULL, 5126 NULL, make_raw); 5127 } 5128 5129 /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */ 5130 rtx_insn * 5131 emit_insn_before_setloc (rtx pattern, rtx_insn *before, location_t loc) 5132 { 5133 return emit_pattern_before_setloc (pattern, before, loc, true, 5134 make_insn_raw); 5135 } 5136 5137 /* Like emit_insn_before_noloc, but set INSN_LOCATION according to BEFORE. */ 5138 rtx_insn * 5139 emit_insn_before (rtx pattern, rtx_insn *before) 5140 { 5141 return emit_pattern_before (pattern, before, true, true, make_insn_raw); 5142 } 5143 5144 /* like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */ 5145 rtx_jump_insn * 5146 emit_jump_insn_before_setloc (rtx pattern, rtx_insn *before, location_t loc) 5147 { 5148 return as_a <rtx_jump_insn *> ( 5149 emit_pattern_before_setloc (pattern, before, loc, false, 5150 make_jump_insn_raw)); 5151 } 5152 5153 /* Like emit_jump_insn_before_noloc, but set INSN_LOCATION according to BEFORE. */ 5154 rtx_jump_insn * 5155 emit_jump_insn_before (rtx pattern, rtx_insn *before) 5156 { 5157 return as_a <rtx_jump_insn *> ( 5158 emit_pattern_before (pattern, before, true, false, 5159 make_jump_insn_raw)); 5160 } 5161 5162 /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */ 5163 rtx_insn * 5164 emit_call_insn_before_setloc (rtx pattern, rtx_insn *before, location_t loc) 5165 { 5166 return emit_pattern_before_setloc (pattern, before, loc, false, 5167 make_call_insn_raw); 5168 } 5169 5170 /* Like emit_call_insn_before_noloc, 5171 but set insn_location according to BEFORE. */ 5172 rtx_insn * 5173 emit_call_insn_before (rtx pattern, rtx_insn *before) 5174 { 5175 return emit_pattern_before (pattern, before, true, false, 5176 make_call_insn_raw); 5177 } 5178 5179 /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */ 5180 rtx_insn * 5181 emit_debug_insn_before_setloc (rtx pattern, rtx_insn *before, location_t loc) 5182 { 5183 return emit_pattern_before_setloc (pattern, before, loc, false, 5184 make_debug_insn_raw); 5185 } 5186 5187 /* Like emit_debug_insn_before_noloc, 5188 but set insn_location according to BEFORE. */ 5189 rtx_insn * 5190 emit_debug_insn_before (rtx pattern, rtx_insn *before) 5191 { 5192 return emit_pattern_before (pattern, before, false, false, 5193 make_debug_insn_raw); 5194 } 5195 5196 /* Take X and emit it at the end of the doubly-linked 5198 INSN list. 5199 5200 Returns the last insn emitted. */ 5201 5202 rtx_insn * 5203 emit_insn (rtx x) 5204 { 5205 rtx_insn *last = get_last_insn (); 5206 rtx_insn *insn; 5207 5208 if (x == NULL_RTX) 5209 return last; 5210 5211 switch (GET_CODE (x)) 5212 { 5213 case DEBUG_INSN: 5214 case INSN: 5215 case JUMP_INSN: 5216 case CALL_INSN: 5217 case CODE_LABEL: 5218 case BARRIER: 5219 case NOTE: 5220 insn = as_a <rtx_insn *> (x); 5221 while (insn) 5222 { 5223 rtx_insn *next = NEXT_INSN (insn); 5224 add_insn (insn); 5225 last = insn; 5226 insn = next; 5227 } 5228 break; 5229 5230 #ifdef ENABLE_RTL_CHECKING 5231 case JUMP_TABLE_DATA: 5232 case SEQUENCE: 5233 gcc_unreachable (); 5234 break; 5235 #endif 5236 5237 default: 5238 last = make_insn_raw (x); 5239 add_insn (last); 5240 break; 5241 } 5242 5243 return last; 5244 } 5245 5246 /* Make an insn of code DEBUG_INSN with pattern X 5247 and add it to the end of the doubly-linked list. */ 5248 5249 rtx_insn * 5250 emit_debug_insn (rtx x) 5251 { 5252 rtx_insn *last = get_last_insn (); 5253 rtx_insn *insn; 5254 5255 if (x == NULL_RTX) 5256 return last; 5257 5258 switch (GET_CODE (x)) 5259 { 5260 case DEBUG_INSN: 5261 case INSN: 5262 case JUMP_INSN: 5263 case CALL_INSN: 5264 case CODE_LABEL: 5265 case BARRIER: 5266 case NOTE: 5267 insn = as_a <rtx_insn *> (x); 5268 while (insn) 5269 { 5270 rtx_insn *next = NEXT_INSN (insn); 5271 add_insn (insn); 5272 last = insn; 5273 insn = next; 5274 } 5275 break; 5276 5277 #ifdef ENABLE_RTL_CHECKING 5278 case JUMP_TABLE_DATA: 5279 case SEQUENCE: 5280 gcc_unreachable (); 5281 break; 5282 #endif 5283 5284 default: 5285 last = make_debug_insn_raw (x); 5286 add_insn (last); 5287 break; 5288 } 5289 5290 return last; 5291 } 5292 5293 /* Make an insn of code JUMP_INSN with pattern X 5294 and add it to the end of the doubly-linked list. */ 5295 5296 rtx_insn * 5297 emit_jump_insn (rtx x) 5298 { 5299 rtx_insn *last = NULL; 5300 rtx_insn *insn; 5301 5302 switch (GET_CODE (x)) 5303 { 5304 case DEBUG_INSN: 5305 case INSN: 5306 case JUMP_INSN: 5307 case CALL_INSN: 5308 case CODE_LABEL: 5309 case BARRIER: 5310 case NOTE: 5311 insn = as_a <rtx_insn *> (x); 5312 while (insn) 5313 { 5314 rtx_insn *next = NEXT_INSN (insn); 5315 add_insn (insn); 5316 last = insn; 5317 insn = next; 5318 } 5319 break; 5320 5321 #ifdef ENABLE_RTL_CHECKING 5322 case JUMP_TABLE_DATA: 5323 case SEQUENCE: 5324 gcc_unreachable (); 5325 break; 5326 #endif 5327 5328 default: 5329 last = make_jump_insn_raw (x); 5330 add_insn (last); 5331 break; 5332 } 5333 5334 return last; 5335 } 5336 5337 /* Make an insn of code JUMP_INSN with pattern X, 5338 add a REG_BR_PROB note that indicates very likely probability, 5339 and add it to the end of the doubly-linked list. */ 5340 5341 rtx_insn * 5342 emit_likely_jump_insn (rtx x) 5343 { 5344 rtx_insn *jump = emit_jump_insn (x); 5345 add_reg_br_prob_note (jump, profile_probability::very_likely ()); 5346 return jump; 5347 } 5348 5349 /* Make an insn of code JUMP_INSN with pattern X, 5350 add a REG_BR_PROB note that indicates very unlikely probability, 5351 and add it to the end of the doubly-linked list. */ 5352 5353 rtx_insn * 5354 emit_unlikely_jump_insn (rtx x) 5355 { 5356 rtx_insn *jump = emit_jump_insn (x); 5357 add_reg_br_prob_note (jump, profile_probability::very_unlikely ()); 5358 return jump; 5359 } 5360 5361 /* Make an insn of code CALL_INSN with pattern X 5362 and add it to the end of the doubly-linked list. */ 5363 5364 rtx_insn * 5365 emit_call_insn (rtx x) 5366 { 5367 rtx_insn *insn; 5368 5369 switch (GET_CODE (x)) 5370 { 5371 case DEBUG_INSN: 5372 case INSN: 5373 case JUMP_INSN: 5374 case CALL_INSN: 5375 case CODE_LABEL: 5376 case BARRIER: 5377 case NOTE: 5378 insn = emit_insn (x); 5379 break; 5380 5381 #ifdef ENABLE_RTL_CHECKING 5382 case SEQUENCE: 5383 case JUMP_TABLE_DATA: 5384 gcc_unreachable (); 5385 break; 5386 #endif 5387 5388 default: 5389 insn = make_call_insn_raw (x); 5390 add_insn (insn); 5391 break; 5392 } 5393 5394 return insn; 5395 } 5396 5397 /* Add the label LABEL to the end of the doubly-linked list. */ 5398 5399 rtx_code_label * 5400 emit_label (rtx uncast_label) 5401 { 5402 rtx_code_label *label = as_a <rtx_code_label *> (uncast_label); 5403 5404 gcc_checking_assert (INSN_UID (label) == 0); 5405 INSN_UID (label) = cur_insn_uid++; 5406 add_insn (label); 5407 return label; 5408 } 5409 5410 /* Make an insn of code JUMP_TABLE_DATA 5411 and add it to the end of the doubly-linked list. */ 5412 5413 rtx_jump_table_data * 5414 emit_jump_table_data (rtx table) 5415 { 5416 rtx_jump_table_data *jump_table_data = 5417 as_a <rtx_jump_table_data *> (rtx_alloc (JUMP_TABLE_DATA)); 5418 INSN_UID (jump_table_data) = cur_insn_uid++; 5419 PATTERN (jump_table_data) = table; 5420 BLOCK_FOR_INSN (jump_table_data) = NULL; 5421 add_insn (jump_table_data); 5422 return jump_table_data; 5423 } 5424 5425 /* Make an insn of code BARRIER 5426 and add it to the end of the doubly-linked list. */ 5427 5428 rtx_barrier * 5429 emit_barrier (void) 5430 { 5431 rtx_barrier *barrier = as_a <rtx_barrier *> (rtx_alloc (BARRIER)); 5432 INSN_UID (barrier) = cur_insn_uid++; 5433 add_insn (barrier); 5434 return barrier; 5435 } 5436 5437 /* Emit a copy of note ORIG. */ 5438 5439 rtx_note * 5440 emit_note_copy (rtx_note *orig) 5441 { 5442 enum insn_note kind = (enum insn_note) NOTE_KIND (orig); 5443 rtx_note *note = make_note_raw (kind); 5444 NOTE_DATA (note) = NOTE_DATA (orig); 5445 add_insn (note); 5446 return note; 5447 } 5448 5449 /* Make an insn of code NOTE or type NOTE_NO 5450 and add it to the end of the doubly-linked list. */ 5451 5452 rtx_note * 5453 emit_note (enum insn_note kind) 5454 { 5455 rtx_note *note = make_note_raw (kind); 5456 add_insn (note); 5457 return note; 5458 } 5459 5460 /* Emit a clobber of lvalue X. */ 5461 5462 rtx_insn * 5463 emit_clobber (rtx x) 5464 { 5465 /* CONCATs should not appear in the insn stream. */ 5466 if (GET_CODE (x) == CONCAT) 5467 { 5468 emit_clobber (XEXP (x, 0)); 5469 return emit_clobber (XEXP (x, 1)); 5470 } 5471 return emit_insn (gen_rtx_CLOBBER (VOIDmode, x)); 5472 } 5473 5474 /* Return a sequence of insns to clobber lvalue X. */ 5475 5476 rtx_insn * 5477 gen_clobber (rtx x) 5478 { 5479 rtx_insn *seq; 5480 5481 start_sequence (); 5482 emit_clobber (x); 5483 seq = get_insns (); 5484 end_sequence (); 5485 return seq; 5486 } 5487 5488 /* Emit a use of rvalue X. */ 5489 5490 rtx_insn * 5491 emit_use (rtx x) 5492 { 5493 /* CONCATs should not appear in the insn stream. */ 5494 if (GET_CODE (x) == CONCAT) 5495 { 5496 emit_use (XEXP (x, 0)); 5497 return emit_use (XEXP (x, 1)); 5498 } 5499 return emit_insn (gen_rtx_USE (VOIDmode, x)); 5500 } 5501 5502 /* Return a sequence of insns to use rvalue X. */ 5503 5504 rtx_insn * 5505 gen_use (rtx x) 5506 { 5507 rtx_insn *seq; 5508 5509 start_sequence (); 5510 emit_use (x); 5511 seq = get_insns (); 5512 end_sequence (); 5513 return seq; 5514 } 5515 5516 /* Notes like REG_EQUAL and REG_EQUIV refer to a set in an instruction. 5517 Return the set in INSN that such notes describe, or NULL if the notes 5518 have no meaning for INSN. */ 5519 5520 rtx 5521 set_for_reg_notes (rtx insn) 5522 { 5523 rtx pat, reg; 5524 5525 if (!INSN_P (insn)) 5526 return NULL_RTX; 5527 5528 pat = PATTERN (insn); 5529 if (GET_CODE (pat) == PARALLEL) 5530 { 5531 /* We do not use single_set because that ignores SETs of unused 5532 registers. REG_EQUAL and REG_EQUIV notes really do require the 5533 PARALLEL to have a single SET. */ 5534 if (multiple_sets (insn)) 5535 return NULL_RTX; 5536 pat = XVECEXP (pat, 0, 0); 5537 } 5538 5539 if (GET_CODE (pat) != SET) 5540 return NULL_RTX; 5541 5542 reg = SET_DEST (pat); 5543 5544 /* Notes apply to the contents of a STRICT_LOW_PART. */ 5545 if (GET_CODE (reg) == STRICT_LOW_PART 5546 || GET_CODE (reg) == ZERO_EXTRACT) 5547 reg = XEXP (reg, 0); 5548 5549 /* Check that we have a register. */ 5550 if (!(REG_P (reg) || GET_CODE (reg) == SUBREG)) 5551 return NULL_RTX; 5552 5553 return pat; 5554 } 5555 5556 /* Place a note of KIND on insn INSN with DATUM as the datum. If a 5557 note of this type already exists, remove it first. */ 5558 5559 rtx 5560 set_unique_reg_note (rtx insn, enum reg_note kind, rtx datum) 5561 { 5562 rtx note = find_reg_note (insn, kind, NULL_RTX); 5563 5564 switch (kind) 5565 { 5566 case REG_EQUAL: 5567 case REG_EQUIV: 5568 /* We need to support the REG_EQUAL on USE trick of find_reloads. */ 5569 if (!set_for_reg_notes (insn) && GET_CODE (PATTERN (insn)) != USE) 5570 return NULL_RTX; 5571 5572 /* Don't add ASM_OPERAND REG_EQUAL/REG_EQUIV notes. 5573 It serves no useful purpose and breaks eliminate_regs. */ 5574 if (GET_CODE (datum) == ASM_OPERANDS) 5575 return NULL_RTX; 5576 5577 /* Notes with side effects are dangerous. Even if the side-effect 5578 initially mirrors one in PATTERN (INSN), later optimizations 5579 might alter the way that the final register value is calculated 5580 and so move or alter the side-effect in some way. The note would 5581 then no longer be a valid substitution for SET_SRC. */ 5582 if (side_effects_p (datum)) 5583 return NULL_RTX; 5584 break; 5585 5586 default: 5587 break; 5588 } 5589 5590 if (note) 5591 XEXP (note, 0) = datum; 5592 else 5593 { 5594 add_reg_note (insn, kind, datum); 5595 note = REG_NOTES (insn); 5596 } 5597 5598 switch (kind) 5599 { 5600 case REG_EQUAL: 5601 case REG_EQUIV: 5602 df_notes_rescan (as_a <rtx_insn *> (insn)); 5603 break; 5604 default: 5605 break; 5606 } 5607 5608 return note; 5609 } 5610 5611 /* Like set_unique_reg_note, but don't do anything unless INSN sets DST. */ 5612 rtx 5613 set_dst_reg_note (rtx insn, enum reg_note kind, rtx datum, rtx dst) 5614 { 5615 rtx set = set_for_reg_notes (insn); 5616 5617 if (set && SET_DEST (set) == dst) 5618 return set_unique_reg_note (insn, kind, datum); 5619 return NULL_RTX; 5620 } 5621 5622 /* Emit the rtl pattern X as an appropriate kind of insn. Also emit a 5624 following barrier if the instruction needs one and if ALLOW_BARRIER_P 5625 is true. 5626 5627 If X is a label, it is simply added into the insn chain. */ 5628 5629 rtx_insn * 5630 emit (rtx x, bool allow_barrier_p) 5631 { 5632 enum rtx_code code = classify_insn (x); 5633 5634 switch (code) 5635 { 5636 case CODE_LABEL: 5637 return emit_label (x); 5638 case INSN: 5639 return emit_insn (x); 5640 case JUMP_INSN: 5641 { 5642 rtx_insn *insn = emit_jump_insn (x); 5643 if (allow_barrier_p 5644 && (any_uncondjump_p (insn) || GET_CODE (x) == RETURN)) 5645 return emit_barrier (); 5646 return insn; 5647 } 5648 case CALL_INSN: 5649 return emit_call_insn (x); 5650 case DEBUG_INSN: 5651 return emit_debug_insn (x); 5652 default: 5653 gcc_unreachable (); 5654 } 5655 } 5656 5657 /* Space for free sequence stack entries. */ 5659 static GTY ((deletable)) struct sequence_stack *free_sequence_stack; 5660 5661 /* Begin emitting insns to a sequence. If this sequence will contain 5662 something that might cause the compiler to pop arguments to function 5663 calls (because those pops have previously been deferred; see 5664 INHIBIT_DEFER_POP for more details), use do_pending_stack_adjust 5665 before calling this function. That will ensure that the deferred 5666 pops are not accidentally emitted in the middle of this sequence. */ 5667 5668 void 5669 start_sequence (void) 5670 { 5671 struct sequence_stack *tem; 5672 5673 if (free_sequence_stack != NULL) 5674 { 5675 tem = free_sequence_stack; 5676 free_sequence_stack = tem->next; 5677 } 5678 else 5679 tem = ggc_alloc<sequence_stack> (); 5680 5681 tem->next = get_current_sequence ()->next; 5682 tem->first = get_insns (); 5683 tem->last = get_last_insn (); 5684 get_current_sequence ()->next = tem; 5685 5686 set_first_insn (0); 5687 set_last_insn (0); 5688 } 5689 5690 /* Set up the insn chain starting with FIRST as the current sequence, 5691 saving the previously current one. See the documentation for 5692 start_sequence for more information about how to use this function. */ 5693 5694 void 5695 push_to_sequence (rtx_insn *first) 5696 { 5697 rtx_insn *last; 5698 5699 start_sequence (); 5700 5701 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last)) 5702 ; 5703 5704 set_first_insn (first); 5705 set_last_insn (last); 5706 } 5707 5708 /* Like push_to_sequence, but take the last insn as an argument to avoid 5709 looping through the list. */ 5710 5711 void 5712 push_to_sequence2 (rtx_insn *first, rtx_insn *last) 5713 { 5714 start_sequence (); 5715 5716 set_first_insn (first); 5717 set_last_insn (last); 5718 } 5719 5720 /* Set up the outer-level insn chain 5721 as the current sequence, saving the previously current one. */ 5722 5723 void 5724 push_topmost_sequence (void) 5725 { 5726 struct sequence_stack *top; 5727 5728 start_sequence (); 5729 5730 top = get_topmost_sequence (); 5731 set_first_insn (top->first); 5732 set_last_insn (top->last); 5733 } 5734 5735 /* After emitting to the outer-level insn chain, update the outer-level 5736 insn chain, and restore the previous saved state. */ 5737 5738 void 5739 pop_topmost_sequence (void) 5740 { 5741 struct sequence_stack *top; 5742 5743 top = get_topmost_sequence (); 5744 top->first = get_insns (); 5745 top->last = get_last_insn (); 5746 5747 end_sequence (); 5748 } 5749 5750 /* After emitting to a sequence, restore previous saved state. 5751 5752 To get the contents of the sequence just made, you must call 5753 `get_insns' *before* calling here. 5754 5755 If the compiler might have deferred popping arguments while 5756 generating this sequence, and this sequence will not be immediately 5757 inserted into the instruction stream, use do_pending_stack_adjust 5758 before calling get_insns. That will ensure that the deferred 5759 pops are inserted into this sequence, and not into some random 5760 location in the instruction stream. See INHIBIT_DEFER_POP for more 5761 information about deferred popping of arguments. */ 5762 5763 void 5764 end_sequence (void) 5765 { 5766 struct sequence_stack *tem = get_current_sequence ()->next; 5767 5768 set_first_insn (tem->first); 5769 set_last_insn (tem->last); 5770 get_current_sequence ()->next = tem->next; 5771 5772 memset (tem, 0, sizeof (*tem)); 5773 tem->next = free_sequence_stack; 5774 free_sequence_stack = tem; 5775 } 5776 5777 /* Return true if currently emitting into a sequence. */ 5778 5779 bool 5780 in_sequence_p (void) 5781 { 5782 return get_current_sequence ()->next != 0; 5783 } 5784 5785 /* Put the various virtual registers into REGNO_REG_RTX. */ 5787 5788 static void 5789 init_virtual_regs (void) 5790 { 5791 regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx; 5792 regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx; 5793 regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx; 5794 regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx; 5795 regno_reg_rtx[VIRTUAL_CFA_REGNUM] = virtual_cfa_rtx; 5796 regno_reg_rtx[VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM] 5797 = virtual_preferred_stack_boundary_rtx; 5798 } 5799 5800 5801 /* Used by copy_insn_1 to avoid copying SCRATCHes more than once. */ 5803 static rtx copy_insn_scratch_in[MAX_RECOG_OPERANDS]; 5804 static rtx copy_insn_scratch_out[MAX_RECOG_OPERANDS]; 5805 static int copy_insn_n_scratches; 5806 5807 /* When an insn is being copied by copy_insn_1, this is nonzero if we have 5808 copied an ASM_OPERANDS. 5809 In that case, it is the original input-operand vector. */ 5810 static rtvec orig_asm_operands_vector; 5811 5812 /* When an insn is being copied by copy_insn_1, this is nonzero if we have 5813 copied an ASM_OPERANDS. 5814 In that case, it is the copied input-operand vector. */ 5815 static rtvec copy_asm_operands_vector; 5816 5817 /* Likewise for the constraints vector. */ 5818 static rtvec orig_asm_constraints_vector; 5819 static rtvec copy_asm_constraints_vector; 5820 5821 /* Recursively create a new copy of an rtx for copy_insn. 5822 This function differs from copy_rtx in that it handles SCRATCHes and 5823 ASM_OPERANDs properly. 5824 Normally, this function is not used directly; use copy_insn as front end. 5825 However, you could first copy an insn pattern with copy_insn and then use 5826 this function afterwards to properly copy any REG_NOTEs containing 5827 SCRATCHes. */ 5828 5829 rtx 5830 copy_insn_1 (rtx orig) 5831 { 5832 rtx copy; 5833 int i, j; 5834 RTX_CODE code; 5835 const char *format_ptr; 5836 5837 if (orig == NULL) 5838 return NULL; 5839 5840 code = GET_CODE (orig); 5841 5842 switch (code) 5843 { 5844 case REG: 5845 case DEBUG_EXPR: 5846 CASE_CONST_ANY: 5847 case SYMBOL_REF: 5848 case CODE_LABEL: 5849 case PC: 5850 case RETURN: 5851 case SIMPLE_RETURN: 5852 return orig; 5853 case CLOBBER: 5854 /* Share clobbers of hard registers, but do not share pseudo reg 5855 clobbers or clobbers of hard registers that originated as pseudos. 5856 This is needed to allow safe register renaming. */ 5857 if (REG_P (XEXP (orig, 0)) 5858 && HARD_REGISTER_NUM_P (REGNO (XEXP (orig, 0))) 5859 && HARD_REGISTER_NUM_P (ORIGINAL_REGNO (XEXP (orig, 0)))) 5860 return orig; 5861 break; 5862 5863 case SCRATCH: 5864 for (i = 0; i < copy_insn_n_scratches; i++) 5865 if (copy_insn_scratch_in[i] == orig) 5866 return copy_insn_scratch_out[i]; 5867 break; 5868 5869 case CONST: 5870 if (shared_const_p (orig)) 5871 return orig; 5872 break; 5873 5874 /* A MEM with a constant address is not sharable. The problem is that 5875 the constant address may need to be reloaded. If the mem is shared, 5876 then reloading one copy of this mem will cause all copies to appear 5877 to have been reloaded. */ 5878 5879 default: 5880 break; 5881 } 5882 5883 /* Copy the various flags, fields, and other information. We assume 5884 that all fields need copying, and then clear the fields that should 5885 not be copied. That is the sensible default behavior, and forces 5886 us to explicitly document why we are *not* copying a flag. */ 5887 copy = shallow_copy_rtx (orig); 5888 5889 /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs. */ 5890 if (INSN_P (orig)) 5891 { 5892 RTX_FLAG (copy, jump) = 0; 5893 RTX_FLAG (copy, call) = 0; 5894 RTX_FLAG (copy, frame_related) = 0; 5895 } 5896 5897 format_ptr = GET_RTX_FORMAT (GET_CODE (copy)); 5898 5899 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++) 5900 switch (*format_ptr++) 5901 { 5902 case 'e': 5903 if (XEXP (orig, i) != NULL) 5904 XEXP (copy, i) = copy_insn_1 (XEXP (orig, i)); 5905 break; 5906 5907 case 'E': 5908 case 'V': 5909 if (XVEC (orig, i) == orig_asm_constraints_vector) 5910 XVEC (copy, i) = copy_asm_constraints_vector; 5911 else if (XVEC (orig, i) == orig_asm_operands_vector) 5912 XVEC (copy, i) = copy_asm_operands_vector; 5913 else if (XVEC (orig, i) != NULL) 5914 { 5915 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i)); 5916 for (j = 0; j < XVECLEN (copy, i); j++) 5917 XVECEXP (copy, i, j) = copy_insn_1 (XVECEXP (orig, i, j)); 5918 } 5919 break; 5920 5921 case 't': 5922 case 'w': 5923 case 'i': 5924 case 'p': 5925 case 's': 5926 case 'S': 5927 case 'u': 5928 case '0': 5929 /* These are left unchanged. */ 5930 break; 5931 5932 default: 5933 gcc_unreachable (); 5934 } 5935 5936 if (code == SCRATCH) 5937 { 5938 i = copy_insn_n_scratches++; 5939 gcc_assert (i < MAX_RECOG_OPERANDS); 5940 copy_insn_scratch_in[i] = orig; 5941 copy_insn_scratch_out[i] = copy; 5942 } 5943 else if (code == ASM_OPERANDS) 5944 { 5945 orig_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (orig); 5946 copy_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (copy); 5947 orig_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (orig); 5948 copy_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (copy); 5949 } 5950 5951 return copy; 5952 } 5953 5954 /* Create a new copy of an rtx. 5955 This function differs from copy_rtx in that it handles SCRATCHes and 5956 ASM_OPERANDs properly. 5957 INSN doesn't really have to be a full INSN; it could be just the 5958 pattern. */ 5959 rtx 5960 copy_insn (rtx insn) 5961 { 5962 copy_insn_n_scratches = 0; 5963 orig_asm_operands_vector = 0; 5964 orig_asm_constraints_vector = 0; 5965 copy_asm_operands_vector = 0; 5966 copy_asm_constraints_vector = 0; 5967 return copy_insn_1 (insn); 5968 } 5969 5970 /* Return a copy of INSN that can be used in a SEQUENCE delay slot, 5971 on that assumption that INSN itself remains in its original place. */ 5972 5973 rtx_insn * 5974 copy_delay_slot_insn (rtx_insn *insn) 5975 { 5976 /* Copy INSN with its rtx_code, all its notes, location etc. */ 5977 insn = as_a <rtx_insn *> (copy_rtx (insn)); 5978 INSN_UID (insn) = cur_insn_uid++; 5979 return insn; 5980 } 5981 5982 /* Initialize data structures and variables in this file 5983 before generating rtl for each function. */ 5984 5985 void 5986 init_emit (void) 5987 { 5988 set_first_insn (NULL); 5989 set_last_insn (NULL); 5990 if (param_min_nondebug_insn_uid) 5991 cur_insn_uid = param_min_nondebug_insn_uid; 5992 else 5993 cur_insn_uid = 1; 5994 cur_debug_insn_uid = 1; 5995 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1; 5996 first_label_num = label_num; 5997 get_current_sequence ()->next = NULL; 5998 5999 /* Init the tables that describe all the pseudo regs. */ 6000 6001 crtl->emit.regno_pointer_align_length = LAST_VIRTUAL_REGISTER + 101; 6002 6003 crtl->emit.regno_pointer_align 6004 = XCNEWVEC (unsigned char, crtl->emit.regno_pointer_align_length); 6005 6006 regno_reg_rtx 6007 = ggc_cleared_vec_alloc<rtx> (crtl->emit.regno_pointer_align_length); 6008 6009 /* Put copies of all the hard registers into regno_reg_rtx. */ 6010 memcpy (regno_reg_rtx, 6011 initial_regno_reg_rtx, 6012 FIRST_PSEUDO_REGISTER * sizeof (rtx)); 6013 6014 /* Put copies of all the virtual register rtx into regno_reg_rtx. */ 6015 init_virtual_regs (); 6016 6017 /* Indicate that the virtual registers and stack locations are 6018 all pointers. */ 6019 REG_POINTER (stack_pointer_rtx) = 1; 6020 REG_POINTER (frame_pointer_rtx) = 1; 6021 REG_POINTER (hard_frame_pointer_rtx) = 1; 6022 REG_POINTER (arg_pointer_rtx) = 1; 6023 6024 REG_POINTER (virtual_incoming_args_rtx) = 1; 6025 REG_POINTER (virtual_stack_vars_rtx) = 1; 6026 REG_POINTER (virtual_stack_dynamic_rtx) = 1; 6027 REG_POINTER (virtual_outgoing_args_rtx) = 1; 6028 REG_POINTER (virtual_cfa_rtx) = 1; 6029 6030 #ifdef STACK_BOUNDARY 6031 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY; 6032 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY; 6033 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM) = STACK_BOUNDARY; 6034 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY; 6035 6036 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM) = STACK_BOUNDARY; 6037 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM) = STACK_BOUNDARY; 6038 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM) = STACK_BOUNDARY; 6039 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM) = STACK_BOUNDARY; 6040 6041 REGNO_POINTER_ALIGN (VIRTUAL_CFA_REGNUM) = BITS_PER_WORD; 6042 #endif 6043 6044 #ifdef INIT_EXPANDERS 6045 INIT_EXPANDERS; 6046 #endif 6047 } 6048 6049 /* Return the value of element I of CONST_VECTOR X as a wide_int. */ 6050 6051 wide_int 6052 const_vector_int_elt (const_rtx x, unsigned int i) 6053 { 6054 /* First handle elements that are directly encoded. */ 6055 machine_mode elt_mode = GET_MODE_INNER (GET_MODE (x)); 6056 if (i < (unsigned int) XVECLEN (x, 0)) 6057 return rtx_mode_t (CONST_VECTOR_ENCODED_ELT (x, i), elt_mode); 6058 6059 /* Identify the pattern that contains element I and work out the index of 6060 the last encoded element for that pattern. */ 6061 unsigned int encoded_nelts = const_vector_encoded_nelts (x); 6062 unsigned int npatterns = CONST_VECTOR_NPATTERNS (x); 6063 unsigned int count = i / npatterns; 6064 unsigned int pattern = i % npatterns; 6065 unsigned int final_i = encoded_nelts - npatterns + pattern; 6066 6067 /* If there are no steps, the final encoded value is the right one. */ 6068 if (!CONST_VECTOR_STEPPED_P (x)) 6069 return rtx_mode_t (CONST_VECTOR_ENCODED_ELT (x, final_i), elt_mode); 6070 6071 /* Otherwise work out the value from the last two encoded elements. */ 6072 rtx v1 = CONST_VECTOR_ENCODED_ELT (x, final_i - npatterns); 6073 rtx v2 = CONST_VECTOR_ENCODED_ELT (x, final_i); 6074 wide_int diff = wi::sub (rtx_mode_t (v2, elt_mode), 6075 rtx_mode_t (v1, elt_mode)); 6076 return wi::add (rtx_mode_t (v2, elt_mode), (count - 2) * diff); 6077 } 6078 6079 /* Return the value of element I of CONST_VECTOR X. */ 6080 6081 rtx 6082 const_vector_elt (const_rtx x, unsigned int i) 6083 { 6084 /* First handle elements that are directly encoded. */ 6085 if (i < (unsigned int) XVECLEN (x, 0)) 6086 return CONST_VECTOR_ENCODED_ELT (x, i); 6087 6088 /* If there are no steps, the final encoded value is the right one. */ 6089 if (!CONST_VECTOR_STEPPED_P (x)) 6090 { 6091 /* Identify the pattern that contains element I and work out the index of 6092 the last encoded element for that pattern. */ 6093 unsigned int encoded_nelts = const_vector_encoded_nelts (x); 6094 unsigned int npatterns = CONST_VECTOR_NPATTERNS (x); 6095 unsigned int pattern = i % npatterns; 6096 unsigned int final_i = encoded_nelts - npatterns + pattern; 6097 return CONST_VECTOR_ENCODED_ELT (x, final_i); 6098 } 6099 6100 /* Otherwise work out the value from the last two encoded elements. */ 6101 return immed_wide_int_const (const_vector_int_elt (x, i), 6102 GET_MODE_INNER (GET_MODE (x))); 6103 } 6104 6105 /* Return true if X is a valid element for a CONST_VECTOR of the given 6106 mode. */ 6107 6108 bool 6109 valid_for_const_vector_p (machine_mode, rtx x) 6110 { 6111 return (CONST_SCALAR_INT_P (x) 6112 || CONST_POLY_INT_P (x) 6113 || CONST_DOUBLE_AS_FLOAT_P (x) 6114 || CONST_FIXED_P (x)); 6115 } 6116 6117 /* Generate a vector constant of mode MODE in which every element has 6118 value ELT. */ 6119 6120 rtx 6121 gen_const_vec_duplicate (machine_mode mode, rtx elt) 6122 { 6123 rtx_vector_builder builder (mode, 1, 1); 6124 builder.quick_push (elt); 6125 return builder.build (); 6126 } 6127 6128 /* Return a vector rtx of mode MODE in which every element has value X. 6129 The result will be a constant if X is constant. */ 6130 6131 rtx 6132 gen_vec_duplicate (machine_mode mode, rtx x) 6133 { 6134 if (valid_for_const_vector_p (mode, x)) 6135 return gen_const_vec_duplicate (mode, x); 6136 return gen_rtx_VEC_DUPLICATE (mode, x); 6137 } 6138 6139 /* A subroutine of const_vec_series_p that handles the case in which: 6140 6141 (GET_CODE (X) == CONST_VECTOR 6142 && CONST_VECTOR_NPATTERNS (X) == 1 6143 && !CONST_VECTOR_DUPLICATE_P (X)) 6144 6145 is known to hold. */ 6146 6147 bool 6148 const_vec_series_p_1 (const_rtx x, rtx *base_out, rtx *step_out) 6149 { 6150 /* Stepped sequences are only defined for integers, to avoid specifying 6151 rounding behavior. */ 6152 if (GET_MODE_CLASS (GET_MODE (x)) != MODE_VECTOR_INT) 6153 return false; 6154 6155 /* A non-duplicated vector with two elements can always be seen as a 6156 series with a nonzero step. Longer vectors must have a stepped 6157 encoding. */ 6158 if (maybe_ne (CONST_VECTOR_NUNITS (x), 2) 6159 && !CONST_VECTOR_STEPPED_P (x)) 6160 return false; 6161 6162 /* Calculate the step between the first and second elements. */ 6163 scalar_mode inner = GET_MODE_INNER (GET_MODE (x)); 6164 rtx base = CONST_VECTOR_ELT (x, 0); 6165 rtx step = simplify_binary_operation (MINUS, inner, 6166 CONST_VECTOR_ENCODED_ELT (x, 1), base); 6167 if (rtx_equal_p (step, CONST0_RTX (inner))) 6168 return false; 6169 6170 /* If we have a stepped encoding, check that the step between the 6171 second and third elements is the same as STEP. */ 6172 if (CONST_VECTOR_STEPPED_P (x)) 6173 { 6174 rtx diff = simplify_binary_operation (MINUS, inner, 6175 CONST_VECTOR_ENCODED_ELT (x, 2), 6176 CONST_VECTOR_ENCODED_ELT (x, 1)); 6177 if (!rtx_equal_p (step, diff)) 6178 return false; 6179 } 6180 6181 *base_out = base; 6182 *step_out = step; 6183 return true; 6184 } 6185 6186 /* Generate a vector constant of mode MODE in which element I has 6187 the value BASE + I * STEP. */ 6188 6189 rtx 6190 gen_const_vec_series (machine_mode mode, rtx base, rtx step) 6191 { 6192 gcc_assert (valid_for_const_vector_p (mode, base) 6193 && valid_for_const_vector_p (mode, step)); 6194 6195 rtx_vector_builder builder (mode, 1, 3); 6196 builder.quick_push (base); 6197 for (int i = 1; i < 3; ++i) 6198 builder.quick_push (simplify_gen_binary (PLUS, GET_MODE_INNER (mode), 6199 builder[i - 1], step)); 6200 return builder.build (); 6201 } 6202 6203 /* Generate a vector of mode MODE in which element I has the value 6204 BASE + I * STEP. The result will be a constant if BASE and STEP 6205 are both constants. */ 6206 6207 rtx 6208 gen_vec_series (machine_mode mode, rtx base, rtx step) 6209 { 6210 if (step == const0_rtx) 6211 return gen_vec_duplicate (mode, base); 6212 if (valid_for_const_vector_p (mode, base) 6213 && valid_for_const_vector_p (mode, step)) 6214 return gen_const_vec_series (mode, base, step); 6215 return gen_rtx_VEC_SERIES (mode, base, step); 6216 } 6217 6218 /* Generate a new vector constant for mode MODE and constant value 6219 CONSTANT. */ 6220 6221 static rtx 6222 gen_const_vector (machine_mode mode, int constant) 6223 { 6224 machine_mode inner = GET_MODE_INNER (mode); 6225 6226 gcc_assert (!DECIMAL_FLOAT_MODE_P (inner)); 6227 6228 rtx el = const_tiny_rtx[constant][(int) inner]; 6229 gcc_assert (el); 6230 6231 return gen_const_vec_duplicate (mode, el); 6232 } 6233 6234 /* Generate a vector like gen_rtx_raw_CONST_VEC, but use the zero vector when 6235 all elements are zero, and the one vector when all elements are one. */ 6236 rtx 6237 gen_rtx_CONST_VECTOR (machine_mode mode, rtvec v) 6238 { 6239 gcc_assert (known_eq (GET_MODE_NUNITS (mode), GET_NUM_ELEM (v))); 6240 6241 /* If the values are all the same, check to see if we can use one of the 6242 standard constant vectors. */ 6243 if (rtvec_all_equal_p (v)) 6244 return gen_const_vec_duplicate (mode, RTVEC_ELT (v, 0)); 6245 6246 unsigned int nunits = GET_NUM_ELEM (v); 6247 rtx_vector_builder builder (mode, nunits, 1); 6248 for (unsigned int i = 0; i < nunits; ++i) 6249 builder.quick_push (RTVEC_ELT (v, i)); 6250 return builder.build (v); 6251 } 6252 6253 /* Initialise global register information required by all functions. */ 6254 6255 void 6256 init_emit_regs (void) 6257 { 6258 int i; 6259 machine_mode mode; 6260 mem_attrs *attrs; 6261 6262 /* Reset register attributes */ 6263 reg_attrs_htab->empty (); 6264 6265 /* We need reg_raw_mode, so initialize the modes now. */ 6266 init_reg_modes_target (); 6267 6268 /* Assign register numbers to the globally defined register rtx. */ 6269 stack_pointer_rtx = gen_raw_REG (Pmode, STACK_POINTER_REGNUM); 6270 frame_pointer_rtx = gen_raw_REG (Pmode, FRAME_POINTER_REGNUM); 6271 hard_frame_pointer_rtx = gen_raw_REG (Pmode, HARD_FRAME_POINTER_REGNUM); 6272 arg_pointer_rtx = gen_raw_REG (Pmode, ARG_POINTER_REGNUM); 6273 virtual_incoming_args_rtx = 6274 gen_raw_REG (Pmode, VIRTUAL_INCOMING_ARGS_REGNUM); 6275 virtual_stack_vars_rtx = 6276 gen_raw_REG (Pmode, VIRTUAL_STACK_VARS_REGNUM); 6277 virtual_stack_dynamic_rtx = 6278 gen_raw_REG (Pmode, VIRTUAL_STACK_DYNAMIC_REGNUM); 6279 virtual_outgoing_args_rtx = 6280 gen_raw_REG (Pmode, VIRTUAL_OUTGOING_ARGS_REGNUM); 6281 virtual_cfa_rtx = gen_raw_REG (Pmode, VIRTUAL_CFA_REGNUM); 6282 virtual_preferred_stack_boundary_rtx = 6283 gen_raw_REG (Pmode, VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM); 6284 6285 /* Initialize RTL for commonly used hard registers. These are 6286 copied into regno_reg_rtx as we begin to compile each function. */ 6287 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) 6288 initial_regno_reg_rtx[i] = gen_raw_REG (reg_raw_mode[i], i); 6289 6290 #ifdef RETURN_ADDRESS_POINTER_REGNUM 6291 return_address_pointer_rtx 6292 = gen_raw_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM); 6293 #endif 6294 6295 pic_offset_table_rtx = NULL_RTX; 6296 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM) 6297 pic_offset_table_rtx = gen_raw_REG (Pmode, PIC_OFFSET_TABLE_REGNUM); 6298 6299 /* Process stack-limiting command-line options. */ 6300 if (opt_fstack_limit_symbol_arg != NULL) 6301 stack_limit_rtx 6302 = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (opt_fstack_limit_symbol_arg)); 6303 if (opt_fstack_limit_register_no >= 0) 6304 stack_limit_rtx = gen_rtx_REG (Pmode, opt_fstack_limit_register_no); 6305 6306 for (i = 0; i < (int) MAX_MACHINE_MODE; i++) 6307 { 6308 mode = (machine_mode) i; 6309 attrs = ggc_cleared_alloc<mem_attrs> (); 6310 attrs->align = BITS_PER_UNIT; 6311 attrs->addrspace = ADDR_SPACE_GENERIC; 6312 if (mode != BLKmode && mode != VOIDmode) 6313 { 6314 attrs->size_known_p = true; 6315 attrs->size = GET_MODE_SIZE (mode); 6316 if (STRICT_ALIGNMENT) 6317 attrs->align = GET_MODE_ALIGNMENT (mode); 6318 } 6319 mode_mem_attrs[i] = attrs; 6320 } 6321 6322 split_branch_probability = profile_probability::uninitialized (); 6323 } 6324 6325 /* Initialize global machine_mode variables. */ 6326 6327 void 6328 init_derived_machine_modes (void) 6329 { 6330 opt_scalar_int_mode mode_iter, opt_byte_mode, opt_word_mode; 6331 FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT) 6332 { 6333 scalar_int_mode mode = mode_iter.require (); 6334 6335 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT 6336 && !opt_byte_mode.exists ()) 6337 opt_byte_mode = mode; 6338 6339 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD 6340 && !opt_word_mode.exists ()) 6341 opt_word_mode = mode; 6342 } 6343 6344 byte_mode = opt_byte_mode.require (); 6345 word_mode = opt_word_mode.require (); 6346 ptr_mode = as_a <scalar_int_mode> 6347 (mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0).require ()); 6348 } 6349 6350 /* Create some permanent unique rtl objects shared between all functions. */ 6351 6352 void 6353 init_emit_once (void) 6354 { 6355 int i; 6356 machine_mode mode; 6357 scalar_float_mode double_mode; 6358 opt_scalar_mode smode_iter; 6359 6360 /* Initialize the CONST_INT, CONST_WIDE_INT, CONST_DOUBLE, 6361 CONST_FIXED, and memory attribute hash tables. */ 6362 const_int_htab = hash_table<const_int_hasher>::create_ggc (37); 6363 6364 #if TARGET_SUPPORTS_WIDE_INT 6365 const_wide_int_htab = hash_table<const_wide_int_hasher>::create_ggc (37); 6366 #endif 6367 const_double_htab = hash_table<const_double_hasher>::create_ggc (37); 6368 6369 if (NUM_POLY_INT_COEFFS > 1) 6370 const_poly_int_htab = hash_table<const_poly_int_hasher>::create_ggc (37); 6371 6372 const_fixed_htab = hash_table<const_fixed_hasher>::create_ggc (37); 6373 6374 reg_attrs_htab = hash_table<reg_attr_hasher>::create_ggc (37); 6375 6376 #ifdef INIT_EXPANDERS 6377 /* This is to initialize {init|mark|free}_machine_status before the first 6378 call to push_function_context_to. This is needed by the Chill front 6379 end which calls push_function_context_to before the first call to 6380 init_function_start. */ 6381 INIT_EXPANDERS; 6382 #endif 6383 6384 /* Create the unique rtx's for certain rtx codes and operand values. */ 6385 6386 /* Don't use gen_rtx_CONST_INT here since gen_rtx_CONST_INT in this case 6387 tries to use these variables. */ 6388 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++) 6389 const_int_rtx[i + MAX_SAVED_CONST_INT] = 6390 gen_rtx_raw_CONST_INT (VOIDmode, (HOST_WIDE_INT) i); 6391 6392 if (STORE_FLAG_VALUE >= - MAX_SAVED_CONST_INT 6393 && STORE_FLAG_VALUE <= MAX_SAVED_CONST_INT) 6394 const_true_rtx = const_int_rtx[STORE_FLAG_VALUE + MAX_SAVED_CONST_INT]; 6395 else 6396 const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE); 6397 6398 double_mode = float_mode_for_size (DOUBLE_TYPE_SIZE).require (); 6399 6400 real_from_integer (&dconst0, double_mode, 0, SIGNED); 6401 real_from_integer (&dconst1, double_mode, 1, SIGNED); 6402 real_from_integer (&dconst2, double_mode, 2, SIGNED); 6403 6404 dconstm0 = dconst0; 6405 dconstm0.sign = 1; 6406 6407 dconstm1 = dconst1; 6408 dconstm1.sign = 1; 6409 6410 dconsthalf = dconst1; 6411 SET_REAL_EXP (&dconsthalf, REAL_EXP (&dconsthalf) - 1); 6412 6413 real_inf (&dconstinf); 6414 real_inf (&dconstninf, true); 6415 6416 for (i = 0; i < 3; i++) 6417 { 6418 const REAL_VALUE_TYPE *const r = 6419 (i == 0 ? &dconst0 : i == 1 ? &dconst1 : &dconst2); 6420 6421 FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT) 6422 const_tiny_rtx[i][(int) mode] = 6423 const_double_from_real_value (*r, mode); 6424 6425 FOR_EACH_MODE_IN_CLASS (mode, MODE_DECIMAL_FLOAT) 6426 const_tiny_rtx[i][(int) mode] = 6427 const_double_from_real_value (*r, mode); 6428 6429 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i); 6430 6431 FOR_EACH_MODE_IN_CLASS (mode, MODE_INT) 6432 const_tiny_rtx[i][(int) mode] = GEN_INT (i); 6433 6434 for (mode = MIN_MODE_PARTIAL_INT; 6435 mode <= MAX_MODE_PARTIAL_INT; 6436 mode = (machine_mode)((int)(mode) + 1)) 6437 const_tiny_rtx[i][(int) mode] = GEN_INT (i); 6438 } 6439 6440 const_tiny_rtx[3][(int) VOIDmode] = constm1_rtx; 6441 6442 FOR_EACH_MODE_IN_CLASS (mode, MODE_INT) 6443 const_tiny_rtx[3][(int) mode] = constm1_rtx; 6444 6445 /* For BImode, 1 and -1 are unsigned and signed interpretations 6446 of the same value. */ 6447 for (mode = MIN_MODE_BOOL; 6448 mode <= MAX_MODE_BOOL; 6449 mode = (machine_mode)((int)(mode) + 1)) 6450 { 6451 const_tiny_rtx[0][(int) mode] = const0_rtx; 6452 if (mode == BImode) 6453 { 6454 const_tiny_rtx[1][(int) mode] = const_true_rtx; 6455 const_tiny_rtx[3][(int) mode] = const_true_rtx; 6456 } 6457 else 6458 { 6459 const_tiny_rtx[1][(int) mode] = const1_rtx; 6460 const_tiny_rtx[3][(int) mode] = constm1_rtx; 6461 } 6462 } 6463 6464 for (mode = MIN_MODE_PARTIAL_INT; 6465 mode <= MAX_MODE_PARTIAL_INT; 6466 mode = (machine_mode)((int)(mode) + 1)) 6467 const_tiny_rtx[3][(int) mode] = constm1_rtx; 6468 6469 FOR_EACH_MODE_IN_CLASS (mode, MODE_COMPLEX_INT) 6470 { 6471 rtx inner = const_tiny_rtx[0][(int)GET_MODE_INNER (mode)]; 6472 const_tiny_rtx[0][(int) mode] = gen_rtx_CONCAT (mode, inner, inner); 6473 } 6474 6475 FOR_EACH_MODE_IN_CLASS (mode, MODE_COMPLEX_FLOAT) 6476 { 6477 rtx inner = const_tiny_rtx[0][(int)GET_MODE_INNER (mode)]; 6478 const_tiny_rtx[0][(int) mode] = gen_rtx_CONCAT (mode, inner, inner); 6479 } 6480 6481 FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_BOOL) 6482 { 6483 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0); 6484 const_tiny_rtx[3][(int) mode] = gen_const_vector (mode, 3); 6485 if (GET_MODE_INNER (mode) == BImode) 6486 /* As for BImode, "all 1" and "all -1" are unsigned and signed 6487 interpretations of the same value. */ 6488 const_tiny_rtx[1][(int) mode] = const_tiny_rtx[3][(int) mode]; 6489 else 6490 const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1); 6491 } 6492 6493 FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_INT) 6494 { 6495 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0); 6496 const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1); 6497 const_tiny_rtx[3][(int) mode] = gen_const_vector (mode, 3); 6498 } 6499 6500 FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_FLOAT) 6501 { 6502 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0); 6503 const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1); 6504 } 6505 6506 FOR_EACH_MODE_IN_CLASS (smode_iter, MODE_FRACT) 6507 { 6508 scalar_mode smode = smode_iter.require (); 6509 FCONST0 (smode).data.high = 0; 6510 FCONST0 (smode).data.low = 0; 6511 FCONST0 (smode).mode = smode; 6512 const_tiny_rtx[0][(int) smode] 6513 = CONST_FIXED_FROM_FIXED_VALUE (FCONST0 (smode), smode); 6514 } 6515 6516 FOR_EACH_MODE_IN_CLASS (smode_iter, MODE_UFRACT) 6517 { 6518 scalar_mode smode = smode_iter.require (); 6519 FCONST0 (smode).data.high = 0; 6520 FCONST0 (smode).data.low = 0; 6521 FCONST0 (smode).mode = smode; 6522 const_tiny_rtx[0][(int) smode] 6523 = CONST_FIXED_FROM_FIXED_VALUE (FCONST0 (smode), smode); 6524 } 6525 6526 FOR_EACH_MODE_IN_CLASS (smode_iter, MODE_ACCUM) 6527 { 6528 scalar_mode smode = smode_iter.require (); 6529 FCONST0 (smode).data.high = 0; 6530 FCONST0 (smode).data.low = 0; 6531 FCONST0 (smode).mode = smode; 6532 const_tiny_rtx[0][(int) smode] 6533 = CONST_FIXED_FROM_FIXED_VALUE (FCONST0 (smode), smode); 6534 6535 /* We store the value 1. */ 6536 FCONST1 (smode).data.high = 0; 6537 FCONST1 (smode).data.low = 0; 6538 FCONST1 (smode).mode = smode; 6539 FCONST1 (smode).data 6540 = double_int_one.lshift (GET_MODE_FBIT (smode), 6541 HOST_BITS_PER_DOUBLE_INT, 6542 SIGNED_FIXED_POINT_MODE_P (smode)); 6543 const_tiny_rtx[1][(int) smode] 6544 = CONST_FIXED_FROM_FIXED_VALUE (FCONST1 (smode), smode); 6545 } 6546 6547 FOR_EACH_MODE_IN_CLASS (smode_iter, MODE_UACCUM) 6548 { 6549 scalar_mode smode = smode_iter.require (); 6550 FCONST0 (smode).data.high = 0; 6551 FCONST0 (smode).data.low = 0; 6552 FCONST0 (smode).mode = smode; 6553 const_tiny_rtx[0][(int) smode] 6554 = CONST_FIXED_FROM_FIXED_VALUE (FCONST0 (smode), smode); 6555 6556 /* We store the value 1. */ 6557 FCONST1 (smode).data.high = 0; 6558 FCONST1 (smode).data.low = 0; 6559 FCONST1 (smode).mode = smode; 6560 FCONST1 (smode).data 6561 = double_int_one.lshift (GET_MODE_FBIT (smode), 6562 HOST_BITS_PER_DOUBLE_INT, 6563 SIGNED_FIXED_POINT_MODE_P (smode)); 6564 const_tiny_rtx[1][(int) smode] 6565 = CONST_FIXED_FROM_FIXED_VALUE (FCONST1 (smode), smode); 6566 } 6567 6568 FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_FRACT) 6569 { 6570 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0); 6571 } 6572 6573 FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_UFRACT) 6574 { 6575 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0); 6576 } 6577 6578 FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_ACCUM) 6579 { 6580 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0); 6581 const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1); 6582 } 6583 6584 FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_UACCUM) 6585 { 6586 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0); 6587 const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1); 6588 } 6589 6590 for (i = (int) CCmode; i < (int) MAX_MACHINE_MODE; ++i) 6591 if (GET_MODE_CLASS ((machine_mode) i) == MODE_CC) 6592 const_tiny_rtx[0][i] = const0_rtx; 6593 6594 pc_rtx = gen_rtx_fmt_ (PC, VOIDmode); 6595 ret_rtx = gen_rtx_fmt_ (RETURN, VOIDmode); 6596 simple_return_rtx = gen_rtx_fmt_ (SIMPLE_RETURN, VOIDmode); 6597 invalid_insn_rtx = gen_rtx_INSN (VOIDmode, 6598 /*prev_insn=*/NULL, 6599 /*next_insn=*/NULL, 6600 /*bb=*/NULL, 6601 /*pattern=*/NULL_RTX, 6602 /*location=*/-1, 6603 CODE_FOR_nothing, 6604 /*reg_notes=*/NULL_RTX); 6605 } 6606 6607 /* Produce exact duplicate of insn INSN after AFTER. 6609 Care updating of libcall regions if present. */ 6610 6611 rtx_insn * 6612 emit_copy_of_insn_after (rtx_insn *insn, rtx_insn *after) 6613 { 6614 rtx_insn *new_rtx; 6615 rtx link; 6616 6617 switch (GET_CODE (insn)) 6618 { 6619 case INSN: 6620 new_rtx = emit_insn_after (copy_insn (PATTERN (insn)), after); 6621 break; 6622 6623 case JUMP_INSN: 6624 new_rtx = emit_jump_insn_after (copy_insn (PATTERN (insn)), after); 6625 CROSSING_JUMP_P (new_rtx) = CROSSING_JUMP_P (insn); 6626 break; 6627 6628 case DEBUG_INSN: 6629 new_rtx = emit_debug_insn_after (copy_insn (PATTERN (insn)), after); 6630 break; 6631 6632 case CALL_INSN: 6633 new_rtx = emit_call_insn_after (copy_insn (PATTERN (insn)), after); 6634 if (CALL_INSN_FUNCTION_USAGE (insn)) 6635 CALL_INSN_FUNCTION_USAGE (new_rtx) 6636 = copy_insn (CALL_INSN_FUNCTION_USAGE (insn)); 6637 SIBLING_CALL_P (new_rtx) = SIBLING_CALL_P (insn); 6638 RTL_CONST_CALL_P (new_rtx) = RTL_CONST_CALL_P (insn); 6639 RTL_PURE_CALL_P (new_rtx) = RTL_PURE_CALL_P (insn); 6640 RTL_LOOPING_CONST_OR_PURE_CALL_P (new_rtx) 6641 = RTL_LOOPING_CONST_OR_PURE_CALL_P (insn); 6642 break; 6643 6644 default: 6645 gcc_unreachable (); 6646 } 6647 6648 /* Update LABEL_NUSES. */ 6649 if (NONDEBUG_INSN_P (insn)) 6650 mark_jump_label (PATTERN (new_rtx), new_rtx, 0); 6651 6652 INSN_LOCATION (new_rtx) = INSN_LOCATION (insn); 6653 6654 /* If the old insn is frame related, then so is the new one. This is 6655 primarily needed for IA-64 unwind info which marks epilogue insns, 6656 which may be duplicated by the basic block reordering code. */ 6657 RTX_FRAME_RELATED_P (new_rtx) = RTX_FRAME_RELATED_P (insn); 6658 6659 /* Locate the end of existing REG_NOTES in NEW_RTX. */ 6660 rtx *ptail = ®_NOTES (new_rtx); 6661 while (*ptail != NULL_RTX) 6662 ptail = &XEXP (*ptail, 1); 6663 6664 /* Copy all REG_NOTES except REG_LABEL_OPERAND since mark_jump_label 6665 will make them. REG_LABEL_TARGETs are created there too, but are 6666 supposed to be sticky, so we copy them. */ 6667 for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) 6668 if (REG_NOTE_KIND (link) != REG_LABEL_OPERAND) 6669 { 6670 *ptail = duplicate_reg_note (link); 6671 ptail = &XEXP (*ptail, 1); 6672 } 6673 6674 INSN_CODE (new_rtx) = INSN_CODE (insn); 6675 return new_rtx; 6676 } 6677 6678 static GTY((deletable)) rtx hard_reg_clobbers [NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER]; 6679 rtx 6680 gen_hard_reg_clobber (machine_mode mode, unsigned int regno) 6681 { 6682 if (hard_reg_clobbers[mode][regno]) 6683 return hard_reg_clobbers[mode][regno]; 6684 else 6685 return (hard_reg_clobbers[mode][regno] = 6686 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (mode, regno))); 6687 } 6688 6689 location_t prologue_location; 6690 location_t epilogue_location; 6691 6692 /* Hold current location information and last location information, so the 6693 datastructures are built lazily only when some instructions in given 6694 place are needed. */ 6695 static location_t curr_location; 6696 6697 /* Allocate insn location datastructure. */ 6698 void 6699 insn_locations_init (void) 6700 { 6701 prologue_location = epilogue_location = 0; 6702 curr_location = UNKNOWN_LOCATION; 6703 } 6704 6705 /* At the end of emit stage, clear current location. */ 6706 void 6707 insn_locations_finalize (void) 6708 { 6709 epilogue_location = curr_location; 6710 curr_location = UNKNOWN_LOCATION; 6711 } 6712 6713 /* Set current location. */ 6714 void 6715 set_curr_insn_location (location_t location) 6716 { 6717 curr_location = location; 6718 } 6719 6720 /* Get current location. */ 6721 location_t 6722 curr_insn_location (void) 6723 { 6724 return curr_location; 6725 } 6726 6727 /* Set the location of the insn chain starting at INSN to LOC. */ 6728 void 6729 set_insn_locations (rtx_insn *insn, location_t loc) 6730 { 6731 while (insn) 6732 { 6733 if (INSN_P (insn)) 6734 INSN_LOCATION (insn) = loc; 6735 insn = NEXT_INSN (insn); 6736 } 6737 } 6738 6739 /* Return lexical scope block insn belongs to. */ 6740 tree 6741 insn_scope (const rtx_insn *insn) 6742 { 6743 return LOCATION_BLOCK (INSN_LOCATION (insn)); 6744 } 6745 6746 /* Return line number of the statement that produced this insn. */ 6747 int 6748 insn_line (const rtx_insn *insn) 6749 { 6750 return LOCATION_LINE (INSN_LOCATION (insn)); 6751 } 6752 6753 /* Return source file of the statement that produced this insn. */ 6754 const char * 6755 insn_file (const rtx_insn *insn) 6756 { 6757 return LOCATION_FILE (INSN_LOCATION (insn)); 6758 } 6759 6760 /* Return expanded location of the statement that produced this insn. */ 6761 expanded_location 6762 insn_location (const rtx_insn *insn) 6763 { 6764 return expand_location (INSN_LOCATION (insn)); 6765 } 6766 6767 /* Return true if memory model MODEL requires a pre-operation (release-style) 6768 barrier or a post-operation (acquire-style) barrier. While not universal, 6769 this function matches behavior of several targets. */ 6770 6771 bool 6772 need_atomic_barrier_p (enum memmodel model, bool pre) 6773 { 6774 switch (model & MEMMODEL_BASE_MASK) 6775 { 6776 case MEMMODEL_RELAXED: 6777 case MEMMODEL_CONSUME: 6778 return false; 6779 case MEMMODEL_RELEASE: 6780 return pre; 6781 case MEMMODEL_ACQUIRE: 6782 return !pre; 6783 case MEMMODEL_ACQ_REL: 6784 case MEMMODEL_SEQ_CST: 6785 return true; 6786 default: 6787 gcc_unreachable (); 6788 } 6789 } 6790 6791 /* Return a constant shift amount for shifting a value of mode MODE 6792 by VALUE bits. */ 6793 6794 rtx 6795 gen_int_shift_amount (machine_mode, poly_int64 value) 6796 { 6797 /* Use a 64-bit mode, to avoid any truncation. 6798 6799 ??? Perhaps this should be automatically derived from the .md files 6800 instead, or perhaps have a target hook. */ 6801 scalar_int_mode shift_mode = (BITS_PER_UNIT == 8 6802 ? DImode 6803 : int_mode_for_size (64, 0).require ()); 6804 return gen_int_mode (value, shift_mode); 6805 } 6806 6807 /* Initialize fields of rtl_data related to stack alignment. */ 6808 6809 void 6810 rtl_data::init_stack_alignment () 6811 { 6812 stack_alignment_needed = STACK_BOUNDARY; 6813 max_used_stack_slot_alignment = STACK_BOUNDARY; 6814 stack_alignment_estimated = 0; 6815 preferred_stack_boundary = STACK_BOUNDARY; 6816 } 6817 6818 6819 #include "gt-emit-rtl.h" 6821