OSDN Git Service

(vmskrunch): Try to not chop trailing uppercase letters.
[pf3gnuchains/gcc-fork.git] / gcc / config / alpha / alpha.c
1 /* Subroutines used for code generation on the DEC Alpha.
2    Copyright (C) 1992, 93, 94, 95, 96, 1997 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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 #include <stdio.h>
24 #include "config.h"
25 #include "rtl.h"
26 #include "regs.h"
27 #include "hard-reg-set.h"
28 #include "real.h"
29 #include "insn-config.h"
30 #include "conditions.h"
31 #include "insn-flags.h"
32 #include "output.h"
33 #include "insn-attr.h"
34 #include "flags.h"
35 #include "recog.h"
36 #include "reload.h"
37 #include "expr.h"
38 #include "obstack.h"
39 #include "tree.h"
40
41 /* Specify which cpu to schedule for. */
42  enum processor_type alpha_cpu;
43
44 /* Specify how accurate floating-point traps need to be.  */
45
46 enum alpha_trap_precision alpha_tp;
47
48 /* Specify the floating-point rounding mode.  */
49
50 enum alpha_fp_rounding_mode alpha_fprm;
51
52 /* Specify which things cause traps.  */
53
54 enum alpha_fp_trap_mode alpha_fptm;
55
56 /* Strings decoded into the above options.  */
57 char *alpha_cpu_string;         /* -mcpu=ev[4|5] */
58 char *alpha_tp_string;          /* -mtrap-precision=[p|s|i] */
59 char *alpha_fprm_string;        /* -mfp-rounding-mode=[n|m|c|d] */
60 char *alpha_fptm_string;        /* -mfp-trap-mode=[n|u|su|sui] */
61
62 /* Save information from a "cmpxx" operation until the branch or scc is
63    emitted.  */
64
65 rtx alpha_compare_op0, alpha_compare_op1;
66 int alpha_compare_fp_p;
67
68 /* Save the name of the current function as used by the assembler.  This
69    is used by the epilogue.  */
70
71 char *alpha_function_name;
72
73 /* Non-zero if inside of a function, because the Alpha asm can't
74    handle .files inside of functions.  */
75
76 static int inside_function = FALSE;
77
78 /* Non-zero if an instruction that may cause a trap is pending.  */
79
80 static int trap_pending = 0;
81
82 /* Nonzero if the current function needs gp.  */
83
84 int alpha_function_needs_gp;
85
86 extern char *version_string;
87 extern int rtx_equal_function_value_matters;
88
89 /* Declarations of static functions.  */
90 static void alpha_set_memflags_1  PROTO((rtx, int, int, int));
91 static rtx alpha_emit_set_const_1 PROTO((rtx, enum machine_mode,
92                                          HOST_WIDE_INT, int));
93 static void add_long_const      PROTO((FILE *, HOST_WIDE_INT, int, int, int));
94
95 /* Compute the size of the save area in the stack.  */
96 static void alpha_sa_mask       PROTO((unsigned long *imaskP,
97                                        unsigned long *fmaskP));
98 /* Strip type information.  */
99 #define CURRENT_FUNCTION_ARGS_INFO  \
100 (TARGET_OPEN_VMS ? current_function_args_info & 0xff \
101  : current_function_args_info)
102 \f
103 /* Parse target option strings. */
104
105 void
106 override_options ()
107 {
108   alpha_cpu = PROCESSOR_EV4;
109
110   if (alpha_cpu_string)
111     {
112       if (! strcmp (alpha_cpu_string, "ev4")
113           || ! strcmp (alpha_cpu_string, "21064"))
114         alpha_cpu = PROCESSOR_EV4;
115       else if (! strcmp (alpha_cpu_string, "ev5")
116                || ! strcmp (alpha_cpu_string, "21164"))
117         alpha_cpu = PROCESSOR_EV5;
118       else
119         error ("bad value `%s' for -mcpu switch", alpha_cpu_string);
120     }
121
122   alpha_tp = ALPHA_TP_PROG;
123   alpha_fprm = ALPHA_FPRM_NORM;
124   alpha_fptm = ALPHA_FPTM_N;
125
126   if (TARGET_IEEE)
127     {
128       alpha_tp = ALPHA_TP_INSN;
129       alpha_fptm = ALPHA_FPTM_SU;
130     }
131
132   if (TARGET_IEEE_WITH_INEXACT)
133     {
134       alpha_tp = ALPHA_TP_INSN;
135       alpha_fptm = ALPHA_FPTM_SUI;
136     }
137
138   if (alpha_tp_string)
139     {
140       if (! strcmp (alpha_tp_string, "p"))
141         alpha_tp = ALPHA_TP_PROG;
142       else if (! strcmp (alpha_tp_string, "f"))
143         alpha_tp = ALPHA_TP_FUNC;
144       else if (! strcmp (alpha_tp_string, "i"))
145         alpha_tp = ALPHA_TP_INSN;
146       else
147         error ("bad value `%s' for -mtrap-precision switch", alpha_tp_string);
148     }
149
150   if (alpha_fprm_string)
151     {
152       if (! strcmp (alpha_fprm_string, "n"))
153         alpha_fprm = ALPHA_FPRM_NORM;
154       else if (! strcmp (alpha_fprm_string, "m"))
155         alpha_fprm = ALPHA_FPRM_MINF;
156       else if (! strcmp (alpha_fprm_string, "c"))
157         alpha_fprm = ALPHA_FPRM_CHOP;
158       else if (! strcmp (alpha_fprm_string,"d"))
159         alpha_fprm = ALPHA_FPRM_DYN;
160       else
161         error ("bad value `%s' for -mfp-rounding-mode switch",
162                alpha_fprm_string);
163     }
164
165   if (alpha_fptm_string)
166     {
167       if (strcmp (alpha_fptm_string, "n") == 0)
168         alpha_fptm = ALPHA_FPTM_N;
169       else if (strcmp (alpha_fptm_string, "u") == 0)
170         alpha_fptm = ALPHA_FPTM_U;
171       else if (strcmp (alpha_fptm_string, "su") == 0)
172         alpha_fptm = ALPHA_FPTM_SU;
173       else if (strcmp (alpha_fptm_string, "sui") == 0)
174         alpha_fptm = ALPHA_FPTM_SUI;
175       else
176         error ("bad value `%s' for -mfp-trap-mode switch", alpha_fptm_string);
177     }
178
179   /* Do some sanity checks on the above option. */
180
181   if ((alpha_fptm == ALPHA_FPTM_SU || alpha_fptm == ALPHA_FPTM_SUI)
182       && alpha_tp != ALPHA_TP_INSN)
183     {
184       warning ("fp software completion requires -mtrap-precision=i");
185       alpha_tp = ALPHA_TP_INSN;
186     }
187
188   if (TARGET_FLOAT_VAX)
189     {
190       if (alpha_fprm == ALPHA_FPRM_MINF || alpha_fprm == ALPHA_FPRM_DYN)
191         {
192           warning ("rounding mode not supported for VAX floats");
193           alpha_fprm = ALPHA_FPRM_NORM;
194         }
195       if (alpha_fptm == ALPHA_FPTM_SUI)
196         {
197           warning ("trap mode not supported for VAX floats");
198           alpha_fptm = ALPHA_FPTM_SU;
199         }
200     }
201 }
202 \f
203 /* Returns 1 if VALUE is a mask that contains full bytes of zero or ones.  */
204
205 int
206 zap_mask (value)
207      HOST_WIDE_INT value;
208 {
209   int i;
210
211   for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
212        i++, value >>= 8)
213     if ((value & 0xff) != 0 && (value & 0xff) != 0xff)
214       return 0;
215
216   return 1;
217 }
218
219 /* Returns 1 if OP is either the constant zero or a register.  If a
220    register, it must be in the proper mode unless MODE is VOIDmode.  */
221
222 int
223 reg_or_0_operand (op, mode)
224       register rtx op;
225       enum machine_mode mode;
226 {
227   return op == const0_rtx || register_operand (op, mode);
228 }
229
230 /* Return 1 if OP is a constant in the range of 0-63 (for a shift) or
231    any register.  */
232
233 int
234 reg_or_6bit_operand (op, mode)
235      register rtx op;
236      enum machine_mode mode;
237 {
238   return ((GET_CODE (op) == CONST_INT
239            && (unsigned HOST_WIDE_INT) INTVAL (op) < 64)
240           || register_operand (op, mode));
241 }
242
243
244 /* Return 1 if OP is an 8-bit constant or any register.  */
245
246 int
247 reg_or_8bit_operand (op, mode)
248      register rtx op;
249      enum machine_mode mode;
250 {
251   return ((GET_CODE (op) == CONST_INT
252            && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100)
253           || register_operand (op, mode));
254 }
255
256 /* Return 1 if OP is an 8-bit constant.  */
257
258 int
259 cint8_operand (op, mode)
260      register rtx op;
261      enum machine_mode mode;
262 {
263   return (GET_CODE (op) == CONST_INT
264           && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100);
265 }
266
267 /* Return 1 if the operand is a valid second operand to an add insn.  */
268
269 int
270 add_operand (op, mode)
271      register rtx op;
272      enum machine_mode mode;
273 {
274   if (GET_CODE (op) == CONST_INT)
275     return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')
276             || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')
277             || CONST_OK_FOR_LETTER_P (INTVAL (op), 'O'));
278
279   return register_operand (op, mode);
280 }
281
282 /* Return 1 if the operand is a valid second operand to a sign-extending
283    add insn.  */
284
285 int
286 sext_add_operand (op, mode)
287      register rtx op;
288      enum machine_mode mode;
289 {
290   if (GET_CODE (op) == CONST_INT)
291     return ((unsigned HOST_WIDE_INT) INTVAL (op) < 255
292             || (unsigned HOST_WIDE_INT) (- INTVAL (op)) < 255);
293
294   return register_operand (op, mode);
295 }
296
297 /* Return 1 if OP is the constant 4 or 8.  */
298
299 int
300 const48_operand (op, mode)
301      register rtx op;
302      enum machine_mode mode;
303 {
304   return (GET_CODE (op) == CONST_INT
305           && (INTVAL (op) == 4 || INTVAL (op) == 8));
306 }
307
308 /* Return 1 if OP is a valid first operand to an AND insn.  */
309
310 int
311 and_operand (op, mode)
312      register rtx op;
313      enum machine_mode mode;
314 {
315   if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
316     return (zap_mask (CONST_DOUBLE_LOW (op))
317             && zap_mask (CONST_DOUBLE_HIGH (op)));
318
319   if (GET_CODE (op) == CONST_INT)
320     return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
321             || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100
322             || zap_mask (INTVAL (op)));
323
324   return register_operand (op, mode);
325 }
326
327 /* Return 1 if OP is a valid first operand to an IOR or XOR insn.  */
328
329 int
330 or_operand (op, mode)
331      register rtx op;
332      enum machine_mode mode;
333 {
334   if (GET_CODE (op) == CONST_INT)
335     return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
336             || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100);
337
338   return register_operand (op, mode);
339 }
340
341 /* Return 1 if OP is a constant that is the width, in bits, of an integral
342    mode smaller than DImode.  */
343
344 int
345 mode_width_operand (op, mode)
346      register rtx op;
347      enum machine_mode mode;
348 {
349   return (GET_CODE (op) == CONST_INT
350           && (INTVAL (op) == 8 || INTVAL (op) == 16 || INTVAL (op) == 32));
351 }
352
353 /* Return 1 if OP is a constant that is the width of an integral machine mode
354    smaller than an integer.  */
355
356 int
357 mode_mask_operand (op, mode)
358      register rtx op;
359      enum machine_mode mode;
360 {
361 #if HOST_BITS_PER_WIDE_INT == 32
362   if (GET_CODE (op) == CONST_DOUBLE)
363     return CONST_DOUBLE_HIGH (op) == 0 && CONST_DOUBLE_LOW (op) == -1;
364 #endif
365
366   return (GET_CODE (op) == CONST_INT
367           && (INTVAL (op) == 0xff
368               || INTVAL (op) == 0xffff
369 #if HOST_BITS_PER_WIDE_INT == 64
370               || INTVAL (op) == 0xffffffff
371 #endif
372               ));
373 }
374
375 /* Return 1 if OP is a multiple of 8 less than 64.  */
376
377 int
378 mul8_operand (op, mode)
379      register rtx op;
380      enum machine_mode mode;
381 {
382   return (GET_CODE (op) == CONST_INT
383           && (unsigned HOST_WIDE_INT) INTVAL (op) < 64
384           && (INTVAL (op) & 7) == 0);
385 }
386
387 /* Return 1 if OP is the constant zero in floating-point.  */
388
389 int
390 fp0_operand (op, mode)
391      register rtx op;
392      enum machine_mode mode;
393 {
394   return (GET_MODE (op) == mode
395           && GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode));
396 }
397
398 /* Return 1 if OP is the floating-point constant zero or a register.  */
399
400 int
401 reg_or_fp0_operand (op, mode)
402      register rtx op;
403      enum machine_mode mode;
404 {
405   return fp0_operand (op, mode) || register_operand (op, mode);
406 }
407
408 /* Return 1 if OP is a register or a constant integer.  */
409
410
411 int
412 reg_or_cint_operand (op, mode)
413     register rtx op;
414     enum machine_mode mode;
415 {
416      return GET_CODE (op) == CONST_INT || register_operand (op, mode);
417 }
418
419 /* Return 1 if OP is something that can be reloaded into a register;
420    if it is a MEM, it need not be valid.  */
421
422 int
423 some_operand (op, mode)
424      register rtx op;
425      enum machine_mode mode;
426 {
427   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
428     return 0;
429
430   switch (GET_CODE (op))
431     {
432     case REG:  case MEM:  case CONST_DOUBLE:
433     case CONST_INT:  case LABEL_REF:  case SYMBOL_REF:  case CONST:
434       return 1;
435
436     case SUBREG:
437       return some_operand (SUBREG_REG (op), VOIDmode);
438     }
439
440   return 0;
441 }
442
443 /* Return 1 if OP is a valid operand for the source of a move insn.  */
444
445 int
446 input_operand (op, mode)
447      register rtx op;
448      enum machine_mode mode;
449 {
450   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
451     return 0;
452
453   if (GET_MODE_CLASS (mode) == MODE_FLOAT && GET_MODE (op) != mode)
454     return 0;
455
456   switch (GET_CODE (op))
457     {
458     case LABEL_REF:
459     case SYMBOL_REF:
460     case CONST:
461         /* This handles both the Windows/NT and OSF cases.  */
462       return mode == ptr_mode || mode == DImode;
463
464     case REG:
465       return 1;
466
467     case SUBREG:
468       if (register_operand (op, mode))
469         return 1;
470       /* ... fall through ... */
471     case MEM:
472       return (TARGET_BYTE_OPS || (mode != HImode && mode != QImode)
473               && general_operand (op, mode));
474
475     case CONST_DOUBLE:
476       return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
477
478     case CONST_INT:
479       return mode == QImode || mode == HImode || add_operand (op, mode);
480     }
481
482   return 0;
483 }
484
485 /* Return 1 if OP is a SYMBOL_REF for a function known to be in this
486    file.  */
487
488 int
489 current_file_function_operand (op, mode)
490      rtx op;
491      enum machine_mode mode;
492 {
493   return (GET_CODE (op) == SYMBOL_REF
494           && ! profile_flag && ! profile_block_flag
495           && (SYMBOL_REF_FLAG (op)
496               || op == XEXP (DECL_RTL (current_function_decl), 0)));
497 }
498
499 /* Return 1 if OP is a valid operand for the MEM of a CALL insn.  */
500
501 int
502 call_operand (op, mode)
503      rtx op;
504      enum machine_mode mode;
505 {
506   if (mode != Pmode)
507     return 0;
508
509   return (GET_CODE (op) == SYMBOL_REF
510           || (GET_CODE (op) == REG && (TARGET_OPEN_VMS || REGNO (op) == 27)));
511 }
512
513 /* Return 1 if OP is a valid Alpha comparison operator.  Here we know which
514    comparisons are valid in which insn.  */
515
516 int
517 alpha_comparison_operator (op, mode)
518      register rtx op;
519      enum machine_mode mode;
520 {
521   enum rtx_code code = GET_CODE (op);
522
523   if (mode != GET_MODE (op) || GET_RTX_CLASS (code) != '<')
524     return 0;
525
526   return (code == EQ || code == LE || code == LT
527           || (mode == DImode && (code == LEU || code == LTU)));
528 }
529
530 /* Return 1 if OP is a valid Alpha swapped comparison operator.  */
531
532 int
533 alpha_swapped_comparison_operator (op, mode)
534      register rtx op;
535      enum machine_mode mode;
536 {
537   enum rtx_code code = GET_CODE (op);
538
539   if (mode != GET_MODE (op) || GET_RTX_CLASS (code) != '<')
540     return 0;
541
542   code = swap_condition (code);
543   return (code == EQ || code == LE || code == LT
544           || (mode == DImode && (code == LEU || code == LTU)));
545 }
546
547 /* Return 1 if OP is a signed comparison operation.  */
548
549 int
550 signed_comparison_operator (op, mode)
551      register rtx op;
552      enum machine_mode mode;
553 {
554   switch (GET_CODE (op))
555     {
556     case EQ:  case NE:  case LE:  case LT:  case GE:   case GT:
557       return 1;
558     }
559
560   return 0;
561 }
562
563 /* Return 1 if this is a divide or modulus operator.  */
564
565 int
566 divmod_operator (op, mode)
567      register rtx op;
568      enum machine_mode mode;
569 {
570   switch (GET_CODE (op))
571     {
572     case DIV:  case MOD:  case UDIV:  case UMOD:
573       return 1;
574     }
575
576   return 0;
577 }
578
579 /* Return 1 if this memory address is a known aligned register plus
580    a constant.  It must be a valid address.  This means that we can do
581    this as an aligned reference plus some offset.
582
583    Take into account what reload will do.
584
585    We could say that out-of-range stack slots are alignable, but that would
586    complicate get_aligned_mem and it isn't worth the trouble since few
587    functions have large stack space.  */
588
589 int
590 aligned_memory_operand (op, mode)
591      register rtx op;
592      enum machine_mode mode;
593 {
594   if (GET_CODE (op) == SUBREG)
595     {
596       if (GET_MODE (op) != mode)
597         return 0;
598       op = SUBREG_REG (op);
599       mode = GET_MODE (op);
600     }
601
602   if (reload_in_progress && GET_CODE (op) == REG
603       && REGNO (op) >= FIRST_PSEUDO_REGISTER)
604     op = reg_equiv_mem[REGNO (op)];
605
606   if (GET_CODE (op) != MEM || GET_MODE (op) != mode
607       || ! memory_address_p (mode, XEXP (op, 0)))
608     return 0;
609
610   op = XEXP (op, 0);
611
612   if (GET_CODE (op) == PLUS)
613     op = XEXP (op, 0);
614
615   return (GET_CODE (op) == REG
616           && REGNO_POINTER_ALIGN (REGNO (op)) >= 4);
617 }
618
619 /* Similar, but return 1 if OP is a MEM which is not alignable.  */
620
621 int
622 unaligned_memory_operand (op, mode)
623      register rtx op;
624      enum machine_mode mode;
625 {
626   if (GET_CODE (op) == SUBREG)
627     {
628       if (GET_MODE (op) != mode)
629         return 0;
630       op = SUBREG_REG (op);
631       mode = GET_MODE (op);
632     }
633
634   if (reload_in_progress && GET_CODE (op) == REG
635       && REGNO (op) >= FIRST_PSEUDO_REGISTER)
636     op = reg_equiv_mem[REGNO (op)];
637
638   if (GET_CODE (op) != MEM || GET_MODE (op) != mode)
639     return 0;
640
641   op = XEXP (op, 0);
642
643   if (! memory_address_p (mode, op))
644     return 1;
645
646   if (GET_CODE (op) == PLUS)
647     op = XEXP (op, 0);
648
649   return (GET_CODE (op) != REG
650           || REGNO_POINTER_ALIGN (REGNO (op)) < 4);
651 }
652
653 /* Return 1 if OP is either a register or an unaligned memory location.  */
654
655 int
656 reg_or_unaligned_mem_operand (op, mode)
657      rtx op;
658      enum machine_mode mode;
659 {
660   return register_operand (op, mode) || unaligned_memory_operand (op, mode);
661 }
662
663 /* Return 1 if OP is any memory location.  During reload a pseudo matches.  */
664
665 int
666 any_memory_operand (op, mode)
667      register rtx op;
668      enum machine_mode mode;
669 {
670   return (GET_CODE (op) == MEM
671           || (GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == REG)
672           || (reload_in_progress && GET_CODE (op) == REG
673               && REGNO (op) >= FIRST_PSEUDO_REGISTER)
674           || (reload_in_progress && GET_CODE (op) == SUBREG
675               && GET_CODE (SUBREG_REG (op)) == REG
676               && REGNO (SUBREG_REG (op)) >= FIRST_PSEUDO_REGISTER));
677 }
678
679 /* REF is an alignable memory location.  Place an aligned SImode
680    reference into *PALIGNED_MEM and the number of bits to shift into
681    *PBITNUM.  */
682
683 void
684 get_aligned_mem (ref, paligned_mem, pbitnum)
685      rtx ref;
686      rtx *paligned_mem, *pbitnum;
687 {
688   rtx base;
689   HOST_WIDE_INT offset = 0;
690
691   if (GET_CODE (ref) == SUBREG)
692     {
693       offset = SUBREG_WORD (ref) * UNITS_PER_WORD;
694       if (BYTES_BIG_ENDIAN)
695         offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref)))
696                    - MIN (UNITS_PER_WORD,
697                           GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref)))));
698       ref = SUBREG_REG (ref);
699     }
700
701   if (GET_CODE (ref) == REG)
702     ref = reg_equiv_mem[REGNO (ref)];
703
704   if (reload_in_progress)
705     base = find_replacement (&XEXP (ref, 0));
706   else
707     base = XEXP (ref, 0);
708
709   if (GET_CODE (base) == PLUS)
710     offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
711
712   *paligned_mem = gen_rtx (MEM, SImode,
713                            plus_constant (base, offset & ~3));
714   MEM_IN_STRUCT_P (*paligned_mem) = MEM_IN_STRUCT_P (ref);
715   MEM_VOLATILE_P (*paligned_mem) = MEM_VOLATILE_P (ref);
716   RTX_UNCHANGING_P (*paligned_mem) = RTX_UNCHANGING_P (ref);
717
718   *pbitnum = GEN_INT ((offset & 3) * 8);
719 }
720
721 /* Similar, but just get the address.  Handle the two reload cases.  
722    Add EXTRA_OFFSET to the address we return.  */
723
724 rtx
725 get_unaligned_address (ref, extra_offset)
726      rtx ref;
727      int extra_offset;
728 {
729   rtx base;
730   HOST_WIDE_INT offset = 0;
731
732   if (GET_CODE (ref) == SUBREG)
733     {
734       offset = SUBREG_WORD (ref) * UNITS_PER_WORD;
735       if (BYTES_BIG_ENDIAN)
736         offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref)))
737                    - MIN (UNITS_PER_WORD,
738                           GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref)))));
739       ref = SUBREG_REG (ref);
740     }
741
742   if (GET_CODE (ref) == REG)
743     ref = reg_equiv_mem[REGNO (ref)];
744
745   if (reload_in_progress)
746     base = find_replacement (&XEXP (ref, 0));
747   else
748     base = XEXP (ref, 0);
749
750   if (GET_CODE (base) == PLUS)
751     offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
752
753   return plus_constant (base, offset + extra_offset);
754 }
755 \f
756 /* Subfunction of the following function.  Update the flags of any MEM
757    found in part of X.  */
758
759 static void
760 alpha_set_memflags_1 (x, in_struct_p, volatile_p, unchanging_p)
761      rtx x;
762      int in_struct_p, volatile_p, unchanging_p;
763 {
764   int i;
765
766   switch (GET_CODE (x))
767     {
768     case SEQUENCE:
769     case PARALLEL:
770       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
771         alpha_set_memflags_1 (XVECEXP (x, 0, i), in_struct_p, volatile_p,
772                               unchanging_p);
773       break;
774
775     case INSN:
776       alpha_set_memflags_1 (PATTERN (x), in_struct_p, volatile_p,
777                             unchanging_p);
778       break;
779
780     case SET:
781       alpha_set_memflags_1 (SET_DEST (x), in_struct_p, volatile_p,
782                             unchanging_p);
783       alpha_set_memflags_1 (SET_SRC (x), in_struct_p, volatile_p,
784                             unchanging_p);
785       break;
786
787     case MEM:
788       MEM_IN_STRUCT_P (x) = in_struct_p;
789       MEM_VOLATILE_P (x) = volatile_p;
790       RTX_UNCHANGING_P (x) = unchanging_p;
791       break;
792     }
793 }
794
795 /* Given INSN, which is either an INSN or a SEQUENCE generated to
796    perform a memory operation, look for any MEMs in either a SET_DEST or
797    a SET_SRC and copy the in-struct, unchanging, and volatile flags from
798    REF into each of the MEMs found.  If REF is not a MEM, don't do
799    anything.  */
800
801 void
802 alpha_set_memflags (insn, ref)
803      rtx insn;
804      rtx ref;
805 {
806   /* Note that it is always safe to get these flags, though they won't
807      be what we think if REF is not a MEM.  */
808   int in_struct_p = MEM_IN_STRUCT_P (ref);
809   int volatile_p = MEM_VOLATILE_P (ref);
810   int unchanging_p = RTX_UNCHANGING_P (ref);
811
812   if (GET_CODE (ref) != MEM
813       || (! in_struct_p && ! volatile_p && ! unchanging_p))
814     return;
815
816   alpha_set_memflags_1 (insn, in_struct_p, volatile_p, unchanging_p);
817 }
818 \f
819 /* Try to output insns to set TARGET equal to the constant C if it can be
820    done in less than N insns.  Do all computations in MODE.  Returns the place
821    where the output has been placed if it can be done and the insns have been
822    emitted.  If it would take more than N insns, zero is returned and no
823    insns and emitted.  */
824
825 rtx
826 alpha_emit_set_const (target, mode, c, n)
827      rtx target;
828      enum machine_mode mode;
829      HOST_WIDE_INT c;
830      int n;
831 {
832   rtx pat;
833   int i;
834
835   /* Try 1 insn, then 2, then up to N. */
836   for (i = 1; i <= n; i++)
837     if ((pat = alpha_emit_set_const_1 (target, mode, c, i)) != 0)
838       return pat;
839
840   return 0;
841 }
842
843 /* Internal routine for the above to check for N or below insns.  */
844
845 static rtx
846 alpha_emit_set_const_1 (target, mode, c, n)
847      rtx target;
848      enum machine_mode mode;
849      HOST_WIDE_INT c;
850      int n;
851 {
852   HOST_WIDE_INT new = c;
853   int i, bits;
854   /* Use a pseudo if highly optimizing and still generating RTL.  */
855   rtx subtarget
856     = (flag_expensive_optimizations && rtx_equal_function_value_matters
857        ? 0 : target);
858   rtx temp;
859
860 #if HOST_BITS_PER_WIDE_INT == 64
861   /* We are only called for SImode and DImode.  If this is SImode, ensure that
862      we are sign extended to a full word.  This does not make any sense when
863      cross-compiling on a narrow machine.  */
864
865   if (mode == SImode)
866     c = (c & 0xffffffff) - 2 * (c & 0x80000000);
867 #endif
868
869   /* If this is a sign-extended 32-bit constant, we can do this in at most
870      three insns, so do it if we have enough insns left.  We always have
871      a sign-extended 32-bit constant when compiling on a narrow machine. 
872      Note that we cannot handle the constant 0x80000000.  */
873
874   if ((HOST_BITS_PER_WIDE_INT != 64
875        || c >> 31 == -1 || c >> 31 == 0)
876       && c != 0x80000000U)
877     {
878       HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000);
879       HOST_WIDE_INT tmp1 = c - low;
880       HOST_WIDE_INT high
881         = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
882       HOST_WIDE_INT extra = 0;
883
884       /* If HIGH will be interpreted as negative but the constant is
885          positive, we must adjust it to do two ldha insns.  */
886
887       if ((high & 0x8000) != 0 && c >= 0)
888         {
889           extra = 0x4000;
890           tmp1 -= 0x40000000;
891           high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
892         }
893
894       if (c == low || (low == 0 && extra == 0))
895         return copy_to_suggested_reg (GEN_INT (c), target, mode);
896       else if (n >= 2 + (extra != 0))
897         {
898           temp = copy_to_suggested_reg (GEN_INT (low), subtarget, mode);
899
900           if (extra != 0)
901             temp = expand_binop (mode, add_optab, temp, GEN_INT (extra << 16),
902                                  subtarget, 0, OPTAB_WIDEN);
903
904           return expand_binop (mode, add_optab, temp, GEN_INT (high << 16),
905                                target, 0, OPTAB_WIDEN);
906         }
907     }
908
909   /* If we couldn't do it that way, try some other methods.  But if we have
910      no instructions left, don't bother.  Likewise, if this is SImode and
911      we can't make pseudos, we can't do anything since the expand_binop
912      and expand_unop calls will widen and try to make pseudos.  */
913
914   if (n == 1
915       || (mode == SImode && ! rtx_equal_function_value_matters))
916     return 0;
917
918 #if HOST_BITS_PER_WIDE_INT == 64
919   /* First, see if can load a value into the target that is the same as the
920      constant except that all bytes that are 0 are changed to be 0xff.  If we
921      can, then we can do a ZAPNOT to obtain the desired constant.  */
922
923   for (i = 0; i < 64; i += 8)
924     if ((new & ((HOST_WIDE_INT) 0xff << i)) == 0)
925       new |= (HOST_WIDE_INT) 0xff << i;
926
927   /* We are only called for SImode and DImode.  If this is SImode, ensure that
928      we are sign extended to a full word.  */
929
930   if (mode == SImode)
931     new = (new & 0xffffffff) - 2 * (new & 0x80000000);
932
933   if (new != c
934       && (temp = alpha_emit_set_const (subtarget, mode, new, n - 1)) != 0)
935     return expand_binop (mode, and_optab, temp, GEN_INT (c | ~ new),
936                          target, 0, OPTAB_WIDEN);
937 #endif
938
939   /* Next, see if we can load a related constant and then shift and possibly
940      negate it to get the constant we want.  Try this once each increasing
941      numbers of insns.  */
942
943   for (i = 1; i < n; i++)
944     {
945       /* First try complementing.  */
946       if ((temp = alpha_emit_set_const (subtarget, mode, ~ c, i)) != 0)
947         return expand_unop (mode, one_cmpl_optab, temp, target, 0);
948
949       /* Next try to form a constant and do a left shift.  We can do this
950          if some low-order bits are zero; the exact_log2 call below tells
951          us that information.  The bits we are shifting out could be any
952          value, but here we'll just try the 0- and sign-extended forms of
953          the constant.  To try to increase the chance of having the same
954          constant in more than one insn, start at the highest number of
955          bits to shift, but try all possibilities in case a ZAPNOT will
956          be useful.  */
957
958       if ((bits = exact_log2 (c & - c)) > 0)
959         for (; bits > 0; bits--)
960           if ((temp = (alpha_emit_set_const
961                        (subtarget, mode,
962                         (unsigned HOST_WIDE_INT) c >> bits, i))) != 0
963               || ((temp = (alpha_emit_set_const
964                           (subtarget, mode,
965                            ((unsigned HOST_WIDE_INT) c) >> bits, i)))
966                   != 0))
967             return expand_binop (mode, ashl_optab, temp, GEN_INT (bits),
968                                  target, 0, OPTAB_WIDEN);
969
970       /* Now try high-order zero bits.  Here we try the shifted-in bits as
971          all zero and all ones.  Be careful to avoid shifting outside the
972          mode and to avoid shifting outside the host wide int size.  */
973
974       if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
975                    - floor_log2 (c) - 1)) > 0)
976         for (; bits > 0; bits--)
977           if ((temp = alpha_emit_set_const (subtarget, mode,
978                                             c << bits, i)) != 0
979               || ((temp = (alpha_emit_set_const
980                            (subtarget, mode,
981                             ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
982                             i)))
983                   != 0))
984             return expand_binop (mode, lshr_optab, temp, GEN_INT (bits),
985                                  target, 1, OPTAB_WIDEN);
986
987       /* Now try high-order 1 bits.  We get that with a sign-extension.
988          But one bit isn't enough here.  Be careful to avoid shifting outside
989          the mode and to avoid shifting outside the host wide int size. */
990       
991       if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
992                    - floor_log2 (~ c) - 2)) > 0)
993         for (; bits > 0; bits--)
994           if ((temp = alpha_emit_set_const (subtarget, mode,
995                                             c << bits, i)) != 0
996               || ((temp = (alpha_emit_set_const
997                            (subtarget, mode,
998                             ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
999                             i)))
1000                   != 0))
1001             return expand_binop (mode, ashr_optab, temp, GEN_INT (bits),
1002                                  target, 0, OPTAB_WIDEN);
1003     }
1004
1005   return 0;
1006 }
1007
1008 #if HOST_BITS_PER_WIDE_INT == 64
1009 /* Having failed to find a 3 insn sequence in alpha_emit_set_const,
1010    fall back to a straight forward decomposition.  We do this to avoid
1011    exponential run times encountered when looking for longer sequences
1012    with alpha_emit_set_const.  */
1013
1014 rtx
1015 alpha_emit_set_long_const (target, c)
1016      rtx target;
1017      HOST_WIDE_INT c;
1018 {
1019   /* Use a pseudo if highly optimizing and still generating RTL.  */
1020   rtx subtarget
1021     = (flag_expensive_optimizations && rtx_equal_function_value_matters
1022        ? 0 : target);
1023   HOST_WIDE_INT d1, d2, d3, d4;
1024   rtx r1, r2;
1025
1026   /* Decompose the entire word */
1027   d1 = ((c & 0xffff) ^ 0x8000) - 0x8000;
1028   c -= d1;
1029   d2 = ((c & 0xffffffff) ^ 0x80000000) - 0x80000000;
1030   c = (c - d2) >> 32;
1031   d3 = ((c & 0xffff) ^ 0x8000) - 0x8000;
1032   c -= d3;
1033   d4 = ((c & 0xffffffff) ^ 0x80000000) - 0x80000000;
1034
1035   if (c - d4 != 0)
1036     abort();
1037
1038   /* Construct the high word */
1039   if (d3 == 0)
1040     r1 = copy_to_suggested_reg (GEN_INT (d4), subtarget, DImode);
1041   else if (d4 == 0)
1042     r1 = copy_to_suggested_reg (GEN_INT (d3), subtarget, DImode);
1043   else
1044     r1 = expand_binop (DImode, add_optab, GEN_INT (d3), GEN_INT (d4),
1045                        subtarget, 0, OPTAB_WIDEN);
1046
1047   /* Shift it into place */
1048   r2 = expand_binop (DImode, ashl_optab, r1, GEN_INT (32), 
1049                      subtarget, 0, OPTAB_WIDEN);
1050
1051   if (subtarget == 0 && d1 == d3 && d2 == d4)
1052     r1 = expand_binop (DImode, add_optab, r1, r2, subtarget, 0, OPTAB_WIDEN);
1053   else
1054     {
1055       r1 = r2;
1056
1057       /* Add in the low word */
1058       if (d2 != 0)
1059         r1 = expand_binop (DImode, add_optab, r1, GEN_INT (d2),
1060                            subtarget, 0, OPTAB_WIDEN);
1061       if (d1 != 0)
1062         r1 = expand_binop (DImode, add_optab, r1, GEN_INT (d1),
1063                            subtarget, 0, OPTAB_WIDEN);
1064     }
1065
1066   if (subtarget == 0)
1067     r1 = copy_to_suggested_reg(r1, target, DImode);
1068
1069   return r1;
1070 }
1071 #endif /* HOST_BITS_PER_WIDE_INT == 64 */
1072
1073 /* Rewrite a comparison against zero CMP of the form
1074    (CODE (cc0) (const_int 0)) so it can be written validly in
1075    a conditional move (if_then_else CMP ...).
1076    If both of the operands that set cc0 are non-zero we must emit
1077    an insn to perform the compare (it can't be done within
1078    the conditional move). */
1079 rtx
1080 alpha_emit_conditional_move (cmp, mode)
1081      rtx cmp;
1082      enum machine_mode mode;
1083 {
1084   enum rtx_code code = GET_CODE (cmp);
1085   enum rtx_code cmov_code = NE;
1086   rtx op0 = alpha_compare_op0;
1087   rtx op1 = alpha_compare_op1;
1088   enum machine_mode cmp_mode
1089     = (GET_MODE (op0) == VOIDmode ? DImode : GET_MODE (op0));
1090   enum machine_mode cmp_op_mode = alpha_compare_fp_p ? DFmode : DImode;
1091   rtx tem;
1092
1093   if (alpha_compare_fp_p != FLOAT_MODE_P (mode))
1094     return 0;
1095
1096   /* We may be able to use a conditional move directly.
1097      This avoids emitting spurious compares. */
1098   if (signed_comparison_operator (cmp, cmp_op_mode)
1099       && (op0 == CONST0_RTX (cmp_mode) || op1 == CONST0_RTX (cmp_mode)))
1100     return gen_rtx (code, VOIDmode, op0, op1);
1101
1102   /* We can't put the comparison insides a conditional move;
1103      emit a compare instruction and put that inside the
1104      conditional move.  Make sure we emit only comparisons we have;
1105      swap or reverse as necessary.  */
1106
1107   switch (code)
1108     {
1109     case EQ:  case LE:  case LT:  case LEU:  case LTU:
1110       /* We have these compares: */
1111       break;
1112
1113     case NE:
1114       /* This must be reversed. */
1115       code = reverse_condition (code);
1116       cmov_code = EQ;
1117       break;
1118
1119     case GE:  case GT:  case GEU:  case GTU:
1120       /* These must be swapped.  Make sure the new first operand is in
1121          a register.  */
1122       code = swap_condition (code);
1123       tem = op0, op0 = op1, op1 = tem;
1124       op0 = force_reg (cmp_mode, op0);
1125       break;
1126
1127     default:
1128       abort ();
1129     }
1130
1131   tem = gen_reg_rtx (cmp_op_mode);
1132   emit_move_insn (tem, gen_rtx (code, cmp_op_mode, op0, op1));
1133   return gen_rtx (cmov_code, VOIDmode, tem, CONST0_RTX (cmp_op_mode));
1134 }
1135 \f
1136 /* Adjust the cost of a scheduling dependency.  Return the new cost of
1137    a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
1138
1139 int
1140 alpha_adjust_cost (insn, link, dep_insn, cost)
1141      rtx insn;
1142      rtx link;
1143      rtx dep_insn;
1144      int cost;
1145 {
1146   rtx set;
1147
1148   /* If the dependence is an anti-dependence, there is no cost.  For an
1149      output dependence, there is sometimes a cost, but it doesn't seem
1150      worth handling those few cases.  */
1151
1152   if (REG_NOTE_KIND (link) != 0)
1153     return 0;
1154
1155   /* EV5 costs are as given in alpha.md; exceptions are given here. */
1156   if (alpha_cpu == PROCESSOR_EV5)
1157     {
1158       /* And the lord DEC sayeth:  "A special bypass provides an effective
1159          latency of 0 cycles for an ICMP or ILOG insn producing the test
1160          operand of an IBR or CMOV insn." */
1161       if (recog_memoized (dep_insn) >= 0
1162           && (get_attr_type (dep_insn) == TYPE_ICMP
1163               || get_attr_type (dep_insn) == TYPE_ILOG)
1164           && recog_memoized (insn) >= 0
1165           && (get_attr_type (insn) == TYPE_IBR
1166               || (get_attr_type (insn) == TYPE_CMOV
1167                   && !((set = single_set (dep_insn)) != 0
1168                        && GET_CODE (PATTERN (insn)) == SET
1169                        && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE
1170                        && (rtx_equal_p (SET_DEST (set),
1171                                         XEXP (SET_SRC (PATTERN (insn)), 1))
1172                            || rtx_equal_p (SET_DEST (set),
1173                                            XEXP (SET_SRC (PATTERN (insn)), 2)))))))
1174         return 1;
1175       return cost;
1176     } 
1177
1178   /* If INSN is a store insn and DEP_INSN is setting the data being stored,
1179      we can sometimes lower the cost.  */
1180
1181   if (recog_memoized (insn) >= 0 && get_attr_type (insn) == TYPE_ST
1182       && (set = single_set (dep_insn)) != 0
1183       && GET_CODE (PATTERN (insn)) == SET
1184       && rtx_equal_p (SET_DEST (set), SET_SRC (PATTERN (insn))))
1185     switch (get_attr_type (dep_insn))
1186       {
1187       case TYPE_LD:
1188         /* No savings here.  */
1189         return cost;
1190
1191       case TYPE_IMULL:
1192       case TYPE_IMULQ:
1193         /* In these cases, we save one cycle.  */
1194         return cost - 2;
1195
1196       default:
1197         /* In all other cases, we save two cycles.  */
1198         return MAX (0, cost - 4);
1199       }
1200
1201   /* Another case that needs adjustment is an arithmetic or logical
1202      operation.  It's cost is usually one cycle, but we default it to
1203      two in the MD file.  The only case that it is actually two is
1204      for the address in loads and stores.  */
1205
1206   if (recog_memoized (dep_insn) >= 0
1207       && (get_attr_type (dep_insn) == TYPE_IADD
1208           || get_attr_type (dep_insn) == TYPE_ILOG))
1209     switch (get_attr_type (insn))
1210       {
1211       case TYPE_LD:
1212       case TYPE_ST:
1213         return cost;
1214
1215       default:
1216         return 2;
1217       }
1218
1219   /* The final case is when a compare feeds into an integer branch.  The cost
1220      is only one cycle in that case.  */
1221
1222   if (recog_memoized (dep_insn) >= 0
1223       && get_attr_type (dep_insn) == TYPE_ICMP
1224       && recog_memoized (insn) >= 0
1225       && get_attr_type (insn) == TYPE_IBR)
1226     return 2;
1227
1228   /* Otherwise, return the default cost. */
1229
1230   return cost;
1231 }
1232 \f
1233 /* Print an operand.  Recognize special options, documented below.  */
1234
1235 void
1236 print_operand (file, x, code)
1237     FILE *file;
1238     rtx x;
1239     char code;
1240 {
1241   int i;
1242
1243   switch (code)
1244     {
1245     case '&':
1246       /* Generates fp-rounding mode suffix: nothing for normal, 'c' for
1247          chopped, 'm' for minus-infinity, and 'd' for dynamic rounding
1248          mode.  alpha_fprm controls which suffix is generated.  */
1249       switch (alpha_fprm)
1250         {
1251         case ALPHA_FPRM_NORM:
1252           break;
1253         case ALPHA_FPRM_MINF: 
1254           fputc ('m', file);
1255           break;
1256         case ALPHA_FPRM_CHOP:
1257           fputc ('c', file);
1258           break;
1259         case ALPHA_FPRM_DYN:
1260           fputc ('d', file);
1261           break;
1262         }
1263       break;
1264
1265     case '\'':
1266       /* Generates trap-mode suffix for instructions that accept the su
1267          suffix only (cmpt et al).  */
1268       if (alpha_tp == ALPHA_TP_INSN)
1269         fputs ("su", file);
1270       break;
1271
1272     case ')':
1273       /* Generates trap-mode suffix for instructions that accept the u, su,
1274          and sui suffix.  This is the bulk of the IEEE floating point
1275          instructions (addt et al).  */
1276       switch (alpha_fptm)
1277         {
1278         case ALPHA_FPTM_N:
1279           break;
1280         case ALPHA_FPTM_U:
1281           fputc ('u', file);
1282           break;
1283         case ALPHA_FPTM_SU:
1284           fputs ("su", file);
1285           break;
1286         case ALPHA_FPTM_SUI:
1287           fputs ("sui", file);
1288           break;
1289         }
1290       break;
1291
1292     case '+':
1293       /* Generates trap-mode suffix for instructions that accept the sui
1294          suffix (cvtqt and cvtqs).  */
1295       switch (alpha_fptm)
1296         {
1297         case ALPHA_FPTM_N: case ALPHA_FPTM_U:
1298         case ALPHA_FPTM_SU:     /* cvtqt/cvtqs can't cause underflow */
1299           break;
1300         case ALPHA_FPTM_SUI:
1301           fputs ("sui", file);
1302           break;
1303         }
1304       break;
1305
1306     case ',':
1307       /* Generates single precision instruction suffix.  */
1308       fprintf (file, "%c", (TARGET_FLOAT_VAX?'f':'s'));
1309       break;
1310
1311     case '-':
1312       /* Generates double precision instruction suffix.  */
1313       fprintf (file, "%c", (TARGET_FLOAT_VAX?'g':'t'));
1314       break;
1315
1316     case 'r':
1317       /* If this operand is the constant zero, write it as "$31".  */
1318       if (GET_CODE (x) == REG)
1319         fprintf (file, "%s", reg_names[REGNO (x)]);
1320       else if (x == CONST0_RTX (GET_MODE (x)))
1321         fprintf (file, "$31");
1322       else
1323         output_operand_lossage ("invalid %%r value");
1324
1325       break;
1326
1327     case 'R':
1328       /* Similar, but for floating-point.  */
1329       if (GET_CODE (x) == REG)
1330         fprintf (file, "%s", reg_names[REGNO (x)]);
1331       else if (x == CONST0_RTX (GET_MODE (x)))
1332         fprintf (file, "$f31");
1333       else
1334         output_operand_lossage ("invalid %%R value");
1335
1336       break;
1337
1338     case 'N':
1339       /* Write the 1's complement of a constant.  */
1340       if (GET_CODE (x) != CONST_INT)
1341         output_operand_lossage ("invalid %%N value");
1342
1343       fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INTVAL (x));
1344       break;
1345
1346     case 'P':
1347       /* Write 1 << C, for a constant C.  */
1348       if (GET_CODE (x) != CONST_INT)
1349         output_operand_lossage ("invalid %%P value");
1350
1351       fprintf (file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) 1 << INTVAL (x));
1352       break;
1353
1354     case 'h':
1355       /* Write the high-order 16 bits of a constant, sign-extended.  */
1356       if (GET_CODE (x) != CONST_INT)
1357         output_operand_lossage ("invalid %%h value");
1358
1359       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) >> 16);
1360       break;
1361
1362     case 'L':
1363       /* Write the low-order 16 bits of a constant, sign-extended.  */
1364       if (GET_CODE (x) != CONST_INT)
1365         output_operand_lossage ("invalid %%L value");
1366
1367       fprintf (file, HOST_WIDE_INT_PRINT_DEC,
1368                (INTVAL (x) & 0xffff) - 2 * (INTVAL (x) & 0x8000));
1369       break;
1370
1371     case 'm':
1372       /* Write mask for ZAP insn.  */
1373       if (GET_CODE (x) == CONST_DOUBLE)
1374         {
1375           HOST_WIDE_INT mask = 0;
1376           HOST_WIDE_INT value;
1377
1378           value = CONST_DOUBLE_LOW (x);
1379           for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
1380                i++, value >>= 8)
1381             if (value & 0xff)
1382               mask |= (1 << i);
1383
1384           value = CONST_DOUBLE_HIGH (x);
1385           for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
1386                i++, value >>= 8)
1387             if (value & 0xff)
1388               mask |= (1 << (i + sizeof (int)));
1389
1390           fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask & 0xff);
1391         }
1392
1393       else if (GET_CODE (x) == CONST_INT)
1394         {
1395           HOST_WIDE_INT mask = 0, value = INTVAL (x);
1396
1397           for (i = 0; i < 8; i++, value >>= 8)
1398             if (value & 0xff)
1399               mask |= (1 << i);
1400
1401           fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask);
1402         }
1403       else
1404         output_operand_lossage ("invalid %%m value");
1405       break;
1406
1407     case 'M':
1408       /* 'b', 'w', or 'l' as the value of the constant.  */
1409       if (GET_CODE (x) != CONST_INT
1410           || (INTVAL (x) != 8 && INTVAL (x) != 16 && INTVAL (x) != 32))
1411         output_operand_lossage ("invalid %%M value");
1412
1413       fprintf (file, "%s",
1414                INTVAL (x) == 8 ? "b" : INTVAL (x) == 16 ? "w" : "l");
1415       break;
1416
1417     case 'U':
1418       /* Similar, except do it from the mask.  */
1419       if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xff)
1420         fprintf (file, "b");
1421       else if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xffff)
1422         fprintf (file, "w");
1423 #if HOST_BITS_PER_WIDE_INT == 32
1424       else if (GET_CODE (x) == CONST_DOUBLE
1425                && CONST_DOUBLE_HIGH (x) == 0
1426                && CONST_DOUBLE_LOW (x) == -1)
1427         fprintf (file, "l");
1428 #else
1429       else if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xffffffff)
1430         fprintf (file, "l");
1431 #endif
1432       else
1433         output_operand_lossage ("invalid %%U value");
1434       break;
1435
1436     case 's':
1437       /* Write the constant value divided by 8.  */
1438       if (GET_CODE (x) != CONST_INT
1439           && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
1440           && (INTVAL (x) & 7) != 8)
1441         output_operand_lossage ("invalid %%s value");
1442
1443       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) / 8);
1444       break;
1445
1446     case 'S':
1447       /* Same, except compute (64 - c) / 8 */
1448
1449       if (GET_CODE (x) != CONST_INT
1450           && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
1451           && (INTVAL (x) & 7) != 8)
1452         output_operand_lossage ("invalid %%s value");
1453
1454       fprintf (file, HOST_WIDE_INT_PRINT_DEC, (64 - INTVAL (x)) / 8);
1455       break;
1456
1457     case 'C': case 'D': case 'c': case 'd':
1458       /* Write out comparison name.  */
1459       {
1460         enum rtx_code c = GET_CODE (x);
1461
1462         if (GET_RTX_CLASS (c) != '<')
1463           output_operand_lossage ("invalid %%C value");
1464
1465         if (code == 'D')
1466           c = reverse_condition (c);
1467         else if (code == 'c')
1468           c = swap_condition (c);
1469         else if (code == 'd')
1470           c = swap_condition (reverse_condition (c));
1471
1472         if (c == LEU)
1473           fprintf (file, "ule");
1474         else if (c == LTU)
1475           fprintf (file, "ult");
1476         else
1477           fprintf (file, "%s", GET_RTX_NAME (c));
1478       }
1479       break;
1480
1481     case 'E':
1482       /* Write the divide or modulus operator.  */
1483       switch (GET_CODE (x))
1484         {
1485         case DIV:
1486           fprintf (file, "div%s", GET_MODE (x) == SImode ? "l" : "q");
1487           break;
1488         case UDIV:
1489           fprintf (file, "div%su", GET_MODE (x) == SImode ? "l" : "q");
1490           break;
1491         case MOD:
1492           fprintf (file, "rem%s", GET_MODE (x) == SImode ? "l" : "q");
1493           break;
1494         case UMOD:
1495           fprintf (file, "rem%su", GET_MODE (x) == SImode ? "l" : "q");
1496           break;
1497         default:
1498           output_operand_lossage ("invalid %%E value");
1499           break;
1500         }
1501       break;
1502
1503     case 'A':
1504       /* Write "_u" for unaligned access.  */
1505       if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
1506         fprintf (file, "_u");
1507       break;
1508
1509     case 0:
1510       if (GET_CODE (x) == REG)
1511         fprintf (file, "%s", reg_names[REGNO (x)]);
1512       else if (GET_CODE (x) == MEM)
1513         output_address (XEXP (x, 0));
1514       else
1515         output_addr_const (file, x);
1516       break;
1517
1518     default:
1519       output_operand_lossage ("invalid %%xn code");
1520     }
1521 }
1522 \f
1523 /* Do what is necessary for `va_start'.  The argument is ignored;
1524    We look at the current function to determine if stdarg or varargs
1525    is used and fill in an initial va_list.  A pointer to this constructor
1526    is returned.  */
1527
1528 struct rtx_def *
1529 alpha_builtin_saveregs (arglist)
1530      tree arglist;
1531 {
1532   rtx block, addr, argsize;
1533   tree fntype = TREE_TYPE (current_function_decl);
1534   int stdarg = (TYPE_ARG_TYPES (fntype) != 0
1535                 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
1536                     != void_type_node));
1537
1538   /* Compute the current position into the args, taking into account
1539      both registers and memory.  Both of these are already included in
1540      current_function_args_info.  */
1541
1542   argsize = GEN_INT (CURRENT_FUNCTION_ARGS_INFO * UNITS_PER_WORD);
1543
1544   /* For Unix, SETUP_INCOMING_VARARGS moves the starting address base up by 48,
1545      storing fp arg registers in the first 48 bytes, and the integer arg
1546      registers in the next 48 bytes.  This is only done, however, if any
1547      integer registers need to be stored.
1548
1549      If no integer registers need be stored, then we must subtract 48 in
1550      order to account for the integer arg registers which are counted in
1551      argsize above, but which are not actually stored on the stack.  */
1552
1553   if (TARGET_OPEN_VMS)
1554     addr = plus_constant (virtual_incoming_args_rtx,
1555                           CURRENT_FUNCTION_ARGS_INFO <= 5 + stdarg
1556                           ? UNITS_PER_WORD : - 6 * UNITS_PER_WORD);
1557   else
1558     addr = (CURRENT_FUNCTION_ARGS_INFO <= 5 + stdarg
1559             ? plus_constant (virtual_incoming_args_rtx,
1560                              6 * UNITS_PER_WORD)
1561             : plus_constant (virtual_incoming_args_rtx,
1562                              - (6 * UNITS_PER_WORD)));
1563
1564   /* For VMS, we include the argsize, while on Unix, it's handled as
1565      a separate field.  */
1566   if (TARGET_OPEN_VMS)
1567     addr = plus_constant (addr, INTVAL (argsize));
1568
1569   addr = force_operand (addr, NULL_RTX);
1570
1571 #ifdef POINTERS_EXTEND_UNSIGNED
1572   addr = convert_memory_address (ptr_mode, addr);
1573 #endif
1574
1575   if (TARGET_OPEN_VMS)
1576     return addr;
1577   else
1578     {
1579       /* Allocate the va_list constructor */
1580       block = assign_stack_local (BLKmode, 2 * UNITS_PER_WORD, BITS_PER_WORD);
1581       RTX_UNCHANGING_P (block) = 1;
1582       RTX_UNCHANGING_P (XEXP (block, 0)) = 1;
1583
1584       /* Store the address of the first integer register in the __base
1585          member.  */
1586
1587       emit_move_insn (change_address (block, ptr_mode, XEXP (block, 0)), addr);
1588
1589       /* Store the argsize as the __va_offset member.  */
1590       emit_move_insn
1591         (change_address (block, TYPE_MODE (integer_type_node),
1592                          plus_constant (XEXP (block, 0),
1593                                         POINTER_SIZE/BITS_PER_UNIT)),
1594          argsize);
1595
1596       /* Return the address of the va_list constructor, but don't put it in a
1597          register.  Doing so would fail when not optimizing and produce worse
1598          code when optimizing.  */
1599       return XEXP (block, 0);
1600     }
1601 }
1602 \f
1603 /* This page contains routines that are used to determine what the function
1604    prologue and epilogue code will do and write them out.  */
1605
1606 /* Compute the size of the save area in the stack.  */
1607
1608 #if OPEN_VMS
1609
1610 #define REG_PV 27
1611 #define REG_RA 26
1612
1613 /* These variables are used for communication between the following functions.
1614    They indicate various things about the current function being compiled
1615    that are used to tell what kind of prologue, epilogue and procedure
1616    descriptior to generate. */
1617
1618 /* Nonzero if we need a stack procedure.  */
1619 static int is_stack_procedure;
1620
1621 /* Register number (either FP or SP) that is used to unwind the frame.  */
1622 static int unwind_regno;
1623
1624 /* Register number used to save FP.  We need not have one for RA since
1625    we don't modify it for register procedures.  This is only defined
1626    for register frame procedures.  */
1627 static int save_fp_regno;
1628
1629 /* Register number used to reference objects off our PV.  */
1630 static int base_regno;
1631
1632 /*  Compute register masks for saved registers.  */
1633
1634 static void
1635 alpha_sa_mask (imaskP, fmaskP)
1636     unsigned long *imaskP;
1637     unsigned long *fmaskP;
1638 {
1639   unsigned long imask = 0;
1640   unsigned long fmask = 0;
1641   int i;
1642
1643   if (is_stack_procedure)
1644     imask |= (1L << HARD_FRAME_POINTER_REGNUM);
1645
1646   /* One for every register we have to save.  */
1647
1648   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1649     if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i])
1650       {
1651         if (i < 32)
1652           imask |= (1L << i);
1653         else
1654           fmask |= (1L << (i - 32));
1655       }
1656
1657   *imaskP = imask;
1658   *fmaskP = fmask;
1659
1660   return;
1661 }
1662
1663 int
1664 alpha_sa_size ()
1665 {
1666   int sa_size = 0;
1667   HOST_WIDE_INT stack_needed;
1668   int i;
1669
1670   /* One for every register we have to save.  */
1671
1672   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1673     if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i])
1674       sa_size++;
1675
1676   /* Start by assuming we can use a register procedure if we don't make any
1677      calls (REG_RA not used) or need to save any registers and a stack
1678      procedure if we do.  */
1679   is_stack_procedure = regs_ever_live[REG_RA] || sa_size != 0;
1680
1681   /* Decide whether to refer to objects off our PV via FP or PV.
1682      If we need need FP for something else or if we receive a nonlocal
1683      goto (which expects PV to contain the value), we must use PV.
1684      Otherwise, start by assuming we can use FP.  */
1685   base_regno = (frame_pointer_needed || current_function_has_nonlocal_label
1686                 || is_stack_procedure
1687                 || current_function_outgoing_args_size
1688                 ? REG_PV : HARD_FRAME_POINTER_REGNUM);
1689
1690   /* If we want to copy PV into FP, we need to find some register in which to
1691      save FP.  */
1692
1693   save_fp_regno = -1;
1694
1695   if (base_regno == HARD_FRAME_POINTER_REGNUM)
1696     for (i = 0; i < 32; i++)
1697       if (! fixed_regs[i] && call_used_regs[i] && ! regs_ever_live[i])
1698         save_fp_regno = i;
1699
1700   if (save_fp_regno == -1)
1701     base_regno = REG_PV, is_stack_procedure = 1;
1702
1703   /* Stack unwinding should be done via FP unless we use it for PV.  */
1704   unwind_regno
1705     = base_regno == REG_PV ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM;
1706
1707   /* If this is a stack procedure, allow space for saving FP and RA.  */
1708   if (is_stack_procedure)
1709     sa_size += 2;
1710
1711   return sa_size * 8;
1712 }
1713
1714 int
1715 alpha_pv_save_size ()
1716 {
1717   alpha_sa_size ();
1718   return is_stack_procedure ? 8 : 0;
1719 }
1720
1721 int
1722 alpha_using_fp ()
1723 {
1724   alpha_sa_size ();
1725   return unwind_regno == HARD_FRAME_POINTER_REGNUM;
1726 }
1727
1728 #else /* ! OPEN_VMS */
1729
1730 int
1731 alpha_sa_size ()
1732 {
1733   int size = 0;
1734   int i;
1735
1736   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1737     if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i])
1738       size++;
1739
1740   /* If some registers were saved but not reg 26, reg 26 must also
1741      be saved, so leave space for it.  */
1742   if (size != 0 && ! regs_ever_live[26])
1743     size++;
1744
1745   /* Our size must be even (multiple of 16 bytes).  */
1746   if (size & 1)
1747     size ++;
1748
1749   return size * 8;
1750 }
1751
1752 #endif /* ! OPEN_VMS */
1753
1754 /* Return 1 if this function can directly return via $26.  */
1755
1756 int
1757 direct_return ()
1758 {
1759   return (! TARGET_OPEN_VMS && reload_completed && alpha_sa_size () == 0
1760           && get_frame_size () == 0
1761           && current_function_outgoing_args_size == 0
1762           && current_function_pretend_args_size == 0);
1763 }
1764
1765 /* Write a version stamp.  Don't write anything if we are running as a
1766    cross-compiler.  Otherwise, use the versions in /usr/include/stamp.h.  */
1767
1768 #if !defined(CROSS_COMPILE) && !defined(_WIN32) && !defined(__linux__) && !defined(VMS)
1769 #include <stamp.h>
1770 #endif
1771
1772 void
1773 alpha_write_verstamp (file)
1774      FILE *file;
1775 {
1776 #ifdef MS_STAMP
1777   fprintf (file, "\t.verstamp %d %d\n", MS_STAMP, LS_STAMP);
1778 #endif
1779 }
1780 \f
1781 /* Write code to add constant C to register number IN_REG (possibly 31)
1782    and put the result into OUT_REG.  Use TEMP_REG as a scratch register;
1783    usually this will be OUT_REG, but should not be if OUT_REG is 
1784    STACK_POINTER_REGNUM, since it must be updated in a single instruction.
1785    Write the code to FILE.  */
1786
1787 static void
1788 add_long_const (file, c, in_reg, out_reg, temp_reg)
1789      FILE *file;
1790      HOST_WIDE_INT c;
1791      int in_reg, out_reg, temp_reg;
1792 {
1793   HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000);
1794   HOST_WIDE_INT tmp1 = c - low;
1795   HOST_WIDE_INT high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
1796   HOST_WIDE_INT extra = 0;
1797
1798   /* We don't have code to write out constants larger than 32 bits.  */
1799 #if HOST_BITS_PER_LONG_INT == 64
1800   if ((unsigned HOST_WIDE_INT) c >> 32 != 0)
1801     abort ();
1802 #endif
1803
1804   /* If HIGH will be interpreted as negative, we must adjust it to do two
1805      ldha insns.  Note that we will never be building a negative constant
1806      here.  */
1807
1808   if (high & 0x8000)
1809     {
1810       extra = 0x4000;
1811       tmp1 -= 0x40000000;
1812       high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
1813     }
1814
1815   if (low != 0)
1816     {
1817       int result_reg = (extra == 0 && high == 0) ? out_reg : temp_reg;
1818
1819       if (low >= 0 && low < 255)
1820         fprintf (file, "\taddq $%d,%d,$%d\n", in_reg, low, result_reg);
1821       else
1822         fprintf (file, "\tlda $%d,%d($%d)\n", result_reg, low, in_reg);
1823
1824       in_reg = result_reg;
1825     }
1826
1827   if (extra)
1828     {
1829       int result_reg = (high == 0) ? out_reg : temp_reg;
1830
1831       fprintf (file, "\tldah $%d,%d($%d)\n", result_reg, extra, in_reg);
1832       in_reg = result_reg;
1833     }
1834
1835   if (high)
1836     fprintf (file, "\tldah $%d,%d($%d)\n", out_reg, high, in_reg);
1837 }
1838
1839 /* Write function prologue.  */
1840
1841 #if OPEN_VMS
1842
1843 /* 
1844    Quick and dirty vmskrunch routine to ensure symbols are within the
1845    64 bytes limit imposed by VMS.
1846
1847    This is written specifically for GNAT, and may not work for C++.
1848
1849    This routine duplicates every symbol passed to it whether it is too
1850    long or not, which is a waste of space, fix later.
1851 */
1852 #include <string.h>
1853 char*
1854 vmskrunch (name)
1855      char *name;
1856 {
1857   char *foo;
1858   int max = 60; /* Allow for the ..xx extension */
1859   int len, tlen;
1860
1861   if (name[0] == '*')
1862     return (&name[1]);
1863
1864   len = tlen = strlen (name);
1865   foo = xstrdup (name);
1866
1867   /* Don't muck with the ..xx extenstion */
1868   if ((foo [tlen-4] == '.') && (foo [tlen-3] == '.'))
1869     {
1870       max = max + 4;
1871       if (tlen > max)
1872         {
1873           foo [tlen-4] = 0;
1874           len = len - 4;
1875           max = max - 4;
1876         }
1877     }
1878
1879   if (len > max)
1880     {
1881       char *bar;
1882       int i, j, slen, nlen, xlen, chopchar;
1883
1884       nlen = len;
1885
1886       /* Change all _ and . characters to spaces, if thats enough then quit.
1887          For example: "foobar__foo__bar" becomes "foobar  foo  bar" */
1888
1889       for (i = 0; bar = index (foo, '_'); i++)
1890         *bar = ' ';
1891       nlen = nlen - i;
1892
1893       for (i = 0; bar = index (foo, '.'); i++)
1894         *bar = ' ';
1895       nlen = nlen - i;
1896
1897       for (i = 0; bar = index (foo, '$'); i++)
1898         *bar = ' ';
1899       nlen = nlen - i;
1900
1901       /* Iteratively make blank the rightmost non-blank character on the
1902          longest leftmost substring delmited by blanks, until it's short
1903          enough. For example: "foobar  foo  bar" becomes, successively:
1904          "fooba   foo bar"
1905          "foob    foo bar"
1906          "foo     foo bar"
1907          "fo      foo bar"
1908          "fo      fo  bar"
1909          "fo      fo  ba "
1910          "f       fo  ba "
1911          "f       f   ba "
1912          "f       f   b  "
1913          etc.  */
1914
1915       while (nlen > max)
1916         {
1917           j = 0;
1918           xlen = 0;
1919
1920           while (foo[j])
1921             {
1922               /* Find first non-blank */
1923               if (foo[j])
1924                 for (i = j; foo[i]==' ' && foo[i]; i++)
1925                   ;
1926
1927               /* Find the first blank */
1928               j = i;
1929               if (foo[j])
1930                 for (i = j + 1; foo[i] != ' ' && foo[i]; i++)
1931                   ;
1932
1933               /* If this substring is the longest so far, remember the
1934                  position of the character to chop off. */
1935               slen = i - j;
1936               if (slen > xlen)
1937                 {
1938                   chopchar = i - 1;
1939                   xlen = slen;
1940                 }
1941
1942               j = i;
1943             }
1944
1945           /* Try to avoid chopping uppercase suffix letters */
1946           if (isupper (foo [chopchar]))
1947             {
1948               for (i = chopchar;
1949                    isupper (foo[i]) && foo[i] != ' ' && i >= 0;
1950                    i--)
1951                 ;
1952               if (islower (foo[i]))
1953                 chopchar = i;
1954             }
1955           foo [chopchar] = ' ';
1956           nlen--;
1957         }
1958
1959       /* Put the ..xx extension back */
1960       if (len != tlen)
1961         {
1962           foo [len] = '.';
1963           len = len + 4;
1964         }
1965
1966       /* Collapse all the blanks */
1967       j = 0;
1968       for (i = 0; foo[i]; i++)
1969         if (foo[i] != ' ')
1970           foo[j++] = foo[i];
1971       foo[j] = 0;
1972
1973       return foo;
1974     }
1975
1976   /* Put back the ..xx extension */
1977   if (len != tlen)
1978     {
1979       foo [len] = '.';
1980       len = len + 4;
1981     }
1982
1983   free (foo);
1984   return name;
1985 }
1986
1987 /* On vms we have two kinds of functions:
1988
1989    - stack frame (PROC_STACK)
1990         these are 'normal' functions with local vars and which are
1991         calling other functions
1992    - register frame (PROC_REGISTER)
1993         keeps all data in registers, needs no stack
1994
1995    We must pass this to the assembler so it can generate the
1996    proper pdsc (procedure descriptor)
1997    This is done with the '.pdesc' command.
1998
1999    size is the stack size needed for local variables.  */
2000
2001 void
2002 output_prolog (file, size)
2003      FILE *file;
2004      HOST_WIDE_INT size;
2005 {
2006   unsigned long imask = 0;
2007   unsigned long fmask = 0;
2008   /* Stack space needed for pushing registers clobbered by us.  */
2009   HOST_WIDE_INT sa_size;
2010   /* Complete stack size needed.  */
2011   HOST_WIDE_INT frame_size;
2012   /* Offset from base reg to register save area.  */
2013   int rsa_offset = 8;
2014   /* Offset during register save.  */
2015   int reg_offset;
2016   /* Label for the procedure entry.  */
2017   char entry_label[70];
2018   int i;
2019
2020   sa_size = alpha_sa_size ();
2021   frame_size
2022     = ALPHA_ROUND (sa_size 
2023                    + (is_stack_procedure ? 8 : 0)
2024                    + size + current_function_pretend_args_size);
2025
2026   /* Issue function start and label.  */
2027   fprintf (file, "\t.ent ");
2028   assemble_name (file, alpha_function_name);
2029   fprintf (file, "\n");
2030   sprintf (entry_label, "%.64s..en", alpha_function_name);
2031   ASM_OUTPUT_LABEL (file, entry_label);
2032   inside_function = TRUE;
2033
2034   fprintf (file, "\t.base $%d\n", base_regno);
2035
2036   /* Calculate register masks for clobbered registers.  */
2037
2038   if (is_stack_procedure)
2039     alpha_sa_mask (&imask, &fmask);
2040
2041   /* Adjust the stack by the frame size.  If the frame size is > 4096
2042      bytes, we need to be sure we probe somewhere in the first and last
2043      4096 bytes (we can probably get away without the latter test) and
2044      every 8192 bytes in between.  If the frame size is > 32768, we
2045      do this in a loop.  Otherwise, we generate the explicit probe
2046      instructions. 
2047
2048      Note that we are only allowed to adjust sp once in the prologue.  */
2049
2050   if (frame_size < 32768)
2051     {
2052       if (frame_size > 4096)
2053         {
2054           int probed = 4096;
2055
2056           fprintf (file, "\tstq $31,-%d($30)\n", probed);
2057
2058           while (probed + 8192 < frame_size)
2059             fprintf (file, "\tstq $31,-%d($30)\n", probed += 8192);
2060
2061           /* We only have to do this probe if we aren't saving registers.  */
2062           if (sa_size == 0 && probed + 4096 < frame_size)
2063             fprintf (file, "\tstq $31,-%d($30)\n", frame_size);
2064         }
2065
2066       if (frame_size != 0)
2067           fprintf (file, "\tlda $30,-%d($30)\n", frame_size);
2068     }
2069   else
2070     {
2071       /* Here we generate code to set R4 to SP + 4096 and set R23 to the
2072          number of 8192 byte blocks to probe.  We then probe each block
2073          in the loop and then set SP to the proper location.  If the
2074          amount remaining is > 4096, we have to do one more probe if we
2075          are not saving any registers.  */
2076
2077       HOST_WIDE_INT blocks = (frame_size + 4096) / 8192;
2078       HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192;
2079
2080       add_long_const (file, blocks, 31, 23, 23);
2081
2082       fprintf (file, "\tlda $22,4096($30)\n");
2083
2084       assemble_name (file, alpha_function_name);
2085       fprintf (file, "..sc:\n");
2086
2087       fprintf (file, "\tstq $31,-8192($22)\n");
2088       fprintf (file, "\tsubq $23,1,$23\n");
2089       fprintf (file, "\tlda $22,-8192($22)\n");
2090
2091       fprintf (file, "\tbne $23,");
2092       assemble_name (file, alpha_function_name);
2093       fprintf (file, "..sc\n");
2094
2095       if (leftover > 4096 && sa_size == 0)
2096         fprintf (file, "\tstq $31,-%d($22)\n", leftover);
2097
2098       fprintf (file, "\tlda $30,-%d($22)\n", leftover);
2099     }
2100
2101   if (is_stack_procedure)
2102     {
2103       int reg_offset = rsa_offset;
2104
2105       /* Store R26 (RA) first.  */
2106       fprintf (file, "\tstq $26,%d($30)\n", reg_offset);
2107       reg_offset += 8;
2108
2109       /* Store integer regs. according to mask.  */
2110       for (i = 0; i < 32; i++)
2111         if (imask & (1L<<i))
2112           {
2113             fprintf (file, "\tstq $%d,%d($30)\n", i, reg_offset);
2114             reg_offset += 8;
2115           }
2116
2117       /* Print the register mask and do floating-point saves.  */
2118
2119       if (imask)
2120         fprintf (file, "\t.mask 0x%x,0\n", imask);
2121
2122       for (i = 0; i < 32; i++)
2123         {
2124           if (fmask & (1L << i))
2125             {
2126               fprintf (file, "\tstt $f%d,%d($30)\n", i, reg_offset);
2127               reg_offset += 8;
2128             }
2129         }
2130
2131       /* Print the floating-point mask, if we've saved any fp register.  */
2132       if (fmask)
2133         fprintf (file, "\t.fmask 0x%x,0\n", fmask);
2134
2135       fprintf (file, "\tstq $27,0($30)\n");
2136     }
2137   else 
2138     {
2139       fprintf (file, "\t.fp_save $%d\n", save_fp_regno);
2140       fprintf (file, "\tbis $%d,$%d,$%d\n", HARD_FRAME_POINTER_REGNUM,
2141                HARD_FRAME_POINTER_REGNUM, save_fp_regno);
2142     }
2143
2144   if (base_regno != REG_PV)
2145     fprintf (file, "\tbis $%d,$%d,$%d\n", REG_PV, REG_PV, base_regno);
2146
2147   if (unwind_regno == HARD_FRAME_POINTER_REGNUM)
2148     fprintf (file, "\tbis $%d,$%d,$%d\n", STACK_POINTER_REGNUM,
2149              STACK_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM);
2150
2151   /* Describe our frame.  */
2152   fprintf (file, "\t.frame $%d,%d,$26,%d\n", 
2153            unwind_regno, frame_size, rsa_offset);
2154
2155   /* If we have to allocate space for outgoing args, do it now.  */
2156   if (current_function_outgoing_args_size != 0)
2157     fprintf (file, "\tlda $%d,%d($%d)\n", STACK_POINTER_REGNUM,
2158              - ALPHA_ROUND (current_function_outgoing_args_size),
2159              HARD_FRAME_POINTER_REGNUM);
2160
2161   fprintf (file, "\t.prologue\n");
2162
2163   link_section ();
2164   fprintf (file, "\t.align 3\n");
2165   ASM_OUTPUT_LABEL (file, alpha_function_name);
2166   fprintf (file, "\t.pdesc ");
2167   assemble_name (file, alpha_function_name);
2168   fprintf (file, "..en,%s\n", is_stack_procedure ? "stack" : "reg");
2169   alpha_need_linkage (alpha_function_name, 1);
2170   text_section ();
2171
2172   return;
2173 }
2174
2175 /* Write function epilogue.  */
2176
2177 void
2178 output_epilog (file, size)
2179      FILE *file;
2180      int size;
2181 {
2182   unsigned long imask = 0;
2183   unsigned long fmask = 0;
2184   /* Stack space needed for pushing registers clobbered by us.  */
2185   HOST_WIDE_INT sa_size = alpha_sa_size ();
2186   /* Complete stack size needed.  */
2187   HOST_WIDE_INT frame_size
2188     = ALPHA_ROUND (sa_size
2189                    + (is_stack_procedure ? 8 : 0)
2190                    + size + current_function_pretend_args_size);
2191   int i;
2192   rtx insn = get_last_insn ();
2193
2194   /* If the last insn was a BARRIER, we don't have to write anything except
2195      the .end pseudo-op.  */
2196
2197   if (GET_CODE (insn) == NOTE)
2198     insn = prev_nonnote_insn (insn);
2199
2200   if (insn == 0 || GET_CODE (insn) != BARRIER)
2201     {
2202       /* Restore clobbered registers, load FP last.  */
2203
2204       if (is_stack_procedure)
2205         {
2206           int rsa_offset = 8;
2207           int reg_offset;
2208           int fp_offset;
2209
2210           if (unwind_regno == HARD_FRAME_POINTER_REGNUM)
2211             fprintf (file, "\tbis $%d,$%d,$%d\n", HARD_FRAME_POINTER_REGNUM,
2212                      HARD_FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM);
2213
2214           alpha_sa_mask (&imask, &fmask);
2215
2216           /* Start reloading registers after RA.  */
2217           reg_offset = rsa_offset + 8;
2218
2219           for (i = 0; i < 32; i++)
2220             if (imask & (1L<<i))
2221               {
2222                 if (i == HARD_FRAME_POINTER_REGNUM)
2223                   fp_offset = reg_offset;
2224                 else
2225                   fprintf (file, "\tldq $%d,%d($30)\n",
2226                                   i, reg_offset);
2227                 reg_offset += 8;
2228               }
2229
2230           for (i = 0; i < 32; i++)
2231             if (fmask & (1L << i))
2232               {
2233                 fprintf (file, "\tldt $f%d,%d($30)\n", i, reg_offset);
2234                 reg_offset += 8;
2235               }
2236
2237           /* Restore R26 (RA).  */
2238           fprintf (file, "\tldq $26,%d($30)\n", rsa_offset);
2239
2240           /* Restore R29 (FP).  */
2241           fprintf (file, "\tldq $29,%d($30)\n", fp_offset);
2242         }
2243       else
2244         fprintf (file, "\tbis $%d,$%d,$%d\n", save_fp_regno, save_fp_regno,
2245                  HARD_FRAME_POINTER_REGNUM);
2246
2247       if (frame_size != 0)
2248         {
2249           if (frame_size < 32768)
2250             fprintf (file, "\tlda $30,%d($30)\n", frame_size);
2251           else
2252             {
2253               long high = frame_size >> 16;
2254               long low = frame_size & 0xffff;
2255               if (low & 0x8000)
2256                 {
2257                   high++;
2258                   low = -32768 + (low & 0x7fff);
2259                 }
2260               fprintf (file, "\tldah $2,%ld($31)\n", high);
2261               fprintf (file, "\tlda $2,%ld($2)\n", low);
2262               fprintf (file, "\taddq $30,$2,$30\n");
2263             }
2264         }
2265
2266       /* Finally return to the caller.  */
2267       fprintf (file, "\tret $31,($26),1\n");
2268     }
2269
2270   /* End the function.  */
2271   fprintf (file, "\t.end ");
2272   assemble_name (file,  alpha_function_name);
2273   fprintf (file, "\n");
2274   inside_function = FALSE;
2275
2276   /* Show that we know this function if it is called again.  */
2277   SYMBOL_REF_FLAG (XEXP (DECL_RTL (current_function_decl), 0)) = 1;
2278 }
2279
2280 #else /* !OPEN_VMS */
2281
2282 void
2283 output_prolog (file, size)
2284      FILE *file;
2285      int size;
2286 {
2287   HOST_WIDE_INT out_args_size
2288     = ALPHA_ROUND (current_function_outgoing_args_size);
2289   HOST_WIDE_INT sa_size = alpha_sa_size ();
2290   HOST_WIDE_INT frame_size
2291     = (out_args_size + sa_size
2292        + ALPHA_ROUND (size + current_function_pretend_args_size));
2293   HOST_WIDE_INT reg_offset = out_args_size;
2294   HOST_WIDE_INT start_reg_offset = reg_offset;
2295   HOST_WIDE_INT actual_start_reg_offset = start_reg_offset;
2296   int int_reg_save_area_size = 0;
2297   rtx insn;
2298   unsigned reg_mask = 0;
2299   int i;
2300
2301   /* Ecoff can handle multiple .file directives, so put out file and lineno.
2302      We have to do that before the .ent directive as we cannot switch
2303      files within procedures with native ecoff because line numbers are
2304      linked to procedure descriptors.
2305      Outputting the lineno helps debugging of one line functions as they
2306      would otherwise get no line number at all. Please note that we would
2307      like to put out last_linenum from final.c, but it is not accessible.  */
2308
2309   if (write_symbols == SDB_DEBUG)
2310     {
2311       ASM_OUTPUT_SOURCE_FILENAME (file,
2312                                   DECL_SOURCE_FILE (current_function_decl));
2313       if (debug_info_level != DINFO_LEVEL_TERSE)
2314         ASM_OUTPUT_SOURCE_LINE (file,
2315                                 DECL_SOURCE_LINE (current_function_decl));
2316     }
2317
2318   /* The assembly language programmer's guide states that the second argument
2319      to the .ent directive, the lex_level, is ignored by the assembler,
2320      so we might as well omit it.  */
2321      
2322   if (!flag_inhibit_size_directive)
2323     {
2324       fprintf (file, "\t.ent ");
2325       assemble_name (file, alpha_function_name);
2326       fprintf (file, "\n");
2327     }
2328   ASM_OUTPUT_LABEL (file, alpha_function_name);
2329   inside_function = TRUE;
2330
2331   if (TARGET_IEEE_CONFORMANT && !flag_inhibit_size_directive)
2332     /* Set flags in procedure descriptor to request IEEE-conformant
2333        math-library routines.  The value we set it to is PDSC_EXC_IEEE
2334        (/usr/include/pdsc.h). */
2335     fprintf (file, "\t.eflag 48\n");
2336
2337   /* Set up offsets to alpha virtual arg/local debugging pointer.  */
2338
2339   alpha_auto_offset = -frame_size + current_function_pretend_args_size;
2340   alpha_arg_offset = -frame_size + 48;
2341
2342   /* If we need a GP (we have a LDSYM insn or a CALL_INSN), load it first. 
2343      Even if we are a static function, we still need to do this in case
2344      our address is taken and passed to something like qsort.
2345
2346      We never need a GP for Windows/NT.  */
2347
2348   alpha_function_needs_gp = 0;
2349
2350 #ifdef TARGET_PROFILING_NEEDS_GP
2351   if (profile_flag)
2352     alpha_function_needs_gp = 1;
2353 #endif
2354
2355   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2356     if ((GET_CODE (insn) == CALL_INSN)
2357         || (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2358             && GET_CODE (PATTERN (insn)) != USE
2359             && GET_CODE (PATTERN (insn)) != CLOBBER
2360             && (get_attr_type (insn) == TYPE_LDSYM
2361                 || get_attr_type (insn) == TYPE_ISUBR)))
2362       {
2363         alpha_function_needs_gp = 1;
2364         break;
2365       }
2366
2367   if (TARGET_WINDOWS_NT == 0)
2368     {
2369       if (alpha_function_needs_gp)
2370         fprintf (file, "\tldgp $29,0($27)\n");
2371
2372       /* Put a label after the GP load so we can enter the function at it.  */
2373       assemble_name (file, alpha_function_name);
2374       fprintf (file, "..ng:\n");
2375     }
2376
2377   /* Adjust the stack by the frame size.  If the frame size is > 4096
2378      bytes, we need to be sure we probe somewhere in the first and last
2379      4096 bytes (we can probably get away without the latter test) and
2380      every 8192 bytes in between.  If the frame size is > 32768, we
2381      do this in a loop.  Otherwise, we generate the explicit probe
2382      instructions. 
2383
2384      Note that we are only allowed to adjust sp once in the prologue.  */
2385
2386   if (frame_size < 32768)
2387     {
2388       if (frame_size > 4096)
2389         {
2390           int probed = 4096;
2391
2392           fprintf (file, "\tstq $31,-%d($30)\n", probed);
2393
2394           while (probed + 8192 < frame_size)
2395             fprintf (file, "\tstq $31,-%d($30)\n", probed += 8192);
2396
2397           /* We only have to do this probe if we aren't saving registers.  */
2398           if (sa_size == 0 && probed + 4096 < frame_size)
2399             fprintf (file, "\tstq $31,-%d($30)\n", frame_size);
2400         }
2401
2402       if (frame_size != 0)
2403         fprintf (file, "\tlda $30,-%d($30)\n", frame_size);
2404     }
2405   else
2406     {
2407       /* Here we generate code to set R4 to SP + 4096 and set R5 to the
2408          number of 8192 byte blocks to probe.  We then probe each block
2409          in the loop and then set SP to the proper location.  If the
2410          amount remaining is > 4096, we have to do one more probe if we
2411          are not saving any registers.  */
2412
2413       HOST_WIDE_INT blocks = (frame_size + 4096) / 8192;
2414       HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192;
2415
2416       add_long_const (file, blocks, 31, 5, 5);
2417
2418       fprintf (file, "\tlda $4,4096($30)\n");
2419
2420       assemble_name (file, alpha_function_name);
2421       fprintf (file, "..sc:\n");
2422
2423       fprintf (file, "\tstq $31,-8192($4)\n");
2424       fprintf (file, "\tsubq $5,1,$5\n");
2425       fprintf (file, "\tlda $4,-8192($4)\n");
2426
2427       fprintf (file, "\tbne $5,");
2428       assemble_name (file, alpha_function_name);
2429       fprintf (file, "..sc\n");
2430
2431       if (leftover > 4096 && sa_size == 0)
2432         fprintf (file, "\tstq $31,-%d($4)\n", leftover);
2433
2434       fprintf (file, "\tlda $30,-%d($4)\n", leftover);
2435     }
2436
2437   /* Describe our frame.  */
2438   if (!flag_inhibit_size_directive)
2439     {
2440       fprintf (file, "\t.frame $%d,%d,$26,%d\n", 
2441                (frame_pointer_needed
2442                 ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM),
2443                frame_size, current_function_pretend_args_size);
2444     }
2445     
2446   /* Save register 26 if any other register needs to be saved.  */
2447   if (sa_size != 0)
2448     {
2449       reg_mask |= 1 << 26;
2450       fprintf (file, "\tstq $26,%d($30)\n", reg_offset);
2451       reg_offset += 8;
2452       int_reg_save_area_size += 8;
2453     }
2454
2455   /* Now save any other used integer registers required to be saved.  */
2456   for (i = 0; i < 32; i++)
2457     if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i] && i != 26)
2458       {
2459         reg_mask |= 1 << i;
2460         fprintf (file, "\tstq $%d,%d($30)\n", i, reg_offset);
2461         reg_offset += 8;
2462         int_reg_save_area_size += 8;
2463       }
2464
2465   /* Print the register mask and do floating-point saves.  */
2466   if (reg_mask && !flag_inhibit_size_directive)
2467     fprintf (file, "\t.mask 0x%x,%d\n", reg_mask,
2468              actual_start_reg_offset - frame_size);
2469
2470   start_reg_offset = reg_offset;
2471   reg_mask = 0;
2472
2473   for (i = 0; i < 32; i++)
2474     if (! fixed_regs[i + 32] && ! call_used_regs[i + 32]
2475         && regs_ever_live[i + 32])
2476       {
2477         reg_mask |= 1 << i;
2478         fprintf (file, "\tstt $f%d,%d($30)\n", i, reg_offset);
2479         reg_offset += 8;
2480       }
2481
2482   /* Print the floating-point mask, if we've saved any fp register.  */
2483   if (reg_mask && !flag_inhibit_size_directive)
2484     fprintf (file, "\t.fmask 0x%x,%d\n", reg_mask,
2485              actual_start_reg_offset - frame_size + int_reg_save_area_size);
2486
2487   /* If we need a frame pointer, set it from the stack pointer.  Note that
2488      this must always be the last instruction in the prologue.  */
2489   if (frame_pointer_needed)
2490     fprintf (file, "\tbis $30,$30,$15\n");
2491
2492   /* End the prologue and say if we used gp.  */
2493   if (!flag_inhibit_size_directive)
2494     fprintf (file, "\t.prologue %d\n", alpha_function_needs_gp);
2495 }
2496
2497 /* Write function epilogue.  */
2498
2499 void
2500 output_epilog (file, size)
2501      FILE *file;
2502      int size;
2503 {
2504   rtx insn = get_last_insn ();
2505   HOST_WIDE_INT out_args_size
2506     = ALPHA_ROUND (current_function_outgoing_args_size);
2507   HOST_WIDE_INT sa_size = alpha_sa_size ();
2508   HOST_WIDE_INT frame_size
2509     = (out_args_size + sa_size
2510        + ALPHA_ROUND (size + current_function_pretend_args_size));
2511   HOST_WIDE_INT reg_offset = out_args_size;
2512   HOST_WIDE_INT frame_size_from_reg_save = frame_size - reg_offset;
2513   int restore_fp
2514     = frame_pointer_needed && regs_ever_live[HARD_FRAME_POINTER_REGNUM];
2515   int i;
2516
2517   /* If the last insn was a BARRIER, we don't have to write anything except
2518      the .end pseudo-op.  */
2519   if (GET_CODE (insn) == NOTE)
2520     insn = prev_nonnote_insn (insn);
2521   if (insn == 0 || GET_CODE (insn) != BARRIER)
2522     {
2523       int fp_offset = 0;
2524
2525       final_prescan_insn (NULL_RTX, NULL_PTR, 0);
2526
2527       /* If we have a frame pointer, restore SP from it.  */
2528       if (frame_pointer_needed)
2529         fprintf (file, "\tbis $15,$15,$30\n");
2530
2531       /* Restore all the registers, starting with the return address
2532          register.  */
2533       if (sa_size != 0)
2534         {
2535           fprintf (file, "\tldq $26,%d($30)\n", reg_offset);
2536           reg_offset += 8;
2537         }
2538
2539       /* Now restore any other used integer registers that that we saved,
2540          except for FP if it is being used as FP, since it must be
2541          restored last.  */
2542
2543       for (i = 0; i < 32; i++)
2544         if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i]
2545             && i != 26)
2546           {
2547             if (i == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed)
2548               fp_offset = reg_offset;
2549             else
2550               fprintf (file, "\tldq $%d,%d($30)\n", i, reg_offset);
2551             reg_offset += 8;
2552           }
2553
2554       for (i = 0; i < 32; i++)
2555         if (! fixed_regs[i + 32] && ! call_used_regs[i + 32]
2556             && regs_ever_live[i + 32])
2557           {
2558             fprintf (file, "\tldt $f%d,%d($30)\n", i, reg_offset);
2559             reg_offset += 8;
2560           }
2561
2562       /* If the stack size is large and we have a frame pointer, compute the
2563          size of the stack into a register because the old FP restore, stack
2564          pointer adjust, and return are required to be consecutive
2565          instructions.   */
2566       if (frame_size > 32767 && restore_fp)
2567         add_long_const (file, frame_size, 31, 1, 1);
2568
2569       /* If we needed a frame pointer and we have to restore it, do it
2570          now.  This must be done in one instruction immediately
2571          before the SP update.  */
2572       if (restore_fp && fp_offset)
2573         fprintf (file, "\tldq $15,%d($30)\n", fp_offset);
2574
2575       /* Now update the stack pointer, if needed.  Only one instruction must
2576          modify the stack pointer.  It must be the last instruction in the
2577          sequence and must be an ADDQ or LDA instruction.  If the frame
2578          pointer was loaded above, we may only put one instruction here.  */
2579
2580       if (frame_size > 32768 && restore_fp)
2581         fprintf  (file, "\taddq $1,$30,$30\n");
2582       else
2583         add_long_const (file, frame_size, 30, 30, 1);
2584
2585       /* Finally return to the caller.  */
2586       fprintf (file, "\tret $31,($26),1\n");
2587     }
2588
2589   /* End the function.  */
2590   if (!flag_inhibit_size_directive)
2591     {
2592       fprintf (file, "\t.end ");
2593       assemble_name (file, alpha_function_name);
2594       fprintf (file, "\n");
2595     }
2596   inside_function = FALSE;
2597
2598   /* Show that we know this function if it is called again.  */
2599   SYMBOL_REF_FLAG (XEXP (DECL_RTL (current_function_decl), 0)) = 1;
2600 }
2601 #endif /* !OPEN_VMS */
2602 \f
2603 /* Debugging support.  */
2604
2605 #include "gstab.h"
2606
2607 /* Count the number of sdb related labels are generated (to find block
2608    start and end boundaries).  */
2609
2610 int sdb_label_count = 0;
2611
2612 /* Next label # for each statement.  */
2613
2614 static int sym_lineno = 0;
2615
2616 /* Count the number of .file directives, so that .loc is up to date.  */
2617
2618 static int num_source_filenames = 0;
2619
2620 /* Name of the file containing the current function.  */
2621
2622 static char *current_function_file = "";
2623
2624 /* Offsets to alpha virtual arg/local debugging pointers.  */
2625
2626 long alpha_arg_offset;
2627 long alpha_auto_offset;
2628 \f
2629 /* Emit a new filename to a stream.  */
2630
2631 void
2632 alpha_output_filename (stream, name)
2633      FILE *stream;
2634      char *name;
2635 {
2636   static int first_time = TRUE;
2637   char ltext_label_name[100];
2638
2639   if (first_time)
2640     {
2641       first_time = FALSE;
2642       ++num_source_filenames;
2643       current_function_file = name;
2644       fprintf (stream, "\t.file\t%d ", num_source_filenames);
2645       output_quoted_string (stream, name);
2646       fprintf (stream, "\n");
2647       if (!TARGET_GAS && write_symbols == DBX_DEBUG)
2648         fprintf (stream, "\t#@stabs\n");
2649     }
2650
2651   else if (write_symbols == DBX_DEBUG)
2652     {
2653       ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
2654       fprintf (stream, "%s ", ASM_STABS_OP);
2655       output_quoted_string (stream, name);
2656       fprintf (stream, ",%d,0,0,%s\n", N_SOL, &ltext_label_name[1]);
2657     }
2658
2659   else if (name != current_function_file
2660       && strcmp (name, current_function_file) != 0)
2661     {
2662       if (inside_function && ! TARGET_GAS)
2663         fprintf (stream, "\t#.file\t%d ", num_source_filenames);
2664       else
2665         {
2666           ++num_source_filenames;
2667           current_function_file = name;
2668           fprintf (stream, "\t.file\t%d ", num_source_filenames);
2669         }
2670
2671       output_quoted_string (stream, name);
2672       fprintf (stream, "\n");
2673     }
2674 }
2675 \f
2676 /* Emit a linenumber to a stream.  */
2677
2678 void
2679 alpha_output_lineno (stream, line)
2680      FILE *stream;
2681      int line;
2682 {
2683   if (write_symbols == DBX_DEBUG)
2684     {
2685       /* mips-tfile doesn't understand .stabd directives.  */
2686       ++sym_lineno;
2687       fprintf (stream, "$LM%d:\n\t%s %d,0,%d,$LM%d\n",
2688                sym_lineno, ASM_STABN_OP, N_SLINE, line, sym_lineno);
2689     }
2690   else
2691     fprintf (stream, "\n\t.loc\t%d %d\n", num_source_filenames, line);
2692 }
2693 \f
2694 /* Structure to show the current status of registers and memory.  */
2695
2696 struct shadow_summary
2697 {
2698   struct {
2699     unsigned long i     : 32;   /* Mask of int regs */
2700     unsigned long fp    : 32;   /* Mask of fp regs */
2701     unsigned long mem   :  1;   /* mem == imem | fpmem */
2702   } used, defd;
2703 };
2704
2705 /* Summary the effects of expression X on the machine.  Update SUM, a pointer
2706    to the summary structure.  SET is nonzero if the insn is setting the
2707    object, otherwise zero.  */
2708
2709 static void
2710 summarize_insn (x, sum, set)
2711      rtx x;
2712      struct shadow_summary *sum;
2713      int set;
2714 {
2715   char *format_ptr;
2716   int i, j;
2717
2718   if (x == 0)
2719     return;
2720
2721   switch (GET_CODE (x))
2722     {
2723       /* ??? Note that this case would be incorrect if the Alpha had a
2724          ZERO_EXTRACT in SET_DEST.  */
2725     case SET:
2726       summarize_insn (SET_SRC (x), sum, 0);
2727       summarize_insn (SET_DEST (x), sum, 1);
2728       break;
2729
2730     case CLOBBER:
2731       summarize_insn (XEXP (x, 0), sum, 1);
2732       break;
2733
2734     case USE:
2735       summarize_insn (XEXP (x, 0), sum, 0);
2736       break;
2737
2738     case PARALLEL:
2739       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
2740         summarize_insn (XVECEXP (x, 0, i), sum, 0);
2741       break;
2742
2743     case REG:
2744       {
2745         int regno = REGNO (x);
2746         unsigned long mask = 1UL << (regno % 32);
2747
2748         if (regno == 31 || regno == 63)
2749           break;
2750
2751         if (set)
2752           {
2753             if (regno < 32)
2754               sum->defd.i |= mask;
2755             else
2756               sum->defd.fp |= mask;
2757           }
2758         else
2759           {
2760             if (regno < 32)
2761               sum->used.i  |= mask;
2762             else
2763               sum->used.fp |= mask;
2764           }
2765         }
2766       break;
2767
2768     case MEM:
2769       if (set)
2770         sum->defd.mem = 1;
2771       else
2772         sum->used.mem = 1;
2773
2774       /* Find the regs used in memory address computation: */
2775       summarize_insn (XEXP (x, 0), sum, 0);
2776       break;
2777
2778     case SUBREG:
2779       summarize_insn (SUBREG_REG (x), sum, 0);
2780       break;
2781
2782     case CONST_INT:   case CONST_DOUBLE:
2783     case SYMBOL_REF:  case LABEL_REF:     case CONST:
2784       break;
2785
2786       /* Handle common unary and binary ops for efficiency.  */
2787     case COMPARE:  case PLUS:    case MINUS:   case MULT:      case DIV:
2788     case MOD:      case UDIV:    case UMOD:    case AND:       case IOR:
2789     case XOR:      case ASHIFT:  case ROTATE:  case ASHIFTRT:  case LSHIFTRT:
2790     case ROTATERT: case SMIN:    case SMAX:    case UMIN:      case UMAX:
2791     case NE:       case EQ:      case GE:      case GT:        case LE:
2792     case LT:       case GEU:     case GTU:     case LEU:       case LTU:
2793       summarize_insn (XEXP (x, 0), sum, 0);
2794       summarize_insn (XEXP (x, 1), sum, 0);
2795       break;
2796
2797     case NEG:  case NOT:  case SIGN_EXTEND:  case ZERO_EXTEND:
2798     case TRUNCATE:  case FLOAT_EXTEND:  case FLOAT_TRUNCATE:  case FLOAT:
2799     case FIX:  case UNSIGNED_FLOAT:  case UNSIGNED_FIX:  case ABS:
2800     case SQRT:  case FFS: 
2801       summarize_insn (XEXP (x, 0), sum, 0);
2802       break;
2803
2804     default:
2805       format_ptr = GET_RTX_FORMAT (GET_CODE (x));
2806       for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2807         switch (format_ptr[i])
2808           {
2809           case 'e':
2810             summarize_insn (XEXP (x, i), sum, 0);
2811             break;
2812
2813           case 'E':
2814             for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2815               summarize_insn (XVECEXP (x, i, j), sum, 0);
2816             break;
2817
2818           default:
2819             abort ();
2820           }
2821     }
2822 }
2823 \f
2824 /* This function is executed just prior to the output of assembler code for
2825    INSN to modify the extracted operands so they will be output differently.
2826
2827    OPVEC is the vector containing the operands extracted from INSN, and
2828    NOPERANDS is the number of elements of the vector which contain meaningful
2829    data for this insn.  The contents of this vector are what will be used to
2830    convert the insn template into assembler code, so you can change the
2831    assembler output by changing the contents of the vector.
2832
2833    We use this function to ensure a sufficient number of `trapb' instructions
2834    are in the code when the user requests code with a trap precision of
2835    functions or instructions.
2836
2837    In naive mode, when the user requests a trap-precision of "instruction", a
2838    trapb is needed after every instruction that may generate a trap (and after
2839    jsr/bsr instructions, because called functions may import a trap from the
2840    caller).  This ensures that the code is resumption safe but it is also slow.
2841
2842    When optimizations are turned on, we delay issuing a trapb as long as
2843    possible.  In this context, a trap shadow is the sequence of instructions
2844    that starts with a (potentially) trap generating instruction and extends to
2845    the next trapb or call_pal instruction (but GCC never generates call_pal by
2846    itself).  We can delay (and therefore sometimes omit) a trapb subject to the
2847    following conditions:
2848
2849    (a) On entry to the trap shadow, if any Alpha register or memory location
2850    contains a value that is used as an operand value by some instruction in
2851    the trap shadow (live on entry), then no instruction in the trap shadow
2852    may modify the register or memory location.
2853
2854    (b) Within the trap shadow, the computation of the base register for a
2855    memory load or store instruction may not involve using the result
2856    of an instruction that might generate an UNPREDICTABLE result.
2857
2858    (c) Within the trap shadow, no register may be used more than once as a
2859    destination register.  (This is to make life easier for the trap-handler.)
2860
2861    (d) The trap shadow may not include any branch instructions.
2862
2863      */
2864
2865 void
2866 final_prescan_insn (insn, opvec, noperands)
2867      rtx insn;
2868      rtx *opvec;
2869      int noperands;
2870 {
2871   static struct shadow_summary shadow = {0, 0, 0, 0, 0};
2872
2873 #define CLOSE_SHADOW                            \
2874   do                                            \
2875     {                                           \
2876       fputs ("\ttrapb\n", asm_out_file);        \
2877       trap_pending = 0;                         \
2878       bzero ((char *) &shadow,  sizeof shadow); \
2879     }                                           \
2880   while (0)
2881
2882   if (alpha_tp == ALPHA_TP_PROG)
2883     return;
2884
2885   if (trap_pending)
2886     switch (alpha_tp)
2887       {
2888       case ALPHA_TP_FUNC:
2889         /* Generate one trapb before epilogue (indicated by INSN==0) */
2890         if (insn == 0)
2891           CLOSE_SHADOW;
2892         break;
2893
2894       case ALPHA_TP_INSN:
2895         if (optimize && insn != 0)
2896           {
2897             struct shadow_summary sum = {0, 0, 0};
2898
2899             switch (GET_CODE(insn))
2900               {
2901               case INSN:
2902                 summarize_insn (PATTERN (insn), &sum, 0);
2903
2904                 if ((sum.defd.i & shadow.defd.i)
2905                     || (sum.defd.fp & shadow.defd.fp))
2906                   {
2907                     /* (c) would be violated */
2908                     CLOSE_SHADOW;
2909                     break;
2910                   }
2911
2912                 /* Combine shadow with summary of current insn: */
2913                 shadow.used.i     |= sum.used.i;
2914                 shadow.used.fp    |= sum.used.fp;
2915                 shadow.used.mem   |= sum.used.mem;
2916                 shadow.defd.i     |= sum.defd.i;
2917                 shadow.defd.fp    |= sum.defd.fp;
2918                 shadow.defd.mem   |= sum.defd.mem;
2919
2920                 if ((sum.defd.i & shadow.used.i)
2921                     || (sum.defd.fp & shadow.used.fp)
2922                     || (sum.defd.mem & shadow.used.mem))
2923                   {
2924                     /* (a) would be violated (also takes care of (b)).  */
2925                     if (get_attr_trap (insn) == TRAP_YES
2926                         && ((sum.defd.i & sum.used.i)
2927                             || (sum.defd.fp & sum.used.fp)))
2928                       abort ();
2929
2930                     CLOSE_SHADOW;
2931                     break;
2932                   }
2933                 break;
2934
2935               case JUMP_INSN:
2936               case CALL_INSN:
2937               case CODE_LABEL:
2938                 CLOSE_SHADOW;
2939                 break;
2940
2941               default:
2942                 abort ();
2943               }
2944           }
2945         else
2946           CLOSE_SHADOW;
2947         break;
2948       }
2949
2950   if (insn != 0 && get_attr_trap (insn) == TRAP_YES)
2951     {
2952       if (optimize && !trap_pending && GET_CODE (insn) == INSN)
2953         summarize_insn (PATTERN (insn), &shadow, 0);
2954       trap_pending = 1;
2955     }
2956 }
2957
2958 /* Check a floating-point value for validity for a particular machine mode.  */
2959
2960 static char *float_strings[] =
2961 {
2962    "1.70141173319264430e+38", /* 2^127 (2^24 - 1) / 2^24 */
2963   "-1.70141173319264430e+38",
2964    "2.93873587705571877e-39", /* 2^-128 */
2965   "-2.93873587705571877e-39"
2966 };
2967
2968 static REAL_VALUE_TYPE float_values[4];
2969 static int inited_float_values = 0;
2970
2971 int
2972 check_float_value (mode, d, overflow)
2973      enum machine_mode mode;
2974      REAL_VALUE_TYPE *d;
2975      int overflow;
2976 {
2977
2978   if (TARGET_IEEE || TARGET_IEEE_CONFORMANT || TARGET_IEEE_WITH_INEXACT)
2979     return 0;
2980
2981   if (TARGET_FLOAT_VAX)
2982     return 0;
2983
2984   if (inited_float_values == 0)
2985     {
2986       int i;
2987       for (i = 0; i < 4; i++)
2988         float_values[i] = REAL_VALUE_ATOF (float_strings[i], DFmode);
2989
2990       inited_float_values = 1;
2991     }
2992
2993   if (mode == SFmode)
2994     {
2995       REAL_VALUE_TYPE r;
2996
2997       bcopy ((char *) d, (char *) &r, sizeof (REAL_VALUE_TYPE));
2998       if (REAL_VALUES_LESS (float_values[0], r))
2999         {
3000           bcopy ((char *) &float_values[0], (char *) d,
3001                  sizeof (REAL_VALUE_TYPE));
3002           return 1;
3003         }
3004       else if (REAL_VALUES_LESS (r, float_values[1]))
3005         {
3006           bcopy ((char *) &float_values[1], (char *) d,
3007                  sizeof (REAL_VALUE_TYPE));
3008           return 1;
3009         }
3010       else if (REAL_VALUES_LESS (dconst0, r)
3011                 && REAL_VALUES_LESS (r, float_values[2]))
3012         {
3013           bcopy ((char *) &dconst0, (char *) d, sizeof (REAL_VALUE_TYPE));
3014           return 1;
3015         }
3016       else if (REAL_VALUES_LESS (r, dconst0)
3017                 && REAL_VALUES_LESS (float_values[3], r))
3018         {
3019           bcopy ((char *) &dconst0, (char *) d, sizeof (REAL_VALUE_TYPE));
3020           return 1;
3021         }
3022     }
3023
3024   return 0;
3025 }
3026
3027 #if OPEN_VMS
3028
3029 void *
3030 function_arg (cum, mode, type, named)
3031     CUMULATIVE_ARGS *cum;
3032     enum machine_mode mode;
3033     tree type;
3034     int named;
3035 {
3036   int arg;
3037
3038   if (mode == VOIDmode)         /* final call, return argument information  */
3039     {
3040       return GEN_INT (*cum);
3041     }
3042
3043   arg = *cum & 0xff;
3044
3045   switch (mode)
3046     {
3047       case SFmode:
3048         *cum |= (((TARGET_FLOAT_VAX)?1:4) << ((arg * 3)+8));      /* 4 = AI$K_AR_FS, IEEE single */
3049         break;
3050       case DFmode:
3051         *cum |= (((TARGET_FLOAT_VAX)?3:5) << ((arg * 3)+8));      /* 5 = AI$K_AR_FT, IEEE double */
3052         break;
3053       case TFmode:
3054         *cum |= (7 << ((arg * 3)+8));        /* 5 = AI$K_AR_FT, IEEE double */
3055         break;
3056       default:
3057         break;
3058     }
3059
3060   return (arg < 6 && ! MUST_PASS_IN_STACK (mode, type)
3061          ? gen_rtx(REG, mode,
3062                    (*cum & 0xff) + 16 + ((TARGET_FPREGS
3063                           && (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3064                               || GET_MODE_CLASS (mode) == MODE_FLOAT))
3065                          * 32))
3066          : 0);
3067 }
3068
3069 /* Structure to collect function names for final output
3070    in link section.  */
3071
3072 enum links_kind {KIND_UNUSED, KIND_LOCAL, KIND_EXTERN};
3073
3074
3075 struct alpha_links {
3076   struct alpha_links *next;
3077   char *name;
3078   enum links_kind kind;
3079 };
3080
3081 static struct alpha_links *alpha_links_base = 0;
3082
3083 /* Make (or fake) .linkage entry for function call.
3084
3085    IS_LOCAL is 0 if name is used in call, 1 if name is used in definition.  */
3086
3087 void
3088 alpha_need_linkage (name, is_local)
3089     char *name;
3090     int is_local;
3091 {
3092   rtx x;
3093   struct alpha_links *lptr, *nptr;
3094
3095   if (name[0] == '*')
3096     name++;
3097
3098   /* Is this name already defined ?  */
3099
3100   for (lptr = alpha_links_base; lptr; lptr = lptr->next)
3101     if (strcmp (lptr->name, name) == 0)
3102       {
3103         if (is_local)
3104           {
3105             /* defined here but external assumed.  */
3106             if (lptr->kind == KIND_EXTERN)
3107               lptr->kind = KIND_LOCAL;
3108           }
3109         else
3110           {
3111             /* used here but unused assumed.  */
3112             if (lptr->kind == KIND_UNUSED)
3113               lptr->kind = KIND_LOCAL;
3114           }
3115         return;
3116       }
3117
3118   nptr = (struct alpha_links *) xmalloc (sizeof (struct alpha_links));
3119   nptr->next = alpha_links_base;
3120   nptr->name = xstrdup (name);
3121
3122   /* Assume external if no definition.  */
3123   nptr->kind = (is_local ? KIND_UNUSED : KIND_EXTERN);
3124
3125   alpha_links_base = nptr;
3126
3127   return;
3128 }
3129
3130
3131 void
3132 alpha_write_linkage (stream)
3133     FILE *stream;
3134 {
3135   struct alpha_links *lptr, *nptr;
3136
3137   readonly_section ();
3138
3139   fprintf (stream, "\t.align 3\n");
3140
3141   for (lptr = alpha_links_base; lptr; lptr = nptr)
3142     {
3143       nptr = lptr->next;
3144
3145       if (lptr->kind == KIND_UNUSED
3146           || ! TREE_SYMBOL_REFERENCED (get_identifier (lptr->name)))
3147         continue;
3148
3149       fprintf (stream, "%s..lk:\n", lptr->name);
3150       if (lptr->kind == KIND_LOCAL)   
3151         {
3152           /*  Local and used, build linkage pair.  */
3153           fprintf (stream, "\t.quad %s..en\n", lptr->name);
3154           fprintf (stream, "\t.quad %s\n", lptr->name);
3155         }
3156       else
3157         /* External and used, request linkage pair.  */
3158         fprintf (stream, "\t.linkage %s\n", lptr->name);
3159     }
3160 }
3161
3162 #else
3163
3164 void
3165 alpha_need_linkage (name, is_local)
3166      char *name;
3167      int is_local;
3168 {
3169 }
3170
3171 #endif /* OPEN_VMS */
3172