Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-complex.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 /* Lower complex number operations to scalar operations. | 1 /* Lower complex number operations to scalar operations. |
2 Copyright (C) 2004-2018 Free Software Foundation, Inc. | 2 Copyright (C) 2004-2020 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GCC. | 4 This file is part of GCC. |
5 | 5 |
6 GCC is free software; you can redistribute it and/or modify it | 6 GCC is free software; you can redistribute it and/or modify it |
7 under the terms of the GNU General Public License as published by the | 7 under the terms of the GNU General Public License as published by the |
78 /* Vector of PHI triplets (original complex PHI and corresponding real and | 78 /* Vector of PHI triplets (original complex PHI and corresponding real and |
79 imag PHIs if real and/or imag PHIs contain temporarily | 79 imag PHIs if real and/or imag PHIs contain temporarily |
80 non-SSA_NAME/non-invariant args that need to be replaced by SSA_NAMEs. */ | 80 non-SSA_NAME/non-invariant args that need to be replaced by SSA_NAMEs. */ |
81 static vec<gphi *> phis_to_revisit; | 81 static vec<gphi *> phis_to_revisit; |
82 | 82 |
83 /* BBs that need EH cleanup. */ | |
84 static bitmap need_eh_cleanup; | |
85 | |
83 /* Lookup UID in the complex_variable_components hashtable and return the | 86 /* Lookup UID in the complex_variable_components hashtable and return the |
84 associated tree. */ | 87 associated tree. */ |
85 static tree | 88 static tree |
86 cvc_lookup (unsigned int uid) | 89 cvc_lookup (unsigned int uid) |
87 { | 90 { |
693 /* Update an assignment to a complex variable in place. */ | 696 /* Update an assignment to a complex variable in place. */ |
694 | 697 |
695 static void | 698 static void |
696 update_complex_assignment (gimple_stmt_iterator *gsi, tree r, tree i) | 699 update_complex_assignment (gimple_stmt_iterator *gsi, tree r, tree i) |
697 { | 700 { |
698 gimple *stmt; | 701 gimple *old_stmt = gsi_stmt (*gsi); |
699 | |
700 gimple_assign_set_rhs_with_ops (gsi, COMPLEX_EXPR, r, i); | 702 gimple_assign_set_rhs_with_ops (gsi, COMPLEX_EXPR, r, i); |
701 stmt = gsi_stmt (*gsi); | 703 gimple *stmt = gsi_stmt (*gsi); |
702 update_stmt (stmt); | 704 update_stmt (stmt); |
703 if (maybe_clean_eh_stmt (stmt)) | 705 if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt)) |
704 gimple_purge_dead_eh_edges (gimple_bb (stmt)); | 706 bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index); |
705 | 707 |
706 update_complex_components (gsi, gsi_stmt (*gsi), r, i); | 708 update_complex_components (gsi, gsi_stmt (*gsi), r, i); |
707 } | 709 } |
708 | 710 |
709 | 711 |
1140 expand_complex_libcall (gsi, type, ar, ai, br, bi, | 1142 expand_complex_libcall (gsi, type, ar, ai, br, bi, |
1141 MULT_EXPR, true); | 1143 MULT_EXPR, true); |
1142 return; | 1144 return; |
1143 } | 1145 } |
1144 | 1146 |
1147 if (!HONOR_NANS (inner_type)) | |
1148 { | |
1149 /* If we are not worrying about NaNs expand to | |
1150 (ar*br - ai*bi) + i(ar*bi + br*ai) directly. */ | |
1151 expand_complex_multiplication_components (gsi, inner_type, | |
1152 ar, ai, br, bi, | |
1153 &rr, &ri); | |
1154 break; | |
1155 } | |
1156 | |
1145 /* Else, expand x = a * b into | 1157 /* Else, expand x = a * b into |
1146 x = (ar*br - ai*bi) + i(ar*bi + br*ai); | 1158 x = (ar*br - ai*bi) + i(ar*bi + br*ai); |
1147 if (isunordered (__real__ x, __imag__ x)) | 1159 if (isunordered (__real__ x, __imag__ x)) |
1148 x = __muldc3 (a, b); */ | 1160 x = __muldc3 (a, b); */ |
1149 | 1161 |
1150 tree tmpr, tmpi; | 1162 tree tmpr, tmpi; |
1151 expand_complex_multiplication_components (gsi, inner_type, ar, ai, | 1163 expand_complex_multiplication_components (gsi, inner_type, ar, ai, |
1152 br, bi, &tmpr, &tmpi); | 1164 br, bi, &tmpr, &tmpi); |
1153 | 1165 |
1154 gimple *check | 1166 gimple *check |
1155 = gimple_build_cond (UNORDERED_EXPR, tmpr, tmpi, | 1167 = gimple_build_cond (UNORDERED_EXPR, tmpr, tmpi, |
1156 NULL_TREE, NULL_TREE); | 1168 NULL_TREE, NULL_TREE); |
1157 | 1169 |
1163 gsi_prev (gsi); | 1175 gsi_prev (gsi); |
1164 basic_block cond_bb | 1176 basic_block cond_bb |
1165 = insert_cond_bb (gsi_bb (*gsi), gsi_stmt (*gsi), check, | 1177 = insert_cond_bb (gsi_bb (*gsi), gsi_stmt (*gsi), check, |
1166 profile_probability::very_unlikely ()); | 1178 profile_probability::very_unlikely ()); |
1167 | 1179 |
1168 | |
1169 gimple_stmt_iterator cond_bb_gsi = gsi_last_bb (cond_bb); | 1180 gimple_stmt_iterator cond_bb_gsi = gsi_last_bb (cond_bb); |
1170 gsi_insert_after (&cond_bb_gsi, gimple_build_nop (), GSI_NEW_STMT); | 1181 gsi_insert_after (&cond_bb_gsi, gimple_build_nop (), GSI_NEW_STMT); |
1171 | 1182 |
1172 tree libcall_res | 1183 tree libcall_res |
1173 = expand_complex_libcall (&cond_bb_gsi, type, ar, ai, br, | 1184 = expand_complex_libcall (&cond_bb_gsi, type, ar, ai, br, |
1174 bi, MULT_EXPR, false); | 1185 bi, MULT_EXPR, false); |
1175 tree cond_real = gimplify_build1 (&cond_bb_gsi, REALPART_EXPR, | 1186 tree cond_real = gimplify_build1 (&cond_bb_gsi, REALPART_EXPR, |
1176 inner_type, libcall_res); | 1187 inner_type, libcall_res); |
1177 tree cond_imag = gimplify_build1 (&cond_bb_gsi, IMAGPART_EXPR, | 1188 tree cond_imag = gimplify_build1 (&cond_bb_gsi, IMAGPART_EXPR, |
1178 inner_type, libcall_res); | 1189 inner_type, libcall_res); |
1179 | 1190 |
1186 ri = make_ssa_name (inner_type); | 1197 ri = make_ssa_name (inner_type); |
1187 edge cond_to_join = single_succ_edge (cond_bb); | 1198 edge cond_to_join = single_succ_edge (cond_bb); |
1188 edge orig_to_join = find_edge (orig_bb, join_bb); | 1199 edge orig_to_join = find_edge (orig_bb, join_bb); |
1189 | 1200 |
1190 gphi *real_phi = create_phi_node (rr, gsi_bb (*gsi)); | 1201 gphi *real_phi = create_phi_node (rr, gsi_bb (*gsi)); |
1191 add_phi_arg (real_phi, cond_real, cond_to_join, | 1202 add_phi_arg (real_phi, cond_real, cond_to_join, UNKNOWN_LOCATION); |
1192 UNKNOWN_LOCATION); | |
1193 add_phi_arg (real_phi, tmpr, orig_to_join, UNKNOWN_LOCATION); | 1203 add_phi_arg (real_phi, tmpr, orig_to_join, UNKNOWN_LOCATION); |
1194 | 1204 |
1195 gphi *imag_phi = create_phi_node (ri, gsi_bb (*gsi)); | 1205 gphi *imag_phi = create_phi_node (ri, gsi_bb (*gsi)); |
1196 add_phi_arg (imag_phi, cond_imag, cond_to_join, | 1206 add_phi_arg (imag_phi, cond_imag, cond_to_join, UNKNOWN_LOCATION); |
1197 UNKNOWN_LOCATION); | |
1198 add_phi_arg (imag_phi, tmpi, orig_to_join, UNKNOWN_LOCATION); | 1207 add_phi_arg (imag_phi, tmpi, orig_to_join, UNKNOWN_LOCATION); |
1199 } | 1208 } |
1200 else | 1209 else |
1201 /* If we are not worrying about NaNs expand to | 1210 /* If we are not worrying about NaNs expand to |
1202 (ar*br - ai*bi) + i(ar*bi + br*ai) directly. */ | 1211 (ar*br - ai*bi) + i(ar*bi + br*ai) directly. */ |
1203 expand_complex_multiplication_components (gsi, inner_type, ar, ai, | 1212 expand_complex_multiplication_components (gsi, inner_type, ar, ai, |
1204 br, bi, &rr, &ri); | 1213 br, bi, &rr, &ri); |
1205 break; | 1214 break; |
1206 | 1215 |
1207 default: | 1216 default: |
1208 gcc_unreachable (); | 1217 gcc_unreachable (); |
1209 } | 1218 } |
1556 default: | 1565 default: |
1557 gcc_unreachable (); | 1566 gcc_unreachable (); |
1558 } | 1567 } |
1559 | 1568 |
1560 update_stmt (stmt); | 1569 update_stmt (stmt); |
1570 if (maybe_clean_eh_stmt (stmt)) | |
1571 bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index); | |
1561 } | 1572 } |
1562 | 1573 |
1563 /* Expand inline asm that sets some complex SSA_NAMEs. */ | 1574 /* Expand inline asm that sets some complex SSA_NAMEs. */ |
1564 | 1575 |
1565 static void | 1576 static void |
1676 if (is_gimple_assign (stmt)) | 1687 if (is_gimple_assign (stmt)) |
1677 { | 1688 { |
1678 ac = gimple_assign_rhs1 (stmt); | 1689 ac = gimple_assign_rhs1 (stmt); |
1679 bc = (gimple_num_ops (stmt) > 2) ? gimple_assign_rhs2 (stmt) : NULL; | 1690 bc = (gimple_num_ops (stmt) > 2) ? gimple_assign_rhs2 (stmt) : NULL; |
1680 } | 1691 } |
1681 /* GIMPLE_CALL can not get here. */ | 1692 /* GIMPLE_CALL cannot get here. */ |
1682 else | 1693 else |
1683 { | 1694 { |
1684 ac = gimple_cond_lhs (stmt); | 1695 ac = gimple_cond_lhs (stmt); |
1685 bc = gimple_cond_rhs (stmt); | 1696 bc = gimple_cond_rhs (stmt); |
1686 } | 1697 } |
1768 complex_lattice_values.safe_grow_cleared (num_ssa_names); | 1779 complex_lattice_values.safe_grow_cleared (num_ssa_names); |
1769 | 1780 |
1770 init_parameter_lattice_values (); | 1781 init_parameter_lattice_values (); |
1771 class complex_propagate complex_propagate; | 1782 class complex_propagate complex_propagate; |
1772 complex_propagate.ssa_propagate (); | 1783 complex_propagate.ssa_propagate (); |
1784 | |
1785 need_eh_cleanup = BITMAP_ALLOC (NULL); | |
1773 | 1786 |
1774 complex_variable_components = new int_tree_htab_type (10); | 1787 complex_variable_components = new int_tree_htab_type (10); |
1775 | 1788 |
1776 complex_ssa_name_components.create (2 * num_ssa_names); | 1789 complex_ssa_name_components.create (2 * num_ssa_names); |
1777 complex_ssa_name_components.safe_grow_cleared (2 * num_ssa_names); | 1790 complex_ssa_name_components.safe_grow_cleared (2 * num_ssa_names); |
1814 phis_to_revisit.release (); | 1827 phis_to_revisit.release (); |
1815 } | 1828 } |
1816 | 1829 |
1817 gsi_commit_edge_inserts (); | 1830 gsi_commit_edge_inserts (); |
1818 | 1831 |
1832 unsigned todo | |
1833 = gimple_purge_all_dead_eh_edges (need_eh_cleanup) ? TODO_cleanup_cfg : 0; | |
1834 BITMAP_FREE (need_eh_cleanup); | |
1835 | |
1819 delete complex_variable_components; | 1836 delete complex_variable_components; |
1820 complex_variable_components = NULL; | 1837 complex_variable_components = NULL; |
1821 complex_ssa_name_components.release (); | 1838 complex_ssa_name_components.release (); |
1822 complex_lattice_values.release (); | 1839 complex_lattice_values.release (); |
1823 return 0; | 1840 return todo; |
1824 } | 1841 } |
1825 | 1842 |
1826 namespace { | 1843 namespace { |
1827 | 1844 |
1828 const pass_data pass_data_lower_complex = | 1845 const pass_data pass_data_lower_complex = |