1 /* Lower complex number operations to scalar operations.
2 Copyright (C) 2004-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
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
8 Free Software Foundation; either version 3, or (at your option) any
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 #include "fold-const.h"
28 #include "stor-layout.h"
31 #include "hard-reg-set.h"
33 #include "dominance.h"
35 #include "basic-block.h"
36 #include "tree-ssa-alias.h"
37 #include "internal-fn.h"
39 #include "gimple-expr.h"
42 #include "gimple-iterator.h"
43 #include "gimplify-me.h"
44 #include "gimple-ssa.h"
46 #include "tree-phinodes.h"
47 #include "ssa-iterators.h"
48 #include "stringpool.h"
49 #include "tree-ssanames.h"
51 #include "insn-config.h"
62 #include "tree-iterator.h"
63 #include "tree-pass.h"
64 #include "tree-ssa-propagate.h"
65 #include "tree-hasher.h"
69 /* For each complex ssa name, a lattice value. We're interested in finding
70 out whether a complex number is degenerate in some way, having only real
71 or only complex parts. */
81 /* The type complex_lattice_t holds combinations of the above
83 typedef int complex_lattice_t
;
85 #define PAIR(a, b) ((a) << 2 | (b))
88 static vec
<complex_lattice_t
> complex_lattice_values
;
90 /* For each complex variable, a pair of variables for the components exists in
92 static int_tree_htab_type
*complex_variable_components
;
94 /* For each complex SSA_NAME, a pair of ssa names for the components. */
95 static vec
<tree
> complex_ssa_name_components
;
97 /* Lookup UID in the complex_variable_components hashtable and return the
100 cvc_lookup (unsigned int uid
)
102 struct int_tree_map in
;
104 return complex_variable_components
->find_with_hash (in
, uid
).to
;
107 /* Insert the pair UID, TO into the complex_variable_components hashtable. */
110 cvc_insert (unsigned int uid
, tree to
)
116 loc
= complex_variable_components
->find_slot_with_hash (h
, uid
, INSERT
);
121 /* Return true if T is not a zero constant. In the case of real values,
122 we're only interested in +0.0. */
125 some_nonzerop (tree t
)
129 /* Operations with real or imaginary part of a complex number zero
130 cannot be treated the same as operations with a real or imaginary
131 operand if we care about the signs of zeros in the result. */
132 if (TREE_CODE (t
) == REAL_CST
&& !flag_signed_zeros
)
133 zerop
= REAL_VALUES_IDENTICAL (TREE_REAL_CST (t
), dconst0
);
134 else if (TREE_CODE (t
) == FIXED_CST
)
135 zerop
= fixed_zerop (t
);
136 else if (TREE_CODE (t
) == INTEGER_CST
)
137 zerop
= integer_zerop (t
);
143 /* Compute a lattice value from the components of a complex type REAL
146 static complex_lattice_t
147 find_lattice_value_parts (tree real
, tree imag
)
150 complex_lattice_t ret
;
152 r
= some_nonzerop (real
);
153 i
= some_nonzerop (imag
);
154 ret
= r
* ONLY_REAL
+ i
* ONLY_IMAG
;
156 /* ??? On occasion we could do better than mapping 0+0i to real, but we
157 certainly don't want to leave it UNINITIALIZED, which eventually gets
158 mapped to VARYING. */
159 if (ret
== UNINITIALIZED
)
166 /* Compute a lattice value from gimple_val T. */
168 static complex_lattice_t
169 find_lattice_value (tree t
)
173 switch (TREE_CODE (t
))
176 return complex_lattice_values
[SSA_NAME_VERSION (t
)];
179 real
= TREE_REALPART (t
);
180 imag
= TREE_IMAGPART (t
);
187 return find_lattice_value_parts (real
, imag
);
190 /* Determine if LHS is something for which we're interested in seeing
191 simulation results. */
194 is_complex_reg (tree lhs
)
196 return TREE_CODE (TREE_TYPE (lhs
)) == COMPLEX_TYPE
&& is_gimple_reg (lhs
);
199 /* Mark the incoming parameters to the function as VARYING. */
202 init_parameter_lattice_values (void)
206 for (parm
= DECL_ARGUMENTS (cfun
->decl
); parm
; parm
= DECL_CHAIN (parm
))
207 if (is_complex_reg (parm
)
208 && (ssa_name
= ssa_default_def (cfun
, parm
)) != NULL_TREE
)
209 complex_lattice_values
[SSA_NAME_VERSION (ssa_name
)] = VARYING
;
212 /* Initialize simulation state for each statement. Return false if we
213 found no statements we want to simulate, and thus there's nothing
214 for the entire pass to do. */
217 init_dont_simulate_again (void)
220 bool saw_a_complex_op
= false;
222 FOR_EACH_BB_FN (bb
, cfun
)
224 for (gphi_iterator gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
);
227 gphi
*phi
= gsi
.phi ();
228 prop_set_simulate_again (phi
,
229 is_complex_reg (gimple_phi_result (phi
)));
232 for (gimple_stmt_iterator gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
);
239 stmt
= gsi_stmt (gsi
);
240 op0
= op1
= NULL_TREE
;
242 /* Most control-altering statements must be initially
243 simulated, else we won't cover the entire cfg. */
244 sim_again_p
= stmt_ends_bb_p (stmt
);
246 switch (gimple_code (stmt
))
249 if (gimple_call_lhs (stmt
))
250 sim_again_p
= is_complex_reg (gimple_call_lhs (stmt
));
254 sim_again_p
= is_complex_reg (gimple_assign_lhs (stmt
));
255 if (gimple_assign_rhs_code (stmt
) == REALPART_EXPR
256 || gimple_assign_rhs_code (stmt
) == IMAGPART_EXPR
)
257 op0
= TREE_OPERAND (gimple_assign_rhs1 (stmt
), 0);
259 op0
= gimple_assign_rhs1 (stmt
);
260 if (gimple_num_ops (stmt
) > 2)
261 op1
= gimple_assign_rhs2 (stmt
);
265 op0
= gimple_cond_lhs (stmt
);
266 op1
= gimple_cond_rhs (stmt
);
274 switch (gimple_expr_code (stmt
))
286 if (TREE_CODE (TREE_TYPE (op0
)) == COMPLEX_TYPE
287 || TREE_CODE (TREE_TYPE (op1
)) == COMPLEX_TYPE
)
288 saw_a_complex_op
= true;
293 if (TREE_CODE (TREE_TYPE (op0
)) == COMPLEX_TYPE
)
294 saw_a_complex_op
= true;
299 /* The total store transformation performed during
300 gimplification creates such uninitialized loads
301 and we need to lower the statement to be able
303 if (TREE_CODE (op0
) == SSA_NAME
304 && ssa_undefined_value_p (op0
))
305 saw_a_complex_op
= true;
312 prop_set_simulate_again (stmt
, sim_again_p
);
316 return saw_a_complex_op
;
320 /* Evaluate statement STMT against the complex lattice defined above. */
322 static enum ssa_prop_result
323 complex_visit_stmt (gimple stmt
, edge
*taken_edge_p ATTRIBUTE_UNUSED
,
326 complex_lattice_t new_l
, old_l
, op1_l
, op2_l
;
330 lhs
= gimple_get_lhs (stmt
);
331 /* Skip anything but GIMPLE_ASSIGN and GIMPLE_CALL with a lhs. */
333 return SSA_PROP_VARYING
;
335 /* These conditions should be satisfied due to the initial filter
336 set up in init_dont_simulate_again. */
337 gcc_assert (TREE_CODE (lhs
) == SSA_NAME
);
338 gcc_assert (TREE_CODE (TREE_TYPE (lhs
)) == COMPLEX_TYPE
);
341 ver
= SSA_NAME_VERSION (lhs
);
342 old_l
= complex_lattice_values
[ver
];
344 switch (gimple_expr_code (stmt
))
348 new_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
352 new_l
= find_lattice_value_parts (gimple_assign_rhs1 (stmt
),
353 gimple_assign_rhs2 (stmt
));
358 op1_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
359 op2_l
= find_lattice_value (gimple_assign_rhs2 (stmt
));
361 /* We've set up the lattice values such that IOR neatly
363 new_l
= op1_l
| op2_l
;
372 op1_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
373 op2_l
= find_lattice_value (gimple_assign_rhs2 (stmt
));
375 /* Obviously, if either varies, so does the result. */
376 if (op1_l
== VARYING
|| op2_l
== VARYING
)
378 /* Don't prematurely promote variables if we've not yet seen
380 else if (op1_l
== UNINITIALIZED
)
382 else if (op2_l
== UNINITIALIZED
)
386 /* At this point both numbers have only one component. If the
387 numbers are of opposite kind, the result is imaginary,
388 otherwise the result is real. The add/subtract translates
389 the real/imag from/to 0/1; the ^ performs the comparison. */
390 new_l
= ((op1_l
- ONLY_REAL
) ^ (op2_l
- ONLY_REAL
)) + ONLY_REAL
;
392 /* Don't allow the lattice value to flip-flop indefinitely. */
399 new_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
407 /* If nothing changed this round, let the propagator know. */
409 return SSA_PROP_NOT_INTERESTING
;
411 complex_lattice_values
[ver
] = new_l
;
412 return new_l
== VARYING
? SSA_PROP_VARYING
: SSA_PROP_INTERESTING
;
415 /* Evaluate a PHI node against the complex lattice defined above. */
417 static enum ssa_prop_result
418 complex_visit_phi (gphi
*phi
)
420 complex_lattice_t new_l
, old_l
;
425 lhs
= gimple_phi_result (phi
);
427 /* This condition should be satisfied due to the initial filter
428 set up in init_dont_simulate_again. */
429 gcc_assert (TREE_CODE (TREE_TYPE (lhs
)) == COMPLEX_TYPE
);
431 /* We've set up the lattice values such that IOR neatly models PHI meet. */
432 new_l
= UNINITIALIZED
;
433 for (i
= gimple_phi_num_args (phi
) - 1; i
>= 0; --i
)
434 new_l
|= find_lattice_value (gimple_phi_arg_def (phi
, i
));
436 ver
= SSA_NAME_VERSION (lhs
);
437 old_l
= complex_lattice_values
[ver
];
440 return SSA_PROP_NOT_INTERESTING
;
442 complex_lattice_values
[ver
] = new_l
;
443 return new_l
== VARYING
? SSA_PROP_VARYING
: SSA_PROP_INTERESTING
;
446 /* Create one backing variable for a complex component of ORIG. */
449 create_one_component_var (tree type
, tree orig
, const char *prefix
,
450 const char *suffix
, enum tree_code code
)
452 tree r
= create_tmp_var (type
, prefix
);
454 DECL_SOURCE_LOCATION (r
) = DECL_SOURCE_LOCATION (orig
);
455 DECL_ARTIFICIAL (r
) = 1;
457 if (DECL_NAME (orig
) && !DECL_IGNORED_P (orig
))
459 const char *name
= IDENTIFIER_POINTER (DECL_NAME (orig
));
461 DECL_NAME (r
) = get_identifier (ACONCAT ((name
, suffix
, NULL
)));
463 SET_DECL_DEBUG_EXPR (r
, build1 (code
, type
, orig
));
464 DECL_HAS_DEBUG_EXPR_P (r
) = 1;
465 DECL_IGNORED_P (r
) = 0;
466 TREE_NO_WARNING (r
) = TREE_NO_WARNING (orig
);
470 DECL_IGNORED_P (r
) = 1;
471 TREE_NO_WARNING (r
) = 1;
477 /* Retrieve a value for a complex component of VAR. */
480 get_component_var (tree var
, bool imag_p
)
482 size_t decl_index
= DECL_UID (var
) * 2 + imag_p
;
483 tree ret
= cvc_lookup (decl_index
);
487 ret
= create_one_component_var (TREE_TYPE (TREE_TYPE (var
)), var
,
488 imag_p
? "CI" : "CR",
489 imag_p
? "$imag" : "$real",
490 imag_p
? IMAGPART_EXPR
: REALPART_EXPR
);
491 cvc_insert (decl_index
, ret
);
497 /* Retrieve a value for a complex component of SSA_NAME. */
500 get_component_ssa_name (tree ssa_name
, bool imag_p
)
502 complex_lattice_t lattice
= find_lattice_value (ssa_name
);
503 size_t ssa_name_index
;
506 if (lattice
== (imag_p
? ONLY_REAL
: ONLY_IMAG
))
508 tree inner_type
= TREE_TYPE (TREE_TYPE (ssa_name
));
509 if (SCALAR_FLOAT_TYPE_P (inner_type
))
510 return build_real (inner_type
, dconst0
);
512 return build_int_cst (inner_type
, 0);
515 ssa_name_index
= SSA_NAME_VERSION (ssa_name
) * 2 + imag_p
;
516 ret
= complex_ssa_name_components
[ssa_name_index
];
519 if (SSA_NAME_VAR (ssa_name
))
520 ret
= get_component_var (SSA_NAME_VAR (ssa_name
), imag_p
);
522 ret
= TREE_TYPE (TREE_TYPE (ssa_name
));
523 ret
= make_ssa_name (ret
);
525 /* Copy some properties from the original. In particular, whether it
526 is used in an abnormal phi, and whether it's uninitialized. */
527 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ret
)
528 = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name
);
529 if (SSA_NAME_IS_DEFAULT_DEF (ssa_name
)
530 && TREE_CODE (SSA_NAME_VAR (ssa_name
)) == VAR_DECL
)
532 SSA_NAME_DEF_STMT (ret
) = SSA_NAME_DEF_STMT (ssa_name
);
533 set_ssa_default_def (cfun
, SSA_NAME_VAR (ret
), ret
);
536 complex_ssa_name_components
[ssa_name_index
] = ret
;
542 /* Set a value for a complex component of SSA_NAME, return a
543 gimple_seq of stuff that needs doing. */
546 set_component_ssa_name (tree ssa_name
, bool imag_p
, tree value
)
548 complex_lattice_t lattice
= find_lattice_value (ssa_name
);
549 size_t ssa_name_index
;
554 /* We know the value must be zero, else there's a bug in our lattice
555 analysis. But the value may well be a variable known to contain
556 zero. We should be safe ignoring it. */
557 if (lattice
== (imag_p
? ONLY_REAL
: ONLY_IMAG
))
560 /* If we've already assigned an SSA_NAME to this component, then this
561 means that our walk of the basic blocks found a use before the set.
562 This is fine. Now we should create an initialization for the value
563 we created earlier. */
564 ssa_name_index
= SSA_NAME_VERSION (ssa_name
) * 2 + imag_p
;
565 comp
= complex_ssa_name_components
[ssa_name_index
];
569 /* If we've nothing assigned, and the value we're given is already stable,
570 then install that as the value for this SSA_NAME. This preemptively
571 copy-propagates the value, which avoids unnecessary memory allocation. */
572 else if (is_gimple_min_invariant (value
)
573 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name
))
575 complex_ssa_name_components
[ssa_name_index
] = value
;
578 else if (TREE_CODE (value
) == SSA_NAME
579 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name
))
581 /* Replace an anonymous base value with the variable from cvc_lookup.
582 This should result in better debug info. */
583 if (SSA_NAME_VAR (ssa_name
)
584 && (!SSA_NAME_VAR (value
) || DECL_IGNORED_P (SSA_NAME_VAR (value
)))
585 && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name
)))
587 comp
= get_component_var (SSA_NAME_VAR (ssa_name
), imag_p
);
588 replace_ssa_name_symbol (value
, comp
);
591 complex_ssa_name_components
[ssa_name_index
] = value
;
595 /* Finally, we need to stabilize the result by installing the value into
598 comp
= get_component_ssa_name (ssa_name
, imag_p
);
600 /* Do all the work to assign VALUE to COMP. */
602 value
= force_gimple_operand (value
, &list
, false, NULL
);
603 last
= gimple_build_assign (comp
, value
);
604 gimple_seq_add_stmt (&list
, last
);
605 gcc_assert (SSA_NAME_DEF_STMT (comp
) == last
);
610 /* Extract the real or imaginary part of a complex variable or constant.
611 Make sure that it's a proper gimple_val and gimplify it if not.
612 Emit any new code before gsi. */
615 extract_component (gimple_stmt_iterator
*gsi
, tree t
, bool imagpart_p
,
618 switch (TREE_CODE (t
))
621 return imagpart_p
? TREE_IMAGPART (t
) : TREE_REALPART (t
);
631 case VIEW_CONVERT_EXPR
:
634 tree inner_type
= TREE_TYPE (TREE_TYPE (t
));
636 t
= build1 ((imagpart_p
? IMAGPART_EXPR
: REALPART_EXPR
),
637 inner_type
, unshare_expr (t
));
640 t
= force_gimple_operand_gsi (gsi
, t
, true, NULL
, true,
647 return get_component_ssa_name (t
, imagpart_p
);
654 /* Update the complex components of the ssa name on the lhs of STMT. */
657 update_complex_components (gimple_stmt_iterator
*gsi
, gimple stmt
, tree r
,
663 lhs
= gimple_get_lhs (stmt
);
665 list
= set_component_ssa_name (lhs
, false, r
);
667 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
669 list
= set_component_ssa_name (lhs
, true, i
);
671 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
675 update_complex_components_on_edge (edge e
, tree lhs
, tree r
, tree i
)
679 list
= set_component_ssa_name (lhs
, false, r
);
681 gsi_insert_seq_on_edge (e
, list
);
683 list
= set_component_ssa_name (lhs
, true, i
);
685 gsi_insert_seq_on_edge (e
, list
);
689 /* Update an assignment to a complex variable in place. */
692 update_complex_assignment (gimple_stmt_iterator
*gsi
, tree r
, tree i
)
696 gimple_assign_set_rhs_with_ops (gsi
, COMPLEX_EXPR
, r
, i
);
697 stmt
= gsi_stmt (*gsi
);
699 if (maybe_clean_eh_stmt (stmt
))
700 gimple_purge_dead_eh_edges (gimple_bb (stmt
));
702 if (gimple_in_ssa_p (cfun
))
703 update_complex_components (gsi
, gsi_stmt (*gsi
), r
, i
);
707 /* Generate code at the entry point of the function to initialize the
708 component variables for a complex parameter. */
711 update_parameter_components (void)
713 edge entry_edge
= single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun
));
716 for (parm
= DECL_ARGUMENTS (cfun
->decl
); parm
; parm
= DECL_CHAIN (parm
))
718 tree type
= TREE_TYPE (parm
);
721 if (TREE_CODE (type
) != COMPLEX_TYPE
|| !is_gimple_reg (parm
))
724 type
= TREE_TYPE (type
);
725 ssa_name
= ssa_default_def (cfun
, parm
);
729 r
= build1 (REALPART_EXPR
, type
, ssa_name
);
730 i
= build1 (IMAGPART_EXPR
, type
, ssa_name
);
731 update_complex_components_on_edge (entry_edge
, ssa_name
, r
, i
);
735 /* Generate code to set the component variables of a complex variable
736 to match the PHI statements in block BB. */
739 update_phi_components (basic_block bb
)
743 for (gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
745 gphi
*phi
= gsi
.phi ();
747 if (is_complex_reg (gimple_phi_result (phi
)))
750 gimple pr
= NULL
, pi
= NULL
;
753 lr
= get_component_ssa_name (gimple_phi_result (phi
), false);
754 if (TREE_CODE (lr
) == SSA_NAME
)
755 pr
= create_phi_node (lr
, bb
);
757 li
= get_component_ssa_name (gimple_phi_result (phi
), true);
758 if (TREE_CODE (li
) == SSA_NAME
)
759 pi
= create_phi_node (li
, bb
);
761 for (i
= 0, n
= gimple_phi_num_args (phi
); i
< n
; ++i
)
763 tree comp
, arg
= gimple_phi_arg_def (phi
, i
);
766 comp
= extract_component (NULL
, arg
, false, false);
767 SET_PHI_ARG_DEF (pr
, i
, comp
);
771 comp
= extract_component (NULL
, arg
, true, false);
772 SET_PHI_ARG_DEF (pi
, i
, comp
);
779 /* Expand a complex move to scalars. */
782 expand_complex_move (gimple_stmt_iterator
*gsi
, tree type
)
784 tree inner_type
= TREE_TYPE (type
);
786 gimple stmt
= gsi_stmt (*gsi
);
788 if (is_gimple_assign (stmt
))
790 lhs
= gimple_assign_lhs (stmt
);
791 if (gimple_num_ops (stmt
) == 2)
792 rhs
= gimple_assign_rhs1 (stmt
);
796 else if (is_gimple_call (stmt
))
798 lhs
= gimple_call_lhs (stmt
);
804 if (TREE_CODE (lhs
) == SSA_NAME
)
806 if (is_ctrl_altering_stmt (stmt
))
810 /* The value is not assigned on the exception edges, so we need not
811 concern ourselves there. We do need to update on the fallthru
813 e
= find_fallthru_edge (gsi_bb (*gsi
)->succs
);
817 r
= build1 (REALPART_EXPR
, inner_type
, lhs
);
818 i
= build1 (IMAGPART_EXPR
, inner_type
, lhs
);
819 update_complex_components_on_edge (e
, lhs
, r
, i
);
821 else if (is_gimple_call (stmt
)
822 || gimple_has_side_effects (stmt
)
823 || gimple_assign_rhs_code (stmt
) == PAREN_EXPR
)
825 r
= build1 (REALPART_EXPR
, inner_type
, lhs
);
826 i
= build1 (IMAGPART_EXPR
, inner_type
, lhs
);
827 update_complex_components (gsi
, stmt
, r
, i
);
831 if (gimple_assign_rhs_code (stmt
) != COMPLEX_EXPR
)
833 r
= extract_component (gsi
, rhs
, 0, true);
834 i
= extract_component (gsi
, rhs
, 1, true);
838 r
= gimple_assign_rhs1 (stmt
);
839 i
= gimple_assign_rhs2 (stmt
);
841 update_complex_assignment (gsi
, r
, i
);
844 else if (rhs
&& TREE_CODE (rhs
) == SSA_NAME
&& !TREE_SIDE_EFFECTS (lhs
))
850 loc
= gimple_location (stmt
);
851 r
= extract_component (gsi
, rhs
, 0, false);
852 i
= extract_component (gsi
, rhs
, 1, false);
854 x
= build1 (REALPART_EXPR
, inner_type
, unshare_expr (lhs
));
855 t
= gimple_build_assign (x
, r
);
856 gimple_set_location (t
, loc
);
857 gsi_insert_before (gsi
, t
, GSI_SAME_STMT
);
859 if (stmt
== gsi_stmt (*gsi
))
861 x
= build1 (IMAGPART_EXPR
, inner_type
, unshare_expr (lhs
));
862 gimple_assign_set_lhs (stmt
, x
);
863 gimple_assign_set_rhs1 (stmt
, i
);
867 x
= build1 (IMAGPART_EXPR
, inner_type
, unshare_expr (lhs
));
868 t
= gimple_build_assign (x
, i
);
869 gimple_set_location (t
, loc
);
870 gsi_insert_before (gsi
, t
, GSI_SAME_STMT
);
872 stmt
= gsi_stmt (*gsi
);
873 gcc_assert (gimple_code (stmt
) == GIMPLE_RETURN
);
874 gimple_return_set_retval (as_a
<greturn
*> (stmt
), lhs
);
881 /* Expand complex addition to scalars:
882 a + b = (ar + br) + i(ai + bi)
883 a - b = (ar - br) + i(ai + bi)
887 expand_complex_addition (gimple_stmt_iterator
*gsi
, tree inner_type
,
888 tree ar
, tree ai
, tree br
, tree bi
,
890 complex_lattice_t al
, complex_lattice_t bl
)
894 switch (PAIR (al
, bl
))
896 case PAIR (ONLY_REAL
, ONLY_REAL
):
897 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
901 case PAIR (ONLY_REAL
, ONLY_IMAG
):
903 if (code
== MINUS_EXPR
)
904 ri
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, ai
, bi
);
909 case PAIR (ONLY_IMAG
, ONLY_REAL
):
910 if (code
== MINUS_EXPR
)
911 rr
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, ar
, br
);
917 case PAIR (ONLY_IMAG
, ONLY_IMAG
):
919 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
922 case PAIR (VARYING
, ONLY_REAL
):
923 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
927 case PAIR (VARYING
, ONLY_IMAG
):
929 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
932 case PAIR (ONLY_REAL
, VARYING
):
933 if (code
== MINUS_EXPR
)
935 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
939 case PAIR (ONLY_IMAG
, VARYING
):
940 if (code
== MINUS_EXPR
)
943 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
946 case PAIR (VARYING
, VARYING
):
948 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
949 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
956 update_complex_assignment (gsi
, rr
, ri
);
959 /* Expand a complex multiplication or division to a libcall to the c99
960 compliant routines. */
963 expand_complex_libcall (gimple_stmt_iterator
*gsi
, tree ar
, tree ai
,
964 tree br
, tree bi
, enum tree_code code
)
967 enum built_in_function bcode
;
972 old_stmt
= gsi_stmt (*gsi
);
973 lhs
= gimple_assign_lhs (old_stmt
);
974 type
= TREE_TYPE (lhs
);
976 mode
= TYPE_MODE (type
);
977 gcc_assert (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
);
979 if (code
== MULT_EXPR
)
980 bcode
= ((enum built_in_function
)
981 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
982 else if (code
== RDIV_EXPR
)
983 bcode
= ((enum built_in_function
)
984 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
987 fn
= builtin_decl_explicit (bcode
);
989 stmt
= gimple_build_call (fn
, 4, ar
, ai
, br
, bi
);
990 gimple_call_set_lhs (stmt
, lhs
);
992 gsi_replace (gsi
, stmt
, false);
994 if (maybe_clean_or_replace_eh_stmt (old_stmt
, stmt
))
995 gimple_purge_dead_eh_edges (gsi_bb (*gsi
));
997 if (gimple_in_ssa_p (cfun
))
999 type
= TREE_TYPE (type
);
1000 update_complex_components (gsi
, stmt
,
1001 build1 (REALPART_EXPR
, type
, lhs
),
1002 build1 (IMAGPART_EXPR
, type
, lhs
));
1003 SSA_NAME_DEF_STMT (lhs
) = stmt
;
1007 /* Expand complex multiplication to scalars:
1008 a * b = (ar*br - ai*bi) + i(ar*bi + br*ai)
1012 expand_complex_multiplication (gimple_stmt_iterator
*gsi
, tree inner_type
,
1013 tree ar
, tree ai
, tree br
, tree bi
,
1014 complex_lattice_t al
, complex_lattice_t bl
)
1020 complex_lattice_t tl
;
1021 rr
= ar
, ar
= br
, br
= rr
;
1022 ri
= ai
, ai
= bi
, bi
= ri
;
1023 tl
= al
, al
= bl
, bl
= tl
;
1026 switch (PAIR (al
, bl
))
1028 case PAIR (ONLY_REAL
, ONLY_REAL
):
1029 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1033 case PAIR (ONLY_IMAG
, ONLY_REAL
):
1035 if (TREE_CODE (ai
) == REAL_CST
1036 && REAL_VALUES_IDENTICAL (TREE_REAL_CST (ai
), dconst1
))
1039 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1042 case PAIR (ONLY_IMAG
, ONLY_IMAG
):
1043 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1044 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, rr
);
1048 case PAIR (VARYING
, ONLY_REAL
):
1049 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1050 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1053 case PAIR (VARYING
, ONLY_IMAG
):
1054 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1055 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, rr
);
1056 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1059 case PAIR (VARYING
, VARYING
):
1060 if (flag_complex_method
== 2 && SCALAR_FLOAT_TYPE_P (inner_type
))
1062 expand_complex_libcall (gsi
, ar
, ai
, br
, bi
, MULT_EXPR
);
1067 tree t1
, t2
, t3
, t4
;
1069 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1070 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1071 t3
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1073 /* Avoid expanding redundant multiplication for the common
1074 case of squaring a complex number. */
1075 if (ar
== br
&& ai
== bi
)
1078 t4
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1080 rr
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, t2
);
1081 ri
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t3
, t4
);
1089 update_complex_assignment (gsi
, rr
, ri
);
1092 /* Keep this algorithm in sync with fold-const.c:const_binop().
1094 Expand complex division to scalars, straightforward algorithm.
1095 a / b = ((ar*br + ai*bi)/t) + i((ai*br - ar*bi)/t)
1100 expand_complex_div_straight (gimple_stmt_iterator
*gsi
, tree inner_type
,
1101 tree ar
, tree ai
, tree br
, tree bi
,
1102 enum tree_code code
)
1104 tree rr
, ri
, div
, t1
, t2
, t3
;
1106 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, br
, br
);
1107 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, bi
, bi
);
1108 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, t2
);
1110 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1111 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1112 t3
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, t2
);
1113 rr
= gimplify_build2 (gsi
, code
, inner_type
, t3
, div
);
1115 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1116 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1117 t3
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, t2
);
1118 ri
= gimplify_build2 (gsi
, code
, inner_type
, t3
, div
);
1120 update_complex_assignment (gsi
, rr
, ri
);
1123 /* Keep this algorithm in sync with fold-const.c:const_binop().
1125 Expand complex division to scalars, modified algorithm to minimize
1126 overflow with wide input ranges. */
1129 expand_complex_div_wide (gimple_stmt_iterator
*gsi
, tree inner_type
,
1130 tree ar
, tree ai
, tree br
, tree bi
,
1131 enum tree_code code
)
1133 tree rr
, ri
, ratio
, div
, t1
, t2
, tr
, ti
, compare
;
1134 basic_block bb_cond
, bb_true
, bb_false
, bb_join
;
1137 /* Examine |br| < |bi|, and branch. */
1138 t1
= gimplify_build1 (gsi
, ABS_EXPR
, inner_type
, br
);
1139 t2
= gimplify_build1 (gsi
, ABS_EXPR
, inner_type
, bi
);
1140 compare
= fold_build2_loc (gimple_location (gsi_stmt (*gsi
)),
1141 LT_EXPR
, boolean_type_node
, t1
, t2
);
1142 STRIP_NOPS (compare
);
1144 bb_cond
= bb_true
= bb_false
= bb_join
= NULL
;
1145 rr
= ri
= tr
= ti
= NULL
;
1146 if (TREE_CODE (compare
) != INTEGER_CST
)
1152 tmp
= create_tmp_var (boolean_type_node
);
1153 stmt
= gimple_build_assign (tmp
, compare
);
1154 if (gimple_in_ssa_p (cfun
))
1156 tmp
= make_ssa_name (tmp
, stmt
);
1157 gimple_assign_set_lhs (stmt
, tmp
);
1160 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1162 cond
= fold_build2_loc (gimple_location (stmt
),
1163 EQ_EXPR
, boolean_type_node
, tmp
, boolean_true_node
);
1164 stmt
= gimple_build_cond_from_tree (cond
, NULL_TREE
, NULL_TREE
);
1165 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1167 /* Split the original block, and create the TRUE and FALSE blocks. */
1168 e
= split_block (gsi_bb (*gsi
), stmt
);
1171 bb_true
= create_empty_bb (bb_cond
);
1172 bb_false
= create_empty_bb (bb_true
);
1174 /* Wire the blocks together. */
1175 e
->flags
= EDGE_TRUE_VALUE
;
1176 redirect_edge_succ (e
, bb_true
);
1177 make_edge (bb_cond
, bb_false
, EDGE_FALSE_VALUE
);
1178 make_edge (bb_true
, bb_join
, EDGE_FALLTHRU
);
1179 make_edge (bb_false
, bb_join
, EDGE_FALLTHRU
);
1180 add_bb_to_loop (bb_true
, bb_cond
->loop_father
);
1181 add_bb_to_loop (bb_false
, bb_cond
->loop_father
);
1183 /* Update dominance info. Note that bb_join's data was
1184 updated by split_block. */
1185 if (dom_info_available_p (CDI_DOMINATORS
))
1187 set_immediate_dominator (CDI_DOMINATORS
, bb_true
, bb_cond
);
1188 set_immediate_dominator (CDI_DOMINATORS
, bb_false
, bb_cond
);
1191 rr
= create_tmp_reg (inner_type
);
1192 ri
= create_tmp_reg (inner_type
);
1195 /* In the TRUE branch, we compute
1197 div = (br * ratio) + bi;
1198 tr = (ar * ratio) + ai;
1199 ti = (ai * ratio) - ar;
1202 if (bb_true
|| integer_nonzerop (compare
))
1206 *gsi
= gsi_last_bb (bb_true
);
1207 gsi_insert_after (gsi
, gimple_build_nop (), GSI_NEW_STMT
);
1210 ratio
= gimplify_build2 (gsi
, code
, inner_type
, br
, bi
);
1212 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, br
, ratio
);
1213 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, bi
);
1215 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, ratio
);
1216 tr
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, ai
);
1218 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, ratio
);
1219 ti
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, ar
);
1221 tr
= gimplify_build2 (gsi
, code
, inner_type
, tr
, div
);
1222 ti
= gimplify_build2 (gsi
, code
, inner_type
, ti
, div
);
1226 stmt
= gimple_build_assign (rr
, tr
);
1227 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1228 stmt
= gimple_build_assign (ri
, ti
);
1229 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1230 gsi_remove (gsi
, true);
1234 /* In the FALSE branch, we compute
1236 divisor = (d * ratio) + c;
1237 tr = (b * ratio) + a;
1238 ti = b - (a * ratio);
1241 if (bb_false
|| integer_zerop (compare
))
1245 *gsi
= gsi_last_bb (bb_false
);
1246 gsi_insert_after (gsi
, gimple_build_nop (), GSI_NEW_STMT
);
1249 ratio
= gimplify_build2 (gsi
, code
, inner_type
, bi
, br
);
1251 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, bi
, ratio
);
1252 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, br
);
1254 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, ratio
);
1255 tr
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, ar
);
1257 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, ratio
);
1258 ti
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, ai
, t1
);
1260 tr
= gimplify_build2 (gsi
, code
, inner_type
, tr
, div
);
1261 ti
= gimplify_build2 (gsi
, code
, inner_type
, ti
, div
);
1265 stmt
= gimple_build_assign (rr
, tr
);
1266 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1267 stmt
= gimple_build_assign (ri
, ti
);
1268 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1269 gsi_remove (gsi
, true);
1274 *gsi
= gsi_start_bb (bb_join
);
1278 update_complex_assignment (gsi
, rr
, ri
);
1281 /* Expand complex division to scalars. */
1284 expand_complex_division (gimple_stmt_iterator
*gsi
, tree inner_type
,
1285 tree ar
, tree ai
, tree br
, tree bi
,
1286 enum tree_code code
,
1287 complex_lattice_t al
, complex_lattice_t bl
)
1291 switch (PAIR (al
, bl
))
1293 case PAIR (ONLY_REAL
, ONLY_REAL
):
1294 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
1298 case PAIR (ONLY_REAL
, ONLY_IMAG
):
1300 ri
= gimplify_build2 (gsi
, code
, inner_type
, ar
, bi
);
1301 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ri
);
1304 case PAIR (ONLY_IMAG
, ONLY_REAL
):
1306 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, br
);
1309 case PAIR (ONLY_IMAG
, ONLY_IMAG
):
1310 rr
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
1314 case PAIR (VARYING
, ONLY_REAL
):
1315 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
1316 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, br
);
1319 case PAIR (VARYING
, ONLY_IMAG
):
1320 rr
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
1321 ri
= gimplify_build2 (gsi
, code
, inner_type
, ar
, bi
);
1322 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ri
);
1324 case PAIR (ONLY_REAL
, VARYING
):
1325 case PAIR (ONLY_IMAG
, VARYING
):
1326 case PAIR (VARYING
, VARYING
):
1327 switch (flag_complex_method
)
1330 /* straightforward implementation of complex divide acceptable. */
1331 expand_complex_div_straight (gsi
, inner_type
, ar
, ai
, br
, bi
, code
);
1335 if (SCALAR_FLOAT_TYPE_P (inner_type
))
1337 expand_complex_libcall (gsi
, ar
, ai
, br
, bi
, code
);
1343 /* wide ranges of inputs must work for complex divide. */
1344 expand_complex_div_wide (gsi
, inner_type
, ar
, ai
, br
, bi
, code
);
1356 update_complex_assignment (gsi
, rr
, ri
);
1359 /* Expand complex negation to scalars:
1364 expand_complex_negation (gimple_stmt_iterator
*gsi
, tree inner_type
,
1369 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ar
);
1370 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ai
);
1372 update_complex_assignment (gsi
, rr
, ri
);
1375 /* Expand complex conjugate to scalars:
1380 expand_complex_conjugate (gimple_stmt_iterator
*gsi
, tree inner_type
,
1385 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ai
);
1387 update_complex_assignment (gsi
, ar
, ri
);
1390 /* Expand complex comparison (EQ or NE only). */
1393 expand_complex_comparison (gimple_stmt_iterator
*gsi
, tree ar
, tree ai
,
1394 tree br
, tree bi
, enum tree_code code
)
1396 tree cr
, ci
, cc
, type
;
1399 cr
= gimplify_build2 (gsi
, code
, boolean_type_node
, ar
, br
);
1400 ci
= gimplify_build2 (gsi
, code
, boolean_type_node
, ai
, bi
);
1401 cc
= gimplify_build2 (gsi
,
1402 (code
== EQ_EXPR
? TRUTH_AND_EXPR
: TRUTH_OR_EXPR
),
1403 boolean_type_node
, cr
, ci
);
1405 stmt
= gsi_stmt (*gsi
);
1407 switch (gimple_code (stmt
))
1411 greturn
*return_stmt
= as_a
<greturn
*> (stmt
);
1412 type
= TREE_TYPE (gimple_return_retval (return_stmt
));
1413 gimple_return_set_retval (return_stmt
, fold_convert (type
, cc
));
1418 type
= TREE_TYPE (gimple_assign_lhs (stmt
));
1419 gimple_assign_set_rhs_from_tree (gsi
, fold_convert (type
, cc
));
1420 stmt
= gsi_stmt (*gsi
);
1425 gcond
*cond_stmt
= as_a
<gcond
*> (stmt
);
1426 gimple_cond_set_code (cond_stmt
, EQ_EXPR
);
1427 gimple_cond_set_lhs (cond_stmt
, cc
);
1428 gimple_cond_set_rhs (cond_stmt
, boolean_true_node
);
1439 /* Expand inline asm that sets some complex SSA_NAMEs. */
1442 expand_complex_asm (gimple_stmt_iterator
*gsi
)
1444 gasm
*stmt
= as_a
<gasm
*> (gsi_stmt (*gsi
));
1447 for (i
= 0; i
< gimple_asm_noutputs (stmt
); ++i
)
1449 tree link
= gimple_asm_output_op (stmt
, i
);
1450 tree op
= TREE_VALUE (link
);
1451 if (TREE_CODE (op
) == SSA_NAME
1452 && TREE_CODE (TREE_TYPE (op
)) == COMPLEX_TYPE
)
1454 tree type
= TREE_TYPE (op
);
1455 tree inner_type
= TREE_TYPE (type
);
1456 tree r
= build1 (REALPART_EXPR
, inner_type
, op
);
1457 tree i
= build1 (IMAGPART_EXPR
, inner_type
, op
);
1458 gimple_seq list
= set_component_ssa_name (op
, false, r
);
1461 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
1463 list
= set_component_ssa_name (op
, true, i
);
1465 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
1470 /* Process one statement. If we identify a complex operation, expand it. */
1473 expand_complex_operations_1 (gimple_stmt_iterator
*gsi
)
1475 gimple stmt
= gsi_stmt (*gsi
);
1476 tree type
, inner_type
, lhs
;
1477 tree ac
, ar
, ai
, bc
, br
, bi
;
1478 complex_lattice_t al
, bl
;
1479 enum tree_code code
;
1481 if (gimple_code (stmt
) == GIMPLE_ASM
)
1483 expand_complex_asm (gsi
);
1487 lhs
= gimple_get_lhs (stmt
);
1488 if (!lhs
&& gimple_code (stmt
) != GIMPLE_COND
)
1491 type
= TREE_TYPE (gimple_op (stmt
, 0));
1492 code
= gimple_expr_code (stmt
);
1494 /* Initial filter for operations we handle. */
1500 case TRUNC_DIV_EXPR
:
1502 case FLOOR_DIV_EXPR
:
1503 case ROUND_DIV_EXPR
:
1507 if (TREE_CODE (type
) != COMPLEX_TYPE
)
1509 inner_type
= TREE_TYPE (type
);
1514 /* Note, both GIMPLE_ASSIGN and GIMPLE_COND may have an EQ_EXPR
1515 subcode, so we need to access the operands using gimple_op. */
1516 inner_type
= TREE_TYPE (gimple_op (stmt
, 1));
1517 if (TREE_CODE (inner_type
) != COMPLEX_TYPE
)
1525 /* GIMPLE_COND may also fallthru here, but we do not need to
1526 do anything with it. */
1527 if (gimple_code (stmt
) == GIMPLE_COND
)
1530 if (TREE_CODE (type
) == COMPLEX_TYPE
)
1531 expand_complex_move (gsi
, type
);
1532 else if (is_gimple_assign (stmt
)
1533 && (gimple_assign_rhs_code (stmt
) == REALPART_EXPR
1534 || gimple_assign_rhs_code (stmt
) == IMAGPART_EXPR
)
1535 && TREE_CODE (lhs
) == SSA_NAME
)
1537 rhs
= gimple_assign_rhs1 (stmt
);
1538 rhs
= extract_component (gsi
, TREE_OPERAND (rhs
, 0),
1539 gimple_assign_rhs_code (stmt
)
1542 gimple_assign_set_rhs_from_tree (gsi
, rhs
);
1543 stmt
= gsi_stmt (*gsi
);
1550 /* Extract the components of the two complex values. Make sure and
1551 handle the common case of the same value used twice specially. */
1552 if (is_gimple_assign (stmt
))
1554 ac
= gimple_assign_rhs1 (stmt
);
1555 bc
= (gimple_num_ops (stmt
) > 2) ? gimple_assign_rhs2 (stmt
) : NULL
;
1557 /* GIMPLE_CALL can not get here. */
1560 ac
= gimple_cond_lhs (stmt
);
1561 bc
= gimple_cond_rhs (stmt
);
1564 ar
= extract_component (gsi
, ac
, false, true);
1565 ai
= extract_component (gsi
, ac
, true, true);
1571 br
= extract_component (gsi
, bc
, 0, true);
1572 bi
= extract_component (gsi
, bc
, 1, true);
1575 br
= bi
= NULL_TREE
;
1577 if (gimple_in_ssa_p (cfun
))
1579 al
= find_lattice_value (ac
);
1580 if (al
== UNINITIALIZED
)
1583 if (TREE_CODE_CLASS (code
) == tcc_unary
)
1589 bl
= find_lattice_value (bc
);
1590 if (bl
== UNINITIALIZED
)
1601 expand_complex_addition (gsi
, inner_type
, ar
, ai
, br
, bi
, code
, al
, bl
);
1605 expand_complex_multiplication (gsi
, inner_type
, ar
, ai
, br
, bi
, al
, bl
);
1608 case TRUNC_DIV_EXPR
:
1610 case FLOOR_DIV_EXPR
:
1611 case ROUND_DIV_EXPR
:
1613 expand_complex_division (gsi
, inner_type
, ar
, ai
, br
, bi
, code
, al
, bl
);
1617 expand_complex_negation (gsi
, inner_type
, ar
, ai
);
1621 expand_complex_conjugate (gsi
, inner_type
, ar
, ai
);
1626 expand_complex_comparison (gsi
, ar
, ai
, br
, bi
, code
);
1635 /* Entry point for complex operation lowering during optimization. */
1638 tree_lower_complex (void)
1640 int old_last_basic_block
;
1641 gimple_stmt_iterator gsi
;
1644 if (!init_dont_simulate_again ())
1647 complex_lattice_values
.create (num_ssa_names
);
1648 complex_lattice_values
.safe_grow_cleared (num_ssa_names
);
1650 init_parameter_lattice_values ();
1651 ssa_propagate (complex_visit_stmt
, complex_visit_phi
);
1653 complex_variable_components
= new int_tree_htab_type (10);
1655 complex_ssa_name_components
.create (2 * num_ssa_names
);
1656 complex_ssa_name_components
.safe_grow_cleared (2 * num_ssa_names
);
1658 update_parameter_components ();
1660 /* ??? Ideally we'd traverse the blocks in breadth-first order. */
1661 old_last_basic_block
= last_basic_block_for_fn (cfun
);
1662 FOR_EACH_BB_FN (bb
, cfun
)
1664 if (bb
->index
>= old_last_basic_block
)
1667 update_phi_components (bb
);
1668 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1669 expand_complex_operations_1 (&gsi
);
1672 gsi_commit_edge_inserts ();
1674 delete complex_variable_components
;
1675 complex_variable_components
= NULL
;
1676 complex_ssa_name_components
.release ();
1677 complex_lattice_values
.release ();
1683 const pass_data pass_data_lower_complex
=
1685 GIMPLE_PASS
, /* type */
1686 "cplxlower", /* name */
1687 OPTGROUP_NONE
, /* optinfo_flags */
1688 TV_NONE
, /* tv_id */
1689 PROP_ssa
, /* properties_required */
1690 PROP_gimple_lcx
, /* properties_provided */
1691 0, /* properties_destroyed */
1692 0, /* todo_flags_start */
1693 TODO_update_ssa
, /* todo_flags_finish */
1696 class pass_lower_complex
: public gimple_opt_pass
1699 pass_lower_complex (gcc::context
*ctxt
)
1700 : gimple_opt_pass (pass_data_lower_complex
, ctxt
)
1703 /* opt_pass methods: */
1704 opt_pass
* clone () { return new pass_lower_complex (m_ctxt
); }
1705 virtual unsigned int execute (function
*) { return tree_lower_complex (); }
1707 }; // class pass_lower_complex
1712 make_pass_lower_complex (gcc::context
*ctxt
)
1714 return new pass_lower_complex (ctxt
);
1720 const pass_data pass_data_lower_complex_O0
=
1722 GIMPLE_PASS
, /* type */
1723 "cplxlower0", /* name */
1724 OPTGROUP_NONE
, /* optinfo_flags */
1725 TV_NONE
, /* tv_id */
1726 PROP_cfg
, /* properties_required */
1727 PROP_gimple_lcx
, /* properties_provided */
1728 0, /* properties_destroyed */
1729 0, /* todo_flags_start */
1730 TODO_update_ssa
, /* todo_flags_finish */
1733 class pass_lower_complex_O0
: public gimple_opt_pass
1736 pass_lower_complex_O0 (gcc::context
*ctxt
)
1737 : gimple_opt_pass (pass_data_lower_complex_O0
, ctxt
)
1740 /* opt_pass methods: */
1741 virtual bool gate (function
*fun
)
1743 /* With errors, normal optimization passes are not run. If we don't
1744 lower complex operations at all, rtl expansion will abort. */
1745 return !(fun
->curr_properties
& PROP_gimple_lcx
);
1748 virtual unsigned int execute (function
*) { return tree_lower_complex (); }
1750 }; // class pass_lower_complex_O0
1755 make_pass_lower_complex_O0 (gcc::context
*ctxt
)
1757 return new pass_lower_complex_O0 (ctxt
);