OSDN Git Service

* except.h (can_throw): Declare it.
[pf3gnuchains/gcc-fork.git] / gcc / resource.c
1 /* Definitions for computing resource usage of specific insns.
2    Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "toplev.h"
24 #include "rtl.h"
25 #include "tm_p.h"
26 #include "hard-reg-set.h"
27 #include "basic-block.h"
28 #include "function.h"
29 #include "regs.h"
30 #include "flags.h"
31 #include "output.h"
32 #include "resource.h"
33 #include "insn-attr.h"
34
35 /* This structure is used to record liveness information at the targets or
36    fallthrough insns of branches.  We will most likely need the information
37    at targets again, so save them in a hash table rather than recomputing them
38    each time.  */
39
40 struct target_info
41 {
42   int uid;                      /* INSN_UID of target.  */
43   struct target_info *next;     /* Next info for same hash bucket.  */
44   HARD_REG_SET live_regs;       /* Registers live at target.  */
45   int block;                    /* Basic block number containing target.  */
46   int bb_tick;                  /* Generation count of basic block info.  */
47 };
48
49 #define TARGET_HASH_PRIME 257
50
51 /* Indicates what resources are required at the beginning of the epilogue.  */
52 static struct resources start_of_epilogue_needs;
53
54 /* Indicates what resources are required at function end.  */
55 static struct resources end_of_function_needs;
56
57 /* Define the hash table itself.  */
58 static struct target_info **target_hash_table = NULL;
59
60 /* For each basic block, we maintain a generation number of its basic
61    block info, which is updated each time we move an insn from the
62    target of a jump.  This is the generation number indexed by block
63    number.  */
64
65 static int *bb_ticks;
66
67 /* Marks registers possibly live at the current place being scanned by
68    mark_target_live_regs.  Used only by next two function.    */
69
70 static HARD_REG_SET current_live_regs;
71
72 /* Marks registers for which we have seen a REG_DEAD note but no assignment.
73    Also only used by the next two functions.  */
74
75 static HARD_REG_SET pending_dead_regs;
76 \f
77 static void update_live_status          PARAMS ((rtx, rtx, void *));
78 static int find_basic_block             PARAMS ((rtx));
79 static rtx next_insn_no_annul           PARAMS ((rtx));
80 static rtx find_dead_or_set_registers   PARAMS ((rtx, struct resources*,
81                                                 rtx*, int, struct resources,
82                                                 struct resources));
83 \f
84 /* Utility function called from mark_target_live_regs via note_stores.
85    It deadens any CLOBBERed registers and livens any SET registers.  */
86
87 static void
88 update_live_status (dest, x, data)
89      rtx dest;
90      rtx x;
91      void *data ATTRIBUTE_UNUSED;
92 {
93   int first_regno, last_regno;
94   int i;
95
96   if (GET_CODE (dest) != REG
97       && (GET_CODE (dest) != SUBREG || GET_CODE (SUBREG_REG (dest)) != REG))
98     return;
99
100   if (GET_CODE (dest) == SUBREG)
101     first_regno = REGNO (SUBREG_REG (dest)) + SUBREG_WORD (dest);
102   else
103     first_regno = REGNO (dest);
104
105   last_regno = first_regno + HARD_REGNO_NREGS (first_regno, GET_MODE (dest));
106
107   if (GET_CODE (x) == CLOBBER)
108     for (i = first_regno; i < last_regno; i++)
109       CLEAR_HARD_REG_BIT (current_live_regs, i);
110   else
111     for (i = first_regno; i < last_regno; i++)
112       {
113         SET_HARD_REG_BIT (current_live_regs, i);
114         CLEAR_HARD_REG_BIT (pending_dead_regs, i);
115       }
116 }
117 /* Find the number of the basic block that starts closest to INSN.  Return -1
118    if we couldn't find such a basic block.  */
119
120 static int
121 find_basic_block (insn)
122      rtx insn;
123 {
124   int i;
125
126   /* Scan backwards to the previous BARRIER.  Then see if we can find a
127      label that starts a basic block.  Return the basic block number.  */
128
129   for (insn = prev_nonnote_insn (insn);
130        insn && GET_CODE (insn) != BARRIER;
131        insn = prev_nonnote_insn (insn))
132     ;
133
134   /* The start of the function is basic block zero.  */
135   if (insn == 0)
136     return 0;
137
138   /* See if any of the upcoming CODE_LABELs start a basic block.  If we reach
139      anything other than a CODE_LABEL or note, we can't find this code.  */
140   for (insn = next_nonnote_insn (insn);
141        insn && GET_CODE (insn) == CODE_LABEL;
142        insn = next_nonnote_insn (insn))
143     {
144       for (i = 0; i < n_basic_blocks; i++)
145         if (insn == BLOCK_HEAD (i))
146           return i;
147     }
148
149   return -1;
150 }
151 \f
152 /* Similar to next_insn, but ignores insns in the delay slots of
153    an annulled branch.  */
154
155 static rtx
156 next_insn_no_annul (insn)
157      rtx insn;
158 {
159   if (insn)
160     {
161       /* If INSN is an annulled branch, skip any insns from the target
162          of the branch.  */
163       if (INSN_ANNULLED_BRANCH_P (insn)
164           && NEXT_INSN (PREV_INSN (insn)) != insn)
165         while (INSN_FROM_TARGET_P (NEXT_INSN (insn)))
166           insn = NEXT_INSN (insn);
167
168       insn = NEXT_INSN (insn);
169       if (insn && GET_CODE (insn) == INSN
170           && GET_CODE (PATTERN (insn)) == SEQUENCE)
171         insn = XVECEXP (PATTERN (insn), 0, 0);
172     }
173
174   return insn;
175 }
176 \f
177 /* Given X, some rtl, and RES, a pointer to a `struct resource', mark
178    which resources are references by the insn.  If INCLUDE_DELAYED_EFFECTS
179    is TRUE, resources used by the called routine will be included for
180    CALL_INSNs.  */
181
182 void
183 mark_referenced_resources (x, res, include_delayed_effects)
184      register rtx x;
185      register struct resources *res;
186      register int include_delayed_effects;
187 {
188   enum rtx_code code = GET_CODE (x);
189   int i, j;
190   unsigned int r;
191   register const char *format_ptr;
192
193   /* Handle leaf items for which we set resource flags.  Also, special-case
194      CALL, SET and CLOBBER operators.  */
195   switch (code)
196     {
197     case CONST:
198     case CONST_INT:
199     case CONST_DOUBLE:
200     case PC:
201     case SYMBOL_REF:
202     case LABEL_REF:
203       return;
204
205     case SUBREG:
206       if (GET_CODE (SUBREG_REG (x)) != REG)
207         mark_referenced_resources (SUBREG_REG (x), res, 0);
208       else
209         {
210           unsigned int regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
211           unsigned int last_regno
212             = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
213
214           for (r = regno; r < last_regno; r++)
215             SET_HARD_REG_BIT (res->regs, r);
216         }
217       return;
218
219     case REG:
220       for (r = 0; r < HARD_REGNO_NREGS (REGNO (x), GET_MODE (x)); r++)
221         SET_HARD_REG_BIT (res->regs, REGNO (x) + r);
222       return;
223
224     case MEM:
225       /* If this memory shouldn't change, it really isn't referencing
226          memory.  */
227       if (RTX_UNCHANGING_P (x))
228         res->unch_memory = 1;
229       else
230         res->memory = 1;
231       res->volatil |= MEM_VOLATILE_P (x);
232
233       /* Mark registers used to access memory.  */
234       mark_referenced_resources (XEXP (x, 0), res, 0);
235       return;
236
237     case CC0:
238       res->cc = 1;
239       return;
240
241     case UNSPEC_VOLATILE:
242     case ASM_INPUT:
243       /* Traditional asm's are always volatile.  */
244       res->volatil = 1;
245       return;
246
247     case TRAP_IF:
248       res->volatil = 1;
249       break;
250
251     case ASM_OPERANDS:
252       res->volatil |= MEM_VOLATILE_P (x);
253
254       /* For all ASM_OPERANDS, we must traverse the vector of input operands.
255          We can not just fall through here since then we would be confused
256          by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
257          traditional asms unlike their normal usage.  */
258       
259       for (i = 0; i < ASM_OPERANDS_INPUT_LENGTH (x); i++)
260         mark_referenced_resources (ASM_OPERANDS_INPUT (x, i), res, 0);
261       return;
262
263     case CALL:
264       /* The first operand will be a (MEM (xxx)) but doesn't really reference
265          memory.  The second operand may be referenced, though.  */
266       mark_referenced_resources (XEXP (XEXP (x, 0), 0), res, 0);
267       mark_referenced_resources (XEXP (x, 1), res, 0);
268       return;
269
270     case SET:
271       /* Usually, the first operand of SET is set, not referenced.  But
272          registers used to access memory are referenced.  SET_DEST is
273          also referenced if it is a ZERO_EXTRACT or SIGN_EXTRACT.  */
274
275       mark_referenced_resources (SET_SRC (x), res, 0);
276
277       x = SET_DEST (x);
278       if (GET_CODE (x) == SIGN_EXTRACT
279           || GET_CODE (x) == ZERO_EXTRACT
280           || GET_CODE (x) == STRICT_LOW_PART)
281         mark_referenced_resources (x, res, 0);
282       else if (GET_CODE (x) == SUBREG)
283         x = SUBREG_REG (x);
284       if (GET_CODE (x) == MEM)
285         mark_referenced_resources (XEXP (x, 0), res, 0);
286       return;
287
288     case CLOBBER:
289       return;
290
291     case CALL_INSN:
292       if (include_delayed_effects)
293         {
294           /* A CALL references memory, the frame pointer if it exists, the
295              stack pointer, any global registers and any registers given in
296              USE insns immediately in front of the CALL.
297
298              However, we may have moved some of the parameter loading insns
299              into the delay slot of this CALL.  If so, the USE's for them
300              don't count and should be skipped.  */
301           rtx insn = PREV_INSN (x);
302           rtx sequence = 0;
303           int seq_size = 0;
304           rtx next = NEXT_INSN (x);
305           int i;
306
307           /* If we are part of a delay slot sequence, point at the SEQUENCE.  */
308           if (NEXT_INSN (insn) != x)
309             {
310               next = NEXT_INSN (NEXT_INSN (insn));
311               sequence = PATTERN (NEXT_INSN (insn));
312               seq_size = XVECLEN (sequence, 0);
313               if (GET_CODE (sequence) != SEQUENCE)
314                 abort ();
315             }
316
317           res->memory = 1;
318           SET_HARD_REG_BIT (res->regs, STACK_POINTER_REGNUM);
319           if (frame_pointer_needed)
320             {
321               SET_HARD_REG_BIT (res->regs, FRAME_POINTER_REGNUM);
322 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
323               SET_HARD_REG_BIT (res->regs, HARD_FRAME_POINTER_REGNUM);
324 #endif
325             }
326
327           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
328             if (global_regs[i])
329               SET_HARD_REG_BIT (res->regs, i);
330
331           /* Check for a NOTE_INSN_SETJMP.  If it exists, then we must
332              assume that this call can need any register.
333
334              This is done to be more conservative about how we handle setjmp.
335              We assume that they both use and set all registers.  Using all
336              registers ensures that a register will not be considered dead
337              just because it crosses a setjmp call.  A register should be
338              considered dead only if the setjmp call returns non-zero.  */
339           if (next && GET_CODE (next) == NOTE
340               && NOTE_LINE_NUMBER (next) == NOTE_INSN_SETJMP)
341             SET_HARD_REG_SET (res->regs);
342
343           {
344             rtx link;
345
346             for (link = CALL_INSN_FUNCTION_USAGE (x);
347                  link;
348                  link = XEXP (link, 1))
349               if (GET_CODE (XEXP (link, 0)) == USE)
350                 {
351                   for (i = 1; i < seq_size; i++)
352                     {
353                       rtx slot_pat = PATTERN (XVECEXP (sequence, 0, i));
354                       if (GET_CODE (slot_pat) == SET
355                           && rtx_equal_p (SET_DEST (slot_pat),
356                                           XEXP (XEXP (link, 0), 0)))
357                         break;
358                     }
359                   if (i >= seq_size)
360                     mark_referenced_resources (XEXP (XEXP (link, 0), 0),
361                                                res, 0);
362                 }
363           }
364         }
365
366       /* ... fall through to other INSN processing ...  */
367
368     case INSN:
369     case JUMP_INSN:
370
371 #ifdef INSN_REFERENCES_ARE_DELAYED
372       if (! include_delayed_effects
373           && INSN_REFERENCES_ARE_DELAYED (x))
374         return;
375 #endif
376
377       /* No special processing, just speed up.  */
378       mark_referenced_resources (PATTERN (x), res, include_delayed_effects);
379       return;
380
381     default:
382       break;
383     }
384
385   /* Process each sub-expression and flag what it needs.  */
386   format_ptr = GET_RTX_FORMAT (code);
387   for (i = 0; i < GET_RTX_LENGTH (code); i++)
388     switch (*format_ptr++)
389       {
390       case 'e':
391         mark_referenced_resources (XEXP (x, i), res, include_delayed_effects);
392         break;
393
394       case 'E':
395         for (j = 0; j < XVECLEN (x, i); j++)
396           mark_referenced_resources (XVECEXP (x, i, j), res,
397                                      include_delayed_effects);
398         break;
399       }
400 }
401 \f
402 /* A subroutine of mark_target_live_regs.  Search forward from TARGET
403    looking for registers that are set before they are used.  These are dead. 
404    Stop after passing a few conditional jumps, and/or a small
405    number of unconditional branches.  */
406
407 static rtx
408 find_dead_or_set_registers (target, res, jump_target, jump_count, set, needed)
409      rtx target;
410      struct resources *res;
411      rtx *jump_target;
412      int jump_count;
413      struct resources set, needed;
414 {
415   HARD_REG_SET scratch;
416   rtx insn, next;
417   rtx jump_insn = 0;
418   int i;
419
420   for (insn = target; insn; insn = next)
421     {
422       rtx this_jump_insn = insn;
423
424       next = NEXT_INSN (insn);
425
426       /* If this instruction can throw an exception, then we don't
427          know where we might end up next.  That means that we have to
428          assume that whatever we have already marked as live really is
429          live.  */
430       if (can_throw (insn))
431         break;
432
433       switch (GET_CODE (insn))
434         {
435         case CODE_LABEL:
436           /* After a label, any pending dead registers that weren't yet
437              used can be made dead.  */
438           AND_COMPL_HARD_REG_SET (pending_dead_regs, needed.regs);
439           AND_COMPL_HARD_REG_SET (res->regs, pending_dead_regs);
440           CLEAR_HARD_REG_SET (pending_dead_regs);
441
442           continue;
443
444         case BARRIER:
445         case NOTE:
446           continue;
447
448         case INSN:
449           if (GET_CODE (PATTERN (insn)) == USE)
450             {
451               /* If INSN is a USE made by update_block, we care about the
452                  underlying insn.  Any registers set by the underlying insn
453                  are live since the insn is being done somewhere else.  */
454               if (GET_RTX_CLASS (GET_CODE (XEXP (PATTERN (insn), 0))) == 'i')
455                 mark_set_resources (XEXP (PATTERN (insn), 0), res, 0,
456                                     MARK_SRC_DEST_CALL);
457
458               /* All other USE insns are to be ignored.  */
459               continue;
460             }
461           else if (GET_CODE (PATTERN (insn)) == CLOBBER)
462             continue;
463           else if (GET_CODE (PATTERN (insn)) == SEQUENCE)
464             {
465               /* An unconditional jump can be used to fill the delay slot
466                  of a call, so search for a JUMP_INSN in any position.  */
467               for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
468                 {
469                   this_jump_insn = XVECEXP (PATTERN (insn), 0, i);
470                   if (GET_CODE (this_jump_insn) == JUMP_INSN)
471                     break;
472                 }
473             }
474
475         default:
476           break;
477         }
478
479       if (GET_CODE (this_jump_insn) == JUMP_INSN)
480         {
481           if (jump_count++ < 10)
482             {
483               if (any_uncondjump_p (this_jump_insn)
484                   || GET_CODE (PATTERN (this_jump_insn)) == RETURN)
485                 {
486                   next = JUMP_LABEL (this_jump_insn);
487                   if (jump_insn == 0)
488                     {
489                       jump_insn = insn;
490                       if (jump_target)
491                         *jump_target = JUMP_LABEL (this_jump_insn);
492                     }
493                 }
494               else if (any_condjump_p (this_jump_insn))
495                 {
496                   struct resources target_set, target_res;
497                   struct resources fallthrough_res;
498
499                   /* We can handle conditional branches here by following
500                      both paths, and then IOR the results of the two paths
501                      together, which will give us registers that are dead
502                      on both paths.  Since this is expensive, we give it
503                      a much higher cost than unconditional branches.  The
504                      cost was chosen so that we will follow at most 1
505                      conditional branch.  */
506
507                   jump_count += 4;
508                   if (jump_count >= 10)
509                     break;
510
511                   mark_referenced_resources (insn, &needed, 1);
512
513                   /* For an annulled branch, mark_set_resources ignores slots
514                      filled by instructions from the target.  This is correct
515                      if the branch is not taken.  Since we are following both
516                      paths from the branch, we must also compute correct info
517                      if the branch is taken.  We do this by inverting all of
518                      the INSN_FROM_TARGET_P bits, calling mark_set_resources,
519                      and then inverting the INSN_FROM_TARGET_P bits again.  */
520
521                   if (GET_CODE (PATTERN (insn)) == SEQUENCE
522                       && INSN_ANNULLED_BRANCH_P (this_jump_insn))
523                     {
524                       for (i = 1; i < XVECLEN (PATTERN (insn), 0); i++)
525                         INSN_FROM_TARGET_P (XVECEXP (PATTERN (insn), 0, i))
526                           = ! INSN_FROM_TARGET_P (XVECEXP (PATTERN (insn), 0, i));
527
528                       target_set = set;
529                       mark_set_resources (insn, &target_set, 0,
530                                           MARK_SRC_DEST_CALL);
531
532                       for (i = 1; i < XVECLEN (PATTERN (insn), 0); i++)
533                         INSN_FROM_TARGET_P (XVECEXP (PATTERN (insn), 0, i))
534                           = ! INSN_FROM_TARGET_P (XVECEXP (PATTERN (insn), 0, i));
535
536                       mark_set_resources (insn, &set, 0, MARK_SRC_DEST_CALL);
537                     }
538                   else
539                     {
540                       mark_set_resources (insn, &set, 0, MARK_SRC_DEST_CALL);
541                       target_set = set;
542                     }
543
544                   target_res = *res;
545                   COPY_HARD_REG_SET (scratch, target_set.regs);
546                   AND_COMPL_HARD_REG_SET (scratch, needed.regs);
547                   AND_COMPL_HARD_REG_SET (target_res.regs, scratch);
548
549                   fallthrough_res = *res;
550                   COPY_HARD_REG_SET (scratch, set.regs);
551                   AND_COMPL_HARD_REG_SET (scratch, needed.regs);
552                   AND_COMPL_HARD_REG_SET (fallthrough_res.regs, scratch);
553
554                   find_dead_or_set_registers (JUMP_LABEL (this_jump_insn),
555                                               &target_res, 0, jump_count,
556                                               target_set, needed);
557                   find_dead_or_set_registers (next,
558                                               &fallthrough_res, 0, jump_count,
559                                               set, needed);
560                   IOR_HARD_REG_SET (fallthrough_res.regs, target_res.regs);
561                   AND_HARD_REG_SET (res->regs, fallthrough_res.regs);
562                   break;
563                 }
564               else
565                 break;
566             }
567           else
568             {
569               /* Don't try this optimization if we expired our jump count
570                  above, since that would mean there may be an infinite loop
571                  in the function being compiled.  */
572               jump_insn = 0;
573               break;
574             }
575         }
576
577       mark_referenced_resources (insn, &needed, 1);
578       mark_set_resources (insn, &set, 0, MARK_SRC_DEST_CALL);
579
580       COPY_HARD_REG_SET (scratch, set.regs);
581       AND_COMPL_HARD_REG_SET (scratch, needed.regs);
582       AND_COMPL_HARD_REG_SET (res->regs, scratch);
583     }
584
585   return jump_insn;
586 }
587 \f
588 /* Given X, a part of an insn, and a pointer to a `struct resource',
589    RES, indicate which resources are modified by the insn. If
590    MARK_TYPE is MARK_SRC_DEST_CALL, also mark resources potentially
591    set by the called routine.  If MARK_TYPE is MARK_DEST, only mark SET_DESTs
592
593    If IN_DEST is nonzero, it means we are inside a SET.  Otherwise,
594    objects are being referenced instead of set.
595
596    We never mark the insn as modifying the condition code unless it explicitly
597    SETs CC0 even though this is not totally correct.  The reason for this is
598    that we require a SET of CC0 to immediately precede the reference to CC0.
599    So if some other insn sets CC0 as a side-effect, we know it cannot affect
600    our computation and thus may be placed in a delay slot.   */
601
602 void
603 mark_set_resources (x, res, in_dest, mark_type)
604      register rtx x;
605      register struct resources *res;
606      int in_dest;
607      enum mark_resource_type mark_type;
608 {
609   enum rtx_code code;
610   int i, j;
611   unsigned int r;
612   const char *format_ptr;
613
614  restart:
615
616   code = GET_CODE (x);
617
618   switch (code)
619     {
620     case NOTE:
621     case BARRIER:
622     case CODE_LABEL:
623     case USE:
624     case CONST_INT:
625     case CONST_DOUBLE:
626     case LABEL_REF:
627     case SYMBOL_REF:
628     case CONST:
629     case PC:
630       /* These don't set any resources.  */
631       return;
632
633     case CC0:
634       if (in_dest)
635         res->cc = 1;
636       return;
637
638     case CALL_INSN:
639       /* Called routine modifies the condition code, memory, any registers
640          that aren't saved across calls, global registers and anything
641          explicitly CLOBBERed immediately after the CALL_INSN.  */
642
643       if (mark_type == MARK_SRC_DEST_CALL)
644         {
645           rtx next = NEXT_INSN (x);
646           rtx prev = PREV_INSN (x);
647           rtx link;
648
649           res->cc = res->memory = 1;
650           for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
651             if (call_used_regs[r] || global_regs[r])
652               SET_HARD_REG_BIT (res->regs, r);
653
654           /* If X is part of a delay slot sequence, then NEXT should be
655              the first insn after the sequence.  */
656           if (NEXT_INSN (prev) != x)
657             next = NEXT_INSN (NEXT_INSN (prev));
658
659           for (link = CALL_INSN_FUNCTION_USAGE (x);
660                link; link = XEXP (link, 1))
661             if (GET_CODE (XEXP (link, 0)) == CLOBBER)
662               mark_set_resources (SET_DEST (XEXP (link, 0)), res, 1,
663                                   MARK_SRC_DEST);
664
665           /* Check for a NOTE_INSN_SETJMP.  If it exists, then we must
666              assume that this call can clobber any register.  */
667           if (next && GET_CODE (next) == NOTE
668               && NOTE_LINE_NUMBER (next) == NOTE_INSN_SETJMP)
669             SET_HARD_REG_SET (res->regs);
670         }
671
672       /* ... and also what its RTL says it modifies, if anything.  */
673
674     case JUMP_INSN:
675     case INSN:
676
677         /* An insn consisting of just a CLOBBER (or USE) is just for flow
678            and doesn't actually do anything, so we ignore it.  */
679
680 #ifdef INSN_SETS_ARE_DELAYED
681       if (mark_type != MARK_SRC_DEST_CALL
682           && INSN_SETS_ARE_DELAYED (x))
683         return;
684 #endif
685
686       x = PATTERN (x);
687       if (GET_CODE (x) != USE && GET_CODE (x) != CLOBBER)
688         goto restart;
689       return;
690
691     case SET:
692       /* If the source of a SET is a CALL, this is actually done by
693          the called routine.  So only include it if we are to include the
694          effects of the calling routine.  */
695
696       mark_set_resources (SET_DEST (x), res,
697                           (mark_type == MARK_SRC_DEST_CALL
698                            || GET_CODE (SET_SRC (x)) != CALL),
699                           mark_type);
700
701       if (mark_type != MARK_DEST)
702         mark_set_resources (SET_SRC (x), res, 0, MARK_SRC_DEST);
703       return;
704
705     case CLOBBER:
706       mark_set_resources (XEXP (x, 0), res, 1, MARK_SRC_DEST);
707       return;
708       
709     case SEQUENCE:
710       for (i = 0; i < XVECLEN (x, 0); i++)
711         if (! (INSN_ANNULLED_BRANCH_P (XVECEXP (x, 0, 0))
712                && INSN_FROM_TARGET_P (XVECEXP (x, 0, i))))
713           mark_set_resources (XVECEXP (x, 0, i), res, 0, mark_type);
714       return;
715
716     case POST_INC:
717     case PRE_INC:
718     case POST_DEC:
719     case PRE_DEC:
720       mark_set_resources (XEXP (x, 0), res, 1, MARK_SRC_DEST);
721       return;
722
723     case SIGN_EXTRACT:
724     case ZERO_EXTRACT:
725       if (! (mark_type == MARK_DEST && in_dest))
726         {
727           mark_set_resources (XEXP (x, 0), res, in_dest, MARK_SRC_DEST);
728           mark_set_resources (XEXP (x, 1), res, 0, MARK_SRC_DEST);
729           mark_set_resources (XEXP (x, 2), res, 0, MARK_SRC_DEST);
730         }
731       return;
732
733     case MEM:
734       if (in_dest)
735         {
736           res->memory = 1;
737           res->unch_memory |= RTX_UNCHANGING_P (x);
738           res->volatil |= MEM_VOLATILE_P (x);
739         }
740
741       mark_set_resources (XEXP (x, 0), res, 0, MARK_SRC_DEST);
742       return;
743
744     case SUBREG:
745       if (in_dest)
746         {
747           if (GET_CODE (SUBREG_REG (x)) != REG)
748             mark_set_resources (SUBREG_REG (x), res, in_dest, mark_type);
749           else
750             {
751               unsigned int regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
752               unsigned int last_regno
753                 = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
754
755               for (r = regno; r < last_regno; r++)
756                 SET_HARD_REG_BIT (res->regs, r);
757             }
758         }
759       return;
760
761     case REG:
762       if (in_dest)
763         for (r = 0; r < HARD_REGNO_NREGS (REGNO (x), GET_MODE (x)); r++)
764           SET_HARD_REG_BIT (res->regs, REGNO (x) + r);
765       return;
766
767     case STRICT_LOW_PART:
768       if (! (mark_type == MARK_DEST && in_dest))
769         {
770           mark_set_resources (XEXP (x, 0), res, 0, MARK_SRC_DEST);
771           return;
772         }
773
774     case UNSPEC_VOLATILE:
775     case ASM_INPUT:
776       /* Traditional asm's are always volatile.  */
777       res->volatil = 1;
778       return;
779
780     case TRAP_IF:
781       res->volatil = 1;
782       break;
783
784     case ASM_OPERANDS:
785       res->volatil |= MEM_VOLATILE_P (x);
786
787       /* For all ASM_OPERANDS, we must traverse the vector of input operands.
788          We can not just fall through here since then we would be confused
789          by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
790          traditional asms unlike their normal usage.  */
791       
792       for (i = 0; i < ASM_OPERANDS_INPUT_LENGTH (x); i++)
793         mark_set_resources (ASM_OPERANDS_INPUT (x, i), res, in_dest,
794                             MARK_SRC_DEST);
795       return;
796
797     default:
798       break;
799     }
800
801   /* Process each sub-expression and flag what it needs.  */
802   format_ptr = GET_RTX_FORMAT (code);
803   for (i = 0; i < GET_RTX_LENGTH (code); i++)
804     switch (*format_ptr++)
805       {
806       case 'e':
807         mark_set_resources (XEXP (x, i), res, in_dest, mark_type);
808         break;
809
810       case 'E':
811         for (j = 0; j < XVECLEN (x, i); j++)
812           mark_set_resources (XVECEXP (x, i, j), res, in_dest, mark_type);
813         break;
814       }
815 }
816 \f
817 /* Set the resources that are live at TARGET.
818
819    If TARGET is zero, we refer to the end of the current function and can
820    return our precomputed value.
821
822    Otherwise, we try to find out what is live by consulting the basic block
823    information.  This is tricky, because we must consider the actions of
824    reload and jump optimization, which occur after the basic block information
825    has been computed.
826
827    Accordingly, we proceed as follows::
828
829    We find the previous BARRIER and look at all immediately following labels
830    (with no intervening active insns) to see if any of them start a basic
831    block.  If we hit the start of the function first, we use block 0.
832
833    Once we have found a basic block and a corresponding first insns, we can
834    accurately compute the live status from basic_block_live_regs and
835    reg_renumber.  (By starting at a label following a BARRIER, we are immune
836    to actions taken by reload and jump.)  Then we scan all insns between
837    that point and our target.  For each CLOBBER (or for call-clobbered regs
838    when we pass a CALL_INSN), mark the appropriate registers are dead.  For
839    a SET, mark them as live.
840
841    We have to be careful when using REG_DEAD notes because they are not
842    updated by such things as find_equiv_reg.  So keep track of registers
843    marked as dead that haven't been assigned to, and mark them dead at the
844    next CODE_LABEL since reload and jump won't propagate values across labels.
845
846    If we cannot find the start of a basic block (should be a very rare
847    case, if it can happen at all), mark everything as potentially live.
848
849    Next, scan forward from TARGET looking for things set or clobbered
850    before they are used.  These are not live.
851
852    Because we can be called many times on the same target, save our results
853    in a hash table indexed by INSN_UID.  This is only done if the function
854    init_resource_info () was invoked before we are called.  */
855
856 void
857 mark_target_live_regs (insns, target, res)
858      rtx insns;
859      rtx target;
860      struct resources *res;
861 {
862   int b = -1;
863   int i;
864   struct target_info *tinfo = NULL;
865   rtx insn;
866   rtx jump_insn = 0;
867   rtx jump_target;
868   HARD_REG_SET scratch;
869   struct resources set, needed;
870
871   /* Handle end of function.  */
872   if (target == 0)
873     {
874       *res = end_of_function_needs;
875       return;
876     }
877
878   /* We have to assume memory is needed, but the CC isn't.  */
879   res->memory = 1;
880   res->volatil = res->unch_memory = 0;
881   res->cc = 0;
882
883   /* See if we have computed this value already.  */
884   if (target_hash_table != NULL)
885     {
886       for (tinfo = target_hash_table[INSN_UID (target) % TARGET_HASH_PRIME];
887            tinfo; tinfo = tinfo->next)
888         if (tinfo->uid == INSN_UID (target))
889           break;
890
891       /* Start by getting the basic block number.  If we have saved
892          information, we can get it from there unless the insn at the
893          start of the basic block has been deleted.  */
894       if (tinfo && tinfo->block != -1
895           && ! INSN_DELETED_P (BLOCK_HEAD (tinfo->block)))
896         b = tinfo->block;
897     }
898
899   if (b == -1)
900     b = find_basic_block (target);
901
902   if (target_hash_table != NULL)
903     {
904       if (tinfo)
905         {
906           /* If the information is up-to-date, use it.  Otherwise, we will
907              update it below.  */
908           if (b == tinfo->block && b != -1 && tinfo->bb_tick == bb_ticks[b])
909             {
910               COPY_HARD_REG_SET (res->regs, tinfo->live_regs);
911               return;
912             }
913         }
914       else
915         {
916           /* Allocate a place to put our results and chain it into the 
917              hash table.  */
918           tinfo = (struct target_info *) oballoc (sizeof (struct target_info));
919           tinfo->uid = INSN_UID (target);
920           tinfo->block = b;
921           tinfo->next = target_hash_table[INSN_UID (target) % TARGET_HASH_PRIME];
922           target_hash_table[INSN_UID (target) % TARGET_HASH_PRIME] = tinfo;
923         }
924     }
925
926   CLEAR_HARD_REG_SET (pending_dead_regs);
927
928   /* If we found a basic block, get the live registers from it and update
929      them with anything set or killed between its start and the insn before
930      TARGET.  Otherwise, we must assume everything is live.  */
931   if (b != -1)
932     {
933       regset regs_live = BASIC_BLOCK (b)->global_live_at_start;
934       unsigned int j;
935       unsigned int regno;
936       rtx start_insn, stop_insn;
937
938       /* Compute hard regs live at start of block -- this is the real hard regs
939          marked live, plus live pseudo regs that have been renumbered to
940          hard regs.  */
941
942       REG_SET_TO_HARD_REG_SET (current_live_regs, regs_live);
943
944       EXECUTE_IF_SET_IN_REG_SET
945         (regs_live, FIRST_PSEUDO_REGISTER, i,
946          {
947            if (reg_renumber[i] >= 0)
948              {
949                regno = reg_renumber[i];
950                for (j = regno;
951                     j < regno + HARD_REGNO_NREGS (regno,
952                                                   PSEUDO_REGNO_MODE (i));
953                     j++)
954                  SET_HARD_REG_BIT (current_live_regs, j);
955              }
956          });
957
958       /* Get starting and ending insn, handling the case where each might
959          be a SEQUENCE.  */
960       start_insn = (b == 0 ? insns : BLOCK_HEAD (b));
961       stop_insn = target;
962
963       if (GET_CODE (start_insn) == INSN
964           && GET_CODE (PATTERN (start_insn)) == SEQUENCE)
965         start_insn = XVECEXP (PATTERN (start_insn), 0, 0);
966
967       if (GET_CODE (stop_insn) == INSN
968           && GET_CODE (PATTERN (stop_insn)) == SEQUENCE)
969         stop_insn = next_insn (PREV_INSN (stop_insn));
970
971       for (insn = start_insn; insn != stop_insn;
972            insn = next_insn_no_annul (insn))
973         {
974           rtx link;
975           rtx real_insn = insn;
976
977           /* If this insn is from the target of a branch, it isn't going to
978              be used in the sequel.  If it is used in both cases, this
979              test will not be true.  */
980           if (INSN_FROM_TARGET_P (insn))
981             continue;
982
983           /* If this insn is a USE made by update_block, we care about the
984              underlying insn.  */
985           if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == USE
986               && GET_RTX_CLASS (GET_CODE (XEXP (PATTERN (insn), 0))) == 'i')
987               real_insn = XEXP (PATTERN (insn), 0);
988
989           if (GET_CODE (real_insn) == CALL_INSN)
990             {
991               /* CALL clobbers all call-used regs that aren't fixed except
992                  sp, ap, and fp.  Do this before setting the result of the
993                  call live.  */
994               for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
995                 if (call_used_regs[i]
996                     && i != STACK_POINTER_REGNUM && i != FRAME_POINTER_REGNUM
997                     && i != ARG_POINTER_REGNUM
998 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
999                     && i != HARD_FRAME_POINTER_REGNUM
1000 #endif
1001 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
1002                     && ! (i == ARG_POINTER_REGNUM && fixed_regs[i])
1003 #endif
1004 #if defined (PIC_OFFSET_TABLE_REGNUM) && !defined (PIC_OFFSET_TABLE_REG_CALL_CLOBBERED)
1005                     && ! (i == PIC_OFFSET_TABLE_REGNUM && flag_pic)
1006 #endif
1007                     )
1008                   CLEAR_HARD_REG_BIT (current_live_regs, i);
1009
1010               /* A CALL_INSN sets any global register live, since it may
1011                  have been modified by the call.  */
1012               for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1013                 if (global_regs[i])
1014                   SET_HARD_REG_BIT (current_live_regs, i);
1015             }
1016
1017           /* Mark anything killed in an insn to be deadened at the next
1018              label.  Ignore USE insns; the only REG_DEAD notes will be for
1019              parameters.  But they might be early.  A CALL_INSN will usually
1020              clobber registers used for parameters.  It isn't worth bothering
1021              with the unlikely case when it won't.  */
1022           if ((GET_CODE (real_insn) == INSN
1023                && GET_CODE (PATTERN (real_insn)) != USE
1024                && GET_CODE (PATTERN (real_insn)) != CLOBBER)
1025               || GET_CODE (real_insn) == JUMP_INSN
1026               || GET_CODE (real_insn) == CALL_INSN)
1027             {
1028               for (link = REG_NOTES (real_insn); link; link = XEXP (link, 1))
1029                 if (REG_NOTE_KIND (link) == REG_DEAD
1030                     && GET_CODE (XEXP (link, 0)) == REG
1031                     && REGNO (XEXP (link, 0)) < FIRST_PSEUDO_REGISTER)
1032                   {
1033                     int first_regno = REGNO (XEXP (link, 0));
1034                     int last_regno
1035                       = (first_regno
1036                          + HARD_REGNO_NREGS (first_regno,
1037                                              GET_MODE (XEXP (link, 0))));
1038                          
1039                     for (i = first_regno; i < last_regno; i++)
1040                       SET_HARD_REG_BIT (pending_dead_regs, i);
1041                   }
1042
1043               note_stores (PATTERN (real_insn), update_live_status, NULL);
1044
1045               /* If any registers were unused after this insn, kill them.
1046                  These notes will always be accurate.  */
1047               for (link = REG_NOTES (real_insn); link; link = XEXP (link, 1))
1048                 if (REG_NOTE_KIND (link) == REG_UNUSED
1049                     && GET_CODE (XEXP (link, 0)) == REG
1050                     && REGNO (XEXP (link, 0)) < FIRST_PSEUDO_REGISTER)
1051                   {
1052                     int first_regno = REGNO (XEXP (link, 0));
1053                     int last_regno
1054                       = (first_regno
1055                          + HARD_REGNO_NREGS (first_regno,
1056                                              GET_MODE (XEXP (link, 0))));
1057                          
1058                     for (i = first_regno; i < last_regno; i++)
1059                       CLEAR_HARD_REG_BIT (current_live_regs, i);
1060                   }
1061             }
1062
1063           else if (GET_CODE (real_insn) == CODE_LABEL)
1064             {
1065               /* A label clobbers the pending dead registers since neither
1066                  reload nor jump will propagate a value across a label.  */
1067               AND_COMPL_HARD_REG_SET (current_live_regs, pending_dead_regs);
1068               CLEAR_HARD_REG_SET (pending_dead_regs);
1069             }
1070
1071           /* The beginning of the epilogue corresponds to the end of the
1072              RTL chain when there are no epilogue insns.  Certain resources
1073              are implicitly required at that point.  */
1074           else if (GET_CODE (real_insn) == NOTE
1075                    && NOTE_LINE_NUMBER (real_insn) == NOTE_INSN_EPILOGUE_BEG)
1076             IOR_HARD_REG_SET (current_live_regs, start_of_epilogue_needs.regs);
1077         }
1078
1079       COPY_HARD_REG_SET (res->regs, current_live_regs);
1080       if (tinfo != NULL)
1081         {
1082           tinfo->block = b;
1083           tinfo->bb_tick = bb_ticks[b];
1084         }
1085     }
1086   else
1087     /* We didn't find the start of a basic block.  Assume everything
1088        in use.  This should happen only extremely rarely.  */
1089     SET_HARD_REG_SET (res->regs);
1090
1091   CLEAR_RESOURCE (&set);
1092   CLEAR_RESOURCE (&needed);
1093
1094   jump_insn = find_dead_or_set_registers (target, res, &jump_target, 0,
1095                                           set, needed);
1096
1097   /* If we hit an unconditional branch, we have another way of finding out
1098      what is live: we can see what is live at the branch target and include
1099      anything used but not set before the branch.  We add the live
1100      resources found using the test below to those found until now. */
1101
1102   if (jump_insn)
1103     {
1104       struct resources new_resources;
1105       rtx stop_insn = next_active_insn (jump_insn);
1106
1107       mark_target_live_regs (insns, next_active_insn (jump_target),
1108                              &new_resources);
1109       CLEAR_RESOURCE (&set);
1110       CLEAR_RESOURCE (&needed);
1111
1112       /* Include JUMP_INSN in the needed registers.  */
1113       for (insn = target; insn != stop_insn; insn = next_active_insn (insn))
1114         {
1115           mark_referenced_resources (insn, &needed, 1);
1116
1117           COPY_HARD_REG_SET (scratch, needed.regs);
1118           AND_COMPL_HARD_REG_SET (scratch, set.regs);
1119           IOR_HARD_REG_SET (new_resources.regs, scratch);
1120
1121           mark_set_resources (insn, &set, 0, MARK_SRC_DEST_CALL);
1122         }
1123
1124       IOR_HARD_REG_SET (res->regs, new_resources.regs);
1125     }
1126
1127   if (tinfo != NULL)
1128     {
1129       COPY_HARD_REG_SET (tinfo->live_regs, res->regs);
1130     }
1131 }
1132 \f
1133 /* Initialize the resources required by mark_target_live_regs ().
1134    This should be invoked before the first call to mark_target_live_regs.  */
1135
1136 void
1137 init_resource_info (epilogue_insn)
1138      rtx epilogue_insn;
1139 {
1140   int i;
1141
1142   /* Indicate what resources are required to be valid at the end of the current
1143      function.  The condition code never is and memory always is.  If the
1144      frame pointer is needed, it is and so is the stack pointer unless
1145      EXIT_IGNORE_STACK is non-zero.  If the frame pointer is not needed, the
1146      stack pointer is.  Registers used to return the function value are
1147      needed.  Registers holding global variables are needed.  */
1148
1149   end_of_function_needs.cc = 0;
1150   end_of_function_needs.memory = 1;
1151   end_of_function_needs.unch_memory = 0;
1152   CLEAR_HARD_REG_SET (end_of_function_needs.regs);
1153
1154   if (frame_pointer_needed)
1155     {
1156       SET_HARD_REG_BIT (end_of_function_needs.regs, FRAME_POINTER_REGNUM);
1157 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
1158       SET_HARD_REG_BIT (end_of_function_needs.regs, HARD_FRAME_POINTER_REGNUM);
1159 #endif
1160 #ifdef EXIT_IGNORE_STACK
1161       if (! EXIT_IGNORE_STACK
1162           || current_function_sp_is_unchanging)
1163 #endif
1164         SET_HARD_REG_BIT (end_of_function_needs.regs, STACK_POINTER_REGNUM);
1165     }
1166   else
1167     SET_HARD_REG_BIT (end_of_function_needs.regs, STACK_POINTER_REGNUM);
1168
1169   if (current_function_return_rtx != 0)
1170     mark_referenced_resources (current_function_return_rtx,
1171                                &end_of_function_needs, 1);
1172
1173   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1174     if (global_regs[i]
1175 #ifdef EPILOGUE_USES
1176         || EPILOGUE_USES (i)
1177 #endif
1178         )
1179       SET_HARD_REG_BIT (end_of_function_needs.regs, i);
1180
1181   /* The registers required to be live at the end of the function are
1182      represented in the flow information as being dead just prior to
1183      reaching the end of the function.  For example, the return of a value
1184      might be represented by a USE of the return register immediately
1185      followed by an unconditional jump to the return label where the
1186      return label is the end of the RTL chain.  The end of the RTL chain
1187      is then taken to mean that the return register is live.
1188
1189      This sequence is no longer maintained when epilogue instructions are
1190      added to the RTL chain.  To reconstruct the original meaning, the
1191      start of the epilogue (NOTE_INSN_EPILOGUE_BEG) is regarded as the
1192      point where these registers become live (start_of_epilogue_needs).
1193      If epilogue instructions are present, the registers set by those
1194      instructions won't have been processed by flow.  Thus, those
1195      registers are additionally required at the end of the RTL chain
1196      (end_of_function_needs).  */
1197
1198   start_of_epilogue_needs = end_of_function_needs;
1199
1200   while ((epilogue_insn = next_nonnote_insn (epilogue_insn)))
1201     mark_set_resources (epilogue_insn, &end_of_function_needs, 0,
1202                         MARK_SRC_DEST_CALL);
1203
1204   /* Allocate and initialize the tables used by mark_target_live_regs.  */
1205   target_hash_table = (struct target_info **)
1206     xcalloc (TARGET_HASH_PRIME, sizeof (struct target_info *));
1207   bb_ticks = (int *) xcalloc (n_basic_blocks, sizeof (int));
1208 }
1209 \f
1210 /* Free up the resources allcated to mark_target_live_regs ().  This
1211    should be invoked after the last call to mark_target_live_regs ().  */
1212
1213 void
1214 free_resource_info ()
1215 {
1216   if (target_hash_table != NULL)
1217     {
1218       free (target_hash_table);
1219       target_hash_table = NULL;
1220     }
1221
1222   if (bb_ticks != NULL)
1223     {
1224       free (bb_ticks);
1225       bb_ticks = NULL;
1226     }
1227 }
1228 \f
1229 /* Clear any hashed information that we have stored for INSN.  */
1230
1231 void
1232 clear_hashed_info_for_insn (insn)
1233      rtx insn;
1234 {
1235   struct target_info *tinfo;
1236       
1237   if (target_hash_table != NULL)
1238     {
1239       for (tinfo = target_hash_table[INSN_UID (insn) % TARGET_HASH_PRIME];
1240            tinfo; tinfo = tinfo->next)
1241         if (tinfo->uid == INSN_UID (insn))
1242           break;
1243
1244       if (tinfo)
1245         tinfo->block = -1;
1246     }
1247 }
1248 \f
1249 /* Increment the tick count for the basic block that contains INSN.  */
1250
1251 void
1252 incr_ticks_for_insn (insn)
1253      rtx insn;
1254 {
1255   int b = find_basic_block (insn);
1256
1257   if (b != -1)
1258     bb_ticks[b]++;
1259 }
1260 \f
1261 /* Add TRIAL to the set of resources used at the end of the current
1262    function. */
1263 void
1264 mark_end_of_function_resources (trial, include_delayed_effects)
1265      rtx trial;
1266      int include_delayed_effects;
1267 {
1268   mark_referenced_resources (trial, &end_of_function_needs,
1269                              include_delayed_effects);
1270 }
1271 \f
1272 /* Try to find a hard register of mode MODE, matching the register class in
1273    CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
1274    remains available until the end of LAST_INSN.  LAST_INSN may be NULL_RTX,
1275    in which case the only condition is that the register must be available
1276    before CURRENT_INSN.
1277    Registers that already have bits set in REG_SET will not be considered.
1278
1279    If an appropriate register is available, it will be returned and the
1280    corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
1281    returned.  */
1282
1283 rtx
1284 find_free_register (current_insn, last_insn, class_str, mode, reg_set)
1285      rtx current_insn, last_insn;
1286      const char *class_str;
1287      int mode;
1288      HARD_REG_SET *reg_set;
1289 {
1290   int i, j;
1291   struct resources used;
1292   unsigned char clet = class_str[0];
1293   enum reg_class class
1294     = (clet == 'r' ? GENERAL_REGS :  REG_CLASS_FROM_LETTER (clet));
1295
1296   mark_target_live_regs (get_insns (), current_insn, &used);
1297   if (last_insn)
1298     while (current_insn != last_insn)
1299       {
1300         /* Exclude anything set in this insn.  */
1301         mark_set_resources (PATTERN (current_insn), &used, 0,
1302                             MARK_SRC_DEST_CALL);
1303         current_insn = next_nonnote_insn (current_insn);
1304       }
1305
1306
1307   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1308     {
1309       int regno;
1310       int success;
1311
1312 #ifdef REG_ALLOC_ORDER
1313       regno = reg_alloc_order [i];
1314 #else
1315       regno = i;
1316 #endif
1317
1318       /* Don't allocate fixed registers.  */
1319       if (fixed_regs[regno])
1320         continue;
1321       /* Make sure the register is of the right class.  */
1322       if (! TEST_HARD_REG_BIT (reg_class_contents[class], regno))
1323         continue;
1324       /* And can support the mode we need.  */
1325       if (! HARD_REGNO_MODE_OK (regno, mode))
1326         continue;
1327       /* And that we don't create an extra save/restore.  */
1328       if (! call_used_regs[regno] && ! regs_ever_live[regno])
1329         continue;
1330       /* And we don't clobber traceback for noreturn functions.  */
1331       if ((regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM)
1332           && (! reload_completed || frame_pointer_needed))
1333         continue;
1334
1335       success = 1;
1336       for (j = HARD_REGNO_NREGS (regno, mode) - 1; j >= 0; j--)
1337         {
1338           if (TEST_HARD_REG_BIT (*reg_set, regno + j)
1339               || TEST_HARD_REG_BIT (used.regs, regno + j))
1340             {
1341               success = 0;
1342               break;
1343             }
1344         }
1345       if (success)
1346         {
1347           for (j = HARD_REGNO_NREGS (regno, mode) - 1; j >= 0; j--)
1348             {
1349               SET_HARD_REG_BIT (*reg_set, regno + j);
1350             }
1351           return gen_rtx_REG (mode, regno);
1352         }
1353     }
1354   return NULL_RTX;
1355 }
1356
1357 /* Return true if REG is dead at CURRENT_INSN.  */
1358
1359 int
1360 reg_dead_p (current_insn, reg)
1361      rtx current_insn, reg;
1362 {
1363   struct resources used;
1364   int regno, j;
1365
1366   mark_target_live_regs (get_insns (), current_insn, &used);
1367   
1368   regno = REGNO (reg);
1369   for (j = HARD_REGNO_NREGS (regno, GET_MODE (reg)) - 1; j >= 0; j--)
1370     {
1371       if (TEST_HARD_REG_BIT (used.regs, regno + j))
1372         return 0;
1373     }
1374
1375   return 1;
1376 }