OSDN Git Service

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