00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "config.h"
00023 #include "system.h"
00024 #include "coretypes.h"
00025 #include "tm.h"
00026 #include "tree.h"
00027 #include "flags.h"
00028 #include "basic-block.h"
00029 #include "function.h"
00030 #include "diagnostic.h"
00031 #include "bitmap.h"
00032 #include "tree-flow.h"
00033 #include "tree-gimple.h"
00034 #include "tree-inline.h"
00035 #include "varray.h"
00036 #include "timevar.h"
00037 #include "hashtab.h"
00038 #include "tree-dump.h"
00039 #include "tree-ssa-live.h"
00040 #include "toplev.h"
00041 #include "vecprim.h"
00042
00043 static void live_worklist (tree_live_info_p, int *, int);
00044 static tree_live_info_p new_tree_live_info (var_map);
00045 static inline void set_if_valid (var_map, bitmap, tree);
00046 static inline void add_livein_if_notdef (tree_live_info_p, bitmap,
00047 tree, basic_block);
00048 static inline void register_ssa_partition (var_map, tree, bool);
00049 static inline void add_conflicts_if_valid (tpa_p, conflict_graph,
00050 var_map, bitmap, tree);
00051 static partition_pair_p find_partition_pair (coalesce_list_p, int, int, bool);
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 var_map
00068 init_var_map (int size)
00069 {
00070 var_map map;
00071
00072 map = (var_map) xmalloc (sizeof (struct _var_map));
00073 map->var_partition = partition_new (size);
00074 map->partition_to_var
00075 = (tree *)xmalloc (size * sizeof (tree));
00076 memset (map->partition_to_var, 0, size * sizeof (tree));
00077
00078 map->partition_to_compact = NULL;
00079 map->compact_to_partition = NULL;
00080 map->num_partitions = size;
00081 map->partition_size = size;
00082 map->ref_count = NULL;
00083 return map;
00084 }
00085
00086
00087
00088
00089 void
00090 delete_var_map (var_map map)
00091 {
00092 free (map->partition_to_var);
00093 partition_delete (map->var_partition);
00094 if (map->partition_to_compact)
00095 free (map->partition_to_compact);
00096 if (map->compact_to_partition)
00097 free (map->compact_to_partition);
00098 if (map->ref_count)
00099 free (map->ref_count);
00100 free (map);
00101 }
00102
00103
00104
00105
00106
00107
00108 int
00109 var_union (var_map map, tree var1, tree var2)
00110 {
00111 int p1, p2, p3;
00112 tree root_var = NULL_TREE;
00113 tree other_var = NULL_TREE;
00114
00115
00116
00117
00118
00119 if (TREE_CODE (var1) == SSA_NAME)
00120 p1 = partition_find (map->var_partition, SSA_NAME_VERSION (var1));
00121 else
00122 {
00123 p1 = var_to_partition (map, var1);
00124 if (map->compact_to_partition)
00125 p1 = map->compact_to_partition[p1];
00126 root_var = var1;
00127 }
00128
00129 if (TREE_CODE (var2) == SSA_NAME)
00130 p2 = partition_find (map->var_partition, SSA_NAME_VERSION (var2));
00131 else
00132 {
00133 p2 = var_to_partition (map, var2);
00134 if (map->compact_to_partition)
00135 p2 = map->compact_to_partition[p2];
00136
00137
00138
00139 if (!root_var || (DECL_P (root_var) && DECL_IGNORED_P (root_var)))
00140 {
00141 other_var = root_var;
00142 root_var = var2;
00143 }
00144 else
00145 other_var = var2;
00146 }
00147
00148 gcc_assert (p1 != NO_PARTITION);
00149 gcc_assert (p2 != NO_PARTITION);
00150
00151 if (p1 == p2)
00152 p3 = p1;
00153 else
00154 p3 = partition_union (map->var_partition, p1, p2);
00155
00156 if (map->partition_to_compact)
00157 p3 = map->partition_to_compact[p3];
00158
00159 if (root_var)
00160 change_partition_var (map, root_var, p3);
00161 if (other_var)
00162 change_partition_var (map, other_var, p3);
00163
00164 return p3;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 void
00186 compact_var_map (var_map map, int flags)
00187 {
00188 sbitmap used;
00189 int tmp, root, root_i;
00190 unsigned int x, limit, count;
00191 tree var;
00192 root_var_p rv = NULL;
00193
00194 limit = map->partition_size;
00195 used = sbitmap_alloc (limit);
00196 sbitmap_zero (used);
00197
00198
00199 if (map->partition_to_compact)
00200 {
00201 free (map->partition_to_compact);
00202 map->partition_to_compact = NULL;
00203 }
00204 if (map->compact_to_partition)
00205 {
00206 free (map->compact_to_partition);
00207 map->compact_to_partition = NULL;
00208 }
00209
00210 map->num_partitions = map->partition_size;
00211
00212 if (flags & VARMAP_NO_SINGLE_DEFS)
00213 rv = root_var_init (map);
00214
00215 map->partition_to_compact = (int *)xmalloc (limit * sizeof (int));
00216 memset (map->partition_to_compact, 0xff, (limit * sizeof (int)));
00217
00218
00219 count = 0;
00220 for (x = 0; x < limit; x++)
00221 {
00222 tmp = partition_find (map->var_partition, x);
00223 if (!TEST_BIT (used, tmp) && map->partition_to_var[tmp] != NULL_TREE)
00224 {
00225
00226
00227 if (rv)
00228 {
00229 root = root_var_find (rv, tmp);
00230 root_i = root_var_first_partition (rv, root);
00231
00232 if (root_var_next_partition (rv, root_i) == ROOT_VAR_NONE)
00233 continue;
00234 }
00235 SET_BIT (used, tmp);
00236 count++;
00237 }
00238 }
00239
00240
00241 if (count != limit)
00242 {
00243 sbitmap_iterator sbi;
00244
00245 map->compact_to_partition = (int *)xmalloc (count * sizeof (int));
00246 count = 0;
00247
00248 EXECUTE_IF_SET_IN_SBITMAP (used, 1, x, sbi)
00249 {
00250 map->partition_to_compact[x] = count;
00251 map->compact_to_partition[count] = x;
00252 var = map->partition_to_var[x];
00253 if (TREE_CODE (var) != SSA_NAME)
00254 change_partition_var (map, var, count);
00255 count++;
00256 }
00257 }
00258 else
00259 {
00260 free (map->partition_to_compact);
00261 map->partition_to_compact = NULL;
00262 }
00263
00264 map->num_partitions = count;
00265
00266 if (rv)
00267 root_var_delete (rv);
00268 sbitmap_free (used);
00269 }
00270
00271
00272
00273
00274
00275
00276 void
00277 change_partition_var (var_map map, tree var, int part)
00278 {
00279 var_ann_t ann;
00280
00281 gcc_assert (TREE_CODE (var) != SSA_NAME);
00282
00283 ann = var_ann (var);
00284 ann->out_of_ssa_tag = 1;
00285 VAR_ANN_PARTITION (ann) = part;
00286 if (map->compact_to_partition)
00287 map->partition_to_var[map->compact_to_partition[part]] = var;
00288 }
00289
00290 static inline void mark_all_vars_used (tree *);
00291
00292
00293
00294 static tree
00295 mark_all_vars_used_1 (tree *tp, int *walk_subtrees,
00296 void *data ATTRIBUTE_UNUSED)
00297 {
00298 tree t = *tp;
00299
00300 if (TREE_CODE (t) == SSA_NAME)
00301 t = SSA_NAME_VAR (t);
00302
00303
00304
00305 if (TREE_CODE (t) == TARGET_MEM_REF)
00306 {
00307 mark_all_vars_used (&TMR_SYMBOL (t));
00308 mark_all_vars_used (&TMR_BASE (t));
00309 mark_all_vars_used (&TMR_INDEX (t));
00310 *walk_subtrees = 0;
00311 return NULL;
00312 }
00313
00314
00315
00316 if (TREE_CODE (t) == VAR_DECL)
00317 set_is_used (t);
00318
00319 if (IS_TYPE_OR_DECL_P (t))
00320 *walk_subtrees = 0;
00321
00322 return NULL;
00323 }
00324
00325
00326
00327
00328 static inline void
00329 mark_all_vars_used (tree *expr_p)
00330 {
00331 walk_tree (expr_p, mark_all_vars_used_1, NULL, NULL);
00332 }
00333
00334
00335
00336
00337 void
00338 remove_unused_locals (void)
00339 {
00340 basic_block bb;
00341 tree t, *cell;
00342
00343
00344 for (t = cfun->unexpanded_var_list; t; t = TREE_CHAIN (t))
00345 {
00346 tree var = TREE_VALUE (t);
00347 if (TREE_CODE (var) != FUNCTION_DECL
00348 && var_ann (var))
00349 var_ann (var)->used = false;
00350 }
00351
00352
00353 FOR_EACH_BB (bb)
00354 {
00355 block_stmt_iterator bsi;
00356 tree phi, def;
00357
00358
00359 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
00360 mark_all_vars_used (bsi_stmt_ptr (bsi));
00361
00362 for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
00363 {
00364 use_operand_p arg_p;
00365 ssa_op_iter i;
00366
00367
00368 if (is_global_var (SSA_NAME_VAR (PHI_RESULT (phi))))
00369 continue;
00370
00371 def = PHI_RESULT (phi);
00372 mark_all_vars_used (&def);
00373
00374 FOR_EACH_PHI_ARG (arg_p, phi, i, SSA_OP_ALL_USES)
00375 {
00376 tree arg = USE_FROM_PTR (arg_p);
00377 mark_all_vars_used (&arg);
00378 }
00379 }
00380 }
00381
00382
00383 for (cell = &cfun->unexpanded_var_list; *cell; )
00384 {
00385 tree var = TREE_VALUE (*cell);
00386 var_ann_t ann;
00387
00388 if (TREE_CODE (var) != FUNCTION_DECL
00389 && (!(ann = var_ann (var))
00390 || !ann->used))
00391 {
00392 *cell = TREE_CHAIN (*cell);
00393 continue;
00394 }
00395
00396 cell = &TREE_CHAIN (*cell);
00397 }
00398 }
00399
00400
00401
00402
00403
00404 var_map
00405 create_ssa_var_map (int flags)
00406 {
00407 block_stmt_iterator bsi;
00408 basic_block bb;
00409 tree dest, use;
00410 tree stmt;
00411 var_map map;
00412 ssa_op_iter iter;
00413 #ifdef ENABLE_CHECKING
00414 bitmap used_in_real_ops;
00415 bitmap used_in_virtual_ops;
00416 #endif
00417
00418 map = init_var_map (num_ssa_names + 1);
00419
00420 #ifdef ENABLE_CHECKING
00421 used_in_real_ops = BITMAP_ALLOC (NULL);
00422 used_in_virtual_ops = BITMAP_ALLOC (NULL);
00423 #endif
00424
00425 if (flags & SSA_VAR_MAP_REF_COUNT)
00426 {
00427 map->ref_count
00428 = (int *)xmalloc (((num_ssa_names + 1) * sizeof (int)));
00429 memset (map->ref_count, 0, (num_ssa_names + 1) * sizeof (int));
00430 }
00431
00432 FOR_EACH_BB (bb)
00433 {
00434 tree phi, arg;
00435
00436 for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
00437 {
00438 int i;
00439 register_ssa_partition (map, PHI_RESULT (phi), false);
00440 for (i = 0; i < PHI_NUM_ARGS (phi); i++)
00441 {
00442 arg = PHI_ARG_DEF (phi, i);
00443 if (TREE_CODE (arg) == SSA_NAME)
00444 register_ssa_partition (map, arg, true);
00445
00446 mark_all_vars_used (&PHI_ARG_DEF_TREE (phi, i));
00447 }
00448 }
00449
00450 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
00451 {
00452 stmt = bsi_stmt (bsi);
00453
00454
00455 FOR_EACH_SSA_TREE_OPERAND (use , stmt, iter, SSA_OP_USE)
00456 {
00457 register_ssa_partition (map, use, true);
00458
00459 #ifdef ENABLE_CHECKING
00460 bitmap_set_bit (used_in_real_ops, DECL_UID (SSA_NAME_VAR (use)));
00461 #endif
00462 }
00463
00464 FOR_EACH_SSA_TREE_OPERAND (dest, stmt, iter, SSA_OP_DEF)
00465 {
00466 register_ssa_partition (map, dest, false);
00467
00468 #ifdef ENABLE_CHECKING
00469 bitmap_set_bit (used_in_real_ops, DECL_UID (SSA_NAME_VAR (dest)));
00470 #endif
00471 }
00472
00473 #ifdef ENABLE_CHECKING
00474
00475 FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter,
00476 SSA_OP_VIRTUAL_USES | SSA_OP_VMUSTDEF)
00477 {
00478 bitmap_set_bit (used_in_virtual_ops,
00479 DECL_UID (SSA_NAME_VAR (use)));
00480 }
00481
00482 #endif
00483
00484 mark_all_vars_used (bsi_stmt_ptr (bsi));
00485 }
00486 }
00487
00488 #if defined ENABLE_CHECKING
00489 {
00490 unsigned i;
00491 bitmap both = BITMAP_ALLOC (NULL);
00492 bitmap_and (both, used_in_real_ops, used_in_virtual_ops);
00493 if (!bitmap_empty_p (both))
00494 {
00495 bitmap_iterator bi;
00496
00497 EXECUTE_IF_SET_IN_BITMAP (both, 0, i, bi)
00498 fprintf (stderr, "Variable %s used in real and virtual operands\n",
00499 get_name (referenced_var (i)));
00500 internal_error ("SSA corruption");
00501 }
00502
00503 BITMAP_FREE (used_in_real_ops);
00504 BITMAP_FREE (used_in_virtual_ops);
00505 BITMAP_FREE (both);
00506 }
00507 #endif
00508
00509 return map;
00510 }
00511
00512
00513
00514
00515 static tree_live_info_p
00516 new_tree_live_info (var_map map)
00517 {
00518 tree_live_info_p live;
00519 unsigned x;
00520
00521 live = (tree_live_info_p) xmalloc (sizeof (struct tree_live_info_d));
00522 live->map = map;
00523 live->num_blocks = last_basic_block;
00524
00525 live->global = BITMAP_ALLOC (NULL);
00526
00527 live->livein = (bitmap *)xmalloc (num_var_partitions (map) * sizeof (bitmap));
00528 for (x = 0; x < num_var_partitions (map); x++)
00529 live->livein[x] = BITMAP_ALLOC (NULL);
00530
00531
00532 live->liveout = NULL;
00533 return live;
00534 }
00535
00536
00537
00538
00539 void
00540 delete_tree_live_info (tree_live_info_p live)
00541 {
00542 int x;
00543 if (live->liveout)
00544 {
00545 for (x = live->num_blocks - 1; x >= 0; x--)
00546 BITMAP_FREE (live->liveout[x]);
00547 free (live->liveout);
00548 }
00549 if (live->livein)
00550 {
00551 for (x = num_var_partitions (live->map) - 1; x >= 0; x--)
00552 BITMAP_FREE (live->livein[x]);
00553 free (live->livein);
00554 }
00555 if (live->global)
00556 BITMAP_FREE (live->global);
00557
00558 free (live);
00559 }
00560
00561
00562
00563
00564
00565
00566 static void
00567 live_worklist (tree_live_info_p live, int *stack, int i)
00568 {
00569 unsigned b;
00570 tree var;
00571 basic_block def_bb = NULL;
00572 edge e;
00573 var_map map = live->map;
00574 edge_iterator ei;
00575 bitmap_iterator bi;
00576 int *tos = stack;
00577
00578 var = partition_to_var (map, i);
00579 if (SSA_NAME_DEF_STMT (var))
00580 def_bb = bb_for_stmt (SSA_NAME_DEF_STMT (var));
00581
00582 EXECUTE_IF_SET_IN_BITMAP (live->livein[i], 0, b, bi)
00583 {
00584 *tos++ = b;
00585 }
00586
00587 while (tos != stack)
00588 {
00589 b = *--tos;
00590
00591 FOR_EACH_EDGE (e, ei, BASIC_BLOCK (b)->preds)
00592 if (e->src != ENTRY_BLOCK_PTR)
00593 {
00594
00595 if (e->src == def_bb)
00596 continue;
00597 if (!bitmap_bit_p (live->livein[i], e->src->index))
00598 {
00599 bitmap_set_bit (live->livein[i], e->src->index);
00600 *tos++ = e->src->index;
00601 }
00602 }
00603 }
00604 }
00605
00606
00607
00608
00609 static inline void
00610 set_if_valid (var_map map, bitmap vec, tree var)
00611 {
00612 int p = var_to_partition (map, var);
00613 if (p != NO_PARTITION)
00614 bitmap_set_bit (vec, p);
00615 }
00616
00617
00618
00619
00620
00621 static inline void
00622 add_livein_if_notdef (tree_live_info_p live, bitmap def_vec,
00623 tree var, basic_block bb)
00624 {
00625 int p = var_to_partition (live->map, var);
00626 if (p == NO_PARTITION || bb == ENTRY_BLOCK_PTR)
00627 return;
00628 if (!bitmap_bit_p (def_vec, p))
00629 {
00630 bitmap_set_bit (live->livein[p], bb->index);
00631 bitmap_set_bit (live->global, p);
00632 }
00633 }
00634
00635
00636
00637
00638
00639 tree_live_info_p
00640 calculate_live_on_entry (var_map map)
00641 {
00642 tree_live_info_p live;
00643 unsigned i;
00644 basic_block bb;
00645 bitmap saw_def;
00646 tree phi, var, stmt;
00647 tree op;
00648 edge e;
00649 int *stack;
00650 block_stmt_iterator bsi;
00651 ssa_op_iter iter;
00652 bitmap_iterator bi;
00653 #ifdef ENABLE_CHECKING
00654 int num;
00655 edge_iterator ei;
00656 #endif
00657
00658 saw_def = BITMAP_ALLOC (NULL);
00659
00660 live = new_tree_live_info (map);
00661
00662 FOR_EACH_BB (bb)
00663 {
00664 bitmap_clear (saw_def);
00665
00666 for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
00667 {
00668 for (i = 0; i < (unsigned)PHI_NUM_ARGS (phi); i++)
00669 {
00670 var = PHI_ARG_DEF (phi, i);
00671 if (!phi_ssa_name_p (var))
00672 continue;
00673 stmt = SSA_NAME_DEF_STMT (var);
00674 e = EDGE_PRED (bb, i);
00675
00676
00677
00678
00679 if (!stmt || e->src != bb_for_stmt (stmt))
00680 add_livein_if_notdef (live, saw_def, var, e->src);
00681 }
00682 }
00683
00684
00685
00686
00687
00688
00689
00690
00691 for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
00692 {
00693 var = PHI_RESULT (phi);
00694 set_if_valid (map, saw_def, var);
00695 }
00696
00697 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
00698 {
00699 stmt = bsi_stmt (bsi);
00700
00701 FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
00702 {
00703 add_livein_if_notdef (live, saw_def, op, bb);
00704 }
00705
00706 FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_DEF)
00707 {
00708 set_if_valid (map, saw_def, op);
00709 }
00710 }
00711 }
00712
00713 stack = XNEWVEC (int, last_basic_block);
00714 EXECUTE_IF_SET_IN_BITMAP (live->global, 0, i, bi)
00715 {
00716 live_worklist (live, stack, i);
00717 }
00718 free (stack);
00719
00720 #ifdef ENABLE_CHECKING
00721
00722
00723
00724
00725 bb = ENTRY_BLOCK_PTR;
00726 num = 0;
00727 FOR_EACH_EDGE (e, ei, bb->succs)
00728 {
00729 int entry_block = e->dest->index;
00730 if (e->dest == EXIT_BLOCK_PTR)
00731 continue;
00732 for (i = 0; i < (unsigned)num_var_partitions (map); i++)
00733 {
00734 basic_block tmp;
00735 tree d;
00736 var = partition_to_var (map, i);
00737 stmt = SSA_NAME_DEF_STMT (var);
00738 tmp = bb_for_stmt (stmt);
00739 d = default_def (SSA_NAME_VAR (var));
00740
00741 if (bitmap_bit_p (live_entry_blocks (live, i), entry_block))
00742 {
00743 if (!IS_EMPTY_STMT (stmt))
00744 {
00745 num++;
00746 print_generic_expr (stderr, var, TDF_SLIM);
00747 fprintf (stderr, " is defined ");
00748 if (tmp)
00749 fprintf (stderr, " in BB%d, ", tmp->index);
00750 fprintf (stderr, "by:\n");
00751 print_generic_expr (stderr, stmt, TDF_SLIM);
00752 fprintf (stderr, "\nIt is also live-on-entry to entry BB %d",
00753 entry_block);
00754 fprintf (stderr, " So it appears to have multiple defs.\n");
00755 }
00756 else
00757 {
00758 if (d != var)
00759 {
00760 num++;
00761 print_generic_expr (stderr, var, TDF_SLIM);
00762 fprintf (stderr, " is live-on-entry to BB%d ",entry_block);
00763 if (d)
00764 {
00765 fprintf (stderr, " but is not the default def of ");
00766 print_generic_expr (stderr, d, TDF_SLIM);
00767 fprintf (stderr, "\n");
00768 }
00769 else
00770 fprintf (stderr, " and there is no default def.\n");
00771 }
00772 }
00773 }
00774 else
00775 if (d == var)
00776 {
00777
00778
00779 int z, ok = 0;
00780 for (phi = phi_nodes (e->dest);
00781 phi && !ok;
00782 phi = PHI_CHAIN (phi))
00783 {
00784 for (z = 0; z < PHI_NUM_ARGS (phi); z++)
00785 if (var == PHI_ARG_DEF (phi, z))
00786 {
00787 ok = 1;
00788 break;
00789 }
00790 }
00791 if (ok)
00792 continue;
00793 num++;
00794 print_generic_expr (stderr, var, TDF_SLIM);
00795 fprintf (stderr, " is not marked live-on-entry to entry BB%d ",
00796 entry_block);
00797 fprintf (stderr, "but it is a default def so it should be.\n");
00798 }
00799 }
00800 }
00801 gcc_assert (num <= 0);
00802 #endif
00803
00804 BITMAP_FREE (saw_def);
00805
00806 return live;
00807 }
00808
00809
00810
00811
00812 void
00813 calculate_live_on_exit (tree_live_info_p liveinfo)
00814 {
00815 unsigned b;
00816 unsigned i, x;
00817 bitmap *on_exit;
00818 basic_block bb;
00819 edge e;
00820 tree t, phi;
00821 bitmap on_entry;
00822 var_map map = liveinfo->map;
00823
00824 on_exit = (bitmap *)xmalloc (last_basic_block * sizeof (bitmap));
00825 for (x = 0; x < (unsigned)last_basic_block; x++)
00826 on_exit[x] = BITMAP_ALLOC (NULL);
00827
00828
00829 FOR_EACH_BB (bb)
00830 {
00831 for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
00832 for (i = 0; i < (unsigned)PHI_NUM_ARGS (phi); i++)
00833 {
00834 t = PHI_ARG_DEF (phi, i);
00835 e = PHI_ARG_EDGE (phi, i);
00836 if (!phi_ssa_name_p (t) || e->src == ENTRY_BLOCK_PTR)
00837 continue;
00838 set_if_valid (map, on_exit[e->src->index], t);
00839 }
00840 }
00841
00842
00843 for (i = 0; i < num_var_partitions (map); i++)
00844 {
00845 bitmap_iterator bi;
00846
00847 on_entry = live_entry_blocks (liveinfo, i);
00848 EXECUTE_IF_SET_IN_BITMAP (on_entry, 0, b, bi)
00849 {
00850 edge_iterator ei;
00851 FOR_EACH_EDGE (e, ei, BASIC_BLOCK (b)->preds)
00852 if (e->src != ENTRY_BLOCK_PTR)
00853 bitmap_set_bit (on_exit[e->src->index], i);
00854 }
00855 }
00856
00857 liveinfo->liveout = on_exit;
00858 }
00859
00860
00861
00862
00863 static tpa_p
00864 tpa_init (var_map map)
00865 {
00866 tpa_p tpa;
00867 int num_partitions = num_var_partitions (map);
00868 int x;
00869
00870 if (num_partitions == 0)
00871 return NULL;
00872
00873 tpa = (tpa_p) xmalloc (sizeof (struct tree_partition_associator_d));
00874 tpa->num_trees = 0;
00875 tpa->uncompressed_num = -1;
00876 tpa->map = map;
00877 tpa->next_partition = (int *)xmalloc (num_partitions * sizeof (int));
00878 memset (tpa->next_partition, TPA_NONE, num_partitions * sizeof (int));
00879
00880 tpa->partition_to_tree_map = (int *)xmalloc (num_partitions * sizeof (int));
00881 memset (tpa->partition_to_tree_map, TPA_NONE, num_partitions * sizeof (int));
00882
00883 x = MAX (40, (num_partitions / 20));
00884 tpa->trees = VEC_alloc (tree, heap, x);
00885 tpa->first_partition = VEC_alloc (int, heap, x);
00886
00887 return tpa;
00888
00889 }
00890
00891
00892
00893
00894 void
00895 tpa_remove_partition (tpa_p tpa, int tree_index, int partition_index)
00896 {
00897 int i;
00898
00899 i = tpa_first_partition (tpa, tree_index);
00900 if (i == partition_index)
00901 {
00902 VEC_replace (int, tpa->first_partition, tree_index,
00903 tpa->next_partition[i]);
00904 }
00905 else
00906 {
00907 for ( ; i != TPA_NONE; i = tpa_next_partition (tpa, i))
00908 {
00909 if (tpa->next_partition[i] == partition_index)
00910 {
00911 tpa->next_partition[i] = tpa->next_partition[partition_index];
00912 break;
00913 }
00914 }
00915 }
00916 }
00917
00918
00919
00920
00921 void
00922 tpa_delete (tpa_p tpa)
00923 {
00924 if (!tpa)
00925 return;
00926
00927 VEC_free (tree, heap, tpa->trees);
00928 VEC_free (int, heap, tpa->first_partition);
00929 free (tpa->partition_to_tree_map);
00930 free (tpa->next_partition);
00931 free (tpa);
00932 }
00933
00934
00935
00936
00937
00938
00939 int
00940 tpa_compact (tpa_p tpa)
00941 {
00942 int last, x, y, first, swap_i;
00943 tree swap_t;
00944
00945
00946 for (last = tpa->num_trees - 1; last > 0; last--)
00947 {
00948 first = tpa_first_partition (tpa, last);
00949 if (tpa_next_partition (tpa, first) != NO_PARTITION)
00950 break;
00951 }
00952
00953 x = 0;
00954 while (x < last)
00955 {
00956 first = tpa_first_partition (tpa, x);
00957
00958
00959
00960 if (tpa_next_partition (tpa, first) == NO_PARTITION)
00961 {
00962 swap_t = VEC_index (tree, tpa->trees, last);
00963 swap_i = VEC_index (int, tpa->first_partition, last);
00964
00965
00966
00967 VEC_replace (tree, tpa->trees, last,
00968 VEC_index (tree, tpa->trees, x));
00969 VEC_replace (int, tpa->first_partition, last,
00970 VEC_index (int, tpa->first_partition, x));
00971 tpa->partition_to_tree_map[tpa_first_partition (tpa, last)] = last;
00972
00973
00974
00975 VEC_replace (tree, tpa->trees, x, swap_t);
00976 VEC_replace (int, tpa->first_partition, x, swap_i);
00977 for (y = tpa_first_partition (tpa, x);
00978 y != NO_PARTITION;
00979 y = tpa_next_partition (tpa, y))
00980 tpa->partition_to_tree_map[y] = x;
00981
00982
00983 last--;
00984 for (; last > x; last--)
00985 {
00986 first = tpa_first_partition (tpa, last);
00987 if (tpa_next_partition (tpa, first) != NO_PARTITION)
00988 break;
00989 }
00990 }
00991 x++;
00992 }
00993
00994 first = tpa_first_partition (tpa, x);
00995 if (tpa_next_partition (tpa, first) != NO_PARTITION)
00996 x++;
00997 tpa->uncompressed_num = tpa->num_trees;
00998 tpa->num_trees = x;
00999 return last;
01000 }
01001
01002
01003
01004
01005
01006 root_var_p
01007 root_var_init (var_map map)
01008 {
01009 root_var_p rv;
01010 int num_partitions = num_var_partitions (map);
01011 int x, p;
01012 tree t;
01013 var_ann_t ann;
01014 sbitmap seen;
01015
01016 rv = tpa_init (map);
01017 if (!rv)
01018 return NULL;
01019
01020 seen = sbitmap_alloc (num_partitions);
01021 sbitmap_zero (seen);
01022
01023
01024
01025 for (x = num_partitions - 1; x >= 0; x--)
01026 {
01027 t = partition_to_var (map, x);
01028
01029
01030 if (!t)
01031 continue;
01032
01033 p = var_to_partition (map, t);
01034
01035 gcc_assert (p != NO_PARTITION);
01036
01037
01038 if (TEST_BIT (seen, p))
01039 continue;
01040 SET_BIT (seen, p);
01041 if (TREE_CODE (t) == SSA_NAME)
01042 t = SSA_NAME_VAR (t);
01043 ann = var_ann (t);
01044 if (ann->root_var_processed)
01045 {
01046 rv->next_partition[p] = VEC_index (int, rv->first_partition,
01047 VAR_ANN_ROOT_INDEX (ann));
01048 VEC_replace (int, rv->first_partition, VAR_ANN_ROOT_INDEX (ann), p);
01049 }
01050 else
01051 {
01052 ann->root_var_processed = 1;
01053 VAR_ANN_ROOT_INDEX (ann) = rv->num_trees++;
01054 VEC_safe_push (tree, heap, rv->trees, t);
01055 VEC_safe_push (int, heap, rv->first_partition, p);
01056 }
01057 rv->partition_to_tree_map[p] = VAR_ANN_ROOT_INDEX (ann);
01058 }
01059
01060
01061 for (x = 0; x < rv->num_trees; x++)
01062 {
01063 t = VEC_index (tree, rv->trees, x);
01064 var_ann (t)->root_var_processed = 0;
01065 }
01066
01067 sbitmap_free (seen);
01068 return rv;
01069 }
01070
01071
01072
01073
01074
01075 type_var_p
01076 type_var_init (var_map map)
01077 {
01078 type_var_p tv;
01079 int x, y, p;
01080 int num_partitions = num_var_partitions (map);
01081 tree t;
01082 sbitmap seen;
01083
01084 tv = tpa_init (map);
01085 if (!tv)
01086 return NULL;
01087
01088 seen = sbitmap_alloc (num_partitions);
01089 sbitmap_zero (seen);
01090
01091 for (x = num_partitions - 1; x >= 0; x--)
01092 {
01093 t = partition_to_var (map, x);
01094
01095
01096 if (!t
01097 || TREE_THIS_VOLATILE (t)
01098 || TREE_CODE (t) == RESULT_DECL
01099 || TREE_CODE (t) == PARM_DECL
01100 || (DECL_P (t)
01101 && (DECL_REGISTER (t)
01102 || !DECL_IGNORED_P (t)
01103 || DECL_RTL_SET_P (t))))
01104 continue;
01105
01106 p = var_to_partition (map, t);
01107
01108 gcc_assert (p != NO_PARTITION);
01109
01110
01111
01112 if (TEST_BIT (seen, p))
01113 continue;
01114 SET_BIT (seen, p);
01115 t = TREE_TYPE (t);
01116
01117
01118 for (y = 0; y < tv->num_trees; y++)
01119 if (t == VEC_index (tree, tv->trees, y))
01120 break;
01121 if (y == tv->num_trees)
01122 {
01123 tv->num_trees++;
01124 VEC_safe_push (tree, heap, tv->trees, t);
01125 VEC_safe_push (int, heap, tv->first_partition, p);
01126 }
01127 else
01128 {
01129 tv->next_partition[p] = VEC_index (int, tv->first_partition, y);
01130 VEC_replace (int, tv->first_partition, y, p);
01131 }
01132 tv->partition_to_tree_map[p] = y;
01133 }
01134 sbitmap_free (seen);
01135 return tv;
01136 }
01137
01138
01139
01140
01141 coalesce_list_p
01142 create_coalesce_list (var_map map)
01143 {
01144 coalesce_list_p list;
01145
01146 list = (coalesce_list_p) xmalloc (sizeof (struct coalesce_list_d));
01147
01148 list->map = map;
01149 list->add_mode = true;
01150 list->list = (partition_pair_p *) xcalloc (num_var_partitions (map),
01151 sizeof (struct partition_pair_d));
01152 return list;
01153 }
01154
01155
01156
01157
01158 void
01159 delete_coalesce_list (coalesce_list_p cl)
01160 {
01161 free (cl->list);
01162 free (cl);
01163 }
01164
01165
01166
01167
01168
01169
01170 static partition_pair_p
01171 find_partition_pair (coalesce_list_p cl, int p1, int p2, bool create)
01172 {
01173 partition_pair_p node, tmp;
01174 int s;
01175
01176
01177 if (p2 < p1)
01178 {
01179 s = p1;
01180 p1 = p2;
01181 p2 = s;
01182 }
01183
01184 tmp = NULL;
01185
01186
01187
01188 for (node = cl->list[p1]; node; node = node->next)
01189 {
01190 if (node->second_partition == p2)
01191 return node;
01192 else
01193 if (node->second_partition > p2)
01194 break;
01195 tmp = node;
01196 }
01197
01198 if (!create)
01199 return NULL;
01200
01201 node = (partition_pair_p) xmalloc (sizeof (struct partition_pair_d));
01202 node->first_partition = p1;
01203 node->second_partition = p2;
01204 node->cost = 0;
01205
01206 if (tmp != NULL)
01207 {
01208 node->next = tmp->next;
01209 tmp->next = node;
01210 }
01211 else
01212 {
01213
01214 node->next = cl->list[p1];
01215 cl->list[p1] = node;
01216 }
01217
01218 return node;
01219 }
01220
01221
01222
01223 int
01224 coalesce_cost (int frequency, bool hot, bool critical)
01225 {
01226
01227 int cost = frequency;
01228
01229 if (!cost)
01230 cost = 1;
01231 if (optimize_size || hot)
01232 cost = 1;
01233
01234
01235 if (critical)
01236 cost *= 2;
01237 return cost;
01238 }
01239
01240
01241
01242 void
01243 add_coalesce (coalesce_list_p cl, int p1, int p2,
01244 int value)
01245 {
01246 partition_pair_p node;
01247
01248 gcc_assert (cl->add_mode);
01249
01250 if (p1 == p2)
01251 return;
01252
01253 node = find_partition_pair (cl, p1, p2, true);
01254
01255 node->cost += value;
01256 }
01257
01258
01259
01260
01261 static
01262 int compare_pairs (const void *p1, const void *p2)
01263 {
01264 return (*(partition_pair_p *)p2)->cost - (*(partition_pair_p *)p1)->cost;
01265 }
01266
01267
01268
01269
01270
01271
01272 void
01273 sort_coalesce_list (coalesce_list_p cl)
01274 {
01275 unsigned x, num, count;
01276 partition_pair_p chain, p;
01277 partition_pair_p *list;
01278
01279 gcc_assert (cl->add_mode);
01280
01281 cl->add_mode = false;
01282
01283
01284 num = 0;
01285 chain = NULL;
01286 for (x = 0; x < num_var_partitions (cl->map); x++)
01287 if (cl->list[x] != NULL)
01288 {
01289 for (p = cl->list[x]; p->next != NULL; p = p->next)
01290 num++;
01291 num++;
01292 p->next = chain;
01293 chain = cl->list[x];
01294 cl->list[x] = NULL;
01295 }
01296
01297
01298 if (num > 2)
01299 {
01300 list = XNEWVEC (partition_pair_p, num);
01301 count = 0;
01302 for (p = chain; p != NULL; p = p->next)
01303 list[count++] = p;
01304
01305 gcc_assert (count == num);
01306
01307 qsort (list, count, sizeof (partition_pair_p), compare_pairs);
01308
01309 p = list[0];
01310 for (x = 1; x < num; x++)
01311 {
01312 p->next = list[x];
01313 p = list[x];
01314 }
01315 p->next = NULL;
01316 cl->list[0] = list[0];
01317 free (list);
01318 }
01319 else
01320 {
01321 cl->list[0] = chain;
01322 if (num == 2)
01323 {
01324
01325 if (chain->cost < chain->next->cost)
01326 {
01327 cl->list[0] = chain->next;
01328 cl->list[0]->next = chain;
01329 chain->next = NULL;
01330 }
01331 }
01332 }
01333 }
01334
01335
01336
01337
01338
01339
01340 static int
01341 pop_best_coalesce (coalesce_list_p cl, int *p1, int *p2)
01342 {
01343 partition_pair_p node;
01344 int ret;
01345
01346 gcc_assert (!cl->add_mode);
01347
01348 node = cl->list[0];
01349 if (!node)
01350 return NO_BEST_COALESCE;
01351
01352 cl->list[0] = node->next;
01353
01354 *p1 = node->first_partition;
01355 *p2 = node->second_partition;
01356 ret = node->cost;
01357 free (node);
01358
01359 return ret;
01360 }
01361
01362
01363
01364
01365
01366
01367 static inline void
01368 add_conflicts_if_valid (tpa_p tpa, conflict_graph graph,
01369 var_map map, bitmap vec, tree var)
01370 {
01371 int p, y, first;
01372 p = var_to_partition (map, var);
01373 if (p != NO_PARTITION)
01374 {
01375 bitmap_clear_bit (vec, p);
01376 first = tpa_find_tree (tpa, p);
01377
01378 if (first == TPA_NONE)
01379 return;
01380
01381 for (y = tpa_first_partition (tpa, first);
01382 y != TPA_NONE;
01383 y = tpa_next_partition (tpa, y))
01384 {
01385 if (bitmap_bit_p (vec, y))
01386 conflict_graph_add (graph, p, y);
01387 }
01388 }
01389 }
01390
01391
01392
01393
01394
01395 conflict_graph
01396 build_tree_conflict_graph (tree_live_info_p liveinfo, tpa_p tpa,
01397 coalesce_list_p cl)
01398 {
01399 conflict_graph graph;
01400 var_map map;
01401 bitmap live;
01402 unsigned x, y, i;
01403 basic_block bb;
01404 int *partition_link, *tpa_nodes;
01405 VEC(int,heap) *tpa_to_clear;
01406 unsigned l;
01407 ssa_op_iter iter;
01408 bitmap_iterator bi;
01409
01410 map = live_var_map (liveinfo);
01411 graph = conflict_graph_new (num_var_partitions (map));
01412
01413 if (tpa_num_trees (tpa) == 0)
01414 return graph;
01415
01416 live = BITMAP_ALLOC (NULL);
01417
01418 partition_link = XCNEWVEC (int, num_var_partitions (map) + 1);
01419 tpa_nodes = XCNEWVEC (int, tpa_num_trees (tpa));
01420 tpa_to_clear = VEC_alloc (int, heap, 50);
01421
01422 FOR_EACH_BB (bb)
01423 {
01424 block_stmt_iterator bsi;
01425 tree phi;
01426 int idx;
01427
01428
01429 bitmap_copy (live, live_on_exit (liveinfo, bb));
01430
01431 for (bsi = bsi_last (bb); !bsi_end_p (bsi); bsi_prev (&bsi))
01432 {
01433 bool is_a_copy = false;
01434 tree stmt = bsi_stmt (bsi);
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446 if (TREE_CODE (stmt) == MODIFY_EXPR)
01447 {
01448 tree lhs = TREE_OPERAND (stmt, 0);
01449 tree rhs = TREE_OPERAND (stmt, 1);
01450 int p1, p2;
01451 int bit;
01452
01453 if (DECL_P (lhs) || TREE_CODE (lhs) == SSA_NAME)
01454 p1 = var_to_partition (map, lhs);
01455 else
01456 p1 = NO_PARTITION;
01457
01458 if (DECL_P (rhs) || TREE_CODE (rhs) == SSA_NAME)
01459 p2 = var_to_partition (map, rhs);
01460 else
01461 p2 = NO_PARTITION;
01462
01463 if (p1 != NO_PARTITION && p2 != NO_PARTITION)
01464 {
01465 is_a_copy = true;
01466 bit = bitmap_bit_p (live, p2);
01467
01468
01469 if (bit)
01470 bitmap_clear_bit (live, p2);
01471 add_conflicts_if_valid (tpa, graph, map, live, lhs);
01472 if (bit)
01473 bitmap_set_bit (live, p2);
01474 if (cl)
01475 add_coalesce (cl, p1, p2,
01476 coalesce_cost (bb->frequency,
01477 maybe_hot_bb_p (bb), false));
01478 set_if_valid (map, live, rhs);
01479 }
01480 }
01481
01482 if (!is_a_copy)
01483 {
01484 tree var;
01485 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF)
01486 {
01487 add_conflicts_if_valid (tpa, graph, map, live, var);
01488 }
01489
01490 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE)
01491 {
01492 set_if_valid (map, live, var);
01493 }
01494 }
01495 }
01496
01497
01498
01499
01500
01501
01502 for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
01503 {
01504 tree result = PHI_RESULT (phi);
01505 int p = var_to_partition (map, result);
01506
01507 if (p != NO_PARTITION && ! bitmap_bit_p (live, p))
01508 add_conflicts_if_valid (tpa, graph, map, live, result);
01509 }
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524 EXECUTE_IF_SET_IN_BITMAP (live, 0, x, bi)
01525 {
01526 i = tpa_find_tree (tpa, x);
01527 if (i != (unsigned)TPA_NONE)
01528 {
01529 int start = tpa_nodes[i];
01530
01531
01532 if (!start)
01533 VEC_safe_push (int, heap, tpa_to_clear, i);
01534
01535
01536 for (y = start; y != 0; y = partition_link[y])
01537 conflict_graph_add (graph, x, y - 1);
01538 tpa_nodes[i] = x + 1;
01539 partition_link[x + 1] = start;
01540 }
01541 }
01542
01543
01544 for (l = 0; VEC_iterate (int, tpa_to_clear, l, idx); l++)
01545 tpa_nodes[idx] = 0;
01546 VEC_truncate (int, tpa_to_clear, 0);
01547 }
01548
01549 free (tpa_nodes);
01550 free (partition_link);
01551 VEC_free (int, heap, tpa_to_clear);
01552 BITMAP_FREE (live);
01553 return graph;
01554 }
01555
01556
01557
01558
01559
01560
01561
01562
01563 void
01564 coalesce_tpa_members (tpa_p tpa, conflict_graph graph, var_map map,
01565 coalesce_list_p cl, FILE *debug)
01566 {
01567 int x, y, z, w;
01568 tree var, tmp;
01569
01570
01571 if (cl)
01572 {
01573 while (pop_best_coalesce (cl, &x, &y) != NO_BEST_COALESCE)
01574 {
01575 if (debug)
01576 {
01577 fprintf (debug, "Coalesce list: (%d)", x);
01578 print_generic_expr (debug, partition_to_var (map, x), TDF_SLIM);
01579 fprintf (debug, " & (%d)", y);
01580 print_generic_expr (debug, partition_to_var (map, y), TDF_SLIM);
01581 }
01582
01583 w = tpa_find_tree (tpa, x);
01584 z = tpa_find_tree (tpa, y);
01585 if (w != z || w == TPA_NONE || z == TPA_NONE)
01586 {
01587 if (debug)
01588 {
01589 if (w != z)
01590 fprintf (debug, ": Fail, Non-matching TPA's\n");
01591 if (w == TPA_NONE)
01592 fprintf (debug, ": Fail %d non TPA.\n", x);
01593 else
01594 fprintf (debug, ": Fail %d non TPA.\n", y);
01595 }
01596 continue;
01597 }
01598 var = partition_to_var (map, x);
01599 tmp = partition_to_var (map, y);
01600 x = var_to_partition (map, var);
01601 y = var_to_partition (map, tmp);
01602 if (debug)
01603 fprintf (debug, " [map: %d, %d] ", x, y);
01604 if (x == y)
01605 {
01606 if (debug)
01607 fprintf (debug, ": Already Coalesced.\n");
01608 continue;
01609 }
01610 if (!conflict_graph_conflict_p (graph, x, y))
01611 {
01612 z = var_union (map, var, tmp);
01613 if (z == NO_PARTITION)
01614 {
01615 if (debug)
01616 fprintf (debug, ": Unable to perform partition union.\n");
01617 continue;
01618 }
01619
01620
01621
01622 if (z == x)
01623 {
01624 conflict_graph_merge_regs (graph, x, y);
01625 w = tpa_find_tree (tpa, y);
01626 tpa_remove_partition (tpa, w, y);
01627 }
01628 else
01629 {
01630 conflict_graph_merge_regs (graph, y, x);
01631 w = tpa_find_tree (tpa, x);
01632 tpa_remove_partition (tpa, w, x);
01633 }
01634
01635 if (debug)
01636 fprintf (debug, ": Success -> %d\n", z);
01637 }
01638 else
01639 if (debug)
01640 fprintf (debug, ": Fail due to conflict\n");
01641 }
01642
01643 return;
01644 }
01645
01646 for (x = 0; x < tpa_num_trees (tpa); x++)
01647 {
01648 while (tpa_first_partition (tpa, x) != TPA_NONE)
01649 {
01650 int p1, p2;
01651
01652 y = tpa_first_partition (tpa, x);
01653 tpa_remove_partition (tpa, x, y);
01654
01655 var = partition_to_var (map, y);
01656
01657 p1 = var_to_partition (map, var);
01658
01659 for (z = tpa_next_partition (tpa, y);
01660 z != TPA_NONE;
01661 z = tpa_next_partition (tpa, z))
01662 {
01663 tmp = partition_to_var (map, z);
01664
01665 p2 = var_to_partition (map, tmp);
01666 if (debug)
01667 {
01668 fprintf (debug, "Coalesce : ");
01669 print_generic_expr (debug, var, TDF_SLIM);
01670 fprintf (debug, " &");
01671 print_generic_expr (debug, tmp, TDF_SLIM);
01672 fprintf (debug, " (%d ,%d)", p1, p2);
01673 }
01674
01675
01676 if (tmp == var)
01677 {
01678 tpa_remove_partition (tpa, x, z);
01679 if (debug)
01680 fprintf (debug, ": Already coalesced\n");
01681 }
01682 else
01683 if (!conflict_graph_conflict_p (graph, p1, p2))
01684 {
01685 int v;
01686 if (tpa_find_tree (tpa, y) == TPA_NONE
01687 || tpa_find_tree (tpa, z) == TPA_NONE)
01688 {
01689 if (debug)
01690 fprintf (debug, ": Fail non-TPA member\n");
01691 continue;
01692 }
01693 if ((v = var_union (map, var, tmp)) == NO_PARTITION)
01694 {
01695 if (debug)
01696 fprintf (debug, ": Fail cannot combine partitions\n");
01697 continue;
01698 }
01699
01700 tpa_remove_partition (tpa, x, z);
01701 if (v == p1)
01702 conflict_graph_merge_regs (graph, v, z);
01703 else
01704 {
01705
01706 conflict_graph_merge_regs (graph, v, y);
01707 p1 = v;
01708 }
01709
01710
01711
01712 var = partition_to_var (map, p1);
01713
01714 if (debug)
01715 fprintf (debug, ": Success -> %d\n", v);
01716 }
01717 else
01718 if (debug)
01719 fprintf (debug, ": Fail, Conflict\n");
01720 }
01721 }
01722 }
01723 }
01724
01725
01726
01727
01728 void
01729 dump_coalesce_list (FILE *f, coalesce_list_p cl)
01730 {
01731 partition_pair_p node;
01732 int x, num;
01733 tree var;
01734
01735 if (cl->add_mode)
01736 {
01737 fprintf (f, "Coalesce List:\n");
01738 num = num_var_partitions (cl->map);
01739 for (x = 0; x < num; x++)
01740 {
01741 node = cl->list[x];
01742 if (node)
01743 {
01744 fprintf (f, "[");
01745 print_generic_expr (f, partition_to_var (cl->map, x), TDF_SLIM);
01746 fprintf (f, "] - ");
01747 for ( ; node; node = node->next)
01748 {
01749 var = partition_to_var (cl->map, node->second_partition);
01750 print_generic_expr (f, var, TDF_SLIM);
01751 fprintf (f, "(%1d), ", node->cost);
01752 }
01753 fprintf (f, "\n");
01754 }
01755 }
01756 }
01757 else
01758 {
01759 fprintf (f, "Sorted Coalesce list:\n");
01760 for (node = cl->list[0]; node; node = node->next)
01761 {
01762 fprintf (f, "(%d) ", node->cost);
01763 var = partition_to_var (cl->map, node->first_partition);
01764 print_generic_expr (f, var, TDF_SLIM);
01765 fprintf (f, " : ");
01766 var = partition_to_var (cl->map, node->second_partition);
01767 print_generic_expr (f, var, TDF_SLIM);
01768 fprintf (f, "\n");
01769 }
01770 }
01771 }
01772
01773
01774
01775
01776 void
01777 tpa_dump (FILE *f, tpa_p tpa)
01778 {
01779 int x, i;
01780
01781 if (!tpa)
01782 return;
01783
01784 for (x = 0; x < tpa_num_trees (tpa); x++)
01785 {
01786 print_generic_expr (f, tpa_tree (tpa, x), TDF_SLIM);
01787 fprintf (f, " : (");
01788 for (i = tpa_first_partition (tpa, x);
01789 i != TPA_NONE;
01790 i = tpa_next_partition (tpa, i))
01791 {
01792 fprintf (f, "(%d)",i);
01793 print_generic_expr (f, partition_to_var (tpa->map, i), TDF_SLIM);
01794 fprintf (f, " ");
01795
01796 #ifdef ENABLE_CHECKING
01797 if (tpa_find_tree (tpa, i) != x)
01798 fprintf (f, "**find tree incorrectly set** ");
01799 #endif
01800
01801 }
01802 fprintf (f, ")\n");
01803 }
01804 fflush (f);
01805 }
01806
01807
01808
01809
01810 void
01811 dump_var_map (FILE *f, var_map map)
01812 {
01813 int t;
01814 unsigned x, y;
01815 int p;
01816
01817 fprintf (f, "\nPartition map \n\n");
01818
01819 for (x = 0; x < map->num_partitions; x++)
01820 {
01821 if (map->compact_to_partition != NULL)
01822 p = map->compact_to_partition[x];
01823 else
01824 p = x;
01825
01826 if (map->partition_to_var[p] == NULL_TREE)
01827 continue;
01828
01829 t = 0;
01830 for (y = 1; y < num_ssa_names; y++)
01831 {
01832 p = partition_find (map->var_partition, y);
01833 if (map->partition_to_compact)
01834 p = map->partition_to_compact[p];
01835 if (p == (int)x)
01836 {
01837 if (t++ == 0)
01838 {
01839 fprintf(f, "Partition %d (", x);
01840 print_generic_expr (f, partition_to_var (map, p), TDF_SLIM);
01841 fprintf (f, " - ");
01842 }
01843 fprintf (f, "%d ", y);
01844 }
01845 }
01846 if (t != 0)
01847 fprintf (f, ")\n");
01848 }
01849 fprintf (f, "\n");
01850 }
01851
01852
01853
01854
01855 void
01856 dump_live_info (FILE *f, tree_live_info_p live, int flag)
01857 {
01858 basic_block bb;
01859 unsigned i;
01860 var_map map = live->map;
01861 bitmap_iterator bi;
01862
01863 if ((flag & LIVEDUMP_ENTRY) && live->livein)
01864 {
01865 FOR_EACH_BB (bb)
01866 {
01867 fprintf (f, "\nLive on entry to BB%d : ", bb->index);
01868 for (i = 0; i < num_var_partitions (map); i++)
01869 {
01870 if (bitmap_bit_p (live_entry_blocks (live, i), bb->index))
01871 {
01872 print_generic_expr (f, partition_to_var (map, i), TDF_SLIM);
01873 fprintf (f, " ");
01874 }
01875 }
01876 fprintf (f, "\n");
01877 }
01878 }
01879
01880 if ((flag & LIVEDUMP_EXIT) && live->liveout)
01881 {
01882 FOR_EACH_BB (bb)
01883 {
01884 fprintf (f, "\nLive on exit from BB%d : ", bb->index);
01885 EXECUTE_IF_SET_IN_BITMAP (live->liveout[bb->index], 0, i, bi)
01886 {
01887 print_generic_expr (f, partition_to_var (map, i), TDF_SLIM);
01888 fprintf (f, " ");
01889 }
01890 fprintf (f, "\n");
01891 }
01892 }
01893 }
01894
01895 #ifdef ENABLE_CHECKING
01896 void
01897 register_ssa_partition_check (tree ssa_var)
01898 {
01899 gcc_assert (TREE_CODE (ssa_var) == SSA_NAME);
01900 if (!is_gimple_reg (SSA_NAME_VAR (ssa_var)))
01901 {
01902 fprintf (stderr, "Illegally registering a virtual SSA name :");
01903 print_generic_expr (stderr, ssa_var, TDF_SLIM);
01904 fprintf (stderr, " in the SSA->Normal phase.\n");
01905 internal_error ("SSA corruption");
01906 }
01907 }
01908 #endif