Mercurial > hg > CbC > CbC_gcc
comparison gcc/lra-assigns.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Assign reload pseudos. | 1 /* Assign reload pseudos. |
2 Copyright (C) 2010-2017 Free Software Foundation, Inc. | 2 Copyright (C) 2010-2018 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 |
483 lra_live_range_t r; | 483 lra_live_range_t r; |
484 int p, i, j, rclass_size, best_hard_regno, priority, hard_regno; | 484 int p, i, j, rclass_size, best_hard_regno, priority, hard_regno; |
485 int hr, conflict_hr, nregs; | 485 int hr, conflict_hr, nregs; |
486 machine_mode biggest_mode; | 486 machine_mode biggest_mode; |
487 unsigned int k, conflict_regno; | 487 unsigned int k, conflict_regno; |
488 int offset, val, biggest_nregs, nregs_diff; | 488 poly_int64 offset; |
489 int val, biggest_nregs, nregs_diff; | |
489 enum reg_class rclass; | 490 enum reg_class rclass; |
490 bitmap_iterator bi; | 491 bitmap_iterator bi; |
491 bool *rclass_intersect_p; | 492 bool *rclass_intersect_p; |
492 HARD_REG_SET impossible_start_hard_regs, available_regs; | 493 HARD_REG_SET impossible_start_hard_regs, available_regs; |
493 | 494 |
1145 setup_live_pseudos_and_spill_after_risky_transforms (bitmap | 1146 setup_live_pseudos_and_spill_after_risky_transforms (bitmap |
1146 spilled_pseudo_bitmap) | 1147 spilled_pseudo_bitmap) |
1147 { | 1148 { |
1148 int p, i, j, n, regno, hard_regno; | 1149 int p, i, j, n, regno, hard_regno; |
1149 unsigned int k, conflict_regno; | 1150 unsigned int k, conflict_regno; |
1150 int val, offset; | 1151 poly_int64 offset; |
1152 int val; | |
1151 HARD_REG_SET conflict_set; | 1153 HARD_REG_SET conflict_set; |
1152 machine_mode mode; | 1154 machine_mode mode; |
1153 lra_live_range_t r; | 1155 lra_live_range_t r; |
1154 bitmap_iterator bi; | 1156 bitmap_iterator bi; |
1155 int max_regno = max_reg_num (); | 1157 int max_regno = max_reg_num (); |
1335 for (r2 = start_point_ranges[p]; | 1337 for (r2 = start_point_ranges[p]; |
1336 r2 != NULL; | 1338 r2 != NULL; |
1337 r2 = r2->start_next) | 1339 r2 = r2->start_next) |
1338 { | 1340 { |
1339 if (live_pseudos_reg_renumber[r2->regno] >= 0 | 1341 if (live_pseudos_reg_renumber[r2->regno] >= 0 |
1340 && rclass_intersect_p[regno_allocno_class_array[r2->regno]]) | 1342 && ! sparseset_bit_p (live_range_hard_reg_pseudos, r2->regno) |
1343 && rclass_intersect_p[regno_allocno_class_array[r2->regno]] | |
1344 && ((int) r2->regno < lra_constraint_new_regno_start | |
1345 || bitmap_bit_p (&lra_inheritance_pseudos, r2->regno) | |
1346 || bitmap_bit_p (&lra_split_regs, r2->regno) | |
1347 || bitmap_bit_p (&lra_optional_reload_pseudos, r2->regno) | |
1348 /* There is no sense to consider another reload | |
1349 pseudo if it has the same class. */ | |
1350 || regno_allocno_class_array[r2->regno] != rclass)) | |
1341 sparseset_set_bit (live_range_hard_reg_pseudos, r2->regno); | 1351 sparseset_set_bit (live_range_hard_reg_pseudos, r2->regno); |
1342 } | 1352 } |
1343 } | 1353 } |
1344 } | 1354 } |
1345 } | 1355 } |
1346 | 1356 |
1347 /* Assign hard registers to reload pseudos and other pseudos. */ | 1357 /* Assign hard registers to reload pseudos and other pseudos. Return |
1348 static void | 1358 true if we was not able to assign hard registers to all reload |
1359 pseudos. */ | |
1360 static bool | |
1349 assign_by_spills (void) | 1361 assign_by_spills (void) |
1350 { | 1362 { |
1351 int i, n, nfails, iter, regno, hard_regno, cost; | 1363 int i, n, nfails, iter, regno, regno2, hard_regno, cost; |
1352 rtx restore_rtx; | 1364 rtx restore_rtx; |
1353 rtx_insn *insn; | |
1354 bitmap_head changed_insns, do_not_assign_nonreload_pseudos; | 1365 bitmap_head changed_insns, do_not_assign_nonreload_pseudos; |
1355 unsigned int u, conflict_regno; | 1366 unsigned int u, conflict_regno; |
1356 bitmap_iterator bi; | 1367 bitmap_iterator bi; |
1357 bool reload_p; | 1368 bool reload_p, fails_p = false; |
1358 int max_regno = max_reg_num (); | 1369 int max_regno = max_reg_num (); |
1359 | 1370 |
1360 for (n = 0, i = lra_constraint_new_regno_start; i < max_regno; i++) | 1371 for (n = 0, i = lra_constraint_new_regno_start; i < max_regno; i++) |
1361 if (reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0 | 1372 if (reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0 |
1362 && regno_allocno_class_array[i] != NO_REGS) | 1373 && regno_allocno_class_array[i] != NO_REGS) |
1395 reload_p = ! bitmap_bit_p (&non_reload_pseudos, regno); | 1406 reload_p = ! bitmap_bit_p (&non_reload_pseudos, regno); |
1396 if (hard_regno < 0 && reload_p) | 1407 if (hard_regno < 0 && reload_p) |
1397 hard_regno = spill_for (regno, &all_spilled_pseudos, iter == 1); | 1408 hard_regno = spill_for (regno, &all_spilled_pseudos, iter == 1); |
1398 if (hard_regno < 0) | 1409 if (hard_regno < 0) |
1399 { | 1410 { |
1400 if (reload_p) | 1411 if (reload_p) { |
1412 /* Put unassigned reload pseudo first in the | |
1413 array. */ | |
1414 regno2 = sorted_pseudos[nfails]; | |
1401 sorted_pseudos[nfails++] = regno; | 1415 sorted_pseudos[nfails++] = regno; |
1416 sorted_pseudos[i] = regno2; | |
1417 } | |
1402 } | 1418 } |
1403 else | 1419 else |
1404 { | 1420 { |
1405 /* This register might have been spilled by the previous | 1421 /* This register might have been spilled by the previous |
1406 pass. Indicate that it is no longer spilled. */ | 1422 pass. Indicate that it is no longer spilled. */ |
1411 should reconsider insns referring for the | 1427 should reconsider insns referring for the |
1412 pseudo. */ | 1428 pseudo. */ |
1413 bitmap_set_bit (&changed_pseudo_bitmap, regno); | 1429 bitmap_set_bit (&changed_pseudo_bitmap, regno); |
1414 } | 1430 } |
1415 } | 1431 } |
1416 if (nfails == 0) | 1432 if (nfails == 0 || iter > 0) |
1417 break; | 1433 { |
1418 if (iter > 0) | 1434 fails_p = nfails != 0; |
1419 { | |
1420 /* We did not assign hard regs to reload pseudos after two iterations. | |
1421 Either it's an asm and something is wrong with the constraints, or | |
1422 we have run out of spill registers; error out in either case. */ | |
1423 bool asm_p = false; | |
1424 bitmap_head failed_reload_insns; | |
1425 | |
1426 bitmap_initialize (&failed_reload_insns, ®_obstack); | |
1427 for (i = 0; i < nfails; i++) | |
1428 { | |
1429 regno = sorted_pseudos[i]; | |
1430 bitmap_ior_into (&failed_reload_insns, | |
1431 &lra_reg_info[regno].insn_bitmap); | |
1432 /* Assign an arbitrary hard register of regno class to | |
1433 avoid further trouble with this insn. */ | |
1434 bitmap_clear_bit (&all_spilled_pseudos, regno); | |
1435 assign_hard_regno | |
1436 (ira_class_hard_regs[regno_allocno_class_array[regno]][0], | |
1437 regno); | |
1438 } | |
1439 EXECUTE_IF_SET_IN_BITMAP (&failed_reload_insns, 0, u, bi) | |
1440 { | |
1441 insn = lra_insn_recog_data[u]->insn; | |
1442 if (asm_noperands (PATTERN (insn)) >= 0) | |
1443 { | |
1444 asm_p = true; | |
1445 error_for_asm (insn, | |
1446 "%<asm%> operand has impossible constraints"); | |
1447 /* Avoid further trouble with this insn. | |
1448 For asm goto, instead of fixing up all the edges | |
1449 just clear the template and clear input operands | |
1450 (asm goto doesn't have any output operands). */ | |
1451 if (JUMP_P (insn)) | |
1452 { | |
1453 rtx asm_op = extract_asm_operands (PATTERN (insn)); | |
1454 ASM_OPERANDS_TEMPLATE (asm_op) = ggc_strdup (""); | |
1455 ASM_OPERANDS_INPUT_VEC (asm_op) = rtvec_alloc (0); | |
1456 ASM_OPERANDS_INPUT_CONSTRAINT_VEC (asm_op) = rtvec_alloc (0); | |
1457 lra_update_insn_regno_info (insn); | |
1458 } | |
1459 else | |
1460 { | |
1461 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx); | |
1462 lra_set_insn_deleted (insn); | |
1463 } | |
1464 } | |
1465 else if (!asm_p) | |
1466 { | |
1467 error ("unable to find a register to spill"); | |
1468 fatal_insn ("this is the insn:", insn); | |
1469 } | |
1470 } | |
1471 break; | 1435 break; |
1472 } | 1436 } |
1473 /* This is a very rare event. We can not assign a hard register | 1437 /* This is a very rare event. We can not assign a hard register |
1474 to reload pseudo because the hard register was assigned to | 1438 to reload pseudo because the hard register was assigned to |
1475 another reload pseudo on a previous assignment pass. For x86 | 1439 another reload pseudo on a previous assignment pass. For x86 |
1514 reg_renumber[conflict_regno], | 1478 reg_renumber[conflict_regno], |
1515 lra_reg_info[conflict_regno].freq); | 1479 lra_reg_info[conflict_regno].freq); |
1516 update_lives (conflict_regno, true); | 1480 update_lives (conflict_regno, true); |
1517 lra_setup_reg_renumber (conflict_regno, -1, false); | 1481 lra_setup_reg_renumber (conflict_regno, -1, false); |
1518 } | 1482 } |
1519 n = nfails; | 1483 if (n < nfails) |
1484 n = nfails; | |
1520 } | 1485 } |
1521 improve_inheritance (&changed_pseudo_bitmap); | 1486 improve_inheritance (&changed_pseudo_bitmap); |
1522 bitmap_clear (&non_reload_pseudos); | 1487 bitmap_clear (&non_reload_pseudos); |
1523 bitmap_clear (&changed_insns); | 1488 bitmap_clear (&changed_insns); |
1524 if (! lra_simple_p) | 1489 if (! lra_simple_p) |
1600 } | 1565 } |
1601 free (update_hard_regno_preference_check); | 1566 free (update_hard_regno_preference_check); |
1602 bitmap_clear (&best_spill_pseudos_bitmap); | 1567 bitmap_clear (&best_spill_pseudos_bitmap); |
1603 bitmap_clear (&spill_pseudos_bitmap); | 1568 bitmap_clear (&spill_pseudos_bitmap); |
1604 bitmap_clear (&insn_conflict_pseudos); | 1569 bitmap_clear (&insn_conflict_pseudos); |
1605 } | 1570 return fails_p; |
1606 | 1571 } |
1607 | 1572 |
1608 /* Entry function to assign hard registers to new reload pseudos | 1573 /* Entry function to assign hard registers to new reload pseudos |
1609 starting with LRA_CONSTRAINT_NEW_REGNO_START (by possible spilling | 1574 starting with LRA_CONSTRAINT_NEW_REGNO_START (by possible spilling |
1610 of old pseudos) and possibly to the old pseudos. The function adds | 1575 of old pseudos) and possibly to the old pseudos. The function adds |
1611 what insns to process for the next constraint pass. Those are all | 1576 what insns to process for the next constraint pass. Those are all |
1612 insns who contains non-reload and non-inheritance pseudos with | 1577 insns who contains non-reload and non-inheritance pseudos with |
1613 changed allocation. | 1578 changed allocation. |
1614 | 1579 |
1615 Return true if we did not spill any non-reload and non-inheritance | 1580 Return true if we did not spill any non-reload and non-inheritance |
1616 pseudos. */ | 1581 pseudos. Set up FAILS_P if we failed to assign hard registers to |
1582 all reload pseudos. */ | |
1617 bool | 1583 bool |
1618 lra_assign (void) | 1584 lra_assign (bool &fails_p) |
1619 { | 1585 { |
1620 int i; | 1586 int i; |
1621 unsigned int u; | 1587 unsigned int u; |
1622 bitmap_iterator bi; | 1588 bitmap_iterator bi; |
1623 bitmap_head insns_to_process; | 1589 bitmap_head insns_to_process; |
1657 PSEUDO_REGNO_MODE (i), reg_renumber[i])) | 1623 PSEUDO_REGNO_MODE (i), reg_renumber[i])) |
1658 gcc_unreachable (); | 1624 gcc_unreachable (); |
1659 /* Setup insns to process on the next constraint pass. */ | 1625 /* Setup insns to process on the next constraint pass. */ |
1660 bitmap_initialize (&changed_pseudo_bitmap, ®_obstack); | 1626 bitmap_initialize (&changed_pseudo_bitmap, ®_obstack); |
1661 init_live_reload_and_inheritance_pseudos (); | 1627 init_live_reload_and_inheritance_pseudos (); |
1662 assign_by_spills (); | 1628 fails_p = assign_by_spills (); |
1663 finish_live_reload_and_inheritance_pseudos (); | 1629 finish_live_reload_and_inheritance_pseudos (); |
1664 bitmap_ior_into (&changed_pseudo_bitmap, &all_spilled_pseudos); | 1630 bitmap_ior_into (&changed_pseudo_bitmap, &all_spilled_pseudos); |
1665 no_spills_p = true; | 1631 no_spills_p = true; |
1666 EXECUTE_IF_SET_IN_BITMAP (&all_spilled_pseudos, 0, u, bi) | 1632 EXECUTE_IF_SET_IN_BITMAP (&all_spilled_pseudos, 0, u, bi) |
1667 /* We ignore spilled pseudos created on last inheritance pass | 1633 /* We ignore spilled pseudos created on last inheritance pass |
1703 ("Maximum number of LRA assignment passes is achieved (%d)\n", | 1669 ("Maximum number of LRA assignment passes is achieved (%d)\n", |
1704 LRA_MAX_ASSIGNMENT_ITERATION_NUMBER); | 1670 LRA_MAX_ASSIGNMENT_ITERATION_NUMBER); |
1705 return no_spills_p; | 1671 return no_spills_p; |
1706 } | 1672 } |
1707 | 1673 |
1674 /* Find start and finish insns for reload pseudo REGNO. Return true | |
1675 if we managed to find the expected insns. Return false, | |
1676 otherwise. */ | |
1677 static bool | |
1678 find_reload_regno_insns (int regno, rtx_insn * &start, rtx_insn * &finish) | |
1679 { | |
1680 unsigned int uid; | |
1681 bitmap_iterator bi; | |
1682 int n = 0; | |
1683 rtx_insn *prev_insn, *next_insn; | |
1684 rtx_insn *start_insn = NULL, *first_insn = NULL, *second_insn = NULL; | |
1685 | |
1686 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi) | |
1687 { | |
1688 if (start_insn == NULL) | |
1689 start_insn = lra_insn_recog_data[uid]->insn; | |
1690 n++; | |
1691 } | |
1692 /* For reload pseudo we should have at most 3 insns referring for it: | |
1693 input/output reload insns and the original insn. */ | |
1694 if (n > 3) | |
1695 return false; | |
1696 if (n > 1) | |
1697 { | |
1698 for (prev_insn = PREV_INSN (start_insn), | |
1699 next_insn = NEXT_INSN (start_insn); | |
1700 n != 1 && (prev_insn != NULL || next_insn != NULL); ) | |
1701 { | |
1702 if (prev_insn != NULL && first_insn == NULL) | |
1703 { | |
1704 if (! bitmap_bit_p (&lra_reg_info[regno].insn_bitmap, | |
1705 INSN_UID (prev_insn))) | |
1706 prev_insn = PREV_INSN (prev_insn); | |
1707 else | |
1708 { | |
1709 first_insn = prev_insn; | |
1710 n--; | |
1711 } | |
1712 } | |
1713 if (next_insn != NULL && second_insn == NULL) | |
1714 { | |
1715 if (! bitmap_bit_p (&lra_reg_info[regno].insn_bitmap, | |
1716 INSN_UID (next_insn))) | |
1717 next_insn = NEXT_INSN (next_insn); | |
1718 else | |
1719 { | |
1720 second_insn = next_insn; | |
1721 n--; | |
1722 } | |
1723 } | |
1724 } | |
1725 if (n > 1) | |
1726 return false; | |
1727 } | |
1728 start = first_insn != NULL ? first_insn : start_insn; | |
1729 finish = second_insn != NULL ? second_insn : start_insn; | |
1730 return true; | |
1731 } | |
1732 | |
1733 /* Process reload pseudos which did not get a hard reg, split a hard | |
1734 reg live range in live range of a reload pseudo, and then return | |
1735 TRUE. If we did not split a hard reg live range, report an error, | |
1736 and return FALSE. */ | |
1737 bool | |
1738 lra_split_hard_reg_for (void) | |
1739 { | |
1740 int i, regno; | |
1741 rtx_insn *insn, *first, *last; | |
1742 unsigned int u; | |
1743 bitmap_iterator bi; | |
1744 enum reg_class rclass; | |
1745 int max_regno = max_reg_num (); | |
1746 /* We did not assign hard regs to reload pseudos after two | |
1747 iterations. Either it's an asm and something is wrong with the | |
1748 constraints, or we have run out of spill registers; error out in | |
1749 either case. */ | |
1750 bool asm_p = false; | |
1751 bitmap_head failed_reload_insns, failed_reload_pseudos; | |
1752 | |
1753 if (lra_dump_file != NULL) | |
1754 fprintf (lra_dump_file, | |
1755 "\n****** Splitting a hard reg after assignment #%d: ******\n\n", | |
1756 lra_assignment_iter); | |
1757 bitmap_initialize (&failed_reload_pseudos, ®_obstack); | |
1758 for (i = lra_constraint_new_regno_start; i < max_regno; i++) | |
1759 if (reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0 | |
1760 && (rclass = lra_get_allocno_class (i)) != NO_REGS | |
1761 && ! bitmap_bit_p (&non_reload_pseudos, i)) | |
1762 { | |
1763 if (! find_reload_regno_insns (i, first, last)) | |
1764 continue; | |
1765 if (spill_hard_reg_in_range (i, rclass, first, last)) | |
1766 { | |
1767 bitmap_clear (&failed_reload_pseudos); | |
1768 return true; | |
1769 } | |
1770 bitmap_set_bit (&failed_reload_pseudos, i); | |
1771 } | |
1772 bitmap_initialize (&failed_reload_insns, ®_obstack); | |
1773 EXECUTE_IF_SET_IN_BITMAP (&failed_reload_pseudos, 0, u, bi) | |
1774 { | |
1775 regno = u; | |
1776 bitmap_ior_into (&failed_reload_insns, | |
1777 &lra_reg_info[regno].insn_bitmap); | |
1778 lra_setup_reg_renumber | |
1779 (regno, ira_class_hard_regs[lra_get_allocno_class (regno)][0], false); | |
1780 } | |
1781 EXECUTE_IF_SET_IN_BITMAP (&failed_reload_insns, 0, u, bi) | |
1782 { | |
1783 insn = lra_insn_recog_data[u]->insn; | |
1784 if (asm_noperands (PATTERN (insn)) >= 0) | |
1785 { | |
1786 asm_p = true; | |
1787 error_for_asm (insn, | |
1788 "%<asm%> operand has impossible constraints"); | |
1789 /* Avoid further trouble with this insn. | |
1790 For asm goto, instead of fixing up all the edges | |
1791 just clear the template and clear input operands | |
1792 (asm goto doesn't have any output operands). */ | |
1793 if (JUMP_P (insn)) | |
1794 { | |
1795 rtx asm_op = extract_asm_operands (PATTERN (insn)); | |
1796 ASM_OPERANDS_TEMPLATE (asm_op) = ggc_strdup (""); | |
1797 ASM_OPERANDS_INPUT_VEC (asm_op) = rtvec_alloc (0); | |
1798 ASM_OPERANDS_INPUT_CONSTRAINT_VEC (asm_op) = rtvec_alloc (0); | |
1799 lra_update_insn_regno_info (insn); | |
1800 } | |
1801 else | |
1802 { | |
1803 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx); | |
1804 lra_set_insn_deleted (insn); | |
1805 } | |
1806 } | |
1807 else if (!asm_p) | |
1808 { | |
1809 error ("unable to find a register to spill"); | |
1810 fatal_insn ("this is the insn:", insn); | |
1811 } | |
1812 } | |
1813 bitmap_clear (&failed_reload_pseudos); | |
1814 bitmap_clear (&failed_reload_insns); | |
1815 return false; | |
1816 } |