comparison gcc/tree-ssa.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 /* Miscellaneous SSA utility functions. 1 /* Miscellaneous SSA utility functions.
2 Copyright (C) 2001-2018 Free Software Foundation, Inc. 2 Copyright (C) 2001-2020 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify 6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
50 50
51 51
52 /* Add a mapping with PHI RESULT and PHI DEF associated with edge E. */ 52 /* Add a mapping with PHI RESULT and PHI DEF associated with edge E. */
53 53
54 void 54 void
55 redirect_edge_var_map_add (edge e, tree result, tree def, source_location locus) 55 redirect_edge_var_map_add (edge e, tree result, tree def, location_t locus)
56 { 56 {
57 edge_var_map new_node; 57 edge_var_map new_node;
58 58
59 if (edge_var_maps == NULL) 59 if (edge_var_maps == NULL)
60 edge_var_maps = new hash_map<edge, auto_vec<edge_var_map> >; 60 edge_var_maps = new hash_map<edge, auto_vec<edge_var_map> >;
149 got PHI argument space reserved nor an interesting argument. */ 149 got PHI argument space reserved nor an interesting argument. */
150 if (! (e->dest->flags & BB_DUPLICATED)) 150 if (! (e->dest->flags & BB_DUPLICATED))
151 for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi)) 151 for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
152 { 152 {
153 tree def; 153 tree def;
154 source_location locus ; 154 location_t locus;
155 155
156 phi = gsi.phi (); 156 phi = gsi.phi ();
157 def = gimple_phi_arg_def (phi, e->dest_idx); 157 def = gimple_phi_arg_def (phi, e->dest_idx);
158 locus = gimple_phi_arg_location (phi, e->dest_idx); 158 locus = gimple_phi_arg_location (phi, e->dest_idx);
159 159
356 /* error_mark_node is what fixup_noreturn_call changes PHI arguments 356 /* error_mark_node is what fixup_noreturn_call changes PHI arguments
357 to. */ 357 to. */
358 else if (value == error_mark_node) 358 else if (value == error_mark_node)
359 value = NULL; 359 value = NULL;
360 } 360 }
361 else if (gimple_clobber_p (def_stmt))
362 /* We can end up here when rewriting a decl into SSA and coming
363 along a clobber for the original decl. Turn that into
364 # DEBUG decl => NULL */
365 value = NULL;
361 else if (is_gimple_assign (def_stmt)) 366 else if (is_gimple_assign (def_stmt))
362 { 367 {
363 bool no_value = false; 368 bool no_value = false;
364 369
365 if (!dom_info_available_p (CDI_DOMINATORS)) 370 if (!dom_info_available_p (CDI_DOMINATORS))
552 unsigned j; 557 unsigned j;
553 bitmap_iterator bi; 558 bitmap_iterator bi;
554 559
555 /* Performing a topological sort is probably overkill, this will 560 /* Performing a topological sort is probably overkill, this will
556 most likely run in slightly superlinear time, rather than the 561 most likely run in slightly superlinear time, rather than the
557 pathological quadratic worst case. */ 562 pathological quadratic worst case.
563 But iterate from max SSA name version to min one because
564 that mimics allocation order during code generation behavior best.
565 Use an array for this which we compact on-the-fly with a NULL
566 marker moving towards the end of the vector. */
567 auto_vec<tree, 16> names;
568 names.reserve (bitmap_count_bits (toremove) + 1);
569 names.quick_push (NULL_TREE);
570 EXECUTE_IF_SET_IN_BITMAP (toremove, 0, j, bi)
571 names.quick_push (ssa_name (j));
572
573 bitmap_tree_view (toremove);
558 while (!bitmap_empty_p (toremove)) 574 while (!bitmap_empty_p (toremove))
559 { 575 {
560 unsigned to_remove_bit = -1U; 576 j = names.length () - 1;
561 EXECUTE_IF_SET_IN_BITMAP (toremove, 0, j, bi) 577 for (unsigned i = names.length () - 1; names[i];)
562 { 578 {
563 if (to_remove_bit != -1U)
564 {
565 bitmap_clear_bit (toremove, to_remove_bit);
566 to_remove_bit = -1U;
567 }
568
569 bool remove_now = true; 579 bool remove_now = true;
570 tree var = ssa_name (j); 580 tree var = names[i];
571 gimple *stmt; 581 gimple *stmt;
572 imm_use_iterator uit; 582 imm_use_iterator uit;
573 583
574 FOR_EACH_IMM_USE_STMT (stmt, uit, var) 584 FOR_EACH_IMM_USE_STMT (stmt, uit, var)
575 { 585 {
610 else 620 else
611 { 621 {
612 gsi_remove (&gsi, true); 622 gsi_remove (&gsi, true);
613 release_defs (def); 623 release_defs (def);
614 } 624 }
615 625 bitmap_clear_bit (toremove, SSA_NAME_VERSION (var));
616 to_remove_bit = j;
617 } 626 }
618 } 627 else
619 if (to_remove_bit != -1U) 628 --i;
620 bitmap_clear_bit (toremove, to_remove_bit); 629 if (--j != i)
621 } 630 names[i] = names[j];
622 631 }
623 } 632 }
633 bitmap_list_view (toremove);
634 }
635
636 /* Disable warnings about missing quoting in GCC diagnostics for
637 the verification errors. Their format strings don't follow GCC
638 diagnostic conventions and the calls are ultimately followed by
639 one to internal_error. */
640 #if __GNUC__ >= 10
641 # pragma GCC diagnostic push
642 # pragma GCC diagnostic ignored "-Wformat-diag"
643 #endif
624 644
625 /* Verify virtual SSA form. */ 645 /* Verify virtual SSA form. */
626 646
627 bool 647 bool
628 verify_vssa (basic_block bb, tree current_vdef, sbitmap visited) 648 verify_vssa (basic_block bb, tree current_vdef, sbitmap visited)
1186 1206
1187 err: 1207 err:
1188 internal_error ("verify_ssa failed"); 1208 internal_error ("verify_ssa failed");
1189 } 1209 }
1190 1210
1211 #if __GNUC__ >= 10
1212 # pragma GCC diagnostic pop
1213 #endif
1191 1214
1192 /* Initialize global DFA and SSA structures. */ 1215 /* Initialize global DFA and SSA structures. */
1193 1216
1194 void 1217 void
1195 init_tree_ssa (struct function *fn) 1218 init_tree_ssa (struct function *fn)
1444 if (integer_zerop (TREE_OPERAND (base, 1)) 1467 if (integer_zerop (TREE_OPERAND (base, 1))
1445 && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (base))) 1468 && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (base)))
1446 return NULL_TREE; 1469 return NULL_TREE;
1447 /* For integral typed extracts we can use a BIT_FIELD_REF. */ 1470 /* For integral typed extracts we can use a BIT_FIELD_REF. */
1448 if (DECL_SIZE (decl) 1471 if (DECL_SIZE (decl)
1472 && TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST
1449 && (known_subrange_p 1473 && (known_subrange_p
1450 (mem_ref_offset (base), 1474 (mem_ref_offset (base),
1451 wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base))), 1475 wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base))),
1452 0, wi::to_poly_offset (DECL_SIZE_UNIT (decl)))) 1476 0, wi::to_poly_offset (DECL_SIZE_UNIT (decl))))
1453 /* ??? We can't handle bitfield precision extracts without 1477 /* ??? We can't handle bitfield precision extracts without
1513 /* A vector-insert using a MEM_REF or ARRAY_REF is rewritable 1537 /* A vector-insert using a MEM_REF or ARRAY_REF is rewritable
1514 using a BIT_INSERT_EXPR. */ 1538 using a BIT_INSERT_EXPR. */
1515 if (DECL_P (decl) 1539 if (DECL_P (decl)
1516 && VECTOR_TYPE_P (TREE_TYPE (decl)) 1540 && VECTOR_TYPE_P (TREE_TYPE (decl))
1517 && TYPE_MODE (TREE_TYPE (decl)) != BLKmode 1541 && TYPE_MODE (TREE_TYPE (decl)) != BLKmode
1518 && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
1519 TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))), 0)
1520 && known_ge (mem_ref_offset (lhs), 0) 1542 && known_ge (mem_ref_offset (lhs), 0)
1521 && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))), 1543 && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
1522 mem_ref_offset (lhs)) 1544 mem_ref_offset (lhs))
1523 && multiple_of_p (sizetype, TREE_OPERAND (lhs, 1), 1545 && multiple_of_p (sizetype, TREE_OPERAND (lhs, 1),
1524 TYPE_SIZE_UNIT (TREE_TYPE (lhs)))) 1546 TYPE_SIZE_UNIT (TREE_TYPE (lhs))))
1525 return false; 1547 {
1548 poly_uint64 lhs_bits, nelts;
1549 if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)), &lhs_bits)
1550 && multiple_p (lhs_bits,
1551 tree_to_uhwi
1552 (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl)))),
1553 &nelts))
1554 {
1555 if (known_eq (nelts, 1u))
1556 return false;
1557 /* For sub-vector inserts the insert vector mode has to be
1558 supported. */
1559 tree vtype = build_vector_type (TREE_TYPE (TREE_TYPE (decl)),
1560 nelts);
1561 if (TYPE_MODE (vtype) != BLKmode)
1562 return false;
1563 }
1564 }
1526 } 1565 }
1527 1566
1528 /* A vector-insert using a BIT_FIELD_REF is rewritable using 1567 /* A vector-insert using a BIT_FIELD_REF is rewritable using
1529 BIT_INSERT_EXPR. */ 1568 BIT_INSERT_EXPR. */
1530 if (TREE_CODE (lhs) == BIT_FIELD_REF 1569 if (TREE_CODE (lhs) == BIT_FIELD_REF
1858 && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0)) 1897 && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
1859 && DECL_P (sym) 1898 && DECL_P (sym)
1860 && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)) 1899 && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym))
1861 && VECTOR_TYPE_P (TREE_TYPE (sym)) 1900 && VECTOR_TYPE_P (TREE_TYPE (sym))
1862 && TYPE_MODE (TREE_TYPE (sym)) != BLKmode 1901 && TYPE_MODE (TREE_TYPE (sym)) != BLKmode
1863 && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)), 1902 /* If it is a full replacement we can do better below. */
1864 TYPE_SIZE_UNIT 1903 && maybe_ne (wi::to_poly_offset
1865 (TREE_TYPE (TREE_TYPE (sym))), 0) 1904 (TYPE_SIZE_UNIT (TREE_TYPE (lhs))),
1866 && tree_fits_uhwi_p (TREE_OPERAND (lhs, 1)) 1905 wi::to_poly_offset
1867 && tree_int_cst_lt (TREE_OPERAND (lhs, 1), 1906 (TYPE_SIZE_UNIT (TREE_TYPE (sym))))
1868 TYPE_SIZE_UNIT (TREE_TYPE (sym))) 1907 && known_ge (mem_ref_offset (lhs), 0)
1869 && (tree_to_uhwi (TREE_OPERAND (lhs, 1)) 1908 && known_gt (wi::to_poly_offset
1870 % tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (lhs)))) == 0) 1909 (TYPE_SIZE_UNIT (TREE_TYPE (sym))),
1910 mem_ref_offset (lhs))
1911 && multiple_of_p (sizetype,
1912 TREE_OPERAND (lhs, 1),
1913 TYPE_SIZE_UNIT (TREE_TYPE (lhs))))
1871 { 1914 {
1872 tree val = gimple_assign_rhs1 (stmt); 1915 tree val = gimple_assign_rhs1 (stmt);
1873 if (! types_compatible_p (TREE_TYPE (val), 1916 if (! types_compatible_p (TREE_TYPE (val),
1874 TREE_TYPE (TREE_TYPE (sym)))) 1917 TREE_TYPE (TREE_TYPE (sym))))
1875 { 1918 {
1876 tree tem = make_ssa_name (TREE_TYPE (TREE_TYPE (sym))); 1919 poly_uint64 lhs_bits, nelts;
1920 tree temtype = TREE_TYPE (TREE_TYPE (sym));
1921 if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)),
1922 &lhs_bits)
1923 && multiple_p (lhs_bits,
1924 tree_to_uhwi
1925 (TYPE_SIZE (TREE_TYPE
1926 (TREE_TYPE (sym)))),
1927 &nelts)
1928 && maybe_ne (nelts, 1u))
1929 temtype = build_vector_type (temtype, nelts);
1930 tree tem = make_ssa_name (temtype);
1877 gimple *pun 1931 gimple *pun
1878 = gimple_build_assign (tem, 1932 = gimple_build_assign (tem,
1879 build1 (VIEW_CONVERT_EXPR, 1933 build1 (VIEW_CONVERT_EXPR,
1880 TREE_TYPE (tem), val)); 1934 TREE_TYPE (tem), val));
1881 gsi_insert_before (&gsi, pun, GSI_SAME_STMT); 1935 gsi_insert_before (&gsi, pun, GSI_SAME_STMT);
1965 else 2019 else
1966 { 2020 {
1967 /* In ASAN_MARK (UNPOISON, &b, ...) the variable 2021 /* In ASAN_MARK (UNPOISON, &b, ...) the variable
1968 is uninitialized. Avoid dependencies on 2022 is uninitialized. Avoid dependencies on
1969 previous out of scope value. */ 2023 previous out of scope value. */
1970 tree clobber 2024 tree clobber = build_clobber (TREE_TYPE (var));
1971 = build_constructor (TREE_TYPE (var), NULL);
1972 TREE_THIS_VOLATILE (clobber) = 1;
1973 gimple *g = gimple_build_assign (var, clobber); 2025 gimple *g = gimple_build_assign (var, clobber);
1974 gsi_replace (&gsi, g, GSI_SAME_STMT); 2026 gsi_replace (&gsi, g, GSI_SAME_STMT);
1975 } 2027 }
1976 continue; 2028 continue;
1977 } 2029 }