]> gcc.gnu.org Git - gcc.git/blame - gcc/tree-complex.c
Remove a layer of indirection from hash_table
[gcc.git] / gcc / tree-complex.c
CommitLineData
2b725155 1/* Lower complex number operations to scalar operations.
23a5b65a 2 Copyright (C) 2004-2014 Free Software Foundation, Inc.
6de9cd9a
DN
3
4This file is part of GCC.
b8698a0f 5
6de9cd9a
DN
6GCC is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
9dcd6f09 8Free Software Foundation; either version 3, or (at your option) any
6de9cd9a 9later version.
b8698a0f 10
6de9cd9a
DN
11GCC is distributed in the hope that it will be useful, but WITHOUT
12ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
b8698a0f 15
6de9cd9a 16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
6de9cd9a
DN
19
20#include "config.h"
21#include "system.h"
22#include "coretypes.h"
6de9cd9a 23#include "tm.h"
e41d82f5 24#include "tree.h"
d8a2d370 25#include "stor-layout.h"
e41d82f5 26#include "flags.h"
2fb9a547
AM
27#include "basic-block.h"
28#include "tree-ssa-alias.h"
29#include "internal-fn.h"
30#include "tree-eh.h"
31#include "gimple-expr.h"
32#include "is-a.h"
18f429e2 33#include "gimple.h"
45b0be94 34#include "gimplify.h"
5be5c238 35#include "gimple-iterator.h"
18f429e2 36#include "gimplify-me.h"
442b4905
AM
37#include "gimple-ssa.h"
38#include "tree-cfg.h"
39#include "tree-phinodes.h"
40#include "ssa-iterators.h"
d8a2d370 41#include "stringpool.h"
442b4905 42#include "tree-ssanames.h"
d8a2d370 43#include "expr.h"
442b4905
AM
44#include "tree-dfa.h"
45#include "tree-ssa.h"
6de9cd9a
DN
46#include "tree-iterator.h"
47#include "tree-pass.h"
e41d82f5 48#include "tree-ssa-propagate.h"
4a8fb1a1 49#include "tree-hasher.h"
a9e0d843 50#include "cfgloop.h"
e41d82f5
RH
51
52
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. */
56
32e8bb8e 57enum
e41d82f5
RH
58{
59 UNINITIALIZED = 0,
60 ONLY_REAL = 1,
61 ONLY_IMAG = 2,
62 VARYING = 3
32e8bb8e
ILT
63};
64
65/* The type complex_lattice_t holds combinations of the above
66 constants. */
67typedef int complex_lattice_t;
e41d82f5
RH
68
69#define PAIR(a, b) ((a) << 2 | (b))
70
e41d82f5 71
9771b263 72static vec<complex_lattice_t> complex_lattice_values;
e41d82f5 73
a3648cfc
DB
74/* For each complex variable, a pair of variables for the components exists in
75 the hashtable. */
c203e8a7 76static int_tree_htab_type *complex_variable_components;
a3648cfc 77
95a8c155 78/* For each complex SSA_NAME, a pair of ssa names for the components. */
9771b263 79static vec<tree> complex_ssa_name_components;
95a8c155 80
a3648cfc
DB
81/* Lookup UID in the complex_variable_components hashtable and return the
82 associated tree. */
b8698a0f 83static tree
a3648cfc
DB
84cvc_lookup (unsigned int uid)
85{
86 struct int_tree_map *h, in;
87 in.uid = uid;
c203e8a7 88 h = complex_variable_components->find_with_hash (&in, uid);
95a8c155 89 return h ? h->to : NULL;
a3648cfc 90}
b8698a0f 91
a3648cfc
DB
92/* Insert the pair UID, TO into the complex_variable_components hashtable. */
93
b8698a0f 94static void
a3648cfc 95cvc_insert (unsigned int uid, tree to)
b8698a0f 96{
a3648cfc 97 struct int_tree_map *h;
4a8fb1a1 98 int_tree_map **loc;
a3648cfc 99
5ed6ace5 100 h = XNEW (struct int_tree_map);
a3648cfc
DB
101 h->uid = uid;
102 h->to = to;
c203e8a7 103 loc = complex_variable_components->find_slot_with_hash (h, uid, INSERT);
4a8fb1a1 104 *loc = h;
a3648cfc 105}
e41d82f5 106
e41d82f5
RH
107/* Return true if T is not a zero constant. In the case of real values,
108 we're only interested in +0.0. */
109
110static int
111some_nonzerop (tree t)
112{
113 int zerop = false;
114
2ca862e9
JM
115 /* Operations with real or imaginary part of a complex number zero
116 cannot be treated the same as operations with a real or imaginary
117 operand if we care about the signs of zeros in the result. */
118 if (TREE_CODE (t) == REAL_CST && !flag_signed_zeros)
e41d82f5 119 zerop = REAL_VALUES_IDENTICAL (TREE_REAL_CST (t), dconst0);
325217ed
CF
120 else if (TREE_CODE (t) == FIXED_CST)
121 zerop = fixed_zerop (t);
e41d82f5
RH
122 else if (TREE_CODE (t) == INTEGER_CST)
123 zerop = integer_zerop (t);
124
125 return !zerop;
126}
127
726a989a
RB
128
129/* Compute a lattice value from the components of a complex type REAL
130 and IMAG. */
6de9cd9a 131
e41d82f5 132static complex_lattice_t
726a989a 133find_lattice_value_parts (tree real, tree imag)
e41d82f5 134{
e41d82f5
RH
135 int r, i;
136 complex_lattice_t ret;
137
726a989a
RB
138 r = some_nonzerop (real);
139 i = some_nonzerop (imag);
140 ret = r * ONLY_REAL + i * ONLY_IMAG;
141
142 /* ??? On occasion we could do better than mapping 0+0i to real, but we
143 certainly don't want to leave it UNINITIALIZED, which eventually gets
144 mapped to VARYING. */
145 if (ret == UNINITIALIZED)
146 ret = ONLY_REAL;
147
148 return ret;
149}
150
151
152/* Compute a lattice value from gimple_val T. */
153
154static complex_lattice_t
155find_lattice_value (tree t)
156{
157 tree real, imag;
158
e41d82f5
RH
159 switch (TREE_CODE (t))
160 {
161 case SSA_NAME:
9771b263 162 return complex_lattice_values[SSA_NAME_VERSION (t)];
e41d82f5
RH
163
164 case COMPLEX_CST:
165 real = TREE_REALPART (t);
166 imag = TREE_IMAGPART (t);
167 break;
168
e41d82f5
RH
169 default:
170 gcc_unreachable ();
171 }
172
726a989a 173 return find_lattice_value_parts (real, imag);
e41d82f5
RH
174}
175
176/* Determine if LHS is something for which we're interested in seeing
177 simulation results. */
178
179static bool
180is_complex_reg (tree lhs)
181{
182 return TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE && is_gimple_reg (lhs);
183}
184
185/* Mark the incoming parameters to the function as VARYING. */
186
187static void
188init_parameter_lattice_values (void)
189{
f0a77246 190 tree parm, ssa_name;
e41d82f5 191
910ad8de 192 for (parm = DECL_ARGUMENTS (cfun->decl); parm ; parm = DECL_CHAIN (parm))
f0a77246 193 if (is_complex_reg (parm)
32244553 194 && (ssa_name = ssa_default_def (cfun, parm)) != NULL_TREE)
9771b263 195 complex_lattice_values[SSA_NAME_VERSION (ssa_name)] = VARYING;
e41d82f5
RH
196}
197
726a989a
RB
198/* Initialize simulation state for each statement. Return false if we
199 found no statements we want to simulate, and thus there's nothing
200 for the entire pass to do. */
e41d82f5
RH
201
202static bool
203init_dont_simulate_again (void)
204{
205 basic_block bb;
726a989a
RB
206 gimple_stmt_iterator gsi;
207 gimple phi;
8f8abce4 208 bool saw_a_complex_op = false;
e41d82f5 209
11cd3bed 210 FOR_EACH_BB_FN (bb, cfun)
e41d82f5 211 {
726a989a
RB
212 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
213 {
214 phi = gsi_stmt (gsi);
215 prop_set_simulate_again (phi,
216 is_complex_reg (gimple_phi_result (phi)));
217 }
e41d82f5 218
726a989a 219 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
e41d82f5 220 {
726a989a
RB
221 gimple stmt;
222 tree op0, op1;
223 bool sim_again_p;
e41d82f5 224
726a989a
RB
225 stmt = gsi_stmt (gsi);
226 op0 = op1 = NULL_TREE;
99e6bdda 227
b8698a0f 228 /* Most control-altering statements must be initially
99e6bdda 229 simulated, else we won't cover the entire cfg. */
726a989a 230 sim_again_p = stmt_ends_bb_p (stmt);
99e6bdda 231
726a989a 232 switch (gimple_code (stmt))
e41d82f5 233 {
726a989a
RB
234 case GIMPLE_CALL:
235 if (gimple_call_lhs (stmt))
236 sim_again_p = is_complex_reg (gimple_call_lhs (stmt));
237 break;
8f8abce4 238
726a989a
RB
239 case GIMPLE_ASSIGN:
240 sim_again_p = is_complex_reg (gimple_assign_lhs (stmt));
241 if (gimple_assign_rhs_code (stmt) == REALPART_EXPR
242 || gimple_assign_rhs_code (stmt) == IMAGPART_EXPR)
243 op0 = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
244 else
245 op0 = gimple_assign_rhs1 (stmt);
246 if (gimple_num_ops (stmt) > 2)
247 op1 = gimple_assign_rhs2 (stmt);
8f8abce4
RH
248 break;
249
726a989a
RB
250 case GIMPLE_COND:
251 op0 = gimple_cond_lhs (stmt);
252 op1 = gimple_cond_rhs (stmt);
8f8abce4
RH
253 break;
254
255 default:
256 break;
e41d82f5
RH
257 }
258
726a989a
RB
259 if (op0 || op1)
260 switch (gimple_expr_code (stmt))
8f8abce4
RH
261 {
262 case EQ_EXPR:
263 case NE_EXPR:
8f8abce4
RH
264 case PLUS_EXPR:
265 case MINUS_EXPR:
266 case MULT_EXPR:
267 case TRUNC_DIV_EXPR:
268 case CEIL_DIV_EXPR:
269 case FLOOR_DIV_EXPR:
270 case ROUND_DIV_EXPR:
271 case RDIV_EXPR:
726a989a
RB
272 if (TREE_CODE (TREE_TYPE (op0)) == COMPLEX_TYPE
273 || TREE_CODE (TREE_TYPE (op1)) == COMPLEX_TYPE)
274 saw_a_complex_op = true;
275 break;
276
8f8abce4
RH
277 case NEGATE_EXPR:
278 case CONJ_EXPR:
726a989a 279 if (TREE_CODE (TREE_TYPE (op0)) == COMPLEX_TYPE)
8f8abce4
RH
280 saw_a_complex_op = true;
281 break;
282
7b7e6ecd
EB
283 case REALPART_EXPR:
284 case IMAGPART_EXPR:
285 /* The total store transformation performed during
726a989a
RB
286 gimplification creates such uninitialized loads
287 and we need to lower the statement to be able
288 to fix things up. */
289 if (TREE_CODE (op0) == SSA_NAME
290 && ssa_undefined_value_p (op0))
7b7e6ecd
EB
291 saw_a_complex_op = true;
292 break;
293
8f8abce4
RH
294 default:
295 break;
296 }
297
726a989a 298 prop_set_simulate_again (stmt, sim_again_p);
e41d82f5
RH
299 }
300 }
301
8f8abce4 302 return saw_a_complex_op;
e41d82f5
RH
303}
304
305
306/* Evaluate statement STMT against the complex lattice defined above. */
307
308static enum ssa_prop_result
726a989a 309complex_visit_stmt (gimple stmt, edge *taken_edge_p ATTRIBUTE_UNUSED,
e41d82f5
RH
310 tree *result_p)
311{
312 complex_lattice_t new_l, old_l, op1_l, op2_l;
313 unsigned int ver;
726a989a 314 tree lhs;
e41d82f5 315
726a989a
RB
316 lhs = gimple_get_lhs (stmt);
317 /* Skip anything but GIMPLE_ASSIGN and GIMPLE_CALL with a lhs. */
318 if (!lhs)
99e6bdda 319 return SSA_PROP_VARYING;
e41d82f5 320
99e6bdda
RH
321 /* These conditions should be satisfied due to the initial filter
322 set up in init_dont_simulate_again. */
e41d82f5
RH
323 gcc_assert (TREE_CODE (lhs) == SSA_NAME);
324 gcc_assert (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE);
325
326 *result_p = lhs;
327 ver = SSA_NAME_VERSION (lhs);
9771b263 328 old_l = complex_lattice_values[ver];
e41d82f5 329
726a989a 330 switch (gimple_expr_code (stmt))
e41d82f5
RH
331 {
332 case SSA_NAME:
e41d82f5 333 case COMPLEX_CST:
726a989a
RB
334 new_l = find_lattice_value (gimple_assign_rhs1 (stmt));
335 break;
336
337 case COMPLEX_EXPR:
338 new_l = find_lattice_value_parts (gimple_assign_rhs1 (stmt),
339 gimple_assign_rhs2 (stmt));
e41d82f5
RH
340 break;
341
342 case PLUS_EXPR:
343 case MINUS_EXPR:
726a989a
RB
344 op1_l = find_lattice_value (gimple_assign_rhs1 (stmt));
345 op2_l = find_lattice_value (gimple_assign_rhs2 (stmt));
e41d82f5
RH
346
347 /* We've set up the lattice values such that IOR neatly
348 models addition. */
349 new_l = op1_l | op2_l;
350 break;
351
352 case MULT_EXPR:
353 case RDIV_EXPR:
354 case TRUNC_DIV_EXPR:
355 case CEIL_DIV_EXPR:
356 case FLOOR_DIV_EXPR:
357 case ROUND_DIV_EXPR:
726a989a
RB
358 op1_l = find_lattice_value (gimple_assign_rhs1 (stmt));
359 op2_l = find_lattice_value (gimple_assign_rhs2 (stmt));
e41d82f5
RH
360
361 /* Obviously, if either varies, so does the result. */
362 if (op1_l == VARYING || op2_l == VARYING)
363 new_l = VARYING;
364 /* Don't prematurely promote variables if we've not yet seen
365 their inputs. */
366 else if (op1_l == UNINITIALIZED)
367 new_l = op2_l;
368 else if (op2_l == UNINITIALIZED)
369 new_l = op1_l;
370 else
371 {
372 /* At this point both numbers have only one component. If the
373 numbers are of opposite kind, the result is imaginary,
374 otherwise the result is real. The add/subtract translates
375 the real/imag from/to 0/1; the ^ performs the comparison. */
376 new_l = ((op1_l - ONLY_REAL) ^ (op2_l - ONLY_REAL)) + ONLY_REAL;
377
378 /* Don't allow the lattice value to flip-flop indefinitely. */
379 new_l |= old_l;
380 }
381 break;
382
383 case NEGATE_EXPR:
384 case CONJ_EXPR:
726a989a 385 new_l = find_lattice_value (gimple_assign_rhs1 (stmt));
e41d82f5
RH
386 break;
387
388 default:
389 new_l = VARYING;
390 break;
391 }
392
393 /* If nothing changed this round, let the propagator know. */
394 if (new_l == old_l)
395 return SSA_PROP_NOT_INTERESTING;
396
9771b263 397 complex_lattice_values[ver] = new_l;
e41d82f5
RH
398 return new_l == VARYING ? SSA_PROP_VARYING : SSA_PROP_INTERESTING;
399}
400
401/* Evaluate a PHI node against the complex lattice defined above. */
402
403static enum ssa_prop_result
726a989a 404complex_visit_phi (gimple phi)
e41d82f5
RH
405{
406 complex_lattice_t new_l, old_l;
407 unsigned int ver;
408 tree lhs;
409 int i;
410
726a989a 411 lhs = gimple_phi_result (phi);
e41d82f5
RH
412
413 /* This condition should be satisfied due to the initial filter
414 set up in init_dont_simulate_again. */
415 gcc_assert (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE);
416
417 /* We've set up the lattice values such that IOR neatly models PHI meet. */
418 new_l = UNINITIALIZED;
726a989a
RB
419 for (i = gimple_phi_num_args (phi) - 1; i >= 0; --i)
420 new_l |= find_lattice_value (gimple_phi_arg_def (phi, i));
e41d82f5
RH
421
422 ver = SSA_NAME_VERSION (lhs);
9771b263 423 old_l = complex_lattice_values[ver];
e41d82f5
RH
424
425 if (new_l == old_l)
426 return SSA_PROP_NOT_INTERESTING;
427
9771b263 428 complex_lattice_values[ver] = new_l;
e41d82f5
RH
429 return new_l == VARYING ? SSA_PROP_VARYING : SSA_PROP_INTERESTING;
430}
431
95a8c155 432/* Create one backing variable for a complex component of ORIG. */
e41d82f5 433
95a8c155
RH
434static tree
435create_one_component_var (tree type, tree orig, const char *prefix,
436 const char *suffix, enum tree_code code)
e41d82f5 437{
95a8c155 438 tree r = create_tmp_var (type, prefix);
e41d82f5 439
95a8c155
RH
440 DECL_SOURCE_LOCATION (r) = DECL_SOURCE_LOCATION (orig);
441 DECL_ARTIFICIAL (r) = 1;
8f8abce4 442
95a8c155
RH
443 if (DECL_NAME (orig) && !DECL_IGNORED_P (orig))
444 {
445 const char *name = IDENTIFIER_POINTER (DECL_NAME (orig));
95a8c155
RH
446
447 DECL_NAME (r) = get_identifier (ACONCAT ((name, suffix, NULL)));
e41d82f5 448
95a8c155 449 SET_DECL_DEBUG_EXPR (r, build1 (code, type, orig));
839b422f 450 DECL_HAS_DEBUG_EXPR_P (r) = 1;
95a8c155
RH
451 DECL_IGNORED_P (r) = 0;
452 TREE_NO_WARNING (r) = TREE_NO_WARNING (orig);
453 }
454 else
e41d82f5 455 {
95a8c155
RH
456 DECL_IGNORED_P (r) = 1;
457 TREE_NO_WARNING (r) = 1;
458 }
e41d82f5 459
95a8c155
RH
460 return r;
461}
e41d82f5 462
95a8c155 463/* Retrieve a value for a complex component of VAR. */
e41d82f5 464
95a8c155
RH
465static tree
466get_component_var (tree var, bool imag_p)
467{
468 size_t decl_index = DECL_UID (var) * 2 + imag_p;
469 tree ret = cvc_lookup (decl_index);
470
471 if (ret == NULL)
472 {
473 ret = create_one_component_var (TREE_TYPE (TREE_TYPE (var)), var,
474 imag_p ? "CI" : "CR",
475 imag_p ? "$imag" : "$real",
476 imag_p ? IMAGPART_EXPR : REALPART_EXPR);
477 cvc_insert (decl_index, ret);
478 }
479
480 return ret;
481}
e41d82f5 482
95a8c155 483/* Retrieve a value for a complex component of SSA_NAME. */
e41d82f5 484
95a8c155
RH
485static tree
486get_component_ssa_name (tree ssa_name, bool imag_p)
487{
488 complex_lattice_t lattice = find_lattice_value (ssa_name);
489 size_t ssa_name_index;
490 tree ret;
e41d82f5 491
95a8c155
RH
492 if (lattice == (imag_p ? ONLY_REAL : ONLY_IMAG))
493 {
494 tree inner_type = TREE_TYPE (TREE_TYPE (ssa_name));
495 if (SCALAR_FLOAT_TYPE_P (inner_type))
496 return build_real (inner_type, dconst0);
497 else
498 return build_int_cst (inner_type, 0);
499 }
e41d82f5 500
95a8c155 501 ssa_name_index = SSA_NAME_VERSION (ssa_name) * 2 + imag_p;
9771b263 502 ret = complex_ssa_name_components[ssa_name_index];
95a8c155
RH
503 if (ret == NULL)
504 {
70b5e7dc
RG
505 if (SSA_NAME_VAR (ssa_name))
506 ret = get_component_var (SSA_NAME_VAR (ssa_name), imag_p);
507 else
508 ret = TREE_TYPE (TREE_TYPE (ssa_name));
95a8c155
RH
509 ret = make_ssa_name (ret, NULL);
510
511 /* Copy some properties from the original. In particular, whether it
512 is used in an abnormal phi, and whether it's uninitialized. */
513 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ret)
514 = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name);
67386041
RG
515 if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
516 && TREE_CODE (SSA_NAME_VAR (ssa_name)) == VAR_DECL)
95a8c155
RH
517 {
518 SSA_NAME_DEF_STMT (ret) = SSA_NAME_DEF_STMT (ssa_name);
32244553 519 set_ssa_default_def (cfun, SSA_NAME_VAR (ret), ret);
e41d82f5
RH
520 }
521
9771b263 522 complex_ssa_name_components[ssa_name_index] = ret;
e41d82f5 523 }
95a8c155
RH
524
525 return ret;
526}
527
726a989a
RB
528/* Set a value for a complex component of SSA_NAME, return a
529 gimple_seq of stuff that needs doing. */
95a8c155 530
726a989a 531static gimple_seq
95a8c155
RH
532set_component_ssa_name (tree ssa_name, bool imag_p, tree value)
533{
534 complex_lattice_t lattice = find_lattice_value (ssa_name);
535 size_t ssa_name_index;
726a989a
RB
536 tree comp;
537 gimple last;
538 gimple_seq list;
95a8c155
RH
539
540 /* We know the value must be zero, else there's a bug in our lattice
541 analysis. But the value may well be a variable known to contain
542 zero. We should be safe ignoring it. */
543 if (lattice == (imag_p ? ONLY_REAL : ONLY_IMAG))
544 return NULL;
545
546 /* If we've already assigned an SSA_NAME to this component, then this
547 means that our walk of the basic blocks found a use before the set.
548 This is fine. Now we should create an initialization for the value
549 we created earlier. */
550 ssa_name_index = SSA_NAME_VERSION (ssa_name) * 2 + imag_p;
9771b263 551 comp = complex_ssa_name_components[ssa_name_index];
95a8c155
RH
552 if (comp)
553 ;
554
555 /* If we've nothing assigned, and the value we're given is already stable,
536fa7b7 556 then install that as the value for this SSA_NAME. This preemptively
95a8c155 557 copy-propagates the value, which avoids unnecessary memory allocation. */
35a45bd4
RH
558 else if (is_gimple_min_invariant (value)
559 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
95a8c155 560 {
9771b263 561 complex_ssa_name_components[ssa_name_index] = value;
95a8c155
RH
562 return NULL;
563 }
564 else if (TREE_CODE (value) == SSA_NAME
565 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
566 {
567 /* Replace an anonymous base value with the variable from cvc_lookup.
568 This should result in better debug info. */
70b5e7dc
RG
569 if (SSA_NAME_VAR (ssa_name)
570 && (!SSA_NAME_VAR (value) || DECL_IGNORED_P (SSA_NAME_VAR (value)))
95a8c155
RH
571 && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name)))
572 {
573 comp = get_component_var (SSA_NAME_VAR (ssa_name), imag_p);
db753fa1 574 replace_ssa_name_symbol (value, comp);
95a8c155
RH
575 }
576
9771b263 577 complex_ssa_name_components[ssa_name_index] = value;
95a8c155
RH
578 return NULL;
579 }
580
581 /* Finally, we need to stabilize the result by installing the value into
582 a new ssa name. */
583 else
584 comp = get_component_ssa_name (ssa_name, imag_p);
b8698a0f 585
95a8c155 586 /* Do all the work to assign VALUE to COMP. */
726a989a 587 list = NULL;
95a8c155 588 value = force_gimple_operand (value, &list, false, NULL);
726a989a
RB
589 last = gimple_build_assign (comp, value);
590 gimple_seq_add_stmt (&list, last);
591 gcc_assert (SSA_NAME_DEF_STMT (comp) == last);
95a8c155
RH
592
593 return list;
e41d82f5 594}
6de9cd9a 595
6de9cd9a
DN
596/* Extract the real or imaginary part of a complex variable or constant.
597 Make sure that it's a proper gimple_val and gimplify it if not.
726a989a 598 Emit any new code before gsi. */
6de9cd9a
DN
599
600static tree
726a989a 601extract_component (gimple_stmt_iterator *gsi, tree t, bool imagpart_p,
e41d82f5 602 bool gimple_p)
6de9cd9a 603{
6de9cd9a
DN
604 switch (TREE_CODE (t))
605 {
606 case COMPLEX_CST:
e41d82f5 607 return imagpart_p ? TREE_IMAGPART (t) : TREE_REALPART (t);
6de9cd9a
DN
608
609 case COMPLEX_EXPR:
726a989a 610 gcc_unreachable ();
6de9cd9a
DN
611
612 case VAR_DECL:
f35a986c 613 case RESULT_DECL:
6de9cd9a 614 case PARM_DECL:
e41d82f5
RH
615 case COMPONENT_REF:
616 case ARRAY_REF:
7ec49257 617 case VIEW_CONVERT_EXPR:
70f34814 618 case MEM_REF:
e41d82f5
RH
619 {
620 tree inner_type = TREE_TYPE (TREE_TYPE (t));
621
622 t = build1 ((imagpart_p ? IMAGPART_EXPR : REALPART_EXPR),
623 inner_type, unshare_expr (t));
624
625 if (gimple_p)
726a989a
RB
626 t = force_gimple_operand_gsi (gsi, t, true, NULL, true,
627 GSI_SAME_STMT);
e41d82f5
RH
628
629 return t;
630 }
631
632 case SSA_NAME:
95a8c155 633 return get_component_ssa_name (t, imagpart_p);
6de9cd9a
DN
634
635 default:
1e128c5f 636 gcc_unreachable ();
6de9cd9a 637 }
e41d82f5
RH
638}
639
640/* Update the complex components of the ssa name on the lhs of STMT. */
6de9cd9a 641
e41d82f5 642static void
726a989a
RB
643update_complex_components (gimple_stmt_iterator *gsi, gimple stmt, tree r,
644 tree i)
e41d82f5 645{
726a989a
RB
646 tree lhs;
647 gimple_seq list;
648
649 lhs = gimple_get_lhs (stmt);
95a8c155
RH
650
651 list = set_component_ssa_name (lhs, false, r);
652 if (list)
726a989a 653 gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
95a8c155
RH
654
655 list = set_component_ssa_name (lhs, true, i);
656 if (list)
726a989a 657 gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
6de9cd9a
DN
658}
659
5d6b3bba 660static void
95a8c155 661update_complex_components_on_edge (edge e, tree lhs, tree r, tree i)
5d6b3bba 662{
726a989a 663 gimple_seq list;
5d6b3bba 664
95a8c155
RH
665 list = set_component_ssa_name (lhs, false, r);
666 if (list)
726a989a 667 gsi_insert_seq_on_edge (e, list);
5d6b3bba 668
95a8c155
RH
669 list = set_component_ssa_name (lhs, true, i);
670 if (list)
726a989a 671 gsi_insert_seq_on_edge (e, list);
5d6b3bba
RH
672}
673
726a989a 674
6de9cd9a
DN
675/* Update an assignment to a complex variable in place. */
676
677static void
726a989a 678update_complex_assignment (gimple_stmt_iterator *gsi, tree r, tree i)
6de9cd9a 679{
f5e5b46c 680 gimple stmt;
726a989a 681
355a7673
MM
682 gimple_assign_set_rhs_with_ops (gsi, COMPLEX_EXPR, r, i);
683 stmt = gsi_stmt (*gsi);
f5e5b46c
RG
684 update_stmt (stmt);
685 if (maybe_clean_eh_stmt (stmt))
686 gimple_purge_dead_eh_edges (gimple_bb (stmt));
355a7673
MM
687
688 if (gimple_in_ssa_p (cfun))
689 update_complex_components (gsi, gsi_stmt (*gsi), r, i);
e41d82f5
RH
690}
691
726a989a 692
e41d82f5
RH
693/* Generate code at the entry point of the function to initialize the
694 component variables for a complex parameter. */
695
696static void
697update_parameter_components (void)
698{
fefa31b5 699 edge entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
e41d82f5
RH
700 tree parm;
701
910ad8de 702 for (parm = DECL_ARGUMENTS (cfun->decl); parm ; parm = DECL_CHAIN (parm))
e41d82f5
RH
703 {
704 tree type = TREE_TYPE (parm);
5d6b3bba 705 tree ssa_name, r, i;
e41d82f5
RH
706
707 if (TREE_CODE (type) != COMPLEX_TYPE || !is_gimple_reg (parm))
708 continue;
709
710 type = TREE_TYPE (type);
32244553 711 ssa_name = ssa_default_def (cfun, parm);
c0a3f887
RG
712 if (!ssa_name)
713 continue;
e41d82f5 714
5d6b3bba
RH
715 r = build1 (REALPART_EXPR, type, ssa_name);
716 i = build1 (IMAGPART_EXPR, type, ssa_name);
95a8c155 717 update_complex_components_on_edge (entry_edge, ssa_name, r, i);
e41d82f5
RH
718 }
719}
720
721/* Generate code to set the component variables of a complex variable
722 to match the PHI statements in block BB. */
723
724static void
725update_phi_components (basic_block bb)
726{
726a989a 727 gimple_stmt_iterator gsi;
e41d82f5 728
726a989a
RB
729 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
730 {
731 gimple phi = gsi_stmt (gsi);
e41d82f5 732
726a989a
RB
733 if (is_complex_reg (gimple_phi_result (phi)))
734 {
735 tree lr, li;
736 gimple pr = NULL, pi = NULL;
737 unsigned int i, n;
95a8c155 738
726a989a
RB
739 lr = get_component_ssa_name (gimple_phi_result (phi), false);
740 if (TREE_CODE (lr) == SSA_NAME)
dcc748dd 741 pr = create_phi_node (lr, bb);
726a989a
RB
742
743 li = get_component_ssa_name (gimple_phi_result (phi), true);
744 if (TREE_CODE (li) == SSA_NAME)
dcc748dd 745 pi = create_phi_node (li, bb);
726a989a
RB
746
747 for (i = 0, n = gimple_phi_num_args (phi); i < n; ++i)
748 {
749 tree comp, arg = gimple_phi_arg_def (phi, i);
750 if (pr)
751 {
752 comp = extract_component (NULL, arg, false, false);
753 SET_PHI_ARG_DEF (pr, i, comp);
754 }
755 if (pi)
756 {
757 comp = extract_component (NULL, arg, true, false);
758 SET_PHI_ARG_DEF (pi, i, comp);
759 }
760 }
761 }
762 }
e41d82f5
RH
763}
764
e41d82f5
RH
765/* Expand a complex move to scalars. */
766
767static void
726a989a 768expand_complex_move (gimple_stmt_iterator *gsi, tree type)
e41d82f5
RH
769{
770 tree inner_type = TREE_TYPE (type);
726a989a
RB
771 tree r, i, lhs, rhs;
772 gimple stmt = gsi_stmt (*gsi);
773
774 if (is_gimple_assign (stmt))
775 {
776 lhs = gimple_assign_lhs (stmt);
777 if (gimple_num_ops (stmt) == 2)
778 rhs = gimple_assign_rhs1 (stmt);
779 else
780 rhs = NULL_TREE;
781 }
782 else if (is_gimple_call (stmt))
783 {
784 lhs = gimple_call_lhs (stmt);
785 rhs = NULL_TREE;
786 }
787 else
788 gcc_unreachable ();
e41d82f5
RH
789
790 if (TREE_CODE (lhs) == SSA_NAME)
791 {
726a989a 792 if (is_ctrl_altering_stmt (stmt))
5d6b3bba 793 {
5d6b3bba
RH
794 edge e;
795
796 /* The value is not assigned on the exception edges, so we need not
797 concern ourselves there. We do need to update on the fallthru
798 edge. Find it. */
0fd4b31d
NF
799 e = find_fallthru_edge (gsi_bb (*gsi)->succs);
800 if (!e)
801 gcc_unreachable ();
5d6b3bba
RH
802
803 r = build1 (REALPART_EXPR, inner_type, lhs);
804 i = build1 (IMAGPART_EXPR, inner_type, lhs);
95a8c155 805 update_complex_components_on_edge (e, lhs, r, i);
5d6b3bba 806 }
726a989a
RB
807 else if (is_gimple_call (stmt)
808 || gimple_has_side_effects (stmt)
809 || gimple_assign_rhs_code (stmt) == PAREN_EXPR)
e41d82f5 810 {
5d6b3bba
RH
811 r = build1 (REALPART_EXPR, inner_type, lhs);
812 i = build1 (IMAGPART_EXPR, inner_type, lhs);
726a989a 813 update_complex_components (gsi, stmt, r, i);
e41d82f5
RH
814 }
815 else
816 {
726a989a
RB
817 if (gimple_assign_rhs_code (stmt) != COMPLEX_EXPR)
818 {
819 r = extract_component (gsi, rhs, 0, true);
820 i = extract_component (gsi, rhs, 1, true);
821 }
822 else
823 {
824 r = gimple_assign_rhs1 (stmt);
825 i = gimple_assign_rhs2 (stmt);
826 }
827 update_complex_assignment (gsi, r, i);
e41d82f5
RH
828 }
829 }
726a989a 830 else if (rhs && TREE_CODE (rhs) == SSA_NAME && !TREE_SIDE_EFFECTS (lhs))
e41d82f5
RH
831 {
832 tree x;
726a989a 833 gimple t;
e1ec47c4 834 location_t loc;
e41d82f5 835
e1ec47c4 836 loc = gimple_location (stmt);
726a989a
RB
837 r = extract_component (gsi, rhs, 0, false);
838 i = extract_component (gsi, rhs, 1, false);
e41d82f5
RH
839
840 x = build1 (REALPART_EXPR, inner_type, unshare_expr (lhs));
726a989a 841 t = gimple_build_assign (x, r);
e1ec47c4 842 gimple_set_location (t, loc);
726a989a 843 gsi_insert_before (gsi, t, GSI_SAME_STMT);
e41d82f5 844
726a989a 845 if (stmt == gsi_stmt (*gsi))
e41d82f5
RH
846 {
847 x = build1 (IMAGPART_EXPR, inner_type, unshare_expr (lhs));
726a989a
RB
848 gimple_assign_set_lhs (stmt, x);
849 gimple_assign_set_rhs1 (stmt, i);
e41d82f5
RH
850 }
851 else
852 {
853 x = build1 (IMAGPART_EXPR, inner_type, unshare_expr (lhs));
726a989a 854 t = gimple_build_assign (x, i);
e1ec47c4 855 gimple_set_location (t, loc);
726a989a 856 gsi_insert_before (gsi, t, GSI_SAME_STMT);
e41d82f5 857
726a989a
RB
858 stmt = gsi_stmt (*gsi);
859 gcc_assert (gimple_code (stmt) == GIMPLE_RETURN);
860 gimple_return_set_retval (stmt, lhs);
e41d82f5
RH
861 }
862
e41d82f5
RH
863 update_stmt (stmt);
864 }
6de9cd9a
DN
865}
866
867/* Expand complex addition to scalars:
868 a + b = (ar + br) + i(ai + bi)
869 a - b = (ar - br) + i(ai + bi)
870*/
871
872static void
726a989a 873expand_complex_addition (gimple_stmt_iterator *gsi, tree inner_type,
6de9cd9a 874 tree ar, tree ai, tree br, tree bi,
e41d82f5
RH
875 enum tree_code code,
876 complex_lattice_t al, complex_lattice_t bl)
6de9cd9a
DN
877{
878 tree rr, ri;
879
e41d82f5
RH
880 switch (PAIR (al, bl))
881 {
882 case PAIR (ONLY_REAL, ONLY_REAL):
726a989a 883 rr = gimplify_build2 (gsi, code, inner_type, ar, br);
e41d82f5
RH
884 ri = ai;
885 break;
886
887 case PAIR (ONLY_REAL, ONLY_IMAG):
888 rr = ar;
889 if (code == MINUS_EXPR)
726a989a 890 ri = gimplify_build2 (gsi, MINUS_EXPR, inner_type, ai, bi);
e41d82f5
RH
891 else
892 ri = bi;
893 break;
894
895 case PAIR (ONLY_IMAG, ONLY_REAL):
896 if (code == MINUS_EXPR)
726a989a 897 rr = gimplify_build2 (gsi, MINUS_EXPR, inner_type, ar, br);
e41d82f5
RH
898 else
899 rr = br;
900 ri = ai;
901 break;
902
903 case PAIR (ONLY_IMAG, ONLY_IMAG):
904 rr = ar;
726a989a 905 ri = gimplify_build2 (gsi, code, inner_type, ai, bi);
e41d82f5
RH
906 break;
907
908 case PAIR (VARYING, ONLY_REAL):
726a989a 909 rr = gimplify_build2 (gsi, code, inner_type, ar, br);
e41d82f5
RH
910 ri = ai;
911 break;
912
913 case PAIR (VARYING, ONLY_IMAG):
914 rr = ar;
726a989a 915 ri = gimplify_build2 (gsi, code, inner_type, ai, bi);
e41d82f5
RH
916 break;
917
918 case PAIR (ONLY_REAL, VARYING):
919 if (code == MINUS_EXPR)
920 goto general;
726a989a 921 rr = gimplify_build2 (gsi, code, inner_type, ar, br);
e41d82f5
RH
922 ri = bi;
923 break;
924
925 case PAIR (ONLY_IMAG, VARYING):
926 if (code == MINUS_EXPR)
927 goto general;
928 rr = br;
726a989a 929 ri = gimplify_build2 (gsi, code, inner_type, ai, bi);
e41d82f5
RH
930 break;
931
932 case PAIR (VARYING, VARYING):
933 general:
726a989a
RB
934 rr = gimplify_build2 (gsi, code, inner_type, ar, br);
935 ri = gimplify_build2 (gsi, code, inner_type, ai, bi);
e41d82f5
RH
936 break;
937
938 default:
939 gcc_unreachable ();
940 }
6de9cd9a 941
726a989a 942 update_complex_assignment (gsi, rr, ri);
6de9cd9a
DN
943}
944
7e7e470f
RH
945/* Expand a complex multiplication or division to a libcall to the c99
946 compliant routines. */
947
948static void
726a989a 949expand_complex_libcall (gimple_stmt_iterator *gsi, tree ar, tree ai,
7e7e470f
RH
950 tree br, tree bi, enum tree_code code)
951{
952 enum machine_mode mode;
953 enum built_in_function bcode;
726a989a 954 tree fn, type, lhs;
04be6ff5 955 gimple old_stmt, stmt;
7e7e470f 956
04be6ff5
JJ
957 old_stmt = gsi_stmt (*gsi);
958 lhs = gimple_assign_lhs (old_stmt);
726a989a 959 type = TREE_TYPE (lhs);
7e7e470f
RH
960
961 mode = TYPE_MODE (type);
962 gcc_assert (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT);
726a989a 963
7e7e470f 964 if (code == MULT_EXPR)
32e8bb8e
ILT
965 bcode = ((enum built_in_function)
966 (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
7e7e470f 967 else if (code == RDIV_EXPR)
32e8bb8e
ILT
968 bcode = ((enum built_in_function)
969 (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
7e7e470f
RH
970 else
971 gcc_unreachable ();
e79983f4 972 fn = builtin_decl_explicit (bcode);
7e7e470f 973
726a989a
RB
974 stmt = gimple_build_call (fn, 4, ar, ai, br, bi);
975 gimple_call_set_lhs (stmt, lhs);
f430bae8 976 update_stmt (stmt);
04be6ff5
JJ
977 gsi_replace (gsi, stmt, false);
978
979 if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
980 gimple_purge_dead_eh_edges (gsi_bb (*gsi));
e41d82f5 981
5cd4ec7f 982 if (gimple_in_ssa_p (cfun))
e41d82f5 983 {
d5c77941 984 type = TREE_TYPE (type);
726a989a 985 update_complex_components (gsi, stmt,
e41d82f5
RH
986 build1 (REALPART_EXPR, type, lhs),
987 build1 (IMAGPART_EXPR, type, lhs));
726a989a 988 SSA_NAME_DEF_STMT (lhs) = stmt;
e41d82f5 989 }
7e7e470f
RH
990}
991
6de9cd9a
DN
992/* Expand complex multiplication to scalars:
993 a * b = (ar*br - ai*bi) + i(ar*bi + br*ai)
994*/
995
996static void
726a989a 997expand_complex_multiplication (gimple_stmt_iterator *gsi, tree inner_type,
e41d82f5
RH
998 tree ar, tree ai, tree br, tree bi,
999 complex_lattice_t al, complex_lattice_t bl)
6de9cd9a 1000{
e41d82f5 1001 tree rr, ri;
6de9cd9a 1002
e41d82f5 1003 if (al < bl)
7e7e470f 1004 {
e41d82f5
RH
1005 complex_lattice_t tl;
1006 rr = ar, ar = br, br = rr;
1007 ri = ai, ai = bi, bi = ri;
1008 tl = al, al = bl, bl = tl;
7e7e470f
RH
1009 }
1010
e41d82f5
RH
1011 switch (PAIR (al, bl))
1012 {
1013 case PAIR (ONLY_REAL, ONLY_REAL):
726a989a 1014 rr = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, br);
e41d82f5
RH
1015 ri = ai;
1016 break;
6de9cd9a 1017
e41d82f5
RH
1018 case PAIR (ONLY_IMAG, ONLY_REAL):
1019 rr = ar;
1020 if (TREE_CODE (ai) == REAL_CST
1021 && REAL_VALUES_IDENTICAL (TREE_REAL_CST (ai), dconst1))
1022 ri = br;
1023 else
726a989a 1024 ri = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, br);
e41d82f5 1025 break;
6de9cd9a 1026
e41d82f5 1027 case PAIR (ONLY_IMAG, ONLY_IMAG):
726a989a
RB
1028 rr = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, bi);
1029 rr = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, rr);
e41d82f5
RH
1030 ri = ar;
1031 break;
1032
1033 case PAIR (VARYING, ONLY_REAL):
726a989a
RB
1034 rr = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, br);
1035 ri = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, br);
e41d82f5
RH
1036 break;
1037
1038 case PAIR (VARYING, ONLY_IMAG):
726a989a
RB
1039 rr = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, bi);
1040 rr = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, rr);
1041 ri = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, bi);
e41d82f5
RH
1042 break;
1043
1044 case PAIR (VARYING, VARYING):
1045 if (flag_complex_method == 2 && SCALAR_FLOAT_TYPE_P (inner_type))
1046 {
726a989a 1047 expand_complex_libcall (gsi, ar, ai, br, bi, MULT_EXPR);
e41d82f5
RH
1048 return;
1049 }
1050 else
1051 {
1052 tree t1, t2, t3, t4;
1053
726a989a
RB
1054 t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, br);
1055 t2 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, bi);
1056 t3 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, bi);
e41d82f5
RH
1057
1058 /* Avoid expanding redundant multiplication for the common
1059 case of squaring a complex number. */
1060 if (ar == br && ai == bi)
1061 t4 = t3;
1062 else
726a989a 1063 t4 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, br);
e41d82f5 1064
726a989a
RB
1065 rr = gimplify_build2 (gsi, MINUS_EXPR, inner_type, t1, t2);
1066 ri = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t3, t4);
e41d82f5
RH
1067 }
1068 break;
1069
1070 default:
1071 gcc_unreachable ();
1072 }
6de9cd9a 1073
726a989a 1074 update_complex_assignment (gsi, rr, ri);
6de9cd9a
DN
1075}
1076
e3d5405d 1077/* Keep this algorithm in sync with fold-const.c:const_binop().
b8698a0f 1078
e3d5405d 1079 Expand complex division to scalars, straightforward algorithm.
6de9cd9a
DN
1080 a / b = ((ar*br + ai*bi)/t) + i((ai*br - ar*bi)/t)
1081 t = br*br + bi*bi
1082*/
1083
1084static void
726a989a 1085expand_complex_div_straight (gimple_stmt_iterator *gsi, tree inner_type,
6de9cd9a
DN
1086 tree ar, tree ai, tree br, tree bi,
1087 enum tree_code code)
1088{
1089 tree rr, ri, div, t1, t2, t3;
1090
726a989a
RB
1091 t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, br, br);
1092 t2 = gimplify_build2 (gsi, MULT_EXPR, inner_type, bi, bi);
1093 div = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, t2);
6de9cd9a 1094
726a989a
RB
1095 t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, br);
1096 t2 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, bi);
1097 t3 = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, t2);
1098 rr = gimplify_build2 (gsi, code, inner_type, t3, div);
6de9cd9a 1099
726a989a
RB
1100 t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, br);
1101 t2 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, bi);
1102 t3 = gimplify_build2 (gsi, MINUS_EXPR, inner_type, t1, t2);
1103 ri = gimplify_build2 (gsi, code, inner_type, t3, div);
6de9cd9a 1104
726a989a 1105 update_complex_assignment (gsi, rr, ri);
6de9cd9a
DN
1106}
1107
e3d5405d
KG
1108/* Keep this algorithm in sync with fold-const.c:const_binop().
1109
1110 Expand complex division to scalars, modified algorithm to minimize
6de9cd9a
DN
1111 overflow with wide input ranges. */
1112
1113static void
726a989a 1114expand_complex_div_wide (gimple_stmt_iterator *gsi, tree inner_type,
6de9cd9a
DN
1115 tree ar, tree ai, tree br, tree bi,
1116 enum tree_code code)
1117{
04b03edb 1118 tree rr, ri, ratio, div, t1, t2, tr, ti, compare;
c63f5a42 1119 basic_block bb_cond, bb_true, bb_false, bb_join;
726a989a 1120 gimple stmt;
6de9cd9a
DN
1121
1122 /* Examine |br| < |bi|, and branch. */
726a989a
RB
1123 t1 = gimplify_build1 (gsi, ABS_EXPR, inner_type, br);
1124 t2 = gimplify_build1 (gsi, ABS_EXPR, inner_type, bi);
db3927fb 1125 compare = fold_build2_loc (gimple_location (gsi_stmt (*gsi)),
b57d8e6f 1126 LT_EXPR, boolean_type_node, t1, t2);
04b03edb 1127 STRIP_NOPS (compare);
6de9cd9a 1128
c63f5a42
RH
1129 bb_cond = bb_true = bb_false = bb_join = NULL;
1130 rr = ri = tr = ti = NULL;
b57d8e6f 1131 if (TREE_CODE (compare) != INTEGER_CST)
6de9cd9a 1132 {
6de9cd9a 1133 edge e;
726a989a 1134 gimple stmt;
04b03edb 1135 tree cond, tmp;
6de9cd9a 1136
04b03edb 1137 tmp = create_tmp_var (boolean_type_node, NULL);
726a989a 1138 stmt = gimple_build_assign (tmp, compare);
04b03edb 1139 if (gimple_in_ssa_p (cfun))
726a989a
RB
1140 {
1141 tmp = make_ssa_name (tmp, stmt);
1142 gimple_assign_set_lhs (stmt, tmp);
1143 }
1144
1145 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
04b03edb 1146
db3927fb
AH
1147 cond = fold_build2_loc (gimple_location (stmt),
1148 EQ_EXPR, boolean_type_node, tmp, boolean_true_node);
726a989a
RB
1149 stmt = gimple_build_cond_from_tree (cond, NULL_TREE, NULL_TREE);
1150 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
6de9cd9a 1151
6de9cd9a 1152 /* Split the original block, and create the TRUE and FALSE blocks. */
726a989a 1153 e = split_block (gsi_bb (*gsi), stmt);
6de9cd9a
DN
1154 bb_cond = e->src;
1155 bb_join = e->dest;
1156 bb_true = create_empty_bb (bb_cond);
1157 bb_false = create_empty_bb (bb_true);
1158
1159 /* Wire the blocks together. */
1160 e->flags = EDGE_TRUE_VALUE;
1161 redirect_edge_succ (e, bb_true);
1162 make_edge (bb_cond, bb_false, EDGE_FALSE_VALUE);
520f34fa
RH
1163 make_edge (bb_true, bb_join, EDGE_FALLTHRU);
1164 make_edge (bb_false, bb_join, EDGE_FALLTHRU);
726338f4
RB
1165 add_bb_to_loop (bb_true, bb_cond->loop_father);
1166 add_bb_to_loop (bb_false, bb_cond->loop_father);
6de9cd9a
DN
1167
1168 /* Update dominance info. Note that bb_join's data was
1169 updated by split_block. */
fce22de5 1170 if (dom_info_available_p (CDI_DOMINATORS))
6de9cd9a
DN
1171 {
1172 set_immediate_dominator (CDI_DOMINATORS, bb_true, bb_cond);
1173 set_immediate_dominator (CDI_DOMINATORS, bb_false, bb_cond);
1174 }
1175
7cc434a3
RG
1176 rr = create_tmp_reg (inner_type, NULL);
1177 ri = create_tmp_reg (inner_type, NULL);
6de9cd9a 1178 }
c63f5a42
RH
1179
1180 /* In the TRUE branch, we compute
1181 ratio = br/bi;
1182 div = (br * ratio) + bi;
1183 tr = (ar * ratio) + ai;
1184 ti = (ai * ratio) - ar;
1185 tr = tr / div;
1186 ti = ti / div; */
04b03edb 1187 if (bb_true || integer_nonzerop (compare))
c63f5a42
RH
1188 {
1189 if (bb_true)
1190 {
726a989a
RB
1191 *gsi = gsi_last_bb (bb_true);
1192 gsi_insert_after (gsi, gimple_build_nop (), GSI_NEW_STMT);
c63f5a42
RH
1193 }
1194
726a989a 1195 ratio = gimplify_build2 (gsi, code, inner_type, br, bi);
c63f5a42 1196
726a989a
RB
1197 t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, br, ratio);
1198 div = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, bi);
c63f5a42 1199
726a989a
RB
1200 t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, ratio);
1201 tr = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, ai);
c63f5a42 1202
726a989a
RB
1203 t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, ratio);
1204 ti = gimplify_build2 (gsi, MINUS_EXPR, inner_type, t1, ar);
c63f5a42 1205
726a989a
RB
1206 tr = gimplify_build2 (gsi, code, inner_type, tr, div);
1207 ti = gimplify_build2 (gsi, code, inner_type, ti, div);
c63f5a42
RH
1208
1209 if (bb_true)
1210 {
726a989a
RB
1211 stmt = gimple_build_assign (rr, tr);
1212 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1213 stmt = gimple_build_assign (ri, ti);
1214 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1215 gsi_remove (gsi, true);
c63f5a42
RH
1216 }
1217 }
1218
1219 /* In the FALSE branch, we compute
1220 ratio = d/c;
1221 divisor = (d * ratio) + c;
1222 tr = (b * ratio) + a;
1223 ti = b - (a * ratio);
1224 tr = tr / div;
1225 ti = ti / div; */
04b03edb 1226 if (bb_false || integer_zerop (compare))
c63f5a42
RH
1227 {
1228 if (bb_false)
1229 {
726a989a
RB
1230 *gsi = gsi_last_bb (bb_false);
1231 gsi_insert_after (gsi, gimple_build_nop (), GSI_NEW_STMT);
c63f5a42
RH
1232 }
1233
726a989a 1234 ratio = gimplify_build2 (gsi, code, inner_type, bi, br);
c63f5a42 1235
726a989a
RB
1236 t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, bi, ratio);
1237 div = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, br);
c63f5a42 1238
726a989a
RB
1239 t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, ratio);
1240 tr = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, ar);
c63f5a42 1241
726a989a
RB
1242 t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, ratio);
1243 ti = gimplify_build2 (gsi, MINUS_EXPR, inner_type, ai, t1);
c63f5a42 1244
726a989a
RB
1245 tr = gimplify_build2 (gsi, code, inner_type, tr, div);
1246 ti = gimplify_build2 (gsi, code, inner_type, ti, div);
c63f5a42
RH
1247
1248 if (bb_false)
1249 {
726a989a
RB
1250 stmt = gimple_build_assign (rr, tr);
1251 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1252 stmt = gimple_build_assign (ri, ti);
1253 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1254 gsi_remove (gsi, true);
c63f5a42
RH
1255 }
1256 }
1257
1258 if (bb_join)
726a989a 1259 *gsi = gsi_start_bb (bb_join);
c63f5a42
RH
1260 else
1261 rr = tr, ri = ti;
6de9cd9a 1262
726a989a 1263 update_complex_assignment (gsi, rr, ri);
6de9cd9a
DN
1264}
1265
1266/* Expand complex division to scalars. */
1267
1268static void
726a989a 1269expand_complex_division (gimple_stmt_iterator *gsi, tree inner_type,
6de9cd9a 1270 tree ar, tree ai, tree br, tree bi,
e41d82f5
RH
1271 enum tree_code code,
1272 complex_lattice_t al, complex_lattice_t bl)
6de9cd9a 1273{
e41d82f5
RH
1274 tree rr, ri;
1275
1276 switch (PAIR (al, bl))
6de9cd9a 1277 {
e41d82f5 1278 case PAIR (ONLY_REAL, ONLY_REAL):
726a989a 1279 rr = gimplify_build2 (gsi, code, inner_type, ar, br);
e41d82f5 1280 ri = ai;
6de9cd9a 1281 break;
7e7e470f 1282
e41d82f5
RH
1283 case PAIR (ONLY_REAL, ONLY_IMAG):
1284 rr = ai;
726a989a
RB
1285 ri = gimplify_build2 (gsi, code, inner_type, ar, bi);
1286 ri = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ri);
e41d82f5
RH
1287 break;
1288
1289 case PAIR (ONLY_IMAG, ONLY_REAL):
1290 rr = ar;
726a989a 1291 ri = gimplify_build2 (gsi, code, inner_type, ai, br);
e41d82f5 1292 break;
7e7e470f 1293
e41d82f5 1294 case PAIR (ONLY_IMAG, ONLY_IMAG):
726a989a 1295 rr = gimplify_build2 (gsi, code, inner_type, ai, bi);
e41d82f5 1296 ri = ar;
6de9cd9a 1297 break;
7e7e470f 1298
e41d82f5 1299 case PAIR (VARYING, ONLY_REAL):
726a989a
RB
1300 rr = gimplify_build2 (gsi, code, inner_type, ar, br);
1301 ri = gimplify_build2 (gsi, code, inner_type, ai, br);
e41d82f5
RH
1302 break;
1303
1304 case PAIR (VARYING, ONLY_IMAG):
726a989a
RB
1305 rr = gimplify_build2 (gsi, code, inner_type, ai, bi);
1306 ri = gimplify_build2 (gsi, code, inner_type, ar, bi);
1307 ri = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ri);
e41d82f5
RH
1308
1309 case PAIR (ONLY_REAL, VARYING):
1310 case PAIR (ONLY_IMAG, VARYING):
1311 case PAIR (VARYING, VARYING):
1312 switch (flag_complex_method)
1313 {
1314 case 0:
1315 /* straightforward implementation of complex divide acceptable. */
726a989a 1316 expand_complex_div_straight (gsi, inner_type, ar, ai, br, bi, code);
e41d82f5
RH
1317 break;
1318
1319 case 2:
1320 if (SCALAR_FLOAT_TYPE_P (inner_type))
1321 {
726a989a 1322 expand_complex_libcall (gsi, ar, ai, br, bi, code);
e41d82f5
RH
1323 break;
1324 }
1325 /* FALLTHRU */
1326
1327 case 1:
1328 /* wide ranges of inputs must work for complex divide. */
726a989a 1329 expand_complex_div_wide (gsi, inner_type, ar, ai, br, bi, code);
e41d82f5
RH
1330 break;
1331
1332 default:
1333 gcc_unreachable ();
1334 }
1335 return;
1336
6de9cd9a 1337 default:
1e128c5f 1338 gcc_unreachable ();
6de9cd9a 1339 }
e41d82f5 1340
726a989a 1341 update_complex_assignment (gsi, rr, ri);
6de9cd9a
DN
1342}
1343
1344/* Expand complex negation to scalars:
1345 -a = (-ar) + i(-ai)
1346*/
1347
1348static void
726a989a 1349expand_complex_negation (gimple_stmt_iterator *gsi, tree inner_type,
6de9cd9a
DN
1350 tree ar, tree ai)
1351{
1352 tree rr, ri;
1353
726a989a
RB
1354 rr = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ar);
1355 ri = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ai);
6de9cd9a 1356
726a989a 1357 update_complex_assignment (gsi, rr, ri);
6de9cd9a
DN
1358}
1359
1360/* Expand complex conjugate to scalars:
1361 ~a = (ar) + i(-ai)
1362*/
1363
1364static void
726a989a 1365expand_complex_conjugate (gimple_stmt_iterator *gsi, tree inner_type,
6de9cd9a
DN
1366 tree ar, tree ai)
1367{
1368 tree ri;
1369
726a989a 1370 ri = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ai);
6de9cd9a 1371
726a989a 1372 update_complex_assignment (gsi, ar, ri);
6de9cd9a
DN
1373}
1374
1375/* Expand complex comparison (EQ or NE only). */
1376
1377static void
726a989a 1378expand_complex_comparison (gimple_stmt_iterator *gsi, tree ar, tree ai,
6de9cd9a
DN
1379 tree br, tree bi, enum tree_code code)
1380{
726a989a
RB
1381 tree cr, ci, cc, type;
1382 gimple stmt;
6de9cd9a 1383
726a989a
RB
1384 cr = gimplify_build2 (gsi, code, boolean_type_node, ar, br);
1385 ci = gimplify_build2 (gsi, code, boolean_type_node, ai, bi);
1386 cc = gimplify_build2 (gsi,
26277d41
PB
1387 (code == EQ_EXPR ? TRUTH_AND_EXPR : TRUTH_OR_EXPR),
1388 boolean_type_node, cr, ci);
6de9cd9a 1389
726a989a 1390 stmt = gsi_stmt (*gsi);
6de9cd9a 1391
726a989a 1392 switch (gimple_code (stmt))
6de9cd9a 1393 {
726a989a
RB
1394 case GIMPLE_RETURN:
1395 type = TREE_TYPE (gimple_return_retval (stmt));
1396 gimple_return_set_retval (stmt, fold_convert (type, cc));
6de9cd9a 1397 break;
726a989a
RB
1398
1399 case GIMPLE_ASSIGN:
1400 type = TREE_TYPE (gimple_assign_lhs (stmt));
1401 gimple_assign_set_rhs_from_tree (gsi, fold_convert (type, cc));
1402 stmt = gsi_stmt (*gsi);
6de9cd9a 1403 break;
726a989a
RB
1404
1405 case GIMPLE_COND:
1406 gimple_cond_set_code (stmt, EQ_EXPR);
1407 gimple_cond_set_lhs (stmt, cc);
1408 gimple_cond_set_rhs (stmt, boolean_true_node);
1409 break;
1410
6de9cd9a 1411 default:
1e128c5f 1412 gcc_unreachable ();
6de9cd9a 1413 }
68b9f53b 1414
e41d82f5 1415 update_stmt (stmt);
6de9cd9a
DN
1416}
1417
a57fc743
JJ
1418/* Expand inline asm that sets some complex SSA_NAMEs. */
1419
1420static void
1421expand_complex_asm (gimple_stmt_iterator *gsi)
1422{
1423 gimple stmt = gsi_stmt (*gsi);
1424 unsigned int i;
1425
1426 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
1427 {
1428 tree link = gimple_asm_output_op (stmt, i);
1429 tree op = TREE_VALUE (link);
1430 if (TREE_CODE (op) == SSA_NAME
1431 && TREE_CODE (TREE_TYPE (op)) == COMPLEX_TYPE)
1432 {
1433 tree type = TREE_TYPE (op);
1434 tree inner_type = TREE_TYPE (type);
1435 tree r = build1 (REALPART_EXPR, inner_type, op);
1436 tree i = build1 (IMAGPART_EXPR, inner_type, op);
1437 gimple_seq list = set_component_ssa_name (op, false, r);
1438
1439 if (list)
1440 gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
1441
1442 list = set_component_ssa_name (op, true, i);
1443 if (list)
1444 gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
1445 }
1446 }
1447}
726a989a 1448
6de9cd9a
DN
1449/* Process one statement. If we identify a complex operation, expand it. */
1450
1451static void
726a989a 1452expand_complex_operations_1 (gimple_stmt_iterator *gsi)
6de9cd9a 1453{
726a989a
RB
1454 gimple stmt = gsi_stmt (*gsi);
1455 tree type, inner_type, lhs;
6de9cd9a 1456 tree ac, ar, ai, bc, br, bi;
e41d82f5 1457 complex_lattice_t al, bl;
6de9cd9a
DN
1458 enum tree_code code;
1459
a57fc743
JJ
1460 if (gimple_code (stmt) == GIMPLE_ASM)
1461 {
1462 expand_complex_asm (gsi);
1463 return;
1464 }
1465
726a989a
RB
1466 lhs = gimple_get_lhs (stmt);
1467 if (!lhs && gimple_code (stmt) != GIMPLE_COND)
1468 return;
6de9cd9a 1469
726a989a
RB
1470 type = TREE_TYPE (gimple_op (stmt, 0));
1471 code = gimple_expr_code (stmt);
6de9cd9a
DN
1472
1473 /* Initial filter for operations we handle. */
1474 switch (code)
1475 {
1476 case PLUS_EXPR:
1477 case MINUS_EXPR:
1478 case MULT_EXPR:
1479 case TRUNC_DIV_EXPR:
1480 case CEIL_DIV_EXPR:
1481 case FLOOR_DIV_EXPR:
1482 case ROUND_DIV_EXPR:
1483 case RDIV_EXPR:
1484 case NEGATE_EXPR:
1485 case CONJ_EXPR:
1486 if (TREE_CODE (type) != COMPLEX_TYPE)
1487 return;
1488 inner_type = TREE_TYPE (type);
1489 break;
1490
1491 case EQ_EXPR:
1492 case NE_EXPR:
726a989a 1493 /* Note, both GIMPLE_ASSIGN and GIMPLE_COND may have an EQ_EXPR
207156e4 1494 subcode, so we need to access the operands using gimple_op. */
726a989a 1495 inner_type = TREE_TYPE (gimple_op (stmt, 1));
6de9cd9a
DN
1496 if (TREE_CODE (inner_type) != COMPLEX_TYPE)
1497 return;
1498 break;
1499
1500 default:
e41d82f5 1501 {
726a989a 1502 tree rhs;
a9b77cd1 1503
726a989a
RB
1504 /* GIMPLE_COND may also fallthru here, but we do not need to
1505 do anything with it. */
1506 if (gimple_code (stmt) == GIMPLE_COND)
a9b77cd1
ZD
1507 return;
1508
e41d82f5 1509 if (TREE_CODE (type) == COMPLEX_TYPE)
726a989a
RB
1510 expand_complex_move (gsi, type);
1511 else if (is_gimple_assign (stmt)
1512 && (gimple_assign_rhs_code (stmt) == REALPART_EXPR
1513 || gimple_assign_rhs_code (stmt) == IMAGPART_EXPR)
1514 && TREE_CODE (lhs) == SSA_NAME)
e41d82f5 1515 {
726a989a
RB
1516 rhs = gimple_assign_rhs1 (stmt);
1517 rhs = extract_component (gsi, TREE_OPERAND (rhs, 0),
1518 gimple_assign_rhs_code (stmt)
1519 == IMAGPART_EXPR,
1520 false);
1521 gimple_assign_set_rhs_from_tree (gsi, rhs);
1522 stmt = gsi_stmt (*gsi);
e41d82f5
RH
1523 update_stmt (stmt);
1524 }
1525 }
6de9cd9a
DN
1526 return;
1527 }
1528
1529 /* Extract the components of the two complex values. Make sure and
1530 handle the common case of the same value used twice specially. */
726a989a
RB
1531 if (is_gimple_assign (stmt))
1532 {
1533 ac = gimple_assign_rhs1 (stmt);
1534 bc = (gimple_num_ops (stmt) > 2) ? gimple_assign_rhs2 (stmt) : NULL;
1535 }
1536 /* GIMPLE_CALL can not get here. */
6de9cd9a
DN
1537 else
1538 {
726a989a
RB
1539 ac = gimple_cond_lhs (stmt);
1540 bc = gimple_cond_rhs (stmt);
1541 }
1542
1543 ar = extract_component (gsi, ac, false, true);
1544 ai = extract_component (gsi, ac, true, true);
1545
1546 if (ac == bc)
1547 br = ar, bi = ai;
1548 else if (bc)
1549 {
1550 br = extract_component (gsi, bc, 0, true);
1551 bi = extract_component (gsi, bc, 1, true);
6de9cd9a 1552 }
726a989a
RB
1553 else
1554 br = bi = NULL_TREE;
6de9cd9a 1555
5cd4ec7f 1556 if (gimple_in_ssa_p (cfun))
e41d82f5
RH
1557 {
1558 al = find_lattice_value (ac);
1559 if (al == UNINITIALIZED)
1560 al = VARYING;
1561
1562 if (TREE_CODE_CLASS (code) == tcc_unary)
1563 bl = UNINITIALIZED;
1564 else if (ac == bc)
1565 bl = al;
1566 else
1567 {
1568 bl = find_lattice_value (bc);
1569 if (bl == UNINITIALIZED)
1570 bl = VARYING;
1571 }
1572 }
1573 else
1574 al = bl = VARYING;
1575
6de9cd9a
DN
1576 switch (code)
1577 {
1578 case PLUS_EXPR:
1579 case MINUS_EXPR:
726a989a 1580 expand_complex_addition (gsi, inner_type, ar, ai, br, bi, code, al, bl);
6de9cd9a
DN
1581 break;
1582
1583 case MULT_EXPR:
726a989a 1584 expand_complex_multiplication (gsi, inner_type, ar, ai, br, bi, al, bl);
6de9cd9a
DN
1585 break;
1586
1587 case TRUNC_DIV_EXPR:
1588 case CEIL_DIV_EXPR:
1589 case FLOOR_DIV_EXPR:
1590 case ROUND_DIV_EXPR:
1591 case RDIV_EXPR:
726a989a 1592 expand_complex_division (gsi, inner_type, ar, ai, br, bi, code, al, bl);
6de9cd9a 1593 break;
b8698a0f 1594
6de9cd9a 1595 case NEGATE_EXPR:
726a989a 1596 expand_complex_negation (gsi, inner_type, ar, ai);
6de9cd9a
DN
1597 break;
1598
1599 case CONJ_EXPR:
726a989a 1600 expand_complex_conjugate (gsi, inner_type, ar, ai);
6de9cd9a
DN
1601 break;
1602
1603 case EQ_EXPR:
1604 case NE_EXPR:
726a989a 1605 expand_complex_comparison (gsi, ar, ai, br, bi, code);
6de9cd9a
DN
1606 break;
1607
1608 default:
1e128c5f 1609 gcc_unreachable ();
6de9cd9a
DN
1610 }
1611}
26277d41 1612
e41d82f5
RH
1613\f
1614/* Entry point for complex operation lowering during optimization. */
1615
c2924966 1616static unsigned int
2b725155 1617tree_lower_complex (void)
6de9cd9a 1618{
e41d82f5 1619 int old_last_basic_block;
726a989a 1620 gimple_stmt_iterator gsi;
6de9cd9a
DN
1621 basic_block bb;
1622
e41d82f5 1623 if (!init_dont_simulate_again ())
c2924966 1624 return 0;
e41d82f5 1625
9771b263
DN
1626 complex_lattice_values.create (num_ssa_names);
1627 complex_lattice_values.safe_grow_cleared (num_ssa_names);
e41d82f5 1628
95a8c155 1629 init_parameter_lattice_values ();
e41d82f5
RH
1630 ssa_propagate (complex_visit_stmt, complex_visit_phi);
1631
c203e8a7 1632 complex_variable_components = new int_tree_htab_type (10);
95a8c155 1633
9771b263
DN
1634 complex_ssa_name_components.create (2 * num_ssa_names);
1635 complex_ssa_name_components.safe_grow_cleared (2 * num_ssa_names);
95a8c155 1636
e41d82f5
RH
1637 update_parameter_components ();
1638
95a8c155 1639 /* ??? Ideally we'd traverse the blocks in breadth-first order. */
8b1c6fd7 1640 old_last_basic_block = last_basic_block_for_fn (cfun);
11cd3bed 1641 FOR_EACH_BB_FN (bb, cfun)
6de9cd9a
DN
1642 {
1643 if (bb->index >= old_last_basic_block)
1644 continue;
726a989a 1645
e41d82f5 1646 update_phi_components (bb);
726a989a
RB
1647 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1648 expand_complex_operations_1 (&gsi);
6de9cd9a 1649 }
6de9cd9a 1650
726a989a 1651 gsi_commit_edge_inserts ();
e41d82f5 1652
c203e8a7
TS
1653 delete complex_variable_components;
1654 complex_variable_components = NULL;
9771b263
DN
1655 complex_ssa_name_components.release ();
1656 complex_lattice_values.release ();
c2924966 1657 return 0;
e41d82f5 1658}
26277d41 1659
27a4cd48
DM
1660namespace {
1661
1662const pass_data pass_data_lower_complex =
26277d41 1663{
27a4cd48
DM
1664 GIMPLE_PASS, /* type */
1665 "cplxlower", /* name */
1666 OPTGROUP_NONE, /* optinfo_flags */
27a4cd48
DM
1667 true, /* has_execute */
1668 TV_NONE, /* tv_id */
1669 PROP_ssa, /* properties_required */
1670 PROP_gimple_lcx, /* properties_provided */
1671 0, /* properties_destroyed */
1672 0, /* todo_flags_start */
3bea341f 1673 TODO_update_ssa, /* todo_flags_finish */
e41d82f5
RH
1674};
1675
27a4cd48
DM
1676class pass_lower_complex : public gimple_opt_pass
1677{
1678public:
c3284718
RS
1679 pass_lower_complex (gcc::context *ctxt)
1680 : gimple_opt_pass (pass_data_lower_complex, ctxt)
27a4cd48
DM
1681 {}
1682
1683 /* opt_pass methods: */
65d3284b 1684 opt_pass * clone () { return new pass_lower_complex (m_ctxt); }
be55bfe6 1685 virtual unsigned int execute (function *) { return tree_lower_complex (); }
27a4cd48
DM
1686
1687}; // class pass_lower_complex
1688
1689} // anon namespace
1690
1691gimple_opt_pass *
1692make_pass_lower_complex (gcc::context *ctxt)
1693{
1694 return new pass_lower_complex (ctxt);
1695}
1696
e41d82f5 1697\f
27a4cd48
DM
1698namespace {
1699
1700const pass_data pass_data_lower_complex_O0 =
e41d82f5 1701{
27a4cd48
DM
1702 GIMPLE_PASS, /* type */
1703 "cplxlower0", /* name */
1704 OPTGROUP_NONE, /* optinfo_flags */
27a4cd48
DM
1705 true, /* has_execute */
1706 TV_NONE, /* tv_id */
1707 PROP_cfg, /* properties_required */
1708 PROP_gimple_lcx, /* properties_provided */
1709 0, /* properties_destroyed */
1710 0, /* todo_flags_start */
3bea341f 1711 TODO_update_ssa, /* todo_flags_finish */
6de9cd9a 1712};
27a4cd48
DM
1713
1714class pass_lower_complex_O0 : public gimple_opt_pass
1715{
1716public:
c3284718
RS
1717 pass_lower_complex_O0 (gcc::context *ctxt)
1718 : gimple_opt_pass (pass_data_lower_complex_O0, ctxt)
27a4cd48
DM
1719 {}
1720
1721 /* opt_pass methods: */
1a3d085c
TS
1722 virtual bool gate (function *fun)
1723 {
1724 /* With errors, normal optimization passes are not run. If we don't
1725 lower complex operations at all, rtl expansion will abort. */
1726 return !(fun->curr_properties & PROP_gimple_lcx);
1727 }
1728
be55bfe6 1729 virtual unsigned int execute (function *) { return tree_lower_complex (); }
27a4cd48
DM
1730
1731}; // class pass_lower_complex_O0
1732
1733} // anon namespace
1734
1735gimple_opt_pass *
1736make_pass_lower_complex_O0 (gcc::context *ctxt)
1737{
1738 return new pass_lower_complex_O0 (ctxt);
1739}
This page took 5.193793 seconds and 5 git commands to generate.