comparison gcc/emit-rtl.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Emit RTL for the GCC expander. 1 /* Emit RTL for the GCC expander.
2 Copyright (C) 1987-2018 Free Software Foundation, Inc. 2 Copyright (C) 1987-2020 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it under 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 7 the terms of the GNU General Public License as published by the Free
52 #include "varasm.h" 52 #include "varasm.h"
53 #include "cfgrtl.h" 53 #include "cfgrtl.h"
54 #include "tree-eh.h" 54 #include "tree-eh.h"
55 #include "explow.h" 55 #include "explow.h"
56 #include "expr.h" 56 #include "expr.h"
57 #include "params.h"
58 #include "builtins.h" 57 #include "builtins.h"
59 #include "rtl-iter.h" 58 #include "rtl-iter.h"
60 #include "stor-layout.h" 59 #include "stor-layout.h"
61 #include "opts.h" 60 #include "opts.h"
62 #include "predict.h" 61 #include "predict.h"
63 #include "rtx-vector-builder.h" 62 #include "rtx-vector-builder.h"
63 #include "gimple.h"
64 #include "gimple-ssa.h"
65 #include "gimplify.h"
64 66
65 struct target_rtl default_target_rtl; 67 struct target_rtl default_target_rtl;
66 #if SWITCHABLE_TARGET 68 #if SWITCHABLE_TARGET
67 struct target_rtl *this_target_rtl = &default_target_rtl; 69 struct target_rtl *this_target_rtl = &default_target_rtl;
68 #endif 70 #endif
346 } 348 }
347 349
348 /* Return true if the given memory attributes are equal. */ 350 /* Return true if the given memory attributes are equal. */
349 351
350 bool 352 bool
351 mem_attrs_eq_p (const struct mem_attrs *p, const struct mem_attrs *q) 353 mem_attrs_eq_p (const class mem_attrs *p, const class mem_attrs *q)
352 { 354 {
353 if (p == q) 355 if (p == q)
354 return true; 356 return true;
355 if (!p || !q) 357 if (!p || !q)
356 return false; 358 return false;
461 : 1); 463 : 1);
462 PUT_MODE_RAW (x, mode); 464 PUT_MODE_RAW (x, mode);
463 set_regno_raw (x, regno, nregs); 465 set_regno_raw (x, regno, nregs);
464 } 466 }
465 467
468 /* Initialize a fresh REG rtx with mode MODE and register REGNO. */
469
470 rtx
471 init_raw_REG (rtx x, machine_mode mode, unsigned int regno)
472 {
473 set_mode_and_regno (x, mode, regno);
474 REG_ATTRS (x) = NULL;
475 ORIGINAL_REGNO (x) = regno;
476 return x;
477 }
478
466 /* Generate a new REG rtx. Make sure ORIGINAL_REGNO is set properly, and 479 /* Generate a new REG rtx. Make sure ORIGINAL_REGNO is set properly, and
467 don't attempt to share with the various global pieces of rtl (such as 480 don't attempt to share with the various global pieces of rtl (such as
468 frame_pointer_rtx). */ 481 frame_pointer_rtx). */
469 482
470 rtx 483 rtx
471 gen_raw_REG (machine_mode mode, unsigned int regno) 484 gen_raw_REG (machine_mode mode, unsigned int regno)
472 { 485 {
473 rtx x = rtx_alloc (REG MEM_STAT_INFO); 486 rtx x = rtx_alloc (REG MEM_STAT_INFO);
474 set_mode_and_regno (x, mode, regno); 487 init_raw_REG (x, mode, regno);
475 REG_ATTRS (x) = NULL;
476 ORIGINAL_REGNO (x) = regno;
477 return x; 488 return x;
478 } 489 }
479 490
480 /* There are some RTL codes that require special attention; the generation 491 /* There are some RTL codes that require special attention; the generation
481 functions do the raw handling. If you add to this list, modify 492 functions do the raw handling. If you add to this list, modify
1779 if (result) 1790 if (result)
1780 return result; 1791 return result;
1781 1792
1782 if (mode != BLKmode && mode != VOIDmode) 1793 if (mode != BLKmode && mode != VOIDmode)
1783 { 1794 {
1784 /* If this is a register which can not be accessed by words, copy it 1795 /* If this is a register which cannot be accessed by words, copy it
1785 to a pseudo register. */ 1796 to a pseudo register. */
1786 if (REG_P (op)) 1797 if (REG_P (op))
1787 op = copy_to_reg (op); 1798 op = copy_to_reg (op);
1788 else 1799 else
1789 op = force_reg (mode, op); 1800 op = force_reg (mode, op);
1919 set_mem_attributes_minus_bitpos (rtx ref, tree t, int objectp, 1930 set_mem_attributes_minus_bitpos (rtx ref, tree t, int objectp,
1920 poly_int64 bitpos) 1931 poly_int64 bitpos)
1921 { 1932 {
1922 poly_int64 apply_bitpos = 0; 1933 poly_int64 apply_bitpos = 0;
1923 tree type; 1934 tree type;
1924 struct mem_attrs attrs, *defattrs, *refattrs; 1935 class mem_attrs attrs, *defattrs, *refattrs;
1925 addr_space_t as; 1936 addr_space_t as;
1926 1937
1927 /* It can happen that type_for_mode was given a mode for which there 1938 /* It can happen that type_for_mode was given a mode for which there
1928 is no language-level type. In which case it returns NULL, which 1939 is no language-level type. In which case it returns NULL, which
1929 we can see here. */ 1940 we can see here. */
2126 attrs.offset_known_p = true; 2137 attrs.offset_known_p = true;
2127 attrs.offset = 0; 2138 attrs.offset = 0;
2128 apply_bitpos = bitpos; 2139 apply_bitpos = bitpos;
2129 } 2140 }
2130 2141
2142 /* If this is a reference based on a partitioned decl replace the
2143 base with a MEM_REF of the pointer representative we created
2144 during stack slot partitioning. */
2145 if (attrs.expr
2146 && VAR_P (base)
2147 && ! is_global_var (base)
2148 && cfun->gimple_df->decls_to_pointers != NULL)
2149 {
2150 tree *namep = cfun->gimple_df->decls_to_pointers->get (base);
2151 if (namep)
2152 {
2153 attrs.expr = unshare_expr (attrs.expr);
2154 tree *orig_base = &attrs.expr;
2155 while (handled_component_p (*orig_base))
2156 orig_base = &TREE_OPERAND (*orig_base, 0);
2157 tree aptrt = reference_alias_ptr_type (*orig_base);
2158 *orig_base = build2 (MEM_REF, TREE_TYPE (*orig_base), *namep,
2159 build_int_cst (aptrt, 0));
2160 }
2161 }
2162
2131 /* Compute the alignment. */ 2163 /* Compute the alignment. */
2132 unsigned int obj_align; 2164 unsigned int obj_align;
2133 unsigned HOST_WIDE_INT obj_bitpos; 2165 unsigned HOST_WIDE_INT obj_bitpos;
2134 get_object_alignment_1 (t, &obj_align, &obj_bitpos); 2166 get_object_alignment_1 (t, &obj_align, &obj_bitpos);
2135 unsigned int diff_align = known_alignment (obj_bitpos - bitpos); 2167 unsigned int diff_align = known_alignment (obj_bitpos - bitpos);
2308 rtx 2340 rtx
2309 change_address (rtx memref, machine_mode mode, rtx addr) 2341 change_address (rtx memref, machine_mode mode, rtx addr)
2310 { 2342 {
2311 rtx new_rtx = change_address_1 (memref, mode, addr, 1, false); 2343 rtx new_rtx = change_address_1 (memref, mode, addr, 1, false);
2312 machine_mode mmode = GET_MODE (new_rtx); 2344 machine_mode mmode = GET_MODE (new_rtx);
2313 struct mem_attrs *defattrs; 2345 class mem_attrs *defattrs;
2314 2346
2315 mem_attrs attrs (*get_mem_attrs (memref)); 2347 mem_attrs attrs (*get_mem_attrs (memref));
2316 defattrs = mode_mem_attrs[(int) mmode]; 2348 defattrs = mode_mem_attrs[(int) mmode];
2317 attrs.expr = NULL_TREE; 2349 attrs.expr = NULL_TREE;
2318 attrs.offset_known_p = false; 2350 attrs.offset_known_p = false;
2352 poly_int64 size) 2384 poly_int64 size)
2353 { 2385 {
2354 rtx addr = XEXP (memref, 0); 2386 rtx addr = XEXP (memref, 0);
2355 rtx new_rtx; 2387 rtx new_rtx;
2356 scalar_int_mode address_mode; 2388 scalar_int_mode address_mode;
2357 struct mem_attrs attrs (*get_mem_attrs (memref)), *defattrs; 2389 class mem_attrs attrs (*get_mem_attrs (memref)), *defattrs;
2358 unsigned HOST_WIDE_INT max_align; 2390 unsigned HOST_WIDE_INT max_align;
2359 #ifdef POINTERS_EXTEND_UNSIGNED 2391 #ifdef POINTERS_EXTEND_UNSIGNED
2360 scalar_int_mode pointer_mode 2392 scalar_int_mode pointer_mode
2361 = targetm.addr_space.pointer_mode (attrs.addrspace); 2393 = targetm.addr_space.pointer_mode (attrs.addrspace);
2362 #endif 2394 #endif
2498 rtx 2530 rtx
2499 offset_address (rtx memref, rtx offset, unsigned HOST_WIDE_INT pow2) 2531 offset_address (rtx memref, rtx offset, unsigned HOST_WIDE_INT pow2)
2500 { 2532 {
2501 rtx new_rtx, addr = XEXP (memref, 0); 2533 rtx new_rtx, addr = XEXP (memref, 0);
2502 machine_mode address_mode; 2534 machine_mode address_mode;
2503 struct mem_attrs *defattrs; 2535 class mem_attrs *defattrs;
2504 2536
2505 mem_attrs attrs (*get_mem_attrs (memref)); 2537 mem_attrs attrs (*get_mem_attrs (memref));
2506 address_mode = get_address_mode (memref); 2538 address_mode = get_address_mode (memref);
2507 new_rtx = simplify_gen_binary (PLUS, address_mode, addr, offset); 2539 new_rtx = simplify_gen_binary (PLUS, address_mode, addr, offset);
2508 2540
2727 2759
2728 set_first_insn (first); 2760 set_first_insn (first);
2729 set_last_insn (last); 2761 set_last_insn (last);
2730 cur_insn_uid = 0; 2762 cur_insn_uid = 0;
2731 2763
2732 if (MIN_NONDEBUG_INSN_UID || MAY_HAVE_DEBUG_INSNS) 2764 if (param_min_nondebug_insn_uid || MAY_HAVE_DEBUG_INSNS)
2733 { 2765 {
2734 int debug_count = 0; 2766 int debug_count = 0;
2735 2767
2736 cur_insn_uid = MIN_NONDEBUG_INSN_UID - 1; 2768 cur_insn_uid = param_min_nondebug_insn_uid - 1;
2737 cur_debug_insn_uid = 0; 2769 cur_debug_insn_uid = 0;
2738 2770
2739 for (insn = first; insn; insn = NEXT_INSN (insn)) 2771 for (insn = first; insn; insn = NEXT_INSN (insn))
2740 if (INSN_UID (insn) < MIN_NONDEBUG_INSN_UID) 2772 if (INSN_UID (insn) < param_min_nondebug_insn_uid)
2741 cur_debug_insn_uid = MAX (cur_debug_insn_uid, INSN_UID (insn)); 2773 cur_debug_insn_uid = MAX (cur_debug_insn_uid, INSN_UID (insn));
2742 else 2774 else
2743 { 2775 {
2744 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn)); 2776 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
2745 if (DEBUG_INSN_P (insn)) 2777 if (DEBUG_INSN_P (insn))
2746 debug_count++; 2778 debug_count++;
2747 } 2779 }
2748 2780
2749 if (debug_count) 2781 if (debug_count)
2750 cur_debug_insn_uid = MIN_NONDEBUG_INSN_UID + debug_count; 2782 cur_debug_insn_uid = param_min_nondebug_insn_uid + debug_count;
2751 else 2783 else
2752 cur_debug_insn_uid++; 2784 cur_debug_insn_uid++;
2753 } 2785 }
2754 else 2786 else
2755 for (insn = first; insn; insn = NEXT_INSN (insn)) 2787 for (insn = first; insn; insn = NEXT_INSN (insn))
2863 case SIMPLE_RETURN: 2895 case SIMPLE_RETURN:
2864 case SCRATCH: 2896 case SCRATCH:
2865 /* SCRATCH must be shared because they represent distinct values. */ 2897 /* SCRATCH must be shared because they represent distinct values. */
2866 return; 2898 return;
2867 case CLOBBER: 2899 case CLOBBER:
2868 case CLOBBER_HIGH:
2869 /* Share clobbers of hard registers (like cc0), but do not share pseudo reg 2900 /* Share clobbers of hard registers (like cc0), but do not share pseudo reg
2870 clobbers or clobbers of hard registers that originated as pseudos. 2901 clobbers or clobbers of hard registers that originated as pseudos.
2871 This is needed to allow safe register renaming. */ 2902 This is needed to allow safe register renaming. */
2872 if (REG_P (XEXP (x, 0)) 2903 if (REG_P (XEXP (x, 0))
2873 && HARD_REGISTER_NUM_P (REGNO (XEXP (x, 0))) 2904 && HARD_REGISTER_NUM_P (REGNO (XEXP (x, 0)))
3117 case SIMPLE_RETURN: 3148 case SIMPLE_RETURN:
3118 case SCRATCH: 3149 case SCRATCH:
3119 /* SCRATCH must be shared because they represent distinct values. */ 3150 /* SCRATCH must be shared because they represent distinct values. */
3120 return; 3151 return;
3121 case CLOBBER: 3152 case CLOBBER:
3122 case CLOBBER_HIGH:
3123 /* Share clobbers of hard registers (like cc0), but do not share pseudo reg 3153 /* Share clobbers of hard registers (like cc0), but do not share pseudo reg
3124 clobbers or clobbers of hard registers that originated as pseudos. 3154 clobbers or clobbers of hard registers that originated as pseudos.
3125 This is needed to allow safe register renaming. */ 3155 This is needed to allow safe register renaming. */
3126 if (REG_P (XEXP (x, 0)) 3156 if (REG_P (XEXP (x, 0))
3127 && HARD_REGISTER_NUM_P (REGNO (XEXP (x, 0))) 3157 && HARD_REGISTER_NUM_P (REGNO (XEXP (x, 0)))
3412 3442
3413 /* The table size must be stable across -g, to avoid codegen 3443 /* The table size must be stable across -g, to avoid codegen
3414 differences due to debug insns, and not be affected by 3444 differences due to debug insns, and not be affected by
3415 -fmin-insn-uid, to avoid excessive table size and to simplify 3445 -fmin-insn-uid, to avoid excessive table size and to simplify
3416 debugging of -fcompare-debug failures. */ 3446 debugging of -fcompare-debug failures. */
3417 if (cur_debug_insn_uid > MIN_NONDEBUG_INSN_UID) 3447 if (cur_debug_insn_uid > param_min_nondebug_insn_uid)
3418 n -= cur_debug_insn_uid; 3448 n -= cur_debug_insn_uid;
3419 else 3449 else
3420 n -= MIN_NONDEBUG_INSN_UID; 3450 n -= param_min_nondebug_insn_uid;
3421 3451
3422 return n; 3452 return n;
3423 } 3453 }
3424 3454
3425 3455
3938 add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0)); 3968 add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0));
3939 } 3969 }
3940 break; 3970 break;
3941 3971
3942 case REG_NON_LOCAL_GOTO: 3972 case REG_NON_LOCAL_GOTO:
3973 case REG_LABEL_TARGET:
3943 for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn)) 3974 for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn))
3944 { 3975 {
3945 if (JUMP_P (insn)) 3976 if (JUMP_P (insn))
3946 add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0)); 3977 add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0));
3947 } 3978 }
3990 } 4021 }
3991 4022
3992 before = PREV_INSN (trial); 4023 before = PREV_INSN (trial);
3993 after = NEXT_INSN (trial); 4024 after = NEXT_INSN (trial);
3994 4025
3995 tem = emit_insn_after_setloc (seq, trial, INSN_LOCATION (trial)); 4026 emit_insn_after_setloc (seq, trial, INSN_LOCATION (trial));
3996 4027
3997 delete_insn (trial); 4028 delete_insn (trial);
3998 4029
3999 /* Recursively call try_split for each new insn created; by the 4030 /* Recursively call try_split for each new insn created; by the
4000 time control returns here that insn will be fully split, so 4031 time control returns here that insn will be fully split, so
4051 { 4082 {
4052 rtx_debug_insn *insn; 4083 rtx_debug_insn *insn;
4053 4084
4054 insn = as_a <rtx_debug_insn *> (rtx_alloc (DEBUG_INSN)); 4085 insn = as_a <rtx_debug_insn *> (rtx_alloc (DEBUG_INSN));
4055 INSN_UID (insn) = cur_debug_insn_uid++; 4086 INSN_UID (insn) = cur_debug_insn_uid++;
4056 if (cur_debug_insn_uid > MIN_NONDEBUG_INSN_UID) 4087 if (cur_debug_insn_uid > param_min_nondebug_insn_uid)
4057 INSN_UID (insn) = cur_insn_uid++; 4088 INSN_UID (insn) = cur_insn_uid++;
4058 4089
4059 PATTERN (insn) = pattern; 4090 PATTERN (insn) = pattern;
4060 INSN_CODE (insn) = -1; 4091 INSN_CODE (insn) = -1;
4061 REG_NOTES (insn) = NULL; 4092 REG_NOTES (insn) = NULL;
5690 case CC0: 5721 case CC0:
5691 case RETURN: 5722 case RETURN:
5692 case SIMPLE_RETURN: 5723 case SIMPLE_RETURN:
5693 return orig; 5724 return orig;
5694 case CLOBBER: 5725 case CLOBBER:
5695 case CLOBBER_HIGH:
5696 /* Share clobbers of hard registers (like cc0), but do not share pseudo reg 5726 /* Share clobbers of hard registers (like cc0), but do not share pseudo reg
5697 clobbers or clobbers of hard registers that originated as pseudos. 5727 clobbers or clobbers of hard registers that originated as pseudos.
5698 This is needed to allow safe register renaming. */ 5728 This is needed to allow safe register renaming. */
5699 if (REG_P (XEXP (orig, 0)) 5729 if (REG_P (XEXP (orig, 0))
5700 && HARD_REGISTER_NUM_P (REGNO (XEXP (orig, 0))) 5730 && HARD_REGISTER_NUM_P (REGNO (XEXP (orig, 0)))
5827 void 5857 void
5828 init_emit (void) 5858 init_emit (void)
5829 { 5859 {
5830 set_first_insn (NULL); 5860 set_first_insn (NULL);
5831 set_last_insn (NULL); 5861 set_last_insn (NULL);
5832 if (MIN_NONDEBUG_INSN_UID) 5862 if (param_min_nondebug_insn_uid)
5833 cur_insn_uid = MIN_NONDEBUG_INSN_UID; 5863 cur_insn_uid = param_min_nondebug_insn_uid;
5834 else 5864 else
5835 cur_insn_uid = 1; 5865 cur_insn_uid = 1;
5836 cur_debug_insn_uid = 1; 5866 cur_debug_insn_uid = 1;
5837 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1; 5867 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
5838 first_label_num = label_num; 5868 first_label_num = label_num;
6502 else 6532 else
6503 return (hard_reg_clobbers[mode][regno] = 6533 return (hard_reg_clobbers[mode][regno] =
6504 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (mode, regno))); 6534 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (mode, regno)));
6505 } 6535 }
6506 6536
6507 static GTY((deletable)) rtx
6508 hard_reg_clobbers_high[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
6509
6510 /* Return a CLOBBER_HIGH expression for register REGNO that clobbers MODE,
6511 caching into HARD_REG_CLOBBERS_HIGH. */
6512 rtx
6513 gen_hard_reg_clobber_high (machine_mode mode, unsigned int regno)
6514 {
6515 if (hard_reg_clobbers_high[mode][regno])
6516 return hard_reg_clobbers_high[mode][regno];
6517 else
6518 return (hard_reg_clobbers_high[mode][regno]
6519 = gen_rtx_CLOBBER_HIGH (VOIDmode, gen_rtx_REG (mode, regno)));
6520 }
6521
6522 location_t prologue_location; 6537 location_t prologue_location;
6523 location_t epilogue_location; 6538 location_t epilogue_location;
6524 6539
6525 /* Hold current location information and last location information, so the 6540 /* Hold current location information and last location information, so the
6526 datastructures are built lazily only when some instructions in given 6541 datastructures are built lazily only when some instructions in given
6553 /* Get current location. */ 6568 /* Get current location. */
6554 location_t 6569 location_t
6555 curr_insn_location (void) 6570 curr_insn_location (void)
6556 { 6571 {
6557 return curr_location; 6572 return curr_location;
6573 }
6574
6575 /* Set the location of the insn chain starting at INSN to LOC. */
6576 void
6577 set_insn_locations (rtx_insn *insn, location_t loc)
6578 {
6579 while (insn)
6580 {
6581 if (INSN_P (insn))
6582 INSN_LOCATION (insn) = loc;
6583 insn = NEXT_INSN (insn);
6584 }
6558 } 6585 }
6559 6586
6560 /* Return lexical scope block insn belongs to. */ 6587 /* Return lexical scope block insn belongs to. */
6561 tree 6588 tree
6562 insn_scope (const rtx_insn *insn) 6589 insn_scope (const rtx_insn *insn)