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"
28 #include "fold-const.h"
29 #include "stor-layout.h"
32 #include "hard-reg-set.h"
34 #include "dominance.h"
36 #include "basic-block.h"
37 #include "tree-ssa-alias.h"
38 #include "internal-fn.h"
40 #include "gimple-expr.h"
44 #include "gimple-iterator.h"
45 #include "gimplify-me.h"
46 #include "gimple-ssa.h"
48 #include "tree-phinodes.h"
49 #include "ssa-iterators.h"
50 #include "stringpool.h"
51 #include "tree-ssanames.h"
53 #include "insn-config.h"
64 #include "tree-iterator.h"
65 #include "tree-pass.h"
66 #include "tree-ssa-propagate.h"
67 #include "tree-hasher.h"
71 /* For each complex ssa name, a lattice value. We're interested in finding
72 out whether a complex number is degenerate in some way, having only real
73 or only complex parts. */
83 /* The type complex_lattice_t holds combinations of the above
85 typedef int complex_lattice_t
;
87 #define PAIR(a, b) ((a) << 2 | (b))
90 static vec
<complex_lattice_t
> complex_lattice_values
;
92 /* For each complex variable, a pair of variables for the components exists in
94 static int_tree_htab_type
*complex_variable_components
;
96 /* For each complex SSA_NAME, a pair of ssa names for the components. */
97 static vec
<tree
> complex_ssa_name_components
;
99 /* Lookup UID in the complex_variable_components hashtable and return the
102 cvc_lookup (unsigned int uid
)
104 struct int_tree_map in
;
106 return complex_variable_components
->find_with_hash (in
, uid
).to
;
109 /* Insert the pair UID, TO into the complex_variable_components hashtable. */
112 cvc_insert (unsigned int uid
, tree to
)
118 loc
= complex_variable_components
->find_slot_with_hash (h
, uid
, INSERT
);
123 /* Return true if T is not a zero constant. In the case of real values,
124 we're only interested in +0.0. */
127 some_nonzerop (tree t
)
131 /* Operations with real or imaginary part of a complex number zero
132 cannot be treated the same as operations with a real or imaginary
133 operand if we care about the signs of zeros in the result. */
134 if (TREE_CODE (t
) == REAL_CST
&& !flag_signed_zeros
)
135 zerop
= REAL_VALUES_IDENTICAL (TREE_REAL_CST (t
), dconst0
);
136 else if (TREE_CODE (t
) == FIXED_CST
)
137 zerop
= fixed_zerop (t
);
138 else if (TREE_CODE (t
) == INTEGER_CST
)
139 zerop
= integer_zerop (t
);
145 /* Compute a lattice value from the components of a complex type REAL
148 static complex_lattice_t
149 find_lattice_value_parts (tree real
, tree imag
)
152 complex_lattice_t ret
;
154 r
= some_nonzerop (real
);
155 i
= some_nonzerop (imag
);
156 ret
= r
* ONLY_REAL
+ i
* ONLY_IMAG
;
158 /* ??? On occasion we could do better than mapping 0+0i to real, but we
159 certainly don't want to leave it UNINITIALIZED, which eventually gets
160 mapped to VARYING. */
161 if (ret
== UNINITIALIZED
)
168 /* Compute a lattice value from gimple_val T. */
170 static complex_lattice_t
171 find_lattice_value (tree t
)
175 switch (TREE_CODE (t
))
178 return complex_lattice_values
[SSA_NAME_VERSION (t
)];
181 real
= TREE_REALPART (t
);
182 imag
= TREE_IMAGPART (t
);
189 return find_lattice_value_parts (real
, imag
);
192 /* Determine if LHS is something for which we're interested in seeing
193 simulation results. */
196 is_complex_reg (tree lhs
)
198 return TREE_CODE (TREE_TYPE (lhs
)) == COMPLEX_TYPE
&& is_gimple_reg (lhs
);
201 /* Mark the incoming parameters to the function as VARYING. */
204 init_parameter_lattice_values (void)
208 for (parm
= DECL_ARGUMENTS (cfun
->decl
); parm
; parm
= DECL_CHAIN (parm
))
209 if (is_complex_reg (parm
)
210 && (ssa_name
= ssa_default_def (cfun
, parm
)) != NULL_TREE
)
211 complex_lattice_values
[SSA_NAME_VERSION (ssa_name
)] = VARYING
;
214 /* Initialize simulation state for each statement. Return false if we
215 found no statements we want to simulate, and thus there's nothing
216 for the entire pass to do. */
219 init_dont_simulate_again (void)
222 bool saw_a_complex_op
= false;
224 FOR_EACH_BB_FN (bb
, cfun
)
226 for (gphi_iterator gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
);
229 gphi
*phi
= gsi
.phi ();
230 prop_set_simulate_again (phi
,
231 is_complex_reg (gimple_phi_result (phi
)));
234 for (gimple_stmt_iterator gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
);
241 stmt
= gsi_stmt (gsi
);
242 op0
= op1
= NULL_TREE
;
244 /* Most control-altering statements must be initially
245 simulated, else we won't cover the entire cfg. */
246 sim_again_p
= stmt_ends_bb_p (stmt
);
248 switch (gimple_code (stmt
))
251 if (gimple_call_lhs (stmt
))
252 sim_again_p
= is_complex_reg (gimple_call_lhs (stmt
));
256 sim_again_p
= is_complex_reg (gimple_assign_lhs (stmt
));
257 if (gimple_assign_rhs_code (stmt
) == REALPART_EXPR
258 || gimple_assign_rhs_code (stmt
) == IMAGPART_EXPR
)
259 op0
= TREE_OPERAND (gimple_assign_rhs1 (stmt
), 0);
261 op0
= gimple_assign_rhs1 (stmt
);
262 if (gimple_num_ops (stmt
) > 2)
263 op1
= gimple_assign_rhs2 (stmt
);
267 op0
= gimple_cond_lhs (stmt
);
268 op1
= gimple_cond_rhs (stmt
);
276 switch (gimple_expr_code (stmt
))
288 if (TREE_CODE (TREE_TYPE (op0
)) == COMPLEX_TYPE
289 || TREE_CODE (TREE_TYPE (op1
)) == COMPLEX_TYPE
)
290 saw_a_complex_op
= true;
295 if (TREE_CODE (TREE_TYPE (op0
)) == COMPLEX_TYPE
)
296 saw_a_complex_op
= true;
301 /* The total store transformation performed during
302 gimplification creates such uninitialized loads
303 and we need to lower the statement to be able
305 if (TREE_CODE (op0
) == SSA_NAME
306 && ssa_undefined_value_p (op0
))
307 saw_a_complex_op
= true;
314 prop_set_simulate_again (stmt
, sim_again_p
);
318 return saw_a_complex_op
;
322 /* Evaluate statement STMT against the complex lattice defined above. */
324 static enum ssa_prop_result
325 complex_visit_stmt (gimple stmt
, edge
*taken_edge_p ATTRIBUTE_UNUSED
,
328 complex_lattice_t new_l
, old_l
, op1_l
, op2_l
;
332 lhs
= gimple_get_lhs (stmt
);
333 /* Skip anything but GIMPLE_ASSIGN and GIMPLE_CALL with a lhs. */
335 return SSA_PROP_VARYING
;
337 /* These conditions should be satisfied due to the initial filter
338 set up in init_dont_simulate_again. */
339 gcc_assert (TREE_CODE (lhs
) == SSA_NAME
);
340 gcc_assert (TREE_CODE (TREE_TYPE (lhs
)) == COMPLEX_TYPE
);
343 ver
= SSA_NAME_VERSION (lhs
);
344 old_l
= complex_lattice_values
[ver
];
346 switch (gimple_expr_code (stmt
))
350 new_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
354 new_l
= find_lattice_value_parts (gimple_assign_rhs1 (stmt
),
355 gimple_assign_rhs2 (stmt
));
360 op1_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
361 op2_l
= find_lattice_value (gimple_assign_rhs2 (stmt
));
363 /* We've set up the lattice values such that IOR neatly
365 new_l
= op1_l
| op2_l
;
374 op1_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
375 op2_l
= find_lattice_value (gimple_assign_rhs2 (stmt
));
377 /* Obviously, if either varies, so does the result. */
378 if (op1_l
== VARYING
|| op2_l
== VARYING
)
380 /* Don't prematurely promote variables if we've not yet seen
382 else if (op1_l
== UNINITIALIZED
)
384 else if (op2_l
== UNINITIALIZED
)
388 /* At this point both numbers have only one component. If the
389 numbers are of opposite kind, the result is imaginary,
390 otherwise the result is real. The add/subtract translates
391 the real/imag from/to 0/1; the ^ performs the comparison. */
392 new_l
= ((op1_l
- ONLY_REAL
) ^ (op2_l
- ONLY_REAL
)) + ONLY_REAL
;
394 /* Don't allow the lattice value to flip-flop indefinitely. */
401 new_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
409 /* If nothing changed this round, let the propagator know. */
411 return SSA_PROP_NOT_INTERESTING
;
413 complex_lattice_values
[ver
] = new_l
;
414 return new_l
== VARYING
? SSA_PROP_VARYING
: SSA_PROP_INTERESTING
;
417 /* Evaluate a PHI node against the complex lattice defined above. */
419 static enum ssa_prop_result
420 complex_visit_phi (gphi
*phi
)
422 complex_lattice_t new_l
, old_l
;
427 lhs
= gimple_phi_result (phi
);
429 /* This condition should be satisfied due to the initial filter
430 set up in init_dont_simulate_again. */
431 gcc_assert (TREE_CODE (TREE_TYPE (lhs
)) == COMPLEX_TYPE
);
433 /* We've set up the lattice values such that IOR neatly models PHI meet. */
434 new_l
= UNINITIALIZED
;
435 for (i
= gimple_phi_num_args (phi
) - 1; i
>= 0; --i
)
436 new_l
|= find_lattice_value (gimple_phi_arg_def (phi
, i
));
438 ver
= SSA_NAME_VERSION (lhs
);
439 old_l
= complex_lattice_values
[ver
];
442 return SSA_PROP_NOT_INTERESTING
;
444 complex_lattice_values
[ver
] = new_l
;
445 return new_l
== VARYING
? SSA_PROP_VARYING
: SSA_PROP_INTERESTING
;
448 /* Create one backing variable for a complex component of ORIG. */
451 create_one_component_var (tree type
, tree orig
, const char *prefix
,
452 const char *suffix
, enum tree_code code
)
454 tree r
= create_tmp_var (type
, prefix
);
456 DECL_SOURCE_LOCATION (r
) = DECL_SOURCE_LOCATION (orig
);
457 DECL_ARTIFICIAL (r
) = 1;
459 if (DECL_NAME (orig
) && !DECL_IGNORED_P (orig
))
461 const char *name
= IDENTIFIER_POINTER (DECL_NAME (orig
));
463 DECL_NAME (r
) = get_identifier (ACONCAT ((name
, suffix
, NULL
)));
465 SET_DECL_DEBUG_EXPR (r
, build1 (code
, type
, orig
));
466 DECL_HAS_DEBUG_EXPR_P (r
) = 1;
467 DECL_IGNORED_P (r
) = 0;
468 TREE_NO_WARNING (r
) = TREE_NO_WARNING (orig
);
472 DECL_IGNORED_P (r
) = 1;
473 TREE_NO_WARNING (r
) = 1;
479 /* Retrieve a value for a complex component of VAR. */
482 get_component_var (tree var
, bool imag_p
)
484 size_t decl_index
= DECL_UID (var
) * 2 + imag_p
;
485 tree ret
= cvc_lookup (decl_index
);
489 ret
= create_one_component_var (TREE_TYPE (TREE_TYPE (var
)), var
,
490 imag_p
? "CI" : "CR",
491 imag_p
? "$imag" : "$real",
492 imag_p
? IMAGPART_EXPR
: REALPART_EXPR
);
493 cvc_insert (decl_index
, ret
);
499 /* Retrieve a value for a complex component of SSA_NAME. */
502 get_component_ssa_name (tree ssa_name
, bool imag_p
)
504 complex_lattice_t lattice
= find_lattice_value (ssa_name
);
505 size_t ssa_name_index
;
508 if (lattice
== (imag_p
? ONLY_REAL
: ONLY_IMAG
))
510 tree inner_type
= TREE_TYPE (TREE_TYPE (ssa_name
));
511 if (SCALAR_FLOAT_TYPE_P (inner_type
))
512 return build_real (inner_type
, dconst0
);
514 return build_int_cst (inner_type
, 0);
517 ssa_name_index
= SSA_NAME_VERSION (ssa_name
) * 2 + imag_p
;
518 ret
= complex_ssa_name_components
[ssa_name_index
];
521 if (SSA_NAME_VAR (ssa_name
))
522 ret
= get_component_var (SSA_NAME_VAR (ssa_name
), imag_p
);
524 ret
= TREE_TYPE (TREE_TYPE (ssa_name
));
525 ret
= make_ssa_name (ret
);
527 /* Copy some properties from the original. In particular, whether it
528 is used in an abnormal phi, and whether it's uninitialized. */
529 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ret
)
530 = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name
);
531 if (SSA_NAME_IS_DEFAULT_DEF (ssa_name
)
532 && TREE_CODE (SSA_NAME_VAR (ssa_name
)) == VAR_DECL
)
534 SSA_NAME_DEF_STMT (ret
) = SSA_NAME_DEF_STMT (ssa_name
);
535 set_ssa_default_def (cfun
, SSA_NAME_VAR (ret
), ret
);
538 complex_ssa_name_components
[ssa_name_index
] = ret
;
544 /* Set a value for a complex component of SSA_NAME, return a
545 gimple_seq of stuff that needs doing. */
548 set_component_ssa_name (tree ssa_name
, bool imag_p
, tree value
)
550 complex_lattice_t lattice
= find_lattice_value (ssa_name
);
551 size_t ssa_name_index
;
556 /* We know the value must be zero, else there's a bug in our lattice
557 analysis. But the value may well be a variable known to contain
558 zero. We should be safe ignoring it. */
559 if (lattice
== (imag_p
? ONLY_REAL
: ONLY_IMAG
))
562 /* If we've already assigned an SSA_NAME to this component, then this
563 means that our walk of the basic blocks found a use before the set.
564 This is fine. Now we should create an initialization for the value
565 we created earlier. */
566 ssa_name_index
= SSA_NAME_VERSION (ssa_name
) * 2 + imag_p
;
567 comp
= complex_ssa_name_components
[ssa_name_index
];
571 /* If we've nothing assigned, and the value we're given is already stable,
572 then install that as the value for this SSA_NAME. This preemptively
573 copy-propagates the value, which avoids unnecessary memory allocation. */
574 else if (is_gimple_min_invariant (value
)
575 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name
))
577 complex_ssa_name_components
[ssa_name_index
] = value
;
580 else if (TREE_CODE (value
) == SSA_NAME
581 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name
))
583 /* Replace an anonymous base value with the variable from cvc_lookup.
584 This should result in better debug info. */
585 if (SSA_NAME_VAR (ssa_name
)
586 && (!SSA_NAME_VAR (value
) || DECL_IGNORED_P (SSA_NAME_VAR (value
)))
587 && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name
)))
589 comp
= get_component_var (SSA_NAME_VAR (ssa_name
), imag_p
);
590 replace_ssa_name_symbol (value
, comp
);
593 complex_ssa_name_components
[ssa_name_index
] = value
;
597 /* Finally, we need to stabilize the result by installing the value into
600 comp
= get_component_ssa_name (ssa_name
, imag_p
);
602 /* Do all the work to assign VALUE to COMP. */
604 value
= force_gimple_operand (value
, &list
, false, NULL
);
605 last
= gimple_build_assign (comp
, value
);
606 gimple_seq_add_stmt (&list
, last
);
607 gcc_assert (SSA_NAME_DEF_STMT (comp
) == last
);
612 /* Extract the real or imaginary part of a complex variable or constant.
613 Make sure that it's a proper gimple_val and gimplify it if not.
614 Emit any new code before gsi. */
617 extract_component (gimple_stmt_iterator
*gsi
, tree t
, bool imagpart_p
,
620 switch (TREE_CODE (t
))
623 return imagpart_p
? TREE_IMAGPART (t
) : TREE_REALPART (t
);
633 case VIEW_CONVERT_EXPR
:
636 tree inner_type
= TREE_TYPE (TREE_TYPE (t
));
638 t
= build1 ((imagpart_p
? IMAGPART_EXPR
: REALPART_EXPR
),
639 inner_type
, unshare_expr (t
));
642 t
= force_gimple_operand_gsi (gsi
, t
, true, NULL
, true,
649 return get_component_ssa_name (t
, imagpart_p
);
656 /* Update the complex components of the ssa name on the lhs of STMT. */
659 update_complex_components (gimple_stmt_iterator
*gsi
, gimple stmt
, tree r
,
665 lhs
= gimple_get_lhs (stmt
);
667 list
= set_component_ssa_name (lhs
, false, r
);
669 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
671 list
= set_component_ssa_name (lhs
, true, i
);
673 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
677 update_complex_components_on_edge (edge e
, tree lhs
, tree r
, tree i
)
681 list
= set_component_ssa_name (lhs
, false, r
);
683 gsi_insert_seq_on_edge (e
, list
);
685 list
= set_component_ssa_name (lhs
, true, i
);
687 gsi_insert_seq_on_edge (e
, list
);
691 /* Update an assignment to a complex variable in place. */
694 update_complex_assignment (gimple_stmt_iterator
*gsi
, tree r
, tree i
)
698 gimple_assign_set_rhs_with_ops (gsi
, COMPLEX_EXPR
, r
, i
);
699 stmt
= gsi_stmt (*gsi
);
701 if (maybe_clean_eh_stmt (stmt
))
702 gimple_purge_dead_eh_edges (gimple_bb (stmt
));
704 if (gimple_in_ssa_p (cfun
))
705 update_complex_components (gsi
, gsi_stmt (*gsi
), r
, i
);
709 /* Generate code at the entry point of the function to initialize the
710 component variables for a complex parameter. */
713 update_parameter_components (void)
715 edge entry_edge
= single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun
));
718 for (parm
= DECL_ARGUMENTS (cfun
->decl
); parm
; parm
= DECL_CHAIN (parm
))
720 tree type
= TREE_TYPE (parm
);
723 if (TREE_CODE (type
) != COMPLEX_TYPE
|| !is_gimple_reg (parm
))
726 type
= TREE_TYPE (type
);
727 ssa_name
= ssa_default_def (cfun
, parm
);
731 r
= build1 (REALPART_EXPR
, type
, ssa_name
);
732 i
= build1 (IMAGPART_EXPR
, type
, ssa_name
);
733 update_complex_components_on_edge (entry_edge
, ssa_name
, r
, i
);
737 /* Generate code to set the component variables of a complex variable
738 to match the PHI statements in block BB. */
741 update_phi_components (basic_block bb
)
745 for (gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
747 gphi
*phi
= gsi
.phi ();
749 if (is_complex_reg (gimple_phi_result (phi
)))
752 gimple pr
= NULL
, pi
= NULL
;
755 lr
= get_component_ssa_name (gimple_phi_result (phi
), false);
756 if (TREE_CODE (lr
) == SSA_NAME
)
757 pr
= create_phi_node (lr
, bb
);
759 li
= get_component_ssa_name (gimple_phi_result (phi
), true);
760 if (TREE_CODE (li
) == SSA_NAME
)
761 pi
= create_phi_node (li
, bb
);
763 for (i
= 0, n
= gimple_phi_num_args (phi
); i
< n
; ++i
)
765 tree comp
, arg
= gimple_phi_arg_def (phi
, i
);
768 comp
= extract_component (NULL
, arg
, false, false);
769 SET_PHI_ARG_DEF (pr
, i
, comp
);
773 comp
= extract_component (NULL
, arg
, true, false);
774 SET_PHI_ARG_DEF (pi
, i
, comp
);
781 /* Expand a complex move to scalars. */
784 expand_complex_move (gimple_stmt_iterator
*gsi
, tree type
)
786 tree inner_type
= TREE_TYPE (type
);
788 gimple stmt
= gsi_stmt (*gsi
);
790 if (is_gimple_assign (stmt
))
792 lhs
= gimple_assign_lhs (stmt
);
793 if (gimple_num_ops (stmt
) == 2)
794 rhs
= gimple_assign_rhs1 (stmt
);
798 else if (is_gimple_call (stmt
))
800 lhs
= gimple_call_lhs (stmt
);
806 if (TREE_CODE (lhs
) == SSA_NAME
)
808 if (is_ctrl_altering_stmt (stmt
))
812 /* The value is not assigned on the exception edges, so we need not
813 concern ourselves there. We do need to update on the fallthru
815 e
= find_fallthru_edge (gsi_bb (*gsi
)->succs
);
819 r
= build1 (REALPART_EXPR
, inner_type
, lhs
);
820 i
= build1 (IMAGPART_EXPR
, inner_type
, lhs
);
821 update_complex_components_on_edge (e
, lhs
, r
, i
);
823 else if (is_gimple_call (stmt
)
824 || gimple_has_side_effects (stmt
)
825 || gimple_assign_rhs_code (stmt
) == PAREN_EXPR
)
827 r
= build1 (REALPART_EXPR
, inner_type
, lhs
);
828 i
= build1 (IMAGPART_EXPR
, inner_type
, lhs
);
829 update_complex_components (gsi
, stmt
, r
, i
);
833 if (gimple_assign_rhs_code (stmt
) != COMPLEX_EXPR
)
835 r
= extract_component (gsi
, rhs
, 0, true);
836 i
= extract_component (gsi
, rhs
, 1, true);
840 r
= gimple_assign_rhs1 (stmt
);
841 i
= gimple_assign_rhs2 (stmt
);
843 update_complex_assignment (gsi
, r
, i
);
846 else if (rhs
&& TREE_CODE (rhs
) == SSA_NAME
&& !TREE_SIDE_EFFECTS (lhs
))
852 loc
= gimple_location (stmt
);
853 r
= extract_component (gsi
, rhs
, 0, false);
854 i
= extract_component (gsi
, rhs
, 1, false);
856 x
= build1 (REALPART_EXPR
, inner_type
, unshare_expr (lhs
));
857 t
= gimple_build_assign (x
, r
);
858 gimple_set_location (t
, loc
);
859 gsi_insert_before (gsi
, t
, GSI_SAME_STMT
);
861 if (stmt
== gsi_stmt (*gsi
))
863 x
= build1 (IMAGPART_EXPR
, inner_type
, unshare_expr (lhs
));
864 gimple_assign_set_lhs (stmt
, x
);
865 gimple_assign_set_rhs1 (stmt
, i
);
869 x
= build1 (IMAGPART_EXPR
, inner_type
, unshare_expr (lhs
));
870 t
= gimple_build_assign (x
, i
);
871 gimple_set_location (t
, loc
);
872 gsi_insert_before (gsi
, t
, GSI_SAME_STMT
);
874 stmt
= gsi_stmt (*gsi
);
875 gcc_assert (gimple_code (stmt
) == GIMPLE_RETURN
);
876 gimple_return_set_retval (as_a
<greturn
*> (stmt
), lhs
);
883 /* Expand complex addition to scalars:
884 a + b = (ar + br) + i(ai + bi)
885 a - b = (ar - br) + i(ai + bi)
889 expand_complex_addition (gimple_stmt_iterator
*gsi
, tree inner_type
,
890 tree ar
, tree ai
, tree br
, tree bi
,
892 complex_lattice_t al
, complex_lattice_t bl
)
896 switch (PAIR (al
, bl
))
898 case PAIR (ONLY_REAL
, ONLY_REAL
):
899 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
903 case PAIR (ONLY_REAL
, ONLY_IMAG
):
905 if (code
== MINUS_EXPR
)
906 ri
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, ai
, bi
);
911 case PAIR (ONLY_IMAG
, ONLY_REAL
):
912 if (code
== MINUS_EXPR
)
913 rr
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, ar
, br
);
919 case PAIR (ONLY_IMAG
, ONLY_IMAG
):
921 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
924 case PAIR (VARYING
, ONLY_REAL
):
925 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
929 case PAIR (VARYING
, ONLY_IMAG
):
931 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
934 case PAIR (ONLY_REAL
, VARYING
):
935 if (code
== MINUS_EXPR
)
937 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
941 case PAIR (ONLY_IMAG
, VARYING
):
942 if (code
== MINUS_EXPR
)
945 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
948 case PAIR (VARYING
, VARYING
):
950 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
951 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
958 update_complex_assignment (gsi
, rr
, ri
);
961 /* Expand a complex multiplication or division to a libcall to the c99
962 compliant routines. */
965 expand_complex_libcall (gimple_stmt_iterator
*gsi
, tree ar
, tree ai
,
966 tree br
, tree bi
, enum tree_code code
)
969 enum built_in_function bcode
;
974 old_stmt
= gsi_stmt (*gsi
);
975 lhs
= gimple_assign_lhs (old_stmt
);
976 type
= TREE_TYPE (lhs
);
978 mode
= TYPE_MODE (type
);
979 gcc_assert (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
);
981 if (code
== MULT_EXPR
)
982 bcode
= ((enum built_in_function
)
983 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
984 else if (code
== RDIV_EXPR
)
985 bcode
= ((enum built_in_function
)
986 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
989 fn
= builtin_decl_explicit (bcode
);
991 stmt
= gimple_build_call (fn
, 4, ar
, ai
, br
, bi
);
992 gimple_call_set_lhs (stmt
, lhs
);
994 gsi_replace (gsi
, stmt
, false);
996 if (maybe_clean_or_replace_eh_stmt (old_stmt
, stmt
))
997 gimple_purge_dead_eh_edges (gsi_bb (*gsi
));
999 if (gimple_in_ssa_p (cfun
))
1001 type
= TREE_TYPE (type
);
1002 update_complex_components (gsi
, stmt
,
1003 build1 (REALPART_EXPR
, type
, lhs
),
1004 build1 (IMAGPART_EXPR
, type
, lhs
));
1005 SSA_NAME_DEF_STMT (lhs
) = stmt
;
1009 /* Expand complex multiplication to scalars:
1010 a * b = (ar*br - ai*bi) + i(ar*bi + br*ai)
1014 expand_complex_multiplication (gimple_stmt_iterator
*gsi
, tree inner_type
,
1015 tree ar
, tree ai
, tree br
, tree bi
,
1016 complex_lattice_t al
, complex_lattice_t bl
)
1022 complex_lattice_t tl
;
1023 rr
= ar
, ar
= br
, br
= rr
;
1024 ri
= ai
, ai
= bi
, bi
= ri
;
1025 tl
= al
, al
= bl
, bl
= tl
;
1028 switch (PAIR (al
, bl
))
1030 case PAIR (ONLY_REAL
, ONLY_REAL
):
1031 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1035 case PAIR (ONLY_IMAG
, ONLY_REAL
):
1037 if (TREE_CODE (ai
) == REAL_CST
1038 && REAL_VALUES_IDENTICAL (TREE_REAL_CST (ai
), dconst1
))
1041 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1044 case PAIR (ONLY_IMAG
, ONLY_IMAG
):
1045 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1046 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, rr
);
1050 case PAIR (VARYING
, ONLY_REAL
):
1051 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1052 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1055 case PAIR (VARYING
, ONLY_IMAG
):
1056 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1057 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, rr
);
1058 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1061 case PAIR (VARYING
, VARYING
):
1062 if (flag_complex_method
== 2 && SCALAR_FLOAT_TYPE_P (inner_type
))
1064 expand_complex_libcall (gsi
, ar
, ai
, br
, bi
, MULT_EXPR
);
1069 tree t1
, t2
, t3
, t4
;
1071 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1072 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1073 t3
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1075 /* Avoid expanding redundant multiplication for the common
1076 case of squaring a complex number. */
1077 if (ar
== br
&& ai
== bi
)
1080 t4
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1082 rr
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, t2
);
1083 ri
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t3
, t4
);
1091 update_complex_assignment (gsi
, rr
, ri
);
1094 /* Keep this algorithm in sync with fold-const.c:const_binop().
1096 Expand complex division to scalars, straightforward algorithm.
1097 a / b = ((ar*br + ai*bi)/t) + i((ai*br - ar*bi)/t)
1102 expand_complex_div_straight (gimple_stmt_iterator
*gsi
, tree inner_type
,
1103 tree ar
, tree ai
, tree br
, tree bi
,
1104 enum tree_code code
)
1106 tree rr
, ri
, div
, t1
, t2
, t3
;
1108 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, br
, br
);
1109 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, bi
, bi
);
1110 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, t2
);
1112 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1113 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1114 t3
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, t2
);
1115 rr
= gimplify_build2 (gsi
, code
, inner_type
, t3
, div
);
1117 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1118 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1119 t3
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, t2
);
1120 ri
= gimplify_build2 (gsi
, code
, inner_type
, t3
, div
);
1122 update_complex_assignment (gsi
, rr
, ri
);
1125 /* Keep this algorithm in sync with fold-const.c:const_binop().
1127 Expand complex division to scalars, modified algorithm to minimize
1128 overflow with wide input ranges. */
1131 expand_complex_div_wide (gimple_stmt_iterator
*gsi
, tree inner_type
,
1132 tree ar
, tree ai
, tree br
, tree bi
,
1133 enum tree_code code
)
1135 tree rr
, ri
, ratio
, div
, t1
, t2
, tr
, ti
, compare
;
1136 basic_block bb_cond
, bb_true
, bb_false
, bb_join
;
1139 /* Examine |br| < |bi|, and branch. */
1140 t1
= gimplify_build1 (gsi
, ABS_EXPR
, inner_type
, br
);
1141 t2
= gimplify_build1 (gsi
, ABS_EXPR
, inner_type
, bi
);
1142 compare
= fold_build2_loc (gimple_location (gsi_stmt (*gsi
)),
1143 LT_EXPR
, boolean_type_node
, t1
, t2
);
1144 STRIP_NOPS (compare
);
1146 bb_cond
= bb_true
= bb_false
= bb_join
= NULL
;
1147 rr
= ri
= tr
= ti
= NULL
;
1148 if (TREE_CODE (compare
) != INTEGER_CST
)
1154 tmp
= create_tmp_var (boolean_type_node
);
1155 stmt
= gimple_build_assign (tmp
, compare
);
1156 if (gimple_in_ssa_p (cfun
))
1158 tmp
= make_ssa_name (tmp
, stmt
);
1159 gimple_assign_set_lhs (stmt
, tmp
);
1162 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1164 cond
= fold_build2_loc (gimple_location (stmt
),
1165 EQ_EXPR
, boolean_type_node
, tmp
, boolean_true_node
);
1166 stmt
= gimple_build_cond_from_tree (cond
, NULL_TREE
, NULL_TREE
);
1167 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1169 /* Split the original block, and create the TRUE and FALSE blocks. */
1170 e
= split_block (gsi_bb (*gsi
), stmt
);
1173 bb_true
= create_empty_bb (bb_cond
);
1174 bb_false
= create_empty_bb (bb_true
);
1176 /* Wire the blocks together. */
1177 e
->flags
= EDGE_TRUE_VALUE
;
1178 redirect_edge_succ (e
, bb_true
);
1179 make_edge (bb_cond
, bb_false
, EDGE_FALSE_VALUE
);
1180 make_edge (bb_true
, bb_join
, EDGE_FALLTHRU
);
1181 make_edge (bb_false
, bb_join
, EDGE_FALLTHRU
);
1182 add_bb_to_loop (bb_true
, bb_cond
->loop_father
);
1183 add_bb_to_loop (bb_false
, bb_cond
->loop_father
);
1185 /* Update dominance info. Note that bb_join's data was
1186 updated by split_block. */
1187 if (dom_info_available_p (CDI_DOMINATORS
))
1189 set_immediate_dominator (CDI_DOMINATORS
, bb_true
, bb_cond
);
1190 set_immediate_dominator (CDI_DOMINATORS
, bb_false
, bb_cond
);
1193 rr
= create_tmp_reg (inner_type
);
1194 ri
= create_tmp_reg (inner_type
);
1197 /* In the TRUE branch, we compute
1199 div = (br * ratio) + bi;
1200 tr = (ar * ratio) + ai;
1201 ti = (ai * ratio) - ar;
1204 if (bb_true
|| integer_nonzerop (compare
))
1208 *gsi
= gsi_last_bb (bb_true
);
1209 gsi_insert_after (gsi
, gimple_build_nop (), GSI_NEW_STMT
);
1212 ratio
= gimplify_build2 (gsi
, code
, inner_type
, br
, bi
);
1214 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, br
, ratio
);
1215 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, bi
);
1217 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, ratio
);
1218 tr
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, ai
);
1220 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, ratio
);
1221 ti
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, ar
);
1223 tr
= gimplify_build2 (gsi
, code
, inner_type
, tr
, div
);
1224 ti
= gimplify_build2 (gsi
, code
, inner_type
, ti
, div
);
1228 stmt
= gimple_build_assign (rr
, tr
);
1229 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1230 stmt
= gimple_build_assign (ri
, ti
);
1231 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1232 gsi_remove (gsi
, true);
1236 /* In the FALSE branch, we compute
1238 divisor = (d * ratio) + c;
1239 tr = (b * ratio) + a;
1240 ti = b - (a * ratio);
1243 if (bb_false
|| integer_zerop (compare
))
1247 *gsi
= gsi_last_bb (bb_false
);
1248 gsi_insert_after (gsi
, gimple_build_nop (), GSI_NEW_STMT
);
1251 ratio
= gimplify_build2 (gsi
, code
, inner_type
, bi
, br
);
1253 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, bi
, ratio
);
1254 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, br
);
1256 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, ratio
);
1257 tr
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, ar
);
1259 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, ratio
);
1260 ti
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, ai
, t1
);
1262 tr
= gimplify_build2 (gsi
, code
, inner_type
, tr
, div
);
1263 ti
= gimplify_build2 (gsi
, code
, inner_type
, ti
, div
);
1267 stmt
= gimple_build_assign (rr
, tr
);
1268 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1269 stmt
= gimple_build_assign (ri
, ti
);
1270 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1271 gsi_remove (gsi
, true);
1276 *gsi
= gsi_start_bb (bb_join
);
1280 update_complex_assignment (gsi
, rr
, ri
);
1283 /* Expand complex division to scalars. */
1286 expand_complex_division (gimple_stmt_iterator
*gsi
, tree inner_type
,
1287 tree ar
, tree ai
, tree br
, tree bi
,
1288 enum tree_code code
,
1289 complex_lattice_t al
, complex_lattice_t bl
)
1293 switch (PAIR (al
, bl
))
1295 case PAIR (ONLY_REAL
, ONLY_REAL
):
1296 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
1300 case PAIR (ONLY_REAL
, ONLY_IMAG
):
1302 ri
= gimplify_build2 (gsi
, code
, inner_type
, ar
, bi
);
1303 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ri
);
1306 case PAIR (ONLY_IMAG
, ONLY_REAL
):
1308 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, br
);
1311 case PAIR (ONLY_IMAG
, ONLY_IMAG
):
1312 rr
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
1316 case PAIR (VARYING
, ONLY_REAL
):
1317 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
1318 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, br
);
1321 case PAIR (VARYING
, ONLY_IMAG
):
1322 rr
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
1323 ri
= gimplify_build2 (gsi
, code
, inner_type
, ar
, bi
);
1324 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ri
);
1326 case PAIR (ONLY_REAL
, VARYING
):
1327 case PAIR (ONLY_IMAG
, VARYING
):
1328 case PAIR (VARYING
, VARYING
):
1329 switch (flag_complex_method
)
1332 /* straightforward implementation of complex divide acceptable. */
1333 expand_complex_div_straight (gsi
, inner_type
, ar
, ai
, br
, bi
, code
);
1337 if (SCALAR_FLOAT_TYPE_P (inner_type
))
1339 expand_complex_libcall (gsi
, ar
, ai
, br
, bi
, code
);
1345 /* wide ranges of inputs must work for complex divide. */
1346 expand_complex_div_wide (gsi
, inner_type
, ar
, ai
, br
, bi
, code
);
1358 update_complex_assignment (gsi
, rr
, ri
);
1361 /* Expand complex negation to scalars:
1366 expand_complex_negation (gimple_stmt_iterator
*gsi
, tree inner_type
,
1371 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ar
);
1372 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ai
);
1374 update_complex_assignment (gsi
, rr
, ri
);
1377 /* Expand complex conjugate to scalars:
1382 expand_complex_conjugate (gimple_stmt_iterator
*gsi
, tree inner_type
,
1387 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ai
);
1389 update_complex_assignment (gsi
, ar
, ri
);
1392 /* Expand complex comparison (EQ or NE only). */
1395 expand_complex_comparison (gimple_stmt_iterator
*gsi
, tree ar
, tree ai
,
1396 tree br
, tree bi
, enum tree_code code
)
1398 tree cr
, ci
, cc
, type
;
1401 cr
= gimplify_build2 (gsi
, code
, boolean_type_node
, ar
, br
);
1402 ci
= gimplify_build2 (gsi
, code
, boolean_type_node
, ai
, bi
);
1403 cc
= gimplify_build2 (gsi
,
1404 (code
== EQ_EXPR
? TRUTH_AND_EXPR
: TRUTH_OR_EXPR
),
1405 boolean_type_node
, cr
, ci
);
1407 stmt
= gsi_stmt (*gsi
);
1409 switch (gimple_code (stmt
))
1413 greturn
*return_stmt
= as_a
<greturn
*> (stmt
);
1414 type
= TREE_TYPE (gimple_return_retval (return_stmt
));
1415 gimple_return_set_retval (return_stmt
, fold_convert (type
, cc
));
1420 type
= TREE_TYPE (gimple_assign_lhs (stmt
));
1421 gimple_assign_set_rhs_from_tree (gsi
, fold_convert (type
, cc
));
1422 stmt
= gsi_stmt (*gsi
);
1427 gcond
*cond_stmt
= as_a
<gcond
*> (stmt
);
1428 gimple_cond_set_code (cond_stmt
, EQ_EXPR
);
1429 gimple_cond_set_lhs (cond_stmt
, cc
);
1430 gimple_cond_set_rhs (cond_stmt
, boolean_true_node
);
1441 /* Expand inline asm that sets some complex SSA_NAMEs. */
1444 expand_complex_asm (gimple_stmt_iterator
*gsi
)
1446 gasm
*stmt
= as_a
<gasm
*> (gsi_stmt (*gsi
));
1449 for (i
= 0; i
< gimple_asm_noutputs (stmt
); ++i
)
1451 tree link
= gimple_asm_output_op (stmt
, i
);
1452 tree op
= TREE_VALUE (link
);
1453 if (TREE_CODE (op
) == SSA_NAME
1454 && TREE_CODE (TREE_TYPE (op
)) == COMPLEX_TYPE
)
1456 tree type
= TREE_TYPE (op
);
1457 tree inner_type
= TREE_TYPE (type
);
1458 tree r
= build1 (REALPART_EXPR
, inner_type
, op
);
1459 tree i
= build1 (IMAGPART_EXPR
, inner_type
, op
);
1460 gimple_seq list
= set_component_ssa_name (op
, false, r
);
1463 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
1465 list
= set_component_ssa_name (op
, true, i
);
1467 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
1472 /* Process one statement. If we identify a complex operation, expand it. */
1475 expand_complex_operations_1 (gimple_stmt_iterator
*gsi
)
1477 gimple stmt
= gsi_stmt (*gsi
);
1478 tree type
, inner_type
, lhs
;
1479 tree ac
, ar
, ai
, bc
, br
, bi
;
1480 complex_lattice_t al
, bl
;
1481 enum tree_code code
;
1483 if (gimple_code (stmt
) == GIMPLE_ASM
)
1485 expand_complex_asm (gsi
);
1489 lhs
= gimple_get_lhs (stmt
);
1490 if (!lhs
&& gimple_code (stmt
) != GIMPLE_COND
)
1493 type
= TREE_TYPE (gimple_op (stmt
, 0));
1494 code
= gimple_expr_code (stmt
);
1496 /* Initial filter for operations we handle. */
1502 case TRUNC_DIV_EXPR
:
1504 case FLOOR_DIV_EXPR
:
1505 case ROUND_DIV_EXPR
:
1509 if (TREE_CODE (type
) != COMPLEX_TYPE
)
1511 inner_type
= TREE_TYPE (type
);
1516 /* Note, both GIMPLE_ASSIGN and GIMPLE_COND may have an EQ_EXPR
1517 subcode, so we need to access the operands using gimple_op. */
1518 inner_type
= TREE_TYPE (gimple_op (stmt
, 1));
1519 if (TREE_CODE (inner_type
) != COMPLEX_TYPE
)
1527 /* GIMPLE_COND may also fallthru here, but we do not need to
1528 do anything with it. */
1529 if (gimple_code (stmt
) == GIMPLE_COND
)
1532 if (TREE_CODE (type
) == COMPLEX_TYPE
)
1533 expand_complex_move (gsi
, type
);
1534 else if (is_gimple_assign (stmt
)
1535 && (gimple_assign_rhs_code (stmt
) == REALPART_EXPR
1536 || gimple_assign_rhs_code (stmt
) == IMAGPART_EXPR
)
1537 && TREE_CODE (lhs
) == SSA_NAME
)
1539 rhs
= gimple_assign_rhs1 (stmt
);
1540 rhs
= extract_component (gsi
, TREE_OPERAND (rhs
, 0),
1541 gimple_assign_rhs_code (stmt
)
1544 gimple_assign_set_rhs_from_tree (gsi
, rhs
);
1545 stmt
= gsi_stmt (*gsi
);
1552 /* Extract the components of the two complex values. Make sure and
1553 handle the common case of the same value used twice specially. */
1554 if (is_gimple_assign (stmt
))
1556 ac
= gimple_assign_rhs1 (stmt
);
1557 bc
= (gimple_num_ops (stmt
) > 2) ? gimple_assign_rhs2 (stmt
) : NULL
;
1559 /* GIMPLE_CALL can not get here. */
1562 ac
= gimple_cond_lhs (stmt
);
1563 bc
= gimple_cond_rhs (stmt
);
1566 ar
= extract_component (gsi
, ac
, false, true);
1567 ai
= extract_component (gsi
, ac
, true, true);
1573 br
= extract_component (gsi
, bc
, 0, true);
1574 bi
= extract_component (gsi
, bc
, 1, true);
1577 br
= bi
= NULL_TREE
;
1579 if (gimple_in_ssa_p (cfun
))
1581 al
= find_lattice_value (ac
);
1582 if (al
== UNINITIALIZED
)
1585 if (TREE_CODE_CLASS (code
) == tcc_unary
)
1591 bl
= find_lattice_value (bc
);
1592 if (bl
== UNINITIALIZED
)
1603 expand_complex_addition (gsi
, inner_type
, ar
, ai
, br
, bi
, code
, al
, bl
);
1607 expand_complex_multiplication (gsi
, inner_type
, ar
, ai
, br
, bi
, al
, bl
);
1610 case TRUNC_DIV_EXPR
:
1612 case FLOOR_DIV_EXPR
:
1613 case ROUND_DIV_EXPR
:
1615 expand_complex_division (gsi
, inner_type
, ar
, ai
, br
, bi
, code
, al
, bl
);
1619 expand_complex_negation (gsi
, inner_type
, ar
, ai
);
1623 expand_complex_conjugate (gsi
, inner_type
, ar
, ai
);
1628 expand_complex_comparison (gsi
, ar
, ai
, br
, bi
, code
);
1637 /* Entry point for complex operation lowering during optimization. */
1640 tree_lower_complex (void)
1642 int old_last_basic_block
;
1643 gimple_stmt_iterator gsi
;
1646 if (!init_dont_simulate_again ())
1649 complex_lattice_values
.create (num_ssa_names
);
1650 complex_lattice_values
.safe_grow_cleared (num_ssa_names
);
1652 init_parameter_lattice_values ();
1653 ssa_propagate (complex_visit_stmt
, complex_visit_phi
);
1655 complex_variable_components
= new int_tree_htab_type (10);
1657 complex_ssa_name_components
.create (2 * num_ssa_names
);
1658 complex_ssa_name_components
.safe_grow_cleared (2 * num_ssa_names
);
1660 update_parameter_components ();
1662 /* ??? Ideally we'd traverse the blocks in breadth-first order. */
1663 old_last_basic_block
= last_basic_block_for_fn (cfun
);
1664 FOR_EACH_BB_FN (bb
, cfun
)
1666 if (bb
->index
>= old_last_basic_block
)
1669 update_phi_components (bb
);
1670 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1671 expand_complex_operations_1 (&gsi
);
1674 gsi_commit_edge_inserts ();
1676 delete complex_variable_components
;
1677 complex_variable_components
= NULL
;
1678 complex_ssa_name_components
.release ();
1679 complex_lattice_values
.release ();
1685 const pass_data pass_data_lower_complex
=
1687 GIMPLE_PASS
, /* type */
1688 "cplxlower", /* name */
1689 OPTGROUP_NONE
, /* optinfo_flags */
1690 TV_NONE
, /* tv_id */
1691 PROP_ssa
, /* properties_required */
1692 PROP_gimple_lcx
, /* properties_provided */
1693 0, /* properties_destroyed */
1694 0, /* todo_flags_start */
1695 TODO_update_ssa
, /* todo_flags_finish */
1698 class pass_lower_complex
: public gimple_opt_pass
1701 pass_lower_complex (gcc::context
*ctxt
)
1702 : gimple_opt_pass (pass_data_lower_complex
, ctxt
)
1705 /* opt_pass methods: */
1706 opt_pass
* clone () { return new pass_lower_complex (m_ctxt
); }
1707 virtual unsigned int execute (function
*) { return tree_lower_complex (); }
1709 }; // class pass_lower_complex
1714 make_pass_lower_complex (gcc::context
*ctxt
)
1716 return new pass_lower_complex (ctxt
);
1722 const pass_data pass_data_lower_complex_O0
=
1724 GIMPLE_PASS
, /* type */
1725 "cplxlower0", /* name */
1726 OPTGROUP_NONE
, /* optinfo_flags */
1727 TV_NONE
, /* tv_id */
1728 PROP_cfg
, /* properties_required */
1729 PROP_gimple_lcx
, /* properties_provided */
1730 0, /* properties_destroyed */
1731 0, /* todo_flags_start */
1732 TODO_update_ssa
, /* todo_flags_finish */
1735 class pass_lower_complex_O0
: public gimple_opt_pass
1738 pass_lower_complex_O0 (gcc::context
*ctxt
)
1739 : gimple_opt_pass (pass_data_lower_complex_O0
, ctxt
)
1742 /* opt_pass methods: */
1743 virtual bool gate (function
*fun
)
1745 /* With errors, normal optimization passes are not run. If we don't
1746 lower complex operations at all, rtl expansion will abort. */
1747 return !(fun
->curr_properties
& PROP_gimple_lcx
);
1750 virtual unsigned int execute (function
*) { return tree_lower_complex (); }
1752 }; // class pass_lower_complex_O0
1757 make_pass_lower_complex_O0 (gcc::context
*ctxt
)
1759 return new pass_lower_complex_O0 (ctxt
);