OSDN Git Service

(output_prolog): Correctly compute floating-reg save area offset.
[pf3gnuchains/gcc-fork.git] / gcc / config / alpha / alpha.c
1 /* Subroutines used for code generation on the DEC Alpha.
2    Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
3    Contributed by Richard Kenner (kenner@nyu.edu)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21
22 #include <stdio.h>
23 #include "config.h"
24 #include "rtl.h"
25 #include "regs.h"
26 #include "hard-reg-set.h"
27 #include "real.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-flags.h"
31 #include "output.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "recog.h"
35 #include "reload.h"
36 #include "expr.h"
37 #include "obstack.h"
38 #include "tree.h"
39
40 /* Save information from a "cmpxx" operation until the branch or scc is
41    emitted.  */
42
43 rtx alpha_compare_op0, alpha_compare_op1;
44 int alpha_compare_fp_p;
45
46 /* Save the name of the current function as used by the assembler.  This
47    is used by the epilogue.  */
48
49 char *alpha_function_name;
50
51 /* Non-zero if inside of a function, because the Alpha asm can't
52    handle .files inside of functions.  */
53
54 static int inside_function = FALSE;
55
56 /* Nonzero if the current function needs gp.  */
57
58 int alpha_function_needs_gp;
59
60 extern char *version_string;
61 \f
62 /* Returns 1 if VALUE is a mask that contains full bytes of zero or ones.  */
63
64 int
65 zap_mask (value)
66      HOST_WIDE_INT value;
67 {
68   int i;
69
70   for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
71        i++, value >>= 8)
72     if ((value & 0xff) != 0 && (value & 0xff) != 0xff)
73       return 0;
74
75   return 1;
76 }
77
78 /* Returns 1 if OP is either the constant zero or a register.  If a
79    register, it must be in the proper mode unless MODE is VOIDmode.  */
80
81 int
82 reg_or_0_operand (op, mode)
83       register rtx op;
84       enum machine_mode mode;
85 {
86   return op == const0_rtx || register_operand (op, mode);
87 }
88
89 /* Return 1 if OP is a constant in the range of 0-63 (for a shift) or
90    any register.  */
91
92 int
93 reg_or_6bit_operand (op, mode)
94      register rtx op;
95      enum machine_mode mode;
96 {
97   return ((GET_CODE (op) == CONST_INT
98            && (unsigned HOST_WIDE_INT) INTVAL (op) < 64)
99           || register_operand (op, mode));
100 }
101
102
103 /* Return 1 if OP is an 8-bit constant or any register.  */
104
105 int
106 reg_or_8bit_operand (op, mode)
107      register rtx op;
108      enum machine_mode mode;
109 {
110   return ((GET_CODE (op) == CONST_INT
111            && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100)
112           || register_operand (op, mode));
113 }
114
115 /* Return 1 if the operand is a valid second operand to an add insn.  */
116
117 int
118 add_operand (op, mode)
119      register rtx op;
120      enum machine_mode mode;
121 {
122   if (GET_CODE (op) == CONST_INT)
123     return ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) < 0x10000
124             || ((INTVAL (op) & 0xffff) == 0
125                 && (INTVAL (op) >> 31 == -1
126                     || INTVAL (op) >> 31 == 0)));
127
128   return register_operand (op, mode);
129 }
130
131 /* Return 1 if the operand is a valid second operand to a sign-extending
132    add insn.  */
133
134 int
135 sext_add_operand (op, mode)
136      register rtx op;
137      enum machine_mode mode;
138 {
139   if (GET_CODE (op) == CONST_INT)
140     return ((unsigned HOST_WIDE_INT) INTVAL (op) < 255
141             || (unsigned HOST_WIDE_INT) (- INTVAL (op)) < 255);
142
143   return register_operand (op, mode);
144 }
145
146 /* Return 1 if OP is the constant 4 or 8.  */
147
148 int
149 const48_operand (op, mode)
150      register rtx op;
151      enum machine_mode mode;
152 {
153   return (GET_CODE (op) == CONST_INT
154           && (INTVAL (op) == 4 || INTVAL (op) == 8));
155 }
156
157 /* Return 1 if OP is a valid first operand to an AND insn.  */
158
159 int
160 and_operand (op, mode)
161      register rtx op;
162      enum machine_mode mode;
163 {
164   if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
165     return (zap_mask (CONST_DOUBLE_LOW (op))
166             && zap_mask (CONST_DOUBLE_HIGH (op)));
167
168   if (GET_CODE (op) == CONST_INT)
169     return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
170             || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100
171             || zap_mask (INTVAL (op)));
172
173   return register_operand (op, mode);
174 }
175
176 /* Return 1 if OP is a valid first operand to an IOR insn.  */
177
178 int
179 ior_operand (op, mode)
180      register rtx op;
181      enum machine_mode mode;
182 {
183   if (GET_CODE (op) == CONST_INT)
184     return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
185             || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100);
186
187   return register_operand (op, mode);
188 }
189
190 /* Return 1 if OP is a constant that is the width, in bits, of an integral
191    mode smaller than DImode.  */
192
193 int
194 mode_width_operand (op, mode)
195      register rtx op;
196      enum machine_mode mode;
197 {
198   return (GET_CODE (op) == CONST_INT
199           && (INTVAL (op) == 8 || INTVAL (op) == 16 || INTVAL (op) == 32));
200 }
201
202 /* Return 1 if OP is a constant that is the width of an integral machine mode
203    smaller than an integer.  */
204
205 int
206 mode_mask_operand (op, mode)
207      register rtx op;
208      enum machine_mode mode;
209 {
210 #if HOST_BITS_PER_WIDE_INT == 32
211   if (GET_CODE (op) == CONST_DOUBLE)
212     return CONST_DOUBLE_HIGH (op) == 0 && CONST_DOUBLE_LOW (op) == -1;
213 #endif
214
215   if (GET_CODE (op) == CONST_INT)
216     return (INTVAL (op) == 0xff
217             || INTVAL (op) == 0xffff
218 #if HOST_BITS_PER_WIDE_INT == 64
219             || INTVAL (op) == 0xffffffff
220 #endif
221             );
222 }
223
224 /* Return 1 if OP is a multiple of 8 less than 64.  */
225
226 int
227 mul8_operand (op, mode)
228      register rtx op;
229      enum machine_mode mode;
230 {
231   return (GET_CODE (op) == CONST_INT
232           && (unsigned HOST_WIDE_INT) INTVAL (op) < 64
233           && (INTVAL (op) & 7) == 0);
234 }
235
236 /* Return 1 if OP is the constant zero in floating-point.  */
237
238 int
239 fp0_operand (op, mode)
240      register rtx op;
241      enum machine_mode mode;
242 {
243   return (GET_MODE (op) == mode
244           && GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode));
245 }
246
247 /* Return 1 if OP is the floating-point constant zero or a register.  */
248
249 int
250 reg_or_fp0_operand (op, mode)
251      register rtx op;
252      enum machine_mode mode;
253 {
254   return fp0_operand (op, mode) || register_operand (op, mode);
255 }
256
257 /* Return 1 if OP is a register or a constant integer.  */
258
259
260 int
261 reg_or_cint_operand (op, mode)
262     register rtx op;
263     enum machine_mode mode;
264 {
265      return GET_CODE (op) == CONST_INT || register_operand (op, mode);
266 }
267
268 /* Return 1 if OP is a valid operand for the source of a move insn.  */
269
270 int
271 input_operand (op, mode)
272      register rtx op;
273      enum machine_mode mode;
274 {
275   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
276     return 0;
277
278   if (GET_MODE_CLASS (mode) == MODE_FLOAT && GET_MODE (op) != mode)
279     return 0;
280
281   switch (GET_CODE (op))
282     {
283     case LABEL_REF:
284     case SYMBOL_REF:
285     case CONST:
286       return mode == DImode;
287
288     case REG:
289       return 1;
290
291     case SUBREG:
292       if (register_operand (op, mode))
293         return 1;
294       /* ... fall through ... */
295     case MEM:
296       return mode != HImode && mode != QImode && general_operand (op, mode);
297
298     case CONST_DOUBLE:
299       return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
300
301     case CONST_INT:
302       return mode == QImode || mode == HImode || add_operand (op, mode);
303     }
304
305   return 0;
306 }
307
308 /* Return 1 if OP is a SYMBOL_REF for a function known to be in this
309    file.  */
310
311 int
312 current_file_function_operand (op, mode)
313      rtx op;
314      enum machine_mode mode;
315 {
316   return (GET_CODE (op) == SYMBOL_REF
317           && (SYMBOL_REF_FLAG (op)
318               || op == XEXP (DECL_RTL (current_function_decl), 0)));
319 }
320
321 /* Return 1 if OP is a valid Alpha comparison operator.  Here we know which
322    comparisons are valid in which insn.  */
323
324 int
325 alpha_comparison_operator (op, mode)
326      register rtx op;
327      enum machine_mode mode;
328 {
329   enum rtx_code code = GET_CODE (op);
330
331   if (mode != GET_MODE (op) || GET_RTX_CLASS (code) != '<')
332     return 0;
333
334   return (code == EQ || code == LE || code == LT
335           || (mode == DImode && (code == LEU || code == LTU)));
336 }
337
338 /* Return 1 if OP is a signed comparison operation.  */
339
340 int
341 signed_comparison_operator (op, mode)
342      register rtx op;
343      enum machine_mode mode;
344 {
345   switch (GET_CODE (op))
346     {
347     case EQ:  case NE:  case LE:  case LT:  case GE:   case GT:
348       return 1;
349     }
350
351   return 0;
352 }
353
354 /* Return 1 if this is a divide or modulus operator.  */
355
356 int
357 divmod_operator (op, mode)
358      register rtx op;
359      enum machine_mode mode;
360 {
361   switch (GET_CODE (op))
362     {
363     case DIV:  case MOD:  case UDIV:  case UMOD:
364       return 1;
365     }
366
367   return 0;
368 }
369
370 /* Return 1 if this memory address is a known aligned register plus
371    a constant.  It must be a valid address.  This means that we can do
372    this as an aligned reference plus some offset.
373
374    Take into account what reload will do.
375
376    We could say that out-of-range stack slots are alignable, but that would
377    complicate get_aligned_mem and it isn't worth the trouble since few
378    functions have large stack space.  */
379
380 int
381 aligned_memory_operand (op, mode)
382      register rtx op;
383      enum machine_mode mode;
384 {
385   if (GET_CODE (op) == SUBREG)
386     {
387       if (GET_MODE (op) != mode)
388         return 0;
389       op = SUBREG_REG (op);
390       mode = GET_MODE (op);
391     }
392
393   if (reload_in_progress && GET_CODE (op) == REG
394       && REGNO (op) >= FIRST_PSEUDO_REGISTER)
395     op = reg_equiv_mem[REGNO (op)];
396
397   if (GET_CODE (op) != MEM || GET_MODE (op) != mode
398       || ! memory_address_p (mode, XEXP (op, 0)))
399     return 0;
400
401   op = XEXP (op, 0);
402
403   if (GET_CODE (op) == PLUS)
404     op = XEXP (op, 0);
405
406   return (GET_CODE (op) == REG
407           && (REGNO (op) == STACK_POINTER_REGNUM || op == frame_pointer_rtx
408               || (REGNO (op) >= FIRST_VIRTUAL_REGISTER
409                   && REGNO (op) <= LAST_VIRTUAL_REGISTER)));
410 }
411
412 /* Similar, but return 1 if OP is a MEM which is not alignable.  */
413
414 int
415 unaligned_memory_operand (op, mode)
416      register rtx op;
417      enum machine_mode mode;
418 {
419   if (GET_CODE (op) == SUBREG)
420     {
421       if (GET_MODE (op) != mode)
422         return 0;
423       op = SUBREG_REG (op);
424       mode = GET_MODE (op);
425     }
426
427   if (reload_in_progress && GET_CODE (op) == REG
428       && REGNO (op) >= FIRST_PSEUDO_REGISTER)
429     op = reg_equiv_mem[REGNO (op)];
430
431   if (GET_CODE (op) != MEM || GET_MODE (op) != mode)
432     return 0;
433
434   op = XEXP (op, 0);
435
436   if (! memory_address_p (mode, op))
437     return 1;
438
439   if (GET_CODE (op) == PLUS)
440     op = XEXP (op, 0);
441
442   return (GET_CODE (op) != REG
443           || (REGNO (op) != STACK_POINTER_REGNUM && op != frame_pointer_rtx
444               && (REGNO (op) < FIRST_VIRTUAL_REGISTER
445                   || REGNO (op) > LAST_VIRTUAL_REGISTER)));
446 }
447
448 /* Return 1 if OP is any memory location.  During reload a pseudo matches.  */
449
450 int
451 any_memory_operand (op, mode)
452      register rtx op;
453      enum machine_mode mode;
454 {
455   return (GET_CODE (op) == MEM
456           || (GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == REG)
457           || (reload_in_progress && GET_CODE (op) == REG
458               && REGNO (op) >= FIRST_PSEUDO_REGISTER)
459           || (reload_in_progress && GET_CODE (op) == SUBREG
460               && GET_CODE (SUBREG_REG (op)) == REG
461               && REGNO (SUBREG_REG (op)) >= FIRST_PSEUDO_REGISTER));
462 }
463
464 /* REF is an alignable memory location.  Place an aligned SImode
465    reference into *PALIGNED_MEM and the number of bits to shift into
466    *PBITNUM.  */
467
468 void
469 get_aligned_mem (ref, paligned_mem, pbitnum)
470      rtx ref;
471      rtx *paligned_mem, *pbitnum;
472 {
473   rtx base;
474   HOST_WIDE_INT offset = 0;
475
476   if (GET_CODE (ref) == SUBREG)
477     {
478       offset = SUBREG_WORD (ref) * UNITS_PER_WORD;
479       if (BYTES_BIG_ENDIAN)
480         offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref)))
481                    - MIN (UNITS_PER_WORD,
482                           GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref)))));
483       ref = SUBREG_REG (ref);
484     }
485
486   if (GET_CODE (ref) == REG)
487     ref = reg_equiv_mem[REGNO (ref)];
488
489   if (reload_in_progress)
490     base = find_replacement (&XEXP (ref, 0));
491   else
492     base = XEXP (ref, 0);
493
494   if (GET_CODE (base) == PLUS)
495     offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
496
497   *paligned_mem = gen_rtx (MEM, SImode,
498                            plus_constant (base, offset & ~3));
499   MEM_IN_STRUCT_P (*paligned_mem) = MEM_IN_STRUCT_P (ref);
500   MEM_VOLATILE_P (*paligned_mem) = MEM_VOLATILE_P (ref);
501   RTX_UNCHANGING_P (*paligned_mem) = RTX_UNCHANGING_P (ref);
502
503   *pbitnum = GEN_INT ((offset & 3) * 8);
504 }
505
506 /* Similar, but just get the address.  Handle the two reload cases.  */
507
508 rtx
509 get_unaligned_address (ref)
510      rtx ref;
511 {
512   rtx base;
513   HOST_WIDE_INT offset = 0;
514
515   if (GET_CODE (ref) == SUBREG)
516     {
517       offset = SUBREG_WORD (ref) * UNITS_PER_WORD;
518       if (BYTES_BIG_ENDIAN)
519         offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref)))
520                    - MIN (UNITS_PER_WORD,
521                           GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref)))));
522       ref = SUBREG_REG (ref);
523     }
524
525   if (GET_CODE (ref) == REG)
526     ref = reg_equiv_mem[REGNO (ref)];
527
528   if (reload_in_progress)
529     base = find_replacement (&XEXP (ref, 0));
530   else
531     base = XEXP (ref, 0);
532
533   if (GET_CODE (base) == PLUS)
534     offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
535
536   return plus_constant (base, offset);
537 }
538 \f
539 /* Subfunction of the following function.  Update the flags of any MEM
540    found in part of X.  */
541
542 static void
543 alpha_set_memflags_1 (x, in_struct_p, volatile_p, unchanging_p)
544      rtx x;
545      int in_struct_p, volatile_p, unchanging_p;
546 {
547   int i;
548
549   switch (GET_CODE (x))
550     {
551     case SEQUENCE:
552     case PARALLEL:
553       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
554         alpha_set_memflags_1 (XVECEXP (x, 0, i), in_struct_p, volatile_p,
555                               unchanging_p);
556       break;
557
558     case INSN:
559       alpha_set_memflags_1 (PATTERN (x), in_struct_p, volatile_p,
560                             unchanging_p);
561       break;
562
563     case SET:
564       alpha_set_memflags_1 (SET_DEST (x), in_struct_p, volatile_p,
565                             unchanging_p);
566       alpha_set_memflags_1 (SET_SRC (x), in_struct_p, volatile_p,
567                             unchanging_p);
568       break;
569
570     case MEM:
571       MEM_IN_STRUCT_P (x) = in_struct_p;
572       MEM_VOLATILE_P (x) = volatile_p;
573       RTX_UNCHANGING_P (x) = unchanging_p;
574       break;
575     }
576 }
577
578 /* Given INSN, which is either an INSN or a SEQUENCE generated to
579    perform a memory operation, look for any MEMs in either a SET_DEST or
580    a SET_SRC and copy the in-struct, unchanging, and volatile flags from
581    REF into each of the MEMs found.  If REF is not a MEM, don't do
582    anything.  */
583
584 void
585 alpha_set_memflags (insn, ref)
586      rtx insn;
587      rtx ref;
588 {
589   /* Note that it is always safe to get these flags, though they won't
590      be what we think if REF is not a MEM.  */
591   int in_struct_p = MEM_IN_STRUCT_P (ref);
592   int volatile_p = MEM_VOLATILE_P (ref);
593   int unchanging_p = RTX_UNCHANGING_P (ref);
594
595   if (GET_CODE (ref) != MEM
596       || (! in_struct_p && ! volatile_p && ! unchanging_p))
597     return;
598
599   alpha_set_memflags_1 (insn, in_struct_p, volatile_p, unchanging_p);
600 }
601 \f
602 /* Try to output insns to set TARGET equal to the constant C if it can be
603    done in less than N insns.  Returns 1 if it can be done and the
604    insns have been emitted.  If it would take more than N insns, zero is
605    returned and no insns and emitted.  */
606
607 int
608 alpha_emit_set_const (target, c, n)
609      rtx target;
610      HOST_WIDE_INT c;
611      int n;
612 {
613   HOST_WIDE_INT new = c;
614   int i, bits;
615
616 #if HOST_BITS_PER_WIDE_INT == 64
617   /* We are only called for SImode and DImode.  If this is SImode, ensure that
618      we are sign extended to a full word.  This does not make any sense when
619      cross-compiling on a narrow machine.  */
620
621   if (GET_MODE (target) == SImode)
622     c = (c & 0xffffffff) - 2 * (c & 0x80000000);
623 #endif
624
625   /* If this is a sign-extended 32-bit constant, we can do this in at most
626      three insns, so do it if we have enough insns left.  We always have
627      a sign-extended 32-bit constant when compiling on a narrow machine.  */
628
629   if (HOST_BITS_PER_WIDE_INT != 64
630       || c >> 31 == -1 || c >> 31 == 0)
631     {
632       HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000);
633       HOST_WIDE_INT tmp1 = c - low;
634       HOST_WIDE_INT high
635         = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
636       HOST_WIDE_INT extra = 0;
637
638       /* If HIGH will be interpreted as negative but the constant is
639          positive, we must adjust it to do two ldha insns.  */
640
641       if ((high & 0x8000) != 0 && c >= 0)
642         {
643           extra = 0x4000;
644           tmp1 -= 0x40000000;
645           high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
646         }
647
648       if (c == low || (low == 0 && extra == 0))
649         {
650           emit_move_insn (target, GEN_INT (c));
651           return 1;
652         }
653       else if (n >= 2 + (extra != 0))
654         {
655           emit_move_insn (target, GEN_INT (low));
656           if (extra != 0)
657             emit_insn (gen_add2_insn (target, GEN_INT (extra << 16)));
658
659           emit_insn (gen_add2_insn (target, GEN_INT (high << 16)));
660           return 1;
661         }
662     }
663
664   /* If we couldn't do it that way, try some other methods (that depend on
665      being able to compute in the target's word size).  But if we have no
666      instructions left, don't bother.  Also, don't even try if this is 
667      SImode (in which case we should have already done something, but
668      do a sanity check here).  */
669
670   if (n == 1 || HOST_BITS_PER_WIDE_INT < 64 || GET_MODE (target) != DImode)
671     return 0;
672
673   /* First, see if can load a value into the target that is the same as the
674      constant except that all bytes that are 0 are changed to be 0xff.  If we
675      can, then we can do a ZAPNOT to obtain the desired constant.  */
676
677   for (i = 0; i < 64; i += 8)
678     if ((new & ((HOST_WIDE_INT) 0xff << i)) == 0)
679       new |= (HOST_WIDE_INT) 0xff << i;
680
681   if (alpha_emit_set_const (target, new, n - 1))
682     {
683       emit_insn (gen_anddi3 (target, target, GEN_INT (c | ~ new)));
684       return 1;
685     }
686
687   /* Find, see if we can load a related constant and then shift and possibly
688      negate it to get the constant we want.  Try this once each increasing
689      numbers of insns.  */
690
691   for (i = 1; i < n; i++)
692     {
693       /* First try complementing.  */
694       if (alpha_emit_set_const (target, ~ c, i))
695         {
696           emit_insn (gen_one_cmpldi2 (target, target));
697           return 1;
698         }
699
700       /* First try to form a constant and do a left shift.  We can do this
701          if some low-order bits are zero; the exact_log2 call below tells
702          us that information.  The bits we are shifting out could be any
703          value, but here we'll just try the 0- and sign-extended forms of
704          the constant.  To try to increase the chance of having the same
705          constant in more than one insn, start at the highest number of
706          bits to shift, but try all possibilities in case a ZAPNOT will
707          be useful.  */
708
709       if ((bits = exact_log2 (c & - c)) > 0)
710         for (; bits > 0; bits--)
711           if (alpha_emit_set_const (target, c >> bits, i)
712               || alpha_emit_set_const (target,
713                                        ((unsigned HOST_WIDE_INT) c) >> bits,
714                                        i))
715             {
716               emit_insn (gen_ashldi3 (target, target, GEN_INT (bits)));
717               return 1;
718             }
719
720       /* Now try high-order zero bits.  Here we try the shifted-in bits as
721          all zero and all ones.  */
722
723       if ((bits = HOST_BITS_PER_WIDE_INT - floor_log2 (c) - 1) > 0)
724         for (; bits > 0; bits--)
725           if (alpha_emit_set_const (target, c << bits, i)
726               || alpha_emit_set_const (target,
727                                        ((c << bits)
728                                         | (((HOST_WIDE_INT) 1 << bits) - 1)),
729                                        i))
730             {
731               emit_insn (gen_lshrdi3 (target, target, GEN_INT (bits)));
732               return 1;
733             }
734
735       /* Now try high-order 1 bits.  We get that with a sign-extension.
736          But one bit isn't enough here.  */
737       
738       if ((bits = HOST_BITS_PER_WIDE_INT - floor_log2 (~ c) - 2) > 0)
739         for (; bits > 0; bits--)
740           if (alpha_emit_set_const (target, c << bits, i)
741               || alpha_emit_set_const (target,
742                                        ((c << bits)
743                                         | (((HOST_WIDE_INT) 1 << bits) - 1)),
744                                        i))
745             {
746               emit_insn (gen_ashrdi3 (target, target, GEN_INT (bits)));
747               return 1;
748             }
749     }
750
751   return 0;
752 }
753 \f
754 /* Adjust the cost of a scheduling dependency.  Return the new cost of
755    a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
756
757 int
758 alpha_adjust_cost (insn, link, dep_insn, cost)
759      rtx insn;
760      rtx link;
761      rtx dep_insn;
762      int cost;
763 {
764   rtx set;
765
766   /* If the dependence is an anti-dependence, there is no cost.  For an
767      output dependence, there is sometimes a cost, but it doesn't seem
768      worth handling those few cases.  */
769
770   if (REG_NOTE_KIND (link) != 0)
771     return 0;
772
773   /* If INSN is a store insn and DEP_INSN is setting the data being stored,
774      we can sometimes lower the cost.  */
775
776   if (recog_memoized (insn) >= 0 && get_attr_type (insn) == TYPE_ST
777       && (set = single_set (dep_insn)) != 0
778       && GET_CODE (PATTERN (insn)) == SET
779       && rtx_equal_p (SET_DEST (set), SET_SRC (PATTERN (insn))))
780     switch (get_attr_type (dep_insn))
781       {
782       case TYPE_LD:
783         /* No savings here.  */
784         return cost;
785
786       case TYPE_IMULL:
787       case TYPE_IMULQ:
788         /* In these cases, we save one cycle.  */
789         return cost - 2;
790
791       default:
792         /* In all other cases, we save two cycles.  */
793         return MAX (0, cost - 4);
794       }
795
796   /* Another case that needs adjustment is an arithmetic or logical
797      operation.  It's cost is usually one cycle, but we default it to
798      two in the MD file.  The only case that it is actually two is
799      for the address in loads and stores.  */
800
801   if (recog_memoized (dep_insn) >= 0
802       && get_attr_type (dep_insn) == TYPE_IADDLOG)
803     switch (get_attr_type (insn))
804       {
805       case TYPE_LD:
806       case TYPE_ST:
807         return cost;
808
809       default:
810         return 2;
811       }
812
813   /* The final case is when a compare feeds into an integer branch.  The cost
814      is only one cycle in that case.  */
815
816   if (recog_memoized (dep_insn) >= 0
817       && get_attr_type (dep_insn) == TYPE_ICMP
818       && recog_memoized (insn) >= 0
819       && get_attr_type (insn) == TYPE_IBR)
820     return 2;
821
822   /* Otherwise, return the default cost. */
823
824   return cost;
825 }
826 \f
827 /* Print an operand.  Recognize special options, documented below.  */
828
829 void
830 print_operand (file, x, code)
831     FILE *file;
832     rtx x;
833     char code;
834 {
835   int i;
836
837   switch (code)
838     {
839     case 'r':
840       /* If this operand is the constant zero, write it as "$31".  */
841       if (GET_CODE (x) == REG)
842         fprintf (file, "%s", reg_names[REGNO (x)]);
843       else if (x == CONST0_RTX (GET_MODE (x)))
844         fprintf (file, "$31");
845       else
846         output_operand_lossage ("invalid %%r value");
847
848       break;
849
850     case 'R':
851       /* Similar, but for floating-point.  */
852       if (GET_CODE (x) == REG)
853         fprintf (file, "%s", reg_names[REGNO (x)]);
854       else if (x == CONST0_RTX (GET_MODE (x)))
855         fprintf (file, "$f31");
856       else
857         output_operand_lossage ("invalid %%R value");
858
859       break;
860
861     case 'N':
862       /* Write the 1's complement of a constant.  */
863       if (GET_CODE (x) != CONST_INT)
864         output_operand_lossage ("invalid %%N value");
865
866       fprintf (file, "%ld", ~ INTVAL (x));
867       break;
868
869     case 'P':
870       /* Write 1 << C, for a constant C.  */
871       if (GET_CODE (x) != CONST_INT)
872         output_operand_lossage ("invalid %%P value");
873
874       fprintf (file, "%ld", (HOST_WIDE_INT) 1 << INTVAL (x));
875       break;
876
877     case 'h':
878       /* Write the high-order 16 bits of a constant, sign-extended.  */
879       if (GET_CODE (x) != CONST_INT)
880         output_operand_lossage ("invalid %%h value");
881
882       fprintf (file, "%ld", INTVAL (x) >> 16);
883       break;
884
885     case 'L':
886       /* Write the low-order 16 bits of a constant, sign-extended.  */
887       if (GET_CODE (x) != CONST_INT)
888         output_operand_lossage ("invalid %%L value");
889
890       fprintf (file, "%ld", (INTVAL (x) & 0xffff) - 2 * (INTVAL (x) & 0x8000));
891       break;
892
893     case 'm':
894       /* Write mask for ZAP insn.  */
895       if (GET_CODE (x) == CONST_DOUBLE)
896         {
897           HOST_WIDE_INT mask = 0;
898           HOST_WIDE_INT value;
899
900           value = CONST_DOUBLE_LOW (x);
901           for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
902                i++, value >>= 8)
903             if (value & 0xff)
904               mask |= (1 << i);
905
906           value = CONST_DOUBLE_HIGH (x);
907           for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
908                i++, value >>= 8)
909             if (value & 0xff)
910               mask |= (1 << (i + sizeof (int)));
911
912           fprintf (file, "%ld", mask & 0xff);
913         }
914
915       else if (GET_CODE (x) == CONST_INT)
916         {
917           HOST_WIDE_INT mask = 0, value = INTVAL (x);
918
919           for (i = 0; i < 8; i++, value >>= 8)
920             if (value & 0xff)
921               mask |= (1 << i);
922
923           fprintf (file, "%ld", mask);
924         }
925       else
926         output_operand_lossage ("invalid %%m value");
927       break;
928
929     case 'M':
930       /* 'b', 'w', or 'l' as the value of the constant.  */
931       if (GET_CODE (x) != CONST_INT
932           || (INTVAL (x) != 8 && INTVAL (x) != 16 && INTVAL (x) != 32))
933         output_operand_lossage ("invalid %%M value");
934
935       fprintf (file, "%s",
936                INTVAL (x) == 8 ? "b" : INTVAL (x) == 16 ? "w" : "l");
937       break;
938
939     case 'U':
940       /* Similar, except do it from the mask.  */
941       if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xff)
942         fprintf (file, "b");
943       else if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xffff)
944         fprintf (file, "w");
945 #if HOST_BITS_PER_WIDE_INT == 32
946       else if (GET_CODE (x) == CONST_DOUBLE
947                && CONST_DOUBLE_HIGH (x) == 0
948                && CONST_DOUBLE_LOW (x) == -1)
949         fprintf (file, "l");
950 #else
951       else if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xffffffff)
952         fprintf (file, "l");
953 #endif
954       else
955         output_operand_lossage ("invalid %%U value");
956       break;
957
958     case 's':
959       /* Write the constant value divided by 8.  */
960       if (GET_CODE (x) != CONST_INT
961           && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
962           && (INTVAL (x) & 7) != 8)
963         output_operand_lossage ("invalid %%s value");
964
965       fprintf (file, "%ld", INTVAL (x) / 8);
966       break;
967
968     case 'S':
969       /* Same, except compute (64 - c) / 8 */
970
971       if (GET_CODE (x) != CONST_INT
972           && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
973           && (INTVAL (x) & 7) != 8)
974         output_operand_lossage ("invalid %%s value");
975
976       fprintf (file, "%ld", (64 - INTVAL (x)) / 8);
977       break;
978
979     case 'C':
980       /* Write out comparison name.  */
981       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
982         output_operand_lossage ("invalid %%C value");
983
984       if (GET_CODE (x) == LEU)
985         fprintf (file, "ule");
986       else if (GET_CODE (x) == LTU)
987         fprintf (file, "ult");
988       else
989         fprintf (file, "%s", GET_RTX_NAME (GET_CODE (x)));
990       break;
991
992     case 'D':
993       /* Similar, but write reversed code.  We can't get an unsigned code
994          here.  */
995       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
996         output_operand_lossage ("invalid %%D value");
997
998       fprintf (file, "%s", GET_RTX_NAME (reverse_condition (GET_CODE (x))));
999       break;
1000
1001     case 'E':
1002       /* Write the divide or modulus operator.  */
1003       switch (GET_CODE (x))
1004         {
1005         case DIV:
1006           fprintf (file, "div%s", GET_MODE (x) == SImode ? "l" : "q");
1007           break;
1008         case UDIV:
1009           fprintf (file, "div%su", GET_MODE (x) == SImode ? "l" : "q");
1010           break;
1011         case MOD:
1012           fprintf (file, "rem%s", GET_MODE (x) == SImode ? "l" : "q");
1013           break;
1014         case UMOD:
1015           fprintf (file, "rem%su", GET_MODE (x) == SImode ? "l" : "q");
1016           break;
1017         default:
1018           output_operand_lossage ("invalid %%E value");
1019           break;
1020         }
1021       break;
1022
1023     case 'A':
1024       /* Write "_u" for unaligned access.  */
1025       if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
1026         fprintf (file, "_u");
1027       break;
1028
1029     case 0:
1030       if (GET_CODE (x) == REG)
1031         fprintf (file, "%s", reg_names[REGNO (x)]);
1032       else if (GET_CODE (x) == MEM)
1033         output_address (XEXP (x, 0));
1034       else
1035         output_addr_const (file, x);
1036       break;
1037
1038     default:
1039       output_operand_lossage ("invalid %%xn code");
1040     }
1041 }
1042 \f
1043 /* Do what is necessary for `va_start'.  The argument is ignored;
1044    We look at the current function to determine if stdarg or varargs
1045    is used and fill in an initial va_list.  A pointer to this constructor
1046    is returned.  */
1047
1048 struct rtx_def *
1049 alpha_builtin_saveregs (arglist)
1050      tree arglist;
1051 {
1052   rtx block, addr, argsize;
1053   tree fntype = TREE_TYPE (current_function_decl);
1054   int stdarg = (TYPE_ARG_TYPES (fntype) != 0
1055                 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
1056                     != void_type_node));
1057
1058   /* Compute the current position into the args, taking into account
1059      both registers and memory.  Both of these are already included in
1060      current_function_args_info.  */
1061
1062   argsize = GEN_INT (current_function_args_info * UNITS_PER_WORD);
1063
1064   /* SETUP_INCOMING_VARARGS moves the starting address base up by 48,
1065      storing fp arg registers in the first 48 bytes, and the integer arg
1066      registers in the next 48 bytes.  This is only done, however, if any
1067      integer registers need to be stored.
1068
1069      If no integer registers need be stored, then we must subtract 48 in
1070      order to account for the integer arg registers which are counted in
1071      argsize above, but which are not actually stored on the stack.  */
1072
1073   addr = (current_function_args_info < 6
1074           ? plus_constant (virtual_incoming_args_rtx, 6 * UNITS_PER_WORD)
1075           : plus_constant (virtual_incoming_args_rtx, - (6 * UNITS_PER_WORD)));
1076
1077   /* Allocate the va_list constructor */
1078   block = assign_stack_local (BLKmode, 2 * UNITS_PER_WORD, BITS_PER_WORD);
1079   RTX_UNCHANGING_P (block) = 1;
1080   RTX_UNCHANGING_P (XEXP (block, 0)) = 1;
1081
1082   /* Store the address of the first integer register in the
1083      __va_base member.  */
1084   emit_move_insn (change_address (block, Pmode, XEXP (block, 0)),
1085                   force_operand (addr, NULL_RTX));
1086
1087   /* Store the argsize as the __va_offset member.  */
1088   emit_move_insn (change_address (block, Pmode,
1089                                   plus_constant (XEXP (block, 0),
1090                                                  UNITS_PER_WORD)),
1091                   force_operand (argsize, NULL_RTX));
1092
1093   /* Return the address of the va_list constructor, but don't put it in a
1094      register.  Doing so would fail when not optimizing and produce worse
1095      code when optimizing.  */
1096   return XEXP (block, 0);
1097 }
1098 \f
1099 /* This page contains routines that are used to determine what the function
1100    prologue and epilogue code will do and write them out.  */
1101
1102 /* Compute the size of the save area in the stack.  */
1103
1104 int
1105 alpha_sa_size ()
1106 {
1107   int size = 0;
1108   int i;
1109
1110   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1111     if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i])
1112       size++;
1113
1114   /* If some registers were saved but not reg 26, reg 26 must also
1115      be saved, so leave space for it.  */
1116   if (size != 0 && ! regs_ever_live[26])
1117     size++;
1118
1119   return size * 8;
1120 }
1121
1122 /* Return 1 if this function can directly return via $26.  */
1123
1124 int
1125 direct_return ()
1126 {
1127   return (reload_completed && alpha_sa_size () == 0
1128           && get_frame_size () == 0
1129           && current_function_pretend_args_size == 0);
1130 }
1131
1132 /* Write a version stamp.  Don't write anything if we are running as a
1133    cross-compiler.  Otherwise, use the versions in /usr/include/stamp.h.  */
1134
1135 #ifndef CROSS_COMPILE
1136 #include <stamp.h>
1137 #endif
1138
1139 void
1140 alpha_write_verstamp (file)
1141      FILE *file;
1142 {
1143 #ifdef MS_STAMP
1144   char *p;
1145
1146   fprintf (file, "\t.verstamp %d %d ", MS_STAMP, LS_STAMP);
1147   for (p = version_string; *p != ' ' && *p != 0; p++)
1148     fprintf (file, "%c", *p == '.' ? ' ' : *p);
1149   fprintf (file, "\n");
1150 #endif
1151 }
1152 \f
1153 /* Write code to add constant C to register number IN_REG (possibly 31)
1154    and put the result into OUT_REG.  Write the code to FILE.  */
1155
1156 static void
1157 add_long_const (file, c, in_reg, out_reg)
1158      HOST_WIDE_INT c;
1159      int in_reg, out_reg;
1160      FILE *file;
1161 {
1162   HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000);
1163   HOST_WIDE_INT tmp1 = c - low;
1164   HOST_WIDE_INT high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
1165   HOST_WIDE_INT extra = 0;
1166
1167   /* We don't have code to write out constants larger than 32 bits.  */
1168 #if HOST_BITS_PER_LONG_INT == 64
1169   if ((unsigned HOST_WIDE_INT) c >> 32 != 0)
1170     abort ();
1171 #endif
1172
1173   /* If HIGH will be interpreted as negative, we must adjust it to do two
1174      ldha insns.  Note that we will never be building a negative constant
1175      here.  */
1176
1177   if (high & 0x8000)
1178     {
1179       extra = 0x4000;
1180       tmp1 -= 0x40000000;
1181       high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
1182     }
1183
1184   if (low != 0)
1185     {
1186       if (low >= 0 && low < 255)
1187         fprintf (file, "\taddq $%d,%d,$%d\n", in_reg, low, out_reg);
1188       else
1189         fprintf (file, "\tlda $%d,%d($%d)\n", out_reg, low, in_reg);
1190       in_reg = out_reg;
1191     }
1192
1193   if (extra)
1194     {
1195       fprintf (file, "\tldah $%d,%d($%d)\n", out_reg, extra, in_reg);
1196       in_reg = out_reg;
1197     }
1198
1199   if (high)
1200     fprintf (file, "\tldah $%d,%d($%d)\n", out_reg, high, in_reg);
1201 }
1202
1203 /* Write function prologue.  */
1204
1205 void
1206 output_prolog (file, size)
1207      FILE *file;
1208      int size;
1209 {
1210   HOST_WIDE_INT vars_size = (size + 7) & ~7;
1211   HOST_WIDE_INT frame_size = ((vars_size + current_function_outgoing_args_size
1212                                + current_function_pretend_args_size
1213                                + alpha_sa_size () + 15) & ~15);
1214   HOST_WIDE_INT reg_offset = vars_size + current_function_outgoing_args_size;
1215   HOST_WIDE_INT start_reg_offset = reg_offset;
1216   HOST_WIDE_INT actual_start_reg_offset = start_reg_offset;
1217   int int_reg_save_area_size = 0;
1218   rtx insn;
1219   int reg_offset_base_reg = 30;
1220   unsigned reg_mask = 0;
1221   int i;
1222
1223   /* Ecoff can handle multiple .file directives, put out file and lineno.
1224      We have to do that before the .ent directive as we cannot switch
1225      files within procedures with native ecoff because line numbers are
1226      linked to procedure descriptors.
1227      Outputting the lineno helps debugging of one line functions as they
1228      would otherwise get no line number at all. Please note that we would
1229      like to put out last_linenum from final.c, but it is not accesible.  */
1230
1231   if (write_symbols == SDB_DEBUG)
1232     {
1233       ASM_OUTPUT_SOURCE_FILENAME (file,
1234                                   DECL_SOURCE_FILE (current_function_decl));
1235       if (debug_info_level != DINFO_LEVEL_TERSE)
1236         ASM_OUTPUT_SOURCE_LINE (file, DECL_SOURCE_LINE (current_function_decl));
1237     }
1238
1239   /* The assembly language programmer's guide states that the second argument
1240      to the .ent directive, the lex_level, is ignored by the assembler,
1241      so we might as well omit it.  */
1242      
1243   fprintf (file, "\t.ent ");
1244   assemble_name (file, alpha_function_name);
1245   fprintf (file, "\n");
1246   ASM_OUTPUT_LABEL (file, alpha_function_name);
1247   inside_function = TRUE;
1248
1249   /* Set up offsets to alpha virtual arg/local debugging pointer.  */
1250
1251   alpha_auto_offset = -frame_size + current_function_pretend_args_size;
1252   alpha_arg_offset = -frame_size + 48;
1253
1254   /* If we need a GP (we have a LDSYM insn or a CALL_INSN), load it first. 
1255      Even if we are a static function, we still need to do this in case
1256      our address is taken and passed to something like qsort.  */
1257
1258   alpha_function_needs_gp = 0;
1259   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
1260     if ((GET_CODE (insn) == CALL_INSN)
1261         || (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
1262             && GET_CODE (PATTERN (insn)) != USE
1263             && GET_CODE (PATTERN (insn)) != CLOBBER
1264             && (get_attr_type (insn) == TYPE_LDSYM
1265                 || get_attr_type (insn) == TYPE_ISUBR)))
1266       {
1267         alpha_function_needs_gp = 1;
1268         break;
1269       }
1270
1271   if (alpha_function_needs_gp)
1272     fprintf (file, "\tldgp $29,0($27)\n");
1273
1274   /* Put a label after the GP load so we can enter the function at it.  */
1275   assemble_name (file, alpha_function_name);
1276   fprintf (file, "..ng:\n");
1277
1278   /* Adjust the stack by the frame size.  If the frame size is > 4096
1279      bytes, we need to be sure we probe somewhere in the first and last
1280      4096 bytes (we can probably get away without the latter test) and
1281      every 8192 bytes in between.  If the frame size is > 32768, we
1282      do this in a loop.  Otherwise, we generate the explicit probe
1283      instructions. 
1284
1285      Note that we are only allowed to adjust sp once in the prologue.  */
1286
1287   if (frame_size < 32768)
1288     {
1289       if (frame_size > 4096)
1290         {
1291           int probed = 4096;
1292           int regnum = 2;
1293
1294           fprintf (file, "\tldq $%d,-%d($30)\n", regnum++, probed);
1295
1296           while (probed + 8192 < frame_size)
1297             fprintf (file, "\tldq $%d,-%d($30)\n", regnum++, probed += 8192);
1298
1299           if (probed + 4096 < frame_size)
1300             fprintf (file, "\tldq $%d,-%d($30)\n", regnum++, probed += 4096);
1301
1302           if (regnum > 9)
1303             abort ();
1304         }
1305
1306       if (frame_size != 0)
1307         fprintf (file, "\tlda $30,-%d($30)\n", frame_size);
1308     }
1309   else
1310     {
1311       /* Here we generate code to set R4 to SP + 4096 and set R5 to the
1312          number of 8192 byte blocks to probe.  We then probe each block
1313          in the loop and then set SP to the proper location.  If the
1314          amount remaining is > 4096, we have to do one more probe.  */
1315
1316       HOST_WIDE_INT blocks = (frame_size + 4096) / 8192;
1317       HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192;
1318
1319       add_long_const (file, blocks, 31, 5);
1320
1321       fprintf (file, "\tlda $4,4096($30)\n");
1322
1323       assemble_name (file, alpha_function_name);
1324       fprintf (file, "..sc:\n");
1325
1326       fprintf (file, "\tldq $6,-8192($4)\n");
1327       fprintf (file, "\tsubq $5,1,$5\n");
1328       fprintf (file, "\tlda $4,-8192($4)\n");
1329
1330       fprintf (file, "\tbne $5,");
1331       assemble_name (file, alpha_function_name);
1332       fprintf (file, "..sc\n");
1333
1334       fprintf (file, "\tlda $30,-%d($4)\n", leftover);
1335
1336       if (leftover > 4096)
1337         fprintf (file, "\tldq $2,%d($30)\n", leftover - 4096);
1338     }
1339
1340   /* Describe our frame.  */
1341   fprintf (file, "\t.frame $%d,%d,$26,%d\n", 
1342            frame_pointer_needed ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM,
1343            frame_size, current_function_pretend_args_size);
1344     
1345   /* If reg_offset is "close enough" to 2**15 that one of the offsets would
1346      overflow a store instruction, compute the base of the register save
1347      area into $28.  */
1348   if (reg_offset >= 32768 - alpha_sa_size () && alpha_sa_size () != 0)
1349     {
1350       add_long_const (file, reg_offset, 30, 28);
1351       reg_offset_base_reg = 28;
1352       reg_offset = start_reg_offset = 0;
1353     }
1354
1355   /* Save register 26 if it is used or if any other register needs to
1356      be saved.  */
1357   if (regs_ever_live[26] || alpha_sa_size () != 0)
1358     {
1359       reg_mask |= 1 << 26;
1360       fprintf (file, "\tstq $26,%d($%d)\n", reg_offset, reg_offset_base_reg);
1361       reg_offset += 8;
1362       int_reg_save_area_size += 8;
1363     }
1364
1365   /* Now save any other used integer registers required to be saved.  */
1366   for (i = 0; i < 32; i++)
1367     if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i] && i != 26)
1368       {
1369         reg_mask |= 1 << i;
1370         fprintf (file, "\tstq $%d,%d($%d)\n",
1371                  i, reg_offset, reg_offset_base_reg);
1372         reg_offset += 8;
1373         int_reg_save_area_size += 8;
1374       }
1375
1376   /* Print the register mask and do floating-point saves.  */
1377   if (reg_mask)
1378     fprintf (file, "\t.mask 0x%x,%d\n", reg_mask,
1379              actual_start_reg_offset - frame_size);
1380
1381   start_reg_offset = reg_offset;
1382   reg_mask = 0;
1383
1384   for (i = 0; i < 32; i++)
1385     if (! fixed_regs[i + 32] && ! call_used_regs[i + 32]
1386         && regs_ever_live[i + 32])
1387       {
1388         reg_mask |= 1 << i;
1389         fprintf (file, "\tstt $f%d,%d($%d)\n",
1390                  i, reg_offset, reg_offset_base_reg);
1391         reg_offset += 8;
1392       }
1393
1394   /* Print the floating-point mask, if we've saved any fp register.  */
1395   if (reg_mask)
1396     fprintf (file, "\t.fmask 0x%x,%d\n", reg_mask,
1397              actual_start_reg_offset - frame_size + int_reg_save_area_size);
1398
1399   /* If we need a frame pointer, set it from the stack pointer.  Note that
1400      this must always be the last instruction in the prologue.  */
1401   if (frame_pointer_needed)
1402     fprintf (file, "\tbis $30,$30,$15\n");
1403
1404   /* End the prologue and say if we used gp.  */
1405   fprintf (file, "\t.prologue %d\n", alpha_function_needs_gp);
1406 }
1407
1408 /* Write function epilogue.  */
1409
1410 void
1411 output_epilog (file, size)
1412      FILE *file;
1413      int size;
1414 {
1415   rtx insn = get_last_insn ();
1416   HOST_WIDE_INT vars_size = (size + 7) & ~7;
1417   HOST_WIDE_INT frame_size = ((vars_size + current_function_outgoing_args_size
1418                                + current_function_pretend_args_size
1419                                + alpha_sa_size () + 15) & ~15);
1420   HOST_WIDE_INT reg_offset = vars_size + current_function_outgoing_args_size;
1421   HOST_WIDE_INT frame_size_from_reg_save = frame_size - reg_offset;
1422   int reg_offset_base_reg = 30;
1423   int i;
1424
1425   /* If the last insn was a BARRIER, we don't have to write anything except
1426      the .end pseudo-op.  */
1427   if (GET_CODE (insn) == NOTE)
1428     insn = prev_nonnote_insn (insn);
1429   if (insn == 0 || GET_CODE (insn) != BARRIER)
1430     {
1431       int fp_offset;
1432
1433       /* If we have a frame pointer, restore SP from it.  */
1434       if (frame_pointer_needed)
1435         fprintf (file, "\tbis $15,$15,$30\n");
1436
1437       /* If the register save area is out of range, put its address into
1438          $28.  */
1439       if (reg_offset >= 32768 - alpha_sa_size () && alpha_sa_size () != 0)
1440         {
1441           add_long_const (file, reg_offset, 30, 28);
1442           reg_offset_base_reg = 28;
1443           reg_offset = 0;
1444         }
1445
1446       /* Restore all the registers, starting with the return address
1447          register.  */
1448       if (regs_ever_live[26] || alpha_sa_size () != 0)
1449         {
1450           fprintf (file, "\tldq $26,%d($%d)\n",
1451                    reg_offset, reg_offset_base_reg);
1452           reg_offset += 8;
1453         }
1454
1455       /* Now restore any other used integer registers that that we saved,
1456          except for FP if it is being used as FP, since it must be
1457          restored last.  */
1458
1459       for (i = 0; i < 32; i++)
1460         if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i]
1461             && i != 26)
1462           {
1463             if (i == FRAME_POINTER_REGNUM && frame_pointer_needed)
1464               fp_offset = reg_offset;
1465             else
1466               fprintf (file, "\tldq $%d,%d($%d)\n",
1467                        i, reg_offset, reg_offset_base_reg);
1468             reg_offset += 8;
1469           }
1470
1471       for (i = 0; i < 32; i++)
1472         if (! fixed_regs[i + 32] && ! call_used_regs[i + 32]
1473             && regs_ever_live[i + 32])
1474           {
1475             fprintf (file, "\tldt $f%d,%d($%d)\n",
1476                      i, reg_offset, reg_offset_base_reg);
1477             reg_offset += 8;
1478           }
1479
1480       /* If the stack size is large, compute the size of the stack into
1481          a register because the old FP restore, stack pointer adjust,
1482          and return are required to be consecutive instructions.  
1483          However, if the new stack pointer can be computed by adding the
1484          a constant to the start of the register save area, we can do
1485          it that way.  */
1486       if (frame_size > 32767
1487           && ! (reg_offset_base_reg != 30
1488                 && frame_size_from_reg_save < 32768))
1489         add_long_const (file, frame_size, 31, 1);
1490
1491       /* If we needed a frame pointer and we have to restore it, do it
1492          now.  This must be done in one instruction immediately
1493          before the SP update.  */
1494       if (frame_pointer_needed && regs_ever_live[FRAME_POINTER_REGNUM])
1495         fprintf (file, "\tldq $15,%d($%d)\n", fp_offset, reg_offset_base_reg);
1496
1497       /* Now update the stack pointer, if needed.  This must be done in
1498          one, stylized, instruction.  */
1499       if (frame_size > 32768)
1500         {
1501           if (reg_offset_base_reg != 30
1502               && frame_size_from_reg_save < 32768)
1503             {
1504               if (frame_size_from_reg_save < 255)
1505                 fprintf (file, "\taddq $%d,%d,$30\n",
1506                          reg_offset_base_reg, frame_size_from_reg_save);
1507               else
1508                 fprintf (file, "\tlda %30,%d($%d)\n",
1509                          frame_size_from_reg_save, reg_offset_base_reg);
1510             }
1511           else
1512             fprintf (file, "\taddq $1,$30,$30\n");
1513         }
1514       else if (frame_size != 0)
1515         fprintf (file, "\tlda $30,%d($30)\n", frame_size);
1516
1517       /* Finally return to the caller.  */
1518       fprintf (file, "\tret $31,($26),1\n");
1519     }
1520
1521   /* End the function.  */
1522   fprintf (file, "\t.end ");
1523   assemble_name (file, alpha_function_name);
1524   fprintf (file, "\n");
1525   inside_function = FALSE;
1526
1527   /* Show that we know this function if it is called again.  */
1528   SYMBOL_REF_FLAG (XEXP (DECL_RTL (current_function_decl), 0)) = 1;
1529 }
1530 \f
1531 /* Debugging support.  */
1532
1533 #include "gstab.h"
1534
1535 /* Count the number of sdb related labels are generated (to find block
1536    start and end boundaries).  */
1537
1538 int sdb_label_count = 0;
1539
1540 /* Next label # for each statement.  */
1541
1542 static int sym_lineno = 0;
1543
1544 /* Count the number of .file directives, so that .loc is up to date.  */
1545
1546 static int num_source_filenames = 0;
1547
1548 /* Name of the file containing the current function.  */
1549
1550 static char *current_function_file = "";
1551
1552 /* Offsets to alpha virtual arg/local debugging pointers.  */
1553
1554 long alpha_arg_offset;
1555 long alpha_auto_offset;
1556 \f
1557 /* Emit a new filename to a stream.  */
1558
1559 void
1560 alpha_output_filename (stream, name)
1561      FILE *stream;
1562      char *name;
1563 {
1564   static int first_time = TRUE;
1565   char ltext_label_name[100];
1566
1567   if (first_time)
1568     {
1569       first_time = FALSE;
1570       ++num_source_filenames;
1571       current_function_file = name;
1572       fprintf (stream, "\t.file\t%d ", num_source_filenames);
1573       output_quoted_string (stream, name);
1574       fprintf (stream, "\n");
1575       if (!TARGET_GAS && write_symbols == DBX_DEBUG)
1576         fprintf (stream, "\t#@stabs\n");
1577     }
1578
1579   else if (!TARGET_GAS && write_symbols == DBX_DEBUG)
1580     {
1581       ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
1582       fprintf (stream, "%s ", ASM_STABS_OP);
1583       output_quoted_string (stream, name);
1584       fprintf (stream, ",%d,0,0,%s\n", N_SOL, &ltext_label_name[1]);
1585     }
1586
1587   else if (name != current_function_file
1588       && strcmp (name, current_function_file) != 0)
1589     {
1590       if (inside_function && ! TARGET_GAS)
1591         fprintf (stream, "\t#.file\t%d ", num_source_filenames);
1592       else
1593         {
1594           ++num_source_filenames;
1595           current_function_file = name;
1596           fprintf (stream, "\t.file\t%d ", num_source_filenames);
1597         }
1598
1599       output_quoted_string (stream, name);
1600       fprintf (stream, "\n");
1601     }
1602 }
1603 \f
1604 /* Emit a linenumber to a stream.  */
1605
1606 void
1607 alpha_output_lineno (stream, line)
1608      FILE *stream;
1609      int line;
1610 {
1611   if (! TARGET_GAS && write_symbols == DBX_DEBUG)
1612     {
1613       /* mips-tfile doesn't understand .stabd directives.  */
1614       ++sym_lineno;
1615       fprintf (stream, "$LM%d:\n\t%s %d,0,%d,$LM%d\n",
1616                sym_lineno, ASM_STABN_OP, N_SLINE, line, sym_lineno);
1617     }
1618   else
1619     fprintf (stream, "\n\t.loc\t%d %d\n", num_source_filenames, line);
1620 }