1 /* Lower complex number operations to scalar operations.
2 Copyright (C) 2004-2014 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"
25 #include "stor-layout.h"
27 #include "basic-block.h"
28 #include "tree-ssa-alias.h"
29 #include "internal-fn.h"
31 #include "gimple-expr.h"
35 #include "gimple-iterator.h"
36 #include "gimplify-me.h"
37 #include "gimple-ssa.h"
39 #include "tree-phinodes.h"
40 #include "ssa-iterators.h"
41 #include "stringpool.h"
42 #include "tree-ssanames.h"
46 #include "tree-iterator.h"
47 #include "tree-pass.h"
48 #include "tree-ssa-propagate.h"
49 #include "tree-hasher.h"
53 /* For each complex ssa name, a lattice value. We're interested in finding
54 out whether a complex number is degenerate in some way, having only real
55 or only complex parts. */
65 /* The type complex_lattice_t holds combinations of the above
67 typedef int complex_lattice_t
;
69 #define PAIR(a, b) ((a) << 2 | (b))
72 static vec
<complex_lattice_t
> complex_lattice_values
;
74 /* For each complex variable, a pair of variables for the components exists in
76 static int_tree_htab_type
*complex_variable_components
;
78 /* For each complex SSA_NAME, a pair of ssa names for the components. */
79 static vec
<tree
> complex_ssa_name_components
;
81 /* Lookup UID in the complex_variable_components hashtable and return the
84 cvc_lookup (unsigned int uid
)
86 struct int_tree_map in
;
88 return complex_variable_components
->find_with_hash (in
, uid
).to
;
91 /* Insert the pair UID, TO into the complex_variable_components hashtable. */
94 cvc_insert (unsigned int uid
, tree to
)
100 loc
= complex_variable_components
->find_slot_with_hash (h
, uid
, INSERT
);
105 /* Return true if T is not a zero constant. In the case of real values,
106 we're only interested in +0.0. */
109 some_nonzerop (tree t
)
113 /* Operations with real or imaginary part of a complex number zero
114 cannot be treated the same as operations with a real or imaginary
115 operand if we care about the signs of zeros in the result. */
116 if (TREE_CODE (t
) == REAL_CST
&& !flag_signed_zeros
)
117 zerop
= REAL_VALUES_IDENTICAL (TREE_REAL_CST (t
), dconst0
);
118 else if (TREE_CODE (t
) == FIXED_CST
)
119 zerop
= fixed_zerop (t
);
120 else if (TREE_CODE (t
) == INTEGER_CST
)
121 zerop
= integer_zerop (t
);
127 /* Compute a lattice value from the components of a complex type REAL
130 static complex_lattice_t
131 find_lattice_value_parts (tree real
, tree imag
)
134 complex_lattice_t ret
;
136 r
= some_nonzerop (real
);
137 i
= some_nonzerop (imag
);
138 ret
= r
* ONLY_REAL
+ i
* ONLY_IMAG
;
140 /* ??? On occasion we could do better than mapping 0+0i to real, but we
141 certainly don't want to leave it UNINITIALIZED, which eventually gets
142 mapped to VARYING. */
143 if (ret
== UNINITIALIZED
)
150 /* Compute a lattice value from gimple_val T. */
152 static complex_lattice_t
153 find_lattice_value (tree t
)
157 switch (TREE_CODE (t
))
160 return complex_lattice_values
[SSA_NAME_VERSION (t
)];
163 real
= TREE_REALPART (t
);
164 imag
= TREE_IMAGPART (t
);
171 return find_lattice_value_parts (real
, imag
);
174 /* Determine if LHS is something for which we're interested in seeing
175 simulation results. */
178 is_complex_reg (tree lhs
)
180 return TREE_CODE (TREE_TYPE (lhs
)) == COMPLEX_TYPE
&& is_gimple_reg (lhs
);
183 /* Mark the incoming parameters to the function as VARYING. */
186 init_parameter_lattice_values (void)
190 for (parm
= DECL_ARGUMENTS (cfun
->decl
); parm
; parm
= DECL_CHAIN (parm
))
191 if (is_complex_reg (parm
)
192 && (ssa_name
= ssa_default_def (cfun
, parm
)) != NULL_TREE
)
193 complex_lattice_values
[SSA_NAME_VERSION (ssa_name
)] = VARYING
;
196 /* Initialize simulation state for each statement. Return false if we
197 found no statements we want to simulate, and thus there's nothing
198 for the entire pass to do. */
201 init_dont_simulate_again (void)
204 gimple_stmt_iterator gsi
;
206 bool saw_a_complex_op
= false;
208 FOR_EACH_BB_FN (bb
, cfun
)
210 for (gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
212 phi
= gsi_stmt (gsi
);
213 prop_set_simulate_again (phi
,
214 is_complex_reg (gimple_phi_result (phi
)));
217 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
223 stmt
= gsi_stmt (gsi
);
224 op0
= op1
= NULL_TREE
;
226 /* Most control-altering statements must be initially
227 simulated, else we won't cover the entire cfg. */
228 sim_again_p
= stmt_ends_bb_p (stmt
);
230 switch (gimple_code (stmt
))
233 if (gimple_call_lhs (stmt
))
234 sim_again_p
= is_complex_reg (gimple_call_lhs (stmt
));
238 sim_again_p
= is_complex_reg (gimple_assign_lhs (stmt
));
239 if (gimple_assign_rhs_code (stmt
) == REALPART_EXPR
240 || gimple_assign_rhs_code (stmt
) == IMAGPART_EXPR
)
241 op0
= TREE_OPERAND (gimple_assign_rhs1 (stmt
), 0);
243 op0
= gimple_assign_rhs1 (stmt
);
244 if (gimple_num_ops (stmt
) > 2)
245 op1
= gimple_assign_rhs2 (stmt
);
249 op0
= gimple_cond_lhs (stmt
);
250 op1
= gimple_cond_rhs (stmt
);
258 switch (gimple_expr_code (stmt
))
270 if (TREE_CODE (TREE_TYPE (op0
)) == COMPLEX_TYPE
271 || TREE_CODE (TREE_TYPE (op1
)) == COMPLEX_TYPE
)
272 saw_a_complex_op
= true;
277 if (TREE_CODE (TREE_TYPE (op0
)) == COMPLEX_TYPE
)
278 saw_a_complex_op
= true;
283 /* The total store transformation performed during
284 gimplification creates such uninitialized loads
285 and we need to lower the statement to be able
287 if (TREE_CODE (op0
) == SSA_NAME
288 && ssa_undefined_value_p (op0
))
289 saw_a_complex_op
= true;
296 prop_set_simulate_again (stmt
, sim_again_p
);
300 return saw_a_complex_op
;
304 /* Evaluate statement STMT against the complex lattice defined above. */
306 static enum ssa_prop_result
307 complex_visit_stmt (gimple stmt
, edge
*taken_edge_p ATTRIBUTE_UNUSED
,
310 complex_lattice_t new_l
, old_l
, op1_l
, op2_l
;
314 lhs
= gimple_get_lhs (stmt
);
315 /* Skip anything but GIMPLE_ASSIGN and GIMPLE_CALL with a lhs. */
317 return SSA_PROP_VARYING
;
319 /* These conditions should be satisfied due to the initial filter
320 set up in init_dont_simulate_again. */
321 gcc_assert (TREE_CODE (lhs
) == SSA_NAME
);
322 gcc_assert (TREE_CODE (TREE_TYPE (lhs
)) == COMPLEX_TYPE
);
325 ver
= SSA_NAME_VERSION (lhs
);
326 old_l
= complex_lattice_values
[ver
];
328 switch (gimple_expr_code (stmt
))
332 new_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
336 new_l
= find_lattice_value_parts (gimple_assign_rhs1 (stmt
),
337 gimple_assign_rhs2 (stmt
));
342 op1_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
343 op2_l
= find_lattice_value (gimple_assign_rhs2 (stmt
));
345 /* We've set up the lattice values such that IOR neatly
347 new_l
= op1_l
| op2_l
;
356 op1_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
357 op2_l
= find_lattice_value (gimple_assign_rhs2 (stmt
));
359 /* Obviously, if either varies, so does the result. */
360 if (op1_l
== VARYING
|| op2_l
== VARYING
)
362 /* Don't prematurely promote variables if we've not yet seen
364 else if (op1_l
== UNINITIALIZED
)
366 else if (op2_l
== UNINITIALIZED
)
370 /* At this point both numbers have only one component. If the
371 numbers are of opposite kind, the result is imaginary,
372 otherwise the result is real. The add/subtract translates
373 the real/imag from/to 0/1; the ^ performs the comparison. */
374 new_l
= ((op1_l
- ONLY_REAL
) ^ (op2_l
- ONLY_REAL
)) + ONLY_REAL
;
376 /* Don't allow the lattice value to flip-flop indefinitely. */
383 new_l
= find_lattice_value (gimple_assign_rhs1 (stmt
));
391 /* If nothing changed this round, let the propagator know. */
393 return SSA_PROP_NOT_INTERESTING
;
395 complex_lattice_values
[ver
] = new_l
;
396 return new_l
== VARYING
? SSA_PROP_VARYING
: SSA_PROP_INTERESTING
;
399 /* Evaluate a PHI node against the complex lattice defined above. */
401 static enum ssa_prop_result
402 complex_visit_phi (gimple phi
)
404 complex_lattice_t new_l
, old_l
;
409 lhs
= gimple_phi_result (phi
);
411 /* This condition should be satisfied due to the initial filter
412 set up in init_dont_simulate_again. */
413 gcc_assert (TREE_CODE (TREE_TYPE (lhs
)) == COMPLEX_TYPE
);
415 /* We've set up the lattice values such that IOR neatly models PHI meet. */
416 new_l
= UNINITIALIZED
;
417 for (i
= gimple_phi_num_args (phi
) - 1; i
>= 0; --i
)
418 new_l
|= find_lattice_value (gimple_phi_arg_def (phi
, i
));
420 ver
= SSA_NAME_VERSION (lhs
);
421 old_l
= complex_lattice_values
[ver
];
424 return SSA_PROP_NOT_INTERESTING
;
426 complex_lattice_values
[ver
] = new_l
;
427 return new_l
== VARYING
? SSA_PROP_VARYING
: SSA_PROP_INTERESTING
;
430 /* Create one backing variable for a complex component of ORIG. */
433 create_one_component_var (tree type
, tree orig
, const char *prefix
,
434 const char *suffix
, enum tree_code code
)
436 tree r
= create_tmp_var (type
, prefix
);
438 DECL_SOURCE_LOCATION (r
) = DECL_SOURCE_LOCATION (orig
);
439 DECL_ARTIFICIAL (r
) = 1;
441 if (DECL_NAME (orig
) && !DECL_IGNORED_P (orig
))
443 const char *name
= IDENTIFIER_POINTER (DECL_NAME (orig
));
445 DECL_NAME (r
) = get_identifier (ACONCAT ((name
, suffix
, NULL
)));
447 SET_DECL_DEBUG_EXPR (r
, build1 (code
, type
, orig
));
448 DECL_HAS_DEBUG_EXPR_P (r
) = 1;
449 DECL_IGNORED_P (r
) = 0;
450 TREE_NO_WARNING (r
) = TREE_NO_WARNING (orig
);
454 DECL_IGNORED_P (r
) = 1;
455 TREE_NO_WARNING (r
) = 1;
461 /* Retrieve a value for a complex component of VAR. */
464 get_component_var (tree var
, bool imag_p
)
466 size_t decl_index
= DECL_UID (var
) * 2 + imag_p
;
467 tree ret
= cvc_lookup (decl_index
);
471 ret
= create_one_component_var (TREE_TYPE (TREE_TYPE (var
)), var
,
472 imag_p
? "CI" : "CR",
473 imag_p
? "$imag" : "$real",
474 imag_p
? IMAGPART_EXPR
: REALPART_EXPR
);
475 cvc_insert (decl_index
, ret
);
481 /* Retrieve a value for a complex component of SSA_NAME. */
484 get_component_ssa_name (tree ssa_name
, bool imag_p
)
486 complex_lattice_t lattice
= find_lattice_value (ssa_name
);
487 size_t ssa_name_index
;
490 if (lattice
== (imag_p
? ONLY_REAL
: ONLY_IMAG
))
492 tree inner_type
= TREE_TYPE (TREE_TYPE (ssa_name
));
493 if (SCALAR_FLOAT_TYPE_P (inner_type
))
494 return build_real (inner_type
, dconst0
);
496 return build_int_cst (inner_type
, 0);
499 ssa_name_index
= SSA_NAME_VERSION (ssa_name
) * 2 + imag_p
;
500 ret
= complex_ssa_name_components
[ssa_name_index
];
503 if (SSA_NAME_VAR (ssa_name
))
504 ret
= get_component_var (SSA_NAME_VAR (ssa_name
), imag_p
);
506 ret
= TREE_TYPE (TREE_TYPE (ssa_name
));
507 ret
= make_ssa_name (ret
, NULL
);
509 /* Copy some properties from the original. In particular, whether it
510 is used in an abnormal phi, and whether it's uninitialized. */
511 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ret
)
512 = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name
);
513 if (SSA_NAME_IS_DEFAULT_DEF (ssa_name
)
514 && TREE_CODE (SSA_NAME_VAR (ssa_name
)) == VAR_DECL
)
516 SSA_NAME_DEF_STMT (ret
) = SSA_NAME_DEF_STMT (ssa_name
);
517 set_ssa_default_def (cfun
, SSA_NAME_VAR (ret
), ret
);
520 complex_ssa_name_components
[ssa_name_index
] = ret
;
526 /* Set a value for a complex component of SSA_NAME, return a
527 gimple_seq of stuff that needs doing. */
530 set_component_ssa_name (tree ssa_name
, bool imag_p
, tree value
)
532 complex_lattice_t lattice
= find_lattice_value (ssa_name
);
533 size_t ssa_name_index
;
538 /* We know the value must be zero, else there's a bug in our lattice
539 analysis. But the value may well be a variable known to contain
540 zero. We should be safe ignoring it. */
541 if (lattice
== (imag_p
? ONLY_REAL
: ONLY_IMAG
))
544 /* If we've already assigned an SSA_NAME to this component, then this
545 means that our walk of the basic blocks found a use before the set.
546 This is fine. Now we should create an initialization for the value
547 we created earlier. */
548 ssa_name_index
= SSA_NAME_VERSION (ssa_name
) * 2 + imag_p
;
549 comp
= complex_ssa_name_components
[ssa_name_index
];
553 /* If we've nothing assigned, and the value we're given is already stable,
554 then install that as the value for this SSA_NAME. This preemptively
555 copy-propagates the value, which avoids unnecessary memory allocation. */
556 else if (is_gimple_min_invariant (value
)
557 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name
))
559 complex_ssa_name_components
[ssa_name_index
] = value
;
562 else if (TREE_CODE (value
) == SSA_NAME
563 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name
))
565 /* Replace an anonymous base value with the variable from cvc_lookup.
566 This should result in better debug info. */
567 if (SSA_NAME_VAR (ssa_name
)
568 && (!SSA_NAME_VAR (value
) || DECL_IGNORED_P (SSA_NAME_VAR (value
)))
569 && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name
)))
571 comp
= get_component_var (SSA_NAME_VAR (ssa_name
), imag_p
);
572 replace_ssa_name_symbol (value
, comp
);
575 complex_ssa_name_components
[ssa_name_index
] = value
;
579 /* Finally, we need to stabilize the result by installing the value into
582 comp
= get_component_ssa_name (ssa_name
, imag_p
);
584 /* Do all the work to assign VALUE to COMP. */
586 value
= force_gimple_operand (value
, &list
, false, NULL
);
587 last
= gimple_build_assign (comp
, value
);
588 gimple_seq_add_stmt (&list
, last
);
589 gcc_assert (SSA_NAME_DEF_STMT (comp
) == last
);
594 /* Extract the real or imaginary part of a complex variable or constant.
595 Make sure that it's a proper gimple_val and gimplify it if not.
596 Emit any new code before gsi. */
599 extract_component (gimple_stmt_iterator
*gsi
, tree t
, bool imagpart_p
,
602 switch (TREE_CODE (t
))
605 return imagpart_p
? TREE_IMAGPART (t
) : TREE_REALPART (t
);
615 case VIEW_CONVERT_EXPR
:
618 tree inner_type
= TREE_TYPE (TREE_TYPE (t
));
620 t
= build1 ((imagpart_p
? IMAGPART_EXPR
: REALPART_EXPR
),
621 inner_type
, unshare_expr (t
));
624 t
= force_gimple_operand_gsi (gsi
, t
, true, NULL
, true,
631 return get_component_ssa_name (t
, imagpart_p
);
638 /* Update the complex components of the ssa name on the lhs of STMT. */
641 update_complex_components (gimple_stmt_iterator
*gsi
, gimple stmt
, tree r
,
647 lhs
= gimple_get_lhs (stmt
);
649 list
= set_component_ssa_name (lhs
, false, r
);
651 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
653 list
= set_component_ssa_name (lhs
, true, i
);
655 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
659 update_complex_components_on_edge (edge e
, tree lhs
, tree r
, tree i
)
663 list
= set_component_ssa_name (lhs
, false, r
);
665 gsi_insert_seq_on_edge (e
, list
);
667 list
= set_component_ssa_name (lhs
, true, i
);
669 gsi_insert_seq_on_edge (e
, list
);
673 /* Update an assignment to a complex variable in place. */
676 update_complex_assignment (gimple_stmt_iterator
*gsi
, tree r
, tree i
)
680 gimple_assign_set_rhs_with_ops (gsi
, COMPLEX_EXPR
, r
, i
);
681 stmt
= gsi_stmt (*gsi
);
683 if (maybe_clean_eh_stmt (stmt
))
684 gimple_purge_dead_eh_edges (gimple_bb (stmt
));
686 if (gimple_in_ssa_p (cfun
))
687 update_complex_components (gsi
, gsi_stmt (*gsi
), r
, i
);
691 /* Generate code at the entry point of the function to initialize the
692 component variables for a complex parameter. */
695 update_parameter_components (void)
697 edge entry_edge
= single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun
));
700 for (parm
= DECL_ARGUMENTS (cfun
->decl
); parm
; parm
= DECL_CHAIN (parm
))
702 tree type
= TREE_TYPE (parm
);
705 if (TREE_CODE (type
) != COMPLEX_TYPE
|| !is_gimple_reg (parm
))
708 type
= TREE_TYPE (type
);
709 ssa_name
= ssa_default_def (cfun
, parm
);
713 r
= build1 (REALPART_EXPR
, type
, ssa_name
);
714 i
= build1 (IMAGPART_EXPR
, type
, ssa_name
);
715 update_complex_components_on_edge (entry_edge
, ssa_name
, r
, i
);
719 /* Generate code to set the component variables of a complex variable
720 to match the PHI statements in block BB. */
723 update_phi_components (basic_block bb
)
725 gimple_stmt_iterator gsi
;
727 for (gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
729 gimple phi
= gsi_stmt (gsi
);
731 if (is_complex_reg (gimple_phi_result (phi
)))
734 gimple pr
= NULL
, pi
= NULL
;
737 lr
= get_component_ssa_name (gimple_phi_result (phi
), false);
738 if (TREE_CODE (lr
) == SSA_NAME
)
739 pr
= create_phi_node (lr
, bb
);
741 li
= get_component_ssa_name (gimple_phi_result (phi
), true);
742 if (TREE_CODE (li
) == SSA_NAME
)
743 pi
= create_phi_node (li
, bb
);
745 for (i
= 0, n
= gimple_phi_num_args (phi
); i
< n
; ++i
)
747 tree comp
, arg
= gimple_phi_arg_def (phi
, i
);
750 comp
= extract_component (NULL
, arg
, false, false);
751 SET_PHI_ARG_DEF (pr
, i
, comp
);
755 comp
= extract_component (NULL
, arg
, true, false);
756 SET_PHI_ARG_DEF (pi
, i
, comp
);
763 /* Expand a complex move to scalars. */
766 expand_complex_move (gimple_stmt_iterator
*gsi
, tree type
)
768 tree inner_type
= TREE_TYPE (type
);
770 gimple stmt
= gsi_stmt (*gsi
);
772 if (is_gimple_assign (stmt
))
774 lhs
= gimple_assign_lhs (stmt
);
775 if (gimple_num_ops (stmt
) == 2)
776 rhs
= gimple_assign_rhs1 (stmt
);
780 else if (is_gimple_call (stmt
))
782 lhs
= gimple_call_lhs (stmt
);
788 if (TREE_CODE (lhs
) == SSA_NAME
)
790 if (is_ctrl_altering_stmt (stmt
))
794 /* The value is not assigned on the exception edges, so we need not
795 concern ourselves there. We do need to update on the fallthru
797 e
= find_fallthru_edge (gsi_bb (*gsi
)->succs
);
801 r
= build1 (REALPART_EXPR
, inner_type
, lhs
);
802 i
= build1 (IMAGPART_EXPR
, inner_type
, lhs
);
803 update_complex_components_on_edge (e
, lhs
, r
, i
);
805 else if (is_gimple_call (stmt
)
806 || gimple_has_side_effects (stmt
)
807 || gimple_assign_rhs_code (stmt
) == PAREN_EXPR
)
809 r
= build1 (REALPART_EXPR
, inner_type
, lhs
);
810 i
= build1 (IMAGPART_EXPR
, inner_type
, lhs
);
811 update_complex_components (gsi
, stmt
, r
, i
);
815 if (gimple_assign_rhs_code (stmt
) != COMPLEX_EXPR
)
817 r
= extract_component (gsi
, rhs
, 0, true);
818 i
= extract_component (gsi
, rhs
, 1, true);
822 r
= gimple_assign_rhs1 (stmt
);
823 i
= gimple_assign_rhs2 (stmt
);
825 update_complex_assignment (gsi
, r
, i
);
828 else if (rhs
&& TREE_CODE (rhs
) == SSA_NAME
&& !TREE_SIDE_EFFECTS (lhs
))
834 loc
= gimple_location (stmt
);
835 r
= extract_component (gsi
, rhs
, 0, false);
836 i
= extract_component (gsi
, rhs
, 1, false);
838 x
= build1 (REALPART_EXPR
, inner_type
, unshare_expr (lhs
));
839 t
= gimple_build_assign (x
, r
);
840 gimple_set_location (t
, loc
);
841 gsi_insert_before (gsi
, t
, GSI_SAME_STMT
);
843 if (stmt
== gsi_stmt (*gsi
))
845 x
= build1 (IMAGPART_EXPR
, inner_type
, unshare_expr (lhs
));
846 gimple_assign_set_lhs (stmt
, x
);
847 gimple_assign_set_rhs1 (stmt
, i
);
851 x
= build1 (IMAGPART_EXPR
, inner_type
, unshare_expr (lhs
));
852 t
= gimple_build_assign (x
, i
);
853 gimple_set_location (t
, loc
);
854 gsi_insert_before (gsi
, t
, GSI_SAME_STMT
);
856 stmt
= gsi_stmt (*gsi
);
857 gcc_assert (gimple_code (stmt
) == GIMPLE_RETURN
);
858 gimple_return_set_retval (stmt
, lhs
);
865 /* Expand complex addition to scalars:
866 a + b = (ar + br) + i(ai + bi)
867 a - b = (ar - br) + i(ai + bi)
871 expand_complex_addition (gimple_stmt_iterator
*gsi
, tree inner_type
,
872 tree ar
, tree ai
, tree br
, tree bi
,
874 complex_lattice_t al
, complex_lattice_t bl
)
878 switch (PAIR (al
, bl
))
880 case PAIR (ONLY_REAL
, ONLY_REAL
):
881 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
885 case PAIR (ONLY_REAL
, ONLY_IMAG
):
887 if (code
== MINUS_EXPR
)
888 ri
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, ai
, bi
);
893 case PAIR (ONLY_IMAG
, ONLY_REAL
):
894 if (code
== MINUS_EXPR
)
895 rr
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, ar
, br
);
901 case PAIR (ONLY_IMAG
, ONLY_IMAG
):
903 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
906 case PAIR (VARYING
, ONLY_REAL
):
907 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
911 case PAIR (VARYING
, ONLY_IMAG
):
913 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
916 case PAIR (ONLY_REAL
, VARYING
):
917 if (code
== MINUS_EXPR
)
919 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
923 case PAIR (ONLY_IMAG
, VARYING
):
924 if (code
== MINUS_EXPR
)
927 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
930 case PAIR (VARYING
, VARYING
):
932 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
933 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
940 update_complex_assignment (gsi
, rr
, ri
);
943 /* Expand a complex multiplication or division to a libcall to the c99
944 compliant routines. */
947 expand_complex_libcall (gimple_stmt_iterator
*gsi
, tree ar
, tree ai
,
948 tree br
, tree bi
, enum tree_code code
)
950 enum machine_mode mode
;
951 enum built_in_function bcode
;
953 gimple old_stmt
, stmt
;
955 old_stmt
= gsi_stmt (*gsi
);
956 lhs
= gimple_assign_lhs (old_stmt
);
957 type
= TREE_TYPE (lhs
);
959 mode
= TYPE_MODE (type
);
960 gcc_assert (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
);
962 if (code
== MULT_EXPR
)
963 bcode
= ((enum built_in_function
)
964 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
965 else if (code
== RDIV_EXPR
)
966 bcode
= ((enum built_in_function
)
967 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
970 fn
= builtin_decl_explicit (bcode
);
972 stmt
= gimple_build_call (fn
, 4, ar
, ai
, br
, bi
);
973 gimple_call_set_lhs (stmt
, lhs
);
975 gsi_replace (gsi
, stmt
, false);
977 if (maybe_clean_or_replace_eh_stmt (old_stmt
, stmt
))
978 gimple_purge_dead_eh_edges (gsi_bb (*gsi
));
980 if (gimple_in_ssa_p (cfun
))
982 type
= TREE_TYPE (type
);
983 update_complex_components (gsi
, stmt
,
984 build1 (REALPART_EXPR
, type
, lhs
),
985 build1 (IMAGPART_EXPR
, type
, lhs
));
986 SSA_NAME_DEF_STMT (lhs
) = stmt
;
990 /* Expand complex multiplication to scalars:
991 a * b = (ar*br - ai*bi) + i(ar*bi + br*ai)
995 expand_complex_multiplication (gimple_stmt_iterator
*gsi
, tree inner_type
,
996 tree ar
, tree ai
, tree br
, tree bi
,
997 complex_lattice_t al
, complex_lattice_t bl
)
1003 complex_lattice_t tl
;
1004 rr
= ar
, ar
= br
, br
= rr
;
1005 ri
= ai
, ai
= bi
, bi
= ri
;
1006 tl
= al
, al
= bl
, bl
= tl
;
1009 switch (PAIR (al
, bl
))
1011 case PAIR (ONLY_REAL
, ONLY_REAL
):
1012 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1016 case PAIR (ONLY_IMAG
, ONLY_REAL
):
1018 if (TREE_CODE (ai
) == REAL_CST
1019 && REAL_VALUES_IDENTICAL (TREE_REAL_CST (ai
), dconst1
))
1022 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1025 case PAIR (ONLY_IMAG
, ONLY_IMAG
):
1026 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1027 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, rr
);
1031 case PAIR (VARYING
, ONLY_REAL
):
1032 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1033 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1036 case PAIR (VARYING
, ONLY_IMAG
):
1037 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1038 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, rr
);
1039 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1042 case PAIR (VARYING
, VARYING
):
1043 if (flag_complex_method
== 2 && SCALAR_FLOAT_TYPE_P (inner_type
))
1045 expand_complex_libcall (gsi
, ar
, ai
, br
, bi
, MULT_EXPR
);
1050 tree t1
, t2
, t3
, t4
;
1052 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1053 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1054 t3
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1056 /* Avoid expanding redundant multiplication for the common
1057 case of squaring a complex number. */
1058 if (ar
== br
&& ai
== bi
)
1061 t4
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1063 rr
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, t2
);
1064 ri
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t3
, t4
);
1072 update_complex_assignment (gsi
, rr
, ri
);
1075 /* Keep this algorithm in sync with fold-const.c:const_binop().
1077 Expand complex division to scalars, straightforward algorithm.
1078 a / b = ((ar*br + ai*bi)/t) + i((ai*br - ar*bi)/t)
1083 expand_complex_div_straight (gimple_stmt_iterator
*gsi
, tree inner_type
,
1084 tree ar
, tree ai
, tree br
, tree bi
,
1085 enum tree_code code
)
1087 tree rr
, ri
, div
, t1
, t2
, t3
;
1089 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, br
, br
);
1090 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, bi
, bi
);
1091 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, t2
);
1093 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1094 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1095 t3
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, t2
);
1096 rr
= gimplify_build2 (gsi
, code
, inner_type
, t3
, div
);
1098 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1099 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1100 t3
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, t2
);
1101 ri
= gimplify_build2 (gsi
, code
, inner_type
, t3
, div
);
1103 update_complex_assignment (gsi
, rr
, ri
);
1106 /* Keep this algorithm in sync with fold-const.c:const_binop().
1108 Expand complex division to scalars, modified algorithm to minimize
1109 overflow with wide input ranges. */
1112 expand_complex_div_wide (gimple_stmt_iterator
*gsi
, tree inner_type
,
1113 tree ar
, tree ai
, tree br
, tree bi
,
1114 enum tree_code code
)
1116 tree rr
, ri
, ratio
, div
, t1
, t2
, tr
, ti
, compare
;
1117 basic_block bb_cond
, bb_true
, bb_false
, bb_join
;
1120 /* Examine |br| < |bi|, and branch. */
1121 t1
= gimplify_build1 (gsi
, ABS_EXPR
, inner_type
, br
);
1122 t2
= gimplify_build1 (gsi
, ABS_EXPR
, inner_type
, bi
);
1123 compare
= fold_build2_loc (gimple_location (gsi_stmt (*gsi
)),
1124 LT_EXPR
, boolean_type_node
, t1
, t2
);
1125 STRIP_NOPS (compare
);
1127 bb_cond
= bb_true
= bb_false
= bb_join
= NULL
;
1128 rr
= ri
= tr
= ti
= NULL
;
1129 if (TREE_CODE (compare
) != INTEGER_CST
)
1135 tmp
= create_tmp_var (boolean_type_node
, NULL
);
1136 stmt
= gimple_build_assign (tmp
, compare
);
1137 if (gimple_in_ssa_p (cfun
))
1139 tmp
= make_ssa_name (tmp
, stmt
);
1140 gimple_assign_set_lhs (stmt
, tmp
);
1143 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1145 cond
= fold_build2_loc (gimple_location (stmt
),
1146 EQ_EXPR
, boolean_type_node
, tmp
, boolean_true_node
);
1147 stmt
= gimple_build_cond_from_tree (cond
, NULL_TREE
, NULL_TREE
);
1148 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1150 /* Split the original block, and create the TRUE and FALSE blocks. */
1151 e
= split_block (gsi_bb (*gsi
), stmt
);
1154 bb_true
= create_empty_bb (bb_cond
);
1155 bb_false
= create_empty_bb (bb_true
);
1157 /* Wire the blocks together. */
1158 e
->flags
= EDGE_TRUE_VALUE
;
1159 redirect_edge_succ (e
, bb_true
);
1160 make_edge (bb_cond
, bb_false
, EDGE_FALSE_VALUE
);
1161 make_edge (bb_true
, bb_join
, EDGE_FALLTHRU
);
1162 make_edge (bb_false
, bb_join
, EDGE_FALLTHRU
);
1163 add_bb_to_loop (bb_true
, bb_cond
->loop_father
);
1164 add_bb_to_loop (bb_false
, bb_cond
->loop_father
);
1166 /* Update dominance info. Note that bb_join's data was
1167 updated by split_block. */
1168 if (dom_info_available_p (CDI_DOMINATORS
))
1170 set_immediate_dominator (CDI_DOMINATORS
, bb_true
, bb_cond
);
1171 set_immediate_dominator (CDI_DOMINATORS
, bb_false
, bb_cond
);
1174 rr
= create_tmp_reg (inner_type
, NULL
);
1175 ri
= create_tmp_reg (inner_type
, NULL
);
1178 /* In the TRUE branch, we compute
1180 div = (br * ratio) + bi;
1181 tr = (ar * ratio) + ai;
1182 ti = (ai * ratio) - ar;
1185 if (bb_true
|| integer_nonzerop (compare
))
1189 *gsi
= gsi_last_bb (bb_true
);
1190 gsi_insert_after (gsi
, gimple_build_nop (), GSI_NEW_STMT
);
1193 ratio
= gimplify_build2 (gsi
, code
, inner_type
, br
, bi
);
1195 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, br
, ratio
);
1196 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, bi
);
1198 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, ratio
);
1199 tr
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, ai
);
1201 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, ratio
);
1202 ti
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, ar
);
1204 tr
= gimplify_build2 (gsi
, code
, inner_type
, tr
, div
);
1205 ti
= gimplify_build2 (gsi
, code
, inner_type
, ti
, div
);
1209 stmt
= gimple_build_assign (rr
, tr
);
1210 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1211 stmt
= gimple_build_assign (ri
, ti
);
1212 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1213 gsi_remove (gsi
, true);
1217 /* In the FALSE branch, we compute
1219 divisor = (d * ratio) + c;
1220 tr = (b * ratio) + a;
1221 ti = b - (a * ratio);
1224 if (bb_false
|| integer_zerop (compare
))
1228 *gsi
= gsi_last_bb (bb_false
);
1229 gsi_insert_after (gsi
, gimple_build_nop (), GSI_NEW_STMT
);
1232 ratio
= gimplify_build2 (gsi
, code
, inner_type
, bi
, br
);
1234 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, bi
, ratio
);
1235 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, br
);
1237 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, ratio
);
1238 tr
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, ar
);
1240 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, ratio
);
1241 ti
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, ai
, t1
);
1243 tr
= gimplify_build2 (gsi
, code
, inner_type
, tr
, div
);
1244 ti
= gimplify_build2 (gsi
, code
, inner_type
, ti
, div
);
1248 stmt
= gimple_build_assign (rr
, tr
);
1249 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1250 stmt
= gimple_build_assign (ri
, ti
);
1251 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1252 gsi_remove (gsi
, true);
1257 *gsi
= gsi_start_bb (bb_join
);
1261 update_complex_assignment (gsi
, rr
, ri
);
1264 /* Expand complex division to scalars. */
1267 expand_complex_division (gimple_stmt_iterator
*gsi
, tree inner_type
,
1268 tree ar
, tree ai
, tree br
, tree bi
,
1269 enum tree_code code
,
1270 complex_lattice_t al
, complex_lattice_t bl
)
1274 switch (PAIR (al
, bl
))
1276 case PAIR (ONLY_REAL
, ONLY_REAL
):
1277 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
1281 case PAIR (ONLY_REAL
, ONLY_IMAG
):
1283 ri
= gimplify_build2 (gsi
, code
, inner_type
, ar
, bi
);
1284 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ri
);
1287 case PAIR (ONLY_IMAG
, ONLY_REAL
):
1289 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, br
);
1292 case PAIR (ONLY_IMAG
, ONLY_IMAG
):
1293 rr
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
1297 case PAIR (VARYING
, ONLY_REAL
):
1298 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
1299 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, br
);
1302 case PAIR (VARYING
, ONLY_IMAG
):
1303 rr
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
1304 ri
= gimplify_build2 (gsi
, code
, inner_type
, ar
, bi
);
1305 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ri
);
1307 case PAIR (ONLY_REAL
, VARYING
):
1308 case PAIR (ONLY_IMAG
, VARYING
):
1309 case PAIR (VARYING
, VARYING
):
1310 switch (flag_complex_method
)
1313 /* straightforward implementation of complex divide acceptable. */
1314 expand_complex_div_straight (gsi
, inner_type
, ar
, ai
, br
, bi
, code
);
1318 if (SCALAR_FLOAT_TYPE_P (inner_type
))
1320 expand_complex_libcall (gsi
, ar
, ai
, br
, bi
, code
);
1326 /* wide ranges of inputs must work for complex divide. */
1327 expand_complex_div_wide (gsi
, inner_type
, ar
, ai
, br
, bi
, code
);
1339 update_complex_assignment (gsi
, rr
, ri
);
1342 /* Expand complex negation to scalars:
1347 expand_complex_negation (gimple_stmt_iterator
*gsi
, tree inner_type
,
1352 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ar
);
1353 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ai
);
1355 update_complex_assignment (gsi
, rr
, ri
);
1358 /* Expand complex conjugate to scalars:
1363 expand_complex_conjugate (gimple_stmt_iterator
*gsi
, tree inner_type
,
1368 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ai
);
1370 update_complex_assignment (gsi
, ar
, ri
);
1373 /* Expand complex comparison (EQ or NE only). */
1376 expand_complex_comparison (gimple_stmt_iterator
*gsi
, tree ar
, tree ai
,
1377 tree br
, tree bi
, enum tree_code code
)
1379 tree cr
, ci
, cc
, type
;
1382 cr
= gimplify_build2 (gsi
, code
, boolean_type_node
, ar
, br
);
1383 ci
= gimplify_build2 (gsi
, code
, boolean_type_node
, ai
, bi
);
1384 cc
= gimplify_build2 (gsi
,
1385 (code
== EQ_EXPR
? TRUTH_AND_EXPR
: TRUTH_OR_EXPR
),
1386 boolean_type_node
, cr
, ci
);
1388 stmt
= gsi_stmt (*gsi
);
1390 switch (gimple_code (stmt
))
1393 type
= TREE_TYPE (gimple_return_retval (stmt
));
1394 gimple_return_set_retval (stmt
, fold_convert (type
, cc
));
1398 type
= TREE_TYPE (gimple_assign_lhs (stmt
));
1399 gimple_assign_set_rhs_from_tree (gsi
, fold_convert (type
, cc
));
1400 stmt
= gsi_stmt (*gsi
);
1404 gimple_cond_set_code (stmt
, EQ_EXPR
);
1405 gimple_cond_set_lhs (stmt
, cc
);
1406 gimple_cond_set_rhs (stmt
, boolean_true_node
);
1416 /* Expand inline asm that sets some complex SSA_NAMEs. */
1419 expand_complex_asm (gimple_stmt_iterator
*gsi
)
1421 gimple stmt
= gsi_stmt (*gsi
);
1424 for (i
= 0; i
< gimple_asm_noutputs (stmt
); ++i
)
1426 tree link
= gimple_asm_output_op (stmt
, i
);
1427 tree op
= TREE_VALUE (link
);
1428 if (TREE_CODE (op
) == SSA_NAME
1429 && TREE_CODE (TREE_TYPE (op
)) == COMPLEX_TYPE
)
1431 tree type
= TREE_TYPE (op
);
1432 tree inner_type
= TREE_TYPE (type
);
1433 tree r
= build1 (REALPART_EXPR
, inner_type
, op
);
1434 tree i
= build1 (IMAGPART_EXPR
, inner_type
, op
);
1435 gimple_seq list
= set_component_ssa_name (op
, false, r
);
1438 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
1440 list
= set_component_ssa_name (op
, true, i
);
1442 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
1447 /* Process one statement. If we identify a complex operation, expand it. */
1450 expand_complex_operations_1 (gimple_stmt_iterator
*gsi
)
1452 gimple stmt
= gsi_stmt (*gsi
);
1453 tree type
, inner_type
, lhs
;
1454 tree ac
, ar
, ai
, bc
, br
, bi
;
1455 complex_lattice_t al
, bl
;
1456 enum tree_code code
;
1458 if (gimple_code (stmt
) == GIMPLE_ASM
)
1460 expand_complex_asm (gsi
);
1464 lhs
= gimple_get_lhs (stmt
);
1465 if (!lhs
&& gimple_code (stmt
) != GIMPLE_COND
)
1468 type
= TREE_TYPE (gimple_op (stmt
, 0));
1469 code
= gimple_expr_code (stmt
);
1471 /* Initial filter for operations we handle. */
1477 case TRUNC_DIV_EXPR
:
1479 case FLOOR_DIV_EXPR
:
1480 case ROUND_DIV_EXPR
:
1484 if (TREE_CODE (type
) != COMPLEX_TYPE
)
1486 inner_type
= TREE_TYPE (type
);
1491 /* Note, both GIMPLE_ASSIGN and GIMPLE_COND may have an EQ_EXPR
1492 subcode, so we need to access the operands using gimple_op. */
1493 inner_type
= TREE_TYPE (gimple_op (stmt
, 1));
1494 if (TREE_CODE (inner_type
) != COMPLEX_TYPE
)
1502 /* GIMPLE_COND may also fallthru here, but we do not need to
1503 do anything with it. */
1504 if (gimple_code (stmt
) == GIMPLE_COND
)
1507 if (TREE_CODE (type
) == COMPLEX_TYPE
)
1508 expand_complex_move (gsi
, type
);
1509 else if (is_gimple_assign (stmt
)
1510 && (gimple_assign_rhs_code (stmt
) == REALPART_EXPR
1511 || gimple_assign_rhs_code (stmt
) == IMAGPART_EXPR
)
1512 && TREE_CODE (lhs
) == SSA_NAME
)
1514 rhs
= gimple_assign_rhs1 (stmt
);
1515 rhs
= extract_component (gsi
, TREE_OPERAND (rhs
, 0),
1516 gimple_assign_rhs_code (stmt
)
1519 gimple_assign_set_rhs_from_tree (gsi
, rhs
);
1520 stmt
= gsi_stmt (*gsi
);
1527 /* Extract the components of the two complex values. Make sure and
1528 handle the common case of the same value used twice specially. */
1529 if (is_gimple_assign (stmt
))
1531 ac
= gimple_assign_rhs1 (stmt
);
1532 bc
= (gimple_num_ops (stmt
) > 2) ? gimple_assign_rhs2 (stmt
) : NULL
;
1534 /* GIMPLE_CALL can not get here. */
1537 ac
= gimple_cond_lhs (stmt
);
1538 bc
= gimple_cond_rhs (stmt
);
1541 ar
= extract_component (gsi
, ac
, false, true);
1542 ai
= extract_component (gsi
, ac
, true, true);
1548 br
= extract_component (gsi
, bc
, 0, true);
1549 bi
= extract_component (gsi
, bc
, 1, true);
1552 br
= bi
= NULL_TREE
;
1554 if (gimple_in_ssa_p (cfun
))
1556 al
= find_lattice_value (ac
);
1557 if (al
== UNINITIALIZED
)
1560 if (TREE_CODE_CLASS (code
) == tcc_unary
)
1566 bl
= find_lattice_value (bc
);
1567 if (bl
== UNINITIALIZED
)
1578 expand_complex_addition (gsi
, inner_type
, ar
, ai
, br
, bi
, code
, al
, bl
);
1582 expand_complex_multiplication (gsi
, inner_type
, ar
, ai
, br
, bi
, al
, bl
);
1585 case TRUNC_DIV_EXPR
:
1587 case FLOOR_DIV_EXPR
:
1588 case ROUND_DIV_EXPR
:
1590 expand_complex_division (gsi
, inner_type
, ar
, ai
, br
, bi
, code
, al
, bl
);
1594 expand_complex_negation (gsi
, inner_type
, ar
, ai
);
1598 expand_complex_conjugate (gsi
, inner_type
, ar
, ai
);
1603 expand_complex_comparison (gsi
, ar
, ai
, br
, bi
, code
);
1612 /* Entry point for complex operation lowering during optimization. */
1615 tree_lower_complex (void)
1617 int old_last_basic_block
;
1618 gimple_stmt_iterator gsi
;
1621 if (!init_dont_simulate_again ())
1624 complex_lattice_values
.create (num_ssa_names
);
1625 complex_lattice_values
.safe_grow_cleared (num_ssa_names
);
1627 init_parameter_lattice_values ();
1628 ssa_propagate (complex_visit_stmt
, complex_visit_phi
);
1630 complex_variable_components
= new int_tree_htab_type (10);
1632 complex_ssa_name_components
.create (2 * num_ssa_names
);
1633 complex_ssa_name_components
.safe_grow_cleared (2 * num_ssa_names
);
1635 update_parameter_components ();
1637 /* ??? Ideally we'd traverse the blocks in breadth-first order. */
1638 old_last_basic_block
= last_basic_block_for_fn (cfun
);
1639 FOR_EACH_BB_FN (bb
, cfun
)
1641 if (bb
->index
>= old_last_basic_block
)
1644 update_phi_components (bb
);
1645 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1646 expand_complex_operations_1 (&gsi
);
1649 gsi_commit_edge_inserts ();
1651 delete complex_variable_components
;
1652 complex_variable_components
= NULL
;
1653 complex_ssa_name_components
.release ();
1654 complex_lattice_values
.release ();
1660 const pass_data pass_data_lower_complex
=
1662 GIMPLE_PASS
, /* type */
1663 "cplxlower", /* name */
1664 OPTGROUP_NONE
, /* optinfo_flags */
1665 TV_NONE
, /* tv_id */
1666 PROP_ssa
, /* properties_required */
1667 PROP_gimple_lcx
, /* properties_provided */
1668 0, /* properties_destroyed */
1669 0, /* todo_flags_start */
1670 TODO_update_ssa
, /* todo_flags_finish */
1673 class pass_lower_complex
: public gimple_opt_pass
1676 pass_lower_complex (gcc::context
*ctxt
)
1677 : gimple_opt_pass (pass_data_lower_complex
, ctxt
)
1680 /* opt_pass methods: */
1681 opt_pass
* clone () { return new pass_lower_complex (m_ctxt
); }
1682 virtual unsigned int execute (function
*) { return tree_lower_complex (); }
1684 }; // class pass_lower_complex
1689 make_pass_lower_complex (gcc::context
*ctxt
)
1691 return new pass_lower_complex (ctxt
);
1697 const pass_data pass_data_lower_complex_O0
=
1699 GIMPLE_PASS
, /* type */
1700 "cplxlower0", /* name */
1701 OPTGROUP_NONE
, /* optinfo_flags */
1702 TV_NONE
, /* tv_id */
1703 PROP_cfg
, /* properties_required */
1704 PROP_gimple_lcx
, /* properties_provided */
1705 0, /* properties_destroyed */
1706 0, /* todo_flags_start */
1707 TODO_update_ssa
, /* todo_flags_finish */
1710 class pass_lower_complex_O0
: public gimple_opt_pass
1713 pass_lower_complex_O0 (gcc::context
*ctxt
)
1714 : gimple_opt_pass (pass_data_lower_complex_O0
, ctxt
)
1717 /* opt_pass methods: */
1718 virtual bool gate (function
*fun
)
1720 /* With errors, normal optimization passes are not run. If we don't
1721 lower complex operations at all, rtl expansion will abort. */
1722 return !(fun
->curr_properties
& PROP_gimple_lcx
);
1725 virtual unsigned int execute (function
*) { return tree_lower_complex (); }
1727 }; // class pass_lower_complex_O0
1732 make_pass_lower_complex_O0 (gcc::context
*ctxt
)
1734 return new pass_lower_complex_O0 (ctxt
);