OSDN Git Service

* doc/install.texi: Document --enable-linker-build-id option.
[pf3gnuchains/gcc-fork.git] / gcc / regrename.c
1 /* Register renaming for the GNU compiler.
2    Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
3    Free Software Foundation, Inc.
4
5    This file is part of GCC.
6
7    GCC is free software; you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3, or (at your option)
10    any later version.
11
12    GCC is distributed in the hope that it will be useful, but WITHOUT
13    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15    License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GCC; see the file COPYING3.  If not see
19    <http://www.gnu.org/licenses/>.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "rtl.h"
26 #include "tm_p.h"
27 #include "insn-config.h"
28 #include "regs.h"
29 #include "addresses.h"
30 #include "hard-reg-set.h"
31 #include "basic-block.h"
32 #include "reload.h"
33 #include "output.h"
34 #include "function.h"
35 #include "recog.h"
36 #include "flags.h"
37 #include "toplev.h"
38 #include "obstack.h"
39 #include "timevar.h"
40 #include "tree-pass.h"
41 #include "df.h"
42
43 struct du_chain
44 {
45   struct du_chain *next_chain;
46   struct du_chain *next_use;
47
48   rtx insn;
49   rtx *loc;
50   ENUM_BITFIELD(reg_class) cl : 16;
51   unsigned int need_caller_save_reg:1;
52   unsigned int earlyclobber:1;
53 };
54
55 enum scan_actions
56 {
57   terminate_all_read,
58   terminate_overlapping_read,
59   terminate_write,
60   terminate_dead,
61   mark_read,
62   mark_write,
63   /* mark_access is for marking the destination regs in
64      REG_FRAME_RELATED_EXPR notes (as if they were read) so that the
65      note is updated properly.  */
66   mark_access
67 };
68
69 static const char * const scan_actions_name[] =
70 {
71   "terminate_all_read",
72   "terminate_overlapping_read",
73   "terminate_write",
74   "terminate_dead",
75   "mark_read",
76   "mark_write",
77   "mark_access"
78 };
79
80 static struct obstack rename_obstack;
81
82 static void do_replace (struct du_chain *, int);
83 static void scan_rtx_reg (rtx, rtx *, enum reg_class,
84                           enum scan_actions, enum op_type, int);
85 static void scan_rtx_address (rtx, rtx *, enum reg_class,
86                               enum scan_actions, enum machine_mode);
87 static void scan_rtx (rtx, rtx *, enum reg_class, enum scan_actions,
88                       enum op_type, int);
89 static struct du_chain *build_def_use (basic_block);
90 static void dump_def_use_chain (struct du_chain *);
91 static void note_sets (rtx, const_rtx, void *);
92 static void clear_dead_regs (HARD_REG_SET *, enum reg_note, rtx);
93 static void merge_overlapping_regs (basic_block, HARD_REG_SET *,
94                                     struct du_chain *);
95
96 /* Called through note_stores.  Find sets of registers, and
97    record them in *DATA (which is actually a HARD_REG_SET *).  */
98
99 static void
100 note_sets (rtx x, const_rtx set ATTRIBUTE_UNUSED, void *data)
101 {
102   HARD_REG_SET *pset = (HARD_REG_SET *) data;
103
104   if (GET_CODE (x) == SUBREG)
105     x = SUBREG_REG (x);
106   if (!REG_P (x))
107     return;
108   /* There must not be pseudos at this point.  */
109   gcc_assert (HARD_REGISTER_P (x));
110   add_to_hard_reg_set (pset, GET_MODE (x), REGNO (x));
111 }
112
113 /* Clear all registers from *PSET for which a note of kind KIND can be found
114    in the list NOTES.  */
115
116 static void
117 clear_dead_regs (HARD_REG_SET *pset, enum reg_note kind, rtx notes)
118 {
119   rtx note;
120   for (note = notes; note; note = XEXP (note, 1))
121     if (REG_NOTE_KIND (note) == kind && REG_P (XEXP (note, 0)))
122       {
123         rtx reg = XEXP (note, 0);
124         /* There must not be pseudos at this point.  */
125         gcc_assert (HARD_REGISTER_P (reg));
126         remove_from_hard_reg_set (pset, GET_MODE (reg), REGNO (reg));
127       }
128 }
129
130 /* For a def-use chain CHAIN in basic block B, find which registers overlap
131    its lifetime and set the corresponding bits in *PSET.  */
132
133 static void
134 merge_overlapping_regs (basic_block b, HARD_REG_SET *pset,
135                         struct du_chain *chain)
136 {
137   struct du_chain *t = chain;
138   rtx insn;
139   HARD_REG_SET live;
140   df_ref *def_rec;
141
142   REG_SET_TO_HARD_REG_SET (live, df_get_live_in (b));
143   for (def_rec = df_get_artificial_defs (b->index); *def_rec; def_rec++)
144     {
145       df_ref def = *def_rec;
146       if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
147         SET_HARD_REG_BIT (live, DF_REF_REGNO (def));
148     }
149   insn = BB_HEAD (b);
150   while (t)
151     {
152       /* Search forward until the next reference to the register to be
153          renamed.  */
154       while (insn != t->insn)
155         {
156           if (INSN_P (insn))
157             {
158               clear_dead_regs (&live, REG_DEAD, REG_NOTES (insn));
159               note_stores (PATTERN (insn), note_sets, (void *) &live);
160               /* Only record currently live regs if we are inside the
161                  reg's live range.  */
162               if (t != chain)
163                 IOR_HARD_REG_SET (*pset, live);
164               clear_dead_regs (&live, REG_UNUSED, REG_NOTES (insn));
165             }
166           insn = NEXT_INSN (insn);
167         }
168
169       IOR_HARD_REG_SET (*pset, live);
170
171       /* For the last reference, also merge in all registers set in the
172          same insn.
173          @@@ We only have take earlyclobbered sets into account.  */
174       if (! t->next_use)
175         note_stores (PATTERN (insn), note_sets, (void *) pset);
176
177       t = t->next_use;
178     }
179 }
180
181 /* Perform register renaming on the current function.  */
182
183 static void
184 regrename_optimize (void)
185 {
186   int tick[FIRST_PSEUDO_REGISTER];
187   int this_tick = 0;
188   basic_block bb;
189   char *first_obj;
190
191   df_set_flags (DF_LR_RUN_DCE);
192   df_note_add_problem ();
193   df_analyze ();
194   df_set_flags (DF_DEFER_INSN_RESCAN);
195
196   memset (tick, 0, sizeof tick);
197
198   gcc_obstack_init (&rename_obstack);
199   first_obj = XOBNEWVAR (&rename_obstack, char, 0);
200
201   FOR_EACH_BB (bb)
202     {
203       struct du_chain *all_chains = 0;
204       HARD_REG_SET unavailable;
205       HARD_REG_SET regs_seen;
206
207       CLEAR_HARD_REG_SET (unavailable);
208
209       if (dump_file)
210         fprintf (dump_file, "\nBasic block %d:\n", bb->index);
211
212       all_chains = build_def_use (bb);
213
214       if (dump_file)
215         dump_def_use_chain (all_chains);
216
217       CLEAR_HARD_REG_SET (unavailable);
218       /* Don't clobber traceback for noreturn functions.  */
219       if (frame_pointer_needed)
220         {
221           add_to_hard_reg_set (&unavailable, Pmode, FRAME_POINTER_REGNUM);
222 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
223           add_to_hard_reg_set (&unavailable, Pmode, HARD_FRAME_POINTER_REGNUM);
224 #endif
225         }
226
227       CLEAR_HARD_REG_SET (regs_seen);
228       while (all_chains)
229         {
230           int new_reg, best_new_reg;
231           int n_uses;
232           struct du_chain *this_du = all_chains;
233           struct du_chain *tmp, *last;
234           HARD_REG_SET this_unavailable;
235           int reg = REGNO (*this_du->loc);
236           int i;
237
238           all_chains = this_du->next_chain;
239
240           best_new_reg = reg;
241
242 #if 0 /* This just disables optimization opportunities.  */
243           /* Only rename once we've seen the reg more than once.  */
244           if (! TEST_HARD_REG_BIT (regs_seen, reg))
245             {
246               SET_HARD_REG_BIT (regs_seen, reg);
247               continue;
248             }
249 #endif
250
251           if (fixed_regs[reg] || global_regs[reg]
252 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
253               || (frame_pointer_needed && reg == HARD_FRAME_POINTER_REGNUM)
254 #else
255               || (frame_pointer_needed && reg == FRAME_POINTER_REGNUM)
256 #endif
257               )
258             continue;
259
260           COPY_HARD_REG_SET (this_unavailable, unavailable);
261
262           /* Find last entry on chain (which has the need_caller_save bit),
263              count number of uses, and narrow the set of registers we can
264              use for renaming.  */
265           n_uses = 0;
266           for (last = this_du; last->next_use; last = last->next_use)
267             {
268               n_uses++;
269               IOR_COMPL_HARD_REG_SET (this_unavailable,
270                                       reg_class_contents[last->cl]);
271             }
272           if (n_uses < 1)
273             continue;
274
275           IOR_COMPL_HARD_REG_SET (this_unavailable,
276                                   reg_class_contents[last->cl]);
277
278           if (this_du->need_caller_save_reg)
279             IOR_HARD_REG_SET (this_unavailable, call_used_reg_set);
280
281           merge_overlapping_regs (bb, &this_unavailable, this_du);
282
283           /* Now potential_regs is a reasonable approximation, let's
284              have a closer look at each register still in there.  */
285           for (new_reg = 0; new_reg < FIRST_PSEUDO_REGISTER; new_reg++)
286             {
287               int nregs = hard_regno_nregs[new_reg][GET_MODE (*this_du->loc)];
288
289               for (i = nregs - 1; i >= 0; --i)
290                 if (TEST_HARD_REG_BIT (this_unavailable, new_reg + i)
291                     || fixed_regs[new_reg + i]
292                     || global_regs[new_reg + i]
293                     /* Can't use regs which aren't saved by the prologue.  */
294                     || (! df_regs_ever_live_p (new_reg + i)
295                         && ! call_used_regs[new_reg + i])
296 #ifdef LEAF_REGISTERS
297                     /* We can't use a non-leaf register if we're in a
298                        leaf function.  */
299                     || (current_function_is_leaf
300                         && !LEAF_REGISTERS[new_reg + i])
301 #endif
302 #ifdef HARD_REGNO_RENAME_OK
303                     || ! HARD_REGNO_RENAME_OK (reg + i, new_reg + i)
304 #endif
305                     )
306                   break;
307               if (i >= 0)
308                 continue;
309
310               /* See whether it accepts all modes that occur in
311                  definition and uses.  */
312               for (tmp = this_du; tmp; tmp = tmp->next_use)
313                 if (! HARD_REGNO_MODE_OK (new_reg, GET_MODE (*tmp->loc))
314                     || (tmp->need_caller_save_reg
315                         && ! (HARD_REGNO_CALL_PART_CLOBBERED
316                               (reg, GET_MODE (*tmp->loc)))
317                         && (HARD_REGNO_CALL_PART_CLOBBERED
318                             (new_reg, GET_MODE (*tmp->loc)))))
319                   break;
320               if (! tmp)
321                 {
322                   if (tick[best_new_reg] > tick[new_reg])
323                     best_new_reg = new_reg;
324                 }
325             }
326
327           if (dump_file)
328             {
329               fprintf (dump_file, "Register %s in insn %d",
330                        reg_names[reg], INSN_UID (last->insn));
331               if (last->need_caller_save_reg)
332                 fprintf (dump_file, " crosses a call");
333             }
334
335           if (best_new_reg == reg)
336             {
337               tick[reg] = ++this_tick;
338               if (dump_file)
339                 fprintf (dump_file, "; no available better choice\n");
340               continue;
341             }
342
343           if (dump_file)
344             fprintf (dump_file, ", renamed as %s\n", reg_names[best_new_reg]);
345
346           do_replace (this_du, best_new_reg);
347           tick[best_new_reg] = ++this_tick;
348           df_set_regs_ever_live (best_new_reg, true);
349         }
350
351       obstack_free (&rename_obstack, first_obj);
352     }
353
354   obstack_free (&rename_obstack, NULL);
355
356   if (dump_file)
357     fputc ('\n', dump_file);
358 }
359
360 static void
361 do_replace (struct du_chain *chain, int reg)
362 {
363   while (chain)
364     {
365       unsigned int regno = ORIGINAL_REGNO (*chain->loc);
366       struct reg_attrs * attr = REG_ATTRS (*chain->loc);
367       int reg_ptr = REG_POINTER (*chain->loc);
368
369       *chain->loc = gen_raw_REG (GET_MODE (*chain->loc), reg);
370       if (regno >= FIRST_PSEUDO_REGISTER)
371         ORIGINAL_REGNO (*chain->loc) = regno;
372       REG_ATTRS (*chain->loc) = attr;
373       REG_POINTER (*chain->loc) = reg_ptr;
374       df_insn_rescan (chain->insn);
375       chain = chain->next_use;
376     }
377 }
378
379
380 static struct du_chain *open_chains;
381 static struct du_chain *closed_chains;
382
383 static void
384 scan_rtx_reg (rtx insn, rtx *loc, enum reg_class cl,
385               enum scan_actions action, enum op_type type, int earlyclobber)
386 {
387   struct du_chain **p;
388   rtx x = *loc;
389   enum machine_mode mode = GET_MODE (x);
390   int this_regno = REGNO (x);
391   int this_nregs = hard_regno_nregs[this_regno][mode];
392
393   if (action == mark_write)
394     {
395       if (type == OP_OUT)
396         {
397           struct du_chain *this_du = XOBNEW (&rename_obstack, struct du_chain);
398           this_du->next_use = 0;
399           this_du->next_chain = open_chains;
400           this_du->loc = loc;
401           this_du->insn = insn;
402           this_du->cl = cl;
403           this_du->need_caller_save_reg = 0;
404           this_du->earlyclobber = earlyclobber;
405           open_chains = this_du;
406         }
407       return;
408     }
409
410   if ((type == OP_OUT) != (action == terminate_write || action == mark_access))
411     return;
412
413   for (p = &open_chains; *p;)
414     {
415       struct du_chain *this_du = *p;
416
417       /* Check if the chain has been terminated if it has then skip to
418          the next chain.
419
420          This can happen when we've already appended the location to
421          the chain in Step 3, but are trying to hide in-out operands
422          from terminate_write in Step 5.  */
423
424       if (*this_du->loc == cc0_rtx)
425         p = &this_du->next_chain;
426       else
427         {
428           int regno = REGNO (*this_du->loc);
429           int nregs = hard_regno_nregs[regno][GET_MODE (*this_du->loc)];
430           int exact_match = (regno == this_regno && nregs == this_nregs);
431
432           if (regno + nregs <= this_regno
433               || this_regno + this_nregs <= regno)
434             {
435               p = &this_du->next_chain;
436               continue;
437             }
438
439           if (action == mark_read || action == mark_access)
440             {
441               gcc_assert (exact_match);
442
443               /* ??? Class NO_REGS can happen if the md file makes use of
444                  EXTRA_CONSTRAINTS to match registers.  Which is arguably
445                  wrong, but there we are.  Since we know not what this may
446                  be replaced with, terminate the chain.  */
447               if (cl != NO_REGS)
448                 {
449                   this_du = XOBNEW (&rename_obstack, struct du_chain);
450                   this_du->next_use = 0;
451                   this_du->next_chain = (*p)->next_chain;
452                   this_du->loc = loc;
453                   this_du->insn = insn;
454                   this_du->cl = cl;
455                   this_du->need_caller_save_reg = 0;
456                   while (*p)
457                     p = &(*p)->next_use;
458                   *p = this_du;
459                   return;
460                 }
461             }
462
463           if (action != terminate_overlapping_read || ! exact_match)
464             {
465               struct du_chain *next = this_du->next_chain;
466
467               /* Whether the terminated chain can be used for renaming
468                  depends on the action and this being an exact match.
469                  In either case, we remove this element from open_chains.  */
470
471               if ((action == terminate_dead || action == terminate_write)
472                   && exact_match)
473                 {
474                   this_du->next_chain = closed_chains;
475                   closed_chains = this_du;
476                   if (dump_file)
477                     fprintf (dump_file,
478                              "Closing chain %s at insn %d (%s)\n",
479                              reg_names[REGNO (*this_du->loc)], INSN_UID (insn),
480                              scan_actions_name[(int) action]);
481                 }
482               else
483                 {
484                   if (dump_file)
485                     fprintf (dump_file,
486                              "Discarding chain %s at insn %d (%s)\n",
487                              reg_names[REGNO (*this_du->loc)], INSN_UID (insn),
488                              scan_actions_name[(int) action]);
489                 }
490               *p = next;
491             }
492           else
493             p = &this_du->next_chain;
494         }
495     }
496 }
497
498 /* Adapted from find_reloads_address_1.  CL is INDEX_REG_CLASS or
499    BASE_REG_CLASS depending on how the register is being considered.  */
500
501 static void
502 scan_rtx_address (rtx insn, rtx *loc, enum reg_class cl,
503                   enum scan_actions action, enum machine_mode mode)
504 {
505   rtx x = *loc;
506   RTX_CODE code = GET_CODE (x);
507   const char *fmt;
508   int i, j;
509
510   if (action == mark_write || action == mark_access)
511     return;
512
513   switch (code)
514     {
515     case PLUS:
516       {
517         rtx orig_op0 = XEXP (x, 0);
518         rtx orig_op1 = XEXP (x, 1);
519         RTX_CODE code0 = GET_CODE (orig_op0);
520         RTX_CODE code1 = GET_CODE (orig_op1);
521         rtx op0 = orig_op0;
522         rtx op1 = orig_op1;
523         rtx *locI = NULL;
524         rtx *locB = NULL;
525         enum rtx_code index_code = SCRATCH;
526
527         if (GET_CODE (op0) == SUBREG)
528           {
529             op0 = SUBREG_REG (op0);
530             code0 = GET_CODE (op0);
531           }
532
533         if (GET_CODE (op1) == SUBREG)
534           {
535             op1 = SUBREG_REG (op1);
536             code1 = GET_CODE (op1);
537           }
538
539         if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
540             || code0 == ZERO_EXTEND || code1 == MEM)
541           {
542             locI = &XEXP (x, 0);
543             locB = &XEXP (x, 1);
544             index_code = GET_CODE (*locI);
545           }
546         else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
547                  || code1 == ZERO_EXTEND || code0 == MEM)
548           {
549             locI = &XEXP (x, 1);
550             locB = &XEXP (x, 0);
551             index_code = GET_CODE (*locI);
552           }
553         else if (code0 == CONST_INT || code0 == CONST
554                  || code0 == SYMBOL_REF || code0 == LABEL_REF)
555           {
556             locB = &XEXP (x, 1);
557             index_code = GET_CODE (XEXP (x, 0));
558           }
559         else if (code1 == CONST_INT || code1 == CONST
560                  || code1 == SYMBOL_REF || code1 == LABEL_REF)
561           {
562             locB = &XEXP (x, 0);
563             index_code = GET_CODE (XEXP (x, 1));
564           }
565         else if (code0 == REG && code1 == REG)
566           {
567             int index_op;
568             unsigned regno0 = REGNO (op0), regno1 = REGNO (op1);
569
570             if (REGNO_OK_FOR_INDEX_P (regno1)
571                 && regno_ok_for_base_p (regno0, mode, PLUS, REG))
572               index_op = 1;
573             else if (REGNO_OK_FOR_INDEX_P (regno0)
574                      && regno_ok_for_base_p (regno1, mode, PLUS, REG))
575               index_op = 0;
576             else if (regno_ok_for_base_p (regno0, mode, PLUS, REG)
577                      || REGNO_OK_FOR_INDEX_P (regno1))
578               index_op = 1;
579             else if (regno_ok_for_base_p (regno1, mode, PLUS, REG))
580               index_op = 0;
581             else
582               index_op = 1;
583
584             locI = &XEXP (x, index_op);
585             locB = &XEXP (x, !index_op);
586             index_code = GET_CODE (*locI);
587           }
588         else if (code0 == REG)
589           {
590             locI = &XEXP (x, 0);
591             locB = &XEXP (x, 1);
592             index_code = GET_CODE (*locI);
593           }
594         else if (code1 == REG)
595           {
596             locI = &XEXP (x, 1);
597             locB = &XEXP (x, 0);
598             index_code = GET_CODE (*locI);
599           }
600
601         if (locI)
602           scan_rtx_address (insn, locI, INDEX_REG_CLASS, action, mode);
603         if (locB)
604           scan_rtx_address (insn, locB, base_reg_class (mode, PLUS, index_code),
605                             action, mode);
606
607         return;
608       }
609
610     case POST_INC:
611     case POST_DEC:
612     case POST_MODIFY:
613     case PRE_INC:
614     case PRE_DEC:
615     case PRE_MODIFY:
616 #ifndef AUTO_INC_DEC
617       /* If the target doesn't claim to handle autoinc, this must be
618          something special, like a stack push.  Kill this chain.  */
619       action = terminate_all_read;
620 #endif
621       break;
622
623     case MEM:
624       scan_rtx_address (insn, &XEXP (x, 0),
625                         base_reg_class (GET_MODE (x), MEM, SCRATCH), action,
626                         GET_MODE (x));
627       return;
628
629     case REG:
630       scan_rtx_reg (insn, loc, cl, action, OP_IN, 0);
631       return;
632
633     default:
634       break;
635     }
636
637   fmt = GET_RTX_FORMAT (code);
638   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
639     {
640       if (fmt[i] == 'e')
641         scan_rtx_address (insn, &XEXP (x, i), cl, action, mode);
642       else if (fmt[i] == 'E')
643         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
644           scan_rtx_address (insn, &XVECEXP (x, i, j), cl, action, mode);
645     }
646 }
647
648 static void
649 scan_rtx (rtx insn, rtx *loc, enum reg_class cl,
650           enum scan_actions action, enum op_type type, int earlyclobber)
651 {
652   const char *fmt;
653   rtx x = *loc;
654   enum rtx_code code = GET_CODE (x);
655   int i, j;
656
657   code = GET_CODE (x);
658   switch (code)
659     {
660     case CONST:
661     case CONST_INT:
662     case CONST_DOUBLE:
663     case CONST_FIXED:
664     case CONST_VECTOR:
665     case SYMBOL_REF:
666     case LABEL_REF:
667     case CC0:
668     case PC:
669       return;
670
671     case REG:
672       scan_rtx_reg (insn, loc, cl, action, type, earlyclobber);
673       return;
674
675     case MEM:
676       scan_rtx_address (insn, &XEXP (x, 0),
677                         base_reg_class (GET_MODE (x), MEM, SCRATCH), action,
678                         GET_MODE (x));
679       return;
680
681     case SET:
682       scan_rtx (insn, &SET_SRC (x), cl, action, OP_IN, 0);
683       scan_rtx (insn, &SET_DEST (x), cl, action,
684                 GET_CODE (PATTERN (insn)) == COND_EXEC ? OP_INOUT : OP_OUT, 0);
685       return;
686
687     case STRICT_LOW_PART:
688       scan_rtx (insn, &XEXP (x, 0), cl, action, OP_INOUT, earlyclobber);
689       return;
690
691     case ZERO_EXTRACT:
692     case SIGN_EXTRACT:
693       scan_rtx (insn, &XEXP (x, 0), cl, action,
694                 type == OP_IN ? OP_IN : OP_INOUT, earlyclobber);
695       scan_rtx (insn, &XEXP (x, 1), cl, action, OP_IN, 0);
696       scan_rtx (insn, &XEXP (x, 2), cl, action, OP_IN, 0);
697       return;
698
699     case POST_INC:
700     case PRE_INC:
701     case POST_DEC:
702     case PRE_DEC:
703     case POST_MODIFY:
704     case PRE_MODIFY:
705       /* Should only happen inside MEM.  */
706       gcc_unreachable ();
707
708     case CLOBBER:
709       scan_rtx (insn, &SET_DEST (x), cl, action,
710                 GET_CODE (PATTERN (insn)) == COND_EXEC ? OP_INOUT : OP_OUT, 0);
711       return;
712
713     case EXPR_LIST:
714       scan_rtx (insn, &XEXP (x, 0), cl, action, type, 0);
715       if (XEXP (x, 1))
716         scan_rtx (insn, &XEXP (x, 1), cl, action, type, 0);
717       return;
718
719     default:
720       break;
721     }
722
723   fmt = GET_RTX_FORMAT (code);
724   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
725     {
726       if (fmt[i] == 'e')
727         scan_rtx (insn, &XEXP (x, i), cl, action, type, 0);
728       else if (fmt[i] == 'E')
729         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
730           scan_rtx (insn, &XVECEXP (x, i, j), cl, action, type, 0);
731     }
732 }
733
734 /* Build def/use chain.  */
735
736 static struct du_chain *
737 build_def_use (basic_block bb)
738 {
739   rtx insn;
740
741   open_chains = closed_chains = NULL;
742
743   for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn))
744     {
745       if (INSN_P (insn))
746         {
747           int n_ops;
748           rtx note;
749           rtx old_operands[MAX_RECOG_OPERANDS];
750           rtx old_dups[MAX_DUP_OPERANDS];
751           int i, icode;
752           int alt;
753           int predicated;
754
755           /* Process the insn, determining its effect on the def-use
756              chains.  We perform the following steps with the register
757              references in the insn:
758              (1) Any read that overlaps an open chain, but doesn't exactly
759                  match, causes that chain to be closed.  We can't deal
760                  with overlaps yet.
761              (2) Any read outside an operand causes any chain it overlaps
762                  with to be closed, since we can't replace it.
763              (3) Any read inside an operand is added if there's already
764                  an open chain for it.
765              (4) For any REG_DEAD note we find, close open chains that
766                  overlap it.
767              (5) For any write we find, close open chains that overlap it.
768              (6) For any write we find in an operand, make a new chain.
769              (7) For any REG_UNUSED, close any chains we just opened.  */
770
771           icode = recog_memoized (insn);
772           extract_insn (insn);
773           if (! constrain_operands (1))
774             fatal_insn_not_found (insn);
775           preprocess_constraints ();
776           alt = which_alternative;
777           n_ops = recog_data.n_operands;
778
779           /* Simplify the code below by rewriting things to reflect
780              matching constraints.  Also promote OP_OUT to OP_INOUT
781              in predicated instructions.  */
782
783           predicated = GET_CODE (PATTERN (insn)) == COND_EXEC;
784           for (i = 0; i < n_ops; ++i)
785             {
786               int matches = recog_op_alt[i][alt].matches;
787               if (matches >= 0)
788                 recog_op_alt[i][alt].cl = recog_op_alt[matches][alt].cl;
789               if (matches >= 0 || recog_op_alt[i][alt].matched >= 0
790                   || (predicated && recog_data.operand_type[i] == OP_OUT))
791                 recog_data.operand_type[i] = OP_INOUT;
792             }
793
794           /* Step 1: Close chains for which we have overlapping reads.  */
795           for (i = 0; i < n_ops; i++)
796             scan_rtx (insn, recog_data.operand_loc[i],
797                       NO_REGS, terminate_overlapping_read,
798                       recog_data.operand_type[i], 0);
799
800           /* Step 2: Close chains for which we have reads outside operands.
801              We do this by munging all operands into CC0, and closing
802              everything remaining.  */
803
804           for (i = 0; i < n_ops; i++)
805             {
806               old_operands[i] = recog_data.operand[i];
807               /* Don't squash match_operator or match_parallel here, since
808                  we don't know that all of the contained registers are
809                  reachable by proper operands.  */
810               if (recog_data.constraints[i][0] == '\0')
811                 continue;
812               *recog_data.operand_loc[i] = cc0_rtx;
813             }
814           for (i = 0; i < recog_data.n_dups; i++)
815             {
816               old_dups[i] = *recog_data.dup_loc[i];
817               *recog_data.dup_loc[i] = cc0_rtx;
818             }
819
820           scan_rtx (insn, &PATTERN (insn), NO_REGS, terminate_all_read,
821                     OP_IN, 0);
822
823           for (i = 0; i < recog_data.n_dups; i++)
824             *recog_data.dup_loc[i] = old_dups[i];
825           for (i = 0; i < n_ops; i++)
826             *recog_data.operand_loc[i] = old_operands[i];
827           if (recog_data.n_dups)
828             df_insn_rescan (insn);
829
830           /* Step 2B: Can't rename function call argument registers.  */
831           if (CALL_P (insn) && CALL_INSN_FUNCTION_USAGE (insn))
832             scan_rtx (insn, &CALL_INSN_FUNCTION_USAGE (insn),
833                       NO_REGS, terminate_all_read, OP_IN, 0);
834
835           /* Step 2C: Can't rename asm operands that were originally
836              hard registers.  */
837           if (asm_noperands (PATTERN (insn)) > 0)
838             for (i = 0; i < n_ops; i++)
839               {
840                 rtx *loc = recog_data.operand_loc[i];
841                 rtx op = *loc;
842
843                 if (REG_P (op)
844                     && REGNO (op) == ORIGINAL_REGNO (op)
845                     && (recog_data.operand_type[i] == OP_IN
846                         || recog_data.operand_type[i] == OP_INOUT))
847                   scan_rtx (insn, loc, NO_REGS, terminate_all_read, OP_IN, 0);
848               }
849
850           /* Step 3: Append to chains for reads inside operands.  */
851           for (i = 0; i < n_ops + recog_data.n_dups; i++)
852             {
853               int opn = i < n_ops ? i : recog_data.dup_num[i - n_ops];
854               rtx *loc = (i < n_ops
855                           ? recog_data.operand_loc[opn]
856                           : recog_data.dup_loc[i - n_ops]);
857               enum reg_class cl = recog_op_alt[opn][alt].cl;
858               enum op_type type = recog_data.operand_type[opn];
859
860               /* Don't scan match_operand here, since we've no reg class
861                  information to pass down.  Any operands that we could
862                  substitute in will be represented elsewhere.  */
863               if (recog_data.constraints[opn][0] == '\0')
864                 continue;
865
866               if (recog_op_alt[opn][alt].is_address)
867                 scan_rtx_address (insn, loc, cl, mark_read, VOIDmode);
868               else
869                 scan_rtx (insn, loc, cl, mark_read, type, 0);
870             }
871
872           /* Step 3B: Record updates for regs in REG_INC notes, and
873              source regs in REG_FRAME_RELATED_EXPR notes.  */
874           for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
875             if (REG_NOTE_KIND (note) == REG_INC
876                 || REG_NOTE_KIND (note) == REG_FRAME_RELATED_EXPR)
877               scan_rtx (insn, &XEXP (note, 0), ALL_REGS, mark_read,
878                         OP_INOUT, 0);
879
880           /* Step 4: Close chains for registers that die here.  */
881           for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
882             if (REG_NOTE_KIND (note) == REG_DEAD)
883               scan_rtx (insn, &XEXP (note, 0), NO_REGS, terminate_dead,
884                         OP_IN, 0);
885
886           /* Step 4B: If this is a call, any chain live at this point
887              requires a caller-saved reg.  */
888           if (CALL_P (insn))
889             {
890               struct du_chain *p;
891               for (p = open_chains; p; p = p->next_chain)
892                 p->need_caller_save_reg = 1;
893             }
894
895           /* Step 5: Close open chains that overlap writes.  Similar to
896              step 2, we hide in-out operands, since we do not want to
897              close these chains.  */
898
899           for (i = 0; i < n_ops; i++)
900             {
901               old_operands[i] = recog_data.operand[i];
902               if (recog_data.operand_type[i] == OP_INOUT)
903                 *recog_data.operand_loc[i] = cc0_rtx;
904             }
905           for (i = 0; i < recog_data.n_dups; i++)
906             {
907               int opn = recog_data.dup_num[i];
908               old_dups[i] = *recog_data.dup_loc[i];
909               if (recog_data.operand_type[opn] == OP_INOUT)
910                 *recog_data.dup_loc[i] = cc0_rtx;
911             }
912
913           scan_rtx (insn, &PATTERN (insn), NO_REGS, terminate_write, OP_IN, 0);
914
915           for (i = 0; i < recog_data.n_dups; i++)
916             *recog_data.dup_loc[i] = old_dups[i];
917           for (i = 0; i < n_ops; i++)
918             *recog_data.operand_loc[i] = old_operands[i];
919
920           /* Step 6: Begin new chains for writes inside operands.  */
921           /* ??? Many targets have output constraints on the SET_DEST
922              of a call insn, which is stupid, since these are certainly
923              ABI defined hard registers.  Don't change calls at all.
924              Similarly take special care for asm statement that originally
925              referenced hard registers.  */
926           if (asm_noperands (PATTERN (insn)) > 0)
927             {
928               for (i = 0; i < n_ops; i++)
929                 if (recog_data.operand_type[i] == OP_OUT)
930                   {
931                     rtx *loc = recog_data.operand_loc[i];
932                     rtx op = *loc;
933                     enum reg_class cl = recog_op_alt[i][alt].cl;
934
935                     if (REG_P (op)
936                         && REGNO (op) == ORIGINAL_REGNO (op))
937                       continue;
938
939                     scan_rtx (insn, loc, cl, mark_write, OP_OUT,
940                               recog_op_alt[i][alt].earlyclobber);
941                   }
942             }
943           else if (!CALL_P (insn))
944             for (i = 0; i < n_ops + recog_data.n_dups; i++)
945               {
946                 int opn = i < n_ops ? i : recog_data.dup_num[i - n_ops];
947                 rtx *loc = (i < n_ops
948                             ? recog_data.operand_loc[opn]
949                             : recog_data.dup_loc[i - n_ops]);
950                 enum reg_class cl = recog_op_alt[opn][alt].cl;
951
952                 if (recog_data.operand_type[opn] == OP_OUT)
953                   scan_rtx (insn, loc, cl, mark_write, OP_OUT,
954                             recog_op_alt[opn][alt].earlyclobber);
955               }
956
957           /* Step 6B: Record destination regs in REG_FRAME_RELATED_EXPR
958              notes for update.  */
959           for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
960             if (REG_NOTE_KIND (note) == REG_FRAME_RELATED_EXPR)
961               scan_rtx (insn, &XEXP (note, 0), ALL_REGS, mark_access,
962                         OP_INOUT, 0);
963
964           /* Step 7: Close chains for registers that were never
965              really used here.  */
966           for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
967             if (REG_NOTE_KIND (note) == REG_UNUSED)
968               scan_rtx (insn, &XEXP (note, 0), NO_REGS, terminate_dead,
969                         OP_IN, 0);
970         }
971       if (insn == BB_END (bb))
972         break;
973     }
974
975   /* Since we close every chain when we find a REG_DEAD note, anything that
976      is still open lives past the basic block, so it can't be renamed.  */
977   return closed_chains;
978 }
979
980 /* Dump all def/use chains in CHAINS to DUMP_FILE.  They are
981    printed in reverse order as that's how we build them.  */
982
983 static void
984 dump_def_use_chain (struct du_chain *chains)
985 {
986   while (chains)
987     {
988       struct du_chain *this_du = chains;
989       int r = REGNO (*this_du->loc);
990       int nregs = hard_regno_nregs[r][GET_MODE (*this_du->loc)];
991       fprintf (dump_file, "Register %s (%d):", reg_names[r], nregs);
992       while (this_du)
993         {
994           fprintf (dump_file, " %d [%s]", INSN_UID (this_du->insn),
995                    reg_class_names[this_du->cl]);
996           this_du = this_du->next_use;
997         }
998       fprintf (dump_file, "\n");
999       chains = chains->next_chain;
1000     }
1001 }
1002 \f
1003 /* The following code does forward propagation of hard register copies.
1004    The object is to eliminate as many dependencies as possible, so that
1005    we have the most scheduling freedom.  As a side effect, we also clean
1006    up some silly register allocation decisions made by reload.  This
1007    code may be obsoleted by a new register allocator.  */
1008
1009 /* For each register, we have a list of registers that contain the same
1010    value.  The OLDEST_REGNO field points to the head of the list, and
1011    the NEXT_REGNO field runs through the list.  The MODE field indicates
1012    what mode the data is known to be in; this field is VOIDmode when the
1013    register is not known to contain valid data.  */
1014
1015 struct value_data_entry
1016 {
1017   enum machine_mode mode;
1018   unsigned int oldest_regno;
1019   unsigned int next_regno;
1020 };
1021
1022 struct value_data
1023 {
1024   struct value_data_entry e[FIRST_PSEUDO_REGISTER];
1025   unsigned int max_value_regs;
1026 };
1027
1028 static void kill_value_one_regno (unsigned, struct value_data *);
1029 static void kill_value_regno (unsigned, unsigned, struct value_data *);
1030 static void kill_value (rtx, struct value_data *);
1031 static void set_value_regno (unsigned, enum machine_mode, struct value_data *);
1032 static void init_value_data (struct value_data *);
1033 static void kill_clobbered_value (rtx, const_rtx, void *);
1034 static void kill_set_value (rtx, const_rtx, void *);
1035 static int kill_autoinc_value (rtx *, void *);
1036 static void copy_value (rtx, rtx, struct value_data *);
1037 static bool mode_change_ok (enum machine_mode, enum machine_mode,
1038                             unsigned int);
1039 static rtx maybe_mode_change (enum machine_mode, enum machine_mode,
1040                               enum machine_mode, unsigned int, unsigned int);
1041 static rtx find_oldest_value_reg (enum reg_class, rtx, struct value_data *);
1042 static bool replace_oldest_value_reg (rtx *, enum reg_class, rtx,
1043                                       struct value_data *);
1044 static bool replace_oldest_value_addr (rtx *, enum reg_class,
1045                                        enum machine_mode, rtx,
1046                                        struct value_data *);
1047 static bool replace_oldest_value_mem (rtx, rtx, struct value_data *);
1048 static bool copyprop_hardreg_forward_1 (basic_block, struct value_data *);
1049 extern void debug_value_data (struct value_data *);
1050 #ifdef ENABLE_CHECKING
1051 static void validate_value_data (struct value_data *);
1052 #endif
1053
1054 /* Kill register REGNO.  This involves removing it from any value
1055    lists, and resetting the value mode to VOIDmode.  This is only a
1056    helper function; it does not handle any hard registers overlapping
1057    with REGNO.  */
1058
1059 static void
1060 kill_value_one_regno (unsigned int regno, struct value_data *vd)
1061 {
1062   unsigned int i, next;
1063
1064   if (vd->e[regno].oldest_regno != regno)
1065     {
1066       for (i = vd->e[regno].oldest_regno;
1067            vd->e[i].next_regno != regno;
1068            i = vd->e[i].next_regno)
1069         continue;
1070       vd->e[i].next_regno = vd->e[regno].next_regno;
1071     }
1072   else if ((next = vd->e[regno].next_regno) != INVALID_REGNUM)
1073     {
1074       for (i = next; i != INVALID_REGNUM; i = vd->e[i].next_regno)
1075         vd->e[i].oldest_regno = next;
1076     }
1077
1078   vd->e[regno].mode = VOIDmode;
1079   vd->e[regno].oldest_regno = regno;
1080   vd->e[regno].next_regno = INVALID_REGNUM;
1081
1082 #ifdef ENABLE_CHECKING
1083   validate_value_data (vd);
1084 #endif
1085 }
1086
1087 /* Kill the value in register REGNO for NREGS, and any other registers
1088    whose values overlap.  */
1089
1090 static void
1091 kill_value_regno (unsigned int regno, unsigned int nregs,
1092                   struct value_data *vd)
1093 {
1094   unsigned int j;
1095
1096   /* Kill the value we're told to kill.  */
1097   for (j = 0; j < nregs; ++j)
1098     kill_value_one_regno (regno + j, vd);
1099
1100   /* Kill everything that overlapped what we're told to kill.  */
1101   if (regno < vd->max_value_regs)
1102     j = 0;
1103   else
1104     j = regno - vd->max_value_regs;
1105   for (; j < regno; ++j)
1106     {
1107       unsigned int i, n;
1108       if (vd->e[j].mode == VOIDmode)
1109         continue;
1110       n = hard_regno_nregs[j][vd->e[j].mode];
1111       if (j + n > regno)
1112         for (i = 0; i < n; ++i)
1113           kill_value_one_regno (j + i, vd);
1114     }
1115 }
1116
1117 /* Kill X.  This is a convenience function wrapping kill_value_regno
1118    so that we mind the mode the register is in.  */
1119
1120 static void
1121 kill_value (rtx x, struct value_data *vd)
1122 {
1123   rtx orig_rtx = x;
1124
1125   if (GET_CODE (x) == SUBREG)
1126     {
1127       x = simplify_subreg (GET_MODE (x), SUBREG_REG (x),
1128                            GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
1129       if (x == NULL_RTX)
1130         x = SUBREG_REG (orig_rtx);
1131     }
1132   if (REG_P (x))
1133     {
1134       unsigned int regno = REGNO (x);
1135       unsigned int n = hard_regno_nregs[regno][GET_MODE (x)];
1136
1137       kill_value_regno (regno, n, vd);
1138     }
1139 }
1140
1141 /* Remember that REGNO is valid in MODE.  */
1142
1143 static void
1144 set_value_regno (unsigned int regno, enum machine_mode mode,
1145                  struct value_data *vd)
1146 {
1147   unsigned int nregs;
1148
1149   vd->e[regno].mode = mode;
1150
1151   nregs = hard_regno_nregs[regno][mode];
1152   if (nregs > vd->max_value_regs)
1153     vd->max_value_regs = nregs;
1154 }
1155
1156 /* Initialize VD such that there are no known relationships between regs.  */
1157
1158 static void
1159 init_value_data (struct value_data *vd)
1160 {
1161   int i;
1162   for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1163     {
1164       vd->e[i].mode = VOIDmode;
1165       vd->e[i].oldest_regno = i;
1166       vd->e[i].next_regno = INVALID_REGNUM;
1167     }
1168   vd->max_value_regs = 0;
1169 }
1170
1171 /* Called through note_stores.  If X is clobbered, kill its value.  */
1172
1173 static void
1174 kill_clobbered_value (rtx x, const_rtx set, void *data)
1175 {
1176   struct value_data *const vd = (struct value_data *) data;
1177   if (GET_CODE (set) == CLOBBER)
1178     kill_value (x, vd);
1179 }
1180
1181 /* Called through note_stores.  If X is set, not clobbered, kill its
1182    current value and install it as the root of its own value list.  */
1183
1184 static void
1185 kill_set_value (rtx x, const_rtx set, void *data)
1186 {
1187   struct value_data *const vd = (struct value_data *) data;
1188   if (GET_CODE (set) != CLOBBER)
1189     {
1190       kill_value (x, vd);
1191       if (REG_P (x))
1192         set_value_regno (REGNO (x), GET_MODE (x), vd);
1193     }
1194 }
1195
1196 /* Called through for_each_rtx.  Kill any register used as the base of an
1197    auto-increment expression, and install that register as the root of its
1198    own value list.  */
1199
1200 static int
1201 kill_autoinc_value (rtx *px, void *data)
1202 {
1203   rtx x = *px;
1204   struct value_data *const vd = (struct value_data *) data;
1205
1206   if (GET_RTX_CLASS (GET_CODE (x)) == RTX_AUTOINC)
1207     {
1208       x = XEXP (x, 0);
1209       kill_value (x, vd);
1210       set_value_regno (REGNO (x), Pmode, vd);
1211       return -1;
1212     }
1213
1214   return 0;
1215 }
1216
1217 /* Assert that SRC has been copied to DEST.  Adjust the data structures
1218    to reflect that SRC contains an older copy of the shared value.  */
1219
1220 static void
1221 copy_value (rtx dest, rtx src, struct value_data *vd)
1222 {
1223   unsigned int dr = REGNO (dest);
1224   unsigned int sr = REGNO (src);
1225   unsigned int dn, sn;
1226   unsigned int i;
1227
1228   /* ??? At present, it's possible to see noop sets.  It'd be nice if
1229      this were cleaned up beforehand...  */
1230   if (sr == dr)
1231     return;
1232
1233   /* Do not propagate copies to the stack pointer, as that can leave
1234      memory accesses with no scheduling dependency on the stack update.  */
1235   if (dr == STACK_POINTER_REGNUM)
1236     return;
1237
1238   /* Likewise with the frame pointer, if we're using one.  */
1239   if (frame_pointer_needed && dr == HARD_FRAME_POINTER_REGNUM)
1240     return;
1241
1242   /* Do not propagate copies to fixed or global registers, patterns
1243      can be relying to see particular fixed register or users can
1244      expect the chosen global register in asm.  */
1245   if (fixed_regs[dr] || global_regs[dr])
1246     return;
1247
1248   /* If SRC and DEST overlap, don't record anything.  */
1249   dn = hard_regno_nregs[dr][GET_MODE (dest)];
1250   sn = hard_regno_nregs[sr][GET_MODE (dest)];
1251   if ((dr > sr && dr < sr + sn)
1252       || (sr > dr && sr < dr + dn))
1253     return;
1254
1255   /* If SRC had no assigned mode (i.e. we didn't know it was live)
1256      assign it now and assume the value came from an input argument
1257      or somesuch.  */
1258   if (vd->e[sr].mode == VOIDmode)
1259     set_value_regno (sr, vd->e[dr].mode, vd);
1260
1261   /* If we are narrowing the input to a smaller number of hard regs,
1262      and it is in big endian, we are really extracting a high part.
1263      Since we generally associate a low part of a value with the value itself,
1264      we must not do the same for the high part.
1265      Note we can still get low parts for the same mode combination through
1266      a two-step copy involving differently sized hard regs.
1267      Assume hard regs fr* are 32 bits bits each, while r* are 64 bits each:
1268      (set (reg:DI r0) (reg:DI fr0))
1269      (set (reg:SI fr2) (reg:SI r0))
1270      loads the low part of (reg:DI fr0) - i.e. fr1 - into fr2, while:
1271      (set (reg:SI fr2) (reg:SI fr0))
1272      loads the high part of (reg:DI fr0) into fr2.
1273
1274      We can't properly represent the latter case in our tables, so don't
1275      record anything then.  */
1276   else if (sn < (unsigned int) hard_regno_nregs[sr][vd->e[sr].mode]
1277            && (GET_MODE_SIZE (vd->e[sr].mode) > UNITS_PER_WORD
1278                ? WORDS_BIG_ENDIAN : BYTES_BIG_ENDIAN))
1279     return;
1280
1281   /* If SRC had been assigned a mode narrower than the copy, we can't
1282      link DEST into the chain, because not all of the pieces of the
1283      copy came from oldest_regno.  */
1284   else if (sn > (unsigned int) hard_regno_nregs[sr][vd->e[sr].mode])
1285     return;
1286
1287   /* Link DR at the end of the value chain used by SR.  */
1288
1289   vd->e[dr].oldest_regno = vd->e[sr].oldest_regno;
1290
1291   for (i = sr; vd->e[i].next_regno != INVALID_REGNUM; i = vd->e[i].next_regno)
1292     continue;
1293   vd->e[i].next_regno = dr;
1294
1295 #ifdef ENABLE_CHECKING
1296   validate_value_data (vd);
1297 #endif
1298 }
1299
1300 /* Return true if a mode change from ORIG to NEW is allowed for REGNO.  */
1301
1302 static bool
1303 mode_change_ok (enum machine_mode orig_mode, enum machine_mode new_mode,
1304                 unsigned int regno ATTRIBUTE_UNUSED)
1305 {
1306   if (GET_MODE_SIZE (orig_mode) < GET_MODE_SIZE (new_mode))
1307     return false;
1308
1309 #ifdef CANNOT_CHANGE_MODE_CLASS
1310   return !REG_CANNOT_CHANGE_MODE_P (regno, orig_mode, new_mode);
1311 #endif
1312
1313   return true;
1314 }
1315
1316 /* Register REGNO was originally set in ORIG_MODE.  It - or a copy of it -
1317    was copied in COPY_MODE to COPY_REGNO, and then COPY_REGNO was accessed
1318    in NEW_MODE.
1319    Return a NEW_MODE rtx for REGNO if that's OK, otherwise return NULL_RTX.  */
1320
1321 static rtx
1322 maybe_mode_change (enum machine_mode orig_mode, enum machine_mode copy_mode,
1323                    enum machine_mode new_mode, unsigned int regno,
1324                    unsigned int copy_regno ATTRIBUTE_UNUSED)
1325 {
1326   if (GET_MODE_SIZE (copy_mode) < GET_MODE_SIZE (orig_mode)
1327       && GET_MODE_SIZE (copy_mode) < GET_MODE_SIZE (new_mode))
1328     return NULL_RTX;
1329
1330   if (orig_mode == new_mode)
1331     return gen_rtx_raw_REG (new_mode, regno);
1332   else if (mode_change_ok (orig_mode, new_mode, regno))
1333     {
1334       int copy_nregs = hard_regno_nregs[copy_regno][copy_mode];
1335       int use_nregs = hard_regno_nregs[copy_regno][new_mode];
1336       int copy_offset
1337         = GET_MODE_SIZE (copy_mode) / copy_nregs * (copy_nregs - use_nregs);
1338       int offset
1339         = GET_MODE_SIZE (orig_mode) - GET_MODE_SIZE (new_mode) - copy_offset;
1340       int byteoffset = offset % UNITS_PER_WORD;
1341       int wordoffset = offset - byteoffset;
1342
1343       offset = ((WORDS_BIG_ENDIAN ? wordoffset : 0)
1344                 + (BYTES_BIG_ENDIAN ? byteoffset : 0));
1345       return gen_rtx_raw_REG (new_mode,
1346                               regno + subreg_regno_offset (regno, orig_mode,
1347                                                            offset,
1348                                                            new_mode));
1349     }
1350   return NULL_RTX;
1351 }
1352
1353 /* Find the oldest copy of the value contained in REGNO that is in
1354    register class CL and has mode MODE.  If found, return an rtx
1355    of that oldest register, otherwise return NULL.  */
1356
1357 static rtx
1358 find_oldest_value_reg (enum reg_class cl, rtx reg, struct value_data *vd)
1359 {
1360   unsigned int regno = REGNO (reg);
1361   enum machine_mode mode = GET_MODE (reg);
1362   unsigned int i;
1363
1364   /* If we are accessing REG in some mode other that what we set it in,
1365      make sure that the replacement is valid.  In particular, consider
1366         (set (reg:DI r11) (...))
1367         (set (reg:SI r9) (reg:SI r11))
1368         (set (reg:SI r10) (...))
1369         (set (...) (reg:DI r9))
1370      Replacing r9 with r11 is invalid.  */
1371   if (mode != vd->e[regno].mode)
1372     {
1373       if (hard_regno_nregs[regno][mode]
1374           > hard_regno_nregs[regno][vd->e[regno].mode])
1375         return NULL_RTX;
1376     }
1377
1378   for (i = vd->e[regno].oldest_regno; i != regno; i = vd->e[i].next_regno)
1379     {
1380       enum machine_mode oldmode = vd->e[i].mode;
1381       rtx new_rtx;
1382
1383       if (!in_hard_reg_set_p (reg_class_contents[cl], mode, i))
1384         return NULL_RTX;
1385
1386       new_rtx = maybe_mode_change (oldmode, vd->e[regno].mode, mode, i, regno);
1387       if (new_rtx)
1388         {
1389           ORIGINAL_REGNO (new_rtx) = ORIGINAL_REGNO (reg);
1390           REG_ATTRS (new_rtx) = REG_ATTRS (reg);
1391           REG_POINTER (new_rtx) = REG_POINTER (reg);
1392           return new_rtx;
1393         }
1394     }
1395
1396   return NULL_RTX;
1397 }
1398
1399 /* If possible, replace the register at *LOC with the oldest register
1400    in register class CL.  Return true if successfully replaced.  */
1401
1402 static bool
1403 replace_oldest_value_reg (rtx *loc, enum reg_class cl, rtx insn,
1404                           struct value_data *vd)
1405 {
1406   rtx new_rtx = find_oldest_value_reg (cl, *loc, vd);
1407   if (new_rtx)
1408     {
1409       if (dump_file)
1410         fprintf (dump_file, "insn %u: replaced reg %u with %u\n",
1411                  INSN_UID (insn), REGNO (*loc), REGNO (new_rtx));
1412
1413       validate_change (insn, loc, new_rtx, 1);
1414       return true;
1415     }
1416   return false;
1417 }
1418
1419 /* Similar to replace_oldest_value_reg, but *LOC contains an address.
1420    Adapted from find_reloads_address_1.  CL is INDEX_REG_CLASS or
1421    BASE_REG_CLASS depending on how the register is being considered.  */
1422
1423 static bool
1424 replace_oldest_value_addr (rtx *loc, enum reg_class cl,
1425                            enum machine_mode mode, rtx insn,
1426                            struct value_data *vd)
1427 {
1428   rtx x = *loc;
1429   RTX_CODE code = GET_CODE (x);
1430   const char *fmt;
1431   int i, j;
1432   bool changed = false;
1433
1434   switch (code)
1435     {
1436     case PLUS:
1437       {
1438         rtx orig_op0 = XEXP (x, 0);
1439         rtx orig_op1 = XEXP (x, 1);
1440         RTX_CODE code0 = GET_CODE (orig_op0);
1441         RTX_CODE code1 = GET_CODE (orig_op1);
1442         rtx op0 = orig_op0;
1443         rtx op1 = orig_op1;
1444         rtx *locI = NULL;
1445         rtx *locB = NULL;
1446         enum rtx_code index_code = SCRATCH;
1447
1448         if (GET_CODE (op0) == SUBREG)
1449           {
1450             op0 = SUBREG_REG (op0);
1451             code0 = GET_CODE (op0);
1452           }
1453
1454         if (GET_CODE (op1) == SUBREG)
1455           {
1456             op1 = SUBREG_REG (op1);
1457             code1 = GET_CODE (op1);
1458           }
1459
1460         if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
1461             || code0 == ZERO_EXTEND || code1 == MEM)
1462           {
1463             locI = &XEXP (x, 0);
1464             locB = &XEXP (x, 1);
1465             index_code = GET_CODE (*locI);
1466           }
1467         else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
1468                  || code1 == ZERO_EXTEND || code0 == MEM)
1469           {
1470             locI = &XEXP (x, 1);
1471             locB = &XEXP (x, 0);
1472             index_code = GET_CODE (*locI);
1473           }
1474         else if (code0 == CONST_INT || code0 == CONST
1475                  || code0 == SYMBOL_REF || code0 == LABEL_REF)
1476           {
1477             locB = &XEXP (x, 1);
1478             index_code = GET_CODE (XEXP (x, 0));
1479           }
1480         else if (code1 == CONST_INT || code1 == CONST
1481                  || code1 == SYMBOL_REF || code1 == LABEL_REF)
1482           {
1483             locB = &XEXP (x, 0);
1484             index_code = GET_CODE (XEXP (x, 1));
1485           }
1486         else if (code0 == REG && code1 == REG)
1487           {
1488             int index_op;
1489             unsigned regno0 = REGNO (op0), regno1 = REGNO (op1);
1490
1491             if (REGNO_OK_FOR_INDEX_P (regno1)
1492                 && regno_ok_for_base_p (regno0, mode, PLUS, REG))
1493               index_op = 1;
1494             else if (REGNO_OK_FOR_INDEX_P (regno0)
1495                      && regno_ok_for_base_p (regno1, mode, PLUS, REG))
1496               index_op = 0;
1497             else if (regno_ok_for_base_p (regno0, mode, PLUS, REG)
1498                      || REGNO_OK_FOR_INDEX_P (regno1))
1499               index_op = 1;
1500             else if (regno_ok_for_base_p (regno1, mode, PLUS, REG))
1501               index_op = 0;
1502             else
1503               index_op = 1;
1504
1505             locI = &XEXP (x, index_op);
1506             locB = &XEXP (x, !index_op);
1507             index_code = GET_CODE (*locI);
1508           }
1509         else if (code0 == REG)
1510           {
1511             locI = &XEXP (x, 0);
1512             locB = &XEXP (x, 1);
1513             index_code = GET_CODE (*locI);
1514           }
1515         else if (code1 == REG)
1516           {
1517             locI = &XEXP (x, 1);
1518             locB = &XEXP (x, 0);
1519             index_code = GET_CODE (*locI);
1520           }
1521
1522         if (locI)
1523           changed |= replace_oldest_value_addr (locI, INDEX_REG_CLASS, mode,
1524                                                 insn, vd);
1525         if (locB)
1526           changed |= replace_oldest_value_addr (locB,
1527                                                 base_reg_class (mode, PLUS,
1528                                                                 index_code),
1529                                                 mode, insn, vd);
1530         return changed;
1531       }
1532
1533     case POST_INC:
1534     case POST_DEC:
1535     case POST_MODIFY:
1536     case PRE_INC:
1537     case PRE_DEC:
1538     case PRE_MODIFY:
1539       return false;
1540
1541     case MEM:
1542       return replace_oldest_value_mem (x, insn, vd);
1543
1544     case REG:
1545       return replace_oldest_value_reg (loc, cl, insn, vd);
1546
1547     default:
1548       break;
1549     }
1550
1551   fmt = GET_RTX_FORMAT (code);
1552   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1553     {
1554       if (fmt[i] == 'e')
1555         changed |= replace_oldest_value_addr (&XEXP (x, i), cl, mode,
1556                                               insn, vd);
1557       else if (fmt[i] == 'E')
1558         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1559           changed |= replace_oldest_value_addr (&XVECEXP (x, i, j), cl,
1560                                                 mode, insn, vd);
1561     }
1562
1563   return changed;
1564 }
1565
1566 /* Similar to replace_oldest_value_reg, but X contains a memory.  */
1567
1568 static bool
1569 replace_oldest_value_mem (rtx x, rtx insn, struct value_data *vd)
1570 {
1571   return replace_oldest_value_addr (&XEXP (x, 0),
1572                                     base_reg_class (GET_MODE (x), MEM,
1573                                                     SCRATCH),
1574                                     GET_MODE (x), insn, vd);
1575 }
1576
1577 /* Perform the forward copy propagation on basic block BB.  */
1578
1579 static bool
1580 copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
1581 {
1582   bool changed = false;
1583   rtx insn;
1584
1585   for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn))
1586     {
1587       int n_ops, i, alt, predicated;
1588       bool is_asm, any_replacements;
1589       rtx set;
1590       bool replaced[MAX_RECOG_OPERANDS];
1591
1592       if (! INSN_P (insn))
1593         {
1594           if (insn == BB_END (bb))
1595             break;
1596           else
1597             continue;
1598         }
1599
1600       set = single_set (insn);
1601       extract_insn (insn);
1602       if (! constrain_operands (1))
1603         fatal_insn_not_found (insn);
1604       preprocess_constraints ();
1605       alt = which_alternative;
1606       n_ops = recog_data.n_operands;
1607       is_asm = asm_noperands (PATTERN (insn)) >= 0;
1608
1609       /* Simplify the code below by rewriting things to reflect
1610          matching constraints.  Also promote OP_OUT to OP_INOUT
1611          in predicated instructions.  */
1612
1613       predicated = GET_CODE (PATTERN (insn)) == COND_EXEC;
1614       for (i = 0; i < n_ops; ++i)
1615         {
1616           int matches = recog_op_alt[i][alt].matches;
1617           if (matches >= 0)
1618             recog_op_alt[i][alt].cl = recog_op_alt[matches][alt].cl;
1619           if (matches >= 0 || recog_op_alt[i][alt].matched >= 0
1620               || (predicated && recog_data.operand_type[i] == OP_OUT))
1621             recog_data.operand_type[i] = OP_INOUT;
1622         }
1623
1624       /* For each earlyclobber operand, zap the value data.  */
1625       for (i = 0; i < n_ops; i++)
1626         if (recog_op_alt[i][alt].earlyclobber)
1627           kill_value (recog_data.operand[i], vd);
1628
1629       /* Within asms, a clobber cannot overlap inputs or outputs.
1630          I wouldn't think this were true for regular insns, but
1631          scan_rtx treats them like that...  */
1632       note_stores (PATTERN (insn), kill_clobbered_value, vd);
1633
1634       /* Kill all auto-incremented values.  */
1635       /* ??? REG_INC is useless, since stack pushes aren't done that way.  */
1636       for_each_rtx (&PATTERN (insn), kill_autoinc_value, vd);
1637
1638       /* Kill all early-clobbered operands.  */
1639       for (i = 0; i < n_ops; i++)
1640         if (recog_op_alt[i][alt].earlyclobber)
1641           kill_value (recog_data.operand[i], vd);
1642
1643       /* Special-case plain move instructions, since we may well
1644          be able to do the move from a different register class.  */
1645       if (set && REG_P (SET_SRC (set)))
1646         {
1647           rtx src = SET_SRC (set);
1648           unsigned int regno = REGNO (src);
1649           enum machine_mode mode = GET_MODE (src);
1650           unsigned int i;
1651           rtx new_rtx;
1652
1653           /* If we are accessing SRC in some mode other that what we
1654              set it in, make sure that the replacement is valid.  */
1655           if (mode != vd->e[regno].mode)
1656             {
1657               if (hard_regno_nregs[regno][mode]
1658                   > hard_regno_nregs[regno][vd->e[regno].mode])
1659                 goto no_move_special_case;
1660             }
1661
1662           /* If the destination is also a register, try to find a source
1663              register in the same class.  */
1664           if (REG_P (SET_DEST (set)))
1665             {
1666               new_rtx = find_oldest_value_reg (REGNO_REG_CLASS (regno), src, vd);
1667               if (new_rtx && validate_change (insn, &SET_SRC (set), new_rtx, 0))
1668                 {
1669                   if (dump_file)
1670                     fprintf (dump_file,
1671                              "insn %u: replaced reg %u with %u\n",
1672                              INSN_UID (insn), regno, REGNO (new_rtx));
1673                   changed = true;
1674                   goto did_replacement;
1675                 }
1676             }
1677
1678           /* Otherwise, try all valid registers and see if its valid.  */
1679           for (i = vd->e[regno].oldest_regno; i != regno;
1680                i = vd->e[i].next_regno)
1681             {
1682               new_rtx = maybe_mode_change (vd->e[i].mode, vd->e[regno].mode,
1683                                        mode, i, regno);
1684               if (new_rtx != NULL_RTX)
1685                 {
1686                   if (validate_change (insn, &SET_SRC (set), new_rtx, 0))
1687                     {
1688                       ORIGINAL_REGNO (new_rtx) = ORIGINAL_REGNO (src);
1689                       REG_ATTRS (new_rtx) = REG_ATTRS (src);
1690                       REG_POINTER (new_rtx) = REG_POINTER (src);
1691                       if (dump_file)
1692                         fprintf (dump_file,
1693                                  "insn %u: replaced reg %u with %u\n",
1694                                  INSN_UID (insn), regno, REGNO (new_rtx));
1695                       changed = true;
1696                       goto did_replacement;
1697                     }
1698                 }
1699             }
1700         }
1701       no_move_special_case:
1702
1703       any_replacements = false;
1704
1705       /* For each input operand, replace a hard register with the
1706          eldest live copy that's in an appropriate register class.  */
1707       for (i = 0; i < n_ops; i++)
1708         {
1709           replaced[i] = false;
1710
1711           /* Don't scan match_operand here, since we've no reg class
1712              information to pass down.  Any operands that we could
1713              substitute in will be represented elsewhere.  */
1714           if (recog_data.constraints[i][0] == '\0')
1715             continue;
1716
1717           /* Don't replace in asms intentionally referencing hard regs.  */
1718           if (is_asm && REG_P (recog_data.operand[i])
1719               && (REGNO (recog_data.operand[i])
1720                   == ORIGINAL_REGNO (recog_data.operand[i])))
1721             continue;
1722
1723           if (recog_data.operand_type[i] == OP_IN)
1724             {
1725               if (recog_op_alt[i][alt].is_address)
1726                 replaced[i]
1727                   = replace_oldest_value_addr (recog_data.operand_loc[i],
1728                                                recog_op_alt[i][alt].cl,
1729                                                VOIDmode, insn, vd);
1730               else if (REG_P (recog_data.operand[i]))
1731                 replaced[i]
1732                   = replace_oldest_value_reg (recog_data.operand_loc[i],
1733                                               recog_op_alt[i][alt].cl,
1734                                               insn, vd);
1735               else if (MEM_P (recog_data.operand[i]))
1736                 replaced[i] = replace_oldest_value_mem (recog_data.operand[i],
1737                                                         insn, vd);
1738             }
1739           else if (MEM_P (recog_data.operand[i]))
1740             replaced[i] = replace_oldest_value_mem (recog_data.operand[i],
1741                                                     insn, vd);
1742
1743           /* If we performed any replacement, update match_dups.  */
1744           if (replaced[i])
1745             {
1746               int j;
1747               rtx new_rtx;
1748
1749               new_rtx = *recog_data.operand_loc[i];
1750               recog_data.operand[i] = new_rtx;
1751               for (j = 0; j < recog_data.n_dups; j++)
1752                 if (recog_data.dup_num[j] == i)
1753                   validate_unshare_change (insn, recog_data.dup_loc[j], new_rtx, 1);
1754
1755               any_replacements = true;
1756             }
1757         }
1758
1759       if (any_replacements)
1760         {
1761           if (! apply_change_group ())
1762             {
1763               for (i = 0; i < n_ops; i++)
1764                 if (replaced[i])
1765                   {
1766                     rtx old = *recog_data.operand_loc[i];
1767                     recog_data.operand[i] = old;
1768                   }
1769
1770               if (dump_file)
1771                 fprintf (dump_file,
1772                          "insn %u: reg replacements not verified\n",
1773                          INSN_UID (insn));
1774             }
1775           else
1776             changed = true;
1777         }
1778
1779     did_replacement:
1780       /* Clobber call-clobbered registers.  */
1781       if (CALL_P (insn))
1782         for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1783           if (TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
1784             kill_value_regno (i, 1, vd);
1785
1786       /* Notice stores.  */
1787       note_stores (PATTERN (insn), kill_set_value, vd);
1788
1789       /* Notice copies.  */
1790       if (set && REG_P (SET_DEST (set)) && REG_P (SET_SRC (set)))
1791         copy_value (SET_DEST (set), SET_SRC (set), vd);
1792
1793       if (insn == BB_END (bb))
1794         break;
1795     }
1796
1797   return changed;
1798 }
1799
1800 /* Main entry point for the forward copy propagation optimization.  */
1801
1802 static void
1803 copyprop_hardreg_forward (void)
1804 {
1805   struct value_data *all_vd;
1806   basic_block bb;
1807   sbitmap visited;
1808
1809   all_vd = XNEWVEC (struct value_data, last_basic_block);
1810
1811   visited = sbitmap_alloc (last_basic_block);
1812   sbitmap_zero (visited);
1813
1814   FOR_EACH_BB (bb)
1815     {
1816       SET_BIT (visited, bb->index);
1817
1818       /* If a block has a single predecessor, that we've already
1819          processed, begin with the value data that was live at
1820          the end of the predecessor block.  */
1821       /* ??? Ought to use more intelligent queuing of blocks.  */
1822       if (single_pred_p (bb) 
1823           && TEST_BIT (visited, single_pred (bb)->index)
1824           && ! (single_pred_edge (bb)->flags & (EDGE_ABNORMAL_CALL | EDGE_EH)))
1825         all_vd[bb->index] = all_vd[single_pred (bb)->index];
1826       else
1827         init_value_data (all_vd + bb->index);
1828
1829       copyprop_hardreg_forward_1 (bb, all_vd + bb->index);
1830     }
1831
1832   sbitmap_free (visited);  
1833   free (all_vd);
1834 }
1835
1836 /* Dump the value chain data to stderr.  */
1837
1838 void
1839 debug_value_data (struct value_data *vd)
1840 {
1841   HARD_REG_SET set;
1842   unsigned int i, j;
1843
1844   CLEAR_HARD_REG_SET (set);
1845
1846   for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1847     if (vd->e[i].oldest_regno == i)
1848       {
1849         if (vd->e[i].mode == VOIDmode)
1850           {
1851             if (vd->e[i].next_regno != INVALID_REGNUM)
1852               fprintf (stderr, "[%u] Bad next_regno for empty chain (%u)\n",
1853                        i, vd->e[i].next_regno);
1854             continue;
1855           }
1856
1857         SET_HARD_REG_BIT (set, i);
1858         fprintf (stderr, "[%u %s] ", i, GET_MODE_NAME (vd->e[i].mode));
1859
1860         for (j = vd->e[i].next_regno;
1861              j != INVALID_REGNUM;
1862              j = vd->e[j].next_regno)
1863           {
1864             if (TEST_HARD_REG_BIT (set, j))
1865               {
1866                 fprintf (stderr, "[%u] Loop in regno chain\n", j);
1867                 return;
1868               }
1869
1870             if (vd->e[j].oldest_regno != i)
1871               {
1872                 fprintf (stderr, "[%u] Bad oldest_regno (%u)\n",
1873                          j, vd->e[j].oldest_regno);
1874                 return;
1875               }
1876             SET_HARD_REG_BIT (set, j);
1877             fprintf (stderr, "[%u %s] ", j, GET_MODE_NAME (vd->e[j].mode));
1878           }
1879         fputc ('\n', stderr);
1880       }
1881
1882   for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1883     if (! TEST_HARD_REG_BIT (set, i)
1884         && (vd->e[i].mode != VOIDmode
1885             || vd->e[i].oldest_regno != i
1886             || vd->e[i].next_regno != INVALID_REGNUM))
1887       fprintf (stderr, "[%u] Non-empty reg in chain (%s %u %i)\n",
1888                i, GET_MODE_NAME (vd->e[i].mode), vd->e[i].oldest_regno,
1889                vd->e[i].next_regno);
1890 }
1891
1892 #ifdef ENABLE_CHECKING
1893 static void
1894 validate_value_data (struct value_data *vd)
1895 {
1896   HARD_REG_SET set;
1897   unsigned int i, j;
1898
1899   CLEAR_HARD_REG_SET (set);
1900
1901   for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1902     if (vd->e[i].oldest_regno == i)
1903       {
1904         if (vd->e[i].mode == VOIDmode)
1905           {
1906             if (vd->e[i].next_regno != INVALID_REGNUM)
1907               internal_error ("validate_value_data: [%u] Bad next_regno for empty chain (%u)",
1908                               i, vd->e[i].next_regno);
1909             continue;
1910           }
1911
1912         SET_HARD_REG_BIT (set, i);
1913
1914         for (j = vd->e[i].next_regno;
1915              j != INVALID_REGNUM;
1916              j = vd->e[j].next_regno)
1917           {
1918             if (TEST_HARD_REG_BIT (set, j))
1919               internal_error ("validate_value_data: Loop in regno chain (%u)",
1920                               j);
1921             if (vd->e[j].oldest_regno != i)
1922               internal_error ("validate_value_data: [%u] Bad oldest_regno (%u)",
1923                               j, vd->e[j].oldest_regno);
1924
1925             SET_HARD_REG_BIT (set, j);
1926           }
1927       }
1928
1929   for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
1930     if (! TEST_HARD_REG_BIT (set, i)
1931         && (vd->e[i].mode != VOIDmode
1932             || vd->e[i].oldest_regno != i
1933             || vd->e[i].next_regno != INVALID_REGNUM))
1934       internal_error ("validate_value_data: [%u] Non-empty reg in chain (%s %u %i)",
1935                       i, GET_MODE_NAME (vd->e[i].mode), vd->e[i].oldest_regno,
1936                       vd->e[i].next_regno);
1937 }
1938 #endif
1939 \f
1940 static bool
1941 gate_handle_regrename (void)
1942 {
1943   return (optimize > 0 && (flag_rename_registers));
1944 }
1945
1946
1947 /* Run the regrename and cprop passes.  */
1948 static unsigned int
1949 rest_of_handle_regrename (void)
1950 {
1951   regrename_optimize ();
1952   return 0;
1953 }
1954
1955 struct rtl_opt_pass pass_regrename =
1956 {
1957  {
1958   RTL_PASS,
1959   "rnreg",                              /* name */
1960   gate_handle_regrename,                /* gate */
1961   rest_of_handle_regrename,             /* execute */
1962   NULL,                                 /* sub */
1963   NULL,                                 /* next */
1964   0,                                    /* static_pass_number */
1965   TV_RENAME_REGISTERS,                  /* tv_id */
1966   0,                                    /* properties_required */
1967   0,                                    /* properties_provided */
1968   0,                                    /* properties_destroyed */
1969   0,                                    /* todo_flags_start */
1970   TODO_df_finish | TODO_verify_rtl_sharing |
1971   TODO_dump_func                        /* todo_flags_finish */
1972  }
1973 };
1974
1975 static bool
1976 gate_handle_cprop (void)
1977 {
1978   return (optimize > 0 && (flag_cprop_registers));
1979 }
1980
1981
1982 /* Run the regrename and cprop passes.  */
1983 static unsigned int
1984 rest_of_handle_cprop (void)
1985 {
1986   copyprop_hardreg_forward ();
1987   return 0;
1988 }
1989
1990 struct rtl_opt_pass pass_cprop_hardreg =
1991 {
1992  {
1993   RTL_PASS,
1994   "cprop_hardreg",                      /* name */
1995   gate_handle_cprop,                    /* gate */
1996   rest_of_handle_cprop,                 /* execute */
1997   NULL,                                 /* sub */
1998   NULL,                                 /* next */
1999   0,                                    /* static_pass_number */
2000   TV_RENAME_REGISTERS,                  /* tv_id */
2001   0,                                    /* properties_required */
2002   0,                                    /* properties_provided */
2003   0,                                    /* properties_destroyed */
2004   0,                                    /* todo_flags_start */
2005   TODO_dump_func | TODO_verify_rtl_sharing /* todo_flags_finish */
2006  }
2007 };