OSDN Git Service

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