Mercurial > hg > CbC > CbC_gcc
comparison gcc/regmove.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 | b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
42 #include "toplev.h" | 42 #include "toplev.h" |
43 #include "reload.h" | 43 #include "reload.h" |
44 #include "timevar.h" | 44 #include "timevar.h" |
45 #include "tree-pass.h" | 45 #include "tree-pass.h" |
46 #include "df.h" | 46 #include "df.h" |
47 | 47 #include "ira.h" |
48 static int perhaps_ends_bb_p (rtx); | 48 |
49 static int optimize_reg_copy_1 (rtx, rtx, rtx); | 49 static int optimize_reg_copy_1 (rtx, rtx, rtx); |
50 static void optimize_reg_copy_2 (rtx, rtx, rtx); | 50 static void optimize_reg_copy_2 (rtx, rtx, rtx); |
51 static void optimize_reg_copy_3 (rtx, rtx, rtx); | 51 static void optimize_reg_copy_3 (rtx, rtx, rtx); |
52 static void copy_src_to_dest (rtx, rtx, rtx); | 52 static void copy_src_to_dest (rtx, rtx, rtx); |
53 | 53 |
54 enum match_use | |
55 { | |
56 READ, | |
57 WRITE, | |
58 READWRITE | |
59 }; | |
60 | |
54 struct match { | 61 struct match { |
55 int with[MAX_RECOG_OPERANDS]; | 62 int with[MAX_RECOG_OPERANDS]; |
56 enum { READ, WRITE, READWRITE } use[MAX_RECOG_OPERANDS]; | 63 enum match_use use[MAX_RECOG_OPERANDS]; |
57 int commutative[MAX_RECOG_OPERANDS]; | 64 int commutative[MAX_RECOG_OPERANDS]; |
58 int early_clobber[MAX_RECOG_OPERANDS]; | 65 int early_clobber[MAX_RECOG_OPERANDS]; |
59 }; | 66 }; |
60 | 67 |
61 static int find_matches (rtx, struct match *); | 68 static int find_matches (rtx, struct match *); |
62 static int regclass_compatible_p (int, int); | |
63 static int fixup_match_2 (rtx, rtx, rtx, rtx); | 69 static int fixup_match_2 (rtx, rtx, rtx, rtx); |
64 | 70 |
65 /* Return nonzero if registers with CLASS1 and CLASS2 can be merged without | 71 /* Return nonzero if registers with CLASS1 and CLASS2 can be merged without |
66 causing too much register allocation problems. */ | 72 causing too much register allocation problems. */ |
67 static int | 73 static int |
68 regclass_compatible_p (int class0, int class1) | 74 regclass_compatible_p (enum reg_class class0, enum reg_class class1) |
69 { | 75 { |
70 return (class0 == class1 | 76 return (class0 == class1 |
71 || (reg_class_subset_p (class0, class1) | 77 || (reg_class_subset_p (class0, class1) |
72 && ! CLASS_LIKELY_SPILLED_P (class0)) | 78 && ! CLASS_LIKELY_SPILLED_P (class0)) |
73 || (reg_class_subset_p (class1, class0) | 79 || (reg_class_subset_p (class1, class0) |
98 if (code == MEM && XEXP (x, 0) == reg && plusconst == 0) | 104 if (code == MEM && XEXP (x, 0) == reg && plusconst == 0) |
99 return x; | 105 return x; |
100 | 106 |
101 if (code == MEM && GET_CODE (XEXP (x, 0)) == PLUS | 107 if (code == MEM && GET_CODE (XEXP (x, 0)) == PLUS |
102 && XEXP (XEXP (x, 0), 0) == reg | 108 && XEXP (XEXP (x, 0), 0) == reg |
103 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | 109 && CONST_INT_P (XEXP (XEXP (x, 0), 1)) |
104 && INTVAL (XEXP (XEXP (x, 0), 1)) == plusconst) | 110 && INTVAL (XEXP (XEXP (x, 0), 1)) == plusconst) |
105 return x; | 111 return x; |
106 | 112 |
107 if (code == SIGN_EXTRACT || code == ZERO_EXTRACT) | 113 if (code == SIGN_EXTRACT || code == ZERO_EXTRACT) |
108 { | 114 { |
177 validate_change | 183 validate_change |
178 (inc_insn, | 184 (inc_insn, |
179 &SET_SRC (inc_insn_set), | 185 &SET_SRC (inc_insn_set), |
180 XEXP (SET_SRC (inc_insn_set), 0), 1); | 186 XEXP (SET_SRC (inc_insn_set), 0), 1); |
181 validate_change (insn, &XEXP (use, 0), | 187 validate_change (insn, &XEXP (use, 0), |
182 gen_rtx_fmt_e (inc_code, Pmode, reg), 1); | 188 gen_rtx_fmt_e (inc_code, |
189 GET_MODE (XEXP (use, 0)), reg), | |
190 1); | |
183 if (apply_change_group ()) | 191 if (apply_change_group ()) |
184 { | 192 { |
185 /* If there is a REG_DEAD note on this insn, we must | 193 /* If there is a REG_DEAD note on this insn, we must |
186 change this not to REG_UNUSED meaning that the register | 194 change this not to REG_UNUSED meaning that the register |
187 is set, but the value is dead. Failure to do so will | 195 is set, but the value is dead. Failure to do so will |
188 result in sched1 dying -- when it recomputes lifetime | 196 result in sched1 dying -- when it recomputes lifetime |
189 information, the number of REG_DEAD notes will have | 197 information, the number of REG_DEAD notes will have |
190 changed. */ | 198 changed. */ |
191 rtx note = find_reg_note (insn, REG_DEAD, reg); | 199 rtx note = find_reg_note (insn, REG_DEAD, reg); |
192 if (note) | 200 if (note) |
193 PUT_MODE (note, REG_UNUSED); | 201 PUT_REG_NOTE_KIND (note, REG_UNUSED); |
194 | 202 |
195 add_reg_note (insn, REG_INC, reg); | 203 add_reg_note (insn, REG_INC, reg); |
196 | 204 |
197 if (! inc_insn_set) | 205 if (! inc_insn_set) |
198 delete_insn (inc_insn); | 206 delete_insn (inc_insn); |
206 #endif | 214 #endif |
207 | 215 |
208 | 216 |
209 static int *regno_src_regno; | 217 static int *regno_src_regno; |
210 | 218 |
211 | |
212 /* Return 1 if INSN might end a basic block. */ | |
213 | |
214 static int perhaps_ends_bb_p (rtx insn) | |
215 { | |
216 switch (GET_CODE (insn)) | |
217 { | |
218 case CODE_LABEL: | |
219 case JUMP_INSN: | |
220 /* These always end a basic block. */ | |
221 return 1; | |
222 | |
223 case CALL_INSN: | |
224 /* A CALL_INSN might be the last insn of a basic block, if it is inside | |
225 an EH region or if there are nonlocal gotos. Note that this test is | |
226 very conservative. */ | |
227 if (nonlocal_goto_handler_labels) | |
228 return 1; | |
229 /* Fall through. */ | |
230 default: | |
231 return can_throw_internal (insn); | |
232 } | |
233 } | |
234 | |
235 /* INSN is a copy from SRC to DEST, both registers, and SRC does not die | 219 /* INSN is a copy from SRC to DEST, both registers, and SRC does not die |
236 in INSN. | 220 in INSN. |
237 | 221 |
238 Search forward to see if SRC dies before either it or DEST is modified, | 222 Search forward to see if SRC dies before either it or DEST is modified, |
239 but don't scan past the end of a basic block. If so, we can replace SRC | 223 but don't scan past the end of a basic block. If so, we can replace SRC |
249 rtx p, q; | 233 rtx p, q; |
250 rtx note; | 234 rtx note; |
251 rtx dest_death = 0; | 235 rtx dest_death = 0; |
252 int sregno = REGNO (src); | 236 int sregno = REGNO (src); |
253 int dregno = REGNO (dest); | 237 int dregno = REGNO (dest); |
238 basic_block bb = BLOCK_FOR_INSN (insn); | |
254 | 239 |
255 /* We don't want to mess with hard regs if register classes are small. */ | 240 /* We don't want to mess with hard regs if register classes are small. */ |
256 if (sregno == dregno | 241 if (sregno == dregno |
257 || (SMALL_REGISTER_CLASSES | 242 || (SMALL_REGISTER_CLASSES |
258 && (sregno < FIRST_PSEUDO_REGISTER | 243 && (sregno < FIRST_PSEUDO_REGISTER |
262 || sregno == STACK_POINTER_REGNUM || dregno == STACK_POINTER_REGNUM) | 247 || sregno == STACK_POINTER_REGNUM || dregno == STACK_POINTER_REGNUM) |
263 return 0; | 248 return 0; |
264 | 249 |
265 for (p = NEXT_INSN (insn); p; p = NEXT_INSN (p)) | 250 for (p = NEXT_INSN (insn); p; p = NEXT_INSN (p)) |
266 { | 251 { |
267 /* ??? We can't scan past the end of a basic block without updating | 252 if (! INSN_P (p)) |
268 the register lifetime info (REG_DEAD/basic_block_live_at_start). */ | 253 continue; |
269 if (perhaps_ends_bb_p (p)) | 254 if (BLOCK_FOR_INSN (p) != bb) |
270 break; | 255 break; |
271 else if (! INSN_P (p)) | |
272 continue; | |
273 | 256 |
274 if (reg_set_p (src, p) || reg_set_p (dest, p) | 257 if (reg_set_p (src, p) || reg_set_p (dest, p) |
275 /* If SRC is an asm-declared register, it must not be replaced | 258 /* If SRC is an asm-declared register, it must not be replaced |
276 in any asm. Unfortunately, the REG_EXPR tree for the asm | 259 in any asm. Unfortunately, the REG_EXPR tree for the asm |
277 variable may be absent in the SRC rtx, so we can't check the | 260 variable may be absent in the SRC rtx, so we can't check the |
321 present in the insn, so fail in that combination | 304 present in the insn, so fail in that combination |
322 of cases. */ | 305 of cases. */ |
323 if (sregno < FIRST_PSEUDO_REGISTER | 306 if (sregno < FIRST_PSEUDO_REGISTER |
324 && reg_mentioned_p (dest, PATTERN (q))) | 307 && reg_mentioned_p (dest, PATTERN (q))) |
325 failed = 1; | 308 failed = 1; |
326 | 309 |
327 /* Attempt to replace all uses. */ | 310 /* Attempt to replace all uses. */ |
328 else if (!validate_replace_rtx (src, dest, q)) | 311 else if (!validate_replace_rtx (src, dest, q)) |
329 failed = 1; | 312 failed = 1; |
330 | 313 |
331 /* If this succeeded, but some part of the register | 314 /* If this succeeded, but some part of the register |
339 } | 322 } |
340 | 323 |
341 /* For SREGNO, count the total number of insns scanned. | 324 /* For SREGNO, count the total number of insns scanned. |
342 For DREGNO, count the total number of insns scanned after | 325 For DREGNO, count the total number of insns scanned after |
343 passing the death note for DREGNO. */ | 326 passing the death note for DREGNO. */ |
344 s_length++; | 327 if (!DEBUG_INSN_P (p)) |
345 if (dest_death) | 328 { |
346 d_length++; | 329 s_length++; |
330 if (dest_death) | |
331 d_length++; | |
332 } | |
347 | 333 |
348 /* If the insn in which SRC dies is a CALL_INSN, don't count it | 334 /* If the insn in which SRC dies is a CALL_INSN, don't count it |
349 as a call that has been crossed. Otherwise, count it. */ | 335 as a call that has been crossed. Otherwise, count it. */ |
350 if (q != p && CALL_P (q)) | 336 if (q != p && CALL_P (q)) |
351 { | 337 { |
455 { | 441 { |
456 rtx p, q; | 442 rtx p, q; |
457 rtx set; | 443 rtx set; |
458 int sregno = REGNO (src); | 444 int sregno = REGNO (src); |
459 int dregno = REGNO (dest); | 445 int dregno = REGNO (dest); |
446 basic_block bb = BLOCK_FOR_INSN (insn); | |
460 | 447 |
461 for (p = NEXT_INSN (insn); p; p = NEXT_INSN (p)) | 448 for (p = NEXT_INSN (insn); p; p = NEXT_INSN (p)) |
462 { | 449 { |
463 /* ??? We can't scan past the end of a basic block without updating | 450 if (! INSN_P (p)) |
464 the register lifetime info (REG_DEAD/basic_block_live_at_start). */ | 451 continue; |
465 if (perhaps_ends_bb_p (p)) | 452 if (BLOCK_FOR_INSN (p) != bb) |
466 break; | 453 break; |
467 else if (! INSN_P (p)) | |
468 continue; | |
469 | 454 |
470 set = single_set (p); | 455 set = single_set (p); |
471 if (set && SET_SRC (set) == dest && SET_DEST (set) == src | 456 if (set && SET_SRC (set) == dest && SET_DEST (set) == src |
472 && find_reg_note (p, REG_DEAD, dest)) | 457 && find_reg_note (p, REG_DEAD, dest)) |
473 { | 458 { |
528 rtx src_reg = XEXP (src, 0); | 513 rtx src_reg = XEXP (src, 0); |
529 int src_no = REGNO (src_reg); | 514 int src_no = REGNO (src_reg); |
530 int dst_no = REGNO (dest); | 515 int dst_no = REGNO (dest); |
531 rtx p, set; | 516 rtx p, set; |
532 enum machine_mode old_mode; | 517 enum machine_mode old_mode; |
518 basic_block bb = BLOCK_FOR_INSN (insn); | |
533 | 519 |
534 if (src_no < FIRST_PSEUDO_REGISTER | 520 if (src_no < FIRST_PSEUDO_REGISTER |
535 || dst_no < FIRST_PSEUDO_REGISTER | 521 || dst_no < FIRST_PSEUDO_REGISTER |
536 || ! find_reg_note (insn, REG_DEAD, src_reg) | 522 || ! find_reg_note (insn, REG_DEAD, src_reg) |
537 || REG_N_DEATHS (src_no) != 1 | 523 || REG_N_DEATHS (src_no) != 1 |
538 || REG_N_SETS (src_no) != 1) | 524 || REG_N_SETS (src_no) != 1) |
539 return; | 525 return; |
526 | |
540 for (p = PREV_INSN (insn); p && ! reg_set_p (src_reg, p); p = PREV_INSN (p)) | 527 for (p = PREV_INSN (insn); p && ! reg_set_p (src_reg, p); p = PREV_INSN (p)) |
541 /* ??? We can't scan past the end of a basic block without updating | 528 if (INSN_P (p) && BLOCK_FOR_INSN (p) != bb) |
542 the register lifetime info (REG_DEAD/basic_block_live_at_start). */ | |
543 if (perhaps_ends_bb_p (p)) | |
544 break; | 529 break; |
545 | 530 |
546 if (! p) | 531 if (! p || BLOCK_FOR_INSN (p) != bb) |
547 return; | 532 return; |
548 | 533 |
549 if (! (set = single_set (p)) | 534 if (! (set = single_set (p)) |
550 || !MEM_P (SET_SRC (set)) | 535 || !MEM_P (SET_SRC (set)) |
551 /* If there's a REG_EQUIV note, this must be an insn that loads an | 536 /* If there's a REG_EQUIV note, this must be an insn that loads an |
618 rtx move_insn; | 603 rtx move_insn; |
619 rtx *p_insn_notes; | 604 rtx *p_insn_notes; |
620 rtx *p_move_notes; | 605 rtx *p_move_notes; |
621 int src_regno; | 606 int src_regno; |
622 int dest_regno; | 607 int dest_regno; |
623 int insn_uid; | |
624 int move_uid; | |
625 | 608 |
626 /* A REG_LIVE_LENGTH of -1 indicates the register is equivalent to a constant | 609 /* A REG_LIVE_LENGTH of -1 indicates the register is equivalent to a constant |
627 or memory location and is used infrequently; a REG_LIVE_LENGTH of -2 is | 610 or memory location and is used infrequently; a REG_LIVE_LENGTH of -2 is |
628 parameter when there is no frame pointer that is not allocated a register. | 611 parameter when there is no frame pointer that is not allocated a register. |
629 For now, we just reject them, rather than incrementing the live length. */ | 612 For now, we just reject them, rather than incrementing the live length. */ |
675 } | 658 } |
676 | 659 |
677 *p_move_notes = NULL_RTX; | 660 *p_move_notes = NULL_RTX; |
678 *p_insn_notes = NULL_RTX; | 661 *p_insn_notes = NULL_RTX; |
679 | 662 |
680 insn_uid = INSN_UID (insn); | |
681 move_uid = INSN_UID (move_insn); | |
682 | |
683 /* Update the various register tables. */ | 663 /* Update the various register tables. */ |
684 dest_regno = REGNO (dest); | 664 dest_regno = REGNO (dest); |
685 INC_REG_N_SETS (dest_regno, 1); | 665 INC_REG_N_SETS (dest_regno, 1); |
686 REG_LIVE_LENGTH (dest_regno)++; | 666 REG_LIVE_LENGTH (dest_regno)++; |
687 src_regno = REGNO (src); | 667 src_regno = REGNO (src); |
765 static int | 745 static int |
766 fixup_match_2 (rtx insn, rtx dst, rtx src, rtx offset) | 746 fixup_match_2 (rtx insn, rtx dst, rtx src, rtx offset) |
767 { | 747 { |
768 rtx p, dst_death = 0; | 748 rtx p, dst_death = 0; |
769 int length, num_calls = 0, freq_calls = 0; | 749 int length, num_calls = 0, freq_calls = 0; |
750 basic_block bb = BLOCK_FOR_INSN (insn); | |
770 | 751 |
771 /* If SRC dies in INSN, we'd have to move the death note. This is | 752 /* If SRC dies in INSN, we'd have to move the death note. This is |
772 considered to be very unlikely, so we just skip the optimization | 753 considered to be very unlikely, so we just skip the optimization |
773 in this case. */ | 754 in this case. */ |
774 if (find_regno_note (insn, REG_DEAD, REGNO (src))) | 755 if (find_regno_note (insn, REG_DEAD, REGNO (src))) |
778 | 759 |
779 for (length = 0, p = PREV_INSN (insn); p; p = PREV_INSN (p)) | 760 for (length = 0, p = PREV_INSN (insn); p; p = PREV_INSN (p)) |
780 { | 761 { |
781 rtx pset; | 762 rtx pset; |
782 | 763 |
783 /* ??? We can't scan past the end of a basic block without updating | 764 if (! INSN_P (p)) |
784 the register lifetime info (REG_DEAD/basic_block_live_at_start). */ | 765 continue; |
785 if (perhaps_ends_bb_p (p)) | 766 if (BLOCK_FOR_INSN (p) != bb) |
786 break; | 767 break; |
787 else if (! INSN_P (p)) | |
788 continue; | |
789 | 768 |
790 if (find_regno_note (p, REG_DEAD, REGNO (dst))) | 769 if (find_regno_note (p, REG_DEAD, REGNO (dst))) |
791 dst_death = p; | 770 dst_death = p; |
792 if (! dst_death) | 771 if (! dst_death && !DEBUG_INSN_P (p)) |
793 length++; | 772 length++; |
794 | 773 |
795 pset = single_set (p); | 774 pset = single_set (p); |
796 if (pset && SET_DEST (pset) == dst | 775 if (pset && SET_DEST (pset) == dst |
797 && GET_CODE (SET_SRC (pset)) == PLUS | 776 && GET_CODE (SET_SRC (pset)) == PLUS |
798 && XEXP (SET_SRC (pset), 0) == src | 777 && XEXP (SET_SRC (pset), 0) == src |
799 && GET_CODE (XEXP (SET_SRC (pset), 1)) == CONST_INT) | 778 && CONST_INT_P (XEXP (SET_SRC (pset), 1))) |
800 { | 779 { |
801 HOST_WIDE_INT newconst | 780 HOST_WIDE_INT newconst |
802 = INTVAL (offset) - INTVAL (XEXP (SET_SRC (pset), 1)); | 781 = INTVAL (offset) - INTVAL (XEXP (SET_SRC (pset), 1)); |
803 rtx add = gen_add3_insn (dst, dst, GEN_INT (newconst)); | 782 rtx add = gen_add3_insn (dst, dst, GEN_INT (newconst)); |
804 | 783 |
819 INSN_UID (insn)); | 798 INSN_UID (insn)); |
820 | 799 |
821 #ifdef AUTO_INC_DEC | 800 #ifdef AUTO_INC_DEC |
822 for (p = PREV_INSN (insn); p; p = PREV_INSN (p)) | 801 for (p = PREV_INSN (insn); p; p = PREV_INSN (p)) |
823 { | 802 { |
824 if (LABEL_P (p) | |
825 || JUMP_P (p)) | |
826 break; | |
827 if (! INSN_P (p)) | 803 if (! INSN_P (p)) |
828 continue; | 804 continue; |
805 if (BLOCK_FOR_INSN (p) != bb) | |
806 break; | |
829 if (reg_overlap_mentioned_p (dst, PATTERN (p))) | 807 if (reg_overlap_mentioned_p (dst, PATTERN (p))) |
830 { | 808 { |
831 if (try_auto_increment (p, insn, 0, dst, newconst, 0)) | 809 if (try_auto_increment (p, insn, 0, dst, newconst, 0)) |
832 return 1; | 810 return 1; |
833 break; | 811 break; |
834 } | 812 } |
835 } | 813 } |
836 for (p = NEXT_INSN (insn); p; p = NEXT_INSN (p)) | 814 for (p = NEXT_INSN (insn); p; p = NEXT_INSN (p)) |
837 { | 815 { |
838 if (LABEL_P (p) | |
839 || JUMP_P (p)) | |
840 break; | |
841 if (! INSN_P (p)) | 816 if (! INSN_P (p)) |
842 continue; | 817 continue; |
818 if (BLOCK_FOR_INSN (p) != bb) | |
819 break; | |
843 if (reg_overlap_mentioned_p (dst, PATTERN (p))) | 820 if (reg_overlap_mentioned_p (dst, PATTERN (p))) |
844 { | 821 { |
845 try_auto_increment (p, insn, 0, dst, newconst, 1); | 822 try_auto_increment (p, insn, 0, dst, newconst, 1); |
846 break; | 823 break; |
847 } | 824 } |
880 } | 857 } |
881 | 858 |
882 return 0; | 859 return 0; |
883 } | 860 } |
884 | 861 |
885 /* Main entry for the register move optimization. */ | 862 /* A forward pass. Replace output operands with input operands. */ |
886 | 863 |
887 static unsigned int | 864 static void |
888 regmove_optimize (void) | 865 regmove_forward_pass (void) |
889 { | 866 { |
867 basic_block bb; | |
890 rtx insn; | 868 rtx insn; |
891 struct match match; | 869 |
892 int i; | 870 if (! flag_expensive_optimizations) |
893 rtx copy_src, copy_dst; | 871 return; |
894 int nregs = max_reg_num (); | 872 |
895 | 873 if (dump_file) |
896 /* ??? Hack. Regmove doesn't examine the CFG, and gets mightily | 874 fprintf (dump_file, "Starting forward pass...\n"); |
897 confused by non-call exceptions ending blocks. */ | 875 |
898 if (flag_non_call_exceptions) | 876 FOR_EACH_BB (bb) |
899 return 0; | 877 { |
900 | 878 FOR_BB_INSNS (bb, insn) |
901 df_note_add_problem (); | |
902 df_analyze (); | |
903 | |
904 regstat_init_n_sets_and_refs (); | |
905 regstat_compute_ri (); | |
906 | |
907 regno_src_regno = XNEWVEC (int, nregs); | |
908 for (i = nregs; --i >= 0; ) | |
909 regno_src_regno[i] = -1; | |
910 | |
911 /* A forward pass. Replace output operands with input operands. */ | |
912 | |
913 if (flag_expensive_optimizations) | |
914 { | |
915 if (dump_file) | |
916 fprintf (dump_file, "Starting forward pass...\n"); | |
917 | |
918 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
919 { | 879 { |
920 rtx set = single_set (insn); | 880 rtx set = single_set (insn); |
921 if (! set) | 881 if (! set) |
922 continue; | 882 continue; |
923 | 883 |
950 } | 910 } |
951 } | 911 } |
952 } | 912 } |
953 } | 913 } |
954 } | 914 } |
955 | 915 } |
956 /* A backward pass. Replace input operands with output operands. */ | 916 |
917 /* A backward pass. Replace input operands with output operands. */ | |
918 | |
919 static void | |
920 regmove_backward_pass (void) | |
921 { | |
922 basic_block bb; | |
923 rtx insn, prev; | |
957 | 924 |
958 if (dump_file) | 925 if (dump_file) |
959 fprintf (dump_file, "Starting backward pass...\n"); | 926 fprintf (dump_file, "Starting backward pass...\n"); |
960 | 927 |
961 for (insn = get_last_insn (); insn; insn = PREV_INSN (insn)) | 928 FOR_EACH_BB_REVERSE (bb) |
962 { | 929 { |
963 if (INSN_P (insn)) | 930 /* ??? Use the safe iterator because fixup_match_2 can remove |
931 insns via try_auto_increment. */ | |
932 FOR_BB_INSNS_REVERSE_SAFE (bb, insn, prev) | |
964 { | 933 { |
934 struct match match; | |
935 rtx copy_src, copy_dst; | |
965 int op_no, match_no; | 936 int op_no, match_no; |
966 int success = 0; | 937 int success = 0; |
938 | |
939 if (! INSN_P (insn)) | |
940 continue; | |
967 | 941 |
968 if (! find_matches (insn, &match)) | 942 if (! find_matches (insn, &match)) |
969 continue; | 943 continue; |
970 | 944 |
971 /* Now scan through the operands looking for a destination operand | 945 /* Now scan through the operands looking for a destination operand |
1040 continue; | 1014 continue; |
1041 | 1015 |
1042 if (REGNO (src) < FIRST_PSEUDO_REGISTER) | 1016 if (REGNO (src) < FIRST_PSEUDO_REGISTER) |
1043 { | 1017 { |
1044 if (GET_CODE (SET_SRC (set)) == PLUS | 1018 if (GET_CODE (SET_SRC (set)) == PLUS |
1045 && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT | 1019 && CONST_INT_P (XEXP (SET_SRC (set), 1)) |
1046 && XEXP (SET_SRC (set), 0) == src | 1020 && XEXP (SET_SRC (set), 0) == src |
1047 && fixup_match_2 (insn, dst, src, | 1021 && fixup_match_2 (insn, dst, src, |
1048 XEXP (SET_SRC (set), 1))) | 1022 XEXP (SET_SRC (set), 1))) |
1049 break; | 1023 break; |
1050 continue; | 1024 continue; |
1115 | 1089 |
1116 for (length = 0, p = PREV_INSN (insn); p; p = PREV_INSN (p)) | 1090 for (length = 0, p = PREV_INSN (insn); p; p = PREV_INSN (p)) |
1117 { | 1091 { |
1118 rtx pset; | 1092 rtx pset; |
1119 | 1093 |
1120 /* ??? We can't scan past the end of a basic block without | 1094 if (! INSN_P (p)) |
1121 updating the register lifetime info | 1095 continue; |
1122 (REG_DEAD/basic_block_live_at_start). */ | 1096 if (BLOCK_FOR_INSN (p) != bb) |
1123 if (perhaps_ends_bb_p (p)) | |
1124 break; | 1097 break; |
1125 else if (! INSN_P (p)) | 1098 |
1126 continue; | 1099 if (!DEBUG_INSN_P (p)) |
1127 | 1100 length++; |
1128 length++; | |
1129 | 1101 |
1130 /* ??? See if all of SRC is set in P. This test is much | 1102 /* ??? See if all of SRC is set in P. This test is much |
1131 more conservative than it needs to be. */ | 1103 more conservative than it needs to be. */ |
1132 pset = single_set (p); | 1104 pset = single_set (p); |
1133 if (pset && SET_DEST (pset) == src) | 1105 if (pset && SET_DEST (pset) == src) |
1134 { | 1106 { |
1135 /* We use validate_replace_rtx, in case there | 1107 /* We use validate_replace_rtx, in case there |
1136 are multiple identical source operands. All of | 1108 are multiple identical source operands. All |
1137 them have to be changed at the same time. */ | 1109 of them have to be changed at the same time: |
1110 when validate_replace_rtx() calls | |
1111 apply_change_group(). */ | |
1112 validate_change (p, &SET_DEST (pset), dst, 1); | |
1138 if (validate_replace_rtx (src, dst, insn)) | 1113 if (validate_replace_rtx (src, dst, insn)) |
1139 { | 1114 success = 1; |
1140 if (validate_change (p, &SET_DEST (pset), | |
1141 dst, 0)) | |
1142 success = 1; | |
1143 else | |
1144 { | |
1145 /* Change all source operands back. | |
1146 This modifies the dst as a side-effect. */ | |
1147 validate_replace_rtx (dst, src, insn); | |
1148 /* Now make sure the dst is right. */ | |
1149 validate_change (insn, | |
1150 recog_data.operand_loc[match_no], | |
1151 dst, 0); | |
1152 } | |
1153 } | |
1154 break; | 1115 break; |
1155 } | 1116 } |
1156 | 1117 |
1157 /* We can't make this change if SRC is read or | 1118 /* We can't make this change if DST is mentioned at |
1119 all in P, since we are going to change its value. | |
1120 We can't make this change if SRC is read or | |
1158 partially written in P, since we are going to | 1121 partially written in P, since we are going to |
1159 eliminate SRC. We can't make this change | 1122 eliminate SRC. However, if it's a debug insn, we |
1160 if DST is mentioned at all in P, | 1123 can't refrain from making the change, for this |
1161 since we are going to change its value. */ | 1124 would cause codegen differences, so instead we |
1162 if (reg_overlap_mentioned_p (src, PATTERN (p)) | 1125 invalidate debug expressions that reference DST, |
1163 || reg_mentioned_p (dst, PATTERN (p))) | 1126 and adjust references to SRC in them so that they |
1164 break; | 1127 become references to DST. */ |
1128 if (reg_mentioned_p (dst, PATTERN (p))) | |
1129 { | |
1130 if (DEBUG_INSN_P (p)) | |
1131 validate_change (p, &INSN_VAR_LOCATION_LOC (p), | |
1132 gen_rtx_UNKNOWN_VAR_LOC (), 1); | |
1133 else | |
1134 break; | |
1135 } | |
1136 if (reg_overlap_mentioned_p (src, PATTERN (p))) | |
1137 { | |
1138 if (DEBUG_INSN_P (p)) | |
1139 validate_replace_rtx_group (src, dst, p); | |
1140 else | |
1141 break; | |
1142 } | |
1165 | 1143 |
1166 /* If we have passed a call instruction, and the | 1144 /* If we have passed a call instruction, and the |
1167 pseudo-reg DST is not already live across a call, | 1145 pseudo-reg DST is not already live across a call, |
1168 then don't perform the optimization. */ | 1146 then don't perform the optimization. */ |
1169 if (CALL_P (p)) | 1147 if (CALL_P (p)) |
1221 "Fixed operand %d of insn %d matching operand %d.\n", | 1199 "Fixed operand %d of insn %d matching operand %d.\n", |
1222 op_no, INSN_UID (insn), match_no); | 1200 op_no, INSN_UID (insn), match_no); |
1223 | 1201 |
1224 break; | 1202 break; |
1225 } | 1203 } |
1204 else if (num_changes_pending () > 0) | |
1205 cancel_changes (0); | |
1226 } | 1206 } |
1227 | 1207 |
1228 /* If we weren't able to replace any of the alternatives, try an | 1208 /* If we weren't able to replace any of the alternatives, try an |
1229 alternative approach of copying the source to the destination. */ | 1209 alternative approach of copying the source to the destination. */ |
1230 if (!success && copy_src != NULL_RTX) | 1210 if (!success && copy_src != NULL_RTX) |
1231 copy_src_to_dest (insn, copy_src, copy_dst); | 1211 copy_src_to_dest (insn, copy_src, copy_dst); |
1232 } | 1212 } |
1233 } | 1213 } |
1214 } | |
1215 | |
1216 /* Main entry for the register move optimization. */ | |
1217 | |
1218 static unsigned int | |
1219 regmove_optimize (void) | |
1220 { | |
1221 int i; | |
1222 int nregs = max_reg_num (); | |
1223 | |
1224 df_note_add_problem (); | |
1225 df_analyze (); | |
1226 | |
1227 if (flag_ira_loop_pressure) | |
1228 ira_set_pseudo_classes (dump_file); | |
1229 | |
1230 regstat_init_n_sets_and_refs (); | |
1231 regstat_compute_ri (); | |
1232 | |
1233 regno_src_regno = XNEWVEC (int, nregs); | |
1234 for (i = nregs; --i >= 0; ) | |
1235 regno_src_regno[i] = -1; | |
1236 | |
1237 /* A forward pass. Replace output operands with input operands. */ | |
1238 regmove_forward_pass (); | |
1239 | |
1240 /* A backward pass. Replace input operands with output operands. */ | |
1241 regmove_backward_pass (); | |
1234 | 1242 |
1235 /* Clean up. */ | 1243 /* Clean up. */ |
1236 free (regno_src_regno); | 1244 free (regno_src_regno); |
1237 if (reg_set_in_bb) | 1245 if (reg_set_in_bb) |
1238 { | 1246 { |
1239 free (reg_set_in_bb); | 1247 free (reg_set_in_bb); |
1240 reg_set_in_bb = NULL; | 1248 reg_set_in_bb = NULL; |
1241 } | 1249 } |
1242 regstat_free_n_sets_and_refs (); | 1250 regstat_free_n_sets_and_refs (); |
1243 regstat_free_ri (); | 1251 regstat_free_ri (); |
1252 if (flag_ira_loop_pressure) | |
1253 free_reg_info (); | |
1244 return 0; | 1254 return 0; |
1245 } | 1255 } |
1246 | 1256 |
1247 /* Returns nonzero if INSN's pattern has matching constraints for any operand. | 1257 /* Returns nonzero if INSN's pattern has matching constraints for any operand. |
1248 Returns 0 if INSN can't be recognized, or if the alternative can't be | 1258 Returns 0 if INSN can't be recognized, or if the alternative can't be |
1362 TODO_df_finish | TODO_verify_rtl_sharing | | 1372 TODO_df_finish | TODO_verify_rtl_sharing | |
1363 TODO_dump_func | | 1373 TODO_dump_func | |
1364 TODO_ggc_collect /* todo_flags_finish */ | 1374 TODO_ggc_collect /* todo_flags_finish */ |
1365 } | 1375 } |
1366 }; | 1376 }; |
1367 |