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 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_phi_iterator gsi
;
727 for (gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
729 gimple_phi phi
= gsi
.phi ();
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 (as_a
<gimple_return
> (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
;
956 old_stmt
= gsi_stmt (*gsi
);
957 lhs
= gimple_assign_lhs (old_stmt
);
958 type
= TREE_TYPE (lhs
);
960 mode
= TYPE_MODE (type
);
961 gcc_assert (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
);
963 if (code
== MULT_EXPR
)
964 bcode
= ((enum built_in_function
)
965 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
966 else if (code
== RDIV_EXPR
)
967 bcode
= ((enum built_in_function
)
968 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
971 fn
= builtin_decl_explicit (bcode
);
973 stmt
= gimple_build_call (fn
, 4, ar
, ai
, br
, bi
);
974 gimple_call_set_lhs (stmt
, lhs
);
976 gsi_replace (gsi
, stmt
, false);
978 if (maybe_clean_or_replace_eh_stmt (old_stmt
, stmt
))
979 gimple_purge_dead_eh_edges (gsi_bb (*gsi
));
981 if (gimple_in_ssa_p (cfun
))
983 type
= TREE_TYPE (type
);
984 update_complex_components (gsi
, stmt
,
985 build1 (REALPART_EXPR
, type
, lhs
),
986 build1 (IMAGPART_EXPR
, type
, lhs
));
987 SSA_NAME_DEF_STMT (lhs
) = stmt
;
991 /* Expand complex multiplication to scalars:
992 a * b = (ar*br - ai*bi) + i(ar*bi + br*ai)
996 expand_complex_multiplication (gimple_stmt_iterator
*gsi
, tree inner_type
,
997 tree ar
, tree ai
, tree br
, tree bi
,
998 complex_lattice_t al
, complex_lattice_t bl
)
1004 complex_lattice_t tl
;
1005 rr
= ar
, ar
= br
, br
= rr
;
1006 ri
= ai
, ai
= bi
, bi
= ri
;
1007 tl
= al
, al
= bl
, bl
= tl
;
1010 switch (PAIR (al
, bl
))
1012 case PAIR (ONLY_REAL
, ONLY_REAL
):
1013 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1017 case PAIR (ONLY_IMAG
, ONLY_REAL
):
1019 if (TREE_CODE (ai
) == REAL_CST
1020 && REAL_VALUES_IDENTICAL (TREE_REAL_CST (ai
), dconst1
))
1023 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1026 case PAIR (ONLY_IMAG
, ONLY_IMAG
):
1027 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1028 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, rr
);
1032 case PAIR (VARYING
, ONLY_REAL
):
1033 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1034 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1037 case PAIR (VARYING
, ONLY_IMAG
):
1038 rr
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1039 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, rr
);
1040 ri
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1043 case PAIR (VARYING
, VARYING
):
1044 if (flag_complex_method
== 2 && SCALAR_FLOAT_TYPE_P (inner_type
))
1046 expand_complex_libcall (gsi
, ar
, ai
, br
, bi
, MULT_EXPR
);
1051 tree t1
, t2
, t3
, t4
;
1053 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1054 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1055 t3
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1057 /* Avoid expanding redundant multiplication for the common
1058 case of squaring a complex number. */
1059 if (ar
== br
&& ai
== bi
)
1062 t4
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1064 rr
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, t2
);
1065 ri
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t3
, t4
);
1073 update_complex_assignment (gsi
, rr
, ri
);
1076 /* Keep this algorithm in sync with fold-const.c:const_binop().
1078 Expand complex division to scalars, straightforward algorithm.
1079 a / b = ((ar*br + ai*bi)/t) + i((ai*br - ar*bi)/t)
1084 expand_complex_div_straight (gimple_stmt_iterator
*gsi
, tree inner_type
,
1085 tree ar
, tree ai
, tree br
, tree bi
,
1086 enum tree_code code
)
1088 tree rr
, ri
, div
, t1
, t2
, t3
;
1090 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, br
, br
);
1091 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, bi
, bi
);
1092 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, t2
);
1094 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, br
);
1095 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, bi
);
1096 t3
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, t2
);
1097 rr
= gimplify_build2 (gsi
, code
, inner_type
, t3
, div
);
1099 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, br
);
1100 t2
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, bi
);
1101 t3
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, t2
);
1102 ri
= gimplify_build2 (gsi
, code
, inner_type
, t3
, div
);
1104 update_complex_assignment (gsi
, rr
, ri
);
1107 /* Keep this algorithm in sync with fold-const.c:const_binop().
1109 Expand complex division to scalars, modified algorithm to minimize
1110 overflow with wide input ranges. */
1113 expand_complex_div_wide (gimple_stmt_iterator
*gsi
, tree inner_type
,
1114 tree ar
, tree ai
, tree br
, tree bi
,
1115 enum tree_code code
)
1117 tree rr
, ri
, ratio
, div
, t1
, t2
, tr
, ti
, compare
;
1118 basic_block bb_cond
, bb_true
, bb_false
, bb_join
;
1121 /* Examine |br| < |bi|, and branch. */
1122 t1
= gimplify_build1 (gsi
, ABS_EXPR
, inner_type
, br
);
1123 t2
= gimplify_build1 (gsi
, ABS_EXPR
, inner_type
, bi
);
1124 compare
= fold_build2_loc (gimple_location (gsi_stmt (*gsi
)),
1125 LT_EXPR
, boolean_type_node
, t1
, t2
);
1126 STRIP_NOPS (compare
);
1128 bb_cond
= bb_true
= bb_false
= bb_join
= NULL
;
1129 rr
= ri
= tr
= ti
= NULL
;
1130 if (TREE_CODE (compare
) != INTEGER_CST
)
1136 tmp
= create_tmp_var (boolean_type_node
, NULL
);
1137 stmt
= gimple_build_assign (tmp
, compare
);
1138 if (gimple_in_ssa_p (cfun
))
1140 tmp
= make_ssa_name (tmp
, stmt
);
1141 gimple_assign_set_lhs (stmt
, tmp
);
1144 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1146 cond
= fold_build2_loc (gimple_location (stmt
),
1147 EQ_EXPR
, boolean_type_node
, tmp
, boolean_true_node
);
1148 stmt
= gimple_build_cond_from_tree (cond
, NULL_TREE
, NULL_TREE
);
1149 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1151 /* Split the original block, and create the TRUE and FALSE blocks. */
1152 e
= split_block (gsi_bb (*gsi
), stmt
);
1155 bb_true
= create_empty_bb (bb_cond
);
1156 bb_false
= create_empty_bb (bb_true
);
1158 /* Wire the blocks together. */
1159 e
->flags
= EDGE_TRUE_VALUE
;
1160 redirect_edge_succ (e
, bb_true
);
1161 make_edge (bb_cond
, bb_false
, EDGE_FALSE_VALUE
);
1162 make_edge (bb_true
, bb_join
, EDGE_FALLTHRU
);
1163 make_edge (bb_false
, bb_join
, EDGE_FALLTHRU
);
1164 add_bb_to_loop (bb_true
, bb_cond
->loop_father
);
1165 add_bb_to_loop (bb_false
, bb_cond
->loop_father
);
1167 /* Update dominance info. Note that bb_join's data was
1168 updated by split_block. */
1169 if (dom_info_available_p (CDI_DOMINATORS
))
1171 set_immediate_dominator (CDI_DOMINATORS
, bb_true
, bb_cond
);
1172 set_immediate_dominator (CDI_DOMINATORS
, bb_false
, bb_cond
);
1175 rr
= create_tmp_reg (inner_type
, NULL
);
1176 ri
= create_tmp_reg (inner_type
, NULL
);
1179 /* In the TRUE branch, we compute
1181 div = (br * ratio) + bi;
1182 tr = (ar * ratio) + ai;
1183 ti = (ai * ratio) - ar;
1186 if (bb_true
|| integer_nonzerop (compare
))
1190 *gsi
= gsi_last_bb (bb_true
);
1191 gsi_insert_after (gsi
, gimple_build_nop (), GSI_NEW_STMT
);
1194 ratio
= gimplify_build2 (gsi
, code
, inner_type
, br
, bi
);
1196 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, br
, ratio
);
1197 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, bi
);
1199 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, ratio
);
1200 tr
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, ai
);
1202 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, ratio
);
1203 ti
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, t1
, ar
);
1205 tr
= gimplify_build2 (gsi
, code
, inner_type
, tr
, div
);
1206 ti
= gimplify_build2 (gsi
, code
, inner_type
, ti
, div
);
1210 stmt
= gimple_build_assign (rr
, tr
);
1211 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1212 stmt
= gimple_build_assign (ri
, ti
);
1213 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1214 gsi_remove (gsi
, true);
1218 /* In the FALSE branch, we compute
1220 divisor = (d * ratio) + c;
1221 tr = (b * ratio) + a;
1222 ti = b - (a * ratio);
1225 if (bb_false
|| integer_zerop (compare
))
1229 *gsi
= gsi_last_bb (bb_false
);
1230 gsi_insert_after (gsi
, gimple_build_nop (), GSI_NEW_STMT
);
1233 ratio
= gimplify_build2 (gsi
, code
, inner_type
, bi
, br
);
1235 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, bi
, ratio
);
1236 div
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, br
);
1238 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ai
, ratio
);
1239 tr
= gimplify_build2 (gsi
, PLUS_EXPR
, inner_type
, t1
, ar
);
1241 t1
= gimplify_build2 (gsi
, MULT_EXPR
, inner_type
, ar
, ratio
);
1242 ti
= gimplify_build2 (gsi
, MINUS_EXPR
, inner_type
, ai
, t1
);
1244 tr
= gimplify_build2 (gsi
, code
, inner_type
, tr
, div
);
1245 ti
= gimplify_build2 (gsi
, code
, inner_type
, ti
, div
);
1249 stmt
= gimple_build_assign (rr
, tr
);
1250 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1251 stmt
= gimple_build_assign (ri
, ti
);
1252 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
1253 gsi_remove (gsi
, true);
1258 *gsi
= gsi_start_bb (bb_join
);
1262 update_complex_assignment (gsi
, rr
, ri
);
1265 /* Expand complex division to scalars. */
1268 expand_complex_division (gimple_stmt_iterator
*gsi
, tree inner_type
,
1269 tree ar
, tree ai
, tree br
, tree bi
,
1270 enum tree_code code
,
1271 complex_lattice_t al
, complex_lattice_t bl
)
1275 switch (PAIR (al
, bl
))
1277 case PAIR (ONLY_REAL
, ONLY_REAL
):
1278 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
1282 case PAIR (ONLY_REAL
, ONLY_IMAG
):
1284 ri
= gimplify_build2 (gsi
, code
, inner_type
, ar
, bi
);
1285 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ri
);
1288 case PAIR (ONLY_IMAG
, ONLY_REAL
):
1290 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, br
);
1293 case PAIR (ONLY_IMAG
, ONLY_IMAG
):
1294 rr
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
1298 case PAIR (VARYING
, ONLY_REAL
):
1299 rr
= gimplify_build2 (gsi
, code
, inner_type
, ar
, br
);
1300 ri
= gimplify_build2 (gsi
, code
, inner_type
, ai
, br
);
1303 case PAIR (VARYING
, ONLY_IMAG
):
1304 rr
= gimplify_build2 (gsi
, code
, inner_type
, ai
, bi
);
1305 ri
= gimplify_build2 (gsi
, code
, inner_type
, ar
, bi
);
1306 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ri
);
1308 case PAIR (ONLY_REAL
, VARYING
):
1309 case PAIR (ONLY_IMAG
, VARYING
):
1310 case PAIR (VARYING
, VARYING
):
1311 switch (flag_complex_method
)
1314 /* straightforward implementation of complex divide acceptable. */
1315 expand_complex_div_straight (gsi
, inner_type
, ar
, ai
, br
, bi
, code
);
1319 if (SCALAR_FLOAT_TYPE_P (inner_type
))
1321 expand_complex_libcall (gsi
, ar
, ai
, br
, bi
, code
);
1327 /* wide ranges of inputs must work for complex divide. */
1328 expand_complex_div_wide (gsi
, inner_type
, ar
, ai
, br
, bi
, code
);
1340 update_complex_assignment (gsi
, rr
, ri
);
1343 /* Expand complex negation to scalars:
1348 expand_complex_negation (gimple_stmt_iterator
*gsi
, tree inner_type
,
1353 rr
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ar
);
1354 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ai
);
1356 update_complex_assignment (gsi
, rr
, ri
);
1359 /* Expand complex conjugate to scalars:
1364 expand_complex_conjugate (gimple_stmt_iterator
*gsi
, tree inner_type
,
1369 ri
= gimplify_build1 (gsi
, NEGATE_EXPR
, inner_type
, ai
);
1371 update_complex_assignment (gsi
, ar
, ri
);
1374 /* Expand complex comparison (EQ or NE only). */
1377 expand_complex_comparison (gimple_stmt_iterator
*gsi
, tree ar
, tree ai
,
1378 tree br
, tree bi
, enum tree_code code
)
1380 tree cr
, ci
, cc
, type
;
1383 cr
= gimplify_build2 (gsi
, code
, boolean_type_node
, ar
, br
);
1384 ci
= gimplify_build2 (gsi
, code
, boolean_type_node
, ai
, bi
);
1385 cc
= gimplify_build2 (gsi
,
1386 (code
== EQ_EXPR
? TRUTH_AND_EXPR
: TRUTH_OR_EXPR
),
1387 boolean_type_node
, cr
, ci
);
1389 stmt
= gsi_stmt (*gsi
);
1391 switch (gimple_code (stmt
))
1395 gimple_return return_stmt
= as_a
<gimple_return
> (stmt
);
1396 type
= TREE_TYPE (gimple_return_retval (return_stmt
));
1397 gimple_return_set_retval (return_stmt
, fold_convert (type
, cc
));
1402 type
= TREE_TYPE (gimple_assign_lhs (stmt
));
1403 gimple_assign_set_rhs_from_tree (gsi
, fold_convert (type
, cc
));
1404 stmt
= gsi_stmt (*gsi
);
1409 gimple_cond cond_stmt
= as_a
<gimple_cond
> (stmt
);
1410 gimple_cond_set_code (cond_stmt
, EQ_EXPR
);
1411 gimple_cond_set_lhs (cond_stmt
, cc
);
1412 gimple_cond_set_rhs (cond_stmt
, boolean_true_node
);
1423 /* Expand inline asm that sets some complex SSA_NAMEs. */
1426 expand_complex_asm (gimple_stmt_iterator
*gsi
)
1428 gimple_asm stmt
= as_a
<gimple_asm
> (gsi_stmt (*gsi
));
1431 for (i
= 0; i
< gimple_asm_noutputs (stmt
); ++i
)
1433 tree link
= gimple_asm_output_op (stmt
, i
);
1434 tree op
= TREE_VALUE (link
);
1435 if (TREE_CODE (op
) == SSA_NAME
1436 && TREE_CODE (TREE_TYPE (op
)) == COMPLEX_TYPE
)
1438 tree type
= TREE_TYPE (op
);
1439 tree inner_type
= TREE_TYPE (type
);
1440 tree r
= build1 (REALPART_EXPR
, inner_type
, op
);
1441 tree i
= build1 (IMAGPART_EXPR
, inner_type
, op
);
1442 gimple_seq list
= set_component_ssa_name (op
, false, r
);
1445 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
1447 list
= set_component_ssa_name (op
, true, i
);
1449 gsi_insert_seq_after (gsi
, list
, GSI_CONTINUE_LINKING
);
1454 /* Process one statement. If we identify a complex operation, expand it. */
1457 expand_complex_operations_1 (gimple_stmt_iterator
*gsi
)
1459 gimple stmt
= gsi_stmt (*gsi
);
1460 tree type
, inner_type
, lhs
;
1461 tree ac
, ar
, ai
, bc
, br
, bi
;
1462 complex_lattice_t al
, bl
;
1463 enum tree_code code
;
1465 if (gimple_code (stmt
) == GIMPLE_ASM
)
1467 expand_complex_asm (gsi
);
1471 lhs
= gimple_get_lhs (stmt
);
1472 if (!lhs
&& gimple_code (stmt
) != GIMPLE_COND
)
1475 type
= TREE_TYPE (gimple_op (stmt
, 0));
1476 code
= gimple_expr_code (stmt
);
1478 /* Initial filter for operations we handle. */
1484 case TRUNC_DIV_EXPR
:
1486 case FLOOR_DIV_EXPR
:
1487 case ROUND_DIV_EXPR
:
1491 if (TREE_CODE (type
) != COMPLEX_TYPE
)
1493 inner_type
= TREE_TYPE (type
);
1498 /* Note, both GIMPLE_ASSIGN and GIMPLE_COND may have an EQ_EXPR
1499 subcode, so we need to access the operands using gimple_op. */
1500 inner_type
= TREE_TYPE (gimple_op (stmt
, 1));
1501 if (TREE_CODE (inner_type
) != COMPLEX_TYPE
)
1509 /* GIMPLE_COND may also fallthru here, but we do not need to
1510 do anything with it. */
1511 if (gimple_code (stmt
) == GIMPLE_COND
)
1514 if (TREE_CODE (type
) == COMPLEX_TYPE
)
1515 expand_complex_move (gsi
, type
);
1516 else if (is_gimple_assign (stmt
)
1517 && (gimple_assign_rhs_code (stmt
) == REALPART_EXPR
1518 || gimple_assign_rhs_code (stmt
) == IMAGPART_EXPR
)
1519 && TREE_CODE (lhs
) == SSA_NAME
)
1521 rhs
= gimple_assign_rhs1 (stmt
);
1522 rhs
= extract_component (gsi
, TREE_OPERAND (rhs
, 0),
1523 gimple_assign_rhs_code (stmt
)
1526 gimple_assign_set_rhs_from_tree (gsi
, rhs
);
1527 stmt
= gsi_stmt (*gsi
);
1534 /* Extract the components of the two complex values. Make sure and
1535 handle the common case of the same value used twice specially. */
1536 if (is_gimple_assign (stmt
))
1538 ac
= gimple_assign_rhs1 (stmt
);
1539 bc
= (gimple_num_ops (stmt
) > 2) ? gimple_assign_rhs2 (stmt
) : NULL
;
1541 /* GIMPLE_CALL can not get here. */
1544 ac
= gimple_cond_lhs (stmt
);
1545 bc
= gimple_cond_rhs (stmt
);
1548 ar
= extract_component (gsi
, ac
, false, true);
1549 ai
= extract_component (gsi
, ac
, true, true);
1555 br
= extract_component (gsi
, bc
, 0, true);
1556 bi
= extract_component (gsi
, bc
, 1, true);
1559 br
= bi
= NULL_TREE
;
1561 if (gimple_in_ssa_p (cfun
))
1563 al
= find_lattice_value (ac
);
1564 if (al
== UNINITIALIZED
)
1567 if (TREE_CODE_CLASS (code
) == tcc_unary
)
1573 bl
= find_lattice_value (bc
);
1574 if (bl
== UNINITIALIZED
)
1585 expand_complex_addition (gsi
, inner_type
, ar
, ai
, br
, bi
, code
, al
, bl
);
1589 expand_complex_multiplication (gsi
, inner_type
, ar
, ai
, br
, bi
, al
, bl
);
1592 case TRUNC_DIV_EXPR
:
1594 case FLOOR_DIV_EXPR
:
1595 case ROUND_DIV_EXPR
:
1597 expand_complex_division (gsi
, inner_type
, ar
, ai
, br
, bi
, code
, al
, bl
);
1601 expand_complex_negation (gsi
, inner_type
, ar
, ai
);
1605 expand_complex_conjugate (gsi
, inner_type
, ar
, ai
);
1610 expand_complex_comparison (gsi
, ar
, ai
, br
, bi
, code
);
1619 /* Entry point for complex operation lowering during optimization. */
1622 tree_lower_complex (void)
1624 int old_last_basic_block
;
1625 gimple_stmt_iterator gsi
;
1628 if (!init_dont_simulate_again ())
1631 complex_lattice_values
.create (num_ssa_names
);
1632 complex_lattice_values
.safe_grow_cleared (num_ssa_names
);
1634 init_parameter_lattice_values ();
1635 ssa_propagate (complex_visit_stmt
, complex_visit_phi
);
1637 complex_variable_components
= new int_tree_htab_type (10);
1639 complex_ssa_name_components
.create (2 * num_ssa_names
);
1640 complex_ssa_name_components
.safe_grow_cleared (2 * num_ssa_names
);
1642 update_parameter_components ();
1644 /* ??? Ideally we'd traverse the blocks in breadth-first order. */
1645 old_last_basic_block
= last_basic_block_for_fn (cfun
);
1646 FOR_EACH_BB_FN (bb
, cfun
)
1648 if (bb
->index
>= old_last_basic_block
)
1651 update_phi_components (bb
);
1652 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1653 expand_complex_operations_1 (&gsi
);
1656 gsi_commit_edge_inserts ();
1658 delete complex_variable_components
;
1659 complex_variable_components
= NULL
;
1660 complex_ssa_name_components
.release ();
1661 complex_lattice_values
.release ();
1667 const pass_data pass_data_lower_complex
=
1669 GIMPLE_PASS
, /* type */
1670 "cplxlower", /* name */
1671 OPTGROUP_NONE
, /* optinfo_flags */
1672 TV_NONE
, /* tv_id */
1673 PROP_ssa
, /* properties_required */
1674 PROP_gimple_lcx
, /* properties_provided */
1675 0, /* properties_destroyed */
1676 0, /* todo_flags_start */
1677 TODO_update_ssa
, /* todo_flags_finish */
1680 class pass_lower_complex
: public gimple_opt_pass
1683 pass_lower_complex (gcc::context
*ctxt
)
1684 : gimple_opt_pass (pass_data_lower_complex
, ctxt
)
1687 /* opt_pass methods: */
1688 opt_pass
* clone () { return new pass_lower_complex (m_ctxt
); }
1689 virtual unsigned int execute (function
*) { return tree_lower_complex (); }
1691 }; // class pass_lower_complex
1696 make_pass_lower_complex (gcc::context
*ctxt
)
1698 return new pass_lower_complex (ctxt
);
1704 const pass_data pass_data_lower_complex_O0
=
1706 GIMPLE_PASS
, /* type */
1707 "cplxlower0", /* name */
1708 OPTGROUP_NONE
, /* optinfo_flags */
1709 TV_NONE
, /* tv_id */
1710 PROP_cfg
, /* properties_required */
1711 PROP_gimple_lcx
, /* properties_provided */
1712 0, /* properties_destroyed */
1713 0, /* todo_flags_start */
1714 TODO_update_ssa
, /* todo_flags_finish */
1717 class pass_lower_complex_O0
: public gimple_opt_pass
1720 pass_lower_complex_O0 (gcc::context
*ctxt
)
1721 : gimple_opt_pass (pass_data_lower_complex_O0
, ctxt
)
1724 /* opt_pass methods: */
1725 virtual bool gate (function
*fun
)
1727 /* With errors, normal optimization passes are not run. If we don't
1728 lower complex operations at all, rtl expansion will abort. */
1729 return !(fun
->curr_properties
& PROP_gimple_lcx
);
1732 virtual unsigned int execute (function
*) { return tree_lower_complex (); }
1734 }; // class pass_lower_complex_O0
1739 make_pass_lower_complex_O0 (gcc::context
*ctxt
)
1741 return new pass_lower_complex_O0 (ctxt
);