comparison gcc/tree-ssa-live.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
22 #include "config.h" 22 #include "config.h"
23 #include "system.h" 23 #include "system.h"
24 #include "coretypes.h" 24 #include "coretypes.h"
25 #include "tm.h" 25 #include "tm.h"
26 #include "tree.h" 26 #include "tree.h"
27 #include "diagnostic.h"
28 #include "tree-pretty-print.h" 27 #include "tree-pretty-print.h"
29 #include "gimple-pretty-print.h" 28 #include "gimple-pretty-print.h"
30 #include "bitmap.h" 29 #include "bitmap.h"
31 #include "tree-flow.h" 30 #include "tree-flow.h"
32 #include "tree-dump.h" 31 #include "tree-dump.h"
33 #include "tree-ssa-live.h" 32 #include "tree-ssa-live.h"
34 #include "toplev.h" 33 #include "diagnostic-core.h"
35 #include "debug.h" 34 #include "debug.h"
36 #include "flags.h" 35 #include "flags.h"
36 #include "gimple.h"
37 37
38 #ifdef ENABLE_CHECKING 38 #ifdef ENABLE_CHECKING
39 static void verify_live_on_entry (tree_live_info_p); 39 static void verify_live_on_entry (tree_live_info_p);
40 #endif 40 #endif
41 41
359 359
360 if (IS_EXPR_CODE_CLASS (c) 360 if (IS_EXPR_CODE_CLASS (c)
361 && (b = TREE_BLOCK (t)) != NULL) 361 && (b = TREE_BLOCK (t)) != NULL)
362 TREE_USED (b) = true; 362 TREE_USED (b) = true;
363 363
364 /* Ignore TREE_ORIGINAL for TARGET_MEM_REFS, as well as other 364 /* Ignore TMR_OFFSET and TMR_STEP for TARGET_MEM_REFS, as those
365 fields that do not contain vars. */ 365 fields do not contain vars. */
366 if (TREE_CODE (t) == TARGET_MEM_REF) 366 if (TREE_CODE (t) == TARGET_MEM_REF)
367 { 367 {
368 mark_all_vars_used (&TMR_SYMBOL (t), data);
369 mark_all_vars_used (&TMR_BASE (t), data); 368 mark_all_vars_used (&TMR_BASE (t), data);
370 mark_all_vars_used (&TMR_INDEX (t), data); 369 mark_all_vars_used (&TMR_INDEX (t), data);
370 mark_all_vars_used (&TMR_INDEX2 (t), data);
371 *walk_subtrees = 0; 371 *walk_subtrees = 0;
372 return NULL; 372 return NULL;
373 } 373 }
374 374
375 /* Only need to mark VAR_DECLS; parameters and return results are not 375 /* Only need to mark VAR_DECLS; parameters and return results are not
376 eliminated as unused. */ 376 eliminated as unused. */
377 if (TREE_CODE (t) == VAR_DECL) 377 if (TREE_CODE (t) == VAR_DECL)
378 { 378 {
379 if (data != NULL && bitmap_bit_p ((bitmap) data, DECL_UID (t))) 379 if (data != NULL && bitmap_clear_bit ((bitmap) data, DECL_UID (t)))
380 { 380 mark_all_vars_used (&DECL_INITIAL (t), data);
381 bitmap_clear_bit ((bitmap) data, DECL_UID (t));
382 mark_all_vars_used (&DECL_INITIAL (t), data);
383 }
384 set_is_used (t); 381 set_is_used (t);
385 } 382 }
383 /* remove_unused_scope_block_p requires information about labels
384 which are not DECL_IGNORED_P to tell if they might be used in the IL. */
385 if (TREE_CODE (t) == LABEL_DECL)
386 /* Although the TREE_USED values that the frontend uses would be
387 acceptable (albeit slightly over-conservative) for our purposes,
388 init_vars_expansion clears TREE_USED for LABEL_DECLs too, so we
389 must re-compute it here. */
390 TREE_USED (t) = 1;
386 391
387 if (IS_TYPE_OR_DECL_P (t)) 392 if (IS_TYPE_OR_DECL_P (t))
388 *walk_subtrees = 0; 393 *walk_subtrees = 0;
389 394
390 return NULL; 395 return NULL;
425 var_ann_t ann; 430 var_ann_t ann;
426 int nsubblocks = 0; 431 int nsubblocks = 0;
427 432
428 for (t = &BLOCK_VARS (scope); *t; t = next) 433 for (t = &BLOCK_VARS (scope); *t; t = next)
429 { 434 {
430 next = &TREE_CHAIN (*t); 435 next = &DECL_CHAIN (*t);
431 436
432 /* Debug info of nested function refers to the block of the 437 /* Debug info of nested function refers to the block of the
433 function. We might stil call it even if all statements 438 function. We might stil call it even if all statements
434 of function it was nested into was elliminated. 439 of function it was nested into was elliminated.
435 440
446 by virtual register instantiation, we may get end up with 451 by virtual register instantiation, we may get end up with
447 different results. */ 452 different results. */
448 else if (TREE_CODE (*t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (*t)) 453 else if (TREE_CODE (*t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (*t))
449 unused = false; 454 unused = false;
450 455
451 /* Remove everything we don't generate debug info for. */ 456 /* Remove everything we don't generate debug info for.
452 else if (DECL_IGNORED_P (*t)) 457 Don't remove larger vars though, because BLOCK_VARS are
458 used also during expansion to determine which variables
459 might share stack space. */
460 else if (DECL_IGNORED_P (*t) && is_gimple_reg (*t))
453 { 461 {
454 *t = TREE_CHAIN (*t); 462 *t = DECL_CHAIN (*t);
455 next = t; 463 next = t;
456 } 464 }
457 465
458 /* When we are outputting debug info, we usually want to output 466 /* When we are outputting debug info, we usually want to output
459 info about optimized-out variables in the scope blocks. 467 info about optimized-out variables in the scope blocks.
460 Exception are the scope blocks not containing any instructions 468 Exception are the scope blocks not containing any instructions
461 at all so user can't get into the scopes at first place. */ 469 at all so user can't get into the scopes at first place. */
462 else if ((ann = var_ann (*t)) != NULL 470 else if ((ann = var_ann (*t)) != NULL
463 && ann->used) 471 && is_used_p (*t))
472 unused = false;
473 else if (TREE_CODE (*t) == LABEL_DECL && TREE_USED (*t))
474 /* For labels that are still used in the IL, the decision to
475 preserve them must not depend DEBUG_INFO_LEVEL, otherwise we
476 risk having different ordering in debug vs. non-debug builds
477 during inlining or versioning.
478 A label appearing here (we have already checked DECL_IGNORED_P)
479 should not be used in the IL unless it has been explicitly used
480 before, so we use TREE_USED as an approximation. */
481 /* In principle, we should do the same here as for the debug case
482 below, however, when debugging, there might be additional nested
483 levels that keep an upper level with a label live, so we have to
484 force this block to be considered used, too. */
464 unused = false; 485 unused = false;
465 486
466 /* When we are not doing full debug info, we however can keep around 487 /* When we are not doing full debug info, we however can keep around
467 only the used variables for cfgexpand's memory packing saving quite 488 only the used variables for cfgexpand's memory packing saving quite
468 a lot of memory. 489 a lot of memory.
470 For sake of -g3, we keep around those vars but we don't count this as 491 For sake of -g3, we keep around those vars but we don't count this as
471 use of block, so innermost block with no used vars and no instructions 492 use of block, so innermost block with no used vars and no instructions
472 can be considered dead. We only want to keep around blocks user can 493 can be considered dead. We only want to keep around blocks user can
473 breakpoint into and ask about value of optimized out variables. 494 breakpoint into and ask about value of optimized out variables.
474 495
475 Similarly we need to keep around types at least until all variables of 496 Similarly we need to keep around types at least until all
476 all nested blocks are gone. We track no information on whether given 497 variables of all nested blocks are gone. We track no
477 type is used or not. */ 498 information on whether given type is used or not, so we have
478 499 to keep them even when not emitting debug information,
479 else if (debug_info_level == DINFO_LEVEL_NORMAL 500 otherwise we may end up remapping variables and their (local)
501 types in different orders depending on whether debug
502 information is being generated. */
503
504 else if (TREE_CODE (*t) == TYPE_DECL
505 || debug_info_level == DINFO_LEVEL_NORMAL
480 || debug_info_level == DINFO_LEVEL_VERBOSE) 506 || debug_info_level == DINFO_LEVEL_VERBOSE)
481 ; 507 ;
482 else 508 else
483 { 509 {
484 *t = TREE_CHAIN (*t); 510 *t = DECL_CHAIN (*t);
485 next = t; 511 next = t;
486 } 512 }
487 } 513 }
488 514
489 for (t = &BLOCK_SUBBLOCKS (scope); *t ;) 515 for (t = &BLOCK_SUBBLOCKS (scope); *t ;)
602 else 628 else
603 fprintf (file, "#%i", BLOCK_NUMBER (origin)); 629 fprintf (file, "#%i", BLOCK_NUMBER (origin));
604 } 630 }
605 } 631 }
606 fprintf (file, " \n"); 632 fprintf (file, " \n");
607 for (var = BLOCK_VARS (scope); var; var = TREE_CHAIN (var)) 633 for (var = BLOCK_VARS (scope); var; var = DECL_CHAIN (var))
608 { 634 {
609 bool used = false; 635 bool used = false;
610 var_ann_t ann; 636
611 637 if (var_ann (var))
612 if ((ann = var_ann (var)) 638 used = is_used_p (var);
613 && ann->used) 639
614 used = true; 640 fprintf (file, "%*s", indent, "");
615
616 fprintf (file, "%*s",indent, "");
617 print_generic_decl (file, var, flags); 641 print_generic_decl (file, var, flags);
618 fprintf (file, "%s\n", used ? "" : " (unused)"); 642 fprintf (file, "%s\n", used ? "" : " (unused)");
619 } 643 }
620 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (scope); i++) 644 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (scope); i++)
621 { 645 {
630 } 654 }
631 655
632 /* Dump the tree of lexical scopes starting at SCOPE to stderr. FLAGS 656 /* Dump the tree of lexical scopes starting at SCOPE to stderr. FLAGS
633 is as in print_generic_expr. */ 657 is as in print_generic_expr. */
634 658
635 void 659 DEBUG_FUNCTION void
636 debug_scope_block (tree scope, int flags) 660 debug_scope_block (tree scope, int flags)
637 { 661 {
638 dump_scope_block (stderr, 0, scope, flags); 662 dump_scope_block (stderr, 0, scope, flags);
639 } 663 }
640 664
650 674
651 675
652 /* Dump the tree of lexical scopes of current_function_decl to stderr. 676 /* Dump the tree of lexical scopes of current_function_decl to stderr.
653 FLAGS is as in print_generic_expr. */ 677 FLAGS is as in print_generic_expr. */
654 678
655 void 679 DEBUG_FUNCTION void
656 debug_scope_blocks (int flags) 680 debug_scope_blocks (int flags)
657 { 681 {
658 dump_scope_blocks (stderr, flags); 682 dump_scope_blocks (stderr, flags);
659 } 683 }
660 684
662 686
663 void 687 void
664 remove_unused_locals (void) 688 remove_unused_locals (void)
665 { 689 {
666 basic_block bb; 690 basic_block bb;
667 tree t, *cell; 691 tree var, t;
668 referenced_var_iterator rvi; 692 referenced_var_iterator rvi;
669 var_ann_t ann; 693 var_ann_t ann;
670 bitmap global_unused_vars = NULL; 694 bitmap global_unused_vars = NULL;
695 unsigned srcidx, dstidx, num;
671 696
672 /* Removing declarations from lexical blocks when not optimizing is 697 /* Removing declarations from lexical blocks when not optimizing is
673 not only a waste of time, it actually causes differences in stack 698 not only a waste of time, it actually causes differences in stack
674 layout. */ 699 layout. */
675 if (!optimize) 700 if (!optimize)
676 return; 701 return;
677 702
703 timevar_push (TV_REMOVE_UNUSED);
704
678 mark_scope_block_unused (DECL_INITIAL (current_function_decl)); 705 mark_scope_block_unused (DECL_INITIAL (current_function_decl));
679 706
680 /* Assume all locals are unused. */ 707 /* Assume all locals are unused. */
681 FOR_EACH_REFERENCED_VAR (t, rvi) 708 FOR_EACH_REFERENCED_VAR (cfun, t, rvi)
682 var_ann (t)->used = false; 709 clear_is_used (t);
683 710
684 /* Walk the CFG marking all referenced symbols. */ 711 /* Walk the CFG marking all referenced symbols. */
685 FOR_EACH_BB (bb) 712 FOR_EACH_BB (bb)
686 { 713 {
687 gimple_stmt_iterator gsi; 714 gimple_stmt_iterator gsi;
732 } 759 }
733 760
734 cfun->has_local_explicit_reg_vars = false; 761 cfun->has_local_explicit_reg_vars = false;
735 762
736 /* Remove unmarked local vars from local_decls. */ 763 /* Remove unmarked local vars from local_decls. */
737 for (cell = &cfun->local_decls; *cell; ) 764 num = VEC_length (tree, cfun->local_decls);
738 { 765 for (srcidx = 0, dstidx = 0; srcidx < num; srcidx++)
739 tree var = TREE_VALUE (*cell); 766 {
740 767 var = VEC_index (tree, cfun->local_decls, srcidx);
741 if (TREE_CODE (var) != FUNCTION_DECL 768 if (TREE_CODE (var) != FUNCTION_DECL
742 && (!(ann = var_ann (var)) 769 && (!(ann = var_ann (var))
743 || !ann->used)) 770 || !is_used_p (var)))
744 { 771 {
745 if (is_global_var (var)) 772 if (is_global_var (var))
746 { 773 {
747 if (global_unused_vars == NULL) 774 if (global_unused_vars == NULL)
748 global_unused_vars = BITMAP_ALLOC (NULL); 775 global_unused_vars = BITMAP_ALLOC (NULL);
749 bitmap_set_bit (global_unused_vars, DECL_UID (var)); 776 bitmap_set_bit (global_unused_vars, DECL_UID (var));
750 } 777 }
751 else 778 else
752 { 779 continue;
753 *cell = TREE_CHAIN (*cell);
754 continue;
755 }
756 } 780 }
757 else if (TREE_CODE (var) == VAR_DECL 781 else if (TREE_CODE (var) == VAR_DECL
758 && DECL_HARD_REGISTER (var) 782 && DECL_HARD_REGISTER (var)
759 && !is_global_var (var)) 783 && !is_global_var (var))
760 cfun->has_local_explicit_reg_vars = true; 784 cfun->has_local_explicit_reg_vars = true;
761 cell = &TREE_CHAIN (*cell); 785
762 } 786 if (srcidx != dstidx)
787 VEC_replace (tree, cfun->local_decls, dstidx, var);
788 dstidx++;
789 }
790 if (dstidx != num)
791 VEC_truncate (tree, cfun->local_decls, dstidx);
763 792
764 /* Remove unmarked global vars from local_decls. */ 793 /* Remove unmarked global vars from local_decls. */
765 if (global_unused_vars != NULL) 794 if (global_unused_vars != NULL)
766 { 795 {
767 for (t = cfun->local_decls; t; t = TREE_CHAIN (t)) 796 tree var;
797 unsigned ix;
798 FOR_EACH_LOCAL_DECL (cfun, ix, var)
799 if (TREE_CODE (var) == VAR_DECL
800 && is_global_var (var)
801 && (ann = var_ann (var)) != NULL
802 && is_used_p (var))
803 mark_all_vars_used (&DECL_INITIAL (var), global_unused_vars);
804
805 num = VEC_length (tree, cfun->local_decls);
806 for (srcidx = 0, dstidx = 0; srcidx < num; srcidx++)
768 { 807 {
769 tree var = TREE_VALUE (t); 808 var = VEC_index (tree, cfun->local_decls, srcidx);
770
771 if (TREE_CODE (var) == VAR_DECL
772 && is_global_var (var)
773 && (ann = var_ann (var)) != NULL
774 && ann->used)
775 mark_all_vars_used (&DECL_INITIAL (var), global_unused_vars);
776 }
777
778 for (cell = &cfun->local_decls; *cell; )
779 {
780 tree var = TREE_VALUE (*cell);
781
782 if (TREE_CODE (var) == VAR_DECL 809 if (TREE_CODE (var) == VAR_DECL
783 && is_global_var (var) 810 && is_global_var (var)
784 && bitmap_bit_p (global_unused_vars, DECL_UID (var))) 811 && bitmap_bit_p (global_unused_vars, DECL_UID (var)))
785 *cell = TREE_CHAIN (*cell); 812 continue;
786 else 813
787 cell = &TREE_CHAIN (*cell); 814 if (srcidx != dstidx)
788 } 815 VEC_replace (tree, cfun->local_decls, dstidx, var);
816 dstidx++;
817 }
818 if (dstidx != num)
819 VEC_truncate (tree, cfun->local_decls, dstidx);
789 BITMAP_FREE (global_unused_vars); 820 BITMAP_FREE (global_unused_vars);
790 } 821 }
791 822
792 /* Remove unused variables from REFERENCED_VARs. As a special 823 /* Remove unused variables from REFERENCED_VARs. */
793 exception keep the variables that are believed to be aliased. 824 FOR_EACH_REFERENCED_VAR (cfun, t, rvi)
794 Those can't be easily removed from the alias sets and operand
795 caches. They will be removed shortly after the next may_alias
796 pass is performed. */
797 FOR_EACH_REFERENCED_VAR (t, rvi)
798 if (!is_global_var (t) 825 if (!is_global_var (t)
799 && TREE_CODE (t) != PARM_DECL 826 && TREE_CODE (t) != PARM_DECL
800 && TREE_CODE (t) != RESULT_DECL 827 && TREE_CODE (t) != RESULT_DECL
801 && !(ann = var_ann (t))->used 828 && !is_used_p (t)
802 && !ann->is_heapvar 829 && !var_ann (t)->is_heapvar)
803 && !TREE_ADDRESSABLE (t))
804 remove_referenced_var (t); 830 remove_referenced_var (t);
805 remove_unused_scope_block_p (DECL_INITIAL (current_function_decl)); 831 remove_unused_scope_block_p (DECL_INITIAL (current_function_decl));
806 if (dump_file && (dump_flags & TDF_DETAILS)) 832 if (dump_file && (dump_flags & TDF_DETAILS))
807 { 833 {
808 fprintf (dump_file, "Scope blocks after cleanups:\n"); 834 fprintf (dump_file, "Scope blocks after cleanups:\n");
809 dump_scope_blocks (dump_file, dump_flags); 835 dump_scope_blocks (dump_file, dump_flags);
810 } 836 }
837
838 timevar_pop (TV_REMOVE_UNUSED);
811 } 839 }
812 840
813 841
814 /* Allocate and return a new live range information object base on MAP. */ 842 /* Allocate and return a new live range information object base on MAP. */
815 843
1168 fprintf (f, "\n"); 1196 fprintf (f, "\n");
1169 } 1197 }
1170 } 1198 }
1171 } 1199 }
1172 1200
1201 struct GTY(()) numbered_tree_d
1202 {
1203 tree t;
1204 int num;
1205 };
1206 typedef struct numbered_tree_d numbered_tree;
1207
1208 DEF_VEC_O (numbered_tree);
1209 DEF_VEC_ALLOC_O (numbered_tree, heap);
1210
1211 /* Compare two declarations references by their DECL_UID / sequence number.
1212 Called via qsort. */
1213
1214 static int
1215 compare_decls_by_uid (const void *pa, const void *pb)
1216 {
1217 const numbered_tree *nt_a = ((const numbered_tree *)pa);
1218 const numbered_tree *nt_b = ((const numbered_tree *)pb);
1219
1220 if (DECL_UID (nt_a->t) != DECL_UID (nt_b->t))
1221 return DECL_UID (nt_a->t) - DECL_UID (nt_b->t);
1222 return nt_a->num - nt_b->num;
1223 }
1224
1225 /* Called via walk_gimple_stmt / walk_gimple_op by dump_enumerated_decls. */
1226 static tree
1227 dump_enumerated_decls_push (tree *tp, int *walk_subtrees, void *data)
1228 {
1229 struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
1230 VEC (numbered_tree, heap) **list = (VEC (numbered_tree, heap) **) &wi->info;
1231 numbered_tree nt;
1232
1233 if (!DECL_P (*tp))
1234 return NULL_TREE;
1235 nt.t = *tp;
1236 nt.num = VEC_length (numbered_tree, *list);
1237 VEC_safe_push (numbered_tree, heap, *list, &nt);
1238 *walk_subtrees = 0;
1239 return NULL_TREE;
1240 }
1241
1242 /* Find all the declarations used by the current function, sort them by uid,
1243 and emit the sorted list. Each declaration is tagged with a sequence
1244 number indicating when it was found during statement / tree walking,
1245 so that TDF_NOUID comparisons of anonymous declarations are still
1246 meaningful. Where a declaration was encountered more than once, we
1247 emit only the sequence number of the first encounter.
1248 FILE is the dump file where to output the list and FLAGS is as in
1249 print_generic_expr. */
1250 void
1251 dump_enumerated_decls (FILE *file, int flags)
1252 {
1253 basic_block bb;
1254 struct walk_stmt_info wi;
1255 VEC (numbered_tree, heap) *decl_list = VEC_alloc (numbered_tree, heap, 40);
1256
1257 memset (&wi, '\0', sizeof (wi));
1258 wi.info = (void*) decl_list;
1259 FOR_EACH_BB (bb)
1260 {
1261 gimple_stmt_iterator gsi;
1262
1263 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1264 if (!is_gimple_debug (gsi_stmt (gsi)))
1265 walk_gimple_stmt (&gsi, NULL, dump_enumerated_decls_push, &wi);
1266 }
1267 decl_list = (VEC (numbered_tree, heap) *) wi.info;
1268 VEC_qsort (numbered_tree, decl_list, compare_decls_by_uid);
1269 if (VEC_length (numbered_tree, decl_list))
1270 {
1271 unsigned ix;
1272 numbered_tree *ntp;
1273 tree last = NULL_TREE;
1274
1275 fprintf (file, "Declarations used by %s, sorted by DECL_UID:\n",
1276 current_function_name ());
1277 FOR_EACH_VEC_ELT (numbered_tree, decl_list, ix, ntp)
1278 {
1279 if (ntp->t == last)
1280 continue;
1281 fprintf (file, "%d: ", ntp->num);
1282 print_generic_decl (file, ntp->t, flags);
1283 fprintf (file, "\n");
1284 last = ntp->t;
1285 }
1286 }
1287 VEC_free (numbered_tree, heap, decl_list);
1288 }
1173 1289
1174 #ifdef ENABLE_CHECKING 1290 #ifdef ENABLE_CHECKING
1175 /* Verify that SSA_VAR is a non-virtual SSA_NAME. */ 1291 /* Verify that SSA_VAR is a non-virtual SSA_NAME. */
1176 1292
1177 void 1293 void