Mercurial > hg > CbC > CbC_gcc
comparison gcc/dce.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | f6334be47118 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
25 #include "rtl.h" | 25 #include "rtl.h" |
26 #include "tree.h" | 26 #include "tree.h" |
27 #include "regs.h" | 27 #include "regs.h" |
28 #include "hard-reg-set.h" | 28 #include "hard-reg-set.h" |
29 #include "flags.h" | 29 #include "flags.h" |
30 #include "except.h" | |
30 #include "df.h" | 31 #include "df.h" |
31 #include "cselib.h" | 32 #include "cselib.h" |
32 #include "dce.h" | 33 #include "dce.h" |
33 #include "timevar.h" | 34 #include "timevar.h" |
34 #include "tree-pass.h" | 35 #include "tree-pass.h" |
35 #include "dbgcnt.h" | 36 #include "dbgcnt.h" |
36 #include "tm_p.h" | 37 #include "tm_p.h" |
37 | |
38 DEF_VEC_I(int); | |
39 DEF_VEC_ALLOC_I(int,heap); | |
40 | 38 |
41 | 39 |
42 /* ------------------------------------------------------------------------- | 40 /* ------------------------------------------------------------------------- |
43 Core mark/delete routines | 41 Core mark/delete routines |
44 ------------------------------------------------------------------------- */ | 42 ------------------------------------------------------------------------- */ |
79 changed, and the UNSPEC case can be removed. */ | 77 changed, and the UNSPEC case can be removed. */ |
80 case UNSPEC: | 78 case UNSPEC: |
81 return false; | 79 return false; |
82 | 80 |
83 default: | 81 default: |
84 if (volatile_refs_p (body)) | 82 return !volatile_refs_p (body); |
85 return false; | |
86 | |
87 if (flag_non_call_exceptions && may_trap_p (body)) | |
88 return false; | |
89 | |
90 return true; | |
91 } | 83 } |
92 } | 84 } |
93 | 85 |
94 | 86 |
95 /* Return true if INSN is a normal instruction that can be deleted by | 87 /* Return true if INSN is a normal instruction that can be deleted by |
98 static bool | 90 static bool |
99 deletable_insn_p (rtx insn, bool fast, bitmap arg_stores) | 91 deletable_insn_p (rtx insn, bool fast, bitmap arg_stores) |
100 { | 92 { |
101 rtx body, x; | 93 rtx body, x; |
102 int i; | 94 int i; |
95 | |
96 /* Don't delete jumps, notes and the like. */ | |
97 if (!NONJUMP_INSN_P (insn)) | |
98 return false; | |
99 | |
100 /* Don't delete insns that can throw. */ | |
101 if (!insn_nothrow_p (insn)) | |
102 return false; | |
103 | 103 |
104 if (CALL_P (insn) | 104 if (CALL_P (insn) |
105 /* We cannot delete calls inside of the recursive dce because | 105 /* We cannot delete calls inside of the recursive dce because |
106 this may cause basic blocks to be deleted and this messes up | 106 this may cause basic blocks to be deleted and this messes up |
107 the rest of the stack of optimization passes. */ | 107 the rest of the stack of optimization passes. */ |
113 infinite loop. */ | 113 infinite loop. */ |
114 && (RTL_CONST_OR_PURE_CALL_P (insn) | 114 && (RTL_CONST_OR_PURE_CALL_P (insn) |
115 && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn))) | 115 && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn))) |
116 return find_call_stack_args (insn, false, fast, arg_stores); | 116 return find_call_stack_args (insn, false, fast, arg_stores); |
117 | 117 |
118 if (!NONJUMP_INSN_P (insn)) | |
119 return false; | |
120 | |
121 body = PATTERN (insn); | 118 body = PATTERN (insn); |
122 switch (GET_CODE (body)) | 119 switch (GET_CODE (body)) |
123 { | 120 { |
124 case USE: | 121 case USE: |
122 case VAR_LOCATION: | |
125 return false; | 123 return false; |
126 | 124 |
127 case CLOBBER: | 125 case CLOBBER: |
128 if (fast) | 126 if (fast) |
129 { | 127 { |
350 set = single_set (DF_REF_INSN (defs->ref)); | 348 set = single_set (DF_REF_INSN (defs->ref)); |
351 off += INTVAL (XEXP (SET_SRC (set), 1)); | 349 off += INTVAL (XEXP (SET_SRC (set), 1)); |
352 } | 350 } |
353 for (byte = off; byte < off + INTVAL (MEM_SIZE (mem)); byte++) | 351 for (byte = off; byte < off + INTVAL (MEM_SIZE (mem)); byte++) |
354 { | 352 { |
355 gcc_assert (!bitmap_bit_p (sp_bytes, byte - min_sp_off)); | 353 if (!bitmap_set_bit (sp_bytes, byte - min_sp_off)) |
356 bitmap_set_bit (sp_bytes, byte - min_sp_off); | 354 gcc_unreachable (); |
357 } | 355 } |
358 } | 356 } |
359 | 357 |
360 /* Walk backwards, looking for argument stores. The search stops | 358 /* Walk backwards, looking for argument stores. The search stops |
361 when seeing another call, sp adjustment or memory store other than | 359 when seeing another call, sp adjustment or memory store other than |
438 | 436 |
439 for (byte = off; byte < off + GET_MODE_SIZE (GET_MODE (mem)); byte++) | 437 for (byte = off; byte < off + GET_MODE_SIZE (GET_MODE (mem)); byte++) |
440 { | 438 { |
441 if (byte < min_sp_off | 439 if (byte < min_sp_off |
442 || byte >= max_sp_off | 440 || byte >= max_sp_off |
443 || !bitmap_bit_p (sp_bytes, byte - min_sp_off)) | 441 || !bitmap_clear_bit (sp_bytes, byte - min_sp_off)) |
444 break; | 442 break; |
445 bitmap_clear_bit (sp_bytes, byte - min_sp_off); | |
446 } | 443 } |
447 | 444 |
448 if (!deletable_insn_p (insn, fast, NULL)) | 445 if (!deletable_insn_p (insn, fast, NULL)) |
449 break; | 446 break; |
450 | 447 |
623 struct df_link *defs; | 620 struct df_link *defs; |
624 df_ref *use_rec; | 621 df_ref *use_rec; |
625 | 622 |
626 FOR_ALL_BB (bb) | 623 FOR_ALL_BB (bb) |
627 { | 624 { |
628 for (use_rec = df_get_artificial_uses (bb->index); | 625 for (use_rec = df_get_artificial_uses (bb->index); |
629 *use_rec; use_rec++) | 626 *use_rec; use_rec++) |
630 for (defs = DF_REF_CHAIN (*use_rec); defs; defs = defs->next) | 627 for (defs = DF_REF_CHAIN (*use_rec); defs; defs = defs->next) |
631 if (! DF_REF_IS_ARTIFICIAL (defs->ref)) | 628 if (! DF_REF_IS_ARTIFICIAL (defs->ref)) |
632 mark_insn (DF_REF_INSN (defs->ref), false); | 629 mark_insn (DF_REF_INSN (defs->ref), false); |
633 } | 630 } |
639 static void | 636 static void |
640 mark_reg_dependencies (rtx insn) | 637 mark_reg_dependencies (rtx insn) |
641 { | 638 { |
642 struct df_link *defs; | 639 struct df_link *defs; |
643 df_ref *use_rec; | 640 df_ref *use_rec; |
641 | |
642 if (DEBUG_INSN_P (insn)) | |
643 return; | |
644 | 644 |
645 for (use_rec = DF_INSN_USES (insn); *use_rec; use_rec++) | 645 for (use_rec = DF_INSN_USES (insn); *use_rec; use_rec++) |
646 { | 646 { |
647 df_ref use = *use_rec; | 647 df_ref use = *use_rec; |
648 if (dump_file) | 648 if (dump_file) |
736 | 736 |
737 struct rtl_opt_pass pass_ud_rtl_dce = | 737 struct rtl_opt_pass pass_ud_rtl_dce = |
738 { | 738 { |
739 { | 739 { |
740 RTL_PASS, | 740 RTL_PASS, |
741 "dce", /* name */ | 741 "ud dce", /* name */ |
742 gate_ud_dce, /* gate */ | 742 gate_ud_dce, /* gate */ |
743 rest_of_handle_ud_dce, /* execute */ | 743 rest_of_handle_ud_dce, /* execute */ |
744 NULL, /* sub */ | 744 NULL, /* sub */ |
745 NULL, /* next */ | 745 NULL, /* next */ |
746 0, /* static_pass_number */ | 746 0, /* static_pass_number */ |
747 TV_DCE, /* tv_id */ | 747 TV_DCE, /* tv_id */ |
748 0, /* properties_required */ | 748 0, /* properties_required */ |
823 if (bitmap_bit_p (au, dregno)) | 823 if (bitmap_bit_p (au, dregno)) |
824 { | 824 { |
825 mark_insn (insn, true); | 825 mark_insn (insn, true); |
826 goto quickexit; | 826 goto quickexit; |
827 } | 827 } |
828 | 828 |
829 last = start + len; | 829 last = start + len; |
830 while (start < last) | 830 while (start < last) |
831 if (bitmap_bit_p (local_live, start++)) | 831 if (bitmap_bit_p (local_live, start++)) |
832 { | 832 { |
833 mark_insn (insn, true); | 833 mark_insn (insn, true); |
834 goto quickexit; | 834 goto quickexit; |
835 } | 835 } |
836 } | 836 } |
837 | 837 |
838 quickexit: | 838 quickexit: |
839 | 839 |
840 /* No matter if the instruction is needed or not, we remove | 840 /* No matter if the instruction is needed or not, we remove |
841 any regno in the defs from the live set. */ | 841 any regno in the defs from the live set. */ |
842 df_byte_lr_simulate_defs (insn, local_live); | 842 df_byte_lr_simulate_defs (insn, local_live); |
843 | 843 |
844 /* On the other hand, we do not allow the dead uses to set | 844 /* On the other hand, we do not allow the dead uses to set |
846 if (marked_insn_p (insn)) | 846 if (marked_insn_p (insn)) |
847 df_byte_lr_simulate_uses (insn, local_live); | 847 df_byte_lr_simulate_uses (insn, local_live); |
848 | 848 |
849 if (dump_file) | 849 if (dump_file) |
850 { | 850 { |
851 fprintf (dump_file, "finished processing insn %d live out = ", | 851 fprintf (dump_file, "finished processing insn %d live out = ", |
852 INSN_UID (insn)); | 852 INSN_UID (insn)); |
853 df_print_byte_regset (dump_file, local_live); | 853 df_print_byte_regset (dump_file, local_live); |
854 } | 854 } |
855 } | 855 } |
856 | 856 |
857 df_byte_lr_simulate_artificial_refs_at_top (bb, local_live); | 857 df_byte_lr_simulate_artificial_refs_at_top (bb, local_live); |
858 | 858 |
859 block_changed = !bitmap_equal_p (local_live, DF_BYTE_LR_IN (bb)); | 859 block_changed = !bitmap_equal_p (local_live, DF_BYTE_LR_IN (bb)); |
860 if (block_changed) | 860 if (block_changed) |
861 bitmap_copy (DF_BYTE_LR_IN (bb), local_live); | 861 bitmap_copy (DF_BYTE_LR_IN (bb), local_live); |
911 || bitmap_bit_p (au, DF_REF_REGNO (*def_rec))) | 911 || bitmap_bit_p (au, DF_REF_REGNO (*def_rec))) |
912 { | 912 { |
913 needed = true; | 913 needed = true; |
914 break; | 914 break; |
915 } | 915 } |
916 | 916 |
917 if (needed) | 917 if (needed) |
918 mark_insn (insn, true); | 918 mark_insn (insn, true); |
919 | 919 |
920 /* No matter if the instruction is needed or not, we remove | 920 /* No matter if the instruction is needed or not, we remove |
921 any regno in the defs from the live set. */ | 921 any regno in the defs from the live set. */ |
922 df_simulate_defs (insn, local_live); | 922 df_simulate_defs (insn, local_live); |
923 | 923 |
924 /* On the other hand, we do not allow the dead uses to set | 924 /* On the other hand, we do not allow the dead uses to set |
925 anything in local_live. */ | 925 anything in local_live. */ |
926 if (marked_insn_p (insn)) | 926 if (marked_insn_p (insn)) |
927 df_simulate_uses (insn, local_live); | 927 df_simulate_uses (insn, local_live); |
928 } | 928 } |
929 | 929 |
930 df_simulate_finalize_backwards (bb, local_live); | 930 df_simulate_finalize_backwards (bb, local_live); |
931 | 931 |
932 block_changed = !bitmap_equal_p (local_live, DF_LR_IN (bb)); | 932 block_changed = !bitmap_equal_p (local_live, DF_LR_IN (bb)); |
933 if (block_changed) | 933 if (block_changed) |
934 bitmap_copy (DF_LR_IN (bb), local_live); | 934 bitmap_copy (DF_LR_IN (bb), local_live); |
984 bitmap_set_bit (processed, index); | 984 bitmap_set_bit (processed, index); |
985 continue; | 985 continue; |
986 } | 986 } |
987 | 987 |
988 if (byte_level) | 988 if (byte_level) |
989 local_changed | 989 local_changed |
990 = byte_dce_process_block (bb, bitmap_bit_p (redo_out, index), | 990 = byte_dce_process_block (bb, bitmap_bit_p (redo_out, index), |
991 bb_has_eh_pred (bb) ? au_eh : au); | 991 bb_has_eh_pred (bb) ? au_eh : au); |
992 else | 992 else |
993 local_changed | 993 local_changed |
994 = dce_process_block (bb, bitmap_bit_p (redo_out, index), | 994 = dce_process_block (bb, bitmap_bit_p (redo_out, index), |
995 bb_has_eh_pred (bb) ? au_eh : au); | 995 bb_has_eh_pred (bb) ? au_eh : au); |
996 bitmap_set_bit (processed, index); | 996 bitmap_set_bit (processed, index); |
997 | 997 |
998 if (local_changed) | 998 if (local_changed) |
999 { | 999 { |
1000 edge e; | 1000 edge e; |
1001 edge_iterator ei; | 1001 edge_iterator ei; |
1002 FOR_EACH_EDGE (e, ei, bb->preds) | 1002 FOR_EACH_EDGE (e, ei, bb->preds) |
1008 global_changed = true; | 1008 global_changed = true; |
1009 else | 1009 else |
1010 bitmap_set_bit (redo_out, e->src->index); | 1010 bitmap_set_bit (redo_out, e->src->index); |
1011 } | 1011 } |
1012 } | 1012 } |
1013 | 1013 |
1014 if (global_changed) | 1014 if (global_changed) |
1015 { | 1015 { |
1016 /* Turn off the RUN_DCE flag to prevent recursive calls to | 1016 /* Turn off the RUN_DCE flag to prevent recursive calls to |
1017 dce. */ | 1017 dce. */ |
1018 int old_flag = df_clear_flags (DF_LR_RUN_DCE); | 1018 int old_flag = df_clear_flags (DF_LR_RUN_DCE); |
1021 the cheap. */ | 1021 the cheap. */ |
1022 delete_unmarked_insns (); | 1022 delete_unmarked_insns (); |
1023 sbitmap_zero (marked); | 1023 sbitmap_zero (marked); |
1024 bitmap_clear (processed); | 1024 bitmap_clear (processed); |
1025 bitmap_clear (redo_out); | 1025 bitmap_clear (redo_out); |
1026 | 1026 |
1027 /* We do not need to rescan any instructions. We only need | 1027 /* We do not need to rescan any instructions. We only need |
1028 to redo the dataflow equations for the blocks that had a | 1028 to redo the dataflow equations for the blocks that had a |
1029 change at the top of the block. Then we need to redo the | 1029 change at the top of the block. Then we need to redo the |
1030 iteration. */ | 1030 iteration. */ |
1031 if (byte_level) | 1031 if (byte_level) |
1032 df_analyze_problem (df_byte_lr, all_blocks, postorder, n_blocks); | 1032 df_analyze_problem (df_byte_lr, all_blocks, postorder, n_blocks); |
1033 else | 1033 else |
1034 df_analyze_problem (df_lr, all_blocks, postorder, n_blocks); | 1034 df_analyze_problem (df_lr, all_blocks, postorder, n_blocks); |
1035 | 1035 |
1088 if (flag_dce) | 1088 if (flag_dce) |
1089 { | 1089 { |
1090 /* If dce is able to delete something, it has to happen | 1090 /* If dce is able to delete something, it has to happen |
1091 immediately. Otherwise there will be problems handling the | 1091 immediately. Otherwise there will be problems handling the |
1092 eq_notes. */ | 1092 eq_notes. */ |
1093 enum df_changeable_flags old_flags | 1093 int old_flags = |
1094 = df_clear_flags (DF_DEFER_INSN_RESCAN + DF_NO_INSN_RESCAN); | 1094 df_clear_flags (DF_DEFER_INSN_RESCAN + DF_NO_INSN_RESCAN); |
1095 | 1095 |
1096 df_in_progress = true; | 1096 df_in_progress = true; |
1097 rest_of_handle_fast_dce (); | 1097 rest_of_handle_fast_dce (); |
1098 df_in_progress = false; | 1098 df_in_progress = false; |
1099 | 1099 |
1100 df_set_flags (old_flags); | 1100 df_set_flags (old_flags); |
1121 | 1121 |
1122 struct rtl_opt_pass pass_fast_rtl_dce = | 1122 struct rtl_opt_pass pass_fast_rtl_dce = |
1123 { | 1123 { |
1124 { | 1124 { |
1125 RTL_PASS, | 1125 RTL_PASS, |
1126 "dce", /* name */ | 1126 "rtl dce", /* name */ |
1127 gate_fast_dce, /* gate */ | 1127 gate_fast_dce, /* gate */ |
1128 rest_of_handle_fast_dce, /* execute */ | 1128 rest_of_handle_fast_dce, /* execute */ |
1129 NULL, /* sub */ | 1129 NULL, /* sub */ |
1130 NULL, /* next */ | 1130 NULL, /* next */ |
1131 0, /* static_pass_number */ | 1131 0, /* static_pass_number */ |