OSDN Git Service

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