libstdc++: Refactor loops in std::__platform_semaphore
[official-gcc.git] / gcc / tree-complex.cc
blob7480c07640e108222d2a9ce06098c1aacd9b641a
1 /* Lower complex number operations to scalar operations.
2 Copyright (C) 2004-2024 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
9 later version.
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
14 for more details.
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/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "backend.h"
24 #include "target.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "gimple.h"
28 #include "cfghooks.h"
29 #include "tree-pass.h"
30 #include "ssa.h"
31 #include "fold-const.h"
32 #include "stor-layout.h"
33 #include "tree-eh.h"
34 #include "gimplify.h"
35 #include "gimple-iterator.h"
36 #include "gimplify-me.h"
37 #include "tree-cfg.h"
38 #include "tree-dfa.h"
39 #include "tree-ssa.h"
40 #include "tree-ssa-propagate.h"
41 #include "tree-hasher.h"
42 #include "cfgloop.h"
43 #include "cfganal.h"
44 #include "gimple-fold.h"
45 #include "diagnostic-core.h"
46 #include "case-cfn-macros.h"
47 #include "builtins.h"
48 #include "optabs-tree.h"
49 #include "tree-ssa-dce.h"
51 /* For each complex ssa name, a lattice value. We're interested in finding
52 out whether a complex number is degenerate in some way, having only real
53 or only complex parts. */
55 enum
57 UNINITIALIZED = 0,
58 ONLY_REAL = 1,
59 ONLY_IMAG = 2,
60 VARYING = 3
63 /* The type complex_lattice_t holds combinations of the above
64 constants. */
65 typedef int complex_lattice_t;
67 #define PAIR(a, b) ((a) << 2 | (b))
69 class complex_propagate : public ssa_propagation_engine
71 enum ssa_prop_result visit_stmt (gimple *, edge *, tree *) final override;
72 enum ssa_prop_result visit_phi (gphi *) final override;
75 static vec<complex_lattice_t> complex_lattice_values;
77 /* For each complex variable, a pair of variables for the components exists in
78 the hashtable. */
79 static int_tree_htab_type *complex_variable_components;
81 /* For each complex SSA_NAME, a pair of ssa names for the components. */
82 static vec<tree> complex_ssa_name_components;
84 /* Vector of PHI triplets (original complex PHI and corresponding real and
85 imag PHIs if real and/or imag PHIs contain temporarily
86 non-SSA_NAME/non-invariant args that need to be replaced by SSA_NAMEs. */
87 static vec<gphi *> phis_to_revisit;
89 /* BBs that need EH cleanup. */
90 static bitmap need_eh_cleanup;
92 /* SSA defs we should try to DCE. */
93 static bitmap dce_worklist;
95 /* Lookup UID in the complex_variable_components hashtable and return the
96 associated tree. */
97 static tree
98 cvc_lookup (unsigned int uid)
100 struct int_tree_map in;
101 in.uid = uid;
102 return complex_variable_components->find_with_hash (in, uid).to;
105 /* Insert the pair UID, TO into the complex_variable_components hashtable. */
107 static void
108 cvc_insert (unsigned int uid, tree to)
110 int_tree_map h;
111 int_tree_map *loc;
113 h.uid = uid;
114 loc = complex_variable_components->find_slot_with_hash (h, uid, INSERT);
115 loc->uid = uid;
116 loc->to = to;
119 /* Return true if T is not a zero constant. In the case of real values,
120 we're only interested in +0.0. */
122 static int
123 some_nonzerop (tree t)
125 int zerop = false;
127 /* Operations with real or imaginary part of a complex number zero
128 cannot be treated the same as operations with a real or imaginary
129 operand if we care about the signs of zeros in the result. */
130 if (TREE_CODE (t) == REAL_CST && !flag_signed_zeros)
131 zerop = real_identical (&TREE_REAL_CST (t), &dconst0);
132 else if (TREE_CODE (t) == FIXED_CST)
133 zerop = fixed_zerop (t);
134 else if (TREE_CODE (t) == INTEGER_CST)
135 zerop = integer_zerop (t);
137 return !zerop;
141 /* Compute a lattice value from the components of a complex type REAL
142 and IMAG. */
144 static complex_lattice_t
145 find_lattice_value_parts (tree real, tree imag)
147 int r, i;
148 complex_lattice_t ret;
150 r = some_nonzerop (real);
151 i = some_nonzerop (imag);
152 ret = r * ONLY_REAL + i * ONLY_IMAG;
154 /* ??? On occasion we could do better than mapping 0+0i to real, but we
155 certainly don't want to leave it UNINITIALIZED, which eventually gets
156 mapped to VARYING. */
157 if (ret == UNINITIALIZED)
158 ret = ONLY_REAL;
160 return ret;
164 /* Compute a lattice value from gimple_val T. */
166 static complex_lattice_t
167 find_lattice_value (tree t)
169 tree real, imag;
171 switch (TREE_CODE (t))
173 case SSA_NAME:
174 return complex_lattice_values[SSA_NAME_VERSION (t)];
176 case COMPLEX_CST:
177 real = TREE_REALPART (t);
178 imag = TREE_IMAGPART (t);
179 break;
181 default:
182 gcc_unreachable ();
185 return find_lattice_value_parts (real, imag);
188 /* Determine if LHS is something for which we're interested in seeing
189 simulation results. */
191 static bool
192 is_complex_reg (tree lhs)
194 return TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE && is_gimple_reg (lhs);
197 /* Mark the incoming parameters to the function as VARYING. */
199 static void
200 init_parameter_lattice_values (void)
202 tree parm, ssa_name;
204 for (parm = DECL_ARGUMENTS (cfun->decl); parm ; parm = DECL_CHAIN (parm))
205 if (is_complex_reg (parm)
206 && (ssa_name = ssa_default_def (cfun, parm)) != NULL_TREE)
207 complex_lattice_values[SSA_NAME_VERSION (ssa_name)] = VARYING;
210 /* Initialize simulation state for each statement. Return false if we
211 found no statements we want to simulate, and thus there's nothing
212 for the entire pass to do. */
214 static bool
215 init_dont_simulate_again (void)
217 basic_block bb;
218 bool saw_a_complex_op = false;
220 FOR_EACH_BB_FN (bb, cfun)
222 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
223 gsi_next (&gsi))
225 gphi *phi = gsi.phi ();
226 prop_set_simulate_again (phi,
227 is_complex_reg (gimple_phi_result (phi)));
230 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
231 gsi_next (&gsi))
233 gimple *stmt;
234 tree op0, op1;
235 bool sim_again_p;
237 stmt = gsi_stmt (gsi);
238 op0 = op1 = NULL_TREE;
240 /* Most control-altering statements must be initially
241 simulated, else we won't cover the entire cfg. */
242 sim_again_p = stmt_ends_bb_p (stmt);
244 switch (gimple_code (stmt))
246 case GIMPLE_CALL:
247 if (gimple_call_lhs (stmt))
249 sim_again_p = is_complex_reg (gimple_call_lhs (stmt));
250 switch (gimple_call_combined_fn (stmt))
252 CASE_CFN_CABS:
253 /* Expand cabs only if unsafe math and optimizing. */
254 if (optimize && flag_unsafe_math_optimizations)
255 saw_a_complex_op = true;
256 break;
257 default:;
260 break;
262 case GIMPLE_ASSIGN:
263 sim_again_p = is_complex_reg (gimple_assign_lhs (stmt));
264 if (gimple_assign_rhs_code (stmt) == REALPART_EXPR
265 || gimple_assign_rhs_code (stmt) == IMAGPART_EXPR)
266 op0 = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
267 else
268 op0 = gimple_assign_rhs1 (stmt);
269 if (gimple_num_ops (stmt) > 2)
270 op1 = gimple_assign_rhs2 (stmt);
271 break;
273 case GIMPLE_COND:
274 op0 = gimple_cond_lhs (stmt);
275 op1 = gimple_cond_rhs (stmt);
276 break;
278 default:
279 break;
282 if (op0 || op1)
283 switch (gimple_expr_code (stmt))
285 case EQ_EXPR:
286 case NE_EXPR:
287 case PLUS_EXPR:
288 case MINUS_EXPR:
289 case MULT_EXPR:
290 case TRUNC_DIV_EXPR:
291 case CEIL_DIV_EXPR:
292 case FLOOR_DIV_EXPR:
293 case ROUND_DIV_EXPR:
294 case RDIV_EXPR:
295 if (TREE_CODE (TREE_TYPE (op0)) == COMPLEX_TYPE
296 || TREE_CODE (TREE_TYPE (op1)) == COMPLEX_TYPE)
297 saw_a_complex_op = true;
298 break;
300 case NEGATE_EXPR:
301 case CONJ_EXPR:
302 case PAREN_EXPR:
303 if (TREE_CODE (TREE_TYPE (op0)) == COMPLEX_TYPE)
304 saw_a_complex_op = true;
305 break;
307 case REALPART_EXPR:
308 case IMAGPART_EXPR:
309 /* The total store transformation performed during
310 gimplification creates such uninitialized loads
311 and we need to lower the statement to be able
312 to fix things up. */
313 if (TREE_CODE (op0) == SSA_NAME
314 && ssa_undefined_value_p (op0))
315 saw_a_complex_op = true;
316 break;
318 default:
319 /* When expand_complex_move would trigger make sure we
320 perform lowering even when there is no actual complex
321 operation. This helps consistency and vectorization. */
322 if (TREE_CODE (TREE_TYPE (gimple_op (stmt, 0))) == COMPLEX_TYPE)
323 saw_a_complex_op = true;
324 break;
327 prop_set_simulate_again (stmt, sim_again_p);
331 return saw_a_complex_op;
335 /* Evaluate statement STMT against the complex lattice defined above. */
337 enum ssa_prop_result
338 complex_propagate::visit_stmt (gimple *stmt, edge *taken_edge_p ATTRIBUTE_UNUSED,
339 tree *result_p)
341 complex_lattice_t new_l, old_l, op1_l, op2_l;
342 unsigned int ver;
343 tree lhs;
345 lhs = gimple_get_lhs (stmt);
346 /* Skip anything but GIMPLE_ASSIGN and GIMPLE_CALL with a lhs. */
347 if (!lhs || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
348 return SSA_PROP_VARYING;
350 /* These conditions should be satisfied due to the initial filter
351 set up in init_dont_simulate_again. */
352 gcc_assert (TREE_CODE (lhs) == SSA_NAME);
353 gcc_assert (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE);
355 *result_p = lhs;
356 ver = SSA_NAME_VERSION (lhs);
357 old_l = complex_lattice_values[ver];
359 switch (gimple_expr_code (stmt))
361 case SSA_NAME:
362 case COMPLEX_CST:
363 new_l = find_lattice_value (gimple_assign_rhs1 (stmt));
364 break;
366 case COMPLEX_EXPR:
367 new_l = find_lattice_value_parts (gimple_assign_rhs1 (stmt),
368 gimple_assign_rhs2 (stmt));
369 break;
371 case PLUS_EXPR:
372 case MINUS_EXPR:
373 op1_l = find_lattice_value (gimple_assign_rhs1 (stmt));
374 op2_l = find_lattice_value (gimple_assign_rhs2 (stmt));
376 /* We've set up the lattice values such that IOR neatly
377 models addition. */
378 new_l = op1_l | op2_l;
379 break;
381 case MULT_EXPR:
382 case RDIV_EXPR:
383 case TRUNC_DIV_EXPR:
384 case CEIL_DIV_EXPR:
385 case FLOOR_DIV_EXPR:
386 case ROUND_DIV_EXPR:
387 op1_l = find_lattice_value (gimple_assign_rhs1 (stmt));
388 op2_l = find_lattice_value (gimple_assign_rhs2 (stmt));
390 /* Obviously, if either varies, so does the result. */
391 if (op1_l == VARYING || op2_l == VARYING)
392 new_l = VARYING;
393 /* Don't prematurely promote variables if we've not yet seen
394 their inputs. */
395 else if (op1_l == UNINITIALIZED)
396 new_l = op2_l;
397 else if (op2_l == UNINITIALIZED)
398 new_l = op1_l;
399 else
401 /* At this point both numbers have only one component. If the
402 numbers are of opposite kind, the result is imaginary,
403 otherwise the result is real. The add/subtract translates
404 the real/imag from/to 0/1; the ^ performs the comparison. */
405 new_l = ((op1_l - ONLY_REAL) ^ (op2_l - ONLY_REAL)) + ONLY_REAL;
407 /* Don't allow the lattice value to flip-flop indefinitely. */
408 new_l |= old_l;
410 break;
412 case NEGATE_EXPR:
413 case PAREN_EXPR:
414 case CONJ_EXPR:
415 new_l = find_lattice_value (gimple_assign_rhs1 (stmt));
416 break;
418 default:
419 new_l = VARYING;
420 break;
423 /* If nothing changed this round, let the propagator know. */
424 if (new_l == old_l)
425 return SSA_PROP_NOT_INTERESTING;
427 complex_lattice_values[ver] = new_l;
428 return new_l == VARYING ? SSA_PROP_VARYING : SSA_PROP_INTERESTING;
431 /* Evaluate a PHI node against the complex lattice defined above. */
433 enum ssa_prop_result
434 complex_propagate::visit_phi (gphi *phi)
436 complex_lattice_t new_l, old_l;
437 unsigned int ver;
438 tree lhs;
439 int i;
441 lhs = gimple_phi_result (phi);
443 /* This condition should be satisfied due to the initial filter
444 set up in init_dont_simulate_again. */
445 gcc_assert (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE);
447 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
448 return SSA_PROP_VARYING;
450 /* We've set up the lattice values such that IOR neatly models PHI meet. */
451 new_l = UNINITIALIZED;
452 for (i = gimple_phi_num_args (phi) - 1; i >= 0; --i)
453 new_l |= find_lattice_value (gimple_phi_arg_def (phi, i));
455 ver = SSA_NAME_VERSION (lhs);
456 old_l = complex_lattice_values[ver];
458 if (new_l == old_l)
459 return SSA_PROP_NOT_INTERESTING;
461 complex_lattice_values[ver] = new_l;
462 return new_l == VARYING ? SSA_PROP_VARYING : SSA_PROP_INTERESTING;
465 /* Create one backing variable for a complex component of ORIG. */
467 static tree
468 create_one_component_var (tree type, tree orig, const char *prefix,
469 const char *suffix, enum tree_code code)
471 tree r = create_tmp_var (type, prefix);
473 DECL_SOURCE_LOCATION (r) = DECL_SOURCE_LOCATION (orig);
474 DECL_ARTIFICIAL (r) = 1;
476 if (DECL_NAME (orig) && !DECL_IGNORED_P (orig))
478 const char *name = IDENTIFIER_POINTER (DECL_NAME (orig));
479 name = ACONCAT ((name, suffix, NULL));
480 DECL_NAME (r) = get_identifier (name);
482 SET_DECL_DEBUG_EXPR (r, build1 (code, type, orig));
483 DECL_HAS_DEBUG_EXPR_P (r) = 1;
484 DECL_IGNORED_P (r) = 0;
485 copy_warning (r, orig);
487 else
489 DECL_IGNORED_P (r) = 1;
490 suppress_warning (r);
493 return r;
496 /* Retrieve a value for a complex component of VAR. */
498 static tree
499 get_component_var (tree var, bool imag_p)
501 size_t decl_index = DECL_UID (var) * 2 + imag_p;
502 tree ret = cvc_lookup (decl_index);
504 if (ret == NULL)
506 ret = create_one_component_var (TREE_TYPE (TREE_TYPE (var)), var,
507 imag_p ? "CI" : "CR",
508 imag_p ? "$imag" : "$real",
509 imag_p ? IMAGPART_EXPR : REALPART_EXPR);
510 cvc_insert (decl_index, ret);
513 return ret;
516 /* Retrieve a value for a complex component of SSA_NAME. */
518 static tree
519 get_component_ssa_name (tree ssa_name, bool imag_p)
521 complex_lattice_t lattice = find_lattice_value (ssa_name);
522 size_t ssa_name_index;
523 tree ret;
525 if (lattice == (imag_p ? ONLY_REAL : ONLY_IMAG))
527 tree inner_type = TREE_TYPE (TREE_TYPE (ssa_name));
528 if (SCALAR_FLOAT_TYPE_P (inner_type))
529 return build_real (inner_type, dconst0);
530 else
531 return build_int_cst (inner_type, 0);
534 ssa_name_index = SSA_NAME_VERSION (ssa_name) * 2 + imag_p;
535 ret = complex_ssa_name_components[ssa_name_index];
536 if (ret == NULL)
538 if (SSA_NAME_VAR (ssa_name))
539 ret = get_component_var (SSA_NAME_VAR (ssa_name), imag_p);
540 else
541 ret = TREE_TYPE (TREE_TYPE (ssa_name));
542 ret = make_ssa_name (ret);
544 /* Copy some properties from the original. In particular, whether it
545 is used in an abnormal phi, and whether it's uninitialized. */
546 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ret)
547 = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name);
548 if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
549 && VAR_P (SSA_NAME_VAR (ssa_name)))
551 SSA_NAME_DEF_STMT (ret) = SSA_NAME_DEF_STMT (ssa_name);
552 set_ssa_default_def (cfun, SSA_NAME_VAR (ret), ret);
555 complex_ssa_name_components[ssa_name_index] = ret;
558 return ret;
561 /* Set a value for a complex component of SSA_NAME, return a
562 gimple_seq of stuff that needs doing. */
564 static gimple_seq
565 set_component_ssa_name (tree ssa_name, bool imag_p, tree value)
567 complex_lattice_t lattice = find_lattice_value (ssa_name);
568 size_t ssa_name_index;
569 tree comp;
570 gimple *last;
571 gimple_seq list;
573 /* We know the value must be zero, else there's a bug in our lattice
574 analysis. But the value may well be a variable known to contain
575 zero. We should be safe ignoring it. */
576 if (lattice == (imag_p ? ONLY_REAL : ONLY_IMAG))
577 return NULL;
579 /* If we've already assigned an SSA_NAME to this component, then this
580 means that our walk of the basic blocks found a use before the set.
581 This is fine. Now we should create an initialization for the value
582 we created earlier. */
583 ssa_name_index = SSA_NAME_VERSION (ssa_name) * 2 + imag_p;
584 comp = complex_ssa_name_components[ssa_name_index];
585 if (comp)
588 /* If we've nothing assigned, and the value we're given is already stable,
589 then install that as the value for this SSA_NAME. This preemptively
590 copy-propagates the value, which avoids unnecessary memory allocation. */
591 else if (is_gimple_min_invariant (value)
592 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
594 complex_ssa_name_components[ssa_name_index] = value;
595 return NULL;
597 else if (TREE_CODE (value) == SSA_NAME
598 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
600 /* Replace an anonymous base value with the variable from cvc_lookup.
601 This should result in better debug info. */
602 if (!SSA_NAME_IS_DEFAULT_DEF (value)
603 && SSA_NAME_VAR (ssa_name)
604 && (!SSA_NAME_VAR (value) || DECL_IGNORED_P (SSA_NAME_VAR (value)))
605 && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name)))
607 comp = get_component_var (SSA_NAME_VAR (ssa_name), imag_p);
608 replace_ssa_name_symbol (value, comp);
611 complex_ssa_name_components[ssa_name_index] = value;
612 return NULL;
615 /* Finally, we need to stabilize the result by installing the value into
616 a new ssa name. */
617 else
618 comp = get_component_ssa_name (ssa_name, imag_p);
620 /* Do all the work to assign VALUE to COMP. */
621 list = NULL;
622 value = force_gimple_operand (value, &list, false, NULL);
623 last = gimple_build_assign (comp, value);
624 gimple_seq_add_stmt (&list, last);
625 gcc_assert (SSA_NAME_DEF_STMT (comp) == last);
627 return list;
630 /* Extract the real or imaginary part of a complex variable or constant.
631 Make sure that it's a proper gimple_val and gimplify it if not.
632 Emit any new code before gsi. */
634 static tree
635 extract_component (gimple_stmt_iterator *gsi, tree t, bool imagpart_p,
636 bool gimple_p, bool phiarg_p = false)
638 switch (TREE_CODE (t))
640 case COMPLEX_CST:
641 return imagpart_p ? TREE_IMAGPART (t) : TREE_REALPART (t);
643 case COMPLEX_EXPR:
644 gcc_unreachable ();
646 case BIT_FIELD_REF:
648 tree inner_type = TREE_TYPE (TREE_TYPE (t));
649 t = unshare_expr (t);
650 TREE_TYPE (t) = inner_type;
651 TREE_OPERAND (t, 1) = TYPE_SIZE (inner_type);
652 if (imagpart_p)
653 TREE_OPERAND (t, 2) = size_binop (PLUS_EXPR, TREE_OPERAND (t, 2),
654 TYPE_SIZE (inner_type));
655 if (gimple_p)
656 t = force_gimple_operand_gsi (gsi, t, true, NULL, true,
657 GSI_SAME_STMT);
658 return t;
661 case VAR_DECL:
662 case RESULT_DECL:
663 case PARM_DECL:
664 case COMPONENT_REF:
665 case ARRAY_REF:
666 case VIEW_CONVERT_EXPR:
667 case MEM_REF:
669 tree inner_type = TREE_TYPE (TREE_TYPE (t));
671 t = build1 ((imagpart_p ? IMAGPART_EXPR : REALPART_EXPR),
672 inner_type, unshare_expr (t));
674 if (gimple_p)
675 t = force_gimple_operand_gsi (gsi, t, true, NULL, true,
676 GSI_SAME_STMT);
678 return t;
681 case SSA_NAME:
682 t = get_component_ssa_name (t, imagpart_p);
683 if (TREE_CODE (t) == SSA_NAME && SSA_NAME_DEF_STMT (t) == NULL)
684 gcc_assert (phiarg_p);
685 return t;
687 default:
688 gcc_unreachable ();
692 /* Update the complex components of the ssa name on the lhs of STMT. */
694 static void
695 update_complex_components (gimple_stmt_iterator *gsi, gimple *stmt, tree r,
696 tree i)
698 tree lhs;
699 gimple_seq list;
701 lhs = gimple_get_lhs (stmt);
703 list = set_component_ssa_name (lhs, false, r);
704 if (list)
705 gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
707 list = set_component_ssa_name (lhs, true, i);
708 if (list)
709 gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
712 static void
713 update_complex_components_on_edge (edge e, tree lhs, tree r, tree i)
715 gimple_seq list;
717 list = set_component_ssa_name (lhs, false, r);
718 if (list)
719 gsi_insert_seq_on_edge (e, list);
721 list = set_component_ssa_name (lhs, true, i);
722 if (list)
723 gsi_insert_seq_on_edge (e, list);
727 /* Update an assignment to a complex variable in place. */
729 static void
730 update_complex_assignment (gimple_stmt_iterator *gsi, tree r, tree i)
732 gimple *old_stmt = gsi_stmt (*gsi);
733 gimple_assign_set_rhs_with_ops (gsi, COMPLEX_EXPR, r, i);
734 gimple *stmt = gsi_stmt (*gsi);
735 update_stmt (stmt);
736 if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
737 bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index);
738 bitmap_set_bit (dce_worklist, SSA_NAME_VERSION (gimple_assign_lhs (stmt)));
740 update_complex_components (gsi, gsi_stmt (*gsi), r, i);
744 /* Generate code at the entry point of the function to initialize the
745 component variables for a complex parameter. */
747 static void
748 update_parameter_components (void)
750 edge entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
751 tree parm;
753 for (parm = DECL_ARGUMENTS (cfun->decl); parm ; parm = DECL_CHAIN (parm))
755 tree type = TREE_TYPE (parm);
756 tree ssa_name, r, i;
758 if (TREE_CODE (type) != COMPLEX_TYPE || !is_gimple_reg (parm))
759 continue;
761 type = TREE_TYPE (type);
762 ssa_name = ssa_default_def (cfun, parm);
763 if (!ssa_name)
764 continue;
766 r = build1 (REALPART_EXPR, type, ssa_name);
767 i = build1 (IMAGPART_EXPR, type, ssa_name);
768 update_complex_components_on_edge (entry_edge, ssa_name, r, i);
772 /* Generate code to set the component variables of a complex variable
773 to match the PHI statements in block BB. */
775 static void
776 update_phi_components (basic_block bb)
778 gphi_iterator gsi;
780 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
782 gphi *phi = gsi.phi ();
784 if (is_complex_reg (gimple_phi_result (phi)))
786 gphi *p[2] = { NULL, NULL };
787 unsigned int i, j, n;
788 bool revisit_phi = false;
790 for (j = 0; j < 2; j++)
792 tree l = get_component_ssa_name (gimple_phi_result (phi), j > 0);
793 if (TREE_CODE (l) == SSA_NAME)
794 p[j] = create_phi_node (l, bb);
797 for (i = 0, n = gimple_phi_num_args (phi); i < n; ++i)
799 tree comp, arg = gimple_phi_arg_def (phi, i);
800 for (j = 0; j < 2; j++)
801 if (p[j])
803 comp = extract_component (NULL, arg, j > 0, false, true);
804 if (TREE_CODE (comp) == SSA_NAME
805 && SSA_NAME_DEF_STMT (comp) == NULL)
807 /* For the benefit of any gimple simplification during
808 this pass that might walk SSA_NAME def stmts,
809 don't add SSA_NAMEs without definitions into the
810 PHI arguments, but put a decl in there instead
811 temporarily, and revisit this PHI later on. */
812 if (SSA_NAME_VAR (comp))
813 comp = SSA_NAME_VAR (comp);
814 else
815 comp = create_tmp_reg (TREE_TYPE (comp),
816 get_name (comp));
817 revisit_phi = true;
819 SET_PHI_ARG_DEF (p[j], i, comp);
823 if (revisit_phi)
825 phis_to_revisit.safe_push (phi);
826 phis_to_revisit.safe_push (p[0]);
827 phis_to_revisit.safe_push (p[1]);
833 /* Expand a complex move to scalars. */
835 static void
836 expand_complex_move (gimple_stmt_iterator *gsi, tree type)
838 tree inner_type = TREE_TYPE (type);
839 tree r, i, lhs, rhs;
840 gimple *stmt = gsi_stmt (*gsi);
842 if (is_gimple_assign (stmt))
844 lhs = gimple_assign_lhs (stmt);
845 if (gimple_num_ops (stmt) == 2)
846 rhs = gimple_assign_rhs1 (stmt);
847 else
848 rhs = NULL_TREE;
850 else if (is_gimple_call (stmt))
852 lhs = gimple_call_lhs (stmt);
853 rhs = NULL_TREE;
855 else
856 gcc_unreachable ();
858 if (TREE_CODE (lhs) == SSA_NAME)
860 if (is_ctrl_altering_stmt (stmt))
862 edge e;
864 /* The value is not assigned on the exception edges, so we need not
865 concern ourselves there. We do need to update on the fallthru
866 edge. Find it. */
867 e = find_fallthru_edge (gsi_bb (*gsi)->succs);
868 if (!e)
869 gcc_unreachable ();
871 r = build1 (REALPART_EXPR, inner_type, lhs);
872 i = build1 (IMAGPART_EXPR, inner_type, lhs);
873 update_complex_components_on_edge (e, lhs, r, i);
875 else if (is_gimple_call (stmt)
876 || gimple_has_side_effects (stmt))
878 r = build1 (REALPART_EXPR, inner_type, lhs);
879 i = build1 (IMAGPART_EXPR, inner_type, lhs);
880 update_complex_components (gsi, stmt, r, i);
882 else
884 if (gimple_assign_rhs_code (stmt) != COMPLEX_EXPR)
886 r = extract_component (gsi, rhs, 0, true);
887 i = extract_component (gsi, rhs, 1, true);
889 else
891 r = gimple_assign_rhs1 (stmt);
892 i = gimple_assign_rhs2 (stmt);
894 update_complex_assignment (gsi, r, i);
897 else if (rhs
898 && (TREE_CODE (rhs) == SSA_NAME || TREE_CODE (rhs) == COMPLEX_CST)
899 && !TREE_SIDE_EFFECTS (lhs))
901 tree x;
902 gimple *t;
903 location_t loc;
905 loc = gimple_location (stmt);
906 r = extract_component (gsi, rhs, 0, false);
907 i = extract_component (gsi, rhs, 1, false);
909 x = build1 (REALPART_EXPR, inner_type, unshare_expr (lhs));
910 t = gimple_build_assign (x, r);
911 gimple_set_location (t, loc);
912 gsi_insert_before (gsi, t, GSI_SAME_STMT);
914 if (stmt == gsi_stmt (*gsi))
916 x = build1 (IMAGPART_EXPR, inner_type, unshare_expr (lhs));
917 gimple_assign_set_lhs (stmt, x);
918 gimple_assign_set_rhs1 (stmt, i);
920 else
922 x = build1 (IMAGPART_EXPR, inner_type, unshare_expr (lhs));
923 t = gimple_build_assign (x, i);
924 gimple_set_location (t, loc);
925 gsi_insert_before (gsi, t, GSI_SAME_STMT);
927 stmt = gsi_stmt (*gsi);
928 gcc_assert (gimple_code (stmt) == GIMPLE_RETURN);
929 gimple_return_set_retval (as_a <greturn *> (stmt), lhs);
932 update_stmt (stmt);
936 /* Expand complex addition to scalars:
937 a + b = (ar + br) + i(ai + bi)
938 a - b = (ar - br) + i(ai + bi)
941 static void
942 expand_complex_addition (gimple_stmt_iterator *gsi, tree inner_type,
943 tree ar, tree ai, tree br, tree bi,
944 enum tree_code code,
945 complex_lattice_t al, complex_lattice_t bl)
947 tree rr, ri;
948 gimple_seq stmts = NULL;
949 location_t loc = gimple_location (gsi_stmt (*gsi));
951 switch (PAIR (al, bl))
953 case PAIR (ONLY_REAL, ONLY_REAL):
954 rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
955 ri = ai;
956 break;
958 case PAIR (ONLY_REAL, ONLY_IMAG):
959 rr = ar;
960 if (code == MINUS_EXPR)
961 ri = gimple_build (&stmts, loc, MINUS_EXPR, inner_type, ai, bi);
962 else
963 ri = bi;
964 break;
966 case PAIR (ONLY_IMAG, ONLY_REAL):
967 if (code == MINUS_EXPR)
968 rr = gimple_build (&stmts, loc, MINUS_EXPR, inner_type, ar, br);
969 else
970 rr = br;
971 ri = ai;
972 break;
974 case PAIR (ONLY_IMAG, ONLY_IMAG):
975 rr = ar;
976 ri = gimple_build (&stmts, loc, code, inner_type, ai, bi);
977 break;
979 case PAIR (VARYING, ONLY_REAL):
980 rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
981 ri = ai;
982 break;
984 case PAIR (VARYING, ONLY_IMAG):
985 rr = ar;
986 ri = gimple_build (&stmts, loc, code, inner_type, ai, bi);
987 break;
989 case PAIR (ONLY_REAL, VARYING):
990 if (code == MINUS_EXPR)
991 goto general;
992 rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
993 ri = bi;
994 break;
996 case PAIR (ONLY_IMAG, VARYING):
997 if (code == MINUS_EXPR)
998 goto general;
999 rr = br;
1000 ri = gimple_build (&stmts, loc, code, inner_type, ai, bi);
1001 break;
1003 case PAIR (VARYING, VARYING):
1004 general:
1005 rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
1006 /* (a+ai) + (b+bi) -> (a+b)+(a+b)i
1007 small optimization to remove one new statement. */
1008 if (operand_equal_p (ar, ai) && operand_equal_p (br, bi))
1009 ri = rr;
1010 else
1011 ri = gimple_build (&stmts, loc, code, inner_type, ai, bi);
1012 break;
1014 default:
1015 gcc_unreachable ();
1018 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1019 update_complex_assignment (gsi, rr, ri);
1022 /* Expand a complex multiplication or division to a libcall to the c99
1023 compliant routines. TYPE is the complex type of the operation.
1024 If INPLACE_P replace the statement at GSI with
1025 the libcall and return NULL_TREE. Else insert the call, assign its
1026 result to an output variable and return that variable. If INPLACE_P
1027 is true then the statement being replaced should be an assignment
1028 statement. */
1030 static tree
1031 expand_complex_libcall (gimple_stmt_iterator *gsi, tree type, tree ar, tree ai,
1032 tree br, tree bi, enum tree_code code, bool inplace_p)
1034 machine_mode mode;
1035 enum built_in_function bcode;
1036 tree fn, lhs;
1037 gcall *stmt;
1039 mode = TYPE_MODE (type);
1040 gcc_assert (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT);
1042 if (code == MULT_EXPR)
1043 bcode = ((enum built_in_function)
1044 (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
1045 else if (code == RDIV_EXPR)
1046 bcode = ((enum built_in_function)
1047 (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
1048 else
1049 gcc_unreachable ();
1050 fn = builtin_decl_explicit (bcode);
1051 stmt = gimple_build_call (fn, 4, ar, ai, br, bi);
1053 if (inplace_p)
1055 gimple *old_stmt = gsi_stmt (*gsi);
1056 gimple_call_set_nothrow (stmt, !stmt_could_throw_p (cfun, old_stmt));
1057 lhs = gimple_assign_lhs (old_stmt);
1058 gimple_call_set_lhs (stmt, lhs);
1059 gsi_replace (gsi, stmt, true);
1061 type = TREE_TYPE (type);
1062 if (stmt_can_throw_internal (cfun, stmt))
1064 edge_iterator ei;
1065 edge e;
1066 FOR_EACH_EDGE (e, ei, gimple_bb (stmt)->succs)
1067 if (!(e->flags & EDGE_EH))
1068 break;
1069 basic_block bb = split_edge (e);
1070 gimple_stmt_iterator gsi2 = gsi_start_bb (bb);
1071 update_complex_components (&gsi2, stmt,
1072 build1 (REALPART_EXPR, type, lhs),
1073 build1 (IMAGPART_EXPR, type, lhs));
1074 return NULL_TREE;
1076 else
1077 update_complex_components (gsi, stmt,
1078 build1 (REALPART_EXPR, type, lhs),
1079 build1 (IMAGPART_EXPR, type, lhs));
1080 SSA_NAME_DEF_STMT (lhs) = stmt;
1081 return NULL_TREE;
1084 gimple_call_set_nothrow (stmt, true);
1085 lhs = make_ssa_name (type);
1086 gimple_call_set_lhs (stmt, lhs);
1087 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1089 return lhs;
1092 /* Perform a complex multiplication on two complex constants A, B represented
1093 by AR, AI, BR, BI of type TYPE.
1094 The operation we want is: a * b = (ar*br - ai*bi) + i(ar*bi + br*ai).
1095 Insert the GIMPLE statements into GSI. Store the real and imaginary
1096 components of the result into RR and RI. */
1098 static void
1099 expand_complex_multiplication_components (gimple_seq *stmts, location_t loc,
1100 tree type, tree ar, tree ai,
1101 tree br, tree bi,
1102 tree *rr, tree *ri)
1104 tree t1, t2, t3, t4;
1106 t1 = gimple_build (stmts, loc, MULT_EXPR, type, ar, br);
1107 t2 = gimple_build (stmts, loc, MULT_EXPR, type, ai, bi);
1108 t3 = gimple_build (stmts, loc, MULT_EXPR, type, ar, bi);
1110 /* Avoid expanding redundant multiplication for the common
1111 case of squaring a complex number. */
1112 if (ar == br && ai == bi)
1113 t4 = t3;
1114 else
1115 t4 = gimple_build (stmts, loc, MULT_EXPR, type, ai, br);
1117 *rr = gimple_build (stmts, loc, MINUS_EXPR, type, t1, t2);
1118 *ri = gimple_build (stmts, loc, PLUS_EXPR, type, t3, t4);
1121 /* Expand complex multiplication to scalars:
1122 a * b = (ar*br - ai*bi) + i(ar*bi + br*ai)
1125 static void
1126 expand_complex_multiplication (gimple_stmt_iterator *gsi, tree type,
1127 tree ar, tree ai, tree br, tree bi,
1128 complex_lattice_t al, complex_lattice_t bl)
1130 tree rr, ri;
1131 tree inner_type = TREE_TYPE (type);
1132 location_t loc = gimple_location (gsi_stmt (*gsi));
1133 gimple_seq stmts = NULL;
1135 if (al < bl)
1137 complex_lattice_t tl;
1138 rr = ar, ar = br, br = rr;
1139 ri = ai, ai = bi, bi = ri;
1140 tl = al, al = bl, bl = tl;
1143 switch (PAIR (al, bl))
1145 case PAIR (ONLY_REAL, ONLY_REAL):
1146 rr = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, br);
1147 ri = ai;
1148 break;
1150 case PAIR (ONLY_IMAG, ONLY_REAL):
1151 rr = ar;
1152 if (TREE_CODE (ai) == REAL_CST
1153 && real_identical (&TREE_REAL_CST (ai), &dconst1))
1154 ri = br;
1155 else
1156 ri = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, br);
1157 break;
1159 case PAIR (ONLY_IMAG, ONLY_IMAG):
1160 rr = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, bi);
1161 rr = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, rr);
1162 ri = ar;
1163 break;
1165 case PAIR (VARYING, ONLY_REAL):
1166 rr = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, br);
1167 ri = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, br);
1168 break;
1170 case PAIR (VARYING, ONLY_IMAG):
1171 rr = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, bi);
1172 rr = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, rr);
1173 ri = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, bi);
1174 break;
1176 case PAIR (VARYING, VARYING):
1177 if (flag_complex_method == 2 && SCALAR_FLOAT_TYPE_P (inner_type))
1179 /* If optimizing for size or not at all just do a libcall.
1180 Same if there are exception-handling edges or signaling NaNs. */
1181 if (optimize == 0 || optimize_bb_for_size_p (gsi_bb (*gsi))
1182 || stmt_can_throw_internal (cfun, gsi_stmt (*gsi))
1183 || flag_signaling_nans)
1185 expand_complex_libcall (gsi, type, ar, ai, br, bi,
1186 MULT_EXPR, true);
1187 return;
1190 if (!HONOR_NANS (inner_type))
1192 /* If we are not worrying about NaNs expand to
1193 (ar*br - ai*bi) + i(ar*bi + br*ai) directly. */
1194 expand_complex_multiplication_components (&stmts, loc, inner_type,
1195 ar, ai, br, bi,
1196 &rr, &ri);
1197 break;
1200 /* Else, expand x = a * b into
1201 x = (ar*br - ai*bi) + i(ar*bi + br*ai);
1202 if (isunordered (__real__ x, __imag__ x))
1203 x = __muldc3 (a, b); */
1205 tree tmpr, tmpi;
1206 expand_complex_multiplication_components (&stmts, loc,
1207 inner_type, ar, ai,
1208 br, bi, &tmpr, &tmpi);
1209 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1210 stmts = NULL;
1212 gimple *check
1213 = gimple_build_cond (UNORDERED_EXPR, tmpr, tmpi,
1214 NULL_TREE, NULL_TREE);
1216 basic_block orig_bb = gsi_bb (*gsi);
1217 /* We want to keep track of the original complex multiplication
1218 statement as we're going to modify it later in
1219 update_complex_assignment. Make sure that insert_cond_bb leaves
1220 that statement in the join block. */
1221 gsi_prev (gsi);
1222 basic_block cond_bb
1223 = insert_cond_bb (gsi_bb (*gsi), gsi_stmt (*gsi), check,
1224 profile_probability::very_unlikely ());
1226 gimple_stmt_iterator cond_bb_gsi = gsi_last_bb (cond_bb);
1227 gsi_insert_after (&cond_bb_gsi, gimple_build_nop (), GSI_NEW_STMT);
1229 tree libcall_res
1230 = expand_complex_libcall (&cond_bb_gsi, type, ar, ai, br,
1231 bi, MULT_EXPR, false);
1232 gimple_seq stmts2 = NULL;
1233 tree cond_real = gimple_build (&stmts2, loc, REALPART_EXPR,
1234 inner_type, libcall_res);
1235 tree cond_imag = gimple_build (&stmts2, loc, IMAGPART_EXPR,
1236 inner_type, libcall_res);
1237 gsi_insert_seq_before (&cond_bb_gsi, stmts2, GSI_SAME_STMT);
1239 basic_block join_bb = single_succ_edge (cond_bb)->dest;
1240 *gsi = gsi_start_nondebug_after_labels_bb (join_bb);
1242 /* We have a conditional block with some assignments in cond_bb.
1243 Wire up the PHIs to wrap up. */
1244 rr = make_ssa_name (inner_type);
1245 ri = make_ssa_name (inner_type);
1246 edge cond_to_join = single_succ_edge (cond_bb);
1247 edge orig_to_join = find_edge (orig_bb, join_bb);
1249 gphi *real_phi = create_phi_node (rr, gsi_bb (*gsi));
1250 add_phi_arg (real_phi, cond_real, cond_to_join, UNKNOWN_LOCATION);
1251 add_phi_arg (real_phi, tmpr, orig_to_join, UNKNOWN_LOCATION);
1253 gphi *imag_phi = create_phi_node (ri, gsi_bb (*gsi));
1254 add_phi_arg (imag_phi, cond_imag, cond_to_join, UNKNOWN_LOCATION);
1255 add_phi_arg (imag_phi, tmpi, orig_to_join, UNKNOWN_LOCATION);
1257 else
1258 /* If we are not worrying about NaNs expand to
1259 (ar*br - ai*bi) + i(ar*bi + br*ai) directly. */
1260 expand_complex_multiplication_components (&stmts, loc,
1261 inner_type, ar, ai,
1262 br, bi, &rr, &ri);
1263 break;
1265 default:
1266 gcc_unreachable ();
1269 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1270 update_complex_assignment (gsi, rr, ri);
1273 /* Keep this algorithm in sync with fold-const.cc:const_binop().
1275 Expand complex division to scalars, straightforward algorithm.
1276 a / b = ((ar*br + ai*bi)/t) + i((ai*br - ar*bi)/t)
1277 t = br*br + bi*bi
1280 static void
1281 expand_complex_div_straight (gimple_stmt_iterator *gsi, tree inner_type,
1282 tree ar, tree ai, tree br, tree bi,
1283 enum tree_code code)
1285 gimple_seq stmts = NULL;
1286 location_t loc = gimple_location (gsi_stmt (*gsi));
1287 tree rr, ri, div, t1, t2, t3;
1289 t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, br, br);
1290 t2 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, bi, bi);
1291 div = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, t2);
1293 t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, br);
1294 t2 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, bi);
1295 t3 = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, t2);
1296 rr = gimple_build (&stmts, loc, code, inner_type, t3, div);
1298 t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, br);
1299 t2 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, bi);
1300 t3 = gimple_build (&stmts, loc, MINUS_EXPR, inner_type, t1, t2);
1301 ri = gimple_build (&stmts, loc, code, inner_type, t3, div);
1303 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1304 update_complex_assignment (gsi, rr, ri);
1307 /* Keep this algorithm in sync with fold-const.cc:const_binop().
1309 Expand complex division to scalars, modified algorithm to minimize
1310 overflow with wide input ranges. */
1312 static void
1313 expand_complex_div_wide (gimple_stmt_iterator *gsi, tree inner_type,
1314 tree ar, tree ai, tree br, tree bi,
1315 enum tree_code code)
1317 tree rr, ri, ratio, div, t1, t2, tr, ti, compare;
1318 basic_block bb_cond, bb_true, bb_false, bb_join;
1319 gimple *stmt;
1320 gimple_seq stmts = NULL;
1321 location_t loc = gimple_location (gsi_stmt (*gsi));
1323 /* Examine |br| < |bi|, and branch. */
1324 t1 = gimple_build (&stmts, loc, ABS_EXPR, inner_type, br);
1325 t2 = gimple_build (&stmts, loc, ABS_EXPR, inner_type, bi);
1326 compare = gimple_build (&stmts, loc,
1327 LT_EXPR, boolean_type_node, t1, t2);
1329 bb_cond = bb_true = bb_false = bb_join = NULL;
1330 rr = ri = tr = ti = NULL;
1331 if (TREE_CODE (compare) != INTEGER_CST)
1333 edge e;
1334 gimple *stmt;
1336 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1337 stmts = NULL;
1338 stmt = gimple_build_cond (NE_EXPR, compare, boolean_false_node,
1339 NULL_TREE, NULL_TREE);
1340 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1342 /* Split the original block, and create the TRUE and FALSE blocks. */
1343 e = split_block (gsi_bb (*gsi), stmt);
1344 bb_cond = e->src;
1345 bb_join = e->dest;
1346 bb_true = create_empty_bb (bb_cond);
1347 bb_false = create_empty_bb (bb_true);
1348 bb_true->count = bb_false->count
1349 = bb_cond->count.apply_probability (profile_probability::even ());
1351 /* Wire the blocks together. */
1352 e->flags = EDGE_TRUE_VALUE;
1353 /* TODO: With value profile we could add an historgram to determine real
1354 branch outcome. */
1355 e->probability = profile_probability::even ();
1356 redirect_edge_succ (e, bb_true);
1357 edge e2 = make_edge (bb_cond, bb_false, EDGE_FALSE_VALUE);
1358 e2->probability = profile_probability::even ();
1359 make_single_succ_edge (bb_true, bb_join, EDGE_FALLTHRU);
1360 make_single_succ_edge (bb_false, bb_join, EDGE_FALLTHRU);
1361 add_bb_to_loop (bb_true, bb_cond->loop_father);
1362 add_bb_to_loop (bb_false, bb_cond->loop_father);
1364 /* Update dominance info. Note that bb_join's data was
1365 updated by split_block. */
1366 if (dom_info_available_p (CDI_DOMINATORS))
1368 set_immediate_dominator (CDI_DOMINATORS, bb_true, bb_cond);
1369 set_immediate_dominator (CDI_DOMINATORS, bb_false, bb_cond);
1372 rr = create_tmp_reg (inner_type);
1373 ri = create_tmp_reg (inner_type);
1375 else
1377 gimple_seq_discard (stmts);
1378 stmts = NULL;
1381 /* In the TRUE branch, we compute
1382 ratio = br/bi;
1383 div = (br * ratio) + bi;
1384 tr = (ar * ratio) + ai;
1385 ti = (ai * ratio) - ar;
1386 tr = tr / div;
1387 ti = ti / div; */
1388 if (bb_true || integer_nonzerop (compare))
1390 if (bb_true)
1392 *gsi = gsi_last_bb (bb_true);
1393 gsi_insert_after (gsi, gimple_build_nop (), GSI_NEW_STMT);
1396 ratio = gimple_build (&stmts, loc, code, inner_type, br, bi);
1398 t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, br, ratio);
1399 div = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, bi);
1401 t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, ratio);
1402 tr = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, ai);
1404 t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, ratio);
1405 ti = gimple_build (&stmts, loc, MINUS_EXPR, inner_type, t1, ar);
1407 tr = gimple_build (&stmts, loc, code, inner_type, tr, div);
1408 ti = gimple_build (&stmts, loc, code, inner_type, ti, div);
1409 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1410 stmts = NULL;
1412 if (bb_true)
1414 stmt = gimple_build_assign (rr, tr);
1415 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1416 stmt = gimple_build_assign (ri, ti);
1417 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1418 gsi_remove (gsi, true);
1422 /* In the FALSE branch, we compute
1423 ratio = d/c;
1424 divisor = (d * ratio) + c;
1425 tr = (b * ratio) + a;
1426 ti = b - (a * ratio);
1427 tr = tr / div;
1428 ti = ti / div; */
1429 if (bb_false || integer_zerop (compare))
1431 if (bb_false)
1433 *gsi = gsi_last_bb (bb_false);
1434 gsi_insert_after (gsi, gimple_build_nop (), GSI_NEW_STMT);
1437 ratio = gimple_build (&stmts, loc, code, inner_type, bi, br);
1439 t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, bi, ratio);
1440 div = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, br);
1442 t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, ratio);
1443 tr = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, ar);
1445 t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, ratio);
1446 ti = gimple_build (&stmts, loc, MINUS_EXPR, inner_type, ai, t1);
1448 tr = gimple_build (&stmts, loc, code, inner_type, tr, div);
1449 ti = gimple_build (&stmts, loc, code, inner_type, ti, div);
1450 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1451 stmts = NULL;
1453 if (bb_false)
1455 stmt = gimple_build_assign (rr, tr);
1456 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1457 stmt = gimple_build_assign (ri, ti);
1458 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1459 gsi_remove (gsi, true);
1463 if (bb_join)
1464 *gsi = gsi_start_bb (bb_join);
1465 else
1466 rr = tr, ri = ti;
1468 update_complex_assignment (gsi, rr, ri);
1471 /* Expand complex division to scalars. */
1473 static void
1474 expand_complex_division (gimple_stmt_iterator *gsi, tree type,
1475 tree ar, tree ai, tree br, tree bi,
1476 enum tree_code code,
1477 complex_lattice_t al, complex_lattice_t bl)
1479 tree rr, ri;
1480 gimple_seq stmts = NULL;
1481 location_t loc = gimple_location (gsi_stmt (*gsi));
1483 tree inner_type = TREE_TYPE (type);
1484 switch (PAIR (al, bl))
1486 case PAIR (ONLY_REAL, ONLY_REAL):
1487 rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
1488 ri = ai;
1489 break;
1491 case PAIR (ONLY_REAL, ONLY_IMAG):
1492 rr = ai;
1493 ri = gimple_build (&stmts, loc, code, inner_type, ar, bi);
1494 ri = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, ri);
1495 break;
1497 case PAIR (ONLY_IMAG, ONLY_REAL):
1498 rr = ar;
1499 ri = gimple_build (&stmts, loc, code, inner_type, ai, br);
1500 break;
1502 case PAIR (ONLY_IMAG, ONLY_IMAG):
1503 rr = gimple_build (&stmts, loc, code, inner_type, ai, bi);
1504 ri = ar;
1505 break;
1507 case PAIR (VARYING, ONLY_REAL):
1508 rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
1509 ri = gimple_build (&stmts, loc, code, inner_type, ai, br);
1510 break;
1512 case PAIR (VARYING, ONLY_IMAG):
1513 rr = gimple_build (&stmts, loc, code, inner_type, ai, bi);
1514 ri = gimple_build (&stmts, loc, code, inner_type, ar, bi);
1515 ri = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, ri);
1516 break;
1518 case PAIR (ONLY_REAL, VARYING):
1519 case PAIR (ONLY_IMAG, VARYING):
1520 case PAIR (VARYING, VARYING):
1521 switch (flag_complex_method)
1523 case 0:
1524 /* straightforward implementation of complex divide acceptable. */
1525 expand_complex_div_straight (gsi, inner_type, ar, ai, br, bi, code);
1526 break;
1528 case 2:
1529 if (SCALAR_FLOAT_TYPE_P (inner_type))
1531 expand_complex_libcall (gsi, type, ar, ai, br, bi, code, true);
1532 break;
1534 /* FALLTHRU */
1536 case 1:
1537 /* wide ranges of inputs must work for complex divide. */
1538 expand_complex_div_wide (gsi, inner_type, ar, ai, br, bi, code);
1539 break;
1541 default:
1542 gcc_unreachable ();
1544 return;
1546 default:
1547 gcc_unreachable ();
1550 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1551 update_complex_assignment (gsi, rr, ri);
1554 /* Expand complex negation to scalars:
1555 -a = (-ar) + i(-ai)
1558 static void
1559 expand_complex_negation (gimple_stmt_iterator *gsi, tree inner_type,
1560 tree ar, tree ai)
1562 tree rr, ri;
1563 gimple_seq stmts = NULL;
1564 location_t loc = gimple_location (gsi_stmt (*gsi));
1566 rr = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, ar);
1567 ri = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, ai);
1569 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1570 update_complex_assignment (gsi, rr, ri);
1573 /* Expand complex paren to scalars:
1574 ((a)) = ((ar)) + i((ai))
1577 static void
1578 expand_complex_paren (gimple_stmt_iterator *gsi, tree inner_type,
1579 tree ar, tree ai)
1581 tree rr, ri;
1582 gimple_seq stmts = NULL;
1583 location_t loc = gimple_location (gsi_stmt (*gsi));
1585 rr = gimple_build (&stmts, loc, PAREN_EXPR, inner_type, ar);
1586 ri = gimple_build (&stmts, loc, PAREN_EXPR, inner_type, ai);
1588 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1589 update_complex_assignment (gsi, rr, ri);
1592 /* Expand complex conjugate to scalars:
1593 ~a = (ar) + i(-ai)
1596 static void
1597 expand_complex_conjugate (gimple_stmt_iterator *gsi, tree inner_type,
1598 tree ar, tree ai)
1600 tree ri;
1601 gimple_seq stmts = NULL;
1602 location_t loc = gimple_location (gsi_stmt (*gsi));
1604 ri = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, ai);
1606 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1607 update_complex_assignment (gsi, ar, ri);
1610 /* Expand complex comparison (EQ or NE only). */
1612 static void
1613 expand_complex_comparison (gimple_stmt_iterator *gsi, tree ar, tree ai,
1614 tree br, tree bi, enum tree_code code)
1616 tree cr, ci, cc, type;
1617 gimple *stmt = gsi_stmt (*gsi);
1618 gimple_seq stmts = NULL;
1619 location_t loc = gimple_location (stmt);
1621 cr = gimple_build (&stmts, loc, code, boolean_type_node, ar, br);
1622 ci = gimple_build (&stmts, loc, code, boolean_type_node, ai, bi);
1623 cc = gimple_build (&stmts, loc,
1624 (code == EQ_EXPR ? BIT_AND_EXPR : BIT_IOR_EXPR),
1625 boolean_type_node, cr, ci);
1626 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1628 switch (gimple_code (stmt))
1630 case GIMPLE_ASSIGN:
1631 type = TREE_TYPE (gimple_assign_lhs (stmt));
1632 gimple_assign_set_rhs_from_tree (gsi, fold_convert (type, cc));
1633 stmt = gsi_stmt (*gsi);
1634 break;
1636 case GIMPLE_COND:
1638 gcond *cond_stmt = as_a <gcond *> (stmt);
1639 gimple_cond_set_code (cond_stmt, EQ_EXPR);
1640 gimple_cond_set_lhs (cond_stmt, cc);
1641 gimple_cond_set_rhs (cond_stmt, boolean_true_node);
1643 break;
1645 default:
1646 gcc_unreachable ();
1649 update_stmt (stmt);
1650 if (maybe_clean_eh_stmt (stmt))
1651 bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index);
1654 /* Expand inline asm that sets some complex SSA_NAMEs. */
1656 static void
1657 expand_complex_asm (gimple_stmt_iterator *gsi)
1659 gasm *stmt = as_a <gasm *> (gsi_stmt (*gsi));
1660 unsigned int i;
1661 bool diagnosed_p = false;
1663 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
1665 tree link = gimple_asm_output_op (stmt, i);
1666 tree op = TREE_VALUE (link);
1667 if (TREE_CODE (op) == SSA_NAME
1668 && TREE_CODE (TREE_TYPE (op)) == COMPLEX_TYPE)
1670 if (gimple_asm_nlabels (stmt) > 0)
1672 if (!diagnosed_p)
1674 sorry_at (gimple_location (stmt),
1675 "%<asm goto%> with complex typed outputs");
1676 diagnosed_p = true;
1678 /* Make sure to not ICE later, see PR105165. */
1679 tree zero = build_zero_cst (TREE_TYPE (TREE_TYPE (op)));
1680 set_component_ssa_name (op, false, zero);
1681 set_component_ssa_name (op, true, zero);
1682 continue;
1684 tree type = TREE_TYPE (op);
1685 tree inner_type = TREE_TYPE (type);
1686 tree r = build1 (REALPART_EXPR, inner_type, op);
1687 tree i = build1 (IMAGPART_EXPR, inner_type, op);
1688 gimple_seq list = set_component_ssa_name (op, false, r);
1690 if (list)
1691 gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
1693 list = set_component_ssa_name (op, true, i);
1694 if (list)
1695 gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
1701 /* ARG is the argument to a cabs builtin call in GSI from the
1702 original OLD_STMT. Create a sequence of statements prior
1703 to GSI that calculates sqrt(R*R + I*I), where R and
1704 I are the real and imaginary components of ARG, respectively. */
1706 static void
1707 gimple_expand_builtin_cabs (gimple_stmt_iterator *gsi, gimple *old_stmt)
1709 tree real_part, imag_part, addend1, addend2, sum;
1710 tree arg = gimple_call_arg (old_stmt, 0);
1711 tree type = TREE_TYPE (TREE_TYPE (arg));
1712 machine_mode mode = TYPE_MODE (type);
1713 gimple *new_stmt;
1715 tree lhs = gimple_call_lhs (old_stmt);
1717 real_part = extract_component (gsi, arg, false, true);
1718 imag_part = extract_component (gsi, arg, true, true);
1719 location_t loc = gimple_location (old_stmt);
1721 gimple_seq stmts = NULL;
1723 /* cabs(x+0i) -> abs(x).
1724 cabs(0+xi) -> abs(x).
1725 These 2 can be done even without unsafe math optimizations. */
1726 if (real_zerop (imag_part)
1727 || real_zerop (real_part))
1729 tree other = real_zerop (imag_part) ? real_part : imag_part;
1730 sum = gimple_build (&stmts, loc, ABS_EXPR, type, other);
1731 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1732 new_stmt = gimple_build_assign (lhs, sum);
1733 gimple_set_location (new_stmt, loc);
1734 gsi_replace (gsi, new_stmt, true);
1735 return;
1738 if (!flag_unsafe_math_optimizations)
1739 return;
1741 /* cabs(x+xi) -> fabs(x)*sqrt(2). */
1742 if (operand_equal_p (real_part, imag_part))
1744 tree sqrt2 = build_real_truncate (type, dconst_sqrt2 ());
1745 sum = gimple_build (&stmts, loc, ABS_EXPR, type, real_part);
1746 sum = gimple_build (&stmts, loc, MULT_EXPR, type, sum, sqrt2);
1747 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1748 new_stmt = gimple_build_assign (lhs, sum);
1749 gimple_set_location (new_stmt, loc);
1750 gsi_replace (gsi, new_stmt, true);
1751 return;
1754 /* cabs(a+bi) -> sqrt(a*a+b*b) if sqrt exists on the target
1755 and optimizing for speed. */
1756 tree sqrtfn = mathfn_built_in (type, BUILT_IN_SQRT);
1757 if (!optimize_bb_for_speed_p (gimple_bb (old_stmt))
1758 || !sqrtfn
1759 || optab_handler (sqrt_optab, mode) == CODE_FOR_nothing)
1760 return;
1762 addend1 = gimple_build (&stmts, loc, MULT_EXPR, type, real_part, real_part);
1763 addend2 = gimple_build (&stmts, loc, MULT_EXPR, type, imag_part, imag_part);
1764 sum = gimple_build (&stmts, loc, PLUS_EXPR, type, addend1, addend2);
1765 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
1767 /* Build the sqrt call. */
1768 new_stmt = gimple_build_call (sqrtfn, 1, sum);
1769 gimple_set_location (new_stmt, loc);
1770 gimple_call_set_lhs (new_stmt, lhs);
1771 gsi_replace (gsi, new_stmt, true);
1774 /* Process one statement. If we identify a complex operation, expand it. */
1776 static void
1777 expand_complex_operations_1 (gimple_stmt_iterator *gsi)
1779 gimple *stmt = gsi_stmt (*gsi);
1780 tree type, inner_type, lhs;
1781 tree ac, ar, ai, bc, br, bi;
1782 complex_lattice_t al, bl;
1783 enum tree_code code;
1784 if (gimple_code (stmt) == GIMPLE_CALL)
1786 switch (gimple_call_combined_fn (stmt))
1788 CASE_CFN_CABS:
1789 gimple_expand_builtin_cabs (gsi, stmt);
1790 return;
1791 default:;
1795 if (gimple_code (stmt) == GIMPLE_ASM)
1797 expand_complex_asm (gsi);
1798 return;
1801 lhs = gimple_get_lhs (stmt);
1802 if (!lhs && gimple_code (stmt) != GIMPLE_COND)
1803 return;
1805 type = TREE_TYPE (gimple_op (stmt, 0));
1806 code = gimple_expr_code (stmt);
1808 /* Initial filter for operations we handle. */
1809 switch (code)
1811 case PLUS_EXPR:
1812 case MINUS_EXPR:
1813 case MULT_EXPR:
1814 case TRUNC_DIV_EXPR:
1815 case CEIL_DIV_EXPR:
1816 case FLOOR_DIV_EXPR:
1817 case ROUND_DIV_EXPR:
1818 case RDIV_EXPR:
1819 case NEGATE_EXPR:
1820 case PAREN_EXPR:
1821 case CONJ_EXPR:
1822 if (TREE_CODE (type) != COMPLEX_TYPE)
1823 return;
1824 inner_type = TREE_TYPE (type);
1825 break;
1827 case EQ_EXPR:
1828 case NE_EXPR:
1829 /* Note, both GIMPLE_ASSIGN and GIMPLE_COND may have an EQ_EXPR
1830 subcode, so we need to access the operands using gimple_op. */
1831 inner_type = TREE_TYPE (gimple_op (stmt, 1));
1832 if (TREE_CODE (inner_type) != COMPLEX_TYPE)
1833 return;
1834 break;
1836 default:
1838 tree rhs;
1840 /* GIMPLE_COND may also fallthru here, but we do not need to
1841 do anything with it. */
1842 if (gimple_code (stmt) == GIMPLE_COND)
1843 return;
1845 if (TREE_CODE (type) == COMPLEX_TYPE)
1846 expand_complex_move (gsi, type);
1847 else if (is_gimple_assign (stmt)
1848 && (gimple_assign_rhs_code (stmt) == REALPART_EXPR
1849 || gimple_assign_rhs_code (stmt) == IMAGPART_EXPR)
1850 && TREE_CODE (lhs) == SSA_NAME)
1852 rhs = gimple_assign_rhs1 (stmt);
1853 rhs = extract_component (gsi, TREE_OPERAND (rhs, 0),
1854 gimple_assign_rhs_code (stmt)
1855 == IMAGPART_EXPR,
1856 false);
1857 gimple_assign_set_rhs_from_tree (gsi, rhs);
1858 stmt = gsi_stmt (*gsi);
1859 update_stmt (stmt);
1862 return;
1865 /* Extract the components of the two complex values. Make sure and
1866 handle the common case of the same value used twice specially. */
1867 if (is_gimple_assign (stmt))
1869 ac = gimple_assign_rhs1 (stmt);
1870 bc = (gimple_num_ops (stmt) > 2) ? gimple_assign_rhs2 (stmt) : NULL;
1872 /* GIMPLE_CALL cannot get here. */
1873 else
1875 ac = gimple_cond_lhs (stmt);
1876 bc = gimple_cond_rhs (stmt);
1879 ar = extract_component (gsi, ac, false, true);
1880 ai = extract_component (gsi, ac, true, true);
1882 if (ac == bc)
1883 br = ar, bi = ai;
1884 else if (bc)
1886 br = extract_component (gsi, bc, 0, true);
1887 bi = extract_component (gsi, bc, 1, true);
1889 else
1890 br = bi = NULL_TREE;
1892 al = find_lattice_value (ac);
1893 if (al == UNINITIALIZED)
1894 al = VARYING;
1896 if (TREE_CODE_CLASS (code) == tcc_unary)
1897 bl = UNINITIALIZED;
1898 else if (ac == bc)
1899 bl = al;
1900 else
1902 bl = find_lattice_value (bc);
1903 if (bl == UNINITIALIZED)
1904 bl = VARYING;
1907 switch (code)
1909 case PLUS_EXPR:
1910 case MINUS_EXPR:
1911 expand_complex_addition (gsi, inner_type, ar, ai, br, bi, code, al, bl);
1912 break;
1914 case MULT_EXPR:
1915 expand_complex_multiplication (gsi, type, ar, ai, br, bi, al, bl);
1916 break;
1918 case TRUNC_DIV_EXPR:
1919 case CEIL_DIV_EXPR:
1920 case FLOOR_DIV_EXPR:
1921 case ROUND_DIV_EXPR:
1922 case RDIV_EXPR:
1923 expand_complex_division (gsi, type, ar, ai, br, bi, code, al, bl);
1924 break;
1926 case NEGATE_EXPR:
1927 expand_complex_negation (gsi, inner_type, ar, ai);
1928 break;
1930 case CONJ_EXPR:
1931 expand_complex_conjugate (gsi, inner_type, ar, ai);
1932 break;
1934 case EQ_EXPR:
1935 case NE_EXPR:
1936 expand_complex_comparison (gsi, ar, ai, br, bi, code);
1937 break;
1939 case PAREN_EXPR:
1940 expand_complex_paren (gsi, inner_type, ar, ai);
1941 break;
1943 default:
1944 gcc_unreachable ();
1949 /* Entry point for complex operation lowering during optimization. */
1951 static unsigned int
1952 tree_lower_complex (void)
1954 gimple_stmt_iterator gsi;
1955 basic_block bb;
1956 int n_bbs, i;
1957 int *rpo;
1959 if (!init_dont_simulate_again ())
1960 return 0;
1962 complex_lattice_values.create (num_ssa_names);
1963 complex_lattice_values.safe_grow_cleared (num_ssa_names, true);
1965 init_parameter_lattice_values ();
1966 class complex_propagate complex_propagate;
1967 complex_propagate.ssa_propagate ();
1969 need_eh_cleanup = BITMAP_ALLOC (NULL);
1970 dce_worklist = BITMAP_ALLOC (NULL);
1972 complex_variable_components = new int_tree_htab_type (10);
1974 complex_ssa_name_components.create (2 * num_ssa_names);
1975 complex_ssa_name_components.safe_grow_cleared (2 * num_ssa_names, true);
1977 update_parameter_components ();
1979 rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
1980 n_bbs = pre_and_rev_post_order_compute (NULL, rpo, false);
1981 for (i = 0; i < n_bbs; i++)
1983 bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
1984 if (!bb)
1985 continue;
1986 update_phi_components (bb);
1987 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1988 expand_complex_operations_1 (&gsi);
1991 free (rpo);
1993 if (!phis_to_revisit.is_empty ())
1995 unsigned int n = phis_to_revisit.length ();
1996 for (unsigned int j = 0; j < n; j += 3)
1997 for (unsigned int k = 0; k < 2; k++)
1998 if (gphi *phi = phis_to_revisit[j + k + 1])
2000 unsigned int m = gimple_phi_num_args (phi);
2001 for (unsigned int l = 0; l < m; ++l)
2003 tree op = gimple_phi_arg_def (phi, l);
2004 if (TREE_CODE (op) == SSA_NAME
2005 || is_gimple_min_invariant (op))
2006 continue;
2007 tree arg = gimple_phi_arg_def (phis_to_revisit[j], l);
2008 op = extract_component (NULL, arg, k > 0, false, false);
2009 SET_PHI_ARG_DEF (phi, l, op);
2012 phis_to_revisit.release ();
2015 gsi_commit_edge_inserts ();
2017 simple_dce_from_worklist (dce_worklist, need_eh_cleanup);
2018 BITMAP_FREE (dce_worklist);
2020 unsigned todo
2021 = gimple_purge_all_dead_eh_edges (need_eh_cleanup) ? TODO_cleanup_cfg : 0;
2022 BITMAP_FREE (need_eh_cleanup);
2024 delete complex_variable_components;
2025 complex_variable_components = NULL;
2026 complex_ssa_name_components.release ();
2027 complex_lattice_values.release ();
2028 return todo;
2031 namespace {
2033 const pass_data pass_data_lower_complex =
2035 GIMPLE_PASS, /* type */
2036 "cplxlower", /* name */
2037 OPTGROUP_NONE, /* optinfo_flags */
2038 TV_NONE, /* tv_id */
2039 PROP_ssa, /* properties_required */
2040 PROP_gimple_lcx, /* properties_provided */
2041 0, /* properties_destroyed */
2042 0, /* todo_flags_start */
2043 TODO_update_ssa, /* todo_flags_finish */
2046 class pass_lower_complex : public gimple_opt_pass
2048 public:
2049 pass_lower_complex (gcc::context *ctxt)
2050 : gimple_opt_pass (pass_data_lower_complex, ctxt)
2053 /* opt_pass methods: */
2054 opt_pass * clone () final override { return new pass_lower_complex (m_ctxt); }
2055 unsigned int execute (function *) final override
2057 return tree_lower_complex ();
2060 }; // class pass_lower_complex
2062 } // anon namespace
2064 gimple_opt_pass *
2065 make_pass_lower_complex (gcc::context *ctxt)
2067 return new pass_lower_complex (ctxt);
2071 namespace {
2073 const pass_data pass_data_lower_complex_O0 =
2075 GIMPLE_PASS, /* type */
2076 "cplxlower0", /* name */
2077 OPTGROUP_NONE, /* optinfo_flags */
2078 TV_NONE, /* tv_id */
2079 PROP_cfg, /* properties_required */
2080 PROP_gimple_lcx, /* properties_provided */
2081 0, /* properties_destroyed */
2082 0, /* todo_flags_start */
2083 TODO_update_ssa, /* todo_flags_finish */
2086 class pass_lower_complex_O0 : public gimple_opt_pass
2088 public:
2089 pass_lower_complex_O0 (gcc::context *ctxt)
2090 : gimple_opt_pass (pass_data_lower_complex_O0, ctxt)
2093 /* opt_pass methods: */
2094 bool gate (function *fun) final override
2096 /* With errors, normal optimization passes are not run. If we don't
2097 lower complex operations at all, rtl expansion will abort. */
2098 return !(fun->curr_properties & PROP_gimple_lcx);
2101 unsigned int execute (function *) final override
2103 return tree_lower_complex ();
2106 }; // class pass_lower_complex_O0
2108 } // anon namespace
2110 gimple_opt_pass *
2111 make_pass_lower_complex_O0 (gcc::context *ctxt)
2113 return new pass_lower_complex_O0 (ctxt);