OSDN Git Service

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