1 /* Register renaming for the GNU compiler.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "coretypes.h"
29 #include "insn-config.h"
31 #include "hard-reg-set.h"
32 #include "basic-block.h"
41 #ifndef REG_MODE_OK_FOR_BASE_P
42 #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
45 static const char *const reg_class_names[] = REG_CLASS_NAMES;
49 struct du_chain *next_chain;
50 struct du_chain *next_use;
54 ENUM_BITFIELD(reg_class) class : 16;
55 unsigned int need_caller_save_reg:1;
56 unsigned int earlyclobber:1;
62 terminate_overlapping_read,
69 static const char * const scan_actions_name[] =
72 "terminate_overlapping_read",
79 static struct obstack rename_obstack;
81 static void do_replace (struct du_chain *, int);
82 static void scan_rtx_reg (rtx, rtx *, enum reg_class,
83 enum scan_actions, enum op_type, int);
84 static void scan_rtx_address (rtx, rtx *, enum reg_class,
85 enum scan_actions, enum machine_mode);
86 static void scan_rtx (rtx, rtx *, enum reg_class, enum scan_actions,
88 static struct du_chain *build_def_use (basic_block);
89 static void dump_def_use_chain (struct du_chain *);
90 static void note_sets (rtx, rtx, void *);
91 static void clear_dead_regs (HARD_REG_SET *, enum machine_mode, rtx);
92 static void merge_overlapping_regs (basic_block, HARD_REG_SET *,
95 /* Called through note_stores from update_life. Find sets of registers, and
96 record them in *DATA (which is actually a HARD_REG_SET *). */
99 note_sets (rtx x, rtx set ATTRIBUTE_UNUSED, void *data)
101 HARD_REG_SET *pset = (HARD_REG_SET *) data;
105 if (GET_CODE (x) == SUBREG)
107 if (GET_CODE (x) != REG)
111 nregs = HARD_REGNO_NREGS (regno, GET_MODE (x));
113 /* There must not be pseudos at this point. */
114 if (regno + nregs > FIRST_PSEUDO_REGISTER)
118 SET_HARD_REG_BIT (*pset, regno + nregs);
121 /* Clear all registers from *PSET for which a note of kind KIND can be found
122 in the list NOTES. */
125 clear_dead_regs (HARD_REG_SET *pset, enum machine_mode kind, rtx notes)
128 for (note = notes; note; note = XEXP (note, 1))
129 if (REG_NOTE_KIND (note) == kind && REG_P (XEXP (note, 0)))
131 rtx reg = XEXP (note, 0);
132 unsigned int regno = REGNO (reg);
133 int nregs = HARD_REGNO_NREGS (regno, GET_MODE (reg));
135 /* There must not be pseudos at this point. */
136 if (regno + nregs > FIRST_PSEUDO_REGISTER)
140 CLEAR_HARD_REG_BIT (*pset, regno + nregs);
144 /* For a def-use chain CHAIN in basic block B, find which registers overlap
145 its lifetime and set the corresponding bits in *PSET. */
148 merge_overlapping_regs (basic_block b, HARD_REG_SET *pset,
149 struct du_chain *chain)
151 struct du_chain *t = chain;
155 REG_SET_TO_HARD_REG_SET (live, b->global_live_at_start);
159 /* Search forward until the next reference to the register to be
161 while (insn != t->insn)
165 clear_dead_regs (&live, REG_DEAD, REG_NOTES (insn));
166 note_stores (PATTERN (insn), note_sets, (void *) &live);
167 /* Only record currently live regs if we are inside the
170 IOR_HARD_REG_SET (*pset, live);
171 clear_dead_regs (&live, REG_UNUSED, REG_NOTES (insn));
173 insn = NEXT_INSN (insn);
176 IOR_HARD_REG_SET (*pset, live);
178 /* For the last reference, also merge in all registers set in the
180 @@@ We only have take earlyclobbered sets into account. */
182 note_stores (PATTERN (insn), note_sets, (void *) pset);
188 /* Perform register renaming on the current function. */
191 regrename_optimize (void)
193 int tick[FIRST_PSEUDO_REGISTER];
198 memset (tick, 0, sizeof tick);
200 gcc_obstack_init (&rename_obstack);
201 first_obj = obstack_alloc (&rename_obstack, 0);
205 struct du_chain *all_chains = 0;
206 HARD_REG_SET unavailable;
207 HARD_REG_SET regs_seen;
209 CLEAR_HARD_REG_SET (unavailable);
212 fprintf (rtl_dump_file, "\nBasic block %d:\n", bb->index);
214 all_chains = build_def_use (bb);
217 dump_def_use_chain (all_chains);
219 CLEAR_HARD_REG_SET (unavailable);
220 /* Don't clobber traceback for noreturn functions. */
221 if (frame_pointer_needed)
225 for (i = HARD_REGNO_NREGS (FRAME_POINTER_REGNUM, Pmode); i--;)
226 SET_HARD_REG_BIT (unavailable, FRAME_POINTER_REGNUM + i);
228 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
229 for (i = HARD_REGNO_NREGS (HARD_FRAME_POINTER_REGNUM, Pmode); i--;)
230 SET_HARD_REG_BIT (unavailable, HARD_FRAME_POINTER_REGNUM + i);
234 CLEAR_HARD_REG_SET (regs_seen);
237 int new_reg, best_new_reg;
239 struct du_chain *this = all_chains;
240 struct du_chain *tmp, *last;
241 HARD_REG_SET this_unavailable;
242 int reg = REGNO (*this->loc);
245 all_chains = this->next_chain;
249 #if 0 /* This just disables optimization opportunities. */
250 /* Only rename once we've seen the reg more than once. */
251 if (! TEST_HARD_REG_BIT (regs_seen, reg))
253 SET_HARD_REG_BIT (regs_seen, reg);
258 if (fixed_regs[reg] || global_regs[reg]
259 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
260 || (frame_pointer_needed && reg == HARD_FRAME_POINTER_REGNUM)
262 || (frame_pointer_needed && reg == FRAME_POINTER_REGNUM)
267 COPY_HARD_REG_SET (this_unavailable, unavailable);
269 /* Find last entry on chain (which has the need_caller_save bit),
270 count number of uses, and narrow the set of registers we can
273 for (last = this; last->next_use; last = last->next_use)
276 IOR_COMPL_HARD_REG_SET (this_unavailable,
277 reg_class_contents[last->class]);
282 IOR_COMPL_HARD_REG_SET (this_unavailable,
283 reg_class_contents[last->class]);
285 if (this->need_caller_save_reg)
286 IOR_HARD_REG_SET (this_unavailable, call_used_reg_set);
288 merge_overlapping_regs (bb, &this_unavailable, this);
290 /* Now potential_regs is a reasonable approximation, let's
291 have a closer look at each register still in there. */
292 for (new_reg = 0; new_reg < FIRST_PSEUDO_REGISTER; new_reg++)
294 int nregs = HARD_REGNO_NREGS (new_reg, GET_MODE (*this->loc));
296 for (i = nregs - 1; i >= 0; --i)
297 if (TEST_HARD_REG_BIT (this_unavailable, new_reg + i)
298 || fixed_regs[new_reg + i]
299 || global_regs[new_reg + i]
300 /* Can't use regs which aren't saved by the prologue. */
301 || (! regs_ever_live[new_reg + i]
302 && ! call_used_regs[new_reg + i])
303 #ifdef LEAF_REGISTERS
304 /* We can't use a non-leaf register if we're in a
306 || (current_function_is_leaf
307 && !LEAF_REGISTERS[new_reg + i])
309 #ifdef HARD_REGNO_RENAME_OK
310 || ! HARD_REGNO_RENAME_OK (reg + i, new_reg + i)
317 /* See whether it accepts all modes that occur in
318 definition and uses. */
319 for (tmp = this; tmp; tmp = tmp->next_use)
320 if (! HARD_REGNO_MODE_OK (new_reg, GET_MODE (*tmp->loc))
321 || (tmp->need_caller_save_reg
322 && ! (HARD_REGNO_CALL_PART_CLOBBERED
323 (reg, GET_MODE (*tmp->loc)))
324 && (HARD_REGNO_CALL_PART_CLOBBERED
325 (new_reg, GET_MODE (*tmp->loc)))))
329 if (tick[best_new_reg] > tick[new_reg])
330 best_new_reg = new_reg;
336 fprintf (rtl_dump_file, "Register %s in insn %d",
337 reg_names[reg], INSN_UID (last->insn));
338 if (last->need_caller_save_reg)
339 fprintf (rtl_dump_file, " crosses a call");
342 if (best_new_reg == reg)
344 tick[reg] = ++this_tick;
346 fprintf (rtl_dump_file, "; no available better choice\n");
350 do_replace (this, best_new_reg);
351 tick[best_new_reg] = ++this_tick;
354 fprintf (rtl_dump_file, ", renamed as %s\n", reg_names[best_new_reg]);
357 obstack_free (&rename_obstack, first_obj);
360 obstack_free (&rename_obstack, NULL);
363 fputc ('\n', rtl_dump_file);
365 count_or_remove_death_notes (NULL, 1);
366 update_life_info (NULL, UPDATE_LIFE_LOCAL,
367 PROP_REG_INFO | PROP_DEATH_NOTES);
371 do_replace (struct du_chain *chain, int reg)
375 unsigned int regno = ORIGINAL_REGNO (*chain->loc);
376 struct reg_attrs * attr = REG_ATTRS (*chain->loc);
378 *chain->loc = gen_raw_REG (GET_MODE (*chain->loc), reg);
379 if (regno >= FIRST_PSEUDO_REGISTER)
380 ORIGINAL_REGNO (*chain->loc) = regno;
381 REG_ATTRS (*chain->loc) = attr;
382 chain = chain->next_use;
387 static struct du_chain *open_chains;
388 static struct du_chain *closed_chains;
391 scan_rtx_reg (rtx insn, rtx *loc, enum reg_class class,
392 enum scan_actions action, enum op_type type, int earlyclobber)
396 enum machine_mode mode = GET_MODE (x);
397 int this_regno = REGNO (x);
398 int this_nregs = HARD_REGNO_NREGS (this_regno, mode);
400 if (action == mark_write)
404 struct du_chain *this
405 = obstack_alloc (&rename_obstack, sizeof (struct du_chain));
407 this->next_chain = open_chains;
411 this->need_caller_save_reg = 0;
412 this->earlyclobber = earlyclobber;
418 if ((type == OP_OUT && action != terminate_write)
419 || (type != OP_OUT && action == terminate_write))
422 for (p = &open_chains; *p;)
424 struct du_chain *this = *p;
426 /* Check if the chain has been terminated if it has then skip to
429 This can happen when we've already appended the location to
430 the chain in Step 3, but are trying to hide in-out operands
431 from terminate_write in Step 5. */
433 if (*this->loc == cc0_rtx)
434 p = &this->next_chain;
437 int regno = REGNO (*this->loc);
438 int nregs = HARD_REGNO_NREGS (regno, GET_MODE (*this->loc));
439 int exact_match = (regno == this_regno && nregs == this_nregs);
441 if (regno + nregs <= this_regno
442 || this_regno + this_nregs <= regno)
444 p = &this->next_chain;
448 if (action == mark_read)
453 /* ??? Class NO_REGS can happen if the md file makes use of
454 EXTRA_CONSTRAINTS to match registers. Which is arguably
455 wrong, but there we are. Since we know not what this may
456 be replaced with, terminate the chain. */
457 if (class != NO_REGS)
459 this = obstack_alloc (&rename_obstack, sizeof (struct du_chain));
461 this->next_chain = (*p)->next_chain;
465 this->need_caller_save_reg = 0;
473 if (action != terminate_overlapping_read || ! exact_match)
475 struct du_chain *next = this->next_chain;
477 /* Whether the terminated chain can be used for renaming
478 depends on the action and this being an exact match.
479 In either case, we remove this element from open_chains. */
481 if ((action == terminate_dead || action == terminate_write)
484 this->next_chain = closed_chains;
485 closed_chains = this;
487 fprintf (rtl_dump_file,
488 "Closing chain %s at insn %d (%s)\n",
489 reg_names[REGNO (*this->loc)], INSN_UID (insn),
490 scan_actions_name[(int) action]);
495 fprintf (rtl_dump_file,
496 "Discarding chain %s at insn %d (%s)\n",
497 reg_names[REGNO (*this->loc)], INSN_UID (insn),
498 scan_actions_name[(int) action]);
503 p = &this->next_chain;
508 /* Adapted from find_reloads_address_1. CLASS is INDEX_REG_CLASS or
509 BASE_REG_CLASS depending on how the register is being considered. */
512 scan_rtx_address (rtx insn, rtx *loc, enum reg_class class,
513 enum scan_actions action, enum machine_mode mode)
516 RTX_CODE code = GET_CODE (x);
520 if (action == mark_write)
527 rtx orig_op0 = XEXP (x, 0);
528 rtx orig_op1 = XEXP (x, 1);
529 RTX_CODE code0 = GET_CODE (orig_op0);
530 RTX_CODE code1 = GET_CODE (orig_op1);
536 if (GET_CODE (op0) == SUBREG)
538 op0 = SUBREG_REG (op0);
539 code0 = GET_CODE (op0);
542 if (GET_CODE (op1) == SUBREG)
544 op1 = SUBREG_REG (op1);
545 code1 = GET_CODE (op1);
548 if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
549 || code0 == ZERO_EXTEND || code1 == MEM)
554 else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
555 || code1 == ZERO_EXTEND || code0 == MEM)
560 else if (code0 == CONST_INT || code0 == CONST
561 || code0 == SYMBOL_REF || code0 == LABEL_REF)
563 else if (code1 == CONST_INT || code1 == CONST
564 || code1 == SYMBOL_REF || code1 == LABEL_REF)
566 else if (code0 == REG && code1 == REG)
570 if (REG_OK_FOR_INDEX_P (op0)
571 && REG_MODE_OK_FOR_BASE_P (op1, mode))
573 else if (REG_OK_FOR_INDEX_P (op1)
574 && REG_MODE_OK_FOR_BASE_P (op0, mode))
576 else if (REG_MODE_OK_FOR_BASE_P (op1, mode))
578 else if (REG_MODE_OK_FOR_BASE_P (op0, mode))
580 else if (REG_OK_FOR_INDEX_P (op1))
585 locI = &XEXP (x, index_op);
586 locB = &XEXP (x, !index_op);
588 else if (code0 == REG)
593 else if (code1 == REG)
600 scan_rtx_address (insn, locI, INDEX_REG_CLASS, action, mode);
602 scan_rtx_address (insn, locB, MODE_BASE_REG_CLASS (mode), action, mode);
613 /* If the target doesn't claim to handle autoinc, this must be
614 something special, like a stack push. Kill this chain. */
615 action = terminate_all_read;
620 scan_rtx_address (insn, &XEXP (x, 0),
621 MODE_BASE_REG_CLASS (GET_MODE (x)), action,
626 scan_rtx_reg (insn, loc, class, action, OP_IN, 0);
633 fmt = GET_RTX_FORMAT (code);
634 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
637 scan_rtx_address (insn, &XEXP (x, i), class, action, mode);
638 else if (fmt[i] == 'E')
639 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
640 scan_rtx_address (insn, &XVECEXP (x, i, j), class, action, mode);
645 scan_rtx (rtx insn, rtx *loc, enum reg_class class,
646 enum scan_actions action, enum op_type type, int earlyclobber)
650 enum rtx_code code = GET_CODE (x);
667 scan_rtx_reg (insn, loc, class, action, type, earlyclobber);
671 scan_rtx_address (insn, &XEXP (x, 0),
672 MODE_BASE_REG_CLASS (GET_MODE (x)), action,
677 scan_rtx (insn, &SET_SRC (x), class, action, OP_IN, 0);
678 scan_rtx (insn, &SET_DEST (x), class, action,
679 GET_CODE (PATTERN (insn)) == COND_EXEC ? OP_INOUT : OP_OUT, 0);
682 case STRICT_LOW_PART:
683 scan_rtx (insn, &XEXP (x, 0), class, action, OP_INOUT, earlyclobber);
688 scan_rtx (insn, &XEXP (x, 0), class, action,
689 type == OP_IN ? OP_IN : OP_INOUT, earlyclobber);
690 scan_rtx (insn, &XEXP (x, 1), class, action, OP_IN, 0);
691 scan_rtx (insn, &XEXP (x, 2), class, action, OP_IN, 0);
700 /* Should only happen inside MEM. */
704 scan_rtx (insn, &SET_DEST (x), class, action,
705 GET_CODE (PATTERN (insn)) == COND_EXEC ? OP_INOUT : OP_OUT, 1);
709 scan_rtx (insn, &XEXP (x, 0), class, action, type, 0);
711 scan_rtx (insn, &XEXP (x, 1), class, action, type, 0);
718 fmt = GET_RTX_FORMAT (code);
719 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
722 scan_rtx (insn, &XEXP (x, i), class, action, type, 0);
723 else if (fmt[i] == 'E')
724 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
725 scan_rtx (insn, &XVECEXP (x, i, j), class, action, type, 0);
729 /* Build def/use chain. */
731 static struct du_chain *
732 build_def_use (basic_block bb)
736 open_chains = closed_chains = NULL;
738 for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn))
744 rtx old_operands[MAX_RECOG_OPERANDS];
745 rtx old_dups[MAX_DUP_OPERANDS];
750 /* Process the insn, determining its effect on the def-use
751 chains. We perform the following steps with the register
752 references in the insn:
753 (1) Any read that overlaps an open chain, but doesn't exactly
754 match, causes that chain to be closed. We can't deal
756 (2) Any read outside an operand causes any chain it overlaps
757 with to be closed, since we can't replace it.
758 (3) Any read inside an operand is added if there's already
759 an open chain for it.
760 (4) For any REG_DEAD note we find, close open chains that
762 (5) For any write we find, close open chains that overlap it.
763 (6) For any write we find in an operand, make a new chain.
764 (7) For any REG_UNUSED, close any chains we just opened. */
766 icode = recog_memoized (insn);
768 if (! constrain_operands (1))
769 fatal_insn_not_found (insn);
770 preprocess_constraints ();
771 alt = which_alternative;
772 n_ops = recog_data.n_operands;
774 /* Simplify the code below by rewriting things to reflect
775 matching constraints. Also promote OP_OUT to OP_INOUT
776 in predicated instructions. */
778 predicated = GET_CODE (PATTERN (insn)) == COND_EXEC;
779 for (i = 0; i < n_ops; ++i)
781 int matches = recog_op_alt[i][alt].matches;
783 recog_op_alt[i][alt].class = recog_op_alt[matches][alt].class;
784 if (matches >= 0 || recog_op_alt[i][alt].matched >= 0
785 || (predicated && recog_data.operand_type[i] == OP_OUT))
786 recog_data.operand_type[i] = OP_INOUT;
789 /* Step 1: Close chains for which we have overlapping reads. */
790 for (i = 0; i < n_ops; i++)
791 scan_rtx (insn, recog_data.operand_loc[i],
792 NO_REGS, terminate_overlapping_read,
793 recog_data.operand_type[i], 0);
795 /* Step 2: Close chains for which we have reads outside operands.
796 We do this by munging all operands into CC0, and closing
797 everything remaining. */
799 for (i = 0; i < n_ops; i++)
801 old_operands[i] = recog_data.operand[i];
802 /* Don't squash match_operator or match_parallel here, since
803 we don't know that all of the contained registers are
804 reachable by proper operands. */
805 if (recog_data.constraints[i][0] == '\0')
807 *recog_data.operand_loc[i] = cc0_rtx;
809 for (i = 0; i < recog_data.n_dups; i++)
811 int dup_num = recog_data.dup_num[i];
813 old_dups[i] = *recog_data.dup_loc[i];
814 *recog_data.dup_loc[i] = cc0_rtx;
816 /* For match_dup of match_operator or match_parallel, share
817 them, so that we don't miss changes in the dup. */
819 && insn_data[icode].operand[dup_num].eliminable == 0)
820 old_dups[i] = recog_data.operand[dup_num];
823 scan_rtx (insn, &PATTERN (insn), NO_REGS, terminate_all_read,
826 for (i = 0; i < recog_data.n_dups; i++)
827 *recog_data.dup_loc[i] = old_dups[i];
828 for (i = 0; i < n_ops; i++)
829 *recog_data.operand_loc[i] = old_operands[i];
831 /* Step 2B: Can't rename function call argument registers. */
832 if (GET_CODE (insn) == CALL_INSN && CALL_INSN_FUNCTION_USAGE (insn))
833 scan_rtx (insn, &CALL_INSN_FUNCTION_USAGE (insn),
834 NO_REGS, terminate_all_read, OP_IN, 0);
836 /* Step 2C: Can't rename asm operands that were originally
838 if (asm_noperands (PATTERN (insn)) > 0)
839 for (i = 0; i < n_ops; i++)
841 rtx *loc = recog_data.operand_loc[i];
844 if (GET_CODE (op) == REG
845 && REGNO (op) == ORIGINAL_REGNO (op)
846 && (recog_data.operand_type[i] == OP_IN
847 || recog_data.operand_type[i] == OP_INOUT))
848 scan_rtx (insn, loc, NO_REGS, terminate_all_read, OP_IN, 0);
851 /* Step 3: Append to chains for reads inside operands. */
852 for (i = 0; i < n_ops + recog_data.n_dups; i++)
854 int opn = i < n_ops ? i : recog_data.dup_num[i - n_ops];
855 rtx *loc = (i < n_ops
856 ? recog_data.operand_loc[opn]
857 : recog_data.dup_loc[i - n_ops]);
858 enum reg_class class = recog_op_alt[opn][alt].class;
859 enum op_type type = recog_data.operand_type[opn];
861 /* Don't scan match_operand here, since we've no reg class
862 information to pass down. Any operands that we could
863 substitute in will be represented elsewhere. */
864 if (recog_data.constraints[opn][0] == '\0')
867 if (recog_op_alt[opn][alt].is_address)
868 scan_rtx_address (insn, loc, class, mark_read, VOIDmode);
870 scan_rtx (insn, loc, class, mark_read, type, 0);
873 /* Step 4: Close chains for registers that die here.
874 Also record updates for REG_INC notes. */
875 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
877 if (REG_NOTE_KIND (note) == REG_DEAD)
878 scan_rtx (insn, &XEXP (note, 0), NO_REGS, terminate_dead,
880 else if (REG_NOTE_KIND (note) == REG_INC)
881 scan_rtx (insn, &XEXP (note, 0), ALL_REGS, mark_read,
885 /* Step 4B: If this is a call, any chain live at this point
886 requires a caller-saved reg. */
887 if (GET_CODE (insn) == CALL_INSN)
890 for (p = open_chains; p; p = p->next_chain)
891 p->need_caller_save_reg = 1;
894 /* Step 5: Close open chains that overlap writes. Similar to
895 step 2, we hide in-out operands, since we do not want to
896 close these chains. */
898 for (i = 0; i < n_ops; i++)
900 old_operands[i] = recog_data.operand[i];
901 if (recog_data.operand_type[i] == OP_INOUT)
902 *recog_data.operand_loc[i] = cc0_rtx;
904 for (i = 0; i < recog_data.n_dups; i++)
906 int opn = recog_data.dup_num[i];
907 old_dups[i] = *recog_data.dup_loc[i];
908 if (recog_data.operand_type[opn] == OP_INOUT)
909 *recog_data.dup_loc[i] = cc0_rtx;
912 scan_rtx (insn, &PATTERN (insn), NO_REGS, terminate_write, OP_IN, 0);
914 for (i = 0; i < recog_data.n_dups; i++)
915 *recog_data.dup_loc[i] = old_dups[i];
916 for (i = 0; i < n_ops; i++)
917 *recog_data.operand_loc[i] = old_operands[i];
919 /* Step 6: Begin new chains for writes inside operands. */
920 /* ??? Many targets have output constraints on the SET_DEST
921 of a call insn, which is stupid, since these are certainly
922 ABI defined hard registers. Don't change calls at all.
923 Similarly take special care for asm statement that originally
924 referenced hard registers. */
925 if (asm_noperands (PATTERN (insn)) > 0)
927 for (i = 0; i < n_ops; i++)
928 if (recog_data.operand_type[i] == OP_OUT)
930 rtx *loc = recog_data.operand_loc[i];
932 enum reg_class class = recog_op_alt[i][alt].class;
934 if (GET_CODE (op) == REG
935 && REGNO (op) == ORIGINAL_REGNO (op))
938 scan_rtx (insn, loc, class, mark_write, OP_OUT,
939 recog_op_alt[i][alt].earlyclobber);
942 else if (GET_CODE (insn) != CALL_INSN)
943 for (i = 0; i < n_ops + recog_data.n_dups; i++)
945 int opn = i < n_ops ? i : recog_data.dup_num[i - n_ops];
946 rtx *loc = (i < n_ops
947 ? recog_data.operand_loc[opn]
948 : recog_data.dup_loc[i - n_ops]);
949 enum reg_class class = recog_op_alt[opn][alt].class;
951 if (recog_data.operand_type[opn] == OP_OUT)
952 scan_rtx (insn, loc, class, mark_write, OP_OUT,
953 recog_op_alt[opn][alt].earlyclobber);
956 /* Step 7: Close chains for registers that were never
958 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
959 if (REG_NOTE_KIND (note) == REG_UNUSED)
960 scan_rtx (insn, &XEXP (note, 0), NO_REGS, terminate_dead,
963 if (insn == BB_END (bb))
967 /* Since we close every chain when we find a REG_DEAD note, anything that
968 is still open lives past the basic block, so it can't be renamed. */
969 return closed_chains;
972 /* Dump all def/use chains in CHAINS to RTL_DUMP_FILE. They are
973 printed in reverse order as that's how we build them. */
976 dump_def_use_chain (struct du_chain *chains)
980 struct du_chain *this = chains;
981 int r = REGNO (*this->loc);
982 int nregs = HARD_REGNO_NREGS (r, GET_MODE (*this->loc));
983 fprintf (rtl_dump_file, "Register %s (%d):", reg_names[r], nregs);
986 fprintf (rtl_dump_file, " %d [%s]", INSN_UID (this->insn),
987 reg_class_names[this->class]);
988 this = this->next_use;
990 fprintf (rtl_dump_file, "\n");
991 chains = chains->next_chain;
995 /* The following code does forward propagation of hard register copies.
996 The object is to eliminate as many dependencies as possible, so that
997 we have the most scheduling freedom. As a side effect, we also clean
998 up some silly register allocation decisions made by reload. This
999 code may be obsoleted by a new register allocator. */
1001 /* For each register, we have a list of registers that contain the same
1002 value. The OLDEST_REGNO field points to the head of the list, and
1003 the NEXT_REGNO field runs through the list. The MODE field indicates
1004 what mode the data is known to be in; this field is VOIDmode when the
1005 register is not known to contain valid data. */
1007 struct value_data_entry
1009 enum machine_mode mode;
1010 unsigned int oldest_regno;
1011 unsigned int next_regno;
1016 struct value_data_entry e[FIRST_PSEUDO_REGISTER];
1017 unsigned int max_value_regs;
1020 static void kill_value_regno (unsigned, struct value_data *);
1021 static void kill_value (rtx, struct value_data *);
1022 static void set_value_regno (unsigned, enum machine_mode, struct value_data *);
1023 static void init_value_data (struct value_data *);
1024 static void kill_clobbered_value (rtx, rtx, void *);
1025 static void kill_set_value (rtx, rtx, void *);
1026 static int kill_autoinc_value (rtx *, void *);
1027 static void copy_value (rtx, rtx, struct value_data *);
1028 static bool mode_change_ok (enum machine_mode, enum machine_mode,
1030 static rtx maybe_mode_change (enum machine_mode, enum machine_mode,
1031 enum machine_mode, unsigned int, unsigned int);
1032 static rtx find_oldest_value_reg (enum reg_class, rtx, struct value_data *);
1033 static bool replace_oldest_value_reg (rtx *, enum reg_class, rtx,
1034 struct value_data *);
1035 static bool replace_oldest_value_addr (rtx *, enum reg_class,
1036 enum machine_mode, rtx,
1037 struct value_data *);
1038 static bool replace_oldest_value_mem (rtx, rtx, struct value_data *);
1039 static bool copyprop_hardreg_forward_1 (basic_block, struct value_data *);
1040 extern void debug_value_data (struct value_data *);
1041 #ifdef ENABLE_CHECKING
1042 static void validate_value_data (struct value_data *);
1045 /* Kill register REGNO. This involves removing it from any value lists,
1046 and resetting the value mode to VOIDmode. */
1049 kill_value_regno (unsigned int regno, struct value_data *vd)
1051 unsigned int i, next;
1053 if (vd->e[regno].oldest_regno != regno)
1055 for (i = vd->e[regno].oldest_regno;
1056 vd->e[i].next_regno != regno;
1057 i = vd->e[i].next_regno)
1059 vd->e[i].next_regno = vd->e[regno].next_regno;
1061 else if ((next = vd->e[regno].next_regno) != INVALID_REGNUM)
1063 for (i = next; i != INVALID_REGNUM; i = vd->e[i].next_regno)
1064 vd->e[i].oldest_regno = next;
1067 vd->e[regno].mode = VOIDmode;
1068 vd->e[regno].oldest_regno = regno;
1069 vd->e[regno].next_regno = INVALID_REGNUM;
1071 #ifdef ENABLE_CHECKING
1072 validate_value_data (vd);
1076 /* Kill X. This is a convenience function for kill_value_regno
1077 so that we mind the mode the register is in. */
1080 kill_value (rtx x, struct value_data *vd)
1082 /* SUBREGS are supposed to have been eliminated by now. But some
1083 ports, e.g. i386 sse, use them to smuggle vector type information
1084 through to instruction selection. Each such SUBREG should simplify,
1085 so if we get a NULL we've done something wrong elsewhere. */
1087 if (GET_CODE (x) == SUBREG)
1088 x = simplify_subreg (GET_MODE (x), SUBREG_REG (x),
1089 GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
1092 unsigned int regno = REGNO (x);
1093 unsigned int n = HARD_REGNO_NREGS (regno, GET_MODE (x));
1096 /* Kill the value we're told to kill. */
1097 for (i = 0; i < n; ++i)
1098 kill_value_regno (regno + i, vd);
1100 /* Kill everything that overlapped what we're told to kill. */
1101 if (regno < vd->max_value_regs)
1104 j = regno - vd->max_value_regs;
1105 for (; j < regno; ++j)
1107 if (vd->e[j].mode == VOIDmode)
1109 n = HARD_REGNO_NREGS (j, vd->e[j].mode);
1111 for (i = 0; i < n; ++i)
1112 kill_value_regno (j + i, vd);
1117 /* Remember that REGNO is valid in MODE. */
1120 set_value_regno (unsigned int regno, enum machine_mode mode,
1121 struct value_data *vd)
1125 vd->e[regno].mode = mode;
1127 nregs = HARD_REGNO_NREGS (regno, mode);
1128 if (nregs > vd->max_value_regs)
1129 vd->max_value_regs = nregs;
1132 /* Initialize VD such that there are no known relationships between regs. */
1135 init_value_data (struct value_data *vd)
1138 for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1140 vd->e[i].mode = VOIDmode;
1141 vd->e[i].oldest_regno = i;
1142 vd->e[i].next_regno = INVALID_REGNUM;
1144 vd->max_value_regs = 0;
1147 /* Called through note_stores. If X is clobbered, kill its value. */
1150 kill_clobbered_value (rtx x, rtx set, void *data)
1152 struct value_data *vd = data;
1153 if (GET_CODE (set) == CLOBBER)
1157 /* Called through note_stores. If X is set, not clobbered, kill its
1158 current value and install it as the root of its own value list. */
1161 kill_set_value (rtx x, rtx set, void *data)
1163 struct value_data *vd = data;
1164 if (GET_CODE (set) != CLOBBER)
1168 set_value_regno (REGNO (x), GET_MODE (x), vd);
1172 /* Called through for_each_rtx. Kill any register used as the base of an
1173 auto-increment expression, and install that register as the root of its
1177 kill_autoinc_value (rtx *px, void *data)
1180 struct value_data *vd = data;
1182 if (GET_RTX_CLASS (GET_CODE (x)) == 'a')
1186 set_value_regno (REGNO (x), Pmode, vd);
1193 /* Assert that SRC has been copied to DEST. Adjust the data structures
1194 to reflect that SRC contains an older copy of the shared value. */
1197 copy_value (rtx dest, rtx src, struct value_data *vd)
1199 unsigned int dr = REGNO (dest);
1200 unsigned int sr = REGNO (src);
1201 unsigned int dn, sn;
1204 /* ??? At present, it's possible to see noop sets. It'd be nice if
1205 this were cleaned up beforehand... */
1209 /* Do not propagate copies to the stack pointer, as that can leave
1210 memory accesses with no scheduling dependency on the stack update. */
1211 if (dr == STACK_POINTER_REGNUM)
1214 /* Likewise with the frame pointer, if we're using one. */
1215 if (frame_pointer_needed && dr == HARD_FRAME_POINTER_REGNUM)
1218 /* If SRC and DEST overlap, don't record anything. */
1219 dn = HARD_REGNO_NREGS (dr, GET_MODE (dest));
1220 sn = HARD_REGNO_NREGS (sr, GET_MODE (dest));
1221 if ((dr > sr && dr < sr + sn)
1222 || (sr > dr && sr < dr + dn))
1225 /* If SRC had no assigned mode (i.e. we didn't know it was live)
1226 assign it now and assume the value came from an input argument
1228 if (vd->e[sr].mode == VOIDmode)
1229 set_value_regno (sr, vd->e[dr].mode, vd);
1231 /* If we are narrowing the input to a smaller number of hard regs,
1232 and it is in big endian, we are really extracting a high part.
1233 Since we generally associate a low part of a value with the value itself,
1234 we must not do the same for the high part.
1235 Note we can still get low parts for the same mode combination through
1236 a two-step copy involving differently sized hard regs.
1237 Assume hard regs fr* are 32 bits bits each, while r* are 64 bits each:
1238 (set (reg:DI r0) (reg:DI fr0))
1239 (set (reg:SI fr2) (reg:SI r0))
1240 loads the low part of (reg:DI fr0) - i.e. fr1 - into fr2, while:
1241 (set (reg:SI fr2) (reg:SI fr0))
1242 loads the high part of (reg:DI fr0) into fr2.
1244 We can't properly represent the latter case in our tables, so don't
1245 record anything then. */
1246 else if (sn < (unsigned int) HARD_REGNO_NREGS (sr, vd->e[sr].mode)
1247 && (GET_MODE_SIZE (vd->e[sr].mode) > UNITS_PER_WORD
1248 ? WORDS_BIG_ENDIAN : BYTES_BIG_ENDIAN))
1251 /* If SRC had been assigned a mode narrower than the copy, we can't
1252 link DEST into the chain, because not all of the pieces of the
1253 copy came from oldest_regno. */
1254 else if (sn > (unsigned int) HARD_REGNO_NREGS (sr, vd->e[sr].mode))
1257 /* Link DR at the end of the value chain used by SR. */
1259 vd->e[dr].oldest_regno = vd->e[sr].oldest_regno;
1261 for (i = sr; vd->e[i].next_regno != INVALID_REGNUM; i = vd->e[i].next_regno)
1263 vd->e[i].next_regno = dr;
1265 #ifdef ENABLE_CHECKING
1266 validate_value_data (vd);
1270 /* Return true if a mode change from ORIG to NEW is allowed for REGNO. */
1273 mode_change_ok (enum machine_mode orig_mode, enum machine_mode new_mode,
1274 unsigned int regno ATTRIBUTE_UNUSED)
1276 if (GET_MODE_SIZE (orig_mode) < GET_MODE_SIZE (new_mode))
1279 #ifdef CANNOT_CHANGE_MODE_CLASS
1280 return !REG_CANNOT_CHANGE_MODE_P (regno, orig_mode, new_mode);
1286 /* Register REGNO was originally set in ORIG_MODE. It - or a copy of it -
1287 was copied in COPY_MODE to COPY_REGNO, and then COPY_REGNO was accessed
1289 Return a NEW_MODE rtx for REGNO if that's OK, otherwise return NULL_RTX. */
1292 maybe_mode_change (enum machine_mode orig_mode, enum machine_mode copy_mode,
1293 enum machine_mode new_mode, unsigned int regno,
1294 unsigned int copy_regno ATTRIBUTE_UNUSED)
1296 if (orig_mode == new_mode)
1297 return gen_rtx_raw_REG (new_mode, regno);
1298 else if (mode_change_ok (orig_mode, new_mode, regno))
1300 int copy_nregs = HARD_REGNO_NREGS (copy_regno, copy_mode);
1301 int use_nregs = HARD_REGNO_NREGS (copy_regno, new_mode);
1303 = GET_MODE_SIZE (copy_mode) / copy_nregs * (copy_nregs - use_nregs);
1305 = GET_MODE_SIZE (orig_mode) - GET_MODE_SIZE (new_mode) - copy_offset;
1306 int byteoffset = offset % UNITS_PER_WORD;
1307 int wordoffset = offset - byteoffset;
1309 offset = ((WORDS_BIG_ENDIAN ? wordoffset : 0)
1310 + (BYTES_BIG_ENDIAN ? byteoffset : 0));
1311 return gen_rtx_raw_REG (new_mode,
1312 regno + subreg_regno_offset (regno, orig_mode,
1319 /* Find the oldest copy of the value contained in REGNO that is in
1320 register class CLASS and has mode MODE. If found, return an rtx
1321 of that oldest register, otherwise return NULL. */
1324 find_oldest_value_reg (enum reg_class class, rtx reg, struct value_data *vd)
1326 unsigned int regno = REGNO (reg);
1327 enum machine_mode mode = GET_MODE (reg);
1330 /* If we are accessing REG in some mode other that what we set it in,
1331 make sure that the replacement is valid. In particular, consider
1332 (set (reg:DI r11) (...))
1333 (set (reg:SI r9) (reg:SI r11))
1334 (set (reg:SI r10) (...))
1335 (set (...) (reg:DI r9))
1336 Replacing r9 with r11 is invalid. */
1337 if (mode != vd->e[regno].mode)
1339 if (HARD_REGNO_NREGS (regno, mode)
1340 > HARD_REGNO_NREGS (regno, vd->e[regno].mode))
1344 for (i = vd->e[regno].oldest_regno; i != regno; i = vd->e[i].next_regno)
1346 enum machine_mode oldmode = vd->e[i].mode;
1350 for (last = i; last < i + HARD_REGNO_NREGS (i, mode); last++)
1351 if (!TEST_HARD_REG_BIT (reg_class_contents[class], last))
1354 new = maybe_mode_change (oldmode, vd->e[regno].mode, mode, i, regno);
1357 ORIGINAL_REGNO (new) = ORIGINAL_REGNO (reg);
1358 REG_ATTRS (new) = REG_ATTRS (reg);
1366 /* If possible, replace the register at *LOC with the oldest register
1367 in register class CLASS. Return true if successfully replaced. */
1370 replace_oldest_value_reg (rtx *loc, enum reg_class class, rtx insn,
1371 struct value_data *vd)
1373 rtx new = find_oldest_value_reg (class, *loc, vd);
1377 fprintf (rtl_dump_file, "insn %u: replaced reg %u with %u\n",
1378 INSN_UID (insn), REGNO (*loc), REGNO (new));
1386 /* Similar to replace_oldest_value_reg, but *LOC contains an address.
1387 Adapted from find_reloads_address_1. CLASS is INDEX_REG_CLASS or
1388 BASE_REG_CLASS depending on how the register is being considered. */
1391 replace_oldest_value_addr (rtx *loc, enum reg_class class,
1392 enum machine_mode mode, rtx insn,
1393 struct value_data *vd)
1396 RTX_CODE code = GET_CODE (x);
1399 bool changed = false;
1405 rtx orig_op0 = XEXP (x, 0);
1406 rtx orig_op1 = XEXP (x, 1);
1407 RTX_CODE code0 = GET_CODE (orig_op0);
1408 RTX_CODE code1 = GET_CODE (orig_op1);
1414 if (GET_CODE (op0) == SUBREG)
1416 op0 = SUBREG_REG (op0);
1417 code0 = GET_CODE (op0);
1420 if (GET_CODE (op1) == SUBREG)
1422 op1 = SUBREG_REG (op1);
1423 code1 = GET_CODE (op1);
1426 if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
1427 || code0 == ZERO_EXTEND || code1 == MEM)
1429 locI = &XEXP (x, 0);
1430 locB = &XEXP (x, 1);
1432 else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
1433 || code1 == ZERO_EXTEND || code0 == MEM)
1435 locI = &XEXP (x, 1);
1436 locB = &XEXP (x, 0);
1438 else if (code0 == CONST_INT || code0 == CONST
1439 || code0 == SYMBOL_REF || code0 == LABEL_REF)
1440 locB = &XEXP (x, 1);
1441 else if (code1 == CONST_INT || code1 == CONST
1442 || code1 == SYMBOL_REF || code1 == LABEL_REF)
1443 locB = &XEXP (x, 0);
1444 else if (code0 == REG && code1 == REG)
1448 if (REG_OK_FOR_INDEX_P (op0)
1449 && REG_MODE_OK_FOR_BASE_P (op1, mode))
1451 else if (REG_OK_FOR_INDEX_P (op1)
1452 && REG_MODE_OK_FOR_BASE_P (op0, mode))
1454 else if (REG_MODE_OK_FOR_BASE_P (op1, mode))
1456 else if (REG_MODE_OK_FOR_BASE_P (op0, mode))
1458 else if (REG_OK_FOR_INDEX_P (op1))
1463 locI = &XEXP (x, index_op);
1464 locB = &XEXP (x, !index_op);
1466 else if (code0 == REG)
1468 locI = &XEXP (x, 0);
1469 locB = &XEXP (x, 1);
1471 else if (code1 == REG)
1473 locI = &XEXP (x, 1);
1474 locB = &XEXP (x, 0);
1478 changed |= replace_oldest_value_addr (locI, INDEX_REG_CLASS, mode,
1481 changed |= replace_oldest_value_addr (locB,
1482 MODE_BASE_REG_CLASS (mode),
1496 return replace_oldest_value_mem (x, insn, vd);
1499 return replace_oldest_value_reg (loc, class, insn, vd);
1505 fmt = GET_RTX_FORMAT (code);
1506 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1509 changed |= replace_oldest_value_addr (&XEXP (x, i), class, mode,
1511 else if (fmt[i] == 'E')
1512 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1513 changed |= replace_oldest_value_addr (&XVECEXP (x, i, j), class,
1520 /* Similar to replace_oldest_value_reg, but X contains a memory. */
1523 replace_oldest_value_mem (rtx x, rtx insn, struct value_data *vd)
1525 return replace_oldest_value_addr (&XEXP (x, 0),
1526 MODE_BASE_REG_CLASS (GET_MODE (x)),
1527 GET_MODE (x), insn, vd);
1530 /* Perform the forward copy propagation on basic block BB. */
1533 copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
1535 bool changed = false;
1538 for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn))
1540 int n_ops, i, alt, predicated;
1544 if (! INSN_P (insn))
1546 if (insn == BB_END (bb))
1552 set = single_set (insn);
1553 extract_insn (insn);
1554 if (! constrain_operands (1))
1555 fatal_insn_not_found (insn);
1556 preprocess_constraints ();
1557 alt = which_alternative;
1558 n_ops = recog_data.n_operands;
1559 is_asm = asm_noperands (PATTERN (insn)) >= 0;
1561 /* Simplify the code below by rewriting things to reflect
1562 matching constraints. Also promote OP_OUT to OP_INOUT
1563 in predicated instructions. */
1565 predicated = GET_CODE (PATTERN (insn)) == COND_EXEC;
1566 for (i = 0; i < n_ops; ++i)
1568 int matches = recog_op_alt[i][alt].matches;
1570 recog_op_alt[i][alt].class = recog_op_alt[matches][alt].class;
1571 if (matches >= 0 || recog_op_alt[i][alt].matched >= 0
1572 || (predicated && recog_data.operand_type[i] == OP_OUT))
1573 recog_data.operand_type[i] = OP_INOUT;
1576 /* For each earlyclobber operand, zap the value data. */
1577 for (i = 0; i < n_ops; i++)
1578 if (recog_op_alt[i][alt].earlyclobber)
1579 kill_value (recog_data.operand[i], vd);
1581 /* Within asms, a clobber cannot overlap inputs or outputs.
1582 I wouldn't think this were true for regular insns, but
1583 scan_rtx treats them like that... */
1584 note_stores (PATTERN (insn), kill_clobbered_value, vd);
1586 /* Kill all auto-incremented values. */
1587 /* ??? REG_INC is useless, since stack pushes aren't done that way. */
1588 for_each_rtx (&PATTERN (insn), kill_autoinc_value, vd);
1590 /* Kill all early-clobbered operands. */
1591 for (i = 0; i < n_ops; i++)
1592 if (recog_op_alt[i][alt].earlyclobber)
1593 kill_value (recog_data.operand[i], vd);
1595 /* Special-case plain move instructions, since we may well
1596 be able to do the move from a different register class. */
1597 if (set && REG_P (SET_SRC (set)))
1599 rtx src = SET_SRC (set);
1600 unsigned int regno = REGNO (src);
1601 enum machine_mode mode = GET_MODE (src);
1605 /* If we are accessing SRC in some mode other that what we
1606 set it in, make sure that the replacement is valid. */
1607 if (mode != vd->e[regno].mode)
1609 if (HARD_REGNO_NREGS (regno, mode)
1610 > HARD_REGNO_NREGS (regno, vd->e[regno].mode))
1611 goto no_move_special_case;
1614 /* If the destination is also a register, try to find a source
1615 register in the same class. */
1616 if (REG_P (SET_DEST (set)))
1618 new = find_oldest_value_reg (REGNO_REG_CLASS (regno), src, vd);
1619 if (new && validate_change (insn, &SET_SRC (set), new, 0))
1622 fprintf (rtl_dump_file,
1623 "insn %u: replaced reg %u with %u\n",
1624 INSN_UID (insn), regno, REGNO (new));
1626 goto did_replacement;
1630 /* Otherwise, try all valid registers and see if its valid. */
1631 for (i = vd->e[regno].oldest_regno; i != regno;
1632 i = vd->e[i].next_regno)
1634 new = maybe_mode_change (vd->e[i].mode, vd->e[regno].mode,
1636 if (new != NULL_RTX)
1638 if (validate_change (insn, &SET_SRC (set), new, 0))
1640 ORIGINAL_REGNO (new) = ORIGINAL_REGNO (src);
1641 REG_ATTRS (new) = REG_ATTRS (src);
1643 fprintf (rtl_dump_file,
1644 "insn %u: replaced reg %u with %u\n",
1645 INSN_UID (insn), regno, REGNO (new));
1647 goto did_replacement;
1652 no_move_special_case:
1654 /* For each input operand, replace a hard register with the
1655 eldest live copy that's in an appropriate register class. */
1656 for (i = 0; i < n_ops; i++)
1658 bool replaced = false;
1660 /* Don't scan match_operand here, since we've no reg class
1661 information to pass down. Any operands that we could
1662 substitute in will be represented elsewhere. */
1663 if (recog_data.constraints[i][0] == '\0')
1666 /* Don't replace in asms intentionally referencing hard regs. */
1667 if (is_asm && GET_CODE (recog_data.operand[i]) == REG
1668 && (REGNO (recog_data.operand[i])
1669 == ORIGINAL_REGNO (recog_data.operand[i])))
1672 if (recog_data.operand_type[i] == OP_IN)
1674 if (recog_op_alt[i][alt].is_address)
1676 = replace_oldest_value_addr (recog_data.operand_loc[i],
1677 recog_op_alt[i][alt].class,
1678 VOIDmode, insn, vd);
1679 else if (REG_P (recog_data.operand[i]))
1681 = replace_oldest_value_reg (recog_data.operand_loc[i],
1682 recog_op_alt[i][alt].class,
1684 else if (GET_CODE (recog_data.operand[i]) == MEM)
1685 replaced = replace_oldest_value_mem (recog_data.operand[i],
1688 else if (GET_CODE (recog_data.operand[i]) == MEM)
1689 replaced = replace_oldest_value_mem (recog_data.operand[i],
1692 /* If we performed any replacement, update match_dups. */
1700 new = *recog_data.operand_loc[i];
1701 recog_data.operand[i] = new;
1702 for (j = 0; j < recog_data.n_dups; j++)
1703 if (recog_data.dup_num[j] == i)
1704 *recog_data.dup_loc[j] = new;
1709 /* Clobber call-clobbered registers. */
1710 if (GET_CODE (insn) == CALL_INSN)
1711 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1712 if (TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
1713 kill_value_regno (i, vd);
1715 /* Notice stores. */
1716 note_stores (PATTERN (insn), kill_set_value, vd);
1718 /* Notice copies. */
1719 if (set && REG_P (SET_DEST (set)) && REG_P (SET_SRC (set)))
1720 copy_value (SET_DEST (set), SET_SRC (set), vd);
1722 if (insn == BB_END (bb))
1729 /* Main entry point for the forward copy propagation optimization. */
1732 copyprop_hardreg_forward (void)
1734 struct value_data *all_vd;
1736 basic_block bb, bbp = 0;
1738 need_refresh = false;
1740 all_vd = xmalloc (sizeof (struct value_data) * last_basic_block);
1744 /* If a block has a single predecessor, that we've already
1745 processed, begin with the value data that was live at
1746 the end of the predecessor block. */
1747 /* ??? Ought to use more intelligent queuing of blocks. */
1749 for (bbp = bb; bbp && bbp != bb->pred->src; bbp = bbp->prev_bb);
1751 && ! bb->pred->pred_next
1752 && ! (bb->pred->flags & (EDGE_ABNORMAL_CALL | EDGE_EH))
1753 && bb->pred->src != ENTRY_BLOCK_PTR
1755 all_vd[bb->index] = all_vd[bb->pred->src->index];
1757 init_value_data (all_vd + bb->index);
1759 if (copyprop_hardreg_forward_1 (bb, all_vd + bb->index))
1760 need_refresh = true;
1766 fputs ("\n\n", rtl_dump_file);
1768 /* ??? Irritatingly, delete_noop_moves does not take a set of blocks
1769 to scan, so we have to do a life update with no initial set of
1770 blocks Just In Case. */
1771 delete_noop_moves (get_insns ());
1772 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
1774 | PROP_SCAN_DEAD_CODE
1775 | PROP_KILL_DEAD_CODE);
1781 /* Dump the value chain data to stderr. */
1784 debug_value_data (struct value_data *vd)
1789 CLEAR_HARD_REG_SET (set);
1791 for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1792 if (vd->e[i].oldest_regno == i)
1794 if (vd->e[i].mode == VOIDmode)
1796 if (vd->e[i].next_regno != INVALID_REGNUM)
1797 fprintf (stderr, "[%u] Bad next_regno for empty chain (%u)\n",
1798 i, vd->e[i].next_regno);
1802 SET_HARD_REG_BIT (set, i);
1803 fprintf (stderr, "[%u %s] ", i, GET_MODE_NAME (vd->e[i].mode));
1805 for (j = vd->e[i].next_regno;
1806 j != INVALID_REGNUM;
1807 j = vd->e[j].next_regno)
1809 if (TEST_HARD_REG_BIT (set, j))
1811 fprintf (stderr, "[%u] Loop in regno chain\n", j);
1815 if (vd->e[j].oldest_regno != i)
1817 fprintf (stderr, "[%u] Bad oldest_regno (%u)\n",
1818 j, vd->e[j].oldest_regno);
1821 SET_HARD_REG_BIT (set, j);
1822 fprintf (stderr, "[%u %s] ", j, GET_MODE_NAME (vd->e[j].mode));
1824 fputc ('\n', stderr);
1827 for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1828 if (! TEST_HARD_REG_BIT (set, i)
1829 && (vd->e[i].mode != VOIDmode
1830 || vd->e[i].oldest_regno != i
1831 || vd->e[i].next_regno != INVALID_REGNUM))
1832 fprintf (stderr, "[%u] Non-empty reg in chain (%s %u %i)\n",
1833 i, GET_MODE_NAME (vd->e[i].mode), vd->e[i].oldest_regno,
1834 vd->e[i].next_regno);
1837 #ifdef ENABLE_CHECKING
1839 validate_value_data (struct value_data *vd)
1844 CLEAR_HARD_REG_SET (set);
1846 for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1847 if (vd->e[i].oldest_regno == i)
1849 if (vd->e[i].mode == VOIDmode)
1851 if (vd->e[i].next_regno != INVALID_REGNUM)
1852 internal_error ("validate_value_data: [%u] Bad next_regno for empty chain (%u)",
1853 i, vd->e[i].next_regno);
1857 SET_HARD_REG_BIT (set, i);
1859 for (j = vd->e[i].next_regno;
1860 j != INVALID_REGNUM;
1861 j = vd->e[j].next_regno)
1863 if (TEST_HARD_REG_BIT (set, j))
1864 internal_error ("validate_value_data: Loop in regno chain (%u)",
1866 if (vd->e[j].oldest_regno != i)
1867 internal_error ("validate_value_data: [%u] Bad oldest_regno (%u)",
1868 j, vd->e[j].oldest_regno);
1870 SET_HARD_REG_BIT (set, j);
1874 for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1875 if (! TEST_HARD_REG_BIT (set, i)
1876 && (vd->e[i].mode != VOIDmode
1877 || vd->e[i].oldest_regno != i
1878 || vd->e[i].next_regno != INVALID_REGNUM))
1879 internal_error ("validate_value_data: [%u] Non-empty reg in chain (%s %u %i)",
1880 i, GET_MODE_NAME (vd->e[i].mode), vd->e[i].oldest_regno,
1881 vd->e[i].next_regno);