comparison gcc/dse.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
471 471
472 /* True if the base of this group is either the frame_pointer or 472 /* True if the base of this group is either the frame_pointer or
473 hard_frame_pointer. */ 473 hard_frame_pointer. */
474 bool frame_related; 474 bool frame_related;
475 475
476 /* A mem wrapped around the base pointer for the group in order to 476 /* A mem wrapped around the base pointer for the group in order to do
477 do read dependency. */ 477 read dependency. It must be given BLKmode in order to encompass all
478 the possible offsets from the base. */
478 rtx base_mem; 479 rtx base_mem;
479 480
480 /* Canonized version of base_mem's address. */ 481 /* Canonized version of base_mem's address. */
481 rtx canon_base_addr; 482 rtx canon_base_addr;
482 483
703 if (gi == NULL) 704 if (gi == NULL)
704 { 705 {
705 *slot = gi = (group_info_t) pool_alloc (rtx_group_info_pool); 706 *slot = gi = (group_info_t) pool_alloc (rtx_group_info_pool);
706 gi->rtx_base = base; 707 gi->rtx_base = base;
707 gi->id = rtx_group_next_id++; 708 gi->id = rtx_group_next_id++;
708 gi->base_mem = gen_rtx_MEM (QImode, base); 709 gi->base_mem = gen_rtx_MEM (BLKmode, base);
709 gi->canon_base_addr = canon_rtx (base); 710 gi->canon_base_addr = canon_rtx (base);
710 gi->store1_n = BITMAP_ALLOC (NULL); 711 gi->store1_n = BITMAP_ALLOC (NULL);
711 gi->store1_p = BITMAP_ALLOC (NULL); 712 gi->store1_p = BITMAP_ALLOC (NULL);
712 gi->store2_n = BITMAP_ALLOC (NULL); 713 gi->store2_n = BITMAP_ALLOC (NULL);
713 gi->store2_p = BITMAP_ALLOC (NULL); 714 gi->store2_p = BITMAP_ALLOC (NULL);
803 insn_info->cannot_delete = true; 804 insn_info->cannot_delete = true;
804 insn_info->contains_cselib_groups = false; 805 insn_info->contains_cselib_groups = false;
805 insn_info->store_rec = NULL; 806 insn_info->store_rec = NULL;
806 } 807 }
807 808
808 809 /* Callback for for_each_inc_dec that emits an INSN that sets DEST to
809 struct insn_size { 810 SRC + SRCOFF before insn ARG. */
810 int size;
811 rtx insn;
812 };
813
814
815 /* Add an insn to do the add inside a x if it is a
816 PRE/POST-INC/DEC/MODIFY. D is an structure containing the insn and
817 the size of the mode of the MEM that this is inside of. */
818 811
819 static int 812 static int
820 replace_inc_dec (rtx *r, void *d) 813 emit_inc_dec_insn_before (rtx mem ATTRIBUTE_UNUSED,
821 { 814 rtx op ATTRIBUTE_UNUSED,
822 rtx x = *r; 815 rtx dest, rtx src, rtx srcoff, void *arg)
823 struct insn_size *data = (struct insn_size *)d; 816 {
824 switch (GET_CODE (x)) 817 rtx insn = (rtx)arg;
825 { 818
826 case PRE_INC: 819 if (srcoff)
827 case POST_INC: 820 src = gen_rtx_PLUS (GET_MODE (src), src, srcoff);
828 { 821
829 rtx r1 = XEXP (x, 0); 822 /* We can reuse all operands without copying, because we are about
830 rtx c = gen_int_mode (data->size, GET_MODE (r1)); 823 to delete the insn that contained it. */
831 emit_insn_before (gen_rtx_SET (VOIDmode, r1, 824
832 gen_rtx_PLUS (GET_MODE (r1), r1, c)), 825 emit_insn_before (gen_rtx_SET (VOIDmode, dest, src), insn);
833 data->insn); 826
834 return -1; 827 return -1;
835 }
836
837 case PRE_DEC:
838 case POST_DEC:
839 {
840 rtx r1 = XEXP (x, 0);
841 rtx c = gen_int_mode (-data->size, GET_MODE (r1));
842 emit_insn_before (gen_rtx_SET (VOIDmode, r1,
843 gen_rtx_PLUS (GET_MODE (r1), r1, c)),
844 data->insn);
845 return -1;
846 }
847
848 case PRE_MODIFY:
849 case POST_MODIFY:
850 {
851 /* We can reuse the add because we are about to delete the
852 insn that contained it. */
853 rtx add = XEXP (x, 0);
854 rtx r1 = XEXP (add, 0);
855 emit_insn_before (gen_rtx_SET (VOIDmode, r1, add), data->insn);
856 return -1;
857 }
858
859 default:
860 return 0;
861 }
862 }
863
864
865 /* If X is a MEM, check the address to see if it is PRE/POST-INC/DEC/MODIFY
866 and generate an add to replace that. */
867
868 static int
869 replace_inc_dec_mem (rtx *r, void *d)
870 {
871 rtx x = *r;
872 if (x != NULL_RTX && MEM_P (x))
873 {
874 struct insn_size data;
875
876 data.size = GET_MODE_SIZE (GET_MODE (x));
877 data.insn = (rtx) d;
878
879 for_each_rtx (&XEXP (x, 0), replace_inc_dec, &data);
880
881 return -1;
882 }
883 return 0;
884 } 828 }
885 829
886 /* Before we delete INSN, make sure that the auto inc/dec, if it is 830 /* Before we delete INSN, make sure that the auto inc/dec, if it is
887 there, is split into a separate insn. */ 831 there, is split into a separate insn. */
888 832
889 static void 833 void
890 check_for_inc_dec (rtx insn) 834 check_for_inc_dec (rtx insn)
891 { 835 {
892 rtx note = find_reg_note (insn, REG_INC, NULL_RTX); 836 rtx note = find_reg_note (insn, REG_INC, NULL_RTX);
893 if (note) 837 if (note)
894 for_each_rtx (&insn, replace_inc_dec_mem, insn); 838 for_each_inc_dec (&insn, emit_inc_dec_insn_before, insn);
895 } 839 }
896 840
897 841
898 /* Delete the insn and free all of the fields inside INSN_INFO. */ 842 /* Delete the insn and free all of the fields inside INSN_INFO. */
899 843
961 store1 = group->store1_p; 905 store1 = group->store1_p;
962 store2 = group->store2_p; 906 store2 = group->store2_p;
963 ai = i; 907 ai = i;
964 } 908 }
965 909
966 if (bitmap_bit_p (store1, ai)) 910 if (!bitmap_set_bit (store1, ai))
967 bitmap_set_bit (store2, ai); 911 bitmap_set_bit (store2, ai);
968 else 912 else
969 { 913 {
970 bitmap_set_bit (store1, ai);
971 if (i < 0) 914 if (i < 0)
972 { 915 {
973 if (group->offset_map_size_n < ai) 916 if (group->offset_map_size_n < ai)
974 group->offset_map_size_n = ai; 917 group->offset_map_size_n = ai;
975 } 918 }
1105 } 1048 }
1106 } 1049 }
1107 1050
1108 *alias_set_out = 0; 1051 *alias_set_out = 0;
1109 1052
1110 cselib_lookup (mem_address, address_mode, 1); 1053 cselib_lookup (mem_address, address_mode, 1, GET_MODE (mem));
1111 1054
1112 if (dump_file) 1055 if (dump_file)
1113 { 1056 {
1114 fprintf (dump_file, " mem: "); 1057 fprintf (dump_file, " mem: ");
1115 print_inline_rtx (dump_file, mem_address, 0); 1058 print_inline_rtx (dump_file, mem_address, 0);
1185 *group_id = group->id; 1128 *group_id = group->id;
1186 return true; 1129 return true;
1187 } 1130 }
1188 } 1131 }
1189 1132
1190 *base = cselib_lookup (address, address_mode, true); 1133 *base = cselib_lookup (address, address_mode, true, GET_MODE (mem));
1191 *group_id = -1; 1134 *group_id = -1;
1192 1135
1193 if (*base == NULL) 1136 if (*base == NULL)
1194 { 1137 {
1195 if (dump_file) 1138 if (dump_file)
1230 static inline void 1173 static inline void
1231 set_position_unneeded (store_info_t s_info, int pos) 1174 set_position_unneeded (store_info_t s_info, int pos)
1232 { 1175 {
1233 if (__builtin_expect (s_info->is_large, false)) 1176 if (__builtin_expect (s_info->is_large, false))
1234 { 1177 {
1235 if (!bitmap_bit_p (s_info->positions_needed.large.bmap, pos)) 1178 if (bitmap_set_bit (s_info->positions_needed.large.bmap, pos))
1236 { 1179 s_info->positions_needed.large.count++;
1237 s_info->positions_needed.large.count++;
1238 bitmap_set_bit (s_info->positions_needed.large.bmap, pos);
1239 }
1240 } 1180 }
1241 else 1181 else
1242 s_info->positions_needed.small_bitmask 1182 s_info->positions_needed.small_bitmask
1243 &= ~(((unsigned HOST_WIDE_INT) 1) << pos); 1183 &= ~(((unsigned HOST_WIDE_INT) 1) << pos);
1244 } 1184 }
1391 bitmap store1 = clear_alias_group->store1_p; 1331 bitmap store1 = clear_alias_group->store1_p;
1392 bitmap store2 = clear_alias_group->store2_p; 1332 bitmap store2 = clear_alias_group->store2_p;
1393 1333
1394 gcc_assert (GET_MODE (mem) != BLKmode); 1334 gcc_assert (GET_MODE (mem) != BLKmode);
1395 1335
1396 if (bitmap_bit_p (store1, spill_alias_set)) 1336 if (!bitmap_set_bit (store1, spill_alias_set))
1397 bitmap_set_bit (store2, spill_alias_set); 1337 bitmap_set_bit (store2, spill_alias_set);
1398 else
1399 bitmap_set_bit (store1, spill_alias_set);
1400 1338
1401 if (clear_alias_group->offset_map_size_p < spill_alias_set) 1339 if (clear_alias_group->offset_map_size_p < spill_alias_set)
1402 clear_alias_group->offset_map_size_p = spill_alias_set; 1340 clear_alias_group->offset_map_size_p = spill_alias_set;
1403 1341
1404 store_info = (store_info_t) pool_alloc (rtx_store_info_pool); 1342 store_info = (store_info_t) pool_alloc (rtx_store_info_pool);
2324 for (idx = 0; 2262 for (idx = 0;
2325 arg != void_list_node && idx < nargs; 2263 arg != void_list_node && idx < nargs;
2326 arg = TREE_CHAIN (arg), idx++) 2264 arg = TREE_CHAIN (arg), idx++)
2327 { 2265 {
2328 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg)); 2266 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
2329 rtx reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1), link, tmp; 2267 rtx reg, link, tmp;
2268 reg = targetm.calls.function_arg (&args_so_far, mode, NULL_TREE, true);
2330 if (!reg || !REG_P (reg) || GET_MODE (reg) != mode 2269 if (!reg || !REG_P (reg) || GET_MODE (reg) != mode
2331 || GET_MODE_CLASS (mode) != MODE_INT) 2270 || GET_MODE_CLASS (mode) != MODE_INT)
2332 return false; 2271 return false;
2333 2272
2334 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); 2273 for (link = CALL_INSN_FUNCTION_USAGE (call_insn);
2358 tmp = GEN_INT (trunc_int_for_mode (INTVAL (tmp), mode)); 2297 tmp = GEN_INT (trunc_int_for_mode (INTVAL (tmp), mode));
2359 } 2298 }
2360 if (tmp) 2299 if (tmp)
2361 args[idx] = tmp; 2300 args[idx] = tmp;
2362 2301
2363 FUNCTION_ARG_ADVANCE (args_so_far, mode, NULL_TREE, 1); 2302 targetm.calls.function_arg_advance (&args_so_far, mode, NULL_TREE, true);
2364 } 2303 }
2365 if (arg != void_list_node || idx != nargs) 2304 if (arg != void_list_node || idx != nargs)
2366 return false; 2305 return false;
2367 return true; 2306 return true;
2368 } 2307 }
2775 dse_step2_init (void) 2714 dse_step2_init (void)
2776 { 2715 {
2777 unsigned int i; 2716 unsigned int i;
2778 group_info_t group; 2717 group_info_t group;
2779 2718
2780 for (i = 0; VEC_iterate (group_info_t, rtx_group_vec, i, group); i++) 2719 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
2781 { 2720 {
2782 /* For all non stack related bases, we only consider a store to 2721 /* For all non stack related bases, we only consider a store to
2783 be deletable if there are two or more stores for that 2722 be deletable if there are two or more stores for that
2784 position. This is because it takes one store to make the 2723 position. This is because it takes one store to make the
2785 other store redundant. However, for the stores that are 2724 other store redundant. However, for the stores that are
2827 group_info_t group; 2766 group_info_t group;
2828 /* Position 0 is unused because 0 is used in the maps to mean 2767 /* Position 0 is unused because 0 is used in the maps to mean
2829 unused. */ 2768 unused. */
2830 current_position = 1; 2769 current_position = 1;
2831 2770
2832 for (i = 0; VEC_iterate (group_info_t, rtx_group_vec, i, group); i++) 2771 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
2833 { 2772 {
2834 bitmap_iterator bi; 2773 bitmap_iterator bi;
2835 unsigned int j; 2774 unsigned int j;
2836 2775
2837 if (group == clear_alias_group) 2776 if (group == clear_alias_group)
3070 group_info_t group; 3009 group_info_t group;
3071 3010
3072 /* If this insn reads the frame, kill all the frame related stores. */ 3011 /* If this insn reads the frame, kill all the frame related stores. */
3073 if (insn_info->frame_read) 3012 if (insn_info->frame_read)
3074 { 3013 {
3075 for (i = 0; VEC_iterate (group_info_t, rtx_group_vec, i, group); i++) 3014 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
3076 if (group->process_globally && group->frame_related) 3015 if (group->process_globally && group->frame_related)
3077 { 3016 {
3078 if (kill) 3017 if (kill)
3079 bitmap_ior_into (kill, group->group_kill); 3018 bitmap_ior_into (kill, group->group_kill);
3080 bitmap_and_compl_into (gen, group->group_kill); 3019 bitmap_and_compl_into (gen, group->group_kill);
3081 } 3020 }
3082 } 3021 }
3083 3022
3084 while (read_info) 3023 while (read_info)
3085 { 3024 {
3086 for (i = 0; VEC_iterate (group_info_t, rtx_group_vec, i, group); i++) 3025 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
3087 { 3026 {
3088 if (group->process_globally) 3027 if (group->process_globally)
3089 { 3028 {
3090 if (i == read_info->group_id) 3029 if (i == read_info->group_id)
3091 { 3030 {
3121 read. Anything with a constant base cannot alias 3060 read. Anything with a constant base cannot alias
3122 something else with a different constant 3061 something else with a different constant
3123 base. */ 3062 base. */
3124 if ((read_info->group_id < 0) 3063 if ((read_info->group_id < 0)
3125 && canon_true_dependence (group->base_mem, 3064 && canon_true_dependence (group->base_mem,
3126 QImode, 3065 GET_MODE (group->base_mem),
3127 group->canon_base_addr, 3066 group->canon_base_addr,
3128 read_info->mem, NULL_RTX, 3067 read_info->mem, NULL_RTX,
3129 rtx_varies_p)) 3068 rtx_varies_p))
3130 { 3069 {
3131 if (kill) 3070 if (kill)
3262 if (stores_off_frame_dead_at_return) 3201 if (stores_off_frame_dead_at_return)
3263 { 3202 {
3264 unsigned int i; 3203 unsigned int i;
3265 group_info_t group; 3204 group_info_t group;
3266 3205
3267 for (i = 0; VEC_iterate (group_info_t, rtx_group_vec, i, group); i++) 3206 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
3268 { 3207 {
3269 if (group->process_globally && group->frame_related) 3208 if (group->process_globally && group->frame_related)
3270 bitmap_ior_into (bb_info->gen, group->group_kill); 3209 bitmap_ior_into (bb_info->gen, group->group_kill);
3271 } 3210 }
3272 } 3211 }
3344 { 3283 {
3345 unsigned int j; 3284 unsigned int j;
3346 group_info_t group; 3285 group_info_t group;
3347 3286
3348 all_ones = BITMAP_ALLOC (NULL); 3287 all_ones = BITMAP_ALLOC (NULL);
3349 for (j = 0; VEC_iterate (group_info_t, rtx_group_vec, j, group); j++) 3288 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, j, group)
3350 bitmap_ior_into (all_ones, group->group_kill); 3289 bitmap_ior_into (all_ones, group->group_kill);
3351 } 3290 }
3352 if (!bb_info->out) 3291 if (!bb_info->out)
3353 { 3292 {
3354 bb_info->out = BITMAP_ALLOC (NULL); 3293 bb_info->out = BITMAP_ALLOC (NULL);
3394 3333
3395 /* Propagate the information from the in set of the dest of E to the 3334 /* Propagate the information from the in set of the dest of E to the
3396 out set of the src of E. If the various in or out sets are not 3335 out set of the src of E. If the various in or out sets are not
3397 there, that means they are all ones. */ 3336 there, that means they are all ones. */
3398 3337
3399 static void 3338 static bool
3400 dse_confluence_n (edge e) 3339 dse_confluence_n (edge e)
3401 { 3340 {
3402 bb_info_t src_info = bb_table[e->src->index]; 3341 bb_info_t src_info = bb_table[e->src->index];
3403 bb_info_t dest_info = bb_table[e->dest->index]; 3342 bb_info_t dest_info = bb_table[e->dest->index];
3404 3343
3410 { 3349 {
3411 src_info->out = BITMAP_ALLOC (NULL); 3350 src_info->out = BITMAP_ALLOC (NULL);
3412 bitmap_copy (src_info->out, dest_info->in); 3351 bitmap_copy (src_info->out, dest_info->in);
3413 } 3352 }
3414 } 3353 }
3354 return true;
3415 } 3355 }
3416 3356
3417 3357
3418 /* Propagate the info from the out to the in set of BB_INDEX's basic 3358 /* Propagate the info from the out to the in set of BB_INDEX's basic
3419 block. There are three cases: 3359 block. There are three cases:
3745 { 3685 {
3746 unsigned int i; 3686 unsigned int i;
3747 group_info_t group; 3687 group_info_t group;
3748 basic_block bb; 3688 basic_block bb;
3749 3689
3750 for (i = 0; VEC_iterate (group_info_t, rtx_group_vec, i, group); i++) 3690 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
3751 { 3691 {
3752 free (group->offset_map_n); 3692 free (group->offset_map_n);
3753 free (group->offset_map_p); 3693 free (group->offset_map_p);
3754 BITMAP_FREE (group->store1_n); 3694 BITMAP_FREE (group->store1_n);
3755 BITMAP_FREE (group->store1_p); 3695 BITMAP_FREE (group->store1_p);