comparison gcc/tree-complex.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Lower complex number operations to scalar operations. 1 /* Lower complex number operations to scalar operations.
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 2 Copyright (C) 2004-2017 Free Software Foundation, Inc.
3 Free Software Foundation, Inc.
4 3
5 This file is part of GCC. 4 This file is part of GCC.
6 5
7 GCC is free software; you can redistribute it and/or modify it 6 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the 7 under the terms of the GNU General Public License as published by the
19 <http://www.gnu.org/licenses/>. */ 18 <http://www.gnu.org/licenses/>. */
20 19
21 #include "config.h" 20 #include "config.h"
22 #include "system.h" 21 #include "system.h"
23 #include "coretypes.h" 22 #include "coretypes.h"
24 #include "tm.h" 23 #include "backend.h"
24 #include "rtl.h"
25 #include "tree.h" 25 #include "tree.h"
26 #include "flags.h"
27 #include "tree-flow.h"
28 #include "gimple.h" 26 #include "gimple.h"
29 #include "tree-iterator.h" 27 #include "cfghooks.h"
30 #include "tree-pass.h" 28 #include "tree-pass.h"
29 #include "ssa.h"
30 #include "fold-const.h"
31 #include "stor-layout.h"
32 #include "tree-eh.h"
33 #include "gimplify.h"
34 #include "gimple-iterator.h"
35 #include "gimplify-me.h"
36 #include "tree-cfg.h"
37 #include "tree-dfa.h"
38 #include "tree-ssa.h"
31 #include "tree-ssa-propagate.h" 39 #include "tree-ssa-propagate.h"
40 #include "tree-hasher.h"
41 #include "cfgloop.h"
42 #include "cfganal.h"
32 43
33 44
34 /* For each complex ssa name, a lattice value. We're interested in finding 45 /* For each complex ssa name, a lattice value. We're interested in finding
35 out whether a complex number is degenerate in some way, having only real 46 out whether a complex number is degenerate in some way, having only real
36 or only complex parts. */ 47 or only complex parts. */
47 constants. */ 58 constants. */
48 typedef int complex_lattice_t; 59 typedef int complex_lattice_t;
49 60
50 #define PAIR(a, b) ((a) << 2 | (b)) 61 #define PAIR(a, b) ((a) << 2 | (b))
51 62
52 DEF_VEC_I(complex_lattice_t); 63
53 DEF_VEC_ALLOC_I(complex_lattice_t, heap); 64 static vec<complex_lattice_t> complex_lattice_values;
54
55 static VEC(complex_lattice_t, heap) *complex_lattice_values;
56 65
57 /* For each complex variable, a pair of variables for the components exists in 66 /* For each complex variable, a pair of variables for the components exists in
58 the hashtable. */ 67 the hashtable. */
59 static htab_t complex_variable_components; 68 static int_tree_htab_type *complex_variable_components;
60 69
61 /* For each complex SSA_NAME, a pair of ssa names for the components. */ 70 /* For each complex SSA_NAME, a pair of ssa names for the components. */
62 static VEC(tree, heap) *complex_ssa_name_components; 71 static vec<tree> complex_ssa_name_components;
72
73 /* Vector of PHI triplets (original complex PHI and corresponding real and
74 imag PHIs if real and/or imag PHIs contain temporarily
75 non-SSA_NAME/non-invariant args that need to be replaced by SSA_NAMEs. */
76 static vec<gphi *> phis_to_revisit;
63 77
64 /* Lookup UID in the complex_variable_components hashtable and return the 78 /* Lookup UID in the complex_variable_components hashtable and return the
65 associated tree. */ 79 associated tree. */
66 static tree 80 static tree
67 cvc_lookup (unsigned int uid) 81 cvc_lookup (unsigned int uid)
68 { 82 {
69 struct int_tree_map *h, in; 83 struct int_tree_map in;
70 in.uid = uid; 84 in.uid = uid;
71 h = (struct int_tree_map *) htab_find_with_hash (complex_variable_components, &in, uid); 85 return complex_variable_components->find_with_hash (in, uid).to;
72 return h ? h->to : NULL;
73 } 86 }
74 87
75 /* Insert the pair UID, TO into the complex_variable_components hashtable. */ 88 /* Insert the pair UID, TO into the complex_variable_components hashtable. */
76 89
77 static void 90 static void
78 cvc_insert (unsigned int uid, tree to) 91 cvc_insert (unsigned int uid, tree to)
79 { 92 {
80 struct int_tree_map *h; 93 int_tree_map h;
81 void **loc; 94 int_tree_map *loc;
82 95
83 h = XNEW (struct int_tree_map); 96 h.uid = uid;
84 h->uid = uid; 97 loc = complex_variable_components->find_slot_with_hash (h, uid, INSERT);
85 h->to = to; 98 loc->uid = uid;
86 loc = htab_find_slot_with_hash (complex_variable_components, h, 99 loc->to = to;
87 uid, INSERT);
88 *(struct int_tree_map **) loc = h;
89 } 100 }
90 101
91 /* Return true if T is not a zero constant. In the case of real values, 102 /* Return true if T is not a zero constant. In the case of real values,
92 we're only interested in +0.0. */ 103 we're only interested in +0.0. */
93 104
98 109
99 /* Operations with real or imaginary part of a complex number zero 110 /* Operations with real or imaginary part of a complex number zero
100 cannot be treated the same as operations with a real or imaginary 111 cannot be treated the same as operations with a real or imaginary
101 operand if we care about the signs of zeros in the result. */ 112 operand if we care about the signs of zeros in the result. */
102 if (TREE_CODE (t) == REAL_CST && !flag_signed_zeros) 113 if (TREE_CODE (t) == REAL_CST && !flag_signed_zeros)
103 zerop = REAL_VALUES_IDENTICAL (TREE_REAL_CST (t), dconst0); 114 zerop = real_identical (&TREE_REAL_CST (t), &dconst0);
104 else if (TREE_CODE (t) == FIXED_CST) 115 else if (TREE_CODE (t) == FIXED_CST)
105 zerop = fixed_zerop (t); 116 zerop = fixed_zerop (t);
106 else if (TREE_CODE (t) == INTEGER_CST) 117 else if (TREE_CODE (t) == INTEGER_CST)
107 zerop = integer_zerop (t); 118 zerop = integer_zerop (t);
108 119
141 tree real, imag; 152 tree real, imag;
142 153
143 switch (TREE_CODE (t)) 154 switch (TREE_CODE (t))
144 { 155 {
145 case SSA_NAME: 156 case SSA_NAME:
146 return VEC_index (complex_lattice_t, complex_lattice_values, 157 return complex_lattice_values[SSA_NAME_VERSION (t)];
147 SSA_NAME_VERSION (t));
148 158
149 case COMPLEX_CST: 159 case COMPLEX_CST:
150 real = TREE_REALPART (t); 160 real = TREE_REALPART (t);
151 imag = TREE_IMAGPART (t); 161 imag = TREE_IMAGPART (t);
152 break; 162 break;
174 { 184 {
175 tree parm, ssa_name; 185 tree parm, ssa_name;
176 186
177 for (parm = DECL_ARGUMENTS (cfun->decl); parm ; parm = DECL_CHAIN (parm)) 187 for (parm = DECL_ARGUMENTS (cfun->decl); parm ; parm = DECL_CHAIN (parm))
178 if (is_complex_reg (parm) 188 if (is_complex_reg (parm)
179 && var_ann (parm) != NULL 189 && (ssa_name = ssa_default_def (cfun, parm)) != NULL_TREE)
180 && (ssa_name = gimple_default_def (cfun, parm)) != NULL_TREE) 190 complex_lattice_values[SSA_NAME_VERSION (ssa_name)] = VARYING;
181 VEC_replace (complex_lattice_t, complex_lattice_values,
182 SSA_NAME_VERSION (ssa_name), VARYING);
183 } 191 }
184 192
185 /* Initialize simulation state for each statement. Return false if we 193 /* Initialize simulation state for each statement. Return false if we
186 found no statements we want to simulate, and thus there's nothing 194 found no statements we want to simulate, and thus there's nothing
187 for the entire pass to do. */ 195 for the entire pass to do. */
188 196
189 static bool 197 static bool
190 init_dont_simulate_again (void) 198 init_dont_simulate_again (void)
191 { 199 {
192 basic_block bb; 200 basic_block bb;
193 gimple_stmt_iterator gsi;
194 gimple phi;
195 bool saw_a_complex_op = false; 201 bool saw_a_complex_op = false;
196 202
197 FOR_EACH_BB (bb) 203 FOR_EACH_BB_FN (bb, cfun)
198 { 204 {
199 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) 205 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
206 gsi_next (&gsi))
200 { 207 {
201 phi = gsi_stmt (gsi); 208 gphi *phi = gsi.phi ();
202 prop_set_simulate_again (phi, 209 prop_set_simulate_again (phi,
203 is_complex_reg (gimple_phi_result (phi))); 210 is_complex_reg (gimple_phi_result (phi)));
204 } 211 }
205 212
206 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) 213 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
214 gsi_next (&gsi))
207 { 215 {
208 gimple stmt; 216 gimple *stmt;
209 tree op0, op1; 217 tree op0, op1;
210 bool sim_again_p; 218 bool sim_again_p;
211 219
212 stmt = gsi_stmt (gsi); 220 stmt = gsi_stmt (gsi);
213 op0 = op1 = NULL_TREE; 221 op0 = op1 = NULL_TREE;
291 299
292 300
293 /* Evaluate statement STMT against the complex lattice defined above. */ 301 /* Evaluate statement STMT against the complex lattice defined above. */
294 302
295 static enum ssa_prop_result 303 static enum ssa_prop_result
296 complex_visit_stmt (gimple stmt, edge *taken_edge_p ATTRIBUTE_UNUSED, 304 complex_visit_stmt (gimple *stmt, edge *taken_edge_p ATTRIBUTE_UNUSED,
297 tree *result_p) 305 tree *result_p)
298 { 306 {
299 complex_lattice_t new_l, old_l, op1_l, op2_l; 307 complex_lattice_t new_l, old_l, op1_l, op2_l;
300 unsigned int ver; 308 unsigned int ver;
301 tree lhs; 309 tree lhs;
310 gcc_assert (TREE_CODE (lhs) == SSA_NAME); 318 gcc_assert (TREE_CODE (lhs) == SSA_NAME);
311 gcc_assert (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE); 319 gcc_assert (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE);
312 320
313 *result_p = lhs; 321 *result_p = lhs;
314 ver = SSA_NAME_VERSION (lhs); 322 ver = SSA_NAME_VERSION (lhs);
315 old_l = VEC_index (complex_lattice_t, complex_lattice_values, ver); 323 old_l = complex_lattice_values[ver];
316 324
317 switch (gimple_expr_code (stmt)) 325 switch (gimple_expr_code (stmt))
318 { 326 {
319 case SSA_NAME: 327 case SSA_NAME:
320 case COMPLEX_CST: 328 case COMPLEX_CST:
379 387
380 /* If nothing changed this round, let the propagator know. */ 388 /* If nothing changed this round, let the propagator know. */
381 if (new_l == old_l) 389 if (new_l == old_l)
382 return SSA_PROP_NOT_INTERESTING; 390 return SSA_PROP_NOT_INTERESTING;
383 391
384 VEC_replace (complex_lattice_t, complex_lattice_values, ver, new_l); 392 complex_lattice_values[ver] = new_l;
385 return new_l == VARYING ? SSA_PROP_VARYING : SSA_PROP_INTERESTING; 393 return new_l == VARYING ? SSA_PROP_VARYING : SSA_PROP_INTERESTING;
386 } 394 }
387 395
388 /* Evaluate a PHI node against the complex lattice defined above. */ 396 /* Evaluate a PHI node against the complex lattice defined above. */
389 397
390 static enum ssa_prop_result 398 static enum ssa_prop_result
391 complex_visit_phi (gimple phi) 399 complex_visit_phi (gphi *phi)
392 { 400 {
393 complex_lattice_t new_l, old_l; 401 complex_lattice_t new_l, old_l;
394 unsigned int ver; 402 unsigned int ver;
395 tree lhs; 403 tree lhs;
396 int i; 404 int i;
405 new_l = UNINITIALIZED; 413 new_l = UNINITIALIZED;
406 for (i = gimple_phi_num_args (phi) - 1; i >= 0; --i) 414 for (i = gimple_phi_num_args (phi) - 1; i >= 0; --i)
407 new_l |= find_lattice_value (gimple_phi_arg_def (phi, i)); 415 new_l |= find_lattice_value (gimple_phi_arg_def (phi, i));
408 416
409 ver = SSA_NAME_VERSION (lhs); 417 ver = SSA_NAME_VERSION (lhs);
410 old_l = VEC_index (complex_lattice_t, complex_lattice_values, ver); 418 old_l = complex_lattice_values[ver];
411 419
412 if (new_l == old_l) 420 if (new_l == old_l)
413 return SSA_PROP_NOT_INTERESTING; 421 return SSA_PROP_NOT_INTERESTING;
414 422
415 VEC_replace (complex_lattice_t, complex_lattice_values, ver, new_l); 423 complex_lattice_values[ver] = new_l;
416 return new_l == VARYING ? SSA_PROP_VARYING : SSA_PROP_INTERESTING; 424 return new_l == VARYING ? SSA_PROP_VARYING : SSA_PROP_INTERESTING;
417 } 425 }
418 426
419 /* Create one backing variable for a complex component of ORIG. */ 427 /* Create one backing variable for a complex component of ORIG. */
420 428
421 static tree 429 static tree
422 create_one_component_var (tree type, tree orig, const char *prefix, 430 create_one_component_var (tree type, tree orig, const char *prefix,
423 const char *suffix, enum tree_code code) 431 const char *suffix, enum tree_code code)
424 { 432 {
425 tree r = create_tmp_var (type, prefix); 433 tree r = create_tmp_var (type, prefix);
426 add_referenced_var (r);
427 434
428 DECL_SOURCE_LOCATION (r) = DECL_SOURCE_LOCATION (orig); 435 DECL_SOURCE_LOCATION (r) = DECL_SOURCE_LOCATION (orig);
429 DECL_ARTIFICIAL (r) = 1; 436 DECL_ARTIFICIAL (r) = 1;
430 437
431 if (DECL_NAME (orig) && !DECL_IGNORED_P (orig)) 438 if (DECL_NAME (orig) && !DECL_IGNORED_P (orig))
432 { 439 {
433 const char *name = IDENTIFIER_POINTER (DECL_NAME (orig)); 440 const char *name = IDENTIFIER_POINTER (DECL_NAME (orig));
434 441 name = ACONCAT ((name, suffix, NULL));
435 DECL_NAME (r) = get_identifier (ACONCAT ((name, suffix, NULL))); 442 DECL_NAME (r) = get_identifier (name);
436 443
437 SET_DECL_DEBUG_EXPR (r, build1 (code, type, orig)); 444 SET_DECL_DEBUG_EXPR (r, build1 (code, type, orig));
438 DECL_DEBUG_EXPR_IS_FROM (r) = 1; 445 DECL_HAS_DEBUG_EXPR_P (r) = 1;
439 DECL_IGNORED_P (r) = 0; 446 DECL_IGNORED_P (r) = 0;
440 TREE_NO_WARNING (r) = TREE_NO_WARNING (orig); 447 TREE_NO_WARNING (r) = TREE_NO_WARNING (orig);
441 } 448 }
442 else 449 else
443 { 450 {
485 else 492 else
486 return build_int_cst (inner_type, 0); 493 return build_int_cst (inner_type, 0);
487 } 494 }
488 495
489 ssa_name_index = SSA_NAME_VERSION (ssa_name) * 2 + imag_p; 496 ssa_name_index = SSA_NAME_VERSION (ssa_name) * 2 + imag_p;
490 ret = VEC_index (tree, complex_ssa_name_components, ssa_name_index); 497 ret = complex_ssa_name_components[ssa_name_index];
491 if (ret == NULL) 498 if (ret == NULL)
492 { 499 {
493 ret = get_component_var (SSA_NAME_VAR (ssa_name), imag_p); 500 if (SSA_NAME_VAR (ssa_name))
494 ret = make_ssa_name (ret, NULL); 501 ret = get_component_var (SSA_NAME_VAR (ssa_name), imag_p);
502 else
503 ret = TREE_TYPE (TREE_TYPE (ssa_name));
504 ret = make_ssa_name (ret);
495 505
496 /* Copy some properties from the original. In particular, whether it 506 /* Copy some properties from the original. In particular, whether it
497 is used in an abnormal phi, and whether it's uninitialized. */ 507 is used in an abnormal phi, and whether it's uninitialized. */
498 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ret) 508 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ret)
499 = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name); 509 = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name);
500 if (TREE_CODE (SSA_NAME_VAR (ssa_name)) == VAR_DECL 510 if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
501 && gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name))) 511 && TREE_CODE (SSA_NAME_VAR (ssa_name)) == VAR_DECL)
502 { 512 {
503 SSA_NAME_DEF_STMT (ret) = SSA_NAME_DEF_STMT (ssa_name); 513 SSA_NAME_DEF_STMT (ret) = SSA_NAME_DEF_STMT (ssa_name);
504 set_default_def (SSA_NAME_VAR (ret), ret); 514 set_ssa_default_def (cfun, SSA_NAME_VAR (ret), ret);
505 } 515 }
506 516
507 VEC_replace (tree, complex_ssa_name_components, ssa_name_index, ret); 517 complex_ssa_name_components[ssa_name_index] = ret;
508 } 518 }
509 519
510 return ret; 520 return ret;
511 } 521 }
512 522
517 set_component_ssa_name (tree ssa_name, bool imag_p, tree value) 527 set_component_ssa_name (tree ssa_name, bool imag_p, tree value)
518 { 528 {
519 complex_lattice_t lattice = find_lattice_value (ssa_name); 529 complex_lattice_t lattice = find_lattice_value (ssa_name);
520 size_t ssa_name_index; 530 size_t ssa_name_index;
521 tree comp; 531 tree comp;
522 gimple last; 532 gimple *last;
523 gimple_seq list; 533 gimple_seq list;
524 534
525 /* We know the value must be zero, else there's a bug in our lattice 535 /* We know the value must be zero, else there's a bug in our lattice
526 analysis. But the value may well be a variable known to contain 536 analysis. But the value may well be a variable known to contain
527 zero. We should be safe ignoring it. */ 537 zero. We should be safe ignoring it. */
531 /* If we've already assigned an SSA_NAME to this component, then this 541 /* If we've already assigned an SSA_NAME to this component, then this
532 means that our walk of the basic blocks found a use before the set. 542 means that our walk of the basic blocks found a use before the set.
533 This is fine. Now we should create an initialization for the value 543 This is fine. Now we should create an initialization for the value
534 we created earlier. */ 544 we created earlier. */
535 ssa_name_index = SSA_NAME_VERSION (ssa_name) * 2 + imag_p; 545 ssa_name_index = SSA_NAME_VERSION (ssa_name) * 2 + imag_p;
536 comp = VEC_index (tree, complex_ssa_name_components, ssa_name_index); 546 comp = complex_ssa_name_components[ssa_name_index];
537 if (comp) 547 if (comp)
538 ; 548 ;
539 549
540 /* If we've nothing assigned, and the value we're given is already stable, 550 /* If we've nothing assigned, and the value we're given is already stable,
541 then install that as the value for this SSA_NAME. This preemptively 551 then install that as the value for this SSA_NAME. This preemptively
542 copy-propagates the value, which avoids unnecessary memory allocation. */ 552 copy-propagates the value, which avoids unnecessary memory allocation. */
543 else if (is_gimple_min_invariant (value) 553 else if (is_gimple_min_invariant (value)
544 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name)) 554 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
545 { 555 {
546 VEC_replace (tree, complex_ssa_name_components, ssa_name_index, value); 556 complex_ssa_name_components[ssa_name_index] = value;
547 return NULL; 557 return NULL;
548 } 558 }
549 else if (TREE_CODE (value) == SSA_NAME 559 else if (TREE_CODE (value) == SSA_NAME
550 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name)) 560 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
551 { 561 {
552 /* Replace an anonymous base value with the variable from cvc_lookup. 562 /* Replace an anonymous base value with the variable from cvc_lookup.
553 This should result in better debug info. */ 563 This should result in better debug info. */
554 if (DECL_IGNORED_P (SSA_NAME_VAR (value)) 564 if (SSA_NAME_VAR (ssa_name)
565 && (!SSA_NAME_VAR (value) || DECL_IGNORED_P (SSA_NAME_VAR (value)))
555 && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name))) 566 && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name)))
556 { 567 {
557 comp = get_component_var (SSA_NAME_VAR (ssa_name), imag_p); 568 comp = get_component_var (SSA_NAME_VAR (ssa_name), imag_p);
558 replace_ssa_name_symbol (value, comp); 569 replace_ssa_name_symbol (value, comp);
559 } 570 }
560 571
561 VEC_replace (tree, complex_ssa_name_components, ssa_name_index, value); 572 complex_ssa_name_components[ssa_name_index] = value;
562 return NULL; 573 return NULL;
563 } 574 }
564 575
565 /* Finally, we need to stabilize the result by installing the value into 576 /* Finally, we need to stabilize the result by installing the value into
566 a new ssa name. */ 577 a new ssa name. */
581 Make sure that it's a proper gimple_val and gimplify it if not. 592 Make sure that it's a proper gimple_val and gimplify it if not.
582 Emit any new code before gsi. */ 593 Emit any new code before gsi. */
583 594
584 static tree 595 static tree
585 extract_component (gimple_stmt_iterator *gsi, tree t, bool imagpart_p, 596 extract_component (gimple_stmt_iterator *gsi, tree t, bool imagpart_p,
586 bool gimple_p) 597 bool gimple_p, bool phiarg_p = false)
587 { 598 {
588 switch (TREE_CODE (t)) 599 switch (TREE_CODE (t))
589 { 600 {
590 case COMPLEX_CST: 601 case COMPLEX_CST:
591 return imagpart_p ? TREE_IMAGPART (t) : TREE_REALPART (t); 602 return imagpart_p ? TREE_IMAGPART (t) : TREE_REALPART (t);
592 603
593 case COMPLEX_EXPR: 604 case COMPLEX_EXPR:
594 gcc_unreachable (); 605 gcc_unreachable ();
606
607 case BIT_FIELD_REF:
608 {
609 tree inner_type = TREE_TYPE (TREE_TYPE (t));
610 t = unshare_expr (t);
611 TREE_TYPE (t) = inner_type;
612 TREE_OPERAND (t, 1) = TYPE_SIZE (inner_type);
613 if (imagpart_p)
614 TREE_OPERAND (t, 2) = size_binop (PLUS_EXPR, TREE_OPERAND (t, 2),
615 TYPE_SIZE (inner_type));
616 if (gimple_p)
617 t = force_gimple_operand_gsi (gsi, t, true, NULL, true,
618 GSI_SAME_STMT);
619 return t;
620 }
595 621
596 case VAR_DECL: 622 case VAR_DECL:
597 case RESULT_DECL: 623 case RESULT_DECL:
598 case PARM_DECL: 624 case PARM_DECL:
599 case COMPONENT_REF: 625 case COMPONENT_REF:
612 638
613 return t; 639 return t;
614 } 640 }
615 641
616 case SSA_NAME: 642 case SSA_NAME:
617 return get_component_ssa_name (t, imagpart_p); 643 t = get_component_ssa_name (t, imagpart_p);
644 if (TREE_CODE (t) == SSA_NAME && SSA_NAME_DEF_STMT (t) == NULL)
645 gcc_assert (phiarg_p);
646 return t;
618 647
619 default: 648 default:
620 gcc_unreachable (); 649 gcc_unreachable ();
621 } 650 }
622 } 651 }
623 652
624 /* Update the complex components of the ssa name on the lhs of STMT. */ 653 /* Update the complex components of the ssa name on the lhs of STMT. */
625 654
626 static void 655 static void
627 update_complex_components (gimple_stmt_iterator *gsi, gimple stmt, tree r, 656 update_complex_components (gimple_stmt_iterator *gsi, gimple *stmt, tree r,
628 tree i) 657 tree i)
629 { 658 {
630 tree lhs; 659 tree lhs;
631 gimple_seq list; 660 gimple_seq list;
632 661
659 /* Update an assignment to a complex variable in place. */ 688 /* Update an assignment to a complex variable in place. */
660 689
661 static void 690 static void
662 update_complex_assignment (gimple_stmt_iterator *gsi, tree r, tree i) 691 update_complex_assignment (gimple_stmt_iterator *gsi, tree r, tree i)
663 { 692 {
664 gimple_stmt_iterator orig_si = *gsi; 693 gimple *stmt;
665 gimple stmt; 694
666 695 gimple_assign_set_rhs_with_ops (gsi, COMPLEX_EXPR, r, i);
667 if (gimple_in_ssa_p (cfun)) 696 stmt = gsi_stmt (*gsi);
668 update_complex_components (gsi, gsi_stmt (*gsi), r, i);
669
670 gimple_assign_set_rhs_with_ops (&orig_si, COMPLEX_EXPR, r, i);
671 stmt = gsi_stmt (orig_si);
672 update_stmt (stmt); 697 update_stmt (stmt);
673 if (maybe_clean_eh_stmt (stmt)) 698 if (maybe_clean_eh_stmt (stmt))
674 gimple_purge_dead_eh_edges (gimple_bb (stmt)); 699 gimple_purge_dead_eh_edges (gimple_bb (stmt));
700
701 if (gimple_in_ssa_p (cfun))
702 update_complex_components (gsi, gsi_stmt (*gsi), r, i);
675 } 703 }
676 704
677 705
678 /* Generate code at the entry point of the function to initialize the 706 /* Generate code at the entry point of the function to initialize the
679 component variables for a complex parameter. */ 707 component variables for a complex parameter. */
680 708
681 static void 709 static void
682 update_parameter_components (void) 710 update_parameter_components (void)
683 { 711 {
684 edge entry_edge = single_succ_edge (ENTRY_BLOCK_PTR); 712 edge entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
685 tree parm; 713 tree parm;
686 714
687 for (parm = DECL_ARGUMENTS (cfun->decl); parm ; parm = DECL_CHAIN (parm)) 715 for (parm = DECL_ARGUMENTS (cfun->decl); parm ; parm = DECL_CHAIN (parm))
688 { 716 {
689 tree type = TREE_TYPE (parm); 717 tree type = TREE_TYPE (parm);
691 719
692 if (TREE_CODE (type) != COMPLEX_TYPE || !is_gimple_reg (parm)) 720 if (TREE_CODE (type) != COMPLEX_TYPE || !is_gimple_reg (parm))
693 continue; 721 continue;
694 722
695 type = TREE_TYPE (type); 723 type = TREE_TYPE (type);
696 ssa_name = gimple_default_def (cfun, parm); 724 ssa_name = ssa_default_def (cfun, parm);
697 if (!ssa_name) 725 if (!ssa_name)
698 continue; 726 continue;
699 727
700 r = build1 (REALPART_EXPR, type, ssa_name); 728 r = build1 (REALPART_EXPR, type, ssa_name);
701 i = build1 (IMAGPART_EXPR, type, ssa_name); 729 i = build1 (IMAGPART_EXPR, type, ssa_name);
707 to match the PHI statements in block BB. */ 735 to match the PHI statements in block BB. */
708 736
709 static void 737 static void
710 update_phi_components (basic_block bb) 738 update_phi_components (basic_block bb)
711 { 739 {
712 gimple_stmt_iterator gsi; 740 gphi_iterator gsi;
713 741
714 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) 742 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
715 { 743 {
716 gimple phi = gsi_stmt (gsi); 744 gphi *phi = gsi.phi ();
717 745
718 if (is_complex_reg (gimple_phi_result (phi))) 746 if (is_complex_reg (gimple_phi_result (phi)))
719 { 747 {
720 tree lr, li; 748 gphi *p[2] = { NULL, NULL };
721 gimple pr = NULL, pi = NULL; 749 unsigned int i, j, n;
722 unsigned int i, n; 750 bool revisit_phi = false;
723 751
724 lr = get_component_ssa_name (gimple_phi_result (phi), false); 752 for (j = 0; j < 2; j++)
725 if (TREE_CODE (lr) == SSA_NAME)
726 { 753 {
727 pr = create_phi_node (lr, bb); 754 tree l = get_component_ssa_name (gimple_phi_result (phi), j > 0);
728 SSA_NAME_DEF_STMT (lr) = pr; 755 if (TREE_CODE (l) == SSA_NAME)
729 } 756 p[j] = create_phi_node (l, bb);
730
731 li = get_component_ssa_name (gimple_phi_result (phi), true);
732 if (TREE_CODE (li) == SSA_NAME)
733 {
734 pi = create_phi_node (li, bb);
735 SSA_NAME_DEF_STMT (li) = pi;
736 } 757 }
737 758
738 for (i = 0, n = gimple_phi_num_args (phi); i < n; ++i) 759 for (i = 0, n = gimple_phi_num_args (phi); i < n; ++i)
739 { 760 {
740 tree comp, arg = gimple_phi_arg_def (phi, i); 761 tree comp, arg = gimple_phi_arg_def (phi, i);
741 if (pr) 762 for (j = 0; j < 2; j++)
742 { 763 if (p[j])
743 comp = extract_component (NULL, arg, false, false); 764 {
744 SET_PHI_ARG_DEF (pr, i, comp); 765 comp = extract_component (NULL, arg, j > 0, false, true);
745 } 766 if (TREE_CODE (comp) == SSA_NAME
746 if (pi) 767 && SSA_NAME_DEF_STMT (comp) == NULL)
747 { 768 {
748 comp = extract_component (NULL, arg, true, false); 769 /* For the benefit of any gimple simplification during
749 SET_PHI_ARG_DEF (pi, i, comp); 770 this pass that might walk SSA_NAME def stmts,
750 } 771 don't add SSA_NAMEs without definitions into the
772 PHI arguments, but put a decl in there instead
773 temporarily, and revisit this PHI later on. */
774 if (SSA_NAME_VAR (comp))
775 comp = SSA_NAME_VAR (comp);
776 else
777 comp = create_tmp_reg (TREE_TYPE (comp),
778 get_name (comp));
779 revisit_phi = true;
780 }
781 SET_PHI_ARG_DEF (p[j], i, comp);
782 }
783 }
784
785 if (revisit_phi)
786 {
787 phis_to_revisit.safe_push (phi);
788 phis_to_revisit.safe_push (p[0]);
789 phis_to_revisit.safe_push (p[1]);
751 } 790 }
752 } 791 }
753 } 792 }
754 } 793 }
755 794
758 static void 797 static void
759 expand_complex_move (gimple_stmt_iterator *gsi, tree type) 798 expand_complex_move (gimple_stmt_iterator *gsi, tree type)
760 { 799 {
761 tree inner_type = TREE_TYPE (type); 800 tree inner_type = TREE_TYPE (type);
762 tree r, i, lhs, rhs; 801 tree r, i, lhs, rhs;
763 gimple stmt = gsi_stmt (*gsi); 802 gimple *stmt = gsi_stmt (*gsi);
764 803
765 if (is_gimple_assign (stmt)) 804 if (is_gimple_assign (stmt))
766 { 805 {
767 lhs = gimple_assign_lhs (stmt); 806 lhs = gimple_assign_lhs (stmt);
768 if (gimple_num_ops (stmt) == 2) 807 if (gimple_num_ops (stmt) == 2)
819 } 858 }
820 } 859 }
821 else if (rhs && TREE_CODE (rhs) == SSA_NAME && !TREE_SIDE_EFFECTS (lhs)) 860 else if (rhs && TREE_CODE (rhs) == SSA_NAME && !TREE_SIDE_EFFECTS (lhs))
822 { 861 {
823 tree x; 862 tree x;
824 gimple t; 863 gimple *t;
825 864 location_t loc;
865
866 loc = gimple_location (stmt);
826 r = extract_component (gsi, rhs, 0, false); 867 r = extract_component (gsi, rhs, 0, false);
827 i = extract_component (gsi, rhs, 1, false); 868 i = extract_component (gsi, rhs, 1, false);
828 869
829 x = build1 (REALPART_EXPR, inner_type, unshare_expr (lhs)); 870 x = build1 (REALPART_EXPR, inner_type, unshare_expr (lhs));
830 t = gimple_build_assign (x, r); 871 t = gimple_build_assign (x, r);
872 gimple_set_location (t, loc);
831 gsi_insert_before (gsi, t, GSI_SAME_STMT); 873 gsi_insert_before (gsi, t, GSI_SAME_STMT);
832 874
833 if (stmt == gsi_stmt (*gsi)) 875 if (stmt == gsi_stmt (*gsi))
834 { 876 {
835 x = build1 (IMAGPART_EXPR, inner_type, unshare_expr (lhs)); 877 x = build1 (IMAGPART_EXPR, inner_type, unshare_expr (lhs));
838 } 880 }
839 else 881 else
840 { 882 {
841 x = build1 (IMAGPART_EXPR, inner_type, unshare_expr (lhs)); 883 x = build1 (IMAGPART_EXPR, inner_type, unshare_expr (lhs));
842 t = gimple_build_assign (x, i); 884 t = gimple_build_assign (x, i);
885 gimple_set_location (t, loc);
843 gsi_insert_before (gsi, t, GSI_SAME_STMT); 886 gsi_insert_before (gsi, t, GSI_SAME_STMT);
844 887
845 stmt = gsi_stmt (*gsi); 888 stmt = gsi_stmt (*gsi);
846 gcc_assert (gimple_code (stmt) == GIMPLE_RETURN); 889 gcc_assert (gimple_code (stmt) == GIMPLE_RETURN);
847 gimple_return_set_retval (stmt, lhs); 890 gimple_return_set_retval (as_a <greturn *> (stmt), lhs);
848 } 891 }
849 892
850 update_stmt (stmt); 893 update_stmt (stmt);
851 } 894 }
852 } 895 }
934 977
935 static void 978 static void
936 expand_complex_libcall (gimple_stmt_iterator *gsi, tree ar, tree ai, 979 expand_complex_libcall (gimple_stmt_iterator *gsi, tree ar, tree ai,
937 tree br, tree bi, enum tree_code code) 980 tree br, tree bi, enum tree_code code)
938 { 981 {
939 enum machine_mode mode; 982 machine_mode mode;
940 enum built_in_function bcode; 983 enum built_in_function bcode;
941 tree fn, type, lhs; 984 tree fn, type, lhs;
942 gimple old_stmt, stmt; 985 gimple *old_stmt;
986 gcall *stmt;
943 987
944 old_stmt = gsi_stmt (*gsi); 988 old_stmt = gsi_stmt (*gsi);
945 lhs = gimple_assign_lhs (old_stmt); 989 lhs = gimple_assign_lhs (old_stmt);
946 type = TREE_TYPE (lhs); 990 type = TREE_TYPE (lhs);
947 991
954 else if (code == RDIV_EXPR) 998 else if (code == RDIV_EXPR)
955 bcode = ((enum built_in_function) 999 bcode = ((enum built_in_function)
956 (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT)); 1000 (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
957 else 1001 else
958 gcc_unreachable (); 1002 gcc_unreachable ();
959 fn = built_in_decls[bcode]; 1003 fn = builtin_decl_explicit (bcode);
960 1004
961 stmt = gimple_build_call (fn, 4, ar, ai, br, bi); 1005 stmt = gimple_build_call (fn, 4, ar, ai, br, bi);
962 gimple_call_set_lhs (stmt, lhs); 1006 gimple_call_set_lhs (stmt, lhs);
963 update_stmt (stmt); 1007 update_stmt (stmt);
964 gsi_replace (gsi, stmt, false); 1008 gsi_replace (gsi, stmt, false);
1003 break; 1047 break;
1004 1048
1005 case PAIR (ONLY_IMAG, ONLY_REAL): 1049 case PAIR (ONLY_IMAG, ONLY_REAL):
1006 rr = ar; 1050 rr = ar;
1007 if (TREE_CODE (ai) == REAL_CST 1051 if (TREE_CODE (ai) == REAL_CST
1008 && REAL_VALUES_IDENTICAL (TREE_REAL_CST (ai), dconst1)) 1052 && real_identical (&TREE_REAL_CST (ai), &dconst1))
1009 ri = br; 1053 ri = br;
1010 else 1054 else
1011 ri = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, br); 1055 ri = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, br);
1012 break; 1056 break;
1013 1057
1102 tree ar, tree ai, tree br, tree bi, 1146 tree ar, tree ai, tree br, tree bi,
1103 enum tree_code code) 1147 enum tree_code code)
1104 { 1148 {
1105 tree rr, ri, ratio, div, t1, t2, tr, ti, compare; 1149 tree rr, ri, ratio, div, t1, t2, tr, ti, compare;
1106 basic_block bb_cond, bb_true, bb_false, bb_join; 1150 basic_block bb_cond, bb_true, bb_false, bb_join;
1107 gimple stmt; 1151 gimple *stmt;
1108 1152
1109 /* Examine |br| < |bi|, and branch. */ 1153 /* Examine |br| < |bi|, and branch. */
1110 t1 = gimplify_build1 (gsi, ABS_EXPR, inner_type, br); 1154 t1 = gimplify_build1 (gsi, ABS_EXPR, inner_type, br);
1111 t2 = gimplify_build1 (gsi, ABS_EXPR, inner_type, bi); 1155 t2 = gimplify_build1 (gsi, ABS_EXPR, inner_type, bi);
1112 compare = fold_build2_loc (gimple_location (gsi_stmt (*gsi)), 1156 compare = fold_build2_loc (gimple_location (gsi_stmt (*gsi)),
1116 bb_cond = bb_true = bb_false = bb_join = NULL; 1160 bb_cond = bb_true = bb_false = bb_join = NULL;
1117 rr = ri = tr = ti = NULL; 1161 rr = ri = tr = ti = NULL;
1118 if (TREE_CODE (compare) != INTEGER_CST) 1162 if (TREE_CODE (compare) != INTEGER_CST)
1119 { 1163 {
1120 edge e; 1164 edge e;
1121 gimple stmt; 1165 gimple *stmt;
1122 tree cond, tmp; 1166 tree cond, tmp;
1123 1167
1124 tmp = create_tmp_var (boolean_type_node, NULL); 1168 tmp = create_tmp_var (boolean_type_node);
1125 stmt = gimple_build_assign (tmp, compare); 1169 stmt = gimple_build_assign (tmp, compare);
1126 if (gimple_in_ssa_p (cfun)) 1170 if (gimple_in_ssa_p (cfun))
1127 { 1171 {
1128 tmp = make_ssa_name (tmp, stmt); 1172 tmp = make_ssa_name (tmp, stmt);
1129 gimple_assign_set_lhs (stmt, tmp); 1173 gimple_assign_set_lhs (stmt, tmp);
1130 } 1174 }
1131 1175
1132 gsi_insert_before (gsi, stmt, GSI_SAME_STMT); 1176 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
1133 1177
1140 e = split_block (gsi_bb (*gsi), stmt); 1184 e = split_block (gsi_bb (*gsi), stmt);
1141 bb_cond = e->src; 1185 bb_cond = e->src;
1142 bb_join = e->dest; 1186 bb_join = e->dest;
1143 bb_true = create_empty_bb (bb_cond); 1187 bb_true = create_empty_bb (bb_cond);
1144 bb_false = create_empty_bb (bb_true); 1188 bb_false = create_empty_bb (bb_true);
1189 bb_true->frequency = bb_false->frequency = bb_cond->frequency / 2;
1190 bb_true->count = bb_false->count
1191 = bb_cond->count.apply_probability (profile_probability::even ());
1145 1192
1146 /* Wire the blocks together. */ 1193 /* Wire the blocks together. */
1147 e->flags = EDGE_TRUE_VALUE; 1194 e->flags = EDGE_TRUE_VALUE;
1195 /* TODO: With value profile we could add an historgram to determine real
1196 branch outcome. */
1197 e->probability = profile_probability::even ();
1148 redirect_edge_succ (e, bb_true); 1198 redirect_edge_succ (e, bb_true);
1149 make_edge (bb_cond, bb_false, EDGE_FALSE_VALUE); 1199 edge e2 = make_edge (bb_cond, bb_false, EDGE_FALSE_VALUE);
1150 make_edge (bb_true, bb_join, EDGE_FALLTHRU); 1200 e2->probability = profile_probability::even ();
1151 make_edge (bb_false, bb_join, EDGE_FALLTHRU); 1201 make_single_succ_edge (bb_true, bb_join, EDGE_FALLTHRU);
1202 make_single_succ_edge (bb_false, bb_join, EDGE_FALLTHRU);
1203 add_bb_to_loop (bb_true, bb_cond->loop_father);
1204 add_bb_to_loop (bb_false, bb_cond->loop_father);
1152 1205
1153 /* Update dominance info. Note that bb_join's data was 1206 /* Update dominance info. Note that bb_join's data was
1154 updated by split_block. */ 1207 updated by split_block. */
1155 if (dom_info_available_p (CDI_DOMINATORS)) 1208 if (dom_info_available_p (CDI_DOMINATORS))
1156 { 1209 {
1157 set_immediate_dominator (CDI_DOMINATORS, bb_true, bb_cond); 1210 set_immediate_dominator (CDI_DOMINATORS, bb_true, bb_cond);
1158 set_immediate_dominator (CDI_DOMINATORS, bb_false, bb_cond); 1211 set_immediate_dominator (CDI_DOMINATORS, bb_false, bb_cond);
1159 } 1212 }
1160 1213
1161 rr = make_rename_temp (inner_type, NULL); 1214 rr = create_tmp_reg (inner_type);
1162 ri = make_rename_temp (inner_type, NULL); 1215 ri = create_tmp_reg (inner_type);
1163 } 1216 }
1164 1217
1165 /* In the TRUE branch, we compute 1218 /* In the TRUE branch, we compute
1166 ratio = br/bi; 1219 ratio = br/bi;
1167 div = (br * ratio) + bi; 1220 div = (br * ratio) + bi;
1288 1341
1289 case PAIR (VARYING, ONLY_IMAG): 1342 case PAIR (VARYING, ONLY_IMAG):
1290 rr = gimplify_build2 (gsi, code, inner_type, ai, bi); 1343 rr = gimplify_build2 (gsi, code, inner_type, ai, bi);
1291 ri = gimplify_build2 (gsi, code, inner_type, ar, bi); 1344 ri = gimplify_build2 (gsi, code, inner_type, ar, bi);
1292 ri = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ri); 1345 ri = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ri);
1346 break;
1293 1347
1294 case PAIR (ONLY_REAL, VARYING): 1348 case PAIR (ONLY_REAL, VARYING):
1295 case PAIR (ONLY_IMAG, VARYING): 1349 case PAIR (ONLY_IMAG, VARYING):
1296 case PAIR (VARYING, VARYING): 1350 case PAIR (VARYING, VARYING):
1297 switch (flag_complex_method) 1351 switch (flag_complex_method)
1362 static void 1416 static void
1363 expand_complex_comparison (gimple_stmt_iterator *gsi, tree ar, tree ai, 1417 expand_complex_comparison (gimple_stmt_iterator *gsi, tree ar, tree ai,
1364 tree br, tree bi, enum tree_code code) 1418 tree br, tree bi, enum tree_code code)
1365 { 1419 {
1366 tree cr, ci, cc, type; 1420 tree cr, ci, cc, type;
1367 gimple stmt; 1421 gimple *stmt;
1368 1422
1369 cr = gimplify_build2 (gsi, code, boolean_type_node, ar, br); 1423 cr = gimplify_build2 (gsi, code, boolean_type_node, ar, br);
1370 ci = gimplify_build2 (gsi, code, boolean_type_node, ai, bi); 1424 ci = gimplify_build2 (gsi, code, boolean_type_node, ai, bi);
1371 cc = gimplify_build2 (gsi, 1425 cc = gimplify_build2 (gsi,
1372 (code == EQ_EXPR ? TRUTH_AND_EXPR : TRUTH_OR_EXPR), 1426 (code == EQ_EXPR ? TRUTH_AND_EXPR : TRUTH_OR_EXPR),
1375 stmt = gsi_stmt (*gsi); 1429 stmt = gsi_stmt (*gsi);
1376 1430
1377 switch (gimple_code (stmt)) 1431 switch (gimple_code (stmt))
1378 { 1432 {
1379 case GIMPLE_RETURN: 1433 case GIMPLE_RETURN:
1380 type = TREE_TYPE (gimple_return_retval (stmt)); 1434 {
1381 gimple_return_set_retval (stmt, fold_convert (type, cc)); 1435 greturn *return_stmt = as_a <greturn *> (stmt);
1436 type = TREE_TYPE (gimple_return_retval (return_stmt));
1437 gimple_return_set_retval (return_stmt, fold_convert (type, cc));
1438 }
1382 break; 1439 break;
1383 1440
1384 case GIMPLE_ASSIGN: 1441 case GIMPLE_ASSIGN:
1385 type = TREE_TYPE (gimple_assign_lhs (stmt)); 1442 type = TREE_TYPE (gimple_assign_lhs (stmt));
1386 gimple_assign_set_rhs_from_tree (gsi, fold_convert (type, cc)); 1443 gimple_assign_set_rhs_from_tree (gsi, fold_convert (type, cc));
1387 stmt = gsi_stmt (*gsi); 1444 stmt = gsi_stmt (*gsi);
1388 break; 1445 break;
1389 1446
1390 case GIMPLE_COND: 1447 case GIMPLE_COND:
1391 gimple_cond_set_code (stmt, EQ_EXPR); 1448 {
1392 gimple_cond_set_lhs (stmt, cc); 1449 gcond *cond_stmt = as_a <gcond *> (stmt);
1393 gimple_cond_set_rhs (stmt, boolean_true_node); 1450 gimple_cond_set_code (cond_stmt, EQ_EXPR);
1451 gimple_cond_set_lhs (cond_stmt, cc);
1452 gimple_cond_set_rhs (cond_stmt, boolean_true_node);
1453 }
1394 break; 1454 break;
1395 1455
1396 default: 1456 default:
1397 gcc_unreachable (); 1457 gcc_unreachable ();
1398 } 1458 }
1399 1459
1400 update_stmt (stmt); 1460 update_stmt (stmt);
1401 } 1461 }
1402 1462
1463 /* Expand inline asm that sets some complex SSA_NAMEs. */
1464
1465 static void
1466 expand_complex_asm (gimple_stmt_iterator *gsi)
1467 {
1468 gasm *stmt = as_a <gasm *> (gsi_stmt (*gsi));
1469 unsigned int i;
1470
1471 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
1472 {
1473 tree link = gimple_asm_output_op (stmt, i);
1474 tree op = TREE_VALUE (link);
1475 if (TREE_CODE (op) == SSA_NAME
1476 && TREE_CODE (TREE_TYPE (op)) == COMPLEX_TYPE)
1477 {
1478 tree type = TREE_TYPE (op);
1479 tree inner_type = TREE_TYPE (type);
1480 tree r = build1 (REALPART_EXPR, inner_type, op);
1481 tree i = build1 (IMAGPART_EXPR, inner_type, op);
1482 gimple_seq list = set_component_ssa_name (op, false, r);
1483
1484 if (list)
1485 gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
1486
1487 list = set_component_ssa_name (op, true, i);
1488 if (list)
1489 gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
1490 }
1491 }
1492 }
1403 1493
1404 /* Process one statement. If we identify a complex operation, expand it. */ 1494 /* Process one statement. If we identify a complex operation, expand it. */
1405 1495
1406 static void 1496 static void
1407 expand_complex_operations_1 (gimple_stmt_iterator *gsi) 1497 expand_complex_operations_1 (gimple_stmt_iterator *gsi)
1408 { 1498 {
1409 gimple stmt = gsi_stmt (*gsi); 1499 gimple *stmt = gsi_stmt (*gsi);
1410 tree type, inner_type, lhs; 1500 tree type, inner_type, lhs;
1411 tree ac, ar, ai, bc, br, bi; 1501 tree ac, ar, ai, bc, br, bi;
1412 complex_lattice_t al, bl; 1502 complex_lattice_t al, bl;
1413 enum tree_code code; 1503 enum tree_code code;
1504
1505 if (gimple_code (stmt) == GIMPLE_ASM)
1506 {
1507 expand_complex_asm (gsi);
1508 return;
1509 }
1414 1510
1415 lhs = gimple_get_lhs (stmt); 1511 lhs = gimple_get_lhs (stmt);
1416 if (!lhs && gimple_code (stmt) != GIMPLE_COND) 1512 if (!lhs && gimple_code (stmt) != GIMPLE_COND)
1417 return; 1513 return;
1418 1514
1438 break; 1534 break;
1439 1535
1440 case EQ_EXPR: 1536 case EQ_EXPR:
1441 case NE_EXPR: 1537 case NE_EXPR:
1442 /* Note, both GIMPLE_ASSIGN and GIMPLE_COND may have an EQ_EXPR 1538 /* Note, both GIMPLE_ASSIGN and GIMPLE_COND may have an EQ_EXPR
1443 subocde, so we need to access the operands using gimple_op. */ 1539 subcode, so we need to access the operands using gimple_op. */
1444 inner_type = TREE_TYPE (gimple_op (stmt, 1)); 1540 inner_type = TREE_TYPE (gimple_op (stmt, 1));
1445 if (TREE_CODE (inner_type) != COMPLEX_TYPE) 1541 if (TREE_CODE (inner_type) != COMPLEX_TYPE)
1446 return; 1542 return;
1447 break; 1543 break;
1448 1544
1563 /* Entry point for complex operation lowering during optimization. */ 1659 /* Entry point for complex operation lowering during optimization. */
1564 1660
1565 static unsigned int 1661 static unsigned int
1566 tree_lower_complex (void) 1662 tree_lower_complex (void)
1567 { 1663 {
1568 int old_last_basic_block;
1569 gimple_stmt_iterator gsi; 1664 gimple_stmt_iterator gsi;
1570 basic_block bb; 1665 basic_block bb;
1666 int n_bbs, i;
1667 int *rpo;
1571 1668
1572 if (!init_dont_simulate_again ()) 1669 if (!init_dont_simulate_again ())
1573 return 0; 1670 return 0;
1574 1671
1575 complex_lattice_values = VEC_alloc (complex_lattice_t, heap, num_ssa_names); 1672 complex_lattice_values.create (num_ssa_names);
1576 VEC_safe_grow_cleared (complex_lattice_t, heap, 1673 complex_lattice_values.safe_grow_cleared (num_ssa_names);
1577 complex_lattice_values, num_ssa_names);
1578 1674
1579 init_parameter_lattice_values (); 1675 init_parameter_lattice_values ();
1580 ssa_propagate (complex_visit_stmt, complex_visit_phi); 1676 ssa_propagate (complex_visit_stmt, complex_visit_phi);
1581 1677
1582 complex_variable_components = htab_create (10, int_tree_map_hash, 1678 complex_variable_components = new int_tree_htab_type (10);
1583 int_tree_map_eq, free); 1679
1584 1680 complex_ssa_name_components.create (2 * num_ssa_names);
1585 complex_ssa_name_components = VEC_alloc (tree, heap, 2*num_ssa_names); 1681 complex_ssa_name_components.safe_grow_cleared (2 * num_ssa_names);
1586 VEC_safe_grow_cleared (tree, heap, complex_ssa_name_components,
1587 2 * num_ssa_names);
1588 1682
1589 update_parameter_components (); 1683 update_parameter_components ();
1590 1684
1591 /* ??? Ideally we'd traverse the blocks in breadth-first order. */ 1685 rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
1592 old_last_basic_block = last_basic_block; 1686 n_bbs = pre_and_rev_post_order_compute (NULL, rpo, false);
1593 FOR_EACH_BB (bb) 1687 for (i = 0; i < n_bbs; i++)
1594 { 1688 {
1595 if (bb->index >= old_last_basic_block) 1689 bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
1596 continue;
1597
1598 update_phi_components (bb); 1690 update_phi_components (bb);
1599 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) 1691 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1600 expand_complex_operations_1 (&gsi); 1692 expand_complex_operations_1 (&gsi);
1601 } 1693 }
1602 1694
1695 free (rpo);
1696
1697 if (!phis_to_revisit.is_empty ())
1698 {
1699 unsigned int n = phis_to_revisit.length ();
1700 for (unsigned int j = 0; j < n; j += 3)
1701 for (unsigned int k = 0; k < 2; k++)
1702 if (gphi *phi = phis_to_revisit[j + k + 1])
1703 {
1704 unsigned int m = gimple_phi_num_args (phi);
1705 for (unsigned int l = 0; l < m; ++l)
1706 {
1707 tree op = gimple_phi_arg_def (phi, l);
1708 if (TREE_CODE (op) == SSA_NAME
1709 || is_gimple_min_invariant (op))
1710 continue;
1711 tree arg = gimple_phi_arg_def (phis_to_revisit[j], l);
1712 op = extract_component (NULL, arg, k > 0, false, false);
1713 SET_PHI_ARG_DEF (phi, l, op);
1714 }
1715 }
1716 phis_to_revisit.release ();
1717 }
1718
1603 gsi_commit_edge_inserts (); 1719 gsi_commit_edge_inserts ();
1604 1720
1605 htab_delete (complex_variable_components); 1721 delete complex_variable_components;
1606 VEC_free (tree, heap, complex_ssa_name_components); 1722 complex_variable_components = NULL;
1607 VEC_free (complex_lattice_t, heap, complex_lattice_values); 1723 complex_ssa_name_components.release ();
1724 complex_lattice_values.release ();
1608 return 0; 1725 return 0;
1609 } 1726 }
1610 1727
1611 struct gimple_opt_pass pass_lower_complex = 1728 namespace {
1612 { 1729
1613 { 1730 const pass_data pass_data_lower_complex =
1614 GIMPLE_PASS, 1731 {
1615 "cplxlower", /* name */ 1732 GIMPLE_PASS, /* type */
1616 0, /* gate */ 1733 "cplxlower", /* name */
1617 tree_lower_complex, /* execute */ 1734 OPTGROUP_NONE, /* optinfo_flags */
1618 NULL, /* sub */ 1735 TV_NONE, /* tv_id */
1619 NULL, /* next */ 1736 PROP_ssa, /* properties_required */
1620 0, /* static_pass_number */ 1737 PROP_gimple_lcx, /* properties_provided */
1621 TV_NONE, /* tv_id */ 1738 0, /* properties_destroyed */
1622 PROP_ssa, /* properties_required */ 1739 0, /* todo_flags_start */
1623 PROP_gimple_lcx, /* properties_provided */ 1740 TODO_update_ssa, /* todo_flags_finish */
1624 0, /* properties_destroyed */
1625 0, /* todo_flags_start */
1626 TODO_dump_func
1627 | TODO_ggc_collect
1628 | TODO_update_ssa
1629 | TODO_verify_stmts /* todo_flags_finish */
1630 }
1631 }; 1741 };
1632 1742
1743 class pass_lower_complex : public gimple_opt_pass
1744 {
1745 public:
1746 pass_lower_complex (gcc::context *ctxt)
1747 : gimple_opt_pass (pass_data_lower_complex, ctxt)
1748 {}
1749
1750 /* opt_pass methods: */
1751 opt_pass * clone () { return new pass_lower_complex (m_ctxt); }
1752 virtual unsigned int execute (function *) { return tree_lower_complex (); }
1753
1754 }; // class pass_lower_complex
1755
1756 } // anon namespace
1757
1758 gimple_opt_pass *
1759 make_pass_lower_complex (gcc::context *ctxt)
1760 {
1761 return new pass_lower_complex (ctxt);
1762 }
1763
1633 1764
1634 static bool 1765 namespace {
1635 gate_no_optimization (void) 1766
1636 { 1767 const pass_data pass_data_lower_complex_O0 =
1637 /* With errors, normal optimization passes are not run. If we don't 1768 {
1638 lower complex operations at all, rtl expansion will abort. */ 1769 GIMPLE_PASS, /* type */
1639 return !(cfun->curr_properties & PROP_gimple_lcx); 1770 "cplxlower0", /* name */
1640 } 1771 OPTGROUP_NONE, /* optinfo_flags */
1641 1772 TV_NONE, /* tv_id */
1642 struct gimple_opt_pass pass_lower_complex_O0 = 1773 PROP_cfg, /* properties_required */
1643 { 1774 PROP_gimple_lcx, /* properties_provided */
1644 { 1775 0, /* properties_destroyed */
1645 GIMPLE_PASS, 1776 0, /* todo_flags_start */
1646 "cplxlower0", /* name */ 1777 TODO_update_ssa, /* todo_flags_finish */
1647 gate_no_optimization, /* gate */
1648 tree_lower_complex, /* execute */
1649 NULL, /* sub */
1650 NULL, /* next */
1651 0, /* static_pass_number */
1652 TV_NONE, /* tv_id */
1653 PROP_cfg, /* properties_required */
1654 PROP_gimple_lcx, /* properties_provided */
1655 0, /* properties_destroyed */
1656 0, /* todo_flags_start */
1657 TODO_dump_func
1658 | TODO_ggc_collect
1659 | TODO_update_ssa
1660 | TODO_verify_stmts /* todo_flags_finish */
1661 }
1662 }; 1778 };
1779
1780 class pass_lower_complex_O0 : public gimple_opt_pass
1781 {
1782 public:
1783 pass_lower_complex_O0 (gcc::context *ctxt)
1784 : gimple_opt_pass (pass_data_lower_complex_O0, ctxt)
1785 {}
1786
1787 /* opt_pass methods: */
1788 virtual bool gate (function *fun)
1789 {
1790 /* With errors, normal optimization passes are not run. If we don't
1791 lower complex operations at all, rtl expansion will abort. */
1792 return !(fun->curr_properties & PROP_gimple_lcx);
1793 }
1794
1795 virtual unsigned int execute (function *) { return tree_lower_complex (); }
1796
1797 }; // class pass_lower_complex_O0
1798
1799 } // anon namespace
1800
1801 gimple_opt_pass *
1802 make_pass_lower_complex_O0 (gcc::context *ctxt)
1803 {
1804 return new pass_lower_complex_O0 (ctxt);
1805 }