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