comparison gcc/cfgloop.c @ 132:d34655255c78

update gcc-8.2
author mir3636
date Thu, 25 Oct 2018 10:21:07 +0900
parents 84e7813d76e9
children 1830386684a0
comparison
equal deleted inserted replaced
130:e108057fa461 132:d34655255c78
1 /* Natural loop discovery code for GNU compiler. 1 /* Natural loop discovery code for GNU compiler.
2 Copyright (C) 2000-2017 Free Software Foundation, Inc. 2 Copyright (C) 2000-2018 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
294 establish_preds (ploop, loop); 294 establish_preds (ploop, loop);
295 } 295 }
296 296
297 /* Add LOOP to the loop hierarchy tree where FATHER is father of the 297 /* Add LOOP to the loop hierarchy tree where FATHER is father of the
298 added loop. If LOOP has some children, take care of that their 298 added loop. If LOOP has some children, take care of that their
299 pred field will be initialized correctly. */ 299 pred field will be initialized correctly. If AFTER is non-null
300 then it's expected it's a pointer into FATHERs inner sibling
301 list and LOOP is added behind AFTER, otherwise it's added in front
302 of FATHERs siblings. */
300 303
301 void 304 void
302 flow_loop_tree_node_add (struct loop *father, struct loop *loop) 305 flow_loop_tree_node_add (struct loop *father, struct loop *loop,
303 { 306 struct loop *after)
304 loop->next = father->inner; 307 {
305 father->inner = loop; 308 if (after)
309 {
310 loop->next = after->next;
311 after->next = loop;
312 }
313 else
314 {
315 loop->next = father->inner;
316 father->inner = loop;
317 }
306 318
307 establish_preds (loop, father); 319 establish_preds (loop, father);
308 } 320 }
309 321
310 /* Remove LOOP from the loop hierarchy tree. */ 322 /* Remove LOOP from the loop hierarchy tree. */
605 mcount = e->count(); 617 mcount = e->count();
606 } 618 }
607 tcount += e->count(); 619 tcount += e->count();
608 } 620 }
609 621
610 if (!tcount.initialized_p () || tcount < HEAVY_EDGE_MIN_SAMPLES 622 if (!tcount.initialized_p () || !(tcount.ipa () > HEAVY_EDGE_MIN_SAMPLES)
611 || (tcount - mcount).apply_scale (HEAVY_EDGE_RATIO, 1) > tcount) 623 || (tcount - mcount).apply_scale (HEAVY_EDGE_RATIO, 1) > tcount)
612 return NULL; 624 return NULL;
613 625
614 if (dump_file) 626 if (dump_file)
615 fprintf (dump_file, 627 fprintf (dump_file,
1525 } 1537 }
1526 1538
1527 /* Check irreducible loops. */ 1539 /* Check irreducible loops. */
1528 if (loops_state_satisfies_p (LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS)) 1540 if (loops_state_satisfies_p (LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS))
1529 { 1541 {
1542 auto_edge_flag saved_irr_mask (cfun);
1530 /* Record old info. */ 1543 /* Record old info. */
1531 auto_sbitmap irreds (last_basic_block_for_fn (cfun)); 1544 auto_sbitmap irreds (last_basic_block_for_fn (cfun));
1532 FOR_EACH_BB_FN (bb, cfun) 1545 FOR_EACH_BB_FN (bb, cfun)
1533 { 1546 {
1534 edge_iterator ei; 1547 edge_iterator ei;
1536 bitmap_set_bit (irreds, bb->index); 1549 bitmap_set_bit (irreds, bb->index);
1537 else 1550 else
1538 bitmap_clear_bit (irreds, bb->index); 1551 bitmap_clear_bit (irreds, bb->index);
1539 FOR_EACH_EDGE (e, ei, bb->succs) 1552 FOR_EACH_EDGE (e, ei, bb->succs)
1540 if (e->flags & EDGE_IRREDUCIBLE_LOOP) 1553 if (e->flags & EDGE_IRREDUCIBLE_LOOP)
1541 e->flags |= EDGE_ALL_FLAGS + 1; 1554 e->flags |= saved_irr_mask;
1542 } 1555 }
1543 1556
1544 /* Recount it. */ 1557 /* Recount it. */
1545 mark_irreducible_loops (); 1558 mark_irreducible_loops ();
1546 1559
1562 err = 1; 1575 err = 1;
1563 } 1576 }
1564 FOR_EACH_EDGE (e, ei, bb->succs) 1577 FOR_EACH_EDGE (e, ei, bb->succs)
1565 { 1578 {
1566 if ((e->flags & EDGE_IRREDUCIBLE_LOOP) 1579 if ((e->flags & EDGE_IRREDUCIBLE_LOOP)
1567 && !(e->flags & (EDGE_ALL_FLAGS + 1))) 1580 && !(e->flags & saved_irr_mask))
1568 { 1581 {
1569 error ("edge from %d to %d should be marked irreducible", 1582 error ("edge from %d to %d should be marked irreducible",
1570 e->src->index, e->dest->index); 1583 e->src->index, e->dest->index);
1571 err = 1; 1584 err = 1;
1572 } 1585 }
1573 else if (!(e->flags & EDGE_IRREDUCIBLE_LOOP) 1586 else if (!(e->flags & EDGE_IRREDUCIBLE_LOOP)
1574 && (e->flags & (EDGE_ALL_FLAGS + 1))) 1587 && (e->flags & saved_irr_mask))
1575 { 1588 {
1576 error ("edge from %d to %d should not be marked irreducible", 1589 error ("edge from %d to %d should not be marked irreducible",
1577 e->src->index, e->dest->index); 1590 e->src->index, e->dest->index);
1578 err = 1; 1591 err = 1;
1579 } 1592 }
1580 e->flags &= ~(EDGE_ALL_FLAGS + 1); 1593 e->flags &= ~saved_irr_mask;
1581 } 1594 }
1582 } 1595 }
1583 } 1596 }
1584 1597
1585 /* Check the recorded loop exits. */ 1598 /* Check the recorded loop exits. */
1786 return false; 1799 return false;
1787 } 1800 }
1788 1801
1789 /* Return location corresponding to the loop control condition if possible. */ 1802 /* Return location corresponding to the loop control condition if possible. */
1790 1803
1791 location_t 1804 dump_user_location_t
1792 get_loop_location (struct loop *loop) 1805 get_loop_location (struct loop *loop)
1793 { 1806 {
1794 rtx_insn *insn = NULL; 1807 rtx_insn *insn = NULL;
1795 struct niter_desc *desc = NULL; 1808 struct niter_desc *desc = NULL;
1796 edge exit; 1809 edge exit;
1805 if (desc->in_edge) 1818 if (desc->in_edge)
1806 { 1819 {
1807 FOR_BB_INSNS_REVERSE (desc->in_edge->src, insn) 1820 FOR_BB_INSNS_REVERSE (desc->in_edge->src, insn)
1808 { 1821 {
1809 if (INSN_P (insn) && INSN_HAS_LOCATION (insn)) 1822 if (INSN_P (insn) && INSN_HAS_LOCATION (insn))
1810 return INSN_LOCATION (insn); 1823 return insn;
1811 } 1824 }
1812 } 1825 }
1813 /* If loop has a single exit, then the loop control branch 1826 /* If loop has a single exit, then the loop control branch
1814 must be at the end of its source. */ 1827 must be at the end of its source. */
1815 if ((exit = single_exit (loop))) 1828 if ((exit = single_exit (loop)))
1816 { 1829 {
1817 FOR_BB_INSNS_REVERSE (exit->src, insn) 1830 FOR_BB_INSNS_REVERSE (exit->src, insn)
1818 { 1831 {
1819 if (INSN_P (insn) && INSN_HAS_LOCATION (insn)) 1832 if (INSN_P (insn) && INSN_HAS_LOCATION (insn))
1820 return INSN_LOCATION (insn); 1833 return insn;
1821 } 1834 }
1822 } 1835 }
1823 /* Next check the latch, to see if it is non-empty. */ 1836 /* Next check the latch, to see if it is non-empty. */
1824 FOR_BB_INSNS_REVERSE (loop->latch, insn) 1837 FOR_BB_INSNS_REVERSE (loop->latch, insn)
1825 { 1838 {
1826 if (INSN_P (insn) && INSN_HAS_LOCATION (insn)) 1839 if (INSN_P (insn) && INSN_HAS_LOCATION (insn))
1827 return INSN_LOCATION (insn); 1840 return insn;
1828 } 1841 }
1829 /* Finally, if none of the above identifies the loop control branch, 1842 /* Finally, if none of the above identifies the loop control branch,
1830 return the first location in the loop header. */ 1843 return the first location in the loop header. */
1831 FOR_BB_INSNS (loop->header, insn) 1844 FOR_BB_INSNS (loop->header, insn)
1832 { 1845 {
1833 if (INSN_P (insn) && INSN_HAS_LOCATION (insn)) 1846 if (INSN_P (insn) && INSN_HAS_LOCATION (insn))
1834 return INSN_LOCATION (insn); 1847 return insn;
1835 } 1848 }
1836 /* If all else fails, simply return the current function location. */ 1849 /* If all else fails, simply return the current function location. */
1837 return DECL_SOURCE_LOCATION (current_function_decl); 1850 return dump_user_location_t::from_function_decl (current_function_decl);
1838 } 1851 }
1839 1852
1840 /* Records that every statement in LOOP is executed I_BOUND times. 1853 /* Records that every statement in LOOP is executed I_BOUND times.
1841 REALISTIC is true if I_BOUND is expected to be close to the real number 1854 REALISTIC is true if I_BOUND is expected to be close to the real number
1842 of iterations. UPPER is true if we are sure the loop iterates at most 1855 of iterations. UPPER is true if we are sure the loop iterates at most