comparison gcc/lra-constraints.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 /* Code for RTL transformations to satisfy insn constraints. 1 /* Code for RTL transformations to satisfy insn constraints.
2 Copyright (C) 2010-2018 Free Software Foundation, Inc. 2 Copyright (C) 2010-2020 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>. 3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
125 #include "output.h" 125 #include "output.h"
126 #include "addresses.h" 126 #include "addresses.h"
127 #include "expr.h" 127 #include "expr.h"
128 #include "cfgrtl.h" 128 #include "cfgrtl.h"
129 #include "rtl-error.h" 129 #include "rtl-error.h"
130 #include "params.h"
131 #include "lra.h" 130 #include "lra.h"
132 #include "lra-int.h" 131 #include "lra-int.h"
133 #include "print-rtl.h" 132 #include "print-rtl.h"
133 #include "function-abi.h"
134 134
135 /* Value of LRA_CURR_RELOAD_NUM at the beginning of BB of the current 135 /* Value of LRA_CURR_RELOAD_NUM at the beginning of BB of the current
136 insn. Remember that LRA_CURR_RELOAD_NUM is the number of emitted 136 insn. Remember that LRA_CURR_RELOAD_NUM is the number of emitted
137 reload insns. */ 137 reload insns. */
138 static int bb_reload_num; 138 static int bb_reload_num;
357 m_index_reg (NULL_RTX) 357 m_index_reg (NULL_RTX)
358 { 358 {
359 if (m_base_loc != NULL) 359 if (m_base_loc != NULL)
360 { 360 {
361 m_base_reg = *m_base_loc; 361 m_base_reg = *m_base_loc;
362 lra_eliminate_reg_if_possible (m_base_loc); 362 /* If we have non-legitimate address which is decomposed not in
363 the way we expected, don't do elimination here. In such case
364 the address will be reloaded and elimination will be done in
365 reload insn finally. */
366 if (REG_P (m_base_reg))
367 lra_eliminate_reg_if_possible (m_base_loc);
363 if (m_ad->base_term2 != NULL) 368 if (m_ad->base_term2 != NULL)
364 *m_ad->base_term2 = *m_ad->base_term; 369 *m_ad->base_term2 = *m_ad->base_term;
365 } 370 }
366 if (m_index_loc != NULL) 371 if (m_index_loc != NULL)
367 { 372 {
368 m_index_reg = *m_index_loc; 373 m_index_reg = *m_index_loc;
369 lra_eliminate_reg_if_possible (m_index_loc); 374 if (REG_P (m_index_reg))
375 lra_eliminate_reg_if_possible (m_index_loc);
370 } 376 }
371 } 377 }
372 378
373 address_eliminator::~address_eliminator () 379 address_eliminator::~address_eliminator ()
374 { 380 {
380 } 386 }
381 if (m_index_loc && *m_index_loc != m_index_reg) 387 if (m_index_loc && *m_index_loc != m_index_reg)
382 *m_index_loc = m_index_reg; 388 *m_index_loc = m_index_reg;
383 } 389 }
384 390
385 /* Return true if the eliminated form of AD is a legitimate target address. */ 391 /* Return true if the eliminated form of AD is a legitimate target address.
392 If OP is a MEM, AD is the address within OP, otherwise OP should be
393 ignored. CONSTRAINT is one constraint that the operand may need
394 to meet. */
386 static bool 395 static bool
387 valid_address_p (struct address_info *ad) 396 valid_address_p (rtx op, struct address_info *ad,
397 enum constraint_num constraint)
388 { 398 {
389 address_eliminator eliminator (ad); 399 address_eliminator eliminator (ad);
400
401 /* Allow a memory OP if it matches CONSTRAINT, even if CONSTRAINT is more
402 forgiving than "m". */
403 if (MEM_P (op)
404 && (insn_extra_memory_constraint (constraint)
405 || insn_extra_special_memory_constraint (constraint))
406 && constraint_satisfied_p (op, constraint))
407 return true;
408
390 return valid_address_p (ad->mode, *ad->outer, ad->as); 409 return valid_address_p (ad->mode, *ad->outer, ad->as);
391 } 410 }
392 411
393 /* Return true if the eliminated form of memory reference OP satisfies 412 /* Return true if the eliminated form of memory reference OP satisfies
394 extra (special) memory constraint CONSTRAINT. */ 413 extra (special) memory constraint CONSTRAINT. */
977 have a situation like "a <- a op b", where the constraints 996 have a situation like "a <- a op b", where the constraints
978 force the second input operand ("b") to match the output 997 force the second input operand ("b") to match the output
979 operand ("a"). "b" must then be copied into a new register 998 operand ("a"). "b" must then be copied into a new register
980 so that it doesn't clobber the current value of "a". 999 so that it doesn't clobber the current value of "a".
981 1000
982 We can not use the same value if the output pseudo is 1001 We cannot use the same value if the output pseudo is
983 early clobbered or the input pseudo is mentioned in the 1002 early clobbered or the input pseudo is mentioned in the
984 output, e.g. as an address part in memory, because 1003 output, e.g. as an address part in memory, because
985 output reload will actually extend the pseudo liveness. 1004 output reload will actually extend the pseudo liveness.
986 We don't care about eliminable hard regs here as we are 1005 We don't care about eliminable hard regs here as we are
987 interesting only in pseudos. */ 1006 interesting only in pseudos. */
1033 lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS); 1052 lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS);
1034 curr_insn_input_reloads[curr_insn_input_reloads_num].input = in_rtx; 1053 curr_insn_input_reloads[curr_insn_input_reloads_num].input = in_rtx;
1035 curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = true; 1054 curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = true;
1036 curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = new_in_reg; 1055 curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = new_in_reg;
1037 for (i = 0; (in = ins[i]) >= 0; i++) 1056 for (i = 0; (in = ins[i]) >= 0; i++)
1038 { 1057 if (GET_MODE (*curr_id->operand_loc[in]) == VOIDmode
1039 lra_assert 1058 || GET_MODE (new_in_reg) == GET_MODE (*curr_id->operand_loc[in]))
1040 (GET_MODE (*curr_id->operand_loc[in]) == VOIDmode
1041 || GET_MODE (new_in_reg) == GET_MODE (*curr_id->operand_loc[in]));
1042 *curr_id->operand_loc[in] = new_in_reg; 1059 *curr_id->operand_loc[in] = new_in_reg;
1043 } 1060 else
1061 {
1062 lra_assert
1063 (GET_MODE (new_out_reg) == GET_MODE (*curr_id->operand_loc[in]));
1064 *curr_id->operand_loc[in] = new_out_reg;
1065 }
1044 lra_update_dups (curr_id, ins); 1066 lra_update_dups (curr_id, ins);
1045 if (out < 0) 1067 if (out < 0)
1046 return; 1068 return;
1047 /* See a comment for the input operand above. */ 1069 /* See a comment for the input operand above. */
1048 narrow_reload_pseudo_class (out_rtx, goal_class); 1070 narrow_reload_pseudo_class (out_rtx, goal_class);
1489 const bool addr_was_valid 1511 const bool addr_was_valid
1490 = valid_address_p (innermode, XEXP (reg, 0), MEM_ADDR_SPACE (reg)); 1512 = valid_address_p (innermode, XEXP (reg, 0), MEM_ADDR_SPACE (reg));
1491 alter_subreg (curr_id->operand_loc[nop], false); 1513 alter_subreg (curr_id->operand_loc[nop], false);
1492 rtx subst = *curr_id->operand_loc[nop]; 1514 rtx subst = *curr_id->operand_loc[nop];
1493 lra_assert (MEM_P (subst)); 1515 lra_assert (MEM_P (subst));
1494 1516 const bool addr_is_valid = valid_address_p (GET_MODE (subst),
1517 XEXP (subst, 0),
1518 MEM_ADDR_SPACE (subst));
1495 if (!addr_was_valid 1519 if (!addr_was_valid
1496 || valid_address_p (GET_MODE (subst), XEXP (subst, 0), 1520 || addr_is_valid
1497 MEM_ADDR_SPACE (subst))
1498 || ((get_constraint_type (lookup_constraint 1521 || ((get_constraint_type (lookup_constraint
1499 (curr_static_id->operand[nop].constraint)) 1522 (curr_static_id->operand[nop].constraint))
1500 != CT_SPECIAL_MEMORY) 1523 != CT_SPECIAL_MEMORY)
1501 /* We still can reload address and if the address is 1524 /* We still can reload address and if the address is
1502 valid, we can remove subreg without reloading its 1525 valid, we can remove subreg without reloading its
1521 However, do not blindly simplify a (subreg (mem ...)) for 1544 However, do not blindly simplify a (subreg (mem ...)) for
1522 WORD_REGISTER_OPERATIONS targets as this may lead to loading junk 1545 WORD_REGISTER_OPERATIONS targets as this may lead to loading junk
1523 data into a register when the inner is narrower than outer or 1546 data into a register when the inner is narrower than outer or
1524 missing important data from memory when the inner is wider than 1547 missing important data from memory when the inner is wider than
1525 outer. This rule only applies to modes that are no wider than 1548 outer. This rule only applies to modes that are no wider than
1526 a word. */ 1549 a word.
1527 if (!(maybe_ne (GET_MODE_PRECISION (mode), 1550
1528 GET_MODE_PRECISION (innermode)) 1551 If valid memory becomes invalid after subreg elimination
1529 && known_le (GET_MODE_SIZE (mode), UNITS_PER_WORD) 1552 and address might be different we still have to reload
1530 && known_le (GET_MODE_SIZE (innermode), UNITS_PER_WORD) 1553 memory.
1531 && WORD_REGISTER_OPERATIONS) 1554 */
1555 if ((! addr_was_valid
1556 || addr_is_valid
1557 || known_eq (GET_MODE_SIZE (mode), GET_MODE_SIZE (innermode)))
1558 && !(maybe_ne (GET_MODE_PRECISION (mode),
1559 GET_MODE_PRECISION (innermode))
1560 && known_le (GET_MODE_SIZE (mode), UNITS_PER_WORD)
1561 && known_le (GET_MODE_SIZE (innermode), UNITS_PER_WORD)
1562 && WORD_REGISTER_OPERATIONS)
1532 && (!(MEM_ALIGN (subst) < GET_MODE_ALIGNMENT (mode) 1563 && (!(MEM_ALIGN (subst) < GET_MODE_ALIGNMENT (mode)
1533 && targetm.slow_unaligned_access (mode, MEM_ALIGN (subst))) 1564 && targetm.slow_unaligned_access (mode, MEM_ALIGN (subst)))
1534 || (MEM_ALIGN (reg) < GET_MODE_ALIGNMENT (innermode) 1565 || (MEM_ALIGN (reg) < GET_MODE_ALIGNMENT (innermode)
1535 && targetm.slow_unaligned_access (innermode, 1566 && targetm.slow_unaligned_access (innermode,
1536 MEM_ALIGN (reg))))) 1567 MEM_ALIGN (reg)))))
1545 1576
1546 /* INNERMODE is fast, MODE slow. Reload the mem in INNERMODE. */ 1577 /* INNERMODE is fast, MODE slow. Reload the mem in INNERMODE. */
1547 enum reg_class rclass 1578 enum reg_class rclass
1548 = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS); 1579 = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1549 if (get_reload_reg (curr_static_id->operand[nop].type, innermode, 1580 if (get_reload_reg (curr_static_id->operand[nop].type, innermode,
1550 reg, rclass, TRUE, "slow mem", &new_reg)) 1581 reg, rclass, TRUE, "slow/invalid mem", &new_reg))
1551 { 1582 {
1552 bool insert_before, insert_after; 1583 bool insert_before, insert_after;
1553 bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg)); 1584 bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1554 1585
1555 insert_before = (type != OP_OUT 1586 insert_before = (type != OP_OUT
1564 /* Convert to MODE. */ 1595 /* Convert to MODE. */
1565 reg = operand; 1596 reg = operand;
1566 rclass 1597 rclass
1567 = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS); 1598 = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1568 if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg, 1599 if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg,
1569 rclass, TRUE, "slow mem", &new_reg)) 1600 rclass, TRUE, "slow/invalid mem", &new_reg))
1570 { 1601 {
1571 bool insert_before, insert_after; 1602 bool insert_before, insert_after;
1572 bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg)); 1603 bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1573 1604
1574 insert_before = type != OP_OUT; 1605 insert_before = type != OP_OUT;
1577 insert_after ? &after : NULL, 1608 insert_after ? &after : NULL,
1578 reg, new_reg); 1609 reg, new_reg);
1579 } 1610 }
1580 *curr_id->operand_loc[nop] = new_reg; 1611 *curr_id->operand_loc[nop] = new_reg;
1581 lra_process_new_insns (curr_insn, before, after, 1612 lra_process_new_insns (curr_insn, before, after,
1582 "Inserting slow mem reload"); 1613 "Inserting slow/invalid mem reload");
1583 return true; 1614 return true;
1584 } 1615 }
1585 1616
1586 /* If the address was valid and became invalid, prefer to reload 1617 /* If the address was valid and became invalid, prefer to reload
1587 the memory. Typical case is when the index scale should 1618 the memory. Typical case is when the index scale should
1753 1784
1754 if (x == NULL_RTX) 1785 if (x == NULL_RTX)
1755 return false; 1786 return false;
1756 code = GET_CODE (x); 1787 code = GET_CODE (x);
1757 mode = GET_MODE (x); 1788 mode = GET_MODE (x);
1789
1758 if (code == SUBREG) 1790 if (code == SUBREG)
1759 { 1791 {
1792 /* For all SUBREGs we want to check whether the full multi-register
1793 overlaps the set. For normal SUBREGs this means 'get_hard_regno' of
1794 the inner register, for paradoxical SUBREGs this means the
1795 'get_hard_regno' of the full SUBREG and for complete SUBREGs either is
1796 fine. Use the wider mode for all cases. */
1797 rtx subreg = SUBREG_REG (x);
1760 mode = wider_subreg_mode (x); 1798 mode = wider_subreg_mode (x);
1761 x = SUBREG_REG (x); 1799 if (mode == GET_MODE (subreg))
1762 code = GET_CODE (x); 1800 {
1763 } 1801 x = subreg;
1764 1802 code = GET_CODE (x);
1765 if (REG_P (x)) 1803 }
1804 }
1805
1806 if (REG_P (x) || SUBREG_P (x))
1766 { 1807 {
1767 x_hard_regno = get_hard_regno (x, true); 1808 x_hard_regno = get_hard_regno (x, true);
1768 return (x_hard_regno >= 0 1809 return (x_hard_regno >= 0
1769 && overlaps_hard_reg_set_p (set, mode, x_hard_regno)); 1810 && overlaps_hard_reg_set_p (set, mode, x_hard_regno));
1770 } 1811 }
1827 machine_mode mode) 1868 machine_mode mode)
1828 { 1869 {
1829 HARD_REG_SET temp; 1870 HARD_REG_SET temp;
1830 1871
1831 lra_assert (hard_reg_set_subset_p (reg_class_contents[rclass], set)); 1872 lra_assert (hard_reg_set_subset_p (reg_class_contents[rclass], set));
1832 COPY_HARD_REG_SET (temp, set); 1873 temp = set & ~lra_no_alloc_regs;
1833 AND_COMPL_HARD_REG_SET (temp, lra_no_alloc_regs);
1834 return (hard_reg_set_subset_p 1874 return (hard_reg_set_subset_p
1835 (temp, ira_prohibited_class_mode_regs[rclass][mode])); 1875 (temp, ira_prohibited_class_mode_regs[rclass][mode]));
1836 } 1876 }
1837 1877
1838 1878
1839 /* Used to check validity info about small class input operands. It 1879 /* Used to check validity info about small class input operands. It
1840 should be incremented at start of processing an insn 1880 should be incremented at start of processing an insn
1841 alternative. */ 1881 alternative. */
1842 static unsigned int curr_small_class_check = 0; 1882 static unsigned int curr_small_class_check = 0;
1843 1883
1844 /* Update number of used inputs of class OP_CLASS for operand NOP. 1884 /* Update number of used inputs of class OP_CLASS for operand NOP
1845 Return true if we have more such class operands than the number of 1885 of alternative NALT. Return true if we have more such class operands
1846 available regs. */ 1886 than the number of available regs. */
1847 static bool 1887 static bool
1848 update_and_check_small_class_inputs (int nop, enum reg_class op_class) 1888 update_and_check_small_class_inputs (int nop, int nalt,
1889 enum reg_class op_class)
1849 { 1890 {
1850 static unsigned int small_class_check[LIM_REG_CLASSES]; 1891 static unsigned int small_class_check[LIM_REG_CLASSES];
1851 static int small_class_input_nums[LIM_REG_CLASSES]; 1892 static int small_class_input_nums[LIM_REG_CLASSES];
1852 1893
1853 if (SMALL_REGISTER_CLASS_P (op_class) 1894 if (SMALL_REGISTER_CLASS_P (op_class)
1854 /* We are interesting in classes became small because of fixing 1895 /* We are interesting in classes became small because of fixing
1855 some hard regs, e.g. by an user through GCC options. */ 1896 some hard regs, e.g. by an user through GCC options. */
1856 && hard_reg_set_intersect_p (reg_class_contents[op_class], 1897 && hard_reg_set_intersect_p (reg_class_contents[op_class],
1857 ira_no_alloc_regs) 1898 ira_no_alloc_regs)
1858 && (curr_static_id->operand[nop].type != OP_OUT 1899 && (curr_static_id->operand[nop].type != OP_OUT
1859 || curr_static_id->operand[nop].early_clobber)) 1900 || TEST_BIT (curr_static_id->operand[nop].early_clobber_alts, nalt)))
1860 { 1901 {
1861 if (small_class_check[op_class] == curr_small_class_check) 1902 if (small_class_check[op_class] == curr_small_class_check)
1862 small_class_input_nums[op_class]++; 1903 small_class_input_nums[op_class]++;
1863 else 1904 else
1864 { 1905 {
1872 } 1913 }
1873 1914
1874 /* Major function to choose the current insn alternative and what 1915 /* Major function to choose the current insn alternative and what
1875 operands should be reloaded and how. If ONLY_ALTERNATIVE is not 1916 operands should be reloaded and how. If ONLY_ALTERNATIVE is not
1876 negative we should consider only this alternative. Return false if 1917 negative we should consider only this alternative. Return false if
1877 we can not choose the alternative or find how to reload the 1918 we cannot choose the alternative or find how to reload the
1878 operands. */ 1919 operands. */
1879 static bool 1920 static bool
1880 process_alt_operands (int only_alternative) 1921 process_alt_operands (int only_alternative)
1881 { 1922 {
1882 bool ok_p = false; 1923 bool ok_p = false;
2123 *curr_id->operand_loc[m], m_hregno)) 2164 *curr_id->operand_loc[m], m_hregno))
2124 { 2165 {
2125 /* We should reject matching of an early 2166 /* We should reject matching of an early
2126 clobber operand if the matching operand is 2167 clobber operand if the matching operand is
2127 not dying in the insn. */ 2168 not dying in the insn. */
2128 if (! curr_static_id->operand[m].early_clobber 2169 if (!TEST_BIT (curr_static_id->operand[m]
2170 .early_clobber_alts, nalt)
2129 || operand_reg[nop] == NULL_RTX 2171 || operand_reg[nop] == NULL_RTX
2130 || (find_regno_note (curr_insn, REG_DEAD, 2172 || (find_regno_note (curr_insn, REG_DEAD,
2131 REGNO (op)) 2173 REGNO (op))
2132 || REGNO (op) == REGNO (operand_reg[m]))) 2174 || REGNO (op) == REGNO (operand_reg[m])))
2133 match_p = true; 2175 match_p = true;
2144 && curr_alt[m] == NO_REGS && ! curr_alt_win[m]) 2186 && curr_alt[m] == NO_REGS && ! curr_alt_win[m])
2145 continue; 2187 continue;
2146 } 2188 }
2147 else 2189 else
2148 { 2190 {
2149 /* Operands don't match. Both operands must 2191 /* If the operands do not match and one
2150 allow a reload register, otherwise we 2192 operand is INOUT, we can not match them.
2151 cannot make them match. */ 2193 Try other possibilities, e.g. other
2194 alternatives or commutative operand
2195 exchange. */
2196 if (curr_static_id->operand[nop].type == OP_INOUT
2197 || curr_static_id->operand[m].type == OP_INOUT)
2198 break;
2199 /* Operands don't match. If the operands are
2200 different user defined explicit hard
2201 registers, then we cannot make them match
2202 when one is early clobber operand. */
2203 if ((REG_P (*curr_id->operand_loc[nop])
2204 || SUBREG_P (*curr_id->operand_loc[nop]))
2205 && (REG_P (*curr_id->operand_loc[m])
2206 || SUBREG_P (*curr_id->operand_loc[m])))
2207 {
2208 rtx nop_reg = *curr_id->operand_loc[nop];
2209 if (SUBREG_P (nop_reg))
2210 nop_reg = SUBREG_REG (nop_reg);
2211 rtx m_reg = *curr_id->operand_loc[m];
2212 if (SUBREG_P (m_reg))
2213 m_reg = SUBREG_REG (m_reg);
2214
2215 if (REG_P (nop_reg)
2216 && HARD_REGISTER_P (nop_reg)
2217 && REG_USERVAR_P (nop_reg)
2218 && REG_P (m_reg)
2219 && HARD_REGISTER_P (m_reg)
2220 && REG_USERVAR_P (m_reg))
2221 {
2222 int i;
2223
2224 for (i = 0; i < early_clobbered_regs_num; i++)
2225 if (m == early_clobbered_nops[i])
2226 break;
2227 if (i < early_clobbered_regs_num
2228 || early_clobber_p)
2229 break;
2230 }
2231 }
2232 /* Both operands must allow a reload register,
2233 otherwise we cannot make them match. */
2152 if (curr_alt[m] == NO_REGS) 2234 if (curr_alt[m] == NO_REGS)
2153 break; 2235 break;
2154 /* Retroactively mark the operand we had to 2236 /* Retroactively mark the operand we had to
2155 match as a loser, if it wasn't already and 2237 match as a loser, if it wasn't already and
2156 it wasn't matched to a register constraint 2238 it wasn't matched to a register constraint
2167 2249
2168 /* Prefer matching earlyclobber alternative as 2250 /* Prefer matching earlyclobber alternative as
2169 it results in less hard regs required for 2251 it results in less hard regs required for
2170 the insn than a non-matching earlyclobber 2252 the insn than a non-matching earlyclobber
2171 alternative. */ 2253 alternative. */
2172 if (curr_static_id->operand[m].early_clobber) 2254 if (TEST_BIT (curr_static_id->operand[m]
2255 .early_clobber_alts, nalt))
2173 { 2256 {
2174 if (lra_dump_file != NULL) 2257 if (lra_dump_file != NULL)
2175 fprintf 2258 fprintf
2176 (lra_dump_file, 2259 (lra_dump_file,
2177 " %d Matching earlyclobber alt:" 2260 " %d Matching earlyclobber alt:"
2218 /* This can be fixed with reloads if the operand 2301 /* This can be fixed with reloads if the operand
2219 we are supposed to match can be fixed with 2302 we are supposed to match can be fixed with
2220 reloads. */ 2303 reloads. */
2221 badop = false; 2304 badop = false;
2222 this_alternative = curr_alt[m]; 2305 this_alternative = curr_alt[m];
2223 COPY_HARD_REG_SET (this_alternative_set, curr_alt_set[m]); 2306 this_alternative_set = curr_alt_set[m];
2224 winreg = this_alternative != NO_REGS; 2307 winreg = this_alternative != NO_REGS;
2225 break; 2308 break;
2226 } 2309 }
2227 2310
2228 case 'g': 2311 case 'g':
2300 break; 2383 break;
2301 } 2384 }
2302 break; 2385 break;
2303 2386
2304 reg: 2387 reg:
2388 if (mode == BLKmode)
2389 break;
2305 this_alternative = reg_class_subunion[this_alternative][cl]; 2390 this_alternative = reg_class_subunion[this_alternative][cl];
2306 IOR_HARD_REG_SET (this_alternative_set, 2391 this_alternative_set |= reg_class_contents[cl];
2307 reg_class_contents[cl]);
2308 if (costly_p) 2392 if (costly_p)
2309 { 2393 {
2310 this_costly_alternative 2394 this_costly_alternative
2311 = reg_class_subunion[this_costly_alternative][cl]; 2395 = reg_class_subunion[this_costly_alternative][cl];
2312 IOR_HARD_REG_SET (this_costly_alternative_set, 2396 this_costly_alternative_set |= reg_class_contents[cl];
2313 reg_class_contents[cl]);
2314 } 2397 }
2315 if (mode == BLKmode)
2316 break;
2317 winreg = true; 2398 winreg = true;
2318 if (REG_P (op)) 2399 if (REG_P (op))
2319 { 2400 {
2320 if (hard_regno[nop] >= 0 2401 if (hard_regno[nop] >= 0
2321 && in_hard_reg_set_p (this_alternative_set, 2402 && in_hard_reg_set_p (this_alternative_set,
2445 goto fail; 2526 goto fail;
2446 } 2527 }
2447 2528
2448 if (this_alternative != NO_REGS) 2529 if (this_alternative != NO_REGS)
2449 { 2530 {
2450 HARD_REG_SET available_regs; 2531 HARD_REG_SET available_regs
2451 2532 = (reg_class_contents[this_alternative]
2452 COPY_HARD_REG_SET (available_regs, 2533 & ~((ira_prohibited_class_mode_regs
2453 reg_class_contents[this_alternative]); 2534 [this_alternative][mode])
2454 AND_COMPL_HARD_REG_SET 2535 | lra_no_alloc_regs));
2455 (available_regs,
2456 ira_prohibited_class_mode_regs[this_alternative][mode]);
2457 AND_COMPL_HARD_REG_SET (available_regs, lra_no_alloc_regs);
2458 if (hard_reg_set_empty_p (available_regs)) 2536 if (hard_reg_set_empty_p (available_regs))
2459 { 2537 {
2460 /* There are no hard regs holding a value of given 2538 /* There are no hard regs holding a value of given
2461 mode. */ 2539 mode. */
2462 if (offmemok) 2540 if (offmemok)
2607 " alt=%d: No input/otput reload -- refuse\n", 2685 " alt=%d: No input/otput reload -- refuse\n",
2608 nalt); 2686 nalt);
2609 goto fail; 2687 goto fail;
2610 } 2688 }
2611 2689
2612 /* Alternative loses if it required class pseudo can not 2690 /* Alternative loses if it required class pseudo cannot
2613 hold value of required mode. Such insns can be 2691 hold value of required mode. Such insns can be
2614 described by insn definitions with mode iterators. */ 2692 described by insn definitions with mode iterators. */
2615 if (GET_MODE (*curr_id->operand_loc[nop]) != VOIDmode 2693 if (GET_MODE (*curr_id->operand_loc[nop]) != VOIDmode
2616 && ! hard_reg_set_empty_p (this_alternative_set) 2694 && ! hard_reg_set_empty_p (this_alternative_set)
2617 /* It is common practice for constraints to use a 2695 /* It is common practice for constraints to use a
2618 class which does not have actually enough regs to 2696 class which does not have actually enough regs to
2619 hold the value (e.g. x86 AREG for mode requiring 2697 hold the value (e.g. x86 AREG for mode requiring
2620 more one general reg). Therefore we have 2 2698 more one general reg). Therefore we have 2
2621 conditions to check that the reload pseudo can 2699 conditions to check that the reload pseudo cannot
2622 not hold the mode value. */ 2700 hold the mode value. */
2623 && (!targetm.hard_regno_mode_ok 2701 && (!targetm.hard_regno_mode_ok
2624 (ira_class_hard_regs[this_alternative][0], 2702 (ira_class_hard_regs[this_alternative][0],
2625 GET_MODE (*curr_id->operand_loc[nop]))) 2703 GET_MODE (*curr_id->operand_loc[nop])))
2626 /* The above condition is not enough as the first 2704 /* The above condition is not enough as the first
2627 reg in ira_class_hard_regs can be not aligned for 2705 reg in ira_class_hard_regs can be not aligned for
2631 GET_MODE (*curr_id->operand_loc[nop])))) 2709 GET_MODE (*curr_id->operand_loc[nop]))))
2632 { 2710 {
2633 if (lra_dump_file != NULL) 2711 if (lra_dump_file != NULL)
2634 fprintf (lra_dump_file, 2712 fprintf (lra_dump_file,
2635 " alt=%d: reload pseudo for op %d " 2713 " alt=%d: reload pseudo for op %d "
2636 " can not hold the mode value -- refuse\n", 2714 "cannot hold the mode value -- refuse\n",
2637 nalt, nop); 2715 nalt, nop);
2638 goto fail; 2716 goto fail;
2639 } 2717 }
2640 2718
2641 /* Check strong discouragement of reload of non-constant 2719 /* Check strong discouragement of reload of non-constant
2645 (op, this_alternative) == NO_REGS 2723 (op, this_alternative) == NO_REGS
2646 || (curr_static_id->operand[nop].type == OP_OUT 2724 || (curr_static_id->operand[nop].type == OP_OUT
2647 && (targetm.preferred_output_reload_class 2725 && (targetm.preferred_output_reload_class
2648 (op, this_alternative) == NO_REGS)))) 2726 (op, this_alternative) == NO_REGS))))
2649 { 2727 {
2650 if (lra_dump_file != NULL) 2728 if (offmemok && REG_P (op))
2651 fprintf (lra_dump_file, 2729 {
2652 " %d Non-prefered reload: reject+=%d\n", 2730 if (lra_dump_file != NULL)
2653 nop, LRA_MAX_REJECT); 2731 fprintf
2654 reject += LRA_MAX_REJECT; 2732 (lra_dump_file,
2733 " %d Spill pseudo into memory: reject+=3\n",
2734 nop);
2735 reject += 3;
2736 }
2737 else
2738 {
2739 if (lra_dump_file != NULL)
2740 fprintf
2741 (lra_dump_file,
2742 " %d Non-prefered reload: reject+=%d\n",
2743 nop, LRA_MAX_REJECT);
2744 reject += LRA_MAX_REJECT;
2745 }
2655 } 2746 }
2656 2747
2657 if (! (MEM_P (op) && offmemok) 2748 if (! (MEM_P (op) && offmemok)
2658 && ! (const_to_mem && constmemok)) 2749 && ! (const_to_mem && constmemok))
2659 { 2750 {
2756 || (curr_static_id->operand[nop].type != OP_IN 2847 || (curr_static_id->operand[nop].type != OP_IN
2757 && (targetm.secondary_memory_needed 2848 && (targetm.secondary_memory_needed
2758 (GET_MODE (op), this_alternative, cl))))) 2849 (GET_MODE (op), this_alternative, cl)))))
2759 losers++; 2850 losers++;
2760 2851
2761 /* Input reloads can be inherited more often than output
2762 reloads can be removed, so penalize output
2763 reloads. */
2764 if (!REG_P (op) || curr_static_id->operand[nop].type != OP_IN)
2765 {
2766 if (lra_dump_file != NULL)
2767 fprintf
2768 (lra_dump_file,
2769 " %d Non input pseudo reload: reject++\n",
2770 nop);
2771 reject++;
2772 }
2773
2774 if (MEM_P (op) && offmemok) 2852 if (MEM_P (op) && offmemok)
2775 addr_losers++; 2853 addr_losers++;
2776 else if (curr_static_id->operand[nop].type == OP_INOUT) 2854 else
2777 { 2855 {
2778 if (lra_dump_file != NULL) 2856 /* Input reloads can be inherited more often than
2779 fprintf 2857 output reloads can be removed, so penalize output
2780 (lra_dump_file, 2858 reloads. */
2781 " %d Input/Output reload: reject+=%d\n", 2859 if (!REG_P (op) || curr_static_id->operand[nop].type != OP_IN)
2782 nop, LRA_LOSER_COST_FACTOR); 2860 {
2783 reject += LRA_LOSER_COST_FACTOR; 2861 if (lra_dump_file != NULL)
2862 fprintf
2863 (lra_dump_file,
2864 " %d Non input pseudo reload: reject++\n",
2865 nop);
2866 reject++;
2867 }
2868
2869 if (curr_static_id->operand[nop].type == OP_INOUT)
2870 {
2871 if (lra_dump_file != NULL)
2872 fprintf
2873 (lra_dump_file,
2874 " %d Input/Output reload: reject+=%d\n",
2875 nop, LRA_LOSER_COST_FACTOR);
2876 reject += LRA_LOSER_COST_FACTOR;
2877 }
2784 } 2878 }
2785 } 2879 }
2786 2880
2787 if (early_clobber_p && ! scratch_p) 2881 if (early_clobber_p && ! scratch_p)
2788 { 2882 {
2805 " alt=%d,overall=%d,losers=%d -- refuse\n", 2899 " alt=%d,overall=%d,losers=%d -- refuse\n",
2806 nalt, overall, losers); 2900 nalt, overall, losers);
2807 goto fail; 2901 goto fail;
2808 } 2902 }
2809 2903
2810 if (update_and_check_small_class_inputs (nop, this_alternative)) 2904 if (update_and_check_small_class_inputs (nop, nalt,
2905 this_alternative))
2811 { 2906 {
2812 if (lra_dump_file != NULL) 2907 if (lra_dump_file != NULL)
2813 fprintf (lra_dump_file, 2908 fprintf (lra_dump_file,
2814 " alt=%d, not enough small class regs -- refuse\n", 2909 " alt=%d, not enough small class regs -- refuse\n",
2815 nalt); 2910 nalt);
2816 goto fail; 2911 goto fail;
2817 } 2912 }
2818 curr_alt[nop] = this_alternative; 2913 curr_alt[nop] = this_alternative;
2819 COPY_HARD_REG_SET (curr_alt_set[nop], this_alternative_set); 2914 curr_alt_set[nop] = this_alternative_set;
2820 curr_alt_win[nop] = this_alternative_win; 2915 curr_alt_win[nop] = this_alternative_win;
2821 curr_alt_match_win[nop] = this_alternative_match_win; 2916 curr_alt_match_win[nop] = this_alternative_match_win;
2822 curr_alt_offmemok[nop] = this_alternative_offmemok; 2917 curr_alt_offmemok[nop] = this_alternative_offmemok;
2823 curr_alt_matches[nop] = this_alternative_matches; 2918 curr_alt_matches[nop] = this_alternative_matches;
2824 2919
2908 && uses_hard_regs_p (*curr_id->operand_loc[j], temp_set)) 3003 && uses_hard_regs_p (*curr_id->operand_loc[j], temp_set))
2909 { 3004 {
2910 if (first_conflict_j < 0) 3005 if (first_conflict_j < 0)
2911 first_conflict_j = j; 3006 first_conflict_j = j;
2912 last_conflict_j = j; 3007 last_conflict_j = j;
3008 /* Both the earlyclobber operand and conflicting operand
3009 cannot both be user defined hard registers. */
3010 if (HARD_REGISTER_P (operand_reg[i])
3011 && REG_USERVAR_P (operand_reg[i])
3012 && operand_reg[j] != NULL_RTX
3013 && HARD_REGISTER_P (operand_reg[j])
3014 && REG_USERVAR_P (operand_reg[j]))
3015 fatal_insn ("unable to generate reloads for "
3016 "impossible constraints:", curr_insn);
2913 } 3017 }
2914 if (last_conflict_j < 0) 3018 if (last_conflict_j < 0)
2915 continue; 3019 continue;
2916 /* If earlyclobber operand conflicts with another 3020
2917 non-matching operand which is actually the same register 3021 /* If an earlyclobber operand conflicts with another non-matching
2918 as the earlyclobber operand, it is better to reload the 3022 operand (ie, they have been assigned the same hard register),
2919 another operand as an operand matching the earlyclobber 3023 then it is better to reload the other operand, as there may
2920 operand can be also the same. */ 3024 exist yet another operand with a matching constraint associated
2921 if (first_conflict_j == last_conflict_j 3025 with the earlyclobber operand. However, if one of the operands
2922 && operand_reg[last_conflict_j] != NULL_RTX 3026 is an explicit use of a hard register, then we must reload the
2923 && ! curr_alt_match_win[last_conflict_j] 3027 other non-hard register operand. */
2924 && REGNO (operand_reg[i]) == REGNO (operand_reg[last_conflict_j])) 3028 if (HARD_REGISTER_P (operand_reg[i])
3029 || (first_conflict_j == last_conflict_j
3030 && operand_reg[last_conflict_j] != NULL_RTX
3031 && !curr_alt_match_win[last_conflict_j]
3032 && !HARD_REGISTER_P (operand_reg[last_conflict_j])))
2925 { 3033 {
2926 curr_alt_win[last_conflict_j] = false; 3034 curr_alt_win[last_conflict_j] = false;
2927 curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++] 3035 curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++]
2928 = last_conflict_j; 3036 = last_conflict_j;
2929 losers++; 3037 losers++;
3316 3424
3317 4) the address is a frame address with an invalid base. 3425 4) the address is a frame address with an invalid base.
3318 3426
3319 All these cases involve a non-autoinc address, so there is no 3427 All these cases involve a non-autoinc address, so there is no
3320 point revalidating other types. */ 3428 point revalidating other types. */
3321 if (ad.autoinc_p || valid_address_p (&ad)) 3429 if (ad.autoinc_p || valid_address_p (op, &ad, cn))
3322 return change_p; 3430 return change_p;
3323 3431
3324 /* Any index existed before LRA started, so we can assume that the 3432 /* Any index existed before LRA started, so we can assume that the
3325 presence and shape of the index is valid. */ 3433 presence and shape of the index is valid. */
3326 push_to_sequence (*before); 3434 push_to_sequence (*before);
3345 gen_rtx_HIGH (Pmode, copy_rtx (addr)))); 3453 gen_rtx_HIGH (Pmode, copy_rtx (addr))));
3346 code = recog_memoized (insn); 3454 code = recog_memoized (insn);
3347 if (code >= 0) 3455 if (code >= 0)
3348 { 3456 {
3349 *ad.inner = gen_rtx_LO_SUM (Pmode, new_reg, addr); 3457 *ad.inner = gen_rtx_LO_SUM (Pmode, new_reg, addr);
3350 if (! valid_address_p (ad.mode, *ad.outer, ad.as)) 3458 if (!valid_address_p (op, &ad, cn))
3351 { 3459 {
3352 /* Try to put lo_sum into register. */ 3460 /* Try to put lo_sum into register. */
3353 insn = emit_insn (gen_rtx_SET 3461 insn = emit_insn (gen_rtx_SET
3354 (new_reg, 3462 (new_reg,
3355 gen_rtx_LO_SUM (Pmode, new_reg, addr))); 3463 gen_rtx_LO_SUM (Pmode, new_reg, addr)));
3356 code = recog_memoized (insn); 3464 code = recog_memoized (insn);
3357 if (code >= 0) 3465 if (code >= 0)
3358 { 3466 {
3359 *ad.inner = new_reg; 3467 *ad.inner = new_reg;
3360 if (! valid_address_p (ad.mode, *ad.outer, ad.as)) 3468 if (!valid_address_p (op, &ad, cn))
3361 { 3469 {
3362 *ad.inner = addr; 3470 *ad.inner = addr;
3363 code = -1; 3471 code = -1;
3364 } 3472 }
3365 } 3473 }
3450 && GET_CODE (SET_SRC (set)) == PLUS 3558 && GET_CODE (SET_SRC (set)) == PLUS
3451 && REG_P (XEXP (SET_SRC (set), 0)) 3559 && REG_P (XEXP (SET_SRC (set), 0))
3452 && CONSTANT_P (XEXP (SET_SRC (set), 1))) 3560 && CONSTANT_P (XEXP (SET_SRC (set), 1)))
3453 { 3561 {
3454 *ad.inner = SET_SRC (set); 3562 *ad.inner = SET_SRC (set);
3455 if (valid_address_p (ad.mode, *ad.outer, ad.as)) 3563 if (valid_address_p (op, &ad, cn))
3456 { 3564 {
3457 *ad.base_term = XEXP (SET_SRC (set), 0); 3565 *ad.base_term = XEXP (SET_SRC (set), 0);
3458 *ad.disp_term = XEXP (SET_SRC (set), 1); 3566 *ad.disp_term = XEXP (SET_SRC (set), 1);
3459 cl = base_reg_class (ad.mode, ad.as, ad.base_outer_code, 3567 cl = base_reg_class (ad.mode, ad.as, ad.base_outer_code,
3460 get_index_code (&ad)); 3568 get_index_code (&ad));
3896 /* No alternative works with reloads?? */ 4004 /* No alternative works with reloads?? */
3897 if (INSN_CODE (curr_insn) >= 0) 4005 if (INSN_CODE (curr_insn) >= 0)
3898 fatal_insn ("unable to generate reloads for:", curr_insn); 4006 fatal_insn ("unable to generate reloads for:", curr_insn);
3899 error_for_asm (curr_insn, 4007 error_for_asm (curr_insn,
3900 "inconsistent operand constraints in an %<asm%>"); 4008 "inconsistent operand constraints in an %<asm%>");
4009 lra_asm_error_p = true;
3901 /* Avoid further trouble with this insn. Don't generate use 4010 /* Avoid further trouble with this insn. Don't generate use
3902 pattern here as we could use the insn SP offset. */ 4011 pattern here as we could use the insn SP offset. */
3903 lra_set_insn_deleted (curr_insn); 4012 lra_set_insn_deleted (curr_insn);
3904 return true; 4013 return true;
3905 } 4014 }
3963 /* If the mode is changed, it should be wider. */ 4072 /* If the mode is changed, it should be wider. */
3964 lra_assert (!partial_subreg_p (sec_mode, rld_mode)); 4073 lra_assert (!partial_subreg_p (sec_mode, rld_mode));
3965 if (sec_mode != rld_mode) 4074 if (sec_mode != rld_mode)
3966 { 4075 {
3967 /* If the target says specifically to use another mode for 4076 /* If the target says specifically to use another mode for
3968 secondary memory moves we can not reuse the original 4077 secondary memory moves we cannot reuse the original
3969 insn. */ 4078 insn. */
3970 after = emit_spill_move (false, new_reg, dest); 4079 after = emit_spill_move (false, new_reg, dest);
3971 lra_process_new_insns (curr_insn, NULL, after, 4080 lra_process_new_insns (curr_insn, NULL, after,
3972 "Inserting the sec. move"); 4081 "Inserting the sec. move");
3973 /* We may have non null BEFORE here (e.g. after address 4082 /* We may have non null BEFORE here (e.g. after address
4189 || GET_CODE (SET_SRC (curr_insn_set)) == SUBREG) 4298 || GET_CODE (SET_SRC (curr_insn_set)) == SUBREG)
4190 && (REG_P (SET_DEST (curr_insn_set)) 4299 && (REG_P (SET_DEST (curr_insn_set))
4191 || MEM_P (SET_DEST (curr_insn_set)) 4300 || MEM_P (SET_DEST (curr_insn_set))
4192 || GET_CODE (SET_DEST (curr_insn_set)) == SUBREG)))) 4301 || GET_CODE (SET_DEST (curr_insn_set)) == SUBREG))))
4193 optional_p = true; 4302 optional_p = true;
4303 else if (goal_alt_matched[i][0] != -1
4304 && curr_static_id->operand[i].type == OP_OUT
4305 && (curr_static_id->operand_alternative
4306 [goal_alt_number * n_operands + i].earlyclobber)
4307 && REG_P (op))
4308 {
4309 for (j = 0; goal_alt_matched[i][j] != -1; j++)
4310 {
4311 rtx op2 = *curr_id->operand_loc[goal_alt_matched[i][j]];
4312
4313 if (REG_P (op2) && REGNO (op) != REGNO (op2))
4314 break;
4315 }
4316 if (goal_alt_matched[i][j] != -1)
4317 {
4318 /* Generate reloads for different output and matched
4319 input registers. This is the easiest way to avoid
4320 creation of non-existing register conflicts in
4321 lra-lives.c. */
4322 match_reload (i, goal_alt_matched[i], outputs, goal_alt[i], &before,
4323 &after, TRUE);
4324 outputs[n_outputs++] = i;
4325 outputs[n_outputs] = -1;
4326 }
4327 continue;
4328 }
4194 else 4329 else
4195 continue; 4330 continue;
4196 } 4331 }
4197 4332
4198 /* Operands that match previous ones have already been handled. */ 4333 /* Operands that match previous ones have already been handled. */
4446 { 4581 {
4447 if (regno >= FIRST_PSEUDO_REGISTER) 4582 if (regno >= FIRST_PSEUDO_REGISTER)
4448 regno = lra_get_regno_hard_regno (regno); 4583 regno = lra_get_regno_hard_regno (regno);
4449 if (regno < 0) 4584 if (regno < 0)
4450 return false; 4585 return false;
4451 COMPL_HARD_REG_SET (alloc_regs, lra_no_alloc_regs); 4586 alloc_regs = ~lra_no_alloc_regs;
4452 return overlaps_hard_reg_set_p (alloc_regs, GET_MODE (x), regno); 4587 return overlaps_hard_reg_set_p (alloc_regs, GET_MODE (x), regno);
4453 } 4588 }
4454 else 4589 else
4455 { 4590 {
4456 if (regno < FIRST_PSEUDO_REGISTER) 4591 if (regno < FIRST_PSEUDO_REGISTER)
4544 #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS 4679 #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS
4545 4680
4546 /* The current iteration number of this LRA pass. */ 4681 /* The current iteration number of this LRA pass. */
4547 int lra_constraint_iter; 4682 int lra_constraint_iter;
4548 4683
4549 /* True if we substituted equiv which needs checking register 4684 /* True if we should during assignment sub-pass check assignment
4550 allocation correctness because the equivalent value contains 4685 correctness for all pseudos and spill some of them to correct
4551 allocatable hard registers or when we restore multi-register 4686 conflicts. It can be necessary when we substitute equiv which
4552 pseudo. */ 4687 needs checking register allocation correctness because the
4553 bool lra_risky_transformations_p; 4688 equivalent value contains allocatable hard registers, or when we
4689 restore multi-register pseudo, or when we change the insn code and
4690 its operand became INOUT operand when it was IN one before. */
4691 bool check_and_force_assignment_correctness_p;
4554 4692
4555 /* Return true if REGNO is referenced in more than one block. */ 4693 /* Return true if REGNO is referenced in more than one block. */
4556 static bool 4694 static bool
4557 multi_block_pseudo_p (int regno) 4695 multi_block_pseudo_p (int regno)
4558 { 4696 {
4690 fprintf (lra_dump_file, "\n********** Local #%d: **********\n\n", 4828 fprintf (lra_dump_file, "\n********** Local #%d: **********\n\n",
4691 lra_constraint_iter); 4829 lra_constraint_iter);
4692 changed_p = false; 4830 changed_p = false;
4693 if (pic_offset_table_rtx 4831 if (pic_offset_table_rtx
4694 && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER) 4832 && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
4695 lra_risky_transformations_p = true; 4833 check_and_force_assignment_correctness_p = true;
4696 else 4834 else if (first_p)
4697 /* On the first iteration we should check IRA assignment 4835 /* On the first iteration we should check IRA assignment
4698 correctness. In rare cases, the assignments can be wrong as 4836 correctness. In rare cases, the assignments can be wrong as
4699 early clobbers operands are ignored in IRA. */ 4837 early clobbers operands are ignored in IRA or usages of
4700 lra_risky_transformations_p = first_p; 4838 paradoxical sub-registers are not taken into account by
4839 IRA. */
4840 check_and_force_assignment_correctness_p = true;
4701 new_insn_uid_start = get_max_uid (); 4841 new_insn_uid_start = get_max_uid ();
4702 new_regno_start = first_p ? lra_constraint_new_regno_start : max_reg_num (); 4842 new_regno_start = first_p ? lra_constraint_new_regno_start : max_reg_num ();
4703 /* Mark used hard regs for target stack size calulations. */ 4843 /* Mark used hard regs for target stack size calulations. */
4704 for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++) 4844 for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
4705 if (lra_reg_info[i].nrefs != 0 4845 if (lra_reg_info[i].nrefs != 0
4722 reg = regno_reg_rtx[i]; 4862 reg = regno_reg_rtx[i];
4723 if (lra_get_regno_hard_regno (i) < 0 && (x = get_equiv (reg)) != reg) 4863 if (lra_get_regno_hard_regno (i) < 0 && (x = get_equiv (reg)) != reg)
4724 { 4864 {
4725 bool pseudo_p = contains_reg_p (x, false, false); 4865 bool pseudo_p = contains_reg_p (x, false, false);
4726 4866
4727 /* After RTL transformation, we can not guarantee that 4867 /* After RTL transformation, we cannot guarantee that
4728 pseudo in the substitution was not reloaded which might 4868 pseudo in the substitution was not reloaded which might
4729 make equivalence invalid. For example, in reverse 4869 make equivalence invalid. For example, in reverse
4730 equiv of p0 4870 equiv of p0
4731 4871
4732 p0 <- ... 4872 p0 <- ...
4755 constant, the right hand side of the init insn can 4895 constant, the right hand side of the init insn can
4756 be a pseudo. */ 4896 be a pseudo. */
4757 || (! reverse_equiv_p (i) 4897 || (! reverse_equiv_p (i)
4758 && (init_insn_rhs_dead_pseudo_p (i) 4898 && (init_insn_rhs_dead_pseudo_p (i)
4759 /* If we reloaded the pseudo in an equivalence 4899 /* If we reloaded the pseudo in an equivalence
4760 init insn, we can not remove the equiv init 4900 init insn, we cannot remove the equiv init
4761 insns and the init insns might write into 4901 insns and the init insns might write into
4762 const memory in this case. */ 4902 const memory in this case. */
4763 || contains_reloaded_insn_p (i))) 4903 || contains_reloaded_insn_p (i)))
4764 /* Prevent access beyond equivalent memory for 4904 /* Prevent access beyond equivalent memory for
4765 paradoxical subregs. */ 4905 paradoxical subregs. */
4803 min_len = new_min_len; 4943 min_len = new_min_len;
4804 new_insns_num = 0; 4944 new_insns_num = 0;
4805 } 4945 }
4806 if (new_insns_num > MAX_RELOAD_INSNS_NUMBER) 4946 if (new_insns_num > MAX_RELOAD_INSNS_NUMBER)
4807 internal_error 4947 internal_error
4808 ("Max. number of generated reload insns per insn is achieved (%d)\n", 4948 ("maximum number of generated reload insns per insn achieved (%d)",
4809 MAX_RELOAD_INSNS_NUMBER); 4949 MAX_RELOAD_INSNS_NUMBER);
4810 new_insns_num++; 4950 new_insns_num++;
4811 if (DEBUG_INSN_P (curr_insn)) 4951 if (DEBUG_INSN_P (curr_insn))
4812 { 4952 {
4813 /* We need to check equivalence in debug insn and change 4953 /* We need to check equivalence in debug insn and change
4837 if (GET_CODE (dest_reg) == SUBREG) 4977 if (GET_CODE (dest_reg) == SUBREG)
4838 dest_reg = SUBREG_REG (dest_reg); 4978 dest_reg = SUBREG_REG (dest_reg);
4839 if ((REG_P (dest_reg) 4979 if ((REG_P (dest_reg)
4840 && (x = get_equiv (dest_reg)) != dest_reg 4980 && (x = get_equiv (dest_reg)) != dest_reg
4841 /* Remove insns which set up a pseudo whose value 4981 /* Remove insns which set up a pseudo whose value
4842 can not be changed. Such insns might be not in 4982 cannot be changed. Such insns might be not in
4843 init_insns because we don't update equiv data 4983 init_insns because we don't update equiv data
4844 during insn transformations. 4984 during insn transformations.
4845 4985
4846 As an example, let suppose that a pseudo got 4986 As an example, let suppose that a pseudo got
4847 hard register and on the 1st pass was not 4987 hard register and on the 1st pass was not
4871 INSN_UID (curr_insn), 5011 INSN_UID (curr_insn),
4872 REG_FREQ_FROM_BB (BLOCK_FOR_INSN (curr_insn))); 5012 REG_FREQ_FROM_BB (BLOCK_FOR_INSN (curr_insn)));
4873 dump_insn_slim (lra_dump_file, curr_insn); 5013 dump_insn_slim (lra_dump_file, curr_insn);
4874 } 5014 }
4875 if (contains_reg_p (x, true, false)) 5015 if (contains_reg_p (x, true, false))
4876 lra_risky_transformations_p = true; 5016 check_and_force_assignment_correctness_p = true;
4877 lra_set_insn_deleted (curr_insn); 5017 lra_set_insn_deleted (curr_insn);
4878 continue; 5018 continue;
4879 } 5019 }
4880 } 5020 }
4881 curr_id = lra_get_insn_recog_data (curr_insn); 5021 curr_id = lra_get_insn_recog_data (curr_insn);
5035 /* Number of reloads passed so far in current EBB. */ 5175 /* Number of reloads passed so far in current EBB. */
5036 static int reloads_num; 5176 static int reloads_num;
5037 5177
5038 /* Number of calls passed so far in current EBB. */ 5178 /* Number of calls passed so far in current EBB. */
5039 static int calls_num; 5179 static int calls_num;
5180
5181 /* Index ID is the CALLS_NUM associated the last call we saw with
5182 ABI identifier ID. */
5183 static int last_call_for_abi[NUM_ABI_IDS];
5184
5185 /* Which registers have been fully or partially clobbered by a call
5186 since they were last used. */
5187 static HARD_REG_SET full_and_partial_call_clobbers;
5040 5188
5041 /* Current reload pseudo check for validity of elements in 5189 /* Current reload pseudo check for validity of elements in
5042 USAGE_INSNS. */ 5190 USAGE_INSNS. */
5043 static int curr_usage_insns_check; 5191 static int curr_usage_insns_check;
5044 5192
5079 usage_insns[regno].check = curr_usage_insns_check; 5227 usage_insns[regno].check = curr_usage_insns_check;
5080 usage_insns[regno].insns = insn; 5228 usage_insns[regno].insns = insn;
5081 usage_insns[regno].reloads_num = reloads_num; 5229 usage_insns[regno].reloads_num = reloads_num;
5082 usage_insns[regno].calls_num = calls_num; 5230 usage_insns[regno].calls_num = calls_num;
5083 usage_insns[regno].after_p = after_p; 5231 usage_insns[regno].after_p = after_p;
5232 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0)
5233 remove_from_hard_reg_set (&full_and_partial_call_clobbers,
5234 PSEUDO_REGNO_MODE (regno),
5235 reg_renumber[regno]);
5084 } 5236 }
5085 5237
5086 /* The function is used to form list REGNO usages which consists of 5238 /* The function is used to form list REGNO usages which consists of
5087 optional debug insns finished by a non-debug insn using REGNO. 5239 optional debug insns finished by a non-debug insn using REGNO.
5088 RELOADS_NUM is current number of reload insns processed so far. */ 5240 RELOADS_NUM is current number of reload insns processed so far. */
5150 5302
5151 /* Registers involved in inheritance/split in the current EBB 5303 /* Registers involved in inheritance/split in the current EBB
5152 (inheritance/split pseudos and original registers). */ 5304 (inheritance/split pseudos and original registers). */
5153 static bitmap_head check_only_regs; 5305 static bitmap_head check_only_regs;
5154 5306
5155 /* Reload pseudos can not be involded in invariant inheritance in the 5307 /* Reload pseudos cannot be involded in invariant inheritance in the
5156 current EBB. */ 5308 current EBB. */
5157 static bitmap_head invalid_invariant_regs; 5309 static bitmap_head invalid_invariant_regs;
5158 5310
5159 /* Do inheritance transformations for insn INSN, which defines (if 5311 /* Do inheritance transformations for insn INSN, which defines (if
5160 DEF_P) or uses ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which 5312 DEF_P) or uses ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which
5324 was assigned to a hard register. */ 5476 was assigned to a hard register. */
5325 static inline bool 5477 static inline bool
5326 need_for_call_save_p (int regno) 5478 need_for_call_save_p (int regno)
5327 { 5479 {
5328 lra_assert (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0); 5480 lra_assert (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0);
5329 return (usage_insns[regno].calls_num < calls_num 5481 if (usage_insns[regno].calls_num < calls_num)
5330 && (overlaps_hard_reg_set_p 5482 {
5331 ((flag_ipa_ra && 5483 unsigned int abis = 0;
5332 ! hard_reg_set_empty_p (lra_reg_info[regno].actual_call_used_reg_set)) 5484 for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
5333 ? lra_reg_info[regno].actual_call_used_reg_set 5485 if (last_call_for_abi[i] > usage_insns[regno].calls_num)
5334 : call_used_reg_set, 5486 abis |= 1 << i;
5335 PSEUDO_REGNO_MODE (regno), reg_renumber[regno]) 5487 gcc_assert (abis);
5336 || (targetm.hard_regno_call_part_clobbered 5488 if (call_clobbered_in_region_p (abis, full_and_partial_call_clobbers,
5337 (reg_renumber[regno], PSEUDO_REGNO_MODE (regno))))); 5489 PSEUDO_REGNO_MODE (regno),
5490 reg_renumber[regno]))
5491 return true;
5492 }
5493 return false;
5338 } 5494 }
5339 5495
5340 /* Global registers occurring in the current EBB. */ 5496 /* Global registers occurring in the current EBB. */
5341 static bitmap_head ebb_global_regs; 5497 static bitmap_head ebb_global_regs;
5342 5498
5368 || ! TEST_HARD_REG_BIT (eliminable_regset, hard_regno)) 5524 || ! TEST_HARD_REG_BIT (eliminable_regset, hard_regno))
5369 && ! TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno) 5525 && ! TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno)
5370 /* Don't split call clobbered hard regs living through 5526 /* Don't split call clobbered hard regs living through
5371 calls, otherwise we might have a check problem in the 5527 calls, otherwise we might have a check problem in the
5372 assign sub-pass as in the most cases (exception is a 5528 assign sub-pass as in the most cases (exception is a
5373 situation when lra_risky_transformations_p value is 5529 situation when check_and_force_assignment_correctness_p value is
5374 true) the assign pass assumes that all pseudos living 5530 true) the assign pass assumes that all pseudos living
5375 through calls are assigned to call saved hard regs. */ 5531 through calls are assigned to call saved hard regs. */
5376 && (regno >= FIRST_PSEUDO_REGISTER 5532 && (regno >= FIRST_PSEUDO_REGISTER
5377 || ! TEST_HARD_REG_BIT (call_used_reg_set, regno) 5533 || !TEST_HARD_REG_BIT (full_and_partial_call_clobbers, regno))
5378 || usage_insns[regno].calls_num == calls_num)
5379 /* We need at least 2 reloads to make pseudo splitting 5534 /* We need at least 2 reloads to make pseudo splitting
5380 profitable. We should provide hard regno splitting in 5535 profitable. We should provide hard regno splitting in
5381 any case to solve 1st insn scheduling problem when 5536 any case to solve 1st insn scheduling problem when
5382 moving hard register definition up might result in 5537 moving hard register definition up might result in
5383 impossibility to find hard register for reload pseudo of 5538 impossibility to find hard register for reload pseudo of
5452 5607
5453 /* Do split transformations for insn INSN, which defines or uses 5608 /* Do split transformations for insn INSN, which defines or uses
5454 ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which instruction in 5609 ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which instruction in
5455 the EBB next uses ORIGINAL_REGNO; it has the same form as the 5610 the EBB next uses ORIGINAL_REGNO; it has the same form as the
5456 "insns" field of usage_insns. If TO is not NULL, we don't use 5611 "insns" field of usage_insns. If TO is not NULL, we don't use
5457 usage_insns, we put restore insns after TO insn. 5612 usage_insns, we put restore insns after TO insn. It is a case when
5613 we call it from lra_split_hard_reg_for, outside the inheritance
5614 pass.
5458 5615
5459 The transformations look like: 5616 The transformations look like:
5460 5617
5461 p <- ... p <- ... 5618 p <- ... p <- ...
5462 ... s <- p (new insn -- save) 5619 ... s <- p (new insn -- save)
5608 rematerializing the original value instead of spilling to the stack. */ 5765 rematerializing the original value instead of spilling to the stack. */
5609 if (!HARD_REGISTER_NUM_P (original_regno) 5766 if (!HARD_REGISTER_NUM_P (original_regno)
5610 && mode == PSEUDO_REGNO_MODE (original_regno)) 5767 && mode == PSEUDO_REGNO_MODE (original_regno))
5611 lra_copy_reg_equiv (new_regno, original_regno); 5768 lra_copy_reg_equiv (new_regno, original_regno);
5612 lra_reg_info[new_regno].restore_rtx = regno_reg_rtx[original_regno]; 5769 lra_reg_info[new_regno].restore_rtx = regno_reg_rtx[original_regno];
5613 bitmap_set_bit (&check_only_regs, new_regno);
5614 bitmap_set_bit (&check_only_regs, original_regno);
5615 bitmap_set_bit (&lra_split_regs, new_regno); 5770 bitmap_set_bit (&lra_split_regs, new_regno);
5616 if (to != NULL) 5771 if (to != NULL)
5617 { 5772 {
5773 lra_assert (next_usage_insns == NULL);
5618 usage_insn = to; 5774 usage_insn = to;
5619 after_p = TRUE; 5775 after_p = TRUE;
5620 } 5776 }
5621 else 5777 else
5622 { 5778 {
5779 /* We need check_only_regs only inside the inheritance pass. */
5780 bitmap_set_bit (&check_only_regs, new_regno);
5781 bitmap_set_bit (&check_only_regs, original_regno);
5623 after_p = usage_insns[original_regno].after_p; 5782 after_p = usage_insns[original_regno].after_p;
5624 for (;;) 5783 for (;;)
5625 { 5784 {
5626 if (GET_CODE (next_usage_insns) != INSN_LIST) 5785 if (GET_CODE (next_usage_insns) != INSN_LIST)
5627 { 5786 {
5657 /* If we are trying to split multi-register. We should check 5816 /* If we are trying to split multi-register. We should check
5658 conflicts on the next assignment sub-pass. IRA can allocate on 5817 conflicts on the next assignment sub-pass. IRA can allocate on
5659 sub-register levels, LRA do this on pseudos level right now and 5818 sub-register levels, LRA do this on pseudos level right now and
5660 this discrepancy may create allocation conflicts after 5819 this discrepancy may create allocation conflicts after
5661 splitting. */ 5820 splitting. */
5662 lra_risky_transformations_p = true; 5821 check_and_force_assignment_correctness_p = true;
5663 if (lra_dump_file != NULL) 5822 if (lra_dump_file != NULL)
5664 fprintf (lra_dump_file, 5823 fprintf (lra_dump_file,
5665 " ))))))))))))))))))))))))))))))))))))))))))))))))\n"); 5824 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5666 return true; 5825 return true;
5667 } 5826 }
5764 { 5923 {
5765 machine_mode mode; 5924 machine_mode mode;
5766 const char *fmt; 5925 const char *fmt;
5767 enum rtx_code code; 5926 enum rtx_code code;
5768 int i, j; 5927 int i, j;
5928
5929 if (side_effects_p (x))
5930 return false;
5769 5931
5770 code = GET_CODE (x); 5932 code = GET_CODE (x);
5771 mode = GET_MODE (x); 5933 mode = GET_MODE (x);
5772 if (code == SUBREG) 5934 if (code == SUBREG)
5773 { 5935 {
6118 6280
6119 change_p = false; 6281 change_p = false;
6120 curr_usage_insns_check++; 6282 curr_usage_insns_check++;
6121 clear_invariants (); 6283 clear_invariants ();
6122 reloads_num = calls_num = 0; 6284 reloads_num = calls_num = 0;
6285 for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
6286 last_call_for_abi[i] = 0;
6287 CLEAR_HARD_REG_SET (full_and_partial_call_clobbers);
6123 bitmap_clear (&check_only_regs); 6288 bitmap_clear (&check_only_regs);
6124 bitmap_clear (&invalid_invariant_regs); 6289 bitmap_clear (&invalid_invariant_regs);
6125 last_processed_bb = NULL; 6290 last_processed_bb = NULL;
6126 CLEAR_HARD_REG_SET (potential_reload_hard_regs); 6291 CLEAR_HARD_REG_SET (potential_reload_hard_regs);
6127 COPY_HARD_REG_SET (live_hard_regs, eliminable_regset); 6292 live_hard_regs = eliminable_regset | lra_no_alloc_regs;
6128 IOR_HARD_REG_SET (live_hard_regs, lra_no_alloc_regs);
6129 /* We don't process new insns generated in the loop. */ 6293 /* We don't process new insns generated in the loop. */
6130 for (curr_insn = tail; curr_insn != PREV_INSN (head); curr_insn = prev_insn) 6294 for (curr_insn = tail; curr_insn != PREV_INSN (head); curr_insn = prev_insn)
6131 { 6295 {
6132 prev_insn = PREV_INSN (curr_insn); 6296 prev_insn = PREV_INSN (curr_insn);
6133 if (BLOCK_FOR_INSN (curr_insn) != NULL) 6297 if (BLOCK_FOR_INSN (curr_insn) != NULL)
6193 if (succ_p) 6357 if (succ_p)
6194 change_p = true; 6358 change_p = true;
6195 else 6359 else
6196 setup_next_usage_insn (src_regno, curr_insn, reloads_num, false); 6360 setup_next_usage_insn (src_regno, curr_insn, reloads_num, false);
6197 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs)) 6361 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
6198 IOR_HARD_REG_SET (potential_reload_hard_regs, 6362 potential_reload_hard_regs |= reg_class_contents[cl];
6199 reg_class_contents[cl]);
6200 } 6363 }
6201 else if (src_regno < 0 6364 else if (src_regno < 0
6202 && dst_regno >= lra_constraint_new_regno_start 6365 && dst_regno >= lra_constraint_new_regno_start
6203 && invariant_p (SET_SRC (curr_set)) 6366 && invariant_p (SET_SRC (curr_set))
6204 && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS 6367 && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS
6211 reloads_num++; 6374 reloads_num++;
6212 update_reloads_num_p = false; 6375 update_reloads_num_p = false;
6213 if (process_invariant_for_inheritance (SET_DEST (curr_set), SET_SRC (curr_set))) 6376 if (process_invariant_for_inheritance (SET_DEST (curr_set), SET_SRC (curr_set)))
6214 change_p = true; 6377 change_p = true;
6215 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs)) 6378 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
6216 IOR_HARD_REG_SET (potential_reload_hard_regs, 6379 potential_reload_hard_regs |= reg_class_contents[cl];
6217 reg_class_contents[cl]);
6218 } 6380 }
6219 else if (src_regno >= lra_constraint_new_regno_start 6381 else if (src_regno >= lra_constraint_new_regno_start
6220 && dst_regno < lra_constraint_new_regno_start 6382 && dst_regno < lra_constraint_new_regno_start
6221 && dst_regno >= FIRST_PSEUDO_REGISTER 6383 && dst_regno >= FIRST_PSEUDO_REGISTER
6222 && reg_renumber[dst_regno] < 0 6384 && reg_renumber[dst_regno] < 0
6234 curr_insn, next_usage_insns)) 6396 curr_insn, next_usage_insns))
6235 change_p = true; 6397 change_p = true;
6236 /* Invalidate. */ 6398 /* Invalidate. */
6237 usage_insns[dst_regno].check = 0; 6399 usage_insns[dst_regno].check = 0;
6238 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs)) 6400 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
6239 IOR_HARD_REG_SET (potential_reload_hard_regs, 6401 potential_reload_hard_regs |= reg_class_contents[cl];
6240 reg_class_contents[cl]);
6241 } 6402 }
6242 else if (INSN_P (curr_insn)) 6403 else if (INSN_P (curr_insn))
6243 { 6404 {
6244 int iter; 6405 int iter;
6245 int max_uid = get_max_uid (); 6406 int max_uid = get_max_uid ();
6267 if (r->type != OP_OUT && r->regno == dst_regno) 6428 if (r->type != OP_OUT && r->regno == dst_regno)
6268 break; 6429 break;
6269 /* Don't do inheritance if the pseudo is also 6430 /* Don't do inheritance if the pseudo is also
6270 used in the insn. */ 6431 used in the insn. */
6271 if (r == NULL) 6432 if (r == NULL)
6272 /* We can not do inheritance right now 6433 /* We cannot do inheritance right now
6273 because the current insn reg info (chain 6434 because the current insn reg info (chain
6274 regs) can change after that. */ 6435 regs) can change after that. */
6275 add_to_inherit (dst_regno, next_usage_insns); 6436 add_to_inherit (dst_regno, next_usage_insns);
6276 } 6437 }
6277 /* We can not process one reg twice here because of 6438 /* We cannot process one reg twice here because of
6278 usage_insns invalidation. */ 6439 usage_insns invalidation. */
6279 if ((dst_regno < FIRST_PSEUDO_REGISTER 6440 if ((dst_regno < FIRST_PSEUDO_REGISTER
6280 || reg_renumber[dst_regno] >= 0) 6441 || reg_renumber[dst_regno] >= 0)
6281 && ! reg->subreg_p && reg->type != OP_IN) 6442 && ! reg->subreg_p && reg->type != OP_IN)
6282 { 6443 {
6290 if (dst_regno < FIRST_PSEUDO_REGISTER) 6451 if (dst_regno < FIRST_PSEUDO_REGISTER)
6291 add_to_hard_reg_set (&s, reg->biggest_mode, dst_regno); 6452 add_to_hard_reg_set (&s, reg->biggest_mode, dst_regno);
6292 else 6453 else
6293 add_to_hard_reg_set (&s, PSEUDO_REGNO_MODE (dst_regno), 6454 add_to_hard_reg_set (&s, PSEUDO_REGNO_MODE (dst_regno),
6294 reg_renumber[dst_regno]); 6455 reg_renumber[dst_regno]);
6295 AND_COMPL_HARD_REG_SET (live_hard_regs, s); 6456 live_hard_regs &= ~s;
6457 potential_reload_hard_regs &= ~s;
6296 } 6458 }
6297 /* We should invalidate potential inheritance or 6459 /* We should invalidate potential inheritance or
6298 splitting for the current insn usages to the next 6460 splitting for the current insn usages to the next
6299 usage insns (see code below) as the output pseudo 6461 usage insns (see code below) as the output pseudo
6300 prevents this. */ 6462 prevents this. */
6334 rtx cheap, pat, dest; 6496 rtx cheap, pat, dest;
6335 rtx_insn *restore; 6497 rtx_insn *restore;
6336 int regno, hard_regno; 6498 int regno, hard_regno;
6337 6499
6338 calls_num++; 6500 calls_num++;
6501 function_abi callee_abi = insn_callee_abi (curr_insn);
6502 last_call_for_abi[callee_abi.id ()] = calls_num;
6503 full_and_partial_call_clobbers
6504 |= callee_abi.full_and_partial_reg_clobbers ();
6339 if ((cheap = find_reg_note (curr_insn, 6505 if ((cheap = find_reg_note (curr_insn,
6340 REG_RETURNED, NULL_RTX)) != NULL_RTX 6506 REG_RETURNED, NULL_RTX)) != NULL_RTX
6341 && ((cheap = XEXP (cheap, 0)), true) 6507 && ((cheap = XEXP (cheap, 0)), true)
6342 && (regno = REGNO (cheap)) >= FIRST_PSEUDO_REGISTER 6508 && (regno = REGNO (cheap)) >= FIRST_PSEUDO_REGISTER
6343 && (hard_regno = reg_renumber[regno]) >= 0 6509 && (hard_regno = reg_renumber[regno]) >= 0
6344 && usage_insns[regno].check == curr_usage_insns_check 6510 && usage_insns[regno].check == curr_usage_insns_check
6345 /* If there are pending saves/restores, the 6511 /* If there are pending saves/restores, the
6346 optimization is not worth. */ 6512 optimization is not worth. */
6347 && usage_insns[regno].calls_num == calls_num - 1 6513 && usage_insns[regno].calls_num == calls_num - 1
6348 && TEST_HARD_REG_BIT (call_used_reg_set, hard_regno)) 6514 && callee_abi.clobbers_reg_p (GET_MODE (cheap), hard_regno))
6349 { 6515 {
6350 /* Restore the pseudo from the call result as 6516 /* Restore the pseudo from the call result as
6351 REG_RETURNED note says that the pseudo value is 6517 REG_RETURNED note says that the pseudo value is
6352 in the call result and the pseudo is an argument 6518 in the call result and the pseudo is an argument
6353 of the call. */ 6519 of the call. */
6366 lra_process_new_insns (curr_insn, NULL, restore, 6532 lra_process_new_insns (curr_insn, NULL, restore,
6367 "Inserting call parameter restore"); 6533 "Inserting call parameter restore");
6368 /* We don't need to save/restore of the pseudo from 6534 /* We don't need to save/restore of the pseudo from
6369 this call. */ 6535 this call. */
6370 usage_insns[regno].calls_num = calls_num; 6536 usage_insns[regno].calls_num = calls_num;
6537 remove_from_hard_reg_set
6538 (&full_and_partial_call_clobbers,
6539 GET_MODE (cheap), hard_regno);
6371 bitmap_set_bit (&check_only_regs, regno); 6540 bitmap_set_bit (&check_only_regs, regno);
6372 } 6541 }
6373 } 6542 }
6374 } 6543 }
6375 to_inherit_num = 0; 6544 to_inherit_num = 0;
6409 && split_if_necessary (src_regno, reg->biggest_mode, 6578 && split_if_necessary (src_regno, reg->biggest_mode,
6410 potential_reload_hard_regs, 6579 potential_reload_hard_regs,
6411 before_p, curr_insn, max_uid)) 6580 before_p, curr_insn, max_uid))
6412 { 6581 {
6413 if (reg->subreg_p) 6582 if (reg->subreg_p)
6414 lra_risky_transformations_p = true; 6583 check_and_force_assignment_correctness_p = true;
6415 change_p = true; 6584 change_p = true;
6416 /* Invalidate. */ 6585 /* Invalidate. */
6417 usage_insns[src_regno].check = 0; 6586 usage_insns[src_regno].check = 0;
6418 if (before_p) 6587 if (before_p)
6419 use_insn = PREV_INSN (curr_insn); 6588 use_insn = PREV_INSN (curr_insn);
6469 && (cl = lra_get_allocno_class (regno)) != NO_REGS)) 6638 && (cl = lra_get_allocno_class (regno)) != NO_REGS))
6470 { 6639 {
6471 if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num) 6640 if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
6472 reloads_num++; 6641 reloads_num++;
6473 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs)) 6642 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
6474 IOR_HARD_REG_SET (potential_reload_hard_regs, 6643 potential_reload_hard_regs |= reg_class_contents[cl];
6475 reg_class_contents[cl]);
6476 } 6644 }
6477 } 6645 }
6478 if (NONDEBUG_INSN_P (curr_insn)) 6646 if (NONDEBUG_INSN_P (curr_insn))
6479 { 6647 {
6480 int regno; 6648 int regno;
6543 6711
6544 /* This value affects EBB forming. If probability of edge from EBB to 6712 /* This value affects EBB forming. If probability of edge from EBB to
6545 a BB is not greater than the following value, we don't add the BB 6713 a BB is not greater than the following value, we don't add the BB
6546 to EBB. */ 6714 to EBB. */
6547 #define EBB_PROBABILITY_CUTOFF \ 6715 #define EBB_PROBABILITY_CUTOFF \
6548 ((REG_BR_PROB_BASE * LRA_INHERITANCE_EBB_PROBABILITY_CUTOFF) / 100) 6716 ((REG_BR_PROB_BASE * param_lra_inheritance_ebb_probability_cutoff) / 100)
6549 6717
6550 /* Current number of inheritance/split iteration. */ 6718 /* Current number of inheritance/split iteration. */
6551 int lra_inheritance_iter; 6719 int lra_inheritance_iter;
6552 6720
6553 /* Entry function for inheritance/split pass. */ 6721 /* Entry function for inheritance/split pass. */
6603 if (inherit_in_ebb (BB_HEAD (start_bb), BB_END (bb))) 6771 if (inherit_in_ebb (BB_HEAD (start_bb), BB_END (bb)))
6604 /* Remember that the EBB head and tail can change in 6772 /* Remember that the EBB head and tail can change in
6605 inherit_in_ebb. */ 6773 inherit_in_ebb. */
6606 update_ebb_live_info (BB_HEAD (start_bb), BB_END (bb)); 6774 update_ebb_live_info (BB_HEAD (start_bb), BB_END (bb));
6607 } 6775 }
6608 bitmap_clear (&ebb_global_regs); 6776 bitmap_release (&ebb_global_regs);
6609 bitmap_clear (&temp_bitmap); 6777 bitmap_release (&temp_bitmap);
6610 bitmap_clear (&live_regs); 6778 bitmap_release (&live_regs);
6611 bitmap_clear (&invalid_invariant_regs); 6779 bitmap_release (&invalid_invariant_regs);
6612 bitmap_clear (&check_only_regs); 6780 bitmap_release (&check_only_regs);
6613 free (usage_insns); 6781 free (usage_insns);
6614 6782
6615 timevar_pop (TV_LRA_INHERITANCE); 6783 timevar_pop (TV_LRA_INHERITANCE);
6616 } 6784 }
6617 6785
6692 rtx set, prev_set; 6860 rtx set, prev_set;
6693 rtx_insn *prev_insn; 6861 rtx_insn *prev_insn;
6694 bool change_p, done_p; 6862 bool change_p, done_p;
6695 6863
6696 change_p = ! bitmap_empty_p (remove_pseudos); 6864 change_p = ! bitmap_empty_p (remove_pseudos);
6697 /* We can not finish the function right away if CHANGE_P is true 6865 /* We cannot finish the function right away if CHANGE_P is true
6698 because we need to marks insns affected by previous 6866 because we need to marks insns affected by previous
6699 inheritance/split pass for processing by the subsequent 6867 inheritance/split pass for processing by the subsequent
6700 constraint pass. */ 6868 constraint pass. */
6701 FOR_EACH_BB_FN (bb, cfun) 6869 FOR_EACH_BB_FN (bb, cfun)
6702 { 6870 {
6733 else if (bitmap_bit_p (remove_pseudos, sregno) 6901 else if (bitmap_bit_p (remove_pseudos, sregno)
6734 && ! REG_P (lra_reg_info[sregno].restore_rtx)) 6902 && ! REG_P (lra_reg_info[sregno].restore_rtx))
6735 { 6903 {
6736 /* reload pseudo <- invariant inheritance pseudo */ 6904 /* reload pseudo <- invariant inheritance pseudo */
6737 start_sequence (); 6905 start_sequence ();
6738 /* We can not just change the source. It might be 6906 /* We cannot just change the source. It might be
6739 an insn different from the move. */ 6907 an insn different from the move. */
6740 emit_insn (lra_reg_info[sregno].restore_rtx); 6908 emit_insn (lra_reg_info[sregno].restore_rtx);
6741 rtx_insn *new_insns = get_insns (); 6909 rtx_insn *new_insns = get_insns ();
6742 end_sequence (); 6910 end_sequence ();
6743 lra_assert (single_set (new_insns) != NULL 6911 lra_assert (single_set (new_insns) != NULL